Search in sources :

Example 1 with Typeface

use of com.mta.tehreer.graphics.Typeface 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;
}
Also used : Typeface(com.mta.tehreer.graphics.Typeface) TypeSizeSpan(com.mta.tehreer.layout.style.TypeSizeSpan) TypefaceSpan(com.mta.tehreer.layout.style.TypefaceSpan)

Example 2 with Typeface

use of com.mta.tehreer.graphics.Typeface in project Tehreer-Android by mta452.

the class FontFile method loadTypefaces.

private void loadTypefaces() {
    List<Typeface> allTypefaces = new ArrayList<>();
    int faceCount = nGetFaceCount(nativeFontFile);
    for (int i = 0; i < faceCount; i++) {
        Typeface firstTypeface = nCreateTypeface(nativeFontFile, i);
        List<NamedStyle> namedStyles = firstTypeface.getNamedStyles();
        if (namedStyles == null || namedStyles.size() == 0) {
            allTypefaces.add(firstTypeface);
        } else {
            for (NamedStyle namedStyle : namedStyles) {
                float[] coordinates = namedStyle.coordinates();
                Typeface instanceTypeface = firstTypeface.getVariationInstance(coordinates);
                allTypefaces.add(instanceTypeface);
            }
        }
    }
    mTypefaces = allTypefaces;
}
Also used : Typeface(com.mta.tehreer.graphics.Typeface) ArrayList(java.util.ArrayList)

Example 3 with Typeface

use of com.mta.tehreer.graphics.Typeface in project Tehreer-Android by mta452.

the class ShapingRunLocator method resolveBaselineShift.

private static void resolveBaselineShift(@NonNull ShapingRun shapingRun, float multiplier) {
    Typeface typeface = shapingRun.typeface;
    if (typeface != null) {
        float sizeByEm = shapingRun.typeSize / typeface.getUnitsPerEm();
        float ascent = typeface.getAscent() * sizeByEm;
        shapingRun.baselineShift = ascent * multiplier;
    }
}
Also used : Typeface(com.mta.tehreer.graphics.Typeface)

Example 4 with Typeface

use of com.mta.tehreer.graphics.Typeface 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();
}
Also used : Typesetter(com.mta.tehreer.layout.Typesetter) Typeface(com.mta.tehreer.graphics.Typeface) ArrayList(java.util.ArrayList) List(java.util.List) TypeSizeSpan(com.mta.tehreer.layout.style.TypeSizeSpan) TypefaceSpan(com.mta.tehreer.layout.style.TypefaceSpan)

Example 5 with Typeface

use of com.mta.tehreer.graphics.Typeface 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());
}
Also used : Typesetter(com.mta.tehreer.layout.Typesetter) Typeface(com.mta.tehreer.graphics.Typeface) NonNull(androidx.annotation.NonNull)

Aggregations

Typeface (com.mta.tehreer.graphics.Typeface)12 ActionBar (androidx.appcompat.app.ActionBar)5 Paint (android.graphics.Paint)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 Spinner (android.widget.Spinner)3 Intent (android.content.Intent)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Typesetter (com.mta.tehreer.layout.Typesetter)2 TypeSizeSpan (com.mta.tehreer.layout.style.TypeSizeSpan)2 TypefaceSpan (com.mta.tehreer.layout.style.TypefaceSpan)2 ShapingResult (com.mta.tehreer.sfnt.ShapingResult)2 WritingDirection (com.mta.tehreer.sfnt.WritingDirection)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 SpannableString (android.text.SpannableString)1 ReplacementSpan (android.text.style.ReplacementSpan)1 DisplayMetrics (android.util.DisplayMetrics)1 ViewTreeObserver (android.view.ViewTreeObserver)1