<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Can Yumusak</title>
    <description>The latest articles on DEV Community by Can Yumusak (@canyudev).</description>
    <link>https://dev.to/canyudev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F833649%2F2955a23b-eaab-4323-82b5-b347e07a5440.png</url>
      <title>DEV Community: Can Yumusak</title>
      <link>https://dev.to/canyudev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/canyudev"/>
    <language>en</language>
    <item>
      <title>Android and Figma Typography and how to achieve 100% fidelity</title>
      <dc:creator>Can Yumusak</dc:creator>
      <pubDate>Tue, 29 Mar 2022 09:00:11 +0000</pubDate>
      <link>https://dev.to/canyudev/android-and-figma-typography-and-how-to-achieve-100-fidelity-l40</link>
      <guid>https://dev.to/canyudev/android-and-figma-typography-and-how-to-achieve-100-fidelity-l40</guid>
      <description>&lt;h3&gt;
  
  
  Post-Compose 1.2.0 Update
&lt;/h3&gt;

&lt;p&gt;The following article still stays relevant since it dives deep into how Android places characters, using mechanisms from it's underlying render engine (Skia). The Google team has since made this process way easier by allowing devs to setup their typography similary to Figma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        TextStyle(
            lineHeight = 2.5.em,
            platformStyle = PlatformTextStyle(
                includeFontPadding = false
            ),
            lineHeightStyle = LineHeightStyle(
                alignment = LineHeightStyle.Alignment.Center,
                trim = LineHeightStyle.Trim.None
            )
        )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please make sure to set the &lt;code&gt;lineHeight&lt;/code&gt; property to the value you find in Figma, since Compose will otherwise choose a different height.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/androiddevelopers/fixing-font-padding-in-compose-text-768cd232425b" rel="noopener noreferrer"&gt;Here's a more in-depth article&lt;/a&gt; by Google about the new settings.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Article
&lt;/h1&gt;

&lt;p&gt;I have been working on Android UI for quite some time now. Getting the typography right compared to a Figma design was always something I winged without getting a more profound understanding as to how and why one is different from the other. Welp, since I got to work on setting up the typo yet another time, I decided it should have a little more foundation this time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Let's quickly pick up the Font "Nationale", draw a Text in Jetpack Compose and the same Text in Figma and compare them:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h8d1pqgosvflsnnf0l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h8d1pqgosvflsnnf0l6.png" alt="Image description" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Android screenshot has a yellow background; the Figma screenshot has a  blue one. The following problems appear when comparing Figma with Android behavior:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The line heights are different (Android bigger than Figma, although slightly)&lt;/li&gt;
&lt;li&gt;The placement inside the text box is different (Android is a little more "down" than Figma)&lt;/li&gt;
&lt;li&gt;The line-height specified in Android is only considered for texts with more than one line. The result is having two lines resulting in a total size of "line-height + text height" (instead of 2x line-height).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is &lt;a href="https://unicorn-utterances.com/posts/hard-grids-and-baselines-android-design-fidelity" rel="noopener noreferrer"&gt;this article&lt;/a&gt; from Eduardo Pratti, which suggests comparing the placement and adding paddings to the top and bottom of the Android view (via "firstBaselineToTopHeight") to make up for the different arrangements. This advice is fantastic and probably satisfies the need of most.&lt;/p&gt;

&lt;p&gt;However, I had a use-case where we wanted arbitrary line-heights and font sizes derived from shared design tokens. I didn't want to admit to the other platforms that we needed two more tokens in platform-agnostic code per text style to fix a shortcoming on the Android side.&lt;/p&gt;

&lt;p&gt;I wanted to get to the bottom of the differences and systematically understand what both platforms are doing to fix the issue. Let's try to understand the behaviors of each first to achieve our goal!&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Android places text?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://proandroiddev.com/android-and-typography-101-5f06722dd611" rel="noopener noreferrer"&gt;This iconic article&lt;/a&gt; from 2017 lays the foundation to understand Android typography. Essentially the Android OS extracts "FontMetrics" from each font, which describes the following values:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;top&lt;/strong&gt;: This value is computed by Skia and is the topmost point of all glyphs in the font.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bottom&lt;/strong&gt;:  This value is computed by Skia and is the bottommost point of all glyphs in the font.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ascent&lt;/strong&gt;: This value is chosen by the font designer and represents the recommended distance above the baseline for any text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;descent&lt;/strong&gt;: This value is chosen by the font designer and represents the recommended distance below the baseline for any text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;leading&lt;/strong&gt;: This value is chosen by the font designer and represents the recommended distance between two lines.&lt;/p&gt;

