mirror of
https://github.com/csharpee/Map-Projections.git
synced 2025-12-07 00:00:07 -05:00
fix issue with unicode in SVG
apparently map projections with unicode in their names create invalid SVG when using the executable (even tho it works fine when I run the source code...). something about the encoding I gess? I don't really understand, but it's better to escape the map projection names anyway just to be consistent with the templates that are already escaped. I did that and now it seems fine.
This commit is contained in:
parent
bd07cf8e11
commit
71dd66bb2c
BIN
MapAnalyzer.jar
BIN
MapAnalyzer.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@
|
||||
<property name="dir.commons" value="C:\Program Files\Java\commons-math3-3.6.1"/>
|
||||
<property name="dir.jre" value="C:\Program Files\Java\jre-1.8"/>
|
||||
<property name="dir.jarfile" value="."/>
|
||||
<property name="version" value="3.5.4"/>
|
||||
<property name="version" value="3.5.5"/>
|
||||
<property name="year" value="2023"/>
|
||||
|
||||
<target name="setup">
|
||||
|
||||
@ -56,6 +56,7 @@ import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static image.SVGMap.escapeHTML;
|
||||
import static java.lang.Double.isNaN;
|
||||
import static java.lang.Math.hypot;
|
||||
import static java.lang.String.format;
|
||||
@ -378,7 +379,7 @@ public class MapDesignerVector extends MapApplication {
|
||||
}
|
||||
// for non-data Strings, replace "Equirectangular" with the name of the projection
|
||||
else if (elementS instanceof Content) {
|
||||
elementP = new Content(((Content) elementS).content.replace("Equirectangular", proj.getName()));
|
||||
elementP = new Content(((Content) elementS).content.replace("Equirectangular", escapeHTML(proj.getName())));
|
||||
}
|
||||
// anything else doesn't need to be changed with the projection
|
||||
else {
|
||||
|
||||
@ -154,15 +154,8 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
||||
@Override
|
||||
public void characters(char[] characters, int start, int length) {
|
||||
// just dump the provided characters into currentFormatString
|
||||
StringBuilder characterString = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = characters[start + i];
|
||||
if (c >= 128 || c == '\'' || c == '"' || c == '<' || c == '>' || c == '&') // some characters must be escaped here
|
||||
characterString.append("&#").append((int) c).append(";");
|
||||
else
|
||||
characterString.append(c);
|
||||
}
|
||||
elements.add(new Content(characterString.toString()));
|
||||
elements.add(new Content(escapeHTML(
|
||||
new String(characters).substring(start, start + length))));
|
||||
}
|
||||
|
||||
// @Override /* only available in Java 14+ */
|
||||
@ -545,6 +538,19 @@ public class SVGMap implements Iterable<SVGMap.SVGElement>, SavableImage {
|
||||
string.append(">");
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String escapeHTML(String raw) {
|
||||
StringBuilder escaped = new StringBuilder();
|
||||
for (int i = 0; i < raw.length(); i ++) {
|
||||
char c = raw.charAt(i); // don't forget to escape special characters
|
||||
if (c >= 128 || c == '\'' || c == '"' || c == '<' || c == '>' || c == '&') // some characters must be escaped here
|
||||
escaped.append(format("&#%d;", (int) c));
|
||||
else
|
||||
escaped.append(c);
|
||||
}
|
||||
return escaped.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user