Examples of TextLayout


Examples of java.awt.font.TextLayout

    return null;
  }


  private IPoint getTextPositionText() {
    final TextLayout tl = new TextLayout(shape.getText(), FONT, FONT_METRICS.getFontRenderContext());
    final Rectangle2D bounds = tl.getBounds();

    switch(shape.getTextPosition()) {
      case BOT : return ShapeFactory.createPoint(shape.getX()-bounds.getWidth()/2., shape.getY());
      case TOP : return ShapeFactory.createPoint(shape.getX()-bounds.getWidth()/2., shape.getY()+bounds.getHeight());
      case BOT_LEFT : return ShapeFactory.createPoint(shape.getX(), shape.getY());
View Full Code Here

Examples of java.awt.font.TextLayout

    final double tly;
    final double widthBorder;
    final double heightBorder;

    if(image==null) {
      final TextLayout tl = new TextLayout(shape.getText(), FONT, FONT_METRICS.getFontRenderContext());
      final Rectangle2D bounds = tl.getBounds();
      tlx = position.getX();
      tly = position.getY()-bounds.getHeight()+tl.getDescent();
      widthBorder = tl.getAdvance();
      heightBorder = bounds.getHeight();
    }
    else {
      final double scale = FlyweightThumbnail.scaleImage();
      tlx = position.getX();
      tly = position.getY();
      widthBorder = image.getWidth(null)*(1/scale);
      heightBorder = image.getHeight(null)*(1/scale);
    }

    if(LNumber.equalsDouble(angle, 0.))
      border.setFrame(tlx, tly, widthBorder, heightBorder);
    else {
      final IPoint tl = ShapeFactory.createPoint();
      final IPoint br = ShapeFactory.createPoint();
      getRotatedRectangle(tlx, tly, widthBorder, heightBorder, angle, shape.getGravityCentre(), tl, br);
      // The border of the rotated rectangle is now the border of the rectangular view.
      border.setFrameFromDiagonal(tl.getX(), tl.getY(), br.getX(), br.getY());
    }
  }
View Full Code Here

Examples of java.awt.font.TextLayout

                angle, rotateX, rotateY);
        g2.transform(rotate);

        if (useDrawRotatedStringWorkaround) {
            // workaround for JDC bug ID 4312117 and others...
            final TextLayout tl = new TextLayout(text, g2.getFont(),
                    g2.getFontRenderContext());
            tl.draw(g2, textX, textY);
        }
        else {
            AttributedString as = new AttributedString(text,
                    g2.getFont().getAttributes());
          g2.drawString(as.getIterator(), textX, textY);
View Full Code Here

Examples of java.awt.font.TextLayout

      AttributedCharacterIterator textIterator = attributedText.getIterator();
      FontRenderContext fontRendering = g.getFontRenderContext();
      LineBreakMeasurer measurer = new LineBreakMeasurer(textIterator, fontRendering);
      WrappedLines lines = new WrappedLines();
      while(measurer.getPosition() < textIterator.getEndIndex()) {
        TextLayout layout = measurer.nextLayout(maxWidth);
        lines.add(layout);
      }
      return lines;
    }
View Full Code Here

Examples of java.awt.font.TextLayout

    try {
      graphics.setFont(font);
      graphics.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON);
     
      FontRenderContext context = graphics.getFontRenderContext();
      TextLayout layout = new TextLayout(text, font, context);
      int x = width / 2 - (int) (layout.getAdvance() / 2f);
      int y = height / 2 + (int) (layout.getAscent() / 2f) - 1;
     
      graphics.setColor(Color.DARK_GRAY.darker());
      graphics.drawString(text, x-1, y-1);
      graphics.setColor(Color.WHITE);
      graphics.drawString(text, x, y);
View Full Code Here

Examples of java.awt.font.TextLayout

    ctx.drawString(label, (int) x,
        (int) y + ctx.getFontMetrics().getMaxAscent());
    if (DEBUG && label != null && !"".equals(label.trim())) {
      ctx.setPaint(Color.RED);

      TextLayout tl = new TextLayout(label, font, ctx.getFontRenderContext());
      Rectangle2D b = tl.getBounds();
      int h = (int) (tl.getAscent() + tl.getDescent() + tl.getLeading());
      ctx.drawRect((int) x, (int) y, (int) b.getWidth(), h);
    }
//    System.out.println("Drawing text " + label + " at " + x + ", "
//        + (y + ctx.getFontMetrics().getMaxAscent()) + " y=" + y + ", maxAscent="
//        + ctx.getFontMetrics().getMaxAscent() + " leading is " + ctx
View Full Code Here

Examples of java.awt.font.TextLayout

    ctx.setFont(new Font(font, Font.PLAIN,
        Integer.parseInt(size.substring(0, size.length() - 2))));
    FontMetrics fm = ctx.getFontMetrics();
    Font f = ctx.getFont();
    TextLayout tl = new TextLayout(string, f, ctx.getFontRenderContext());
    Rectangle2D b = tl.getBounds();
    int h = (int) (tl.getAscent() + tl.getDescent() + tl.getLeading());
    // b.getHeight();//(int) fm.getMaxAscent() + fm.getMaxDescent() + 2;
//    System.out.println("height of " + string + " is " + h + "  vs " + fm
//        .getStringBounds(string, ctx));
    return h;
//        .getHeight();
View Full Code Here

Examples of java.awt.font.TextLayout

        getG2D().setStroke(new BasicStroke(width));
    }

    public float getStringPixelWidth(Font font, String s) {
        getG2D().setFont(font);
        TextLayout layout = new TextLayout(s, getG2D().getFont(), getG2D().getFontRenderContext());
        return (float)layout.getBounds().getWidth();
    }
View Full Code Here

Examples of java.awt.font.TextLayout

        getG2D().fillPolygon(x, y, 3);
    }

    public void drawString(Font font, String s, float x, float y, int align) {
        getG2D().setFont(font);
        TextLayout layout = new TextLayout(s, font, getG2D().getFontRenderContext());
        float tx = Float.MIN_VALUE;
        float ty = Float.MIN_VALUE;
        switch(align) {
            case GContext.ALIGN_CENTER:
                tx = (float)(x-layout.getBounds().getWidth()*0.5);
                ty = (float)(y+layout.getBounds().getHeight()*0.5);
                break;
            case GContext.ALIGN_CENTER_UP:
                tx = (float)(x-layout.getBounds().getWidth()*0.5);
                ty = y;
                break;
            case GContext.ALIGN_RIGHT:
                tx = (float)(x-layout.getBounds().getWidth());
                ty = (float)(y+layout.getBounds().getHeight()*0.5);
                break;
            case GContext.ALIGN_LEFT:
                tx = x;
                ty = (float)(y+layout.getBounds().getHeight()*0.5);
                break;
        }
        layout.draw(getG2D(), tx, ty-1);
    }
View Full Code Here

Examples of java.awt.font.TextLayout

        int size = tipsModel.size();
        if(size > 0) {
            int width = 0;
            for(int i=0; i<tipsModel.size(); i++) {
                String e = (String)tipsModel.getElementAt(i);
                TextLayout layout = new TextLayout(e, tipsList.getFont(), ((Graphics2D)tipsList.getGraphics()).getFontRenderContext());
                width = Math.max(width, (int)layout.getBounds().getWidth());
            }
            height = height*Math.min(VISIBLE_TIPS, size)+5;
            Dimension d = new Dimension(width+10, height);
            setSize(d);
            tipsList.setSize(d);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.