Examples of LineBreakMeasurer


Examples of java.awt.font.LineBreakMeasurer

        MTextIterator iter = new MTextIterator(fText,
                                               fFontResolver,
                                               paragraphStart,
                                               paragraphLimit);
        LineBreakMeasurer measurer = new LineBreakMeasurer(iter, fFontRenderContext);
        if (fgCacheMeasurers) {
            fCachedMeasurerStart = paragraphStart;
            fCachedMeasurerLimit = paragraphLimit;
            fCachedMeasurer = measurer;
        }
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

        int curParagraphLimit = Integer.MIN_VALUE; // dummy value

        int damageStart = curGraphicStart;

        ParagraphRenderer renderer = null;
        LineBreakMeasurer measurer = null;
       
        // try to use cached LineBreakMeasurer if possible
        if (fCachedMeasurer != null &&
            curParagraphStart == fCachedMeasurerStart) {

            curParagraphLimit = fText.paragraphLimit(curParagraphStart);
           
            try {
                if (newCurTextLen - fLTCurTextLen == 1 && afLength == 1) {
                    if (curParagraphLimit == fCachedMeasurerLimit+1) {
                        MTextIterator iter = new MTextIterator(fText,
                                                               fFontResolver,
                                                               curParagraphStart,
                                                               curParagraphLimit);
                        fCachedMeasurer.insertChar(iter, afStart);
                        fCachedMeasurerLimit += 1;
                        measurer = fCachedMeasurer;
                    }
                }
                else if (fLTCurTextLen - newCurTextLen == 1 && afLength == 0) {
                    if (fCachedMeasurerLimit > fCachedMeasurerStart + 1 &&
                                curParagraphLimit == fCachedMeasurerLimit-1) {
                        MTextIterator iter = new MTextIterator(fText,
                                                               fFontResolver,
                                                               curParagraphStart,
                                                               curParagraphLimit);
                        fCachedMeasurer.deleteChar(iter, afStart);
                        fCachedMeasurerLimit -= 1;
                        measurer = fCachedMeasurer;
                    }
                }
            }
            catch(ArrayIndexOutOfBoundsException e) {
                fCachedMeasurer = null;
                fgCacheMeasurers = false;
            }
           
            if (measurer != null) {
                // need to set up renderer since the paragraph update in the
                // formatting loop will not happen
                AttributeMap style = fText.paragraphStyleAt(curParagraphStart);
                renderer = getRendererFor(style);
                measurer.setPosition(curLineStart);
            }
        }
       
        if (measurer == null) {
            // trigger paragraph update at start of formatting loop
            curParagraphLimit = curParagraphStart;
            curParagraphStart = 0;
        }

        fLTCurTextLen = newCurTextLen;
       
        while (true) {
            // System.out.println("line: " + fLTPosEnd + ", cls: " + curLineStart);


            if (curLineStart >= curParagraphLimit) {
                curParagraphStart = curParagraphLimit;
                curParagraphLimit = fText.paragraphLimit(curParagraphStart);

                AttributeMap style = fText.paragraphStyleAt(curParagraphStart);
                renderer = getRendererFor(style);

                if (curParagraphStart < curParagraphLimit) {
                    measurer = makeMeasurer(curParagraphStart, curParagraphLimit);
                    measurer.setPosition(curLineStart);
                }
                else {
                    measurer = null;
                }
            }
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

                    lineBreakTLs = new Vector();
                    for ( int i = 0; i < fileText.length; i++ ) {
                        AttributedString as =
                          new AttributedString( fileText[i], g2.getFont().getAttributes() );

                        LineBreakMeasurer lbm =
                          new LineBreakMeasurer( as.getIterator(), g2.getFontRenderContext() );

                        while ( lbm.getPosition() < fileText[i].length() )
                          lineBreakTLs.add( lbm.nextLayout( (float) w ));

                    }
                }
                if ( !isPrinting )
                  resetScrollbar( verticalBar.getValue() );
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

        Rectangle2D anchor = _shape.getLogicalAnchor2D();

        float textHeight = 0;
        ArrayList lines = new ArrayList();
        LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext());
        measurer.setPosition(paragraphStart);
        while (measurer.getPosition() < paragraphEnd) {
            int startIndex = measurer.getPosition();
            int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);

            boolean prStart = text.charAt(startIndex) == '\n';
            if(prStart) measurer.setPosition(startIndex++);

            RichTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
            if(rt == null) {
                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
                break;
            }

            float wrappingWidth = (float)anchor.getWidth() - _shape.getMarginLeft() - _shape.getMarginRight();
            int bulletOffset = rt.getBulletOffset();
            int textOffset = rt.getTextOffset();
            int indent = rt.getIndentLevel();

            TextRulerAtom ruler = run.getTextRuler();
            if(ruler != null) {
                int bullet_val = ruler.getBulletOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
                int text_val = ruler.getTextOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
                if(bullet_val > text_val){
                    int a = bullet_val;
                    bullet_val = text_val;
                    text_val = a;
                }
                if(bullet_val != 0 ) bulletOffset = bullet_val;
                if(text_val != 0) textOffset = text_val;
            }

            wrappingWidth -= textOffset;

            if (_shape.getWordWrap() == TextShape.WrapNone) {
                wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
            }

            TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
                    nextBreak == -1 ? paragraphEnd : nextBreak, true);
            if (textLayout == null) {
                textLayout = measurer.nextLayout((float)anchor.getWidth(),
                    nextBreak == -1 ? paragraphEnd : nextBreak, false);
            }
            if(textLayout == null){
                logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
                        "; text: " + rt.getText());
                measurer.setPosition(rt.getEndIndex());
                continue;
            }
            int endIndex = measurer.getPosition();

            float lineHeight = (float)textLayout.getBounds().getHeight();
            int linespacing = rt.getLineSpacing();
            if(linespacing == 0) linespacing = 100;

