Examples of TextLayout


Examples of ae.java.awt.font.TextLayout

        if (font.hasLayoutAttributes()) {
            if (str.length() == 0) {
                return;
            }
            new TextLayout(str, font, getFontRenderContext()).draw(this, x, y);
            return;
        }

        try {
            textpipe.drawString(this, str, x, y);
View Full Code Here

Examples of com.google.code.appengine.awt.font.TextLayout

        // TextLayout draws the iterator as glyph vector
        // thats why we use it only in the case of TEXT_AS_SHAPES,
        // otherwise tagged strings are always written as glyphs
        if (isProperty(TEXT_AS_SHAPES)) {
            // draws all attributes
            TextLayout tl = new TextLayout(iterator, getFontRenderContext());
            tl.draw(this, x, y);
        } else {
            // reset to that font at the end
            Font font = getFont();

            // initial attributes, we us TextAttribute.equals() rather
            // than Font.equals() because using Font.equals() we do
            // not get a 'false' if underline etc. is changed
            Map/*<TextAttribute, ?>*/ attributes = FontUtilities.getAttributes(font);

            // stores all characters which are written with the same font
            // if font is changed the buffer will be written and cleared
            // after it
            StringBuffer sb = new StringBuffer();

            for (char c = iterator.first();
                 c != AttributedCharacterIterator.DONE;
                 c = iterator.next()) {

                // append c if font is not changed
                if (attributes.equals(iterator.getAttributes())) {
                    sb.append(c);

                } else {
                    // TextLayout does not like 0 length strings
                    if (sb.length() > 0) {
                        // draw sb if font is changed
                        drawString(sb.toString(), x, y);
   
                        // change the x offset for the next drawing
                        // FIXME: change y offset for vertical text
                        TextLayout tl = new TextLayout(
                            sb.toString(),
                            attributes,
                            getFontRenderContext());
   
                        // calculate real width
                        x = x + Math.max(
                            tl.getAdvance(),
                            (float)tl.getBounds().getWidth());
                    }
                   
                    // empty sb
                    sb = new StringBuffer();
                    sb.append(c);
View Full Code Here

Examples of com.sun.javafx.scene.text.TextLayout

        // workaround for https://javafx-jira.kenai.com/browse/RT-37801
        if(paragraph.length() == 0) {
            return Optional.empty();
        }

        TextLayout textLayout = textLayout();
        HitInfo hit = textLayout.getHitInfo((float)x, (float)y);

        if(hit.getCharIndex() == paragraph.length() - 1) {
            // Might be a hit beyond the end of line, investigate.
            // Workaround for https://javafx-jira.kenai.com/browse/RT-37803
            PathElement[] elems = textLayout.getCaretShape(paragraph.length(), true, 0, 0);
            Path caret = new Path(elems);
            if(x > caret.getBoundsInLocal().getMinX()) {
                return Optional.empty();
            } else {
                return Optional.of(hit);
View Full Code Here

Examples of java.awt.font.TextLayout

        ArrayList<TextLayout> layoutList = new ArrayList<TextLayout>();
        if (str.length() > 0 && wrapWidth > 5) {
            // expensive methode, because if wrapWidth is too small => layoutList could be very large!!

            String lines[] = str.split("\\n");
            TextLayout layout;
            for (String text : lines) {
                final AttributedString attStr = new AttributedString(text);
                //attStr.addAttribute(TextAttribute.FONT, new Font ("TimesRoman", Font.PLAIN, 12));
               
                final LineBreakMeasurer measurer =
View Full Code Here

Examples of java.awt.font.TextLayout

    descent = fm.getDescent();
    int[] xs = new int[s.length()];
    int[] ys = new int[s.length()];
    for (int i = 0; i < xs.length; i++) {
      xs[i] = fm.stringWidth(s.substring(0, i + 1));
      TextLayout lay = new TextLayout(s.substring(i, i + 1), font, frc);
      Rectangle2D rect = lay.getBounds();
      int asc = (int) Math.ceil(-rect.getMinY());
      int desc = (int) Math.ceil(rect.getMaxY());
      if (asc < 0) asc = 0;
      if (asc > 0xFFFF) asc = 0xFFFF;
      if (desc < 0) desc = 0;
View Full Code Here

Examples of java.awt.font.TextLayout

                    maxY = bounds.getMaxY();
            }
           
            if (text != null && text.length() > 0) {
                FontRenderContext context = g2.getFontRenderContext();
                TextLayout layout = new TextLayout(text, getFont(), context);
                Rectangle2D bounds = layout.getBounds();
                g2.setColor(getForeground());
                layout.draw(g2, (float) (width - bounds.getWidth()) / 2,
                        (float) (maxY + layout.getLeading() + 2 * layout.getAscent()));
            }
        }
    }
View Full Code Here

Examples of java.awt.font.TextLayout

        g2.drawRect(shape.getBounds().x, shape.getBounds().y, CIRCLE_SIZE, CIRCLE_SIZE);
       
        g2.setColor(Color.RED);
        g2.fillRect(shape.getBounds().x, shape.getBounds().y, CIRCLE_SIZE, CIRCLE_SIZE);
        g2.setColor(Color.WHITE);
        new TextLayout(new Integer(i).toString(), g2.getFont(), g2.getFontRenderContext()).draw(g2, shape.getBounds().x+4, shape.getBounds().y+ (CIRCLE_SIZE-4));
      }
    }
   
    ImageIO.write(bi,resources.getString("imageFileExtension"),_imageFile);
    _htmlFile = new File(resources.getString("htmlFileName")).getCanonicalFile();
View Full Code Here

Examples of java.awt.font.TextLayout

        }
       
        double lRotation;
        double lX;
        double lY;
        TextLayout lLabel;

    // draw the lines
    for (int lCol = 0; lCol < lNumberOfColumns; lCol++)
    {
      // determine rotation: there are 2PI/noOfCols vertexes, this is vertex no lCol   
      // -1 : we want to rotate clockwise
      // + PI: rotate 180 degree to get the first column pointing up
            // Math.PI ... - Math.PI
      lRotation = (-1 * (2 * Math.PI / lNumberOfColumns) * lCol) + Math.PI;

      // determine the end points
      lX = center_x + (lRadius * Math.sin(lRotation));
      lY = center_y + (lRadius * Math.cos(lRotation));

      // draw the line
      Line2D lLine = new Line2D.Double(center_x, center_y, lX, lY );
          g.setColor(Color.black);
          g.draw(lLine);

          // draw the label
          lLabel = new TextLayout("" + model.getColumnValueAt(lCol), new Font("Courier", Font.BOLD, 9), new FontRenderContext(null, true, false));
          g.setColor(Color.black);
           
            // Move the labels in the lower half circle down a bit, so the upper left corner touches the axis
            if ((lRotation <= Math.PI / 2) && (lRotation >= -Math.PI / 2))
                lY += lLabel.getBounds().getHeight();
           
            // Move the labels in the left half circle a bit left, so the upper right corner touches the axis
            if (lRotation <= 0)
                lX -= lLabel.getBounds().getWidth();
           
      lLabel.draw(g, (float)lX,  (float)lY);
    }

    // reset rendering hint       
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rh);
    }   
View Full Code Here

Examples of java.awt.font.TextLayout

      //float availableWidth = formatWidth - ParagraphUtil.getSegmentOffset(nextTabStopHolder[0], rightX); // nextTabStop can be null here; and that's OK
      float availableWidth = endX - textElement.getParagraph().getLeftIndent() - ParagraphUtil.getSegmentOffset(nextTabStopHolder[0], rightX); // nextTabStop can be null here; and that's OK
     
      // creating a text layout object for each tab segment
      TextLayout layout =
        lineMeasurer.nextLayout(
          availableWidth,
          tabIndexOrEndIndex,
          requireNextWordHolder[0]
          );
     
      if (layout != null)
      {
        maxAscent = Math.max(maxAscent, layout.getAscent());
        maxDescent = Math.max(maxDescent, layout.getDescent());
        maxLeading = Math.max(maxLeading, layout.getLeading());
        characterCount += layout.getCharacterCount();
        isLeftToRight = isLeftToRight && layout.isLeftToRight();

        //creating the current segment
        crtSegment = new TabSegment();
        crtSegment.layout = layout;

        int leftX = ParagraphUtil.getLeftX(nextTabStopHolder[0], layout.getAdvance()); // nextTabStop can be null here; and that's OK
        if (rightX > leftX)
        {
          crtSegment.leftX = rightX;
          crtSegment.rightX = (int)(rightX + layout.getAdvance());//FIXMETAB some rounding issues here
        }
        else
        {
          crtSegment.leftX = leftX;
          // we need this special tab stop based utility call because adding the advance to leftX causes rounding issues
          crtSegment.rightX = ParagraphUtil.getRightX(nextTabStopHolder[0], layout.getAdvance()); // nextTabStop can be null here; and that's OK
        }

        segments.add(crtSegment);
      }
     
      requireNextWordHolder[0] = true;

      if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
      {
        // the segment limit was a tab; going to the next tab
        currentTabHolder[0] = currentTabHolder[0] + 1;
      }
     
      if (lineMeasurer.getPosition() == paragraph.getEndIndex())
      {
        // the segment limit was the paragraph end; line completed and next line should start at normal zero x offset
        lineComplete = true;
        nextTabStopHolder[0] = null;
      }
      else
      {
        // there is paragraph text remaining
        if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
        {
          // the segment limit was a tab
          if (crtSegment.rightX >= ParagraphUtil.getLastTabStop(jrParagraph, endX).getPosition())
          {
            // current segment stretches out beyond the last tab stop; line complete
            lineComplete = true;
            // next line should should start at first tab stop indent
            nextTabStopHolder[0] = ParagraphUtil.getFirstTabStop(jrParagraph, endX);
          }
          else
          {
            //nothing; this leaves lineComplete=false
          }
        }
        else
        {
          // the segment did not fit entirely
          lineComplete = true;
          if (layout == null)
          {
            // nothing fitted; next line should start at first tab stop indent
            if (nextTabStopHolder[0].getPosition() == ParagraphUtil.getFirstTabStop(jrParagraph, endX).getPosition())//FIXMETAB check based on segments.size()
            {
              // at second attempt we give up to avoid infinite loop
              nextTabStopHolder[0] = null;
              requireNextWordHolder[0] = false;
             
              //provide dummy maxFontSize because it is used for the line height of this empty line when attempting drawing below
               AttributedString tmpText =
                new AttributedString(
                  paragraph,
                  startIndex,
                  startIndex + 1
                  );
               LineBreakMeasurer lbm = new LineBreakMeasurer(tmpText.getIterator(), getFontRenderContext());
               TextLayout tlyt = lbm.nextLayout(100);
              maxAscent = tlyt.getAscent();
              maxDescent = tlyt.getDescent();
              maxLeading = tlyt.getLeading();
            }
            else
            {
              nextTabStopHolder[0] = ParagraphUtil.getFirstTabStop(jrParagraph, endX);
            }
View Full Code Here

Examples of java.awt.font.TextLayout

   * @param size
   * @param color
   */
  private void drawText(Graphics2D gr, String text, int size, Color color, int iconSize) {
    int max = iconSize - 1;
    TextLayout tl = new TextLayout(text, gr.getFont(), gr.getFontRenderContext());
    gr.setColor(TEXTBACKGROUND);
    gr.setStroke(new BasicStroke());
    Rectangle2D b = tl.getBounds();
    b = new Rectangle2D.Double(0, max, b.getWidth() + 1, b.getHeight() + 1);
    gr.fill(b);
    gr.setColor(color);
    gr.setFont(new Font("SansSerif", Font.PLAIN, size));
    gr.drawString(text, 1, max);
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.