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

Allow SVG width/height to be non-integral values #423

Merged
merged 2 commits into from
Oct 22, 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 @@ -121,18 +121,20 @@ protected XdmMap parseProperty(XdmMap map, String name, String value, int tagTyp
}
break;
case "width":
// Only output this property if it's an integer
// This property must be returned as an integer; round if necessary
try {
int width = Integer.parseInt(value);
float fwidth = Float.parseFloat(value);
int width = Math.round(fwidth);
map = map.put(new XdmAtomicValue("width"), new XdmAtomicValue(width));
} catch (NumberFormatException nfe) {
// nevermind
}
break;
case "height":
// Only output this property if it's an integer
// This property must be returned as an integer; round if necessary
try {
int height = Integer.parseInt(value);
float fheight = Float.parseFloat(value);
int height = Math.round(fheight);
map = map.put(new XdmAtomicValue("height"), new XdmAtomicValue(height));
} catch (NumberFormatException nfe) {
// nevermind
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/expected/svg.002.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="no-js"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script><title>Unit test: svg.002</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link href="https://purl.org/dc/elements/1.1/" rel="schema.dc"/><meta content="2011-04-22T17:02:00-06:00" name="dc.modified"/><meta content="DocBook xslTNG" name="generator"/><link href="./css/docbook.css" rel="stylesheet" media="screen"/></head><body class="home"><nav class="top"></nav><main><article class="book division"><header><h1>Unit test: svg.002</h1></header><div class="list-of-titles"><div class="lot toc"><div class="title">Table of Contents</div><ul class="toc"><li><a href="#R_ch1"><span class="label">1</span><span class="sep">. </span>Test</a></li></ul></div><div class="list-of-figures lot"><div class="title">List of Figures</div><ul class="toc"><li><a href="#R_ch1_fig1"><span class="label">1<span class="sep">.</span>1</span><span class="sep">. </span>Address Type</a></li></ul></div></div><section id="R_ch1" class="chapter component"><header><h2>Chapter <span class="label">1</span><span class="sep">. </span>Test</h2></header><p>Dimensions of this SVG Image are <em>width="325.03125" height="382"</em>. Scaled with 110% and <em>scalefit='1'</em> should result in widtg=357px, height=420px. </p><div id="R_ch1_fig1" class="figure formalobject"><div class="mediaobject"><div class="media image"><span class="viewport-table"><span class="viewport-row"><span class="viewport-cell" style="vertical-align:middle;"><span><span class="viewport"><picture class="imageobject"><img src="media/AddressType.svg" style="width:358px;height:420px;"/></picture></span></span></span></span></span></div></div><header><div class="title">Figure <span class="label">1<span class="sep">.</span>1</span><span class="sep">. </span>Address Type</div></header></div></section></article></main><nav class="bottom"></nav></body></html>
235 changes: 235 additions & 0 deletions src/test/resources/media/AddressType.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/test/resources/xml/svg.002.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.1">
<info>
<title>Unit test: svg.002</title>
<!-- Contributed by frank-steimke; see issue #413 -->
</info>
<chapter>
<title>Test</title>
<para>Dimensions of this SVG Image are <emphasis>width="325.03125" height="382"</emphasis>. Scaled with 110% and <emphasis>scalefit='1'</emphasis> should result in widtg=357px, height=420px. </para>
<figure>
<title>Address Type</title>
<mediaobject>
<imageobject>
<imagedata fileref="../media/AddressType.svg" scalefit="1" scale="110"/>
</imageobject>
</mediaobject>
</figure>
</chapter>
</book>