Permalink
Browse files

Fix #347 (#409)

* Do not use width="100%" height="100%" for scaling when seen in document root.
Fixes fablabnbg#7

* Fixing #347

Parse the inkscape version number from the SVG headers.
Then decide for a dpi settings.

Next time give me a DPI number right in the document, please!

* Max, thanks!
  • Loading branch information...
jnweiger authored and t-oster committed Apr 23, 2017
1 parent 4f41f65 commit 419fa1a539e72ab5e63fa2dc30c75e351e57aeda
Showing with 38 additions and 4 deletions.
  1. +38 −4 src/com/t_oster/visicut/model/graphicelements/svgsupport/SVGImporter.java
@@ -49,6 +49,8 @@
import java.io.InputStreamReader;
import java.net.URI;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -122,7 +124,7 @@ public void flush(){}
public void close() throws SecurityException{}
};
-
+
try
{
u.clear();
@@ -180,6 +182,7 @@ public double determineResolution(File f, List<String> warnings)
double result = 90;
boolean AdobeIllustratorSeen = false;
boolean WwwInkscapeComSeen = false;
+ boolean InkscapeVersion092Seen = false;
boolean usesFlowRoot = false;
try
{
@@ -197,6 +200,33 @@ public double determineResolution(File f, List<String> warnings)
{
WwwInkscapeComSeen = true;
}
+ if (line.contains("inkscape:version="))
+ {
+ // inkscape:version="0.92.0 ...."
+ // inkscape:version="0.91 r"
+
+ // FIXME: version number comparison needed here!
+ Pattern versionPattern = Pattern.compile("inkscape:version\\s*=\\s*[\"']?([0-9]+)\\.([0-9]+)");
+ Matcher matcher = versionPattern.matcher(line);
+ if (matcher.find())
+ {
+ String vers = matcher.group();
+ // vers = "inkscape:version=\"0.92"
+
+ int vers_maj;
+ try { vers_maj = Integer.parseInt(matcher.group(1)); }
+ catch (NumberFormatException e) { vers_maj = -1; }
+
+ int vers_min;
+ try { vers_min = Integer.parseInt(matcher.group(2)); }
+ catch (NumberFormatException e) { vers_min = -1; }
+
+ if (((vers_maj == 0) && (vers_min >= 92)) || (vers_maj > 0))
+ {
+ InkscapeVersion092Seen = true;
+ }
+ }
+ }
if (line.contains("</flowRoot>"))
{
usesFlowRoot = true;
@@ -237,22 +267,26 @@ public double determineResolution(File f, List<String> warnings)
// SVG files loaded in inkscape retain the Illustrator comment, but are saved with 90 DPI.
if (AdobeIllustratorSeen) { result = 72; }
if (WwwInkscapeComSeen) { result = 90; } // inkscape wins over Illustrator
+ if (InkscapeVersion092Seen) { result = 96; } // inkscape with known version wins over anything else.
if (result != 90)
{
if (AdobeIllustratorSeen)
{
warnings.add("Adobe Illustrator comment seen in SVG.");
}
- warnings.add("Switching to DPI from 90 to " + result + " - Please check object size!");
-
+ if (InkscapeVersion092Seen)
+ {
+ warnings.add("Inkscape Version 0.92+ comment seen in SVG.");
+ }
+ warnings.add("Switching DPI from 90 to " + result + " - Please check object size!");
}
return result;
}
/*
* Tries to determine the Coordinate resolution in DPI.
* SVG default is 90, but AI generates 72??
- *
+ * Since inkscape 0.92 SVG default is 96 DPI.
*/
private AffineTransform determineTransformation(SVGRoot root, double svgResolution)
{

0 comments on commit 419fa1a

Please sign in to comment.