Search in sources :

Example 1 with BidiLine

use of com.mta.tehreer.unicode.BidiLine in project Tehreer-Android by mta452.

the class ParagraphCollection method forEachLineRun.

public void forEachLineRun(int lineStart, int lineEnd, @NonNull RunConsumer runConsumer) {
    int paragraphIndex = binarySearch(lineStart);
    BidiParagraph directionalParagraph = get(paragraphIndex);
    boolean isRTL = (directionalParagraph.getBaseLevel() & 1) == 1;
    if (isRTL) {
        int paragraphEnd = directionalParagraph.getCharEnd();
        if (paragraphEnd < lineEnd) {
            paragraphIndex = binarySearch(lineEnd - 1);
        }
    }
    int next = (isRTL ? -1 : 1);
    int feasibleStart;
    int feasibleEnd;
    do {
        BidiParagraph bidiParagraph = get(paragraphIndex);
        feasibleStart = Math.max(bidiParagraph.getCharStart(), lineStart);
        feasibleEnd = Math.min(bidiParagraph.getCharEnd(), lineEnd);
        BidiLine bidiLine = bidiParagraph.createLine(feasibleStart, feasibleEnd);
        List<BidiRun> bidiRuns = bidiLine.getVisualRuns();
        int runCount = bidiRuns.size();
        for (int i = 0; i < runCount; i++) {
            runConsumer.accept(bidiRuns.get(i));
        }
        bidiLine.dispose();
        paragraphIndex += next;
    } while (isRTL ? feasibleStart != lineStart : feasibleEnd != lineEnd);
}
Also used : BidiRun(com.mta.tehreer.unicode.BidiRun) BidiParagraph(com.mta.tehreer.unicode.BidiParagraph) BidiLine(com.mta.tehreer.unicode.BidiLine)

Example 2 with BidiLine

use of com.mta.tehreer.unicode.BidiLine in project Tehreer-Android by mta452.

the class Typesetter method addContinuousLineRuns.

private void addContinuousLineRuns(int charStart, int charEnd, BidiRunConsumer runConsumer) {
    int paragraphIndex = indexOfBidiParagraph(charStart);
    int feasibleStart;
    int feasibleEnd;
    do {
        BidiParagraph bidiParagraph = mBidiParagraphs.get(paragraphIndex);
        feasibleStart = Math.max(bidiParagraph.getCharStart(), charStart);
        feasibleEnd = Math.min(bidiParagraph.getCharEnd(), charEnd);
        BidiLine bidiLine = bidiParagraph.createLine(feasibleStart, feasibleEnd);
        for (BidiRun bidiRun : bidiLine.getVisualRuns()) {
            runConsumer.accept(bidiRun);
        }
        bidiLine.dispose();
        paragraphIndex++;
    } while (feasibleEnd != charEnd);
}
Also used : BidiRun(com.mta.tehreer.unicode.BidiRun) BidiParagraph(com.mta.tehreer.unicode.BidiParagraph) BidiLine(com.mta.tehreer.unicode.BidiLine)

Example 3 with BidiLine

use of com.mta.tehreer.unicode.BidiLine in project Tehreer-Android by mta452.

the class BidiInfoActivity method writeParagraphText.

private void writeParagraphText(SpannableStringBuilder builder, BidiParagraph paragraph, int index) {
    int paragraphStart = paragraph.getCharStart();
    int paragraphEnd = paragraph.getCharEnd();
    int paragraphLength = paragraphEnd - paragraphStart;
    String paragraphText = ((paragraph.getBaseLevel() & 1) == 1 ? RLI : LRI) + mBidiText.substring(paragraphStart, paragraphEnd) + PDI;
    appendText(builder, "Paragraph " + index + "\n", spansFirstHeading());
    appendText(builder, "Paragraph Text:", spansInlineHeading());
    appendText(builder, " “" + paragraphText + "”\n");
    appendText(builder, "Paragraph Range:", spansInlineHeading());
    appendText(builder, " Start=" + paragraphStart + " Length=" + paragraphLength + "\n");
    appendText(builder, "Base Level:", spansInlineHeading());
    appendText(builder, " " + paragraph.getBaseLevel() + "\n\n");
    int counter = 1;
    for (BidiRun bidiRun : paragraph.getLogicalRuns()) {
        writeRunText(builder, bidiRun, counter);
        counter++;
    }
    BidiLine line = null;
    try {
        line = paragraph.createLine(paragraphStart, paragraphEnd);
        writeLineText(builder, line);
        writeMirrorsText(builder, line);
    } finally {
        if (line != null) {
            line.dispose();
        }
    }
    appendText(builder, "\n");
}
Also used : BidiRun(com.mta.tehreer.unicode.BidiRun) BidiLine(com.mta.tehreer.unicode.BidiLine)

Aggregations

BidiLine (com.mta.tehreer.unicode.BidiLine)3 BidiRun (com.mta.tehreer.unicode.BidiRun)3 BidiParagraph (com.mta.tehreer.unicode.BidiParagraph)2