use of com.mta.tehreer.unicode.ScriptClassifier in project Tehreer-Android by mta452.
the class ShapeResolver method fillRuns.
public static void fillRuns(@NonNull String text, @NonNull Spanned spanned, @NonNull List<Object> defaultSpans, @NonNull byte[] breaks, @NonNull List<BidiParagraph> paragraphs, @NonNull List<TextRun> runs) {
BidiAlgorithm bidiAlgorithm = null;
ShapingEngine shapingEngine = null;
try {
bidiAlgorithm = new BidiAlgorithm(text);
shapingEngine = new ShapingEngine();
ScriptClassifier scriptClassifier = new ScriptClassifier(text);
ShapingRunLocator locator = new ShapingRunLocator(spanned, defaultSpans);
BaseDirection baseDirection = BaseDirection.DEFAULT_LEFT_TO_RIGHT;
byte forwardType = BreakResolver.typeMode(BreakResolver.PARAGRAPH, true);
byte backwardType = BreakResolver.typeMode(BreakResolver.PARAGRAPH, false);
int paragraphStart = 0;
int suggestedEnd = text.length();
while (paragraphStart != suggestedEnd) {
BidiParagraph paragraph = bidiAlgorithm.createParagraph(paragraphStart, suggestedEnd, baseDirection);
for (BidiRun bidiRun : paragraph.getLogicalRuns()) {
for (ScriptRun scriptRun : scriptClassifier.getScriptRuns(bidiRun.charStart, bidiRun.charEnd)) {
int scriptTag = Script.getOpenTypeTag(scriptRun.script);
WritingDirection writingDirection = ShapingEngine.getScriptDirection(scriptTag);
boolean isOddLevel = ((bidiRun.embeddingLevel & 1) == 1);
boolean isBackward = (isOddLevel && writingDirection == WritingDirection.LEFT_TO_RIGHT) | (!isOddLevel && writingDirection == WritingDirection.RIGHT_TO_LEFT);
ShapingOrder shapingOrder = (isBackward ? ShapingOrder.BACKWARD : ShapingOrder.FORWARD);
locator.reset(scriptRun.charStart, scriptRun.charEnd);
shapingEngine.setScriptTag(scriptTag);
shapingEngine.setWritingDirection(writingDirection);
shapingEngine.setShapingOrder(shapingOrder);
resolveTypefaces(text, spanned, runs, locator, shapingEngine, bidiRun.embeddingLevel);
}
}
paragraphs.add(paragraph);
breaks[paragraph.getCharStart()] |= backwardType;
breaks[paragraph.getCharEnd() - 1] |= forwardType;
paragraphStart = paragraph.getCharEnd();
}
} finally {
if (shapingEngine != null) {
shapingEngine.dispose();
}
if (bidiAlgorithm != null) {
bidiAlgorithm.dispose();
}
}
}
Aggregations