forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Font with lazy get data in skikoMain #906
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
130b114
Font with lazy getData in skikoMain
dima-avdeev-jb 6072f2c
doc
dima-avdeev-jb 79bbbf8
remove redundant spaces
dima-avdeev-jb 1986b95
Deprecation annotation
dima-avdeev-jb bdb5600
Fix backward compatibility
dima-avdeev-jb 4f58e7e
Deprecation warning
dima-avdeev-jb 273d711
remove deprecation warning and made getData as internal value
dima-avdeev-jb 0b2fdd4
update ui-text.api
dima-avdeev-jb ccc9c7f
val data by lazy {
dima-avdeev-jb 7e1dd1f
Revert "val data by lazy {"
dima-avdeev-jb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -57,7 +57,7 @@ class SystemFont( | |||||||||
* Defines a Font using byte array with loaded font data. | ||||||||||
* | ||||||||||
* @param identity Unique identity for a font. Used internally to distinguish fonts. | ||||||||||
* @param data Byte array with loaded font data. | ||||||||||
* @param getData should return Byte array with loaded font data. | ||||||||||
* @param weight The weight of the font. The system uses this to match a font to a font request | ||||||||||
* that is given in a [androidx.compose.ui.text.SpanStyle]. | ||||||||||
* @param style The style of the font, normal or italic. The system uses this to match a font to a | ||||||||||
|
@@ -67,13 +67,15 @@ class SystemFont( | |||||||||
*/ | ||||||||||
class LoadedFont internal constructor( | ||||||||||
override val identity: String, | ||||||||||
val data: ByteArray, | ||||||||||
internal val getData: () -> ByteArray, | ||||||||||
override val weight: FontWeight, | ||||||||||
override val style: FontStyle | ||||||||||
) : PlatformFont() { | ||||||||||
@ExperimentalTextApi | ||||||||||
override val loadingStrategy: FontLoadingStrategy = FontLoadingStrategy.Blocking | ||||||||||
|
||||||||||
val data: ByteArray get() = getData() | ||||||||||
|
||||||||||
override fun equals(other: Any?): Boolean { | ||||||||||
if (this === other) return true | ||||||||||
if (other !is LoadedFont) return false | ||||||||||
|
@@ -98,7 +100,7 @@ class LoadedFont internal constructor( | |||||||||
* Creates a Font using byte array with loaded font data. | ||||||||||
* | ||||||||||
* @param identity Unique identity for a font. Used internally to distinguish fonts. | ||||||||||
* @param data Byte array with loaded font data. | ||||||||||
* @param getData should return Byte array with loaded font data. | ||||||||||
* @param weight The weight of the font. The system uses this to match a font to a font request | ||||||||||
* that is given in a [androidx.compose.ui.text.SpanStyle]. | ||||||||||
* @param style The style of the font, normal or italic. The system uses this to match a font to a | ||||||||||
|
@@ -108,10 +110,10 @@ class LoadedFont internal constructor( | |||||||||
*/ | ||||||||||
fun Font( | ||||||||||
identity: String, | ||||||||||
data: ByteArray, | ||||||||||
getData: () -> ByteArray, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, better to leave getData(). It is simple name for this case. |
||||||||||
weight: FontWeight = FontWeight.Normal, | ||||||||||
style: FontStyle = FontStyle.Normal | ||||||||||
): Font = LoadedFont(identity, data, weight, style) | ||||||||||
): Font = LoadedFont(identity, getData, weight, style) | ||||||||||
|
||||||||||
private class SkiaBackedTypeface( | ||||||||||
alias: String?, | ||||||||||
|
@@ -121,6 +123,30 @@ private class SkiaBackedTypeface( | |||||||||
override val fontFamily: FontFamily? = null | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Creates a Font using byte array with loaded font data. | ||||||||||
* | ||||||||||
* @param identity Unique identity for a font. Used internally to distinguish fonts. | ||||||||||
* @param data Byte array with loaded font data. | ||||||||||
* @param weight The weight of the font. The system uses this to match a font to a font request | ||||||||||
* that is given in a [androidx.compose.ui.text.SpanStyle]. | ||||||||||
* @param style The style of the font, normal or italic. The system uses this to match a font to a | ||||||||||
* font request that is given in a [androidx.compose.ui.text.SpanStyle]. | ||||||||||
* | ||||||||||
* @see FontFamily | ||||||||||
*/ | ||||||||||
fun Font( | ||||||||||
identity: String, | ||||||||||
data: ByteArray, | ||||||||||
weight: FontWeight = FontWeight.Normal, | ||||||||||
style: FontStyle = FontStyle.Normal | ||||||||||
): Font = Font( | ||||||||||
identity = identity, | ||||||||||
getData = { data }, | ||||||||||
weight = weight, | ||||||||||
style = style, | ||||||||||
) | ||||||||||
|
||||||||||
/** | ||||||||||
* Returns a Compose [Typeface] from Skia [SkTypeface]. | ||||||||||
* | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but maybe better to make it
by lazy
to avoid unexpected multirun for the lambdaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggestion! Done!