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

Images scaled with RetainShape are sometimes rendered too small #483

Open
mfg92 opened this issue Sep 23, 2024 · 5 comments
Open

Images scaled with RetainShape are sometimes rendered too small #483

mfg92 opened this issue Sep 23, 2024 · 5 comments

Comments

@mfg92
Copy link

mfg92 commented Sep 23, 2024

I have noticed that some SVGs are rendered too small when using the RetainShape scaling option. I tried to find out what distinguishes the SVGs that are scaled correctly from those that are scaled too small.
My conclusion is that if the optional attributes width and height in the root tag svg are missing, then the problem can occur.
It seems that without these attributes, the scaling algorithm assumes that the image is a square, where each side has a length of MAX(viewBox.width, viewBox.height).

I think RetainShape should work the same regardless of whether width and height are in the root tag or not.

Examples:
grafik
grafik

Template of the example:

<!-- Created with Jaspersoft Studio version 7.0.0.final using JasperReports Library version 7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa  -->
<!-- 2024-09-23T14:00:01 -->
<jasperReport name="image" language="java" pageWidth="500" pageHeight="800" columnWidth="400" leftMargin="50" rightMargin="50" topMargin="0" bottomMargin="0" uuid="890c1c55-90c2-4100-bc34-807a0fe94789">
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
	<parameter name="horizontalBox" forPrompting="false" class="java.lang.String">
		<defaultValueExpression><![CDATA["PHN2ZyB3aWR0aD0iMzYiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAzNiAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxnPgogICAgICAgIDxyZWN0CiAgICAgICAgICAgICAgICB4PSIwLjUiIHk9IjAuNSIKICAgICAgICAgICAgICAgIHdpZHRoPSIzNSIgaGVpZ2h0PSIyMyIKICAgICAgICAgICAgICAgIHJ4PSI1IgogICAgICAgICAgICAgICAgZmlsbD0iI2ZmMCIgc3Ryb2tlPSIjZjQ4ZTAwIgogICAgICAgIC8+CiAgICA8L2c+Cjwvc3ZnPg=="]]></defaultValueExpression>
	</parameter>
	<parameter name="verticalBox" forPrompting="false" class="java.lang.String">
		<defaultValueExpression><![CDATA["PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMzYiIHZpZXdCb3g9IjAgMCAyNCAzNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxnPgogICAgICAgIDxyZWN0CiAgICAgICAgICAgICAgICB4PSIwLjUiIHk9IjAuNSIKICAgICAgICAgICAgICAgIHdpZHRoPSIyMyIgaGVpZ2h0PSIzNSIKICAgICAgICAgICAgICAgIHJ4PSI1IgogICAgICAgICAgICAgICAgZmlsbD0iI2ZmMCIgc3Ryb2tlPSIjZjQ4ZTAwIgogICAgICAgIC8+CiAgICA8L2c+Cjwvc3ZnPg=="]]></defaultValueExpression>
	</parameter>
	<parameter name="image" forPrompting="false" class="java.lang.String">
		<defaultValueExpression><![CDATA[new String(org.apache.commons.codec.binary.Base64.decodeBase64($P{horizontalBox}.getBytes()), "UTF-8").replaceFirst("<svg.*?viewBox", "<svg viewBox")]]></defaultValueExpression>
	</parameter>
	<parameter name="image2" forPrompting="false" class="java.lang.String">
		<defaultValueExpression><![CDATA[new String(org.apache.commons.codec.binary.Base64.decodeBase64($P{horizontalBox}.getBytes()), "UTF-8")]]></defaultValueExpression>
	</parameter>
	<group name="Main">
		<groupHeader>
			<band height="800" splitType="Prevent">
				<element kind="staticText" uuid="3cd785d5-a435-4964-aee8-446203ac8b82" x="0" y="0" width="400" height="30" fontSize="20.0" bold="true" hTextAlign="Center">
					<text><![CDATA[only viewBox]]></text>
				</element>
				<element kind="textField" uuid="9048b3eb-76d9-43e4-af86-61b5d2402099" x="0" y="40" width="400" height="100" textAdjust="ScaleFont">
					<expression><![CDATA[$P{image}]]></expression>
				</element>
				<element kind="image" uuid="4a78d751-4ed2-41ce-8365-4305b44034ab" positionType="Float" x="0" y="150" width="200" height="100" scaleImage="RetainShape" hImageAlign="Center" vImageAlign="Top">
					<expression><![CDATA[new java.io.ByteArrayInputStream($P{image}.getBytes())]]></expression>
					<box>
						<pen lineWidth="2.0" lineStyle="Dashed"/>
					</box>
				</element>
				<element kind="image" uuid="e675f9a9-78cc-4b40-81e2-333a75f612ce" positionType="Float" x="250" y="150" width="100" height="200" scaleImage="RetainShape" hImageAlign="Center" vImageAlign="Top">
					<expression><![CDATA[new java.io.ByteArrayInputStream($P{image}.getBytes())]]></expression>
					<box>
						<pen lineWidth="2.0" lineStyle="Dashed"/>
					</box>
				</element>
				<element kind="staticText" uuid="29c991fb-e8a9-4910-832a-f4ec0c516784" x="0" y="400" width="400" height="30" fontSize="20.0" bold="true" hTextAlign="Center">
					<text><![CDATA[viewBox + width + height]]></text>
				</element>
				<element kind="textField" uuid="09d79785-ddfb-4719-ab91-56afee41fe94" x="0" y="440" width="400" height="100" textAdjust="ScaleFont">
					<expression><![CDATA[$P{image2}]]></expression>
				</element>
				<element kind="image" uuid="4a396040-4cfa-4f2a-8cdd-d8c14448a27e" positionType="Float" x="0" y="550" width="200" height="100" scaleImage="RetainShape" hImageAlign="Center" vImageAlign="Top">
					<expression><![CDATA[new java.io.ByteArrayInputStream($P{image2}.getBytes())]]></expression>
					<box>
						<pen lineWidth="2.0" lineStyle="Dashed"/>
					</box>
				</element>
				<element kind="image" uuid="e3a1e7f5-33b1-4ca6-a946-5fb9145f5c58" positionType="Float" x="250" y="550" width="100" height="200" scaleImage="RetainShape" hImageAlign="Center" vImageAlign="Top">
					<expression><![CDATA[new java.io.ByteArrayInputStream($P{image2}.getBytes())]]></expression>
					<box>
						<pen lineWidth="2.0" lineStyle="Dashed"/>
					</box>
				</element>
			</band>
		</groupHeader>
	</group>
</jasperReport>
@teodord
Copy link
Collaborator

teodord commented Sep 23, 2024

We are not introspecting SVG files to see if they have or don't have the width and height attributes.
When we scale something and try to retain its shape, we simply ask that particular graphic what is its size.
We load SVG using Apache Batik and whatever Batik tells us about the size, we take it and don't question it.
If Batik does not handle the size well, maybe a bug should be logged against their project.

Thank you,
Teodor

@teodord
Copy link
Collaborator

teodord commented Sep 24, 2024

I'm taking it back. We do seem to look for width and height attributes in the svg tag. Digging...

Thanks,
Teodor

@mfg92
Copy link
Author

mfg92 commented Oct 9, 2024

What can I do to move this issue forward?

@teodord
Copy link
Collaborator

teodord commented Nov 4, 2024

What is the size of an SVG that does not provide width and height?

Thank you,
Teodor

@mfg92
Copy link
Author

mfg92 commented Nov 4, 2024

What is the size of an SVG that does not provide width and height?

According to these sources [1] [2] the size is undetermined/auto but the aspect ratio is determined by using the viewBox attribute if given. If neither width+height nor the vierwbox is given, the width and height is 300px x 150px.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@teodord @mfg92 and others