From 57120ab563bc06e06368865560a197f98c374296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20W=C3=BCrthner?= Date: Tue, 12 Nov 2024 14:13:42 +0100 Subject: [PATCH] Fix Android raster scales --- .../main/kotlin/com/iodigital/figex/api/FigmaApi.kt | 6 +++++- .../com/iodigital/figex/models/figex/FigExConfig.kt | 10 +++++----- samples/config.json | 11 ++++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/figex-core/src/main/kotlin/com/iodigital/figex/api/FigmaApi.kt b/figex-core/src/main/kotlin/com/iodigital/figex/api/FigmaApi.kt index 370740b..4679449 100644 --- a/figex-core/src/main/kotlin/com/iodigital/figex/api/FigmaApi.kt +++ b/figex-core/src/main/kotlin/com/iodigital/figex/api/FigmaApi.kt @@ -48,6 +48,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.withContext import java.io.File +import java.io.IOException import java.io.OutputStream import java.lang.Math.random import javax.imageio.ImageIO @@ -227,9 +228,12 @@ class FigmaApi( if (format == Webp) { debug(tag = tag, message = " Inline converting PNG => WEBP: $tmpFile") val png = ImageIO.read(tmpFile) - ImageIO.write(png, "webp", out) + if(!ImageIO.write(png, "webp", out)) { + throw IOException("Writing of WEBP $id failed") + } } } finally { + out.close() requestCount.update { it - 1 } } } diff --git a/figex-core/src/main/kotlin/com/iodigital/figex/models/figex/FigExConfig.kt b/figex-core/src/main/kotlin/com/iodigital/figex/models/figex/FigExConfig.kt index 7193cb5..beac1d9 100644 --- a/figex-core/src/main/kotlin/com/iodigital/figex/models/figex/FigExConfig.kt +++ b/figex-core/src/main/kotlin/com/iodigital/figex/models/figex/FigExConfig.kt @@ -35,11 +35,11 @@ data class FigExConfig( ) : Export() { companion object { val androidScales = listOf( - Scale(1f, "mdip/"), - Scale(1.5f, "hdip/"), - Scale(2f, "xhdip/"), - Scale(3f, "xxhdip/"), - Scale(4f, "xxxhdip/"), + Scale(1f, "drawable-mdpi/"), + Scale(1.5f, "drawable-hdpi/"), + Scale(2f, "drawable-xhdpi/"), + Scale(3f, "drawable-xxhdpi/"), + Scale(4f, "drawable-xxxhdpi/"), ) } diff --git a/samples/config.json b/samples/config.json index 9685249..fb2fa73 100644 --- a/samples/config.json +++ b/samples/config.json @@ -34,8 +34,17 @@ "format": "androidxml", "filter": "{% if full_name|startsWith('content', true) %} true {% else %} false {% endif %}", "fileNames" : "{{ full_name|replaceSpecialChars('_')|lowercase }}", + "destinationPath": "../sample_output/icons/drawable", + "clearDestination": false + }, + { + "type": "icons", + "format": "png", + "filter": "{% if full_name|startsWith('content', true) %} true {% else %} false {% endif %}", + "fileNames": "{{ full_name|replaceSpecialChars('_')|lowercase }}", "destinationPath": "../sample_output/icons", - "clearDestination": true + "clearDestination": false, + "useAndroidRasterScales": false } ] } \ No newline at end of file