Package java.awt.font

Examples of java.awt.font.LineBreakMeasurer


                  FontRenderContext frc =
                      new FontRenderContext(null, false, false);

                  // now that we have all text tokens in a row in one attributed
                  // string we measure its dimension
                  LineBreakMeasurer lbm =
                      new LineBreakMeasurer(as.getIterator(), frc);

                  TextLayout layout;

                  int maxOffs = text.length();
                  if (linebreakPos.size() > 0) {
                    maxOffs = linebreakPos.get(0);
                  }

                  while ((layout =
                      lbm.nextLayout(Math.max(0, width - 6), maxOffs, false)) != null) {
                    Rectangle2D r = layout.getBounds();
                    dim.width = Math.max((int) r.getWidth(), dim.width);
                    dim.height +=
                        (int) (layout.getAscent() + layout.getDescent() + layout
                            .getLeading());

                    if (lbm.getPosition() >= maxOffs) {
                      if (linebreakPos.size() > 0) {
                        linebreakPos.remove(0);
                      }
                      maxOffs = text.length();
                      if (linebreakPos.size() > 0) {
View Full Code Here


        maxLineLength = 0;
        maxLineHeight = 0;
        nbrLines = 0;
        AttributedCharacterIterator paragraph = styledText.getIterator(null, 0, plainText.length());
        FontRenderContext frc = g2d.getFontRenderContext();
        lineMeasurer = new LineBreakMeasurer(paragraph, frc);
        float yposinpara = 0;
        int charssofar = 0;
        while (lineMeasurer.getPosition() < plainText.length()) {
          TextLayout layout = lineMeasurer.nextLayout(wrapWidth);
          float advance = layout.getVisibleAdvance();
View Full Code Here

    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.isEmpty()) {
          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

      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();
        double tX = graphicInfo.getX();
        if (centered)
            tX += (int) (graphicInfo.getWidth() / 2 - bb.getWidth() / 2);
View Full Code Here

    attrString.addAttribute(TextAttribute.FONT, model.getFont());
    AttributedCharacterIterator iterator = attrString.getIterator();

    ArrayList<Integer> newLineCharIndices = findNewLineCharIndices(text);

    LineBreakMeasurer breaker = new LineBreakMeasurer(iterator, TextPanel.getRenderContext());
    int lastCharIndex = 0, newLineCharIndex = 0;
    while(breaker.getPosition() < iterator.getEndIndex())
    {
      lastCharIndex = addNewLayoutForTheNextLine(text, model, lines, breaker, lastCharIndex, newLineCharIndex, newLineCharIndices);
      if(layoutEndedOnNewLineChar(lastCharIndex, newLineCharIndex, newLineCharIndices))
        newLineCharIndex++;
    }
View Full Code Here

  {
    AttributedString aText = prepareAttributedString();
    AttributedCharacterIterator styledTextIterator = aText.getIterator();

    List<Integer> newlineLocations = getNewlineLocations(styledTextIterator);
    LineBreakMeasurer lbm = new LineBreakMeasurer(styledTextIterator, getRenderContext());

    float width = (float) consumableArea.width;
    if(width <= 0)
      return;

    TextLayout layout;
    int startOfNextLayout;

    int currentLine = 0;
    int endIndex = styledTextIterator.getEndIndex();

    do
    {
      if(currentLine < newlineLocations.size())
        startOfNextLayout = newlineLocations.get(currentLine) + 1;
      else
        startOfNextLayout = endIndex + 1;

      layout = lbm.nextLayout(width, startOfNextLayout, false);

      lines.add(layout);

      if(lbm.getPosition() == startOfNextLayout)
        currentLine += 1;
    }
    while(layout != null && lbm.getPosition() < endIndex);
  }
View Full Code Here

                // build the line break iterator that will split lines at word
                // boundaries when the wrapping length is exceeded
                AttributedString attributed = new AttributedString(line, map);
                AttributedCharacterIterator iter = attributed.getIterator();
                LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(iter,
                        BreakIterator.getLineInstance(), graphics.getFontRenderContext());
                BreakIterator breaks = BreakIterator.getLineInstance();
                breaks.setText(line);

                // setup iteration and start splitting at word boundaries
                int prevPosition = 0;
                while (lineMeasurer.getPosition() < iter.getEndIndex()) {
                    // grab the next portion of text within the wrapping limits
                    TextLayout layout = lineMeasurer.nextLayout(labelItem.getAutoWrap(), line.length(), true);
                    int newPosition = prevPosition;

                    if (layout != null) {
                        newPosition = lineMeasurer.getPosition();
                    } else {
                        int nextBoundary = breaks.following(prevPosition);
                        if (nextBoundary == BreakIterator.DONE) {
                            newPosition = line.length();
                        } else {
                            newPosition = nextBoundary;
                        }
                        AttributedCharacterIterator subIter = attributed.getIterator(null, prevPosition, newPosition);
                        layout = new TextLayout(subIter, graphics.getFontRenderContext());
                        lineMeasurer.setPosition(newPosition);
                    }

                    // extract the text, and trim it since leading and trailing
                    // and ... spaces can affect label alignment in an
                    // unpleasant way (improper left or right alignment, or bad
View Full Code Here

     
      str     = cmd[ off++ ].toString();
      off     = decode( cmd, off, 6 );

      final AttributedCharacterIterator styledText = new AttributedString( str, gc.fnt.getAttributes() ).getIterator();
      final LineBreakMeasurer lbm = new LineBreakMeasurer( styledText, frc);
      final float w = pt[ 2 ];
      float x = pt[ 0 ];              
      float y = pt[ 1 ];
      final float yStop = y + pt[ 3 ];
      final float halign = pt[ 4 ];
      final float valign = pt[ 5 ];
//      final GeneralPath gp = new GeneralPath();
//      final AffineTransform atPos = new AffineTransform();
      final float dy;
      float dx;
      TextLayout txtLay;
       
      try {
        while( lbm.getPosition() < styledText.getEndIndex() ) {
          txtLay  = lbm.nextLayout( w );
          y       += txtLay.getAscent();
          if( y + txtLay.getDescent() > yStop ) break;
          dx    = (w - txtLay.getVisibleAdvance()) *
            (txtLay.isLeftToRight() ? halign : (1.0f - halign));
         
View Full Code Here

      AttributedCharacterIterator itr = attrString.getIterator();
      iterators.addElement(itr);

      if (itr.getEndIndex() != 0) {
        //measurer = new LineBreakMeasurer(iterator, frc);
        measurers.addElement(new LineBreakMeasurer(itr, frc));
      } else {
        measurers.addElement(null);
      }
    }
  }
View Full Code Here

      StringBuffer bfr = (StringBuffer) buffers.elementAt(i); //PROBLEM
      Color color = (Color) colors.elementAt(i);
      int paragraphStart = itr.getBeginIndex();
      int paragraphEnd = itr.getEndIndex();

      LineBreakMeasurer msr = (LineBreakMeasurer) measurers.elementAt(i);
      if (msr != null) {
        msr.setPosition(paragraphStart);
        while (msr.getPosition() < paragraphEnd) {
          int begin = msr.getPosition();
          TextLayout layout = msr.nextLayout(textWidth);
          int end = begin + layout.getCharacterCount();

          // update the lineheight if that's necessary
          lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
          lineAscent = layout.getAscent();
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.