forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support configurable vertical centering via `LineHeightStyle.Alignmen…
…t` (#1569) Fixes JetBrains/compose-multiplatform#2602 ([CMP-2602](https://youtrack.jetbrains.com/issue/CMP-2602)) Desktop | Android --- | --- <img width="400" src="/~https://github.com/user-attachments/assets/5428e2a4-3a11-4755-8bc7-b66177bcc2a8"> | <img width="400" src="/~https://github.com/user-attachments/assets/67db44bc-a41d-4c23-9245-aab6fee07f3e"> ## Testing Added a sample page into mpp demo This should be tested by QA ## Release Notes ### Features - Multiple Platforms - Support configurable vertical text centering via `LineHeightStyle.Alignment`
- Loading branch information
1 parent
d96615c
commit 5b07907
Showing
11 changed files
with
499 additions
and
118 deletions.
There are no files selected for viewing
76 changes: 0 additions & 76 deletions
76
compose/mpp/demo/src/commonMain/kotlin/androidx/compose/mpp/demo/FontRasterization.kt
This file was deleted.
Oops, something went wrong.
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
110 changes: 110 additions & 0 deletions
110
...demo/src/commonMain/kotlin/androidx/compose/mpp/demo/components/text/FontRasterization.kt
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.mpp.demo.components.text | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.ExperimentalTextApi | ||
import androidx.compose.ui.text.FontHinting | ||
import androidx.compose.ui.text.FontRasterizationSettings | ||
import androidx.compose.ui.text.FontSmoothing | ||
import androidx.compose.ui.text.PlatformParagraphStyle | ||
import androidx.compose.ui.text.PlatformTextStyle | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.dp | ||
|
||
@OptIn(ExperimentalTextApi::class) | ||
@Composable | ||
fun FontRasterization() { | ||
val state = rememberScrollState() | ||
Column( | ||
modifier = Modifier.fillMaxSize().padding(10.dp).verticalScroll(state), | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
val hintingOptions = listOf(FontHinting.None, FontHinting.Slight, FontHinting.Normal, FontHinting.Full) | ||
val isAutoHintingForcedOptions = listOf(false, true) | ||
val subpixelOptions = listOf(false, true) | ||
val smoothingOptions = listOf(FontSmoothing.None, FontSmoothing.AntiAlias, FontSmoothing.SubpixelAntiAlias) | ||
val text = "Lorem ipsum" | ||
|
||
for (hinting in hintingOptions) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
for (smoothing in smoothingOptions) { | ||
Column( | ||
modifier = Modifier.weight(1f).border(1.dp, Color.Black).padding(10.dp), | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
for (subpixel in subpixelOptions) { | ||
for (autoHintingForced in isAutoHintingForcedOptions) { | ||
FontRasterizationSample( | ||
text = text, | ||
modifier = Modifier.offset(x = 0.25.dp, y = 0.25.dp), | ||
hinting = hinting, | ||
smoothing = smoothing, | ||
subpixelPositioning = subpixel, | ||
autoHintingForced = autoHintingForced | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalTextApi::class) | ||
@Composable | ||
private fun FontRasterizationSample( | ||
text: String, | ||
modifier: Modifier, | ||
hinting: FontHinting, | ||
smoothing: FontSmoothing, | ||
subpixelPositioning: Boolean, | ||
autoHintingForced: Boolean | ||
) { | ||
BasicText( | ||
text = text, | ||
modifier = modifier, | ||
style = TextStyle( | ||
platformStyle = PlatformTextStyle( | ||
spanStyle = null, | ||
paragraphStyle = PlatformParagraphStyle( | ||
fontRasterizationSettings = FontRasterizationSettings( | ||
smoothing = smoothing, | ||
hinting = hinting, | ||
subpixelPositioning = subpixelPositioning, | ||
autoHintingForced = autoHintingForced | ||
) | ||
) | ||
) | ||
) | ||
) | ||
} |
Oops, something went wrong.