use of com.mta.tehreer.layout.Typesetter in project Tehreer-Android by mta452.
the class TLabel method updateTypesetter.
private void updateTypesetter() {
if (mNeedsTypesetter) {
return;
}
mTypesetter = null;
long t1 = System.nanoTime();
if (mText != null) {
Typeface typeface = getTypeface();
if (typeface != null && mText.length() > 0) {
mTypesetter = new Typesetter(mText, typeface, getTextSize());
}
} else if (mSpanned != null) {
if (mSpanned.length() > 0) {
List<Object> defaultSpans = new ArrayList<>();
Typeface typeface = getTypeface();
float textSize = getTextSize();
if (typeface != null) {
defaultSpans.add(new TypefaceSpan(typeface));
}
defaultSpans.add(new TypeSizeSpan(textSize));
mTypesetter = new Typesetter(mSpanned, defaultSpans);
}
}
long t2 = System.nanoTime();
Log.i("Tehreer", "Time taken to create typesetter: " + ((t2 - t1) * 1E-6));
requestLayout();
invalidate();
}
use of com.mta.tehreer.layout.Typesetter in project Tehreer-Android by mta452.
the class TokenResolver method createToken.
@NonNull
public static ComposedLine createToken(@NonNull RunCollection runs, int charStart, int charEnd, @NonNull TruncationPlace truncationPlace, @Nullable String tokenStr) {
int truncationIndex = 0;
switch(truncationPlace) {
case START:
truncationIndex = charStart;
break;
case MIDDLE:
truncationIndex = (charStart + charEnd) / 2;
break;
case END:
truncationIndex = charEnd - 1;
break;
}
int runIndex = runs.binarySearch(truncationIndex);
TextRun suitableRun = runs.get(runIndex);
Typeface tokenTypeface = suitableRun.getTypeface();
float tokenTypeSize = suitableRun.getTypeSize();
if (tokenStr == null || tokenStr.length() == 0) {
// Token string is not given. Use ellipsis character if available; fallback to three
// dot characters.
int ellipsisGlyphId = tokenTypeface.getGlyphId(0x2026);
if (ellipsisGlyphId == 0) {
tokenStr = "...";
} else {
tokenStr = "\u2026";
}
}
Typesetter typesetter = new Typesetter(tokenStr, tokenTypeface, tokenTypeSize);
return typesetter.createSimpleLine(0, tokenStr.length());
}
Aggregations