Package java.awt.font

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


    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

                    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

        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

        }
       
        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

      //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

   * @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

       
        if (xmin <= 0 && xmax > 0) {
    xmin = Math.abs(xmin);
    xmax = Math.abs(xmax);
   
    TextLayout layout = new TextLayout(c.getYAxisUnit(), c.getFont(),
               c.getFontRenderContext());
       
    // yaxis label width
    int maxlmargin = computeYAxisLabelWidth() + marginOffset; // + yaxis title width
       
    // unit width
    maxlmargin = Math.max(maxlmargin, (int) layout.getBounds().getWidth() + marginOffset);
       
       
    int margin = (int)(maxlmargin - (xmin / (xmin + xmax)) * (c.getBounds().getWidth() - c.getRightMargin()));
       
    margin += 5; // just for good looking
View Full Code Here

  }
    }
   
    /** Computes the right margin. */
    public int computeRightMargin() {
  TextLayout layout = new TextLayout(c.getXAxisUnit(), c.getFont(),
              c.getFontRenderContext());
  return Math.max((int)(layout.getBounds().getWidth() + (double)c.ARROWLENGTH / 3) , c.ARROWLENGTH);
    }
View Full Code Here

  return Math.max((int)(layout.getBounds().getWidth() + (double)c.ARROWLENGTH / 3) , c.ARROWLENGTH);
    }
   
    /** Computes the top margin. */
    public int computeTopMargin() {
  TextLayout layout = new TextLayout(c.getYAxisUnit(), c.getFont(),
             c.getFontRenderContext());
  return Math.max((int)(layout.getBounds().getHeight() + (double)c.ARROWLENGTH / 3 + layout.getDescent()), c.ARROWLENGTH);
    }
View Full Code Here

TOP

Related Classes of java.awt.font.TextLayout

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.