Skip to content

Commit 5d6745b

Browse files
committed
MOPPAND-1750 Another option to create smallCaps text with Android Jetpack Compose.
1 parent 18be9f0 commit 5d6745b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app/src/main/kotlin/ee/ria/DigiDoc/fragment/screen/InitScreen.kt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ import androidx.compose.ui.res.painterResource
4141
import androidx.compose.ui.res.stringResource
4242
import androidx.compose.ui.semantics.semantics
4343
import androidx.compose.ui.semantics.testTagsAsResourceId
44+
import androidx.compose.ui.text.AnnotatedString
45+
import androidx.compose.ui.text.SpanStyle
46+
import androidx.compose.ui.text.buildAnnotatedString
47+
import androidx.compose.ui.text.withStyle
4448
import androidx.compose.ui.tooling.preview.Preview
49+
import androidx.compose.ui.unit.TextUnit
4550
import androidx.navigation.NavHostController
4651
import androidx.navigation.compose.rememberNavController
4752
import ee.ria.DigiDoc.R
@@ -106,9 +111,14 @@ fun InitScreen(
106111
},
107112
)
108113
}
109-
114+
val baseStyle = MaterialTheme.typography.displaySmall
110115
Text(
111-
text = stringResource(id = R.string.ria),
116+
text =
117+
smallCapsText(
118+
text = stringResource(id = R.string.ria),
119+
normalSize = baseStyle.fontSize,
120+
smallCapsSize = baseStyle.fontSize * 0.8f,
121+
),
112122
style = MaterialTheme.typography.displaySmall,
113123
modifier =
114124
modifier
@@ -120,6 +130,29 @@ fun InitScreen(
120130
}
121131
}
122132

133+
fun smallCapsText(
134+
text: String,
135+
normalSize: TextUnit,
136+
smallCapsSize: TextUnit,
137+
): AnnotatedString =
138+
buildAnnotatedString {
139+
text.forEach { ch ->
140+
if (ch.isLowerCase()) {
141+
withStyle(
142+
SpanStyle(fontSize = smallCapsSize),
143+
) {
144+
append(ch.uppercaseChar())
145+
}
146+
} else {
147+
withStyle(
148+
SpanStyle(fontSize = normalSize),
149+
) {
150+
append(ch)
151+
}
152+
}
153+
}
154+
}
155+
123156
@Preview(showBackground = true)
124157
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
125158
@Composable

app/src/main/res/values/donottranslate.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<string name="app_name">RIA DigiDoc</string>
44
<string name="digidoc_all_caps">RIA DIGIDOC</string>
55
<string name="digidoc">RIA DigiDoc</string>
6-
<string name="ria">Rɪɪɢɪ Iɴꜰᴏꜱüꜱᴛᴇᴇᴍɪ Aᴍᴇᴛ</string>
6+
<string name="ria">Riigi Infosüsteemi Amet</string>
77

88
<string name="mobile_id_country_code_and_phone_number_placeholder">372XXXXXXXX</string>
99
<string name="signature_id_card_pin1">PIN1</string>

0 commit comments

Comments
 (0)