Skip to content
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 10 commits into from
Nov 23, 2023

Conversation

dima-avdeev-jb
Copy link

We just added new function Font with lazy getData lambda.
We don't need changes in Skiko library.

@MatkovIvan Where are no good primitives for stream of bytes in Kotlin stdlib (This one declared in ktor.io framework https://api.ktor.io/ktor-io/io.ktor.utils.io/-byte-read-channel/index.html).
Anyway - fonts is not big enought, so be can fully handle it in memory.

@@ -67,13 +67,19 @@ class SystemFont(
*/
class LoadedFont internal constructor(
override val identity: String,
val data: ByteArray,
val getData: () -> ByteArray,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it in public?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is better to make it internal

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @see FontFamily
*/
@Deprecated(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid deprecation, just add new overload

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

@@ -108,10 +114,10 @@ class LoadedFont internal constructor(
*/
fun Font(
identity: String,
data: ByteArray,
getData: () -> ByteArray,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getData: () -> ByteArray,
data: () -> ByteArray,

or

Suggested change
getData: () -> ByteArray,
dataReader: () -> ByteArray,

Copy link
Author

Choose a reason for hiding this comment

The 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.

override val weight: FontWeight,
override val style: FontStyle
) : PlatformFont() {
@ExperimentalTextApi
override val loadingStrategy: FontLoadingStrategy = FontLoadingStrategy.Blocking

val data: ByteArray get() = getData()

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 lambda

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion! Done!

This reverts commit ccc9c7f.
@MatkovIvan MatkovIvan dismissed their stale review November 22, 2023 09:46

Blocker has been fixed

@dima-avdeev-jb dima-avdeev-jb merged commit 0b8aa46 into jb-main Nov 23, 2023
4 checks passed
@dima-avdeev-jb dima-avdeev-jb deleted the dima.avdeev/Font-with-lazy-getData branch November 23, 2023 04:59
mazunin-v-jb pushed a commit that referenced this pull request Dec 7, 2023
We just added new function Font with lazy getData lambda.
We don't need changes in Skiko library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants