Search in sources :

Example 1 with Renderer

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

the class TypefaceGlyphsActivity method loadTypeface.

private void loadTypeface(Typeface typeface) {
    if (typeface != mTypeface) {
        mTypeface = typeface;
        float density = getResources().getDisplayMetrics().density;
        float typeSize = 28.0f * density;
        Renderer renderer = new Renderer();
        renderer.setTypeface(typeface);
        renderer.setTypeSize(typeSize);
        mGlyphsGridView.setAdapter(new GlyphAdapter(this, renderer));
    }
}
Also used : Renderer(com.mta.tehreer.graphics.Renderer)

Example 2 with Renderer

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

the class OpenTypeInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_opentype_info);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    Intent intent = getIntent();
    String typefaceName = intent.getStringExtra(TYPEFACE_NAME);
    int typeSize = intent.getIntExtra(TYPE_SIZE, 0);
    int scriptTag = intent.getIntExtra(SCRIPT_TAG, 0);
    int languageTag = intent.getIntExtra(LANGUAGE_TAG, 0);
    String sourceText = intent.getCharSequenceExtra(SOURCE_TEXT).toString();
    WritingDirection writingDirection = ShapingEngine.getScriptDirection(scriptTag);
    Typeface typeface = TypefaceManager.getTypefaceByName(typefaceName);
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    float displaySize = 18.0f * displayMetrics.scaledDensity;
    float sizeScale = displaySize / typeSize;
    Renderer renderer = new Renderer();
    renderer.setTypeface(typeface);
    renderer.setTypeSize(typeSize);
    renderer.setScaleX(sizeScale);
    renderer.setScaleY(sizeScale);
    ShapingEngine shapingEngine = ShapingEngine.finalizable(new ShapingEngine());
    shapingEngine.setTypeface(typeface);
    shapingEngine.setTypeSize(typeSize);
    shapingEngine.setScriptTag(scriptTag);
    shapingEngine.setLanguageTag(languageTag);
    shapingEngine.setWritingDirection(writingDirection);
    ShapingResult shapingResult = ShapingResult.finalizable(shapingEngine.shapeText(sourceText, 0, sourceText.length()));
    IntList clusterMap = shapingResult.getClusterMap();
    int length = clusterMap.size();
    int[] initials = new int[length + 1];
    int cluster = -1;
    int previous = -1;
    for (int i = 0; i < length; i++) {
        int value = clusterMap.get(i);
        if (value != previous) {
            initials[++cluster] = i;
        }
        previous = value;
    }
    initials[++cluster] = length;
    ListView infoListView = findViewById(R.id.list_view_info);
    infoListView.setAdapter(new ClusterAdapter(this, renderer, sourceText, shapingResult, IntList.of(initials).subList(0, cluster + 1)));
}
Also used : ShapingEngine(com.mta.tehreer.sfnt.ShapingEngine) Typeface(com.mta.tehreer.graphics.Typeface) Intent(android.content.Intent) SpannableString(android.text.SpannableString) DisplayMetrics(android.util.DisplayMetrics) ShapingResult(com.mta.tehreer.sfnt.ShapingResult) Paint(android.graphics.Paint) IntList(com.mta.tehreer.collections.IntList) ListView(android.widget.ListView) Renderer(com.mta.tehreer.graphics.Renderer) WritingDirection(com.mta.tehreer.sfnt.WritingDirection) ActionBar(androidx.appcompat.app.ActionBar)

Aggregations

Renderer (com.mta.tehreer.graphics.Renderer)2 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 SpannableString (android.text.SpannableString)1 DisplayMetrics (android.util.DisplayMetrics)1 ListView (android.widget.ListView)1 ActionBar (androidx.appcompat.app.ActionBar)1 IntList (com.mta.tehreer.collections.IntList)1 Typeface (com.mta.tehreer.graphics.Typeface)1 ShapingEngine (com.mta.tehreer.sfnt.ShapingEngine)1 ShapingResult (com.mta.tehreer.sfnt.ShapingResult)1 WritingDirection (com.mta.tehreer.sfnt.WritingDirection)1