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();
}
}
}
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();
}
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();
}
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);
}
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();
}
}
}
}
Aggregations