&lt;p&gt;Note that these metrics are a property of the font, thus independent of the string!&lt;br&gt;
Skia is the underlying graphics engine. Essentially the Android Canvas is a wrapper for the Skia Canvas. So if you call "Paint.fontMetrics" you essentially ask Skia to give you the Font Metrics. See this &lt;a href="https://api.skia.org/structSkFontMetrics.html" rel="noopener noreferrer"&gt;Skia documentation&lt;/a&gt; of FontMetrics. I use an OpenType font, and other font formats may lead to different results.&lt;/p&gt;

&lt;p&gt;Let's have a look at the values of the "Nationale" font on Android (I wrote a small tool to visualize these, you can get it &lt;a href="https://github.com/CanYumusak/FontAnalyzer" rel="noopener noreferrer"&gt;here&lt;/a&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93diitjt79p0y6hn8fg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93diitjt79p0y6hn8fg8.png" alt="FontAnalyzer" width="724" height="1078"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The yellow background shows the area of the text composable or the size of the TextView. That area extends between the "top" and the "bottom" line.&lt;/p&gt;

&lt;p&gt;This means that the height of our "TextView" / "Text Composeable" for a single line of text will be &lt;code&gt;ceil(bottom - top)&lt;/code&gt;, in our case this amounts to &lt;code&gt;ceil(93,94 + 381,15) = 476&lt;/code&gt;. The main reason for this is Androids &lt;a href="https://developer.android.com/reference/android/widget/TextView#attr_android:includeFontPadding" rel="noopener noreferrer"&gt;includeFontPadding&lt;/a&gt; property which can't be turned off in Compose currently.&lt;/p&gt;
&lt;h2&gt;
  
  
  How does Figma places text?
&lt;/h2&gt;

&lt;p&gt;Let's render the text in Figma:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbphcgmnzux2pzadcgno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqbphcgmnzux2pzadcgno.png" alt="Image description" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The visual comparison suggests that Figma uses "ascent" and "descent" as the limits of the text box. A quick calculation confirms that numbers add up as well: &lt;code&gt;115,50 - (-346,50) = 462,0&lt;/code&gt;; 462 is exactly the line-height chosen by Figma.&lt;/p&gt;

&lt;p&gt;So that's a great success! We are now aware of how Android and Figma place text and can account for that. But your designer might want to have a larger line-height than what Figma picks. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3hndrd83kxg2rbx9w5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3hndrd83kxg2rbx9w5y.png" alt="Image description" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So let's increase the Figma line-height to 1000 and look at the result: Figma adds 269 points - which is &lt;code&gt;(1000 - 462) / 2&lt;/code&gt; - to the top and the bottom (adding more to the bottom when the amount is not even). We can safely conclude that Figma centers the area between ascent and descent inside the line-height.&lt;/p&gt;

&lt;p&gt;That's is excellent! We now know how Figma places text inside its available space and can emulate this in Compose.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;So let's recap what we need to do: Make sure that line-heights are also respected for single-line text and shift the placement of the text so that it imitates Figmas behavior.&lt;/p&gt;
&lt;h3&gt;
  
  
  Figma-like Line Height
&lt;/h3&gt;

