Examples of AttributedCharacterIterator


Examples of java.text.AttributedCharacterIterator

  protected Phrase getPhrase(AttributedString as, String text, JRPrintText textElement)
  {
    Phrase phrase = new Phrase();
    int runLimit = 0;

    AttributedCharacterIterator iterator = as.getIterator();
    Locale locale = getTextLocale(textElement);
    
    boolean firstChunk = true;
    while(runLimit < text.length() && (runLimit = iterator.getRunLimit()) <= text.length())
    {
      Map attributes = iterator.getAttributes();
      Chunk chunk = getChunk(attributes, text.substring(iterator.getIndex(), runLimit), locale);
     
      if (firstChunk)
      {
        // only set anchor + bookmark for the first chunk in the text
        setAnchor(chunk, textElement, textElement);
      }
     
      JRPrintHyperlink hyperlink = textElement;
      if (hyperlink.getHyperlinkTypeValue() == HyperlinkTypeEnum.NONE)
      {
        hyperlink = (JRPrintHyperlink)attributes.get(JRTextAttribute.HYPERLINK);
      }
     
      setHyperlinkInfo(chunk, hyperlink);
      phrase.add(chunk);

      iterator.setIndex(runLimit);
      firstChunk = false;
    }

    return phrase;
  }
View Full Code Here

Examples of java.text.AttributedCharacterIterator

//            }
//          }
//        }
      }
     
      AttributedCharacterIterator iterator = awtAttributedString.getIterator();
     
      int runLimit = 0;
      AffineTransform atrans = null;

      while(runLimit < iterator.getEndIndex() && (runLimit = iterator.getRunLimit(FONT_ATTRS)) <= iterator.getEndIndex())
      {
        Map attrs = iterator.getAttributes();
         
        String familyName = (String)attrs.get(TextAttribute.FAMILY);
       
        Font awtFont =
          JRFontUtil.getAwtFontFromBundles(
            familyName,
            ((TextAttribute.WEIGHT_BOLD.equals(attrs.get(TextAttribute.WEIGHT))?Font.BOLD:Font.PLAIN)
              |(TextAttribute.POSTURE_OBLIQUE.equals(attrs.get(TextAttribute.POSTURE))?Font.ITALIC:Font.PLAIN)),
            ((Float)attrs.get(TextAttribute.SIZE)).intValue(),
            locale,
            ignoreMissingFont
            );
        if (awtFont == null)
        {
          // The font was not found in any of the font extensions, so it is expected that the TextAttribute.FAMILY attribute
          // will be used by AWT. In that case, we want make sure the font family name is available to the JVM.
          JRFontUtil.checkAwtFont(familyName, ignoreMissingFont);
        }
        else
        {
          if (AWT_SUPERSCRIPT_FIX_ENABLED && atrans != null)
          {
            double y = atrans.getTranslateY();
            atrans = new AffineTransform();
            atrans.translate(0, - y);
            awtFont = awtFont.deriveFont(atrans);
            atrans = null;
          }
          Integer superscript = (Integer)attrs.get(TextAttribute.SUPERSCRIPT);
          if (TextAttribute.SUPERSCRIPT_SUPER.equals(superscript))
          {
            atrans = new AffineTransform();
            atrans.scale(2 / 3d, 2 / 3d);
            atrans.translate(0, - awtFont.getSize() / 2f);
            awtFont = awtFont.deriveFont(atrans);
          }
          else if (TextAttribute.SUPERSCRIPT_SUB.equals(superscript))
          {
            atrans = new AffineTransform();
            atrans.scale(2 / 3d, 2 / 3d);
            atrans.translate(0, awtFont.getSize() / 2f);
            awtFont = awtFont.deriveFont(atrans);
          }
          awtAttributedString.addAttribute(TextAttribute.FONT, awtFont, iterator.getIndex(), runLimit);
        }
       
        iterator.setIndex(runLimit);
      }

    }
   
    return awtAttributedString;
View Full Code Here

