Package java.awt.font

Examples of java.awt.font.LineBreakMeasurer


            AttributedString attributedText = new AttributedString(text);
            attributedText.addAttribute(TextAttribute.FONT, font);

            AttributedCharacterIterator aci = attributedText.getIterator();
            LineBreakMeasurer lbm = new LineBreakMeasurer(aci, fontRenderContext);

            float lineHeights = 0;
            while (lbm.getPosition() < aci.getEndIndex()) {
                int offset = lbm.nextOffset(contentWidth);

                LineMetrics lm = font.getLineMetrics(aci,
                    lbm.getPosition(), offset, fontRenderContext);

                float lineHeight = lm.getAscent() + lm.getDescent()
                    + lm.getLeading();
                lineHeights += lineHeight;

                lbm.setPosition(offset);
            }

            preferredHeight = (int)Math.ceil(lineHeights);
        } else {
            LineMetrics lm = font.getLineMetrics(text, fontRenderContext);
View Full Code Here


            if (wrapText) {
                AttributedString attributedText = new AttributedString(text);
                attributedText.addAttribute(TextAttribute.FONT, font);

                AttributedCharacterIterator aci = attributedText.getIterator();
                LineBreakMeasurer lbm = new LineBreakMeasurer(aci, fontRenderContext);

                int contentWidth = width - (padding.left + padding.right);

                while (lbm.getPosition() < aci.getEndIndex()) {
                    TextLayout textLayout = lbm.nextLayout(contentWidth);
                    y += textLayout.getAscent();
                    drawText(graphics, textLayout, y);
                    y += textLayout.getDescent() + textLayout.getLeading();
                }
            } else {
View Full Code Here

 
  private void wrapTextIntoLabel(JLabel lbl, String text, int width) {
    AttributedString astr = new AttributedString(text);
    astr.addAttribute(TextAttribute.FONT, lbl.getFont());
    FontRenderContext frc = lbl.getFontMetrics(lbl.getFont()).getFontRenderContext();
    LineBreakMeasurer lbm = new LineBreakMeasurer(astr.getIterator(), frc);
    Vector<String> lines = new Vector<String>();
    int prevOffs = 0;
    int offs = lbm.nextOffset(width, text.length(), false);
    do {
      lines.add(text.substring(prevOffs, offs));
      lbm.setPosition(offs);
      prevOffs = offs;
      offs = lbm.nextOffset(width, text.length(), false);
    } while(offs > prevOffs);
   
    StringBuilder output = new StringBuilder();
    output.append("<html><center>");
    for(int i = 0; i < lines.size(); i++) {
View Full Code Here

      cur = min + ((max - min) / 2);
      Font font = getFont().deriveFont((float)cur);
      AttributedString attrstr = new AttributedString(text);
      attrstr.addAttribute(TextAttribute.FONT, font);
      FontRenderContext frc = g.getFontRenderContext();
      LineBreakMeasurer lbm = new LineBreakMeasurer(attrstr.getIterator(), frc);
      layouts.clear();
      int pos = lbm.getPosition();
      int linebreak = text.indexOf("\n", pos);
      TextLayout tl = lbm.nextLayout((float)dispArea.getWidth(), (linebreak == -1 ? text.length() : linebreak + 1), false);
      do {
        layouts.add(tl);
        pos = lbm.getPosition();
        linebreak = text.indexOf("\n", pos);
        tl = lbm.nextLayout((float)dispArea.getWidth(), (linebreak == -1 ? text.length() : linebreak + 1), false);
      } while(tl != null);
      metrics = g.getFontMetrics(font);
      int h = metrics.getHeight() * layouts.size();
     
      if(h < dispArea.getHeight()) {
View Full Code Here

    if (text != null && text.length() > 0) {
      AttributedString atString = new AttributedString(text);
      atString.addAttribute(TextAttribute.FONT, getFont());
      AttributedCharacterIterator itr = atString.getIterator();
      LineBreakMeasurer measurer = new LineBreakMeasurer(itr,
          PPaintContext.RENDER_QUALITY_HIGH_FRC);
      float availableWidth = constrainWidthToTextWidth ? Float.MAX_VALUE
          : (float) getWidth();

      int nextLineBreakOffset = text.indexOf('\n');
      if (nextLineBreakOffset == -1) {
        nextLineBreakOffset = Integer.MAX_VALUE;
      } else {
        nextLineBreakOffset++;
      }

      while (measurer.getPosition() < itr.getEndIndex()) {
        TextLayout aTextLayout = computeNextLayout(measurer,
            availableWidth, nextLineBreakOffset);

        if (nextLineBreakOffset == measurer.getPosition()) {
          nextLineBreakOffset = text.indexOf('\n', measurer
              .getPosition());
          if (nextLineBreakOffset == -1) {
            nextLineBreakOffset = Integer.MAX_VALUE;
          } else {
            nextLineBreakOffset++;
View Full Code Here

            textParts = text.split("\n");
            measurers = new LineBreakMeasurer[textParts.length];
            FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
            for (int i = 0; i < textParts.length; i++) {
                AttributedString s = getStyledText(textParts[i]);
                measurers[i] = new LineBreakMeasurer(s.getIterator(), frc);
            }
            currentMeasurer = measurers[currentIndex];
            currentText = textParts[currentIndex];
            first = true;
        }
View Full Code Here

            if ("".equals(line)) {
                cursor.y += lineHeight;
            } else {
                AttributedString styledText = new AttributedString(line);
                LineBreakMeasurer measurer = new LineBreakMeasurer(styledText.getIterator(), frc);

                while (measurer.getPosition() < line.length()) {

                    TextLayout layout = measurer.nextLayout(lineWidth - startX);

                    cursor.y += (layout.getAscent());
                    float dx = layout.isLeftToRight() ? 0 : (lineWidth - layout.getAdvance());

                    layout.draw(g, cursor.x + dx, cursor.y);
View Full Code Here

            if (wrapText) {
                AttributedString attributedText = new AttributedString(text);
                attributedText.addAttribute(TextAttribute.FONT, font);

                AttributedCharacterIterator aci = attributedText.getIterator();
                LineBreakMeasurer lbm = new LineBreakMeasurer(aci, fontRenderContext);

                int contentWidth = width - (padding.left + padding.right);

                while (lbm.getPosition() < aci.getEndIndex()) {
                    TextLayout textLayout = lbm.nextLayout(contentWidth);
                    y += textLayout.getAscent();
                    drawText(graphics, textLayout, y);
                    y += textLayout.getDescent() + textLayout.getLeading();
                }
            } else {
View Full Code Here

                AttributedString attributedText = new AttributedString(text);
                attributedText.addAttribute(TextAttribute.FONT, font);

                AttributedCharacterIterator aci = attributedText.getIterator();
                LineBreakMeasurer lbm = new LineBreakMeasurer(aci, fontRenderContext);

                float lineHeights = 0;
                while (lbm.getPosition() < aci.getEndIndex()) {
                    TextLayout line = lbm.nextLayout(width);
                    lines.add(line);
                    lineHeights += line.getAscent() + line.getDescent()
                        + line.getLeading();
                }
View Full Code Here

            if ("".equals(line)) {
                cursor.y += lineHeight;
            } else {
                AttributedString styledText = new AttributedString(line);
                LineBreakMeasurer measurer = new LineBreakMeasurer(styledText.getIterator(), frc);

                while (measurer.getPosition() < line.length()) {

                    TextLayout layout = measurer.nextLayout(lineWidth - startX);

                    cursor.y += (layout.getAscent());
                    float dx = layout.isLeftToRight() ? 0 : (lineWidth - layout.getAdvance());

                    layout.draw(g, cursor.x + dx, cursor.y);
View Full Code Here

TOP

Related Classes of java.awt.font.LineBreakMeasurer

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.