&lt;p&gt;Let's reason about the first issue: We could wrap our text in a &lt;code&gt;Box&lt;/code&gt; and give it the correct height. Unfortunately, we are not aware of how many lines the text will have when placing our &lt;code&gt;Box&lt;/code&gt;, thus making it difficult to specify the correct height. However, we could leverage Composes feature of using layout modifiers which will let us modify the height &lt;em&gt;and&lt;/em&gt; the placement. Let's try that approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class FigmaTextModifier : LayoutModifier {
    override fun MeasureScope.measure(
        measurable: Measurable,
        constraints: Constraints
    ): MeasureResult {
        TODO("Not yet implemented")
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When developers implement a Figma design, they usually have use defined line-height. So let's assume that line-height is a constant which is correctly set in its &lt;code&gt;TextStyle&lt;/code&gt;. Our first challenge is computing the number of lines the text has. We cannot access the text computation results, but we have the total intended height. Using our knowledge that all lines after the first are a multiple of &lt;code&gt;lineHeight&lt;/code&gt; and the fact that compose gives us alignment lines, we can infer our count:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  private val lineHeight: TextUnit
    get() = textStyle.lineHeight

private fun Density.lineCount(placeable: Placeable): Int {
    val firstToLast = (placeable[LastBaseline] - placeable[FirstBaseline]).toFloat()
    return (firstToLast / lineHeight.toPx()).roundToInt() + 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we know the line-height and the number of lines! Consequently, we can compute the height we would like to achieve. Let's assume we want to center the text in the available space for now. The &lt;code&gt;measure&lt;/code&gt; method equates to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun MeasureScope.measure(
    measurable: Measurable,
    constraints: Constraints
): MeasureResult {
    val placeable = measurable.measure(constraints)
    val lineCount = lineCount(placeable)
    val fullHeight = (lineHeight.toPx() * lineCount).roundToInt()
    return layout(width = placeable.width, height = fullHeight) {
        placeable.placeRelative(
            x = 0,
            y = Alignment.CenterVertically.align(
                placeable.height,
                fullHeight
            )
        )
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this is a win in our books. However, Compose has a mechanism called "Intrinsics". They allow getting the minimum and maximum sizes of a layout node before it is measured. Intrinsics are very useful to avoid two measurement passes (which are not simply not allowed and will crash in Compose). &lt;br&gt;
 Since we do not have access to alignment lines when computing intrinsics, we need to find a different way to calculate the correct height. One naive way is just rounding the size to the next multiple of &lt;code&gt;lineHeight&lt;/code&gt;. This assumption is only valid if the specified &lt;code&gt;lineHeight&lt;/code&gt; is not smaller than the text height. We could get to a more elaborate calculation that correctly behaves when that's the case, but let's keep things simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    override fun IntrinsicMeasureScope.maxIntrinsicHeight(
        measurable: IntrinsicMeasurable,
        width: Int
    ): Int {
        return ceilToLineHeight(measurable.maxIntrinsicHeight(width))
    }

    override fun IntrinsicMeasureScope.minIntrinsicHeight(
        measurable: IntrinsicMeasurable,
        width: Int
    ): Int {
        return ceilToLineHeight(measurable.minIntrinsicHeight(width))
    }

    override fun IntrinsicMeasureScope.minIntrinsicWidth(
        measurable: IntrinsicMeasurable,
        height: Int
    ): Int {
        return measurable.minIntrinsicWidth(height)
    }

    override fun IntrinsicMeasureScope.maxIntrinsicWidth(
        measurable: IntrinsicMeasurable,
        height: Int
    ): Int {
        return measurable.maxIntrinsicWidth(height)
    }

    private fun Density.ceilToLineHeight(value: Int): Int {
        val lineHeightPx = lineHeight.toPx()
        return (ceil(value.toFloat() / lineHeightPx) * lineHeightPx).roundToInt()
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! We achieved the same line heights as Figma and now need to account for the placement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Figma-like Text Placement
&lt;/h3&gt;

&lt;p&gt;Our knowledge of Figmas and Android text placement rests on font metrics. So the first thing we need is getting access to the &lt;code&gt;FontMetrics&lt;/code&gt;. We thus need to build a &lt;code&gt;Paint&lt;/code&gt; object with the &lt;code&gt;typeface&lt;/code&gt; and &lt;code&gt;textSize&lt;/code&gt; values correctly set. It may be easy to build such a &lt;code&gt;Paint&lt;/code&gt; instance if you have complete knowledge of your typography. If you do not, you will need to duplicate the &lt;code&gt;TypefaceAdapter&lt;/code&gt; which Compose UI for Android uses internally. Let's skip the computation to shorten this already long article. &lt;code&gt;TypefaceAdapter&lt;/code&gt; handles font matching based on the given font attributes and caches the result to get quicker access on subsequent calls. If you want to read more on how Compose paints text on the Canvas &lt;code&gt;AndroidParagraphIntrinsics&lt;/code&gt; may be a good entry point.&lt;/p&gt;

&lt;p&gt;Let's assume that we know our font and just detail on the &lt;code&gt;FontMetrics&lt;/code&gt; part. For my use-case I decided to wrap &lt;code&gt;TextStyle&lt;/code&gt; with a custom object which brings knowledge about the font:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private fun Density.fontMetrics(context: Context, textStyle: WaveTextStyle): Paint.FontMetrics {
    val fontResourceId = textStyle.fonts[textStyle.fontWeight]!!
    val font = ResourcesCompat.getFont(context, fontResourceId)
    val paint = Paint().also {
        it.typeface = font
        it.textSize = textStyle.fontSize.toPx()
    }

    return paint.fontMetrics
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we have the &lt;code&gt;FontMetrics&lt;/code&gt; object, all we need to do is recall the difference between Figma and our Text: Figma centers between "ascent" and "descent" while Android centers between "top" and "bottom". All we need to do is adjust for that difference. How? Let's do some math.&lt;/p&gt;

&lt;p&gt;We need to find out how much we need to vertically offset our text for it to match the Figma placement. In other words, we need to find out two things: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How much offset from the top of the line does Figma use? We will call this &lt;code&gt;centerOffset&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;How much do I need to adjust for the differences between Android and Figma? We will call this &lt;code&gt;figmaOffset&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the &lt;code&gt;centerOffset&lt;/code&gt; we take our line-height, substract our ascent-descent distance and divide the rest by two. Also we need to floor that amount - remember that Figma favors the bottom when partitioning space? Thus the calculation will need to be in DP. The result looks a bit scary but:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val centerOffset = floor((lineHeight.toPx().toDp() - fontMetrics.descent.toDp() + fontMetrics.ascent.toDp()).value / 2f).dp.toPx().toInt()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thankfully the &lt;code&gt;figmaOffset&lt;/code&gt; is much easier to calculate. All we need to do is take the difference between aligning from "top" and aligning from "ascent" into account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;val figmaOffset = fontMetrics.ascent - fontMetrics.top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In sum, this means that our placement logic looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun MeasureScope.measure(
        measurable: Measurable,
        constraints: Constraints
    ): MeasureResult {
        val placeable = measurable.measure(constraints)
        val lineCount = lineCount(placeable)
        val fullHeight = (lineHeight.toPx() * lineCount).roundToInt()
        val fontMetrics = fontMetrics(context, style)
        val centerOffset = floor((lineHeight.toPx().toDp() - fontMetrics.descent.toDp() + fontMetrics.ascent.toDp()).value / 2f).dp.toPx().toInt()
        val figmaOffset = fontMetrics.ascent - fontMetrics.top
        return layout(width = placeable.width, height = fullHeight) {
            // Alignment lines are recorded with the parents automatically.
            placeable.placeRelative(
                x = 0,
                y = (centerOffset - figmaOffset).toInt()
            )
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Result
&lt;/h2&gt;

&lt;p&gt;Let's put the result near the Figma text again:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bmn0s11ldmrsjjstpqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bmn0s11ldmrsjjstpqw.png" alt="Image description" width="800" height="247"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;A perfect match! Since putting together all the snippets is tedious work, I have built a little gist that captures the essence of the adjustments needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/CanYumusak/34e6620f444d5ba0c8f7419362d5d394" rel="noopener noreferrer"&gt;The final code as gist&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Compose 1.2.0
&lt;/h2&gt;

&lt;p&gt;In other news, Google currently works on massively improving the Compose Text API.&lt;br&gt;
Adjustments of line-height are happening &lt;a href="https://issuetracker.google.com/issues/181155707#comment5" rel="noopener noreferrer"&gt;on this tracker&lt;/a&gt;. There is even a finished prototype implementation &lt;a href="https://android-review.googlesource.com/c/platform/frameworks/support/+/2045372" rel="noopener noreferrer"&gt;for the line-height adjustment&lt;/a&gt;.&lt;br&gt;
The difference of text placement between Figma and Compose will be fixed with Compose 1.2.0 as well, since &lt;code&gt;includeFontPadding&lt;/code&gt; is set to false for all texts with &lt;a href="https://android-review.googlesource.com/c/platform/frameworks/support/+/1992050" rel="noopener noreferrer"&gt;this PR&lt;/a&gt; - it is already part of Compose 1.2.0-alpha05, see &lt;a href="https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0-alpha05" rel="noopener noreferrer"&gt;release notes&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;So if you are not in a hurry, you can wait for Compose 1.2.0 to include the new &lt;code&gt;LineHeightBehaviour&lt;/code&gt; API. With the new text API, fidelity should be attainable with only the tools Compose provides.&lt;/p&gt;

&lt;p&gt;I will follow up with a post-"Compose 1.2.0" guide once it hits beta status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Acknowledgements
&lt;/h2&gt;

&lt;p&gt;I want to thank Helios Alonso from the Square team at Block, who had put a lot of groundwork together and assisted me, especially with the maths!&lt;/p&gt;

</description>
      <category>android</category>
    </item>
  </channel>
</rss>
