Package javax.microedition.lcdui

Examples of javax.microedition.lcdui.Font


    }

    private void paintGrid( final Graphics g )
    {
        final Vector items = this.items;
        final Font helpFont = this.helpFont;

        if( dirty )
        {
            calcGrid();
        }
        final int labelX = this.labelX;
        final Rectangle[] zones = this.zones;
        final MenuItem selected = (MenuItem) items.elementAt( selectedIndex );
        int x, align;
        if( gridFont.stringWidth( selected.label ) > getWidth() - 2 )
        {
            x = 1;
            align = Graphics.LEFT;
        }
        else
        {
            x = labelX;
            align = Graphics.HCENTER;
        }
        g.setFont( gridFont );
        g.setColor( 0xC0C0C0 );
        g.drawString(
                selected.label,
                x + 1,
                labelY + 1,
                Graphics.BASELINE | align
        );
        g.setColor( color );
        g.drawString(
                selected.label,
                x,
                labelY,
                Graphics.BASELINE | align
        );
        final int zoneCount = zones.length;
        final int itemCount = items.size();
        int index = firstVisible;
        for( int i = 0; i < zoneCount; i++ )
        {
            final MenuItem item = (MenuItem) items.elementAt( index );
            g.drawImage(
                    index == selectedIndex ? item.selectedImage : item.image,
                    zones[i].getX() + 2,
                    zones[i].getY() + 2,
                    Graphics.LEFT | Graphics.TOP
            );
            index++;
            if( index >= itemCount )
            {
                index = 0;
            }
        }

        if( selected.help != null )
        {
            g.setFont( helpFont );
            g.setColor( color );
            if( helpFont.stringWidth( selected.help ) > getWidth() - 2 )
            {
                g.drawString(
                    selected.help,
                    1,
                    getHeight() - helpFont.getHeight() + helpFont.getBaselinePosition() - 1,
                    Graphics.BASELINE | Graphics.LEFT
                );
            }
            else
            {
                g.drawString(
                    selected.help,
                    labelX,
                    getHeight() - helpFont.getHeight() + helpFont.getBaselinePosition() - 1,
                    Graphics.BASELINE | Graphics.HCENTER
                );
            }
        }
    }
View Full Code Here


         */
        void drawChar(Graphics g, char c, int row, int col, boolean reverse) {
            int y = wy + row * cellSize + hmargin;
            int x = wx + col * cellSize + wmargin;

            Font old_font = g.getFont();
            g.setFont(font);
            g.setGrayScale(reverse ? 255 : 0);
            g.drawChar(c, x, y, Graphics.HCENTER | Graphics.TOP);
            g.setFont(old_font);
        }
View Full Code Here

    public static int canDrawStringPart(Graphics g, String str,
                                 int width) {
        if (width < 0) {
            return 0;
        }
        final Font font = g.getFont();
        final int stringWidth = font.stringWidth(str);

        if (width >= stringWidth) {
            return str.length();
        }
        final int widthForTruncatedText = width - font.charWidth(truncationMark);
        int availableLength;
        for (availableLength = str.length() - 1 ;
             font.substringWidth(str,0,availableLength) > widthForTruncatedText;
             availableLength-- ) {};
        return availableLength;
    }
View Full Code Here

            int clipX = g.getClipX();
            int clipY = g.getClipY();
            int clipW = g.getClipWidth();
            int clipH = g.getClipHeight();

            Font old_font = g.getFont();
            g.setFont(font);

            g.setGrayScale(255);
            g.fillRect(clipX, clipY, clipW, clipH);
