mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 01:19:33 +00:00
Review
This commit is contained in:
+3
-3
@@ -223,10 +223,10 @@ class AndroidMediaPreProcessor(
|
|||||||
private suspend fun processSvgImage(uri: Uri, mimeType: String): MediaUploadInfo {
|
private suspend fun processSvgImage(uri: Uri, mimeType: String): MediaUploadInfo {
|
||||||
Timber.d("Processing SVG image ${uri.path.orEmpty().hash()}")
|
Timber.d("Processing SVG image ${uri.path.orEmpty().hash()}")
|
||||||
val file = copyToTmpFile(uri)
|
val file = copyToTmpFile(uri)
|
||||||
val (width, height) = svgDimensionExtractor.extractDimensions(file)
|
val size = svgDimensionExtractor.extractDimensions(file)
|
||||||
val imageInfo = ImageInfo(
|
val imageInfo = ImageInfo(
|
||||||
width = width,
|
width = size.width.toLong(),
|
||||||
height = height,
|
height = size.height.toLong(),
|
||||||
mimetype = mimeType,
|
mimetype = mimeType,
|
||||||
size = file.length(),
|
size = file.length(),
|
||||||
thumbnailInfo = null,
|
thumbnailInfo = null,
|
||||||
|
|||||||
+7
-8
@@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2025 Element Creations Ltd.
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
* Copyright 2023-2025 New Vector Ltd.
|
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
@@ -16,7 +15,7 @@ class SvgDimensionExtractor(
|
|||||||
private val defaultWidth: Long = 640L,
|
private val defaultWidth: Long = 640L,
|
||||||
private val defaultHeight: Long = 480L,
|
private val defaultHeight: Long = 480L,
|
||||||
) {
|
) {
|
||||||
fun extractDimensions(file: File): Pair<Long, Long> {
|
fun extractDimensions(file: File): android.util.Size {
|
||||||
return file.inputStream().use { inputStream ->
|
return file.inputStream().use { inputStream ->
|
||||||
try {
|
try {
|
||||||
val parser = Xml.newPullParser()
|
val parser = Xml.newPullParser()
|
||||||
@@ -32,7 +31,7 @@ class SvgDimensionExtractor(
|
|||||||
val parsedHeight = height?.let { parseLength(it) }
|
val parsedHeight = height?.let { parseLength(it) }
|
||||||
|
|
||||||
if (parsedWidth != null && parsedHeight != null) {
|
if (parsedWidth != null && parsedHeight != null) {
|
||||||
return parsedWidth to parsedHeight
|
return android.util.Size(parsedWidth.toInt(), parsedHeight.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewBox != null) {
|
if (viewBox != null) {
|
||||||
@@ -40,17 +39,17 @@ class SvgDimensionExtractor(
|
|||||||
if (parts.size == 4 && parts[2] != null && parts[3] != null) {
|
if (parts.size == 4 && parts[2] != null && parts[3] != null) {
|
||||||
val vbWidth = parts[2]!!.toLong().coerceAtLeast(1)
|
val vbWidth = parts[2]!!.toLong().coerceAtLeast(1)
|
||||||
val vbHeight = parts[3]!!.toLong().coerceAtLeast(1)
|
val vbHeight = parts[3]!!.toLong().coerceAtLeast(1)
|
||||||
return vbWidth to vbHeight
|
return android.util.Size(vbWidth.toInt(), vbHeight.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (parsedWidth ?: defaultWidth) to (parsedHeight ?: defaultHeight)
|
return android.util.Size((parsedWidth ?: defaultWidth).toInt(), (parsedHeight ?: defaultHeight).toInt())
|
||||||
}
|
}
|
||||||
eventType = parser.next()
|
eventType = parser.next()
|
||||||
}
|
}
|
||||||
defaultWidth to defaultHeight
|
android.util.Size(defaultWidth.toInt(), defaultHeight.toInt())
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
defaultWidth to defaultHeight
|
android.util.Size(defaultWidth.toInt(), defaultHeight.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user