use of com.mta.tehreer.layout.style.TypeSizeSpan in project Tehreer-Android by mta452.
the class Typesetter method resolveFonts.
private void resolveFonts(int charStart, int charEnd, byte bidiLevel, ShapingEngine shapingEngine, Typeface typeface) {
Spanned spanned = mSpanned;
TopSpanIterator<TypeSizeSpan> iterator = new TopSpanIterator<>(spanned, charStart, charEnd, TypeSizeSpan.class);
while (iterator.hasNext()) {
TypeSizeSpan spanObject = iterator.next();
int spanStart = iterator.getSpanStart();
int spanEnd = iterator.getSpanEnd();
float typeSize;
if (spanObject == null) {
typeSize = DEFAULT_FONT_SIZE;
} else {
typeSize = spanObject.getSize();
if (typeSize < 0.0f) {
typeSize = 0.0f;
}
}
IntrinsicRun intrinsicRun = resolveGlyphs(spanStart, spanEnd, bidiLevel, shapingEngine, typeface, typeSize);
mIntrinsicRuns.add(intrinsicRun);
}
}
use of com.mta.tehreer.layout.style.TypeSizeSpan in project Tehreer-Android by mta452.
the class Typesetter method createTruncationToken.
private ComposedLine createTruncationToken(int charStart, int charEnd, TruncationPlace truncationPlace, 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;
}
Object[] charSpans = mSpanned.getSpans(truncationIndex, truncationIndex + 1, Object.class);
TypefaceSpan typefaceSpan = null;
TypeSizeSpan typeSizeSpan = null;
final int typefaceBit = 1;
final int typeSizeBit = 1 << 1;
final int requiredBits = typefaceBit | typeSizeBit;
int foundBits = 0;
for (Object span : charSpans) {
if (span instanceof TypefaceSpan) {
if (typefaceSpan == null) {
typefaceSpan = (TypefaceSpan) span;
foundBits |= typefaceBit;
}
} else if (span instanceof TypeSizeSpan) {
if (typeSizeSpan == null) {
typeSizeSpan = (TypeSizeSpan) span;
foundBits |= typeSizeBit;
}
}
if (foundBits == requiredBits) {
Typeface tokenTypeface = typefaceSpan.getTypeface();
float tokenTypeSize = typeSizeSpan.getSize();
if (tokenStr == null || tokenStr.length() == 0) {
// Token string is not given. Use ellipsis character if available; fallback to
// three dots.
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());
}
}
return null;
}
use of com.mta.tehreer.layout.style.TypeSizeSpan 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.style.TypeSizeSpan in project Tehreer-Android by mta452.
the class ShapingRunLocator method resolveSpans.
private static void resolveSpans(@NonNull ShapingRun shapingRun, @NonNull Object[] spans) {
for (Object span : spans) {
if (span instanceof com.mta.tehreer.layout.style.TypefaceSpan) {
com.mta.tehreer.layout.style.TypefaceSpan typefaceSpan = (com.mta.tehreer.layout.style.TypefaceSpan) span;
shapingRun.typeface = typefaceSpan.getTypeface();
shapingRun.typeWeight = shapingRun.typeface.getWeight();
shapingRun.typeSlope = shapingRun.typeface.getSlope();
} else if (span instanceof TypeSizeSpan) {
TypeSizeSpan typeSizeSpan = (TypeSizeSpan) span;
shapingRun.typeSize = typeSizeSpan.getSize();
} else if (span instanceof TypefaceSpan) {
TypefaceSpan typefaceSpan = (TypefaceSpan) span;
resolveTypeface(shapingRun, typefaceSpan.getFamily(), TypeWidth.NORMAL);
} else if (span instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan absoluteSizeSpan = (AbsoluteSizeSpan) span;
shapingRun.typeSize = absoluteSizeSpan.getSize();
} else if (span instanceof RelativeSizeSpan) {
RelativeSizeSpan relativeSizeSpan = (RelativeSizeSpan) span;
shapingRun.typeSize *= relativeSizeSpan.getSizeChange();
} else if (span instanceof StyleSpan) {
StyleSpan styleSpan = (StyleSpan) span;
resolveStyle(shapingRun, styleSpan.getStyle());
updateTypeface(shapingRun);
} else if (span instanceof TextAppearanceSpan) {
TextAppearanceSpan appearanceSpan = (TextAppearanceSpan) span;
shapingRun.typeSize = appearanceSpan.getTextSize();
resolveStyle(shapingRun, appearanceSpan.getTextStyle());
String familyName = appearanceSpan.getFamily();
if (familyName != null) {
resolveTypeface(shapingRun, familyName, TypeWidth.NORMAL);
} else {
updateTypeface(shapingRun);
}
} else if (span instanceof ScaleXSpan) {
ScaleXSpan scaleXSpan = (ScaleXSpan) span;
shapingRun.scaleX = scaleXSpan.getScaleX();
} else if (span instanceof SuperscriptSpan) {
resolveBaselineShift(shapingRun, 0.5f);
} else if (span instanceof SubscriptSpan) {
resolveBaselineShift(shapingRun, -0.5f);
} else if (span instanceof ReplacementSpan) {
shapingRun.replacement = (ReplacementSpan) span;
}
}
if (shapingRun.typeSize < 0.0f) {
shapingRun.typeSize = 0.0f;
}
}
Aggregations