-
-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolves style issues in CustomTypefaceSpan #298
Conversation
When two or more `CustomTypefaceSpan` are applied on a same character sequence, previous `TextPaint`'s style was not respected. Example: -------- **Strong Emphasis _strong emphasis and emphasis combined_** Before the inner text will only have the font applied without respecting that the outer text is strong. Related [bug report](https://issuetracker.google.com/issues/169658958) on Google:
d6583ea
to
6284264
Compare
Hello @c-b-h , thank you for bringing this up 🙌 There is one thing I think we can improve. We can skip the |
Also, I want to mention a case for discussion: when bundling a custom typeface. In most cases we are given multiple typeface files, for example:
So I'm not sure what will happen when using them with |
The reason I didn't skip if same or null is because how public static Typeface create(Typeface family, @Style int style) {
if ((style & ~STYLE_MASK) != 0) {
style = NORMAL;
}
if (family == null) {
family = sDefaultTypeface;
}
// Return early if we're asked for the same face/style
if (family.mStyle == style) {
return family;
}
|
First of all, there is no <font-family xmlns:android="http://schemas.android.com/apk/res/android">
<!-- regular -->
<font
android:font="@font/dr_publik_regular"
android:fontStyle="normal"
android:fontWeight="400" />
<!-- italic -->
<font
android:font="@font/dr_publik_italic"
android:fontStyle="italic"
android:fontWeight="400" />
<!-- bold -->
<font
android:font="@font/dr_publik_bold"
android:fontStyle="normal"
android:fontWeight="700" />
<!-- bold italic -->
<font
android:font="@font/dr_publik_bold_italic"
android:fontStyle="italic"
android:fontWeight="700" />
</font-family> If the
|
Unfortunately, internal code cannot be viewed as the contract - different API levels can have different implementations. Moreover, different devices can have different implementations of internal methods (vendor specific code). So, let's be on a safer side, especially when it is in our control and the change required is small. Thanks for clearing this up for XML-defined fonts. I was referring to fonts bundled with the app in the CustomTypefaceSpan(MyFont.italic()) and then have a system regular font used instead because some text appeared inside other typeface. I see the value in having styles merged, but it seems that it must be done by a new span that makes it explicit and obvious that a font must be creatable by the |
I'll make the appropriate changes in the follow-up commit. The source of Philosophy aside, if you want us to retain the old contract as much as possible, I suggest adding a |
Other changes: • Added flag for enabling merging of styles
Hello @c-b-h , I like the
It should not really, the constructor must've been at least package-private |
When two or more
CustomTypefaceSpan
are applied on a same charactersequence, previous
TextPaint
's style was not respected.Example:
Strong Emphasis strong emphasis and emphasis combined
Before the inner text will only have the font applied without respecting
that the outer text is strong.
Related bug report on Google: