Search in sources :

Example 6 with BidiParagraph

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

the class Typesetter method resolveBidi.

private void resolveBidi() {
    // TODO: Analyze script runs.
    BidiAlgorithm bidiAlgorithm = null;
    ShapingEngine shapingEngine = null;
    try {
        bidiAlgorithm = new BidiAlgorithm(mText);
        shapingEngine = new ShapingEngine();
        BaseDirection baseDirection = BaseDirection.DEFAULT_LEFT_TO_RIGHT;
        byte forwardType = specializeBreakType(BREAK_TYPE_PARAGRAPH, true);
        byte backwardType = specializeBreakType(BREAK_TYPE_PARAGRAPH, false);
        int paragraphStart = 0;
        int suggestedEnd = mText.length();
        while (paragraphStart != suggestedEnd) {
            BidiParagraph paragraph = bidiAlgorithm.createParagraph(paragraphStart, suggestedEnd, baseDirection);
            for (BidiRun bidiRun : paragraph.getLogicalRuns()) {
                int scriptTag = SfntTag.make(bidiRun.isRightToLeft() ? "arab" : "latn");
                WritingDirection writingDirection = ShapingEngine.getScriptDirection(scriptTag);
                shapingEngine.setScriptTag(scriptTag);
                shapingEngine.setWritingDirection(writingDirection);
                resolveTypefaces(bidiRun.charStart, bidiRun.charEnd, bidiRun.embeddingLevel, shapingEngine);
            }
            mBidiParagraphs.add(paragraph);
            mBreakRecord[paragraph.getCharStart()] |= backwardType;
            mBreakRecord[paragraph.getCharEnd() - 1] |= forwardType;
            paragraphStart = paragraph.getCharEnd();
        }
    } finally {
        if (shapingEngine != null) {
            shapingEngine.dispose();
        }
        if (bidiAlgorithm != null) {
            bidiAlgorithm.dispose();
        }
    }
}
Also used : ShapingEngine(com.mta.tehreer.sfnt.ShapingEngine) BaseDirection(com.mta.tehreer.unicode.BaseDirection) BidiRun(com.mta.tehreer.unicode.BidiRun) BidiParagraph(com.mta.tehreer.unicode.BidiParagraph) WritingDirection(com.mta.tehreer.sfnt.WritingDirection) BidiAlgorithm(com.mta.tehreer.unicode.BidiAlgorithm)

Example 7 with BidiParagraph

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

the class Typesetter method getCharParagraphLevel.

private byte getCharParagraphLevel(int charIndex) {
    int paragraphIndex = indexOfBidiParagraph(charIndex);
    BidiParagraph charParagraph = mBidiParagraphs.get(paragraphIndex);
    return charParagraph.getBaseLevel();
}
Also used : BidiParagraph(com.mta.tehreer.unicode.BidiParagraph)

Example 8 with BidiParagraph

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

the class ParagraphCollection method charLevel.

public byte charLevel(int charIndex) {
    int paragraphIndex = binarySearch(charIndex);
    BidiParagraph charParagraph = get(paragraphIndex);
    return charParagraph.getBaseLevel();
}
Also used : BidiParagraph(com.mta.tehreer.unicode.BidiParagraph)

Example 9 with BidiParagraph

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

the class ParagraphCollection method binarySearch.

public int binarySearch(int charIndex) {
    int low = 0;
    int high = size() - 1;
    while (low <= high) {
        int mid = (low + high) >>> 1;
        BidiParagraph value = get(mid);
        if (charIndex >= value.getCharEnd()) {
            low = mid + 1;
        } else if (charIndex < value.getCharStart()) {
            high = mid - 1;
        } else {
            return mid;
        }
    }
    return -(low + 1);
}
Also used : BidiParagraph(com.mta.tehreer.unicode.BidiParagraph)

Example 10 with BidiParagraph

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

the class BidiInfoActivity method writeAlgorithmText.

private void writeAlgorithmText(SpannableStringBuilder builder, BidiAlgorithm algorithm) {
    int paragraphIndex = 1;
    int paragraphStart = 0;
    int suggestedEnd = mBidiText.length();
    while (paragraphStart != suggestedEnd) {
        BidiParagraph paragraph = null;
        try {
            paragraph = algorithm.createParagraph(paragraphStart, suggestedEnd, BaseDirection.DEFAULT_LEFT_TO_RIGHT);
            writeParagraphText(builder, paragraph, paragraphIndex);
            paragraphIndex++;
            paragraphStart = paragraph.getCharEnd();
        } finally {
            if (paragraph != null) {
                paragraph.dispose();
            }
        }
    }
}
Also used : BidiParagraph(com.mta.tehreer.unicode.BidiParagraph)

Aggregations

BidiParagraph (com.mta.tehreer.unicode.BidiParagraph)10 BidiRun (com.mta.tehreer.unicode.BidiRun)4 Paint (android.graphics.Paint)2 ShapingEngine (com.mta.tehreer.sfnt.ShapingEngine)2 WritingDirection (com.mta.tehreer.sfnt.WritingDirection)2 BaseDirection (com.mta.tehreer.unicode.BaseDirection)2 BidiAlgorithm (com.mta.tehreer.unicode.BidiAlgorithm)2 BidiLine (com.mta.tehreer.unicode.BidiLine)2 NonNull (androidx.annotation.NonNull)1 ShapingOrder (com.mta.tehreer.sfnt.ShapingOrder)1 ScriptClassifier (com.mta.tehreer.unicode.ScriptClassifier)1 ScriptRun (com.mta.tehreer.unicode.ScriptRun)1