Example usage for java.text AttributedCharacterIterator getRunLimit

List of usage examples for java.text AttributedCharacterIterator getRunLimit

Introduction

In this page you can find the example usage for java.text AttributedCharacterIterator getRunLimit.

Prototype

public int getRunLimit();

Source Link

Document

Returns the index of the first character following the run with respect to all attributes containing the current character.

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

/**
 *
 */// w w w .j a va  2 s  . c o  m
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<Attribute, Object> 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;
}

From source file:net.sf.jasperreports.engine.export.HtmlExporter.java

protected void exportStyledText(JRPrintText printText, JRStyledText styledText, String tooltip,
        boolean hyperlinkStarted) throws IOException {
    Locale locale = getTextLocale(printText);
    LineSpacingEnum lineSpacing = printText.getParagraph().getLineSpacing();
    Float lineSpacingSize = printText.getParagraph().getLineSpacingSize();
    float lineSpacingFactor = printText.getLineSpacingFactor();
    Color backcolor = printText.getBackcolor();

    String text = styledText.getText();

    int runLimit = 0;

    addSearchAttributes(styledText, printText);

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

    boolean first = true;
    boolean startedSpan = false;

    boolean highlightStarted = 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;/*from   w w w . java 2s  .c  om*/
            writer.write("<span title=\"");
            writer.write(JRStringUtil.encodeXmlAttribute(tooltip));
            writer.write("\">");
            //reset the tooltip so that inner <span>s to not use it
            tooltip = null;
        }
        first = false;

        Map<Attribute, Object> attributes = iterator.getAttributes();
        Color highlightColor = (Color) attributes.get(JRTextAttribute.SEARCH_HIGHLIGHT);
        if (highlightColor != null && !highlightStarted) {
            highlightStarted = true;
            writer.write("<span class=\"jr_search_result\">");
        } else if (highlightColor == null && highlightStarted) {
            highlightStarted = false;
            writer.write("</span>");
        }

        exportStyledTextRun(attributes, text.substring(iterator.getIndex(), runLimit), tooltip, locale,
                lineSpacing, lineSpacingSize, lineSpacingFactor, backcolor, hyperlinkStarted);

        iterator.setIndex(runLimit);
    }

    if (highlightStarted) {
        writer.write("</span>");
    }

    if (startedSpan) {
        writer.write("</span>");
    }
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

protected boolean canUseGlyphRendering(JRPrintText text, JRStyledText styledText) {
    Locale locale = getTextLocale(text);
    AttributedCharacterIterator attributesIterator = styledText.getAttributedString().getIterator();
    int index = 0;
    while (index < styledText.length()) {
        FontKey fontKey = extractFontKey(attributesIterator.getAttributes(), locale);
        if (!fontKey.fontAttribute.hasAttribute()) {
            return false;
        }//from w w  w  . j a  va 2 s. c  o  m

        Boolean canUse = glyphRendererFonts.get(fontKey);
        if (canUse == null) {
            canUse = canUseGlyphRendering(fontKey);
            glyphRendererFonts.put(fontKey, canUse);
        }

        if (!canUse) {
            return false;
        }

        index = attributesIterator.getRunLimit();
        attributesIterator.setIndex(index);
    }
    return true;
}

From source file:org.apache.fop.svg.ACIUtils.java

/**
 * Dumps the contents of an ACI to System.out. Used for debugging only.
 * @param aci the ACI to dump//from  w w w.j a  v a  2s  .co m
 */
public static void dumpAttrs(AttributedCharacterIterator aci) {
    aci.first();
    Set<Entry<Attribute, Object>> entries = aci.getAttributes().entrySet();
    for (Map.Entry<Attribute, Object> entry : entries) {
        if (entry.getValue() != null) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
    int start = aci.getBeginIndex();
    System.out.print("AttrRuns: ");
    while (aci.current() != CharacterIterator.DONE) {
        int end = aci.getRunLimit();
        System.out.print("" + (end - start) + ", ");
        aci.setIndex(end);
        if (start == end) {
            break;
        }
        start = end;
    }
    System.out.println("");
}