View Full Code Here

   * Draws the text.
   */
  public void drawContent(Graphics g, int dx, int dy) {
    // System.out.println("drawing tfw: "+text);
    Style style = element.getComputedStyle();
    Font font = style.getFont();
    int textColor = style.getValue(Style.COLOR);
    if (isFocused() && !element.isFocused()) {
      element.setFocused();
    }
    boolean focus = element.isFocused();

    if (indices == null) {
      if (focus) {
      Skin.get().fillFocusRect(g, dx, dy,
            font.stringWidth(text), font.getHeight());
      }
      g.setColor(textColor);
      g.setFont(font);
      g.drawString(text, dx, dy, Graphics.TOP | Graphics.LEFT);
    } else {
      int y = dy + firstLineYOffset;
      int clipY = g.getClipY();
      int clipH = g.getClipHeight();
      int fh = font.getHeight();

      for (int i = 0; i < indices.length; i += 3) {
        if (clipY < y + fh &&  y < clipY + clipH) {
          int start = indices[i];
          int len = indices[i + 1];

          if (focus) {
            Skin.get().fillFocusRect(g, dx + indices[i + 2], y,
                font.substringWidth(text, start, len), font.getHeight());
          }
          g.setColor(textColor);
          g.setFont(font);
          g.drawSubstring(text, start, len, dx + indices[i + 2], y, Graphics.TOP | Graphics.LEFT);
        }
        y += fh;
        if (i == 0) {
          y += mainYOffset;
        }
        if (i == indices.length - 6) {
          y += lastLineYOffset;
        }
      }
    }
   
    if (HtmlWidget.debug == this) {
      g.setColor(0x00ff00);
      g.drawRect(dx, dy, getWidth() - 1, getHeight() - 1);
      if (getLineCount() > 1) {
      
        int fh = font.getHeight();
        int y = dy;
        g.setColor(0x0ff0000);
        g.drawLine(dx, y, dx, y + firstLineYOffset);
        y += firstLineYOffset;
       
        for (int i = 0; i < indices.length; i += 3) {
          g.setColor(0x0000ff);
          g.drawRect(dx + indices[i + 2], y,
              font.substringWidth(text, indices[i], indices[i + 1]), fh - 1);
          y += fh;
          if (i == 0) {
            g.setColor(0x0ff0000);
            g.drawLine(dx + 2, y, dx + 2, y + mainYOffset);
            y += mainYOffset;
View Full Code Here

   * Delegates break position search to next sibling if necessary.
   */
  private final int findBreakPosition(BlockWidget parent, int myIndex,
      char currentChar, int nextCharIndex, int w, int bestPos, int maxWidth) {
    int[] widths = element.getComputedStyle().getCharWidths();
    Font font = getFont();
    int len = text.length();
   
    while (true) {
      if (currentChar == '\n') {
        return nextCharIndex;
      }
      if (w > maxWidth && bestPos != Integer.MAX_VALUE) {
        return bestPos;
      }
      if (nextCharIndex >= len) {
        break;
      }
      char nextChar = text.charAt(nextCharIndex);
      if (Util.canBreak(currentChar, nextChar)) {
        bestPos = nextCharIndex;
      }
      nextCharIndex++;
      currentChar = nextChar;
      // we do not consider kerning for performance reasons. This may result in
      // breaking the line slightly too early, which should be fine.
      // TODO(haustein) consider summing up word lengths instead
      w += currentChar < widths.length ? widths[currentChar] :
        font.charWidth(currentChar);
    }

    TextFragmentWidget next = getNextSibling(parent, myIndex);
    if (next == null) {
      return w <= maxWidth ? Integer.MAX_VALUE : bestPos;
View Full Code Here

    int h = boxHeight - bottom - top;

    dx += left + boxX;
    dy += top + boxY;

    Font font = style.getFont();
    int color = style.getValue(Style.COLOR);
    boolean selected = false;

    switch(type) {
      case Skin.INPUT_TYPE_OPTION: 
View Full Code Here

   */
  public StyleSheet(boolean init) {
    if(!init) {
      return;
    }
    Font font = new Style().getFont();

    // Set default indent with to sufficient space for ordered lists with
    // two digits and the default paragraph spacing to 50% of the font height
    // (so top and bottom spacing adds up to a full line)
    int defaultIndent = font.stringWidth("88. ") * 1000;
    int defaultParagraphSpace = Math.max(1, font.getHeight() / 2) * 1000;
   
    put(":link", new Style().set(Style.COLOR, 0x0ff0000ff, Style.ARGB).
        set(Style.TEXT_DECORATION, Style.UNDERLINE, Style.ENUM));
    put("address", new Style().set(Style.DISPLAY, Style.BLOCK, Style.ENUM));
    put("b", new Style().set(Style.FONT_WEIGHT, 700000, Style.NUMBER));
View Full Code Here

      for (int i = 0; i < children.size(); i++) {
        Widget child = (Widget) children.elementAt(i);
        if (child instanceof TextFragmentWidget) {
          TextFragmentWidget fragment = (TextFragmentWidget) child;
          int[] widths = fragment.element.getComputedStyle().getCharWidths();
          Font font = fragment.getFont();
          String text = fragment.text;

          char c = 160;
          int wordWidth = 0;
          for (int j = 0; j < text.length(); j++) {
            char d = text.charAt(j);
            if (Util.canBreak(c, d)) {
              minW = Math.max(minW, wordWidth);
              currentLineWidth += wordWidth;
              if (c == '\n') {
                maxW = Math.max(maxW, currentLineWidth);
                currentLineWidth = 0;
              }
              wordWidth = 0;
            }
            c = d;
            wordWidth += c < widths.length ? widths[c] : font.charWidth(c);
          }
          if (c == '\n') {
            maxW = Math.max(maxW, currentLineWidth);
            currentLineWidth = 0;
          }
View Full Code Here

      }
    }
    if (style.getEnum(Style.DISPLAY) == Style.LIST_ITEM) {
      g.setColor(style.getValue(Style.COLOR));

      Font f = style.getFont();
      // en space -- see http://en.wikipedia.org/wiki/En_%28typography%29
      // using this because on blackberry digit widths are messed up
      int en = f.getHeight() / 2;
      // round up so in doubt the dot size is a bit bigger and the pos is lower
      int size = (f.getHeight() + 2) / 3;
      int liy = y0 + 1 + style.getPx(Style.PADDING_TOP, containingWidth);

      switch (style.getValue(Style.LIST_STYLE_TYPE)) {
        case Style.SQUARE:
          g.fillRect(dx - size - en, liy + size, size, size);
          break;
        case Style.CIRCLE:
          g.drawRoundRect(dx - size - en, liy + size, size, size, size / 2, size / 2);
          break;
        case Style.DECIMAL:
          String nr = (getParent().indexOfChild(this) + 1) + ". ";
          g.setFont(f);
          g.drawString(nr, dx - f.stringWidth(nr), liy, Graphics.TOP | Graphics.LEFT);
          break;
        case Style.DISC:
          g.fillRoundRect(dx - size - en, liy + size, size, size, size / 2,
              size / 2);
          break;
View Full Code Here

TOP

Related Classes of javax.microedition.lcdui.Font

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.