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

minor note about matchFamilyStyle that doesn't work #698

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions skiko/src/commonMain/kotlin/org/jetbrains/skia/FontStyle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ class FontStyle {
val _value: Int

constructor(weight: Int, width: Int, slant: FontSlant) {
_value = weight and 65535 or (width and 255 shl 16) or (slant.ordinal shl 24)
_value = (weight and 0xFFFF) or
Copy link
Member

Choose a reason for hiding this comment

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

Can we add require or similar thing to print readable message in case of overflow?

((width and 0xFF) shl 16) or
((slant.ordinal and 0xFF) shl 24)
}

internal constructor(value: Int) {
_value = value
}

val weight: Int
get() = _value and 65535
get() = _value and 0xFFFF

fun withWeight(weight: Int): FontStyle {
return FontStyle(weight, width, slant)
}

val width: Int
get() = _value shr 16 and 255
get() = (_value shr 16) and 0xFF

fun withWidth(width: Int): FontStyle {
return FontStyle(weight, width, slant)
}

val slant: FontSlant
get() = FontSlant.values()[_value shr 24 and 255]
get() = FontSlant.values()[(_value shr 24) and 0xFF]

fun withSlant(slant: FontSlant): FontStyle {
return FontStyle(weight, width, slant)
Expand All @@ -43,10 +45,7 @@ class FontStyle {
}

override fun hashCode(): Int {
val PRIME = 59
var result = 1
result = result * PRIME + _value
return result
return _value
}

companion object {
Expand Down
9 changes: 9 additions & 0 deletions skiko/src/commonTest/kotlin/org/jetbrains/skia/FontMgrTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class FontMgrTest {
assertEquals(jbMono, styleSet.matchStyle(FontStyle.ITALIC))
}

/*
when `TypefaceFontProvider` is used
`matchFamilyStyle` always returns null,
even if we have an appropriate styles in styleSet returned by `matchFamily`
It should be fixed in skia at some point
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 add TODO mark here

*/
assertNull(fontManager.matchFamilyStyle(null, FontStyle.NORMAL))
assertNull(fontManager.matchFamilyStyle("JetBrains Mono", FontStyle.NORMAL))

assertNull(fontManager.matchFamilyStyle("JetBrains Mono", FontStyle.BOLD))
assertNull(fontManager.matchFamilyStyle("Interface", FontStyle.NORMAL))

Expand Down