Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51085a46 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix test failure due to missing Roboto VF font

Due to b/189235998, the weight 400 of default font is no longer a
VF font. To be able to test the interpolation of variable font,
create Typeface manually for testing purposes.

Bug: 190623361
Test: atest TextInterpolatorTest
Change-Id: I4ef5f5b98f8f5af75e5c30121ace0e2d9b30a649
parent 33f8e116
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.keyguard

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Typeface
import android.graphics.fonts.Font
import android.graphics.fonts.FontFamily
import android.testing.AndroidTestingRunner
import android.text.Layout
import android.text.StaticLayout
@@ -29,6 +32,7 @@ import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
import kotlin.math.ceil

private const val TEXT = "Hello, World."
@@ -36,16 +40,24 @@ private const val BIDI_TEXT = "abc\u05D0\u05D1\u05D2"
private const val BMP_WIDTH = 400
private const val BMP_HEIGHT = 300

// Due to b/189235998 the weight 400 of the default font is no longer variable font. To be able to
// test variable behavior, create the interpolatable typefaces with manually here.
private val VF_FONT = Font.Builder(File("/system/fonts/Roboto-Regular.ttf")).build()

private fun Font.toTypeface() =
        Typeface.CustomFallbackBuilder(FontFamily.Builder(this).build()).build()

private val PAINT = TextPaint().apply {
    typeface = Font.Builder(VF_FONT).setFontVariationSettings("'wght' 400").build().toTypeface()
    textSize = 32f
}

private val START_PAINT = TextPaint(PAINT).apply {
    fontVariationSettings = "'wght' 400"
    typeface = Font.Builder(VF_FONT).setFontVariationSettings("'wght' 400").build().toTypeface()
}

private val END_PAINT = TextPaint(PAINT).apply {
    fontVariationSettings = "'wght' 700"
    typeface = Font.Builder(VF_FONT).setFontVariationSettings("'wght' 700").build().toTypeface()
}

@RunWith(AndroidTestingRunner::class)