Examples of LineBreakMeasurer


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

             return;
         }
       
         AttributedCharacterIterator aci = this.atribStr.getIterator();
         FontRenderContext frc = g.getFontRenderContext();
         LineBreakMeasurer lbm;
         try{
            lbm = new LineBreakMeasurer(aci, frc);
         }catch(Exception e){
             e.printStackTrace();
             return;
         }

         // Compute text font size
         float drawPosY;
         float fontReduction = 0f;
         int limit;
         do {

getFullWord: {
   
             this.atribStr.addAttribute(TextAttribute.SIZE, getFontSize() - fontReduction);
             lbm = new LineBreakMeasurer(aci, frc);
             fontReduction += 1f;
             drawPosY = 0;
             while (lbm.getPosition() < formatedString.length() ) {
                 //TextLayout layout = lbm.nextLayout(this.getWidth());
                
                 limit = lbm.getPosition() + formatedString.substring( lbm.getPosition() ).indexOf('\n')+1;
                 if (limit <= lbm.getPosition()){
                     limit = formatedString.length();
                 }
                 TextLayout layout = lbm.nextLayout(this.getWidth(), limit, true);
                
                 if (layout == null){
                     break getFullWord;
                 }
                
                 drawPosY += layout.getAscent();
                 drawPosY += layout.getDescent();
                 drawPosY += layout.getLeading();
             }
}

         }while ( (lbm.getPosition() < formatedString.length()) || ( drawPosY > this.getHeight() && fontReduction < getFontSize()));
       
         // do the paiting
         aci = this.atribStr.getIterator();
         lbm.setPosition(0);
         if ( vertAlign == VALIGN_MIDDLE ){
             drawPosY = (this.getHeight() - drawPosY) / 2;
         } else if (vertAlign == VALIGN_BOTTOM){
             drawPosY = this.getHeight() - drawPosY;
         } else {
             drawPosY = 0;
         }
        
         Color oldColor = g.getColor();
         Composite oldComposite = g.getComposite();
         try{
             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
             g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
             g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
             g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.getAlpha() * time ) );
             while (lbm.getPosition() < formatedString.length() ) {

                 limit = lbm.getPosition() + formatedString.substring( lbm.getPosition() ).indexOf('\n')+1;
                 if (limit <= lbm.getPosition()){
                     limit = formatedString.length();
                 }
                 TextLayout layout = lbm.nextLayout(this.getWidth(), limit, true);

                 drawPosY += layout.getAscent();

                 // default alignment = Left
                 float drawPosX = this.getLeft();
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

        AttributedCharacterIterator it = at.getIterator();
        int paragraphStart = it.getBeginIndex();
        int paragraphEnd = it.getEndIndex();

        List<TextElement> lines = new ArrayList<TextElement>();
        LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
        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 = textWidth - _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;
            }

            if(bulletOffset > 0 || prStart || startIndex == 0) 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(textWidth,
                    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

        AttributedCharacterIterator it = at.getIterator();
        int paragraphStart = it.getBeginIndex();
        int paragraphEnd = it.getEndIndex();

        ArrayList lines = new ArrayList();
        LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
        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 = textWidth - _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;
            }

            if(bulletOffset > 0 || prStart || startIndex == 0) 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(textWidth,
                    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

               
                if (wordLength > maxLineLength) {
                    // This word by itself is too long to fit on one line so we truncate the word.
               
                    AttributedString attrString = new AttributedString (word);
                    LineBreakMeasurer measurer = new LineBreakMeasurer(attrString.getIterator(), context);
                    int index = measurer.nextOffset(maxLineLength);
               
                    // Add the previous line if there is any
                    if (lineBuffer.length() > 0) {
                        result.add (lineBuffer.toString ());
                        lineBuffer = new StringBuilder ();
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

     * Use a LineBreakMeasurer instance to break our text into lines that fit
     * the imageable area of the page.
     */
    Point2D.Float pen = new Point2D.Float();
    AttributedCharacterIterator charIterator = myStyledText.getIterator();
    LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator,
        graphics2d.getFontRenderContext());
    float wrappingWidth = (float) format.getImageableWidth();
    while (measurer.getPosition() == charIterator.getEndIndex()) {
      TextLayout layout = measurer.nextLayout(wrappingWidth);
      pen.y += layout.getAscent();
      float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout
          .getAdvance());
      layout.draw(graphics2d, pen.x + dx, pen.y);
      pen.y += layout.getDescent() + layout.getLeading();
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

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