Examples of java.text.AttributedCharacterIterator

    )
  {
    /*   */
    initialize(styledText, remainingTextStart, availableStretchHeight, canOverflow);

    AttributedCharacterIterator allParagraphs =
      styledText.getAwtAttributedString(
        JRProperties.getBooleanProperty(propertiesHolder, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false)
        ).getIterator();

    int tokenPosition = remainingTextStart;
View Full Code Here

Examples of java.text.AttributedCharacterIterator

    AttributedCharacterIterator allParagraphs,
    int lastParagraphStart,
    String lastParagraphText
    )
  {
    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();
    }

    List<Integer> tabIndexes = JRStringUtil.getTabIndexes(lastParagraphText);
   
    int[] currentTabHolder = new int[]{0};
    TabStop[] nextTabStopHolder = new TabStop[]{null};
    boolean[] requireNextWordHolder = new boolean[]{false};

    LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, getFontRenderContext());
   
    measuredState.paragraphStartLine = measuredState.lines;
    measuredState.textOffset = lastParagraphStart;
   
    boolean rendered = true;
    boolean renderedLine = false;

    // the paragraph is measured one line at a time
    while (lineMeasurer.getPosition() < paragraph.getEndIndex() && rendered)
    {
      rendered = renderNextLine(lineMeasurer, paragraph, tabIndexes, currentTabHolder, nextTabStopHolder, requireNextWordHolder);
      renderedLine = renderedLine || rendered;
    }
   
View Full Code Here

Examples of java.text.AttributedCharacterIterator

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

Examples of java.text.AttributedCharacterIterator

      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

Examples of java.text.AttributedCharacterIterator

  /**
   *
   */
  public void render()
  {
    AttributedCharacterIterator allParagraphs = 
      styledText.getAwtAttributedString(ignoreMissingFont).getIterator();

    int tokenPosition = 0;
    int lastParagraphStart = 0;
    String lastParagraphText = null;
View Full Code Here

Examples of java.text.AttributedCharacterIterator

    AttributedCharacterIterator allParagraphs,
    int lastParagraphStart,
    String lastParagraphText
    )
  {
    AttributedCharacterIterator paragraph = null;
   
    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;
        }
View Full Code Here

Examples of java.text.AttributedCharacterIterator

  {
    String text = styledText.getText();

    int runLimit = 0;

    AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();

    boolean first = true;
    boolean startedSpan = false;
    while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length())
    {
      //if there are several text runs, write the tooltip into a parent <span>
      if (first && runLimit < styledText.length() && tooltip != null)
      {
        startedSpan = true;
        writer.write("<span title=\"");
        writer.write(JRStringUtil.xmlEncode(tooltip));
        writer.write("\">");
        //reset the tooltip so that inner <span>s to not use it
        tooltip = null;
      }
      first = false;
     
      exportStyledTextRun(
        iterator.getAttributes(),
        text.substring(iterator.getIndex(), runLimit),
        tooltip,
        locale
        );

      iterator.setIndex(runLimit);
    }
   
    if (startedSpan)
    {
      writer.write("</span>");
View Full Code Here

Examples of java.text.AttributedCharacterIterator

  {
    String text = styledText.getText();

    int runLimit = 0;

    AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();

    boolean first = true;
    boolean startedSpan = false;
    while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length())
    {
      //if there are several text runs, write the tooltip into a parent <span>
      if (first && runLimit < styledText.length() && tooltip != null)
      {
        startedSpan = true;
        writer.write("<span title=\"");
        writer.write(JRStringUtil.xmlEncode(tooltip));
        writer.write("\">");
        //reset the tooltip so that inner <span>s to not use it
        tooltip = null;
      }
      first = false;
     
      exportStyledTextRun(
        iterator.getAttributes(),
        text.substring(iterator.getIndex(), runLimit),
        tooltip,
        locale
        );

      iterator.setIndex(runLimit);
    }
   
    if (startedSpan)
    {
      writer.write("</span>");
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.