Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4231: Adding support for svgz images #4862

Merged
merged 12 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class UrlImageParser private constructor(
val imageUrl = "$gcsPrefix/$gcsResourceName/$imagePath"
val proxyDrawable = ProxyDrawable()
// TODO(#1039): Introduce custom type OppiaImage for rendering Bitmap and Svg.
val isSvg = machineLocale.run { imageUrl.endsWithIgnoreCase("svg") }
val isSvg = machineLocale.run {
imageUrl.endsWithIgnoreCase("svg") || imageUrl.endsWithIgnoreCase("svgz")
}
val adjustedType = if (type == INLINE_TEXT_IMAGE && !isSvg) {
// Treat non-svg in-line images as block, instead, since only SVG is supported.
consoleLogger.w("UrlImageParser", "Forcing image $filename to block image")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class UrlImageParserTest {
assertThat(loadedBitmaps.first()).contains("test_image.svg")
}

@Test
fun testGetDrawable_svgz_loadsSvgzBlockImage() {
urlImageParser.getDrawable("test_image.svgz")

val loadedBitmaps = testGlideImageLoader.getLoadedBlockSvgs()
assertThat(loadedBitmaps).hasSize(1)
assertThat(loadedBitmaps.first()).contains("test_image.svgz")
}

@Test
fun testLoadDrawable_bitmap_blockType_loadsBitmapImage() {
urlImageParser.loadDrawable("test_image.png", BLOCK_IMAGE)
Expand Down Expand Up @@ -109,6 +118,15 @@ class UrlImageParserTest {
assertThat(loadedBitmaps.first()).contains("test_image.svg")
}

@Test
fun testLoadDrawable_svgz_blockType_loadsSvgzBlockImage() {
urlImageParser.loadDrawable("test_image.svgz", BLOCK_IMAGE)

val loadedBitmaps = testGlideImageLoader.getLoadedBlockSvgs()
assertThat(loadedBitmaps).hasSize(1)
assertThat(loadedBitmaps.first()).contains("test_image.svgz")
}

@Test
fun testLoadDrawable_svg_inlineType_loadsSvgTextImage() {
urlImageParser.loadDrawable("test_image.svg", INLINE_TEXT_IMAGE)
Expand All @@ -119,6 +137,16 @@ class UrlImageParserTest {
assertThat(loadedBitmaps.first()).contains("test_image.svg")
}

@Test
fun testLoadDrawable_svgz_inlineType_loadsSvgzTextImage() {
urlImageParser.loadDrawable("test_image.svgz", INLINE_TEXT_IMAGE)

// The request to load the bitmap inline is ignored since inline bitmaps aren't supported.
val loadedBitmaps = testGlideImageLoader.getLoadedTextSvgs()
assertThat(loadedBitmaps).hasSize(1)
assertThat(loadedBitmaps.first()).contains("test_image.svgz")
}

@Test
fun testLoadDrawable_latex_inlineType_loadsInlineLatexImage() {
urlImageParser.loadMathDrawable(
Expand Down