-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom font family for codeblocks and inline code on Android (#…
…133)
- Loading branch information
Showing
3 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
36 changes: 32 additions & 4 deletions
36
android/src/main/java/com/expensify/livemarkdown/MarkdownFontFamilySpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
package com.expensify.livemarkdown; | ||
|
||
import android.text.style.TypefaceSpan; | ||
import android.content.res.AssetManager; | ||
import android.graphics.Paint; | ||
import android.graphics.Typeface; | ||
import android.text.TextPaint; | ||
import android.text.style.MetricAffectingSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class MarkdownFontFamilySpan extends TypefaceSpan implements MarkdownSpan { | ||
public MarkdownFontFamilySpan(@NonNull String fontFamily) { | ||
super(fontFamily); | ||
import com.facebook.react.views.text.ReactFontManager; | ||
|
||
public class MarkdownFontFamilySpan extends MetricAffectingSpan implements MarkdownSpan { | ||
|
||
private final @NonNull String mFontFamily; | ||
private final @NonNull AssetManager mAssetManager; | ||
|
||
public MarkdownFontFamilySpan(@NonNull String fontFamily, @NonNull AssetManager assetManager) { | ||
mFontFamily = fontFamily; | ||
mAssetManager = assetManager; | ||
} | ||
|
||
@Override | ||
public void updateMeasureState(@NonNull TextPaint textPaint) { | ||
apply(textPaint); | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) { | ||
apply(tp); | ||
} | ||
|
||
private void apply(@NonNull TextPaint textPaint) { | ||
int style = textPaint.getTypeface().getStyle(); | ||
Typeface typeface = ReactFontManager.getInstance().getTypeface(mFontFamily, style, mAssetManager); | ||
textPaint.setTypeface(typeface); | ||
textPaint.setFlags(textPaint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters