Skip to content

Commit 0cbdc41

Browse files
authored
Repro issue with font loading on Windows (#2074)
1 parent 79034b4 commit 0cbdc41

File tree

11 files changed

+184
-1
lines changed

11 files changed

+184
-1
lines changed

paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/instrumentation/ResourcesCompatVisitorFactory.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ internal abstract class ResourcesCompatVisitorFactory : AsmClassVisitorFactory<I
4141
private class LoadFontVisitor(api: Int, delegate: MethodVisitor) : MethodVisitor(api, delegate) {
4242
override fun visitMethodInsn(opcode: Int, owner: String, name: String, descriptor: String, isInterface: Boolean) {
4343
if ("startsWith" == name) {
44-
super.visitMethodInsn(opcode, owner, "contains", "(Ljava/lang/CharSequence;)Z", isInterface)
44+
// Skip calls to `startsWith`, return true
45+
super.visitInsn(Opcodes.POP) // Pop the arg being passed to `startsWith`, which is "res/"
46+
super.visitInsn(Opcodes.POP) // Pop the receiver of `startsWith`, which is the font file path
47+
super.visitLdcInsn(1) // Push `1` to the stack, as if `startsWith` returned true
4548
} else {
4649
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
4750
}

paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ class PaparazziPluginTest {
209209
assertThat(snapshotsDir.exists()).isTrue()
210210
}
211211

212+
@Test
213+
fun resourceMultiModule() {
214+
val fixtureRoot = File("src/test/projects/resource-multi-module")
215+
216+
gradleRunner
217+
.withArguments("verifyPaparazziDebug", "--stacktrace")
218+
.forwardOutput()
219+
.runFixture(fixtureRoot) { build() }
220+
}
221+
212222
@Test
213223
fun invalidChars() {
214224
val fixtureRoot = File("src/test/projects/invalid-chars")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
id 'org.jetbrains.kotlin.plugin.compose'
5+
id 'app.cash.paparazzi'
6+
}
7+
8+
android {
9+
namespace = 'app.cash.paparazzi.plugin.test'
10+
compileSdk = libs.versions.compileSdk.get() as int
11+
defaultConfig {
12+
minSdk = libs.versions.minSdk.get() as int
13+
}
14+
compileOptions {
15+
sourceCompatibility = libs.versions.javaTarget.get()
16+
targetCompatibility = libs.versions.javaTarget.get()
17+
}
18+
kotlinOptions {
19+
jvmTarget = libs.versions.javaTarget.get()
20+
}
21+
buildFeatures {
22+
compose = true
23+
}
24+
}
25+
26+
dependencies {
27+
implementation project(':typography')
28+
29+
implementation libs.composeUi.material
30+
implementation libs.androidx.appcompat
31+
}
32+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
~ Copyright (C) 2018 The Android Open Source Project
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
<manifest package="app.cash.paparazzi.plugin.test">
17+
</manifest>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package app.cash.paparazzi.plugin.test
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.material.MaterialTheme
7+
import androidx.compose.material.Text
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.graphics.Color
11+
import androidx.compose.ui.text.TextStyle
12+
import app.cash.paparazzi.plugin.typography.GreatVibes
13+
14+
@Composable
15+
fun CustomFont() {
16+
MaterialTheme {
17+
Box(Modifier.fillMaxSize().background(color = Color.White)) {
18+
Text(
19+
text = "Hello, Paparazzi!",
20+
style = TextStyle(
21+
fontFamily = GreatVibes
22+
)
23+
)
24+
}
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2020 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package app.cash.paparazzi.plugin.test
17+
18+
import android.widget.LinearLayout
19+
import app.cash.paparazzi.Paparazzi
20+
import org.junit.Rule
21+
import org.junit.Test
22+
23+
class VerifyTest {
24+
@get:Rule
25+
val paparazzi = Paparazzi()
26+
27+
@Test
28+
fun verify() {
29+
paparazzi.snapshot {
30+
CustomFont()
31+
}
32+
}
33+
}
5.88 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apply from: '../test.settings.gradle'
2+
3+
include ':app'
4+
include ':typography'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
id 'org.jetbrains.kotlin.plugin.compose'
5+
}
6+
7+
android {
8+
namespace = 'app.cash.paparazzi.plugin.typography'
9+
compileSdk = libs.versions.compileSdk.get() as int
10+
defaultConfig {
11+
minSdk = libs.versions.minSdk.get() as int
12+
}
13+
compileOptions {
14+
sourceCompatibility = libs.versions.javaTarget.get()
15+
targetCompatibility = libs.versions.javaTarget.get()
16+
}
17+
kotlinOptions {
18+
jvmTarget = libs.versions.javaTarget.get()
19+
}
20+
buildFeatures {
21+
compose = true
22+
}
23+
}
24+
25+
dependencies {
26+
implementation libs.composeUi.material
27+
implementation libs.androidx.appcompat
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2020 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package app.cash.paparazzi.plugin.typography
17+
18+
import androidx.compose.ui.text.font.Font
19+
import androidx.compose.ui.text.font.FontFamily
20+
import androidx.compose.ui.text.font.FontStyle
21+
import androidx.compose.ui.text.font.FontWeight
22+
import app.cash.paparazzi.plugin.typography.R
23+
24+
val GreatVibes = FontFamily(
25+
Font(
26+
resId = R.font.cashmarket_medium_normal,
27+
weight = FontWeight.Normal,
28+
FontStyle.Normal
29+
)
30+
)

0 commit comments

Comments
 (0)