Package java.text

Examples of java.text.AttributedString$AttributeMap


            // 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 =
                        new LineBreakMeasurer(attStr.getIterator(),
                        metrics.getFontRenderContext());


                while ((layout = measurer.nextLayout(wrapWidth)) != null) {
                    layoutList.add(layout);
View Full Code Here


        char[] text = string.toCharArray();
        if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
            fastInit(text, font, attributes, frc);
        } else {
            AttributedString as = attributes == null
                ? new AttributedString(string)
                : new AttributedString(string, attributes);
            as.addAttribute(TextAttribute.FONT, font);
            standardInit(as.getIterator(), text, frc);
        }
    }
View Full Code Here

        char[] text = string.toCharArray();
        Font font = singleFont(text, 0, text.length, attributes);
        if (font != null) {
            fastInit(text, font, attributes, frc);
        } else {
            AttributedString as = new AttributedString(string, attributes);
            standardInit(as.getIterator(), text, frc);
        }
    }
View Full Code Here

   */
  public AttributedString getAttributedString()
  {
    if (attributedString == null)
    {
      attributedString = new AttributedString(sbuffer.toString());

      for(int i = runs.size() - 1; i >= 0; i--)
      {
        Run run = (Run)runs.get(i);
        if (run.startIndex != run.endIndex && run.attributes != null)
View Full Code Here

   */
  public AttributedString getAwtAttributedString(boolean ignoreMissingFont)
  {
    if (awtAttributedString == null)
    {
      awtAttributedString = new AttributedString(sbuffer.toString());

      for(int i = runs.size() - 1; i >= 0; i--)
      {
        Run run = (Run)runs.get(i);
        if (run.startIndex != run.endIndex && run.attributes != null)
View Full Code Here

    AttributedCharacterIterator paragraph = null;
   
    if (lastParagraphText == null)
    {
      paragraph =
        new AttributedString(
          " ",
          new AttributedString(
            allParagraphs,
            lastParagraphStart,
            lastParagraphStart + 1
            ).getIterator().getAttributes()
          ).getIterator();
    }
    else
    {
      paragraph =
        new AttributedString(
          allParagraphs,
          lastParagraphStart,
          lastParagraphStart + lastParagraphText.length()
          ).getIterator();
    }
View Full Code Here

    )
  {
    //truncate the original line at char
    measuredState = prevMeasuredState.cloneState();
    AttributedCharacterIterator lineParagraph =
      new AttributedString(
        allParagraphs,
        measuredState.textOffset,
        paragraphOffset + paragraphText.length()
        ).getIterator();
    LineBreakMeasurer lineMeasurer =
View Full Code Here

    do
    {
      measuredState = prevMeasuredState.cloneState();

      String text = lineText.substring(0, linePosition) + truncateSuffx;
      AttributedString attributedText = new AttributedString(text);
     
      //set original attributes for the text part
      AttributedCharacterIterator lineAttributes =
        new AttributedString(
          allParagraphs,
          measuredState.textOffset,
          measuredState.textOffset + linePosition
          ).getIterator();
      setAttributes(attributedText, lineAttributes, 0);
     
      //set global attributes for the suffix part
      setAttributes(
        attributedText,
        globalAttributes,
        text.length() - truncateSuffx.length(),
        text.length()
        );
     
      AttributedCharacterIterator lineParagraph = attributedText.getIterator();
     
      BreakIterator breakIterator =
        isToTruncateAtChar()
        ? BreakIterator.getCharacterInstance()
        : BreakIterator.getLineInstance();
View Full Code Here

              // 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();
            }
View Full Code Here

   
    if (lastParagraphText == null)
    {
      lastParagraphText = " ";
      paragraph =
        new AttributedString(
          lastParagraphText,
          new AttributedString(
            allParagraphs,
            lastParagraphStart,
            lastParagraphStart + lastParagraphText.length()
            ).getIterator().getAttributes()
          ).getIterator();
    }
    else
    {
      paragraph =
        new AttributedString(
          allParagraphs,
          lastParagraphStart,
          lastParagraphStart + lastParagraphText.length()
          ).getIterator();
    }

    List<Integer> tabIndexes = JRStringUtil.getTabIndexes(lastParagraphText);
   
    int currentTab = 0;
    int lines = 0;
    float endX = 0;
   
    TabStop nextTabStop = null;
    boolean requireNextWord = false;
 
    LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, getFontRenderContext());//grx.getFontRenderContext()

    // the paragraph is rendered one line at a time
    while (lineMeasurer.getPosition() < paragraph.getEndIndex() && !isMaxHeightReached)
    {
      boolean lineComplete = false;

      float maxAscent = 0;
      float maxDescent = 0;
      float maxLeading = 0;
     
      // each line is split into segments, using the tab character as delimiter
      segments = new ArrayList<TabSegment>(1);

      TabSegment oldSegment = null;
      TabSegment crtSegment = null;

      // splitting the current line into tab segments
      while (!lineComplete)
      {
        // the current segment limit is either the next tab character or the paragraph end
        int tabIndexOrEndIndex = (tabIndexes == null || currentTab >= tabIndexes.size() ? paragraph.getEndIndex() : tabIndexes.get(currentTab) + 1);
       
        float startX = (lineMeasurer.getPosition() == 0 ? text.getParagraph().getFirstLineIndent() : 0);
        endX = width - text.getParagraph().getRightIndent() - rightPadding;
        endX = endX < startX ? startX : endX;
        //formatWidth = endX - startX;
        //formatWidth = endX;
       
        int startIndex = lineMeasurer.getPosition();

        int rightX = 0;

        if (segments.size() == 0)
        {
          rightX = (int)startX;
          //nextTabStop = nextTabStop;
        }
        else
        {
          rightX = oldSegment.rightX;
          nextTabStop = ParagraphUtil.getNextTabStop(text.getParagraph(), endX, rightX);
        }

        //float availableWidth = formatWidth - ParagraphUtil.getSegmentOffset(nextTabStop, rightX); // nextTabStop can be null here; and that's OK
        float availableWidth = endX - text.getParagraph().getLeftIndent() - ParagraphUtil.getSegmentOffset(nextTabStop, 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,
            requireNextWord
            );
       
        if (layout != null)
        {
           AttributedString tmpText =
            new AttributedString(
              paragraph,
              startIndex,
              startIndex + layout.getCharacterCount()
              );
          
          if (isMinimizePrinterJobSize)
          {
            //eugene fix - start
            layout = new TextLayout(tmpText.getIterator(), getFontRenderContext());
            //eugene fix - end
          }
   
          if (
            text.getHorizontalAlignmentValue() == HorizontalAlignEnum.JUSTIFIED
            && lineMeasurer.getPosition() < paragraph.getEndIndex()
            )
          {
            layout = layout.getJustifiedLayout(availableWidth);
          }
         
          maxAscent = Math.max(maxAscent, layout.getAscent());
          maxDescent = Math.max(maxDescent, layout.getDescent());
          maxLeading = Math.max(maxLeading, layout.getLeading());

          //creating the current segment
          crtSegment = new TabSegment();
          crtSegment.layout = layout;
          crtSegment.as = tmpText;
          crtSegment.text = lastParagraphText.substring(startIndex, startIndex + layout.getCharacterCount());

          int leftX = ParagraphUtil.getLeftX(nextTabStop, 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(nextTabStop, layout.getAdvance()); // nextTabStop can be null here; and that's OK
          }

          segments.add(crtSegment);
        }
       
        requireNextWord = true;

        if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
        {
          // the segment limit was a tab; going to the next tab
          currentTab++;
        }

        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;
          nextTabStop = null;
        }
        else
        {
          // there is paragraph text remaining
          if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
          {
            // the segment limit was a tab
            if (crtSegment.rightX >= ParagraphUtil.getLastTabStop(text.getParagraph(), 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
              nextTabStop = ParagraphUtil.getFirstTabStop(text.getParagraph(), 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 (nextTabStop.getPosition() == ParagraphUtil.getFirstTabStop(text.getParagraph(), endX).getPosition())//FIXMETAB check based on segments.size()
              {
                // at second attempt we give up to avoid infinite loop
                nextTabStop = null;
                requireNextWord = 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();
              }
View Full Code Here

TOP

Related Classes of java.text.AttributedString$AttributeMap

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.