Package java.awt.font

Examples of java.awt.font.GlyphVector


    final Rectangle2D rect = this.font.getMaxCharBounds(frc);
    this.maxCharAdvance = FontStrictGeomUtility.toInternalValue(rect.getWidth());
    this.ascent = FontStrictGeomUtility.toInternalValue(-rect.getY());
    this.descent = FontStrictGeomUtility.toInternalValue(rect.getHeight() + rect.getY());

    final GlyphVector gv = font.createGlyphVector(frc, "x");
    final Rectangle2D bounds = gv.getVisualBounds();
    this.xheight = FontStrictGeomUtility.toInternalValue(bounds.getHeight());

    this.cpBuffer = new char[4];
    this.cachedBaselines = new BaselineInfo[256 - 32];
    this.cachedWidths = new long[256 - 32];
View Full Code Here


    final int retvalC2 = CodePointUtilities.toChars(character, cpBuffer, retvalC1);
    if (retvalC2 > 0)
    {
      final int limit = (retvalC1 + retvalC2);
      final GlyphVector gv = font.createGlyphVector(frc, new String(cpBuffer, 0, limit));
      final long totalSize = FontStrictGeomUtility.toInternalValue(gv.getGlyphPosition(limit).getX());
      final long renderedWidth = FontStrictGeomUtility.toInternalValue(gv.getOutline().getBounds2D().getWidth());
      return totalSize - renderedWidth;
    }
    else
    {
      return 0;
View Full Code Here

                            lastWhitespaceIndex = -1;

                            // Append the current line
                            if ((i - 1) - start > 0) {
                                StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                                GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                                glyphVectors.add(glyphVector);

                                Rectangle2D textBounds = glyphVector.getLogicalBounds();
                                textHeight += textBounds.getHeight();
                            }

                            start = i + 1;
                        }

                        i++;
                    }

                    // Append the final line
                    if ((i - 1) - start > 0) {
                        StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                        GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                        glyphVectors.add(glyphVector);

                        Rectangle2D textBounds = glyphVector.getLogicalBounds();
                        textHeight += textBounds.getHeight();
                    }
                } else {
                    GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, text);
                    glyphVectors.add(glyphVector);

                    Rectangle2D textBounds = glyphVector.getLogicalBounds();
                    textHeight += textBounds.getHeight();
                }
            }
        }
    }