View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

    AttributedString attributedString = new AttributedString(getText());
    attributedString.addAttribute(TextAttribute.FONT, getFont());
    AttributedCharacterIterator charIterator = attributedString.getIterator();
    FontRenderContext fontContext = g2d.getFontRenderContext();

    LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
    lineCount = 0;
    while (measurer.getPosition() < charIterator.getEndIndex()) {
      //TextLayout textLayout = measurer.nextLayout(wrapWidth);
      lineCount++;
      if (lineCount > 2) break;
    }
    charIterator.first();
    // Use char wrap if word wrap would cause more than two lines of text.
    if (lineCount > 2)
      measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
    else
      measurer.setPosition(0);
    while (measurer.getPosition() < charIterator.getEndIndex()) {
      TextLayout textLayout = measurer.nextLayout(wrapWidth);
      float ascent = textLayout.getAscent();
      textY += ascent; // Move down to baseline.

      g2d.setColor(glowColor);
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

        String text = getRenderableText();
        if(text.length() == 0) return _lines;

        AttributedString at = getAttributedString(graphics);
        AttributedCharacterIterator it = at.getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext())  ;
        for (;;) {
            int startIndex = measurer.getPosition();

            double wrappingWidth = getWrappingWidth(_lines.size() == 0, graphics) + 1; // add a pixel to compensate rounding errors
            // shape width can be smaller that the sum of insets (this was proved by a test file)
            if(wrappingWidth < 0) wrappingWidth = 1;

            int nextBreak = text.indexOf('\n', startIndex + 1);
            if(nextBreak == -1) nextBreak = it.getEndIndex();

            TextLayout layout = measurer.nextLayout((float)wrappingWidth, nextBreak, true);
            if (layout == null) {
                 // layout can be null if the entire word at the current position
                 // does not fit within the wrapping width. Try with requireNextWord=false.
                 layout = measurer.nextLayout((float)wrappingWidth, nextBreak, false);
            }

            if(layout == null) {
                // exit if can't break any more
                break;
            }

            int endIndex = measurer.getPosition();
            // skip over new line breaks (we paint 'clear' text runs not starting or ending with \n)
            if(endIndex < it.getEndIndex() && text.charAt(endIndex) == '\n'){
                measurer.setPosition(endIndex + 1);
            }

            TextAlign hAlign = getTextAlign();
            if(hAlign == TextAlign.JUSTIFY || hAlign == TextAlign.JUSTIFY_LOW) {
                layout = layout.getJustifiedLayout((float)wrappingWidth);
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

    int currentHeight = 0;
    // Prepare a list of lines of text we'll be drawing
    List<TextLayout> layouts = new ArrayList<TextLayout>();
    String lastLine = null;
   
    LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, g.getFontRenderContext());
   
    TextLayout layout = null;
    while (measurer.getPosition() < characterIterator.getEndIndex() && currentHeight <= boxHeight) {
      
      int previousPosition = measurer.getPosition();
     
      // Request next layout
      layout = measurer.nextLayout(boxWidth);
     
      int height = ((Float)(layout.getDescent() + layout.getAscent() + layout.getLeading())).intValue();
     
      if(currentHeight + height > boxHeight) {
        // The line we're about to add should NOT be added anymore, append three dots to previous one instead
        // to indicate more text is truncated
        if (layouts.size() > 0) {
          layouts.remove(layouts.size() - 1);
         
          if(lastLine.length() >= 4) {
            lastLine = lastLine.substring(0, lastLine.length() - 4) + "...";
          }
          layouts.add(new TextLayout(lastLine, g.getFont(), g.getFontRenderContext()));
        }
      } else {
        layouts.add(layout);
        lastLine = text.substring(previousPosition, measurer.getPosition());
        currentHeight += height;
      }
    }
   
   
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

      AttributedString as = new AttributedString(text);
      as.addAttribute(TextAttribute.FOREGROUND, g.getPaint());
      as.addAttribute(TextAttribute.FONT, g.getFont());
      AttributedCharacterIterator aci = as.getIterator();
      FontRenderContext frc = new FontRenderContext(null, true, false);
      LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
     
      while (lbm.getPosition() < text.length()) {
        TextLayout tl = lbm.nextLayout(wrapWidth);
        textY += tl.getAscent();
        Rectangle2D bb = tl.getBounds();
        int tX = (int) graphicInfo.getX();
        if (centered)
            tX += (int) (graphicInfo.getWidth() / 2 - bb.getWidth() / 2);
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

            AttributedString attrStr = new AttributedString(text);
            attrStr.addAttribute(TextAttribute.FONT, currFont);
   
            // Use LineBreakMeasurer to count number of lines needed for the text
            FontRenderContext frc = new FontRenderContext(null, true, true);
            LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(),
            frc);
            int nextPos = 0;
            int lineCnt = 0;
            while (measurer.getPosition() < text.length())  {
                nextPos = measurer.nextOffset(width/43);            // mergedCellWidth is the max width of each line
                lineCnt++;
                measurer.setPosition(nextPos);
            }
            if(255*lineCnt > r.getHeight()){
                r.setHeight((short)(255 * lineCnt));
            }
        }
View Full Code Here

Examples of java.awt.font.LineBreakMeasurer

            AttributedString attrStr = new AttributedString(text);
            attrStr.addAttribute(TextAttribute.FONT, currFont);
   
            // Use LineBreakMeasurer to count number of lines needed for the text
            FontRenderContext frc = new FontRenderContext(null, true, true);
            LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(),
            frc);
            int nextPos = 0;
            int lineCnt = 0;
            while (measurer.getPosition() < text.length())  {
                nextPos = measurer.nextOffset(width/43);            // mergedCellWidth is the max width of each line
                lineCnt++;
                measurer.setPosition(nextPos);
            }
            if(255*lineCnt > r.getHeight()){
                r.setHeight((short)(255 * lineCnt));
            }
        }
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.