View Full Code Here

                    break;
                }
            }

            for (int i = 0, n = glyphVectors.getLength(); i < n; i++) {
                GlyphVector glyphVector = glyphVectors.get(i);

                Rectangle2D textBounds = glyphVector.getLogicalBounds();
                float lineWidth = (float)textBounds.getWidth();

                float x = 0;
                switch(horizontalAlignment) {
                    case LEFT: {
View Full Code Here

        }

        this.font = font;

        int missingGlyphCode = font.getMissingGlyphCode();
        GlyphVector missingGlyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT,
            new int[] {missingGlyphCode});
        Rectangle2D textBounds = missingGlyphVector.getLogicalBounds();

        Rectangle2D maxCharBounds = font.getMaxCharBounds(FONT_RENDER_CONTEXT);
        averageCharacterSize = new Dimensions((int)Math.ceil(textBounds.getWidth()),
            (int)Math.ceil(maxCharBounds.getHeight()));
View Full Code Here

            float ascent = lm.getAscent();

            float y = 0;

            for (int i = 0, n = glyphVectors.getLength(); i < n; i++) {
                GlyphVector glyphVector = glyphVectors.get(i);

                Rectangle2D textBounds = glyphVector.getLogicalBounds();
                float lineWidth = (float)textBounds.getWidth();

                float x = 0;
                switch(alignment) {
                    case LEFT: {
                        x = 0;
                        break;
                    }

                    case RIGHT: {
                        x = width - lineWidth;
                        break;
                    }

                    case CENTER: {
                        x = (width - lineWidth) / 2;
                        break;
                    }
                }

                if (fill != null) {
                    graphics.setFont(font);
                    graphics.setPaint(fill);
                    graphics.drawGlyphVector(glyphVector, x, y + ascent);
                }

                // TODO Would caching the outlines help optimize this method, or are they
                // already cached by the glyph vector itself?
                if (stroke != null
                    && strokeThickness > 0) {
                    java.awt.Shape outline = glyphVector.getOutline();

                    graphics.setPaint(stroke);
                    graphics.setStroke(new BasicStroke(strokeThickness));

                    graphics.translate(x, y + ascent);
View Full Code Here

                    || text.length() == 0) {
                    width = 0;
                    height = 0;
                } else {
                    // Create a single glyph vector representing the entire string
                    GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, text);
                    glyphVectors.add(glyphVector);

                    Rectangle2D textBounds = glyphVector.getLogicalBounds();
                    width = (int)Math.ceil(textBounds.getWidth());
                    height = (int)Math.ceil(textBounds.getHeight());
                }
            } else {
                float textWidth = 0;
                float textHeight = 0;

                int n = text.length();
                if (n > 0) {
                    float lineWidth = 0;
                    int lastWhitespaceIndex = -1;

                    int start = 0;
                    int i = 0;
                    while (i < n) {
                        char c = text.charAt(i);
                        if (Character.isWhitespace(c)) {
                            lastWhitespaceIndex = i;
                        }

                        Rectangle2D characterBounds = font.getStringBounds(text, i, i + 1,
                            FONT_RENDER_CONTEXT);
                        lineWidth += characterBounds.getWidth();

                        if (lineWidth > this.width
                            && lastWhitespaceIndex != -1) {
                            i = lastWhitespaceIndex;

                            lineWidth = 0;
                            lastWhitespaceIndex = -1;

                            // Append the current line
                            if ((i - 1) - start > 0) {
                                StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                                GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                                glyphVectors.add(glyphVector);

                                Rectangle2D textBounds = glyphVector.getLogicalBounds();
                                textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
                                textHeight += textBounds.getHeight();
                            }

                            start = i + 1;
                        }

                        i++;
                    }

                    // Append the final line
                    if ((i - 1) - start > 0) {
                        StringCharacterIterator line = new StringCharacterIterator(text, start, i, start);
                        GlyphVector glyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, line);
                        glyphVectors.add(glyphVector);

                        Rectangle2D textBounds = glyphVector.getLogicalBounds();
                        textWidth = (float)Math.max(textBounds.getWidth(), textWidth);
                        textHeight += textBounds.getHeight();
                    }

                    width = (int)Math.ceil(textWidth);
View Full Code Here

   * @param y position of the table header baseline
   * @throws FontFormatException
   * @throws IOException
   */
  private void drawTableHeader(Graphics2D g2d,final int y) throws FontFormatException, IOException{
    GlyphVector gv = opPainter.createGlyphVector(g2d, "Ware", 19); // TODO externalize
    int x = positions.xWare-(int)Math.rint(gv.getVisualBounds().getWidth());
    g2d.drawGlyphVector(gv, x, y);
    String columnTitle = "Stock";
    gv = opPainter.createGlyphVector(g2d, columnTitle, 19);
    g2d.drawGlyphVector(gv, positions.xCity, y);
    gv = opPainter.createGlyphVector(g2d, "from City", 19);
View Full Code Here

  protected BufferedImage initBackgroundImage(IImageLoader loader,Point topLeft) {
    BufferedImage bg = super.initBackgroundImage(loader,topLeft);
    Graphics2D g2d = bg.createGraphics();
    g2d.setColor(Color.BLACK);
    try {
      GlyphVector gv = opPainter.createGlyphVector(g2d, "Wares in stock", 24); // TODO externalize
      double titleHeight = gv.getVisualBounds().getHeight();
      int length = (int) Math.rint(gv.getVisualBounds().getWidth());
      int x = ((bg.getWidth()-getInset().left-getInset().right)-length)/2;
      int y = getInset().top+10+(int)Math.rint(titleHeight*2/3);
      g2d.drawGlyphVector(gv, x, y);
      // Dynamic row
      y += titleHeight;
      y += (int)Math.rint(titleHeight*2/3);
     
      BufferedImage waxSeal = loader.getImage("waxseal");
      int leftBorderX = topLeft.x+getInset().left;
      int xWare = leftBorderX+100; // right aligned
      int xCity = leftBorderX+110;
      int xBuy = leftBorderX+200; // size of the image + 10
      int xSell = leftBorderX+280;// size of the image + 10
      int yLineDiff = waxSeal.getHeight();
      // Initialize the position relative to the frame
      positions = new DialogPositions(titleHeight, yLineDiff, leftBorderX, xWare, xCity, xBuy, xSell);
     
      leftBorderX = getInset().left; // Use local coordinates
      xWare = leftBorderX+100; // right aligned
     
      // table header
      y += positions.lineHeight; // more space to the title
      y += positions.lineHeight;
     
      // Table
      EWare[] wares = EWare.values();
      for (EWare ware : wares) {
        // Ware name
        y += positions.lineHeight;
        gv = opPainter.createGlyphVector(g2d, ware.getLocalDisplayName(), 18);
        x = xWare-(int)Math.rint(gv.getVisualBounds().getWidth());
        g2d.drawGlyphVector(gv, x, y);
        // Amount available
       
        // from city
       
        // to city
      }
      // Footer buttons
      y = bg.getHeight()-getInset().bottom-positions.lineHeight;
      x = getInset().left+30;
      int footerWidth = bg.getWidth()-getInset().left-getInset().right-2*30;
      x += 3*footerWidth/4;
      // close
      g2d.drawImage(waxSeal, x,y-(int)(positions.lineHeight*0.8), null);
      NamedPolygon polygon = new NamedPolygon("Close");
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8));
      polygon.addPoint(topLeft.x+x+waxSeal.getWidth(), topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      polygon.addPoint(topLeft.x+x, topLeft.y+y-(int)(positions.lineHeight*0.8)+waxSeal.getHeight());
      footerPolygons.add(polygon, new CloseAction(this));
      g2d.setColor(new Color(0xEA,0xC1,0x17)); // Gold
      gv = opPainter.createGlyphVector(g2d, "X", 18);
      int xPadding = imageUtils.computeCenterAlignX(x, waxSeal.getWidth(), (int)gv.getVisualBounds().getWidth());
      g2d.drawGlyphVector(gv, xPadding, y); // centeralign


    } catch (FontFormatException e1) {
      e1.printStackTrace();
View Full Code Here

  private int drawAvailableAmount(Graphics2D g2d, ICity city,IWare ware,BufferedImage barrel, BufferedImage bale,int y) throws FontFormatException, IOException{
    AmountablePrice available = city.getWare(ware);
    int availableAmount = available.getAmount();
    int value = availableAmount; // amount available
    if (value>0){
      GlyphVector gv = opPainter.createGlyphVector(g2d, String.valueOf(value), 18);
      g2d.drawGlyphVector(gv, positions.xCity, y);
      // draw barrel or burden
      if (ware.getSizeAsBarrels()==1){
        // barrel
        g2d.drawImage(barrel, (int)(positions.xCity+gv.getVisualBounds().getWidth())+5, y-positions.lineHeight*2/3, null);
      } else {
        g2d.drawImage(bale, (int)(positions.xCity+gv.getVisualBounds().getWidth())+5, y-positions.lineHeight*2/3, null);
      }
    }
    return availableAmount;

  }
View Full Code Here

TOP

Related Classes of java.awt.font.GlyphVector

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.