aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.idea/dictionaries/david.xml7
-rw-r--r--src/main/java/net/java/dev/typecast/exchange/Exporter.java4
-rw-r--r--src/main/java/net/java/dev/typecast/exchange/Messages.java24
-rw-r--r--src/main/java/net/java/dev/typecast/exchange/SVGExporter.java54
-rw-r--r--src/main/java/net/java/dev/typecast/ot/TTGlyph.java9
-rw-r--r--src/main/resources/net/java/dev/typecast/exchange/Messages.properties (renamed from src/main/java/net/java/dev/typecast/exchange/Messages.properties)0
-rw-r--r--src/test/java/net/java/dev/typecast/exchange/SVGExporterTest.java62
-rw-r--r--src/test/java/net/java/dev/typecast/ot/OTFontCollectionTest.java1
8 files changed, 121 insertions, 40 deletions
diff --git a/.idea/dictionaries/david.xml b/.idea/dictionaries/david.xml
new file mode 100644
index 0000000..892fdb6
--- /dev/null
+++ b/.idea/dictionaries/david.xml
@@ -0,0 +1,7 @@
+<component name="ProjectDictionaryState">
+ <dictionary name="david">
+ <words>
+ <w>schweinsberg</w>
+ </words>
+ </dictionary>
+</component> \ No newline at end of file
diff --git a/src/main/java/net/java/dev/typecast/exchange/Exporter.java b/src/main/java/net/java/dev/typecast/exchange/Exporter.java
index b88b297..98ef724 100644
--- a/src/main/java/net/java/dev/typecast/exchange/Exporter.java
+++ b/src/main/java/net/java/dev/typecast/exchange/Exporter.java
@@ -1,7 +1,7 @@
/*
- * Typecast - The Font Development Environment
+ * Typecast
*
- * Copyright (c) 2004 David Schweinsberg
+ * Copyright © 2004-2019 David Schweinsberg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/main/java/net/java/dev/typecast/exchange/Messages.java b/src/main/java/net/java/dev/typecast/exchange/Messages.java
index 995fda5..8338bc4 100644
--- a/src/main/java/net/java/dev/typecast/exchange/Messages.java
+++ b/src/main/java/net/java/dev/typecast/exchange/Messages.java
@@ -1,10 +1,20 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/*
+ * Typecast
+ *
+ * Copyright © 2004-2019 David Schweinsberg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package net.java.dev.typecast.exchange;
diff --git a/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java b/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java
index 3a774ec..d24d92e 100644
--- a/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java
+++ b/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java
@@ -132,59 +132,59 @@ public class SVGExporter
if (offset == 0) {
sb.append(PATH_MOVE)
- .append(String.valueOf(point.x))
+ .append(point.x)
.append(XML_SPACE)
- .append(String.valueOf(point.y));
+ .append(point.y);
}
if (point.onCurve && point_plus1.onCurve) {
if (point_plus1.x == point.x) { // This is a vertical line
sb.append(PATH_VERTICAL_LINE_TO)
- .append(String.valueOf(point_plus1.y));
+ .append(point_plus1.y);
} else if (point_plus1.y == point.y) { // This is a horizontal line
sb.append(PATH_HORIZONTAL_LINE_TO)
- .append(String.valueOf(point_plus1.x));
+ .append(point_plus1.x);
} else {
sb.append(PATH_LINE_TO)
- .append(String.valueOf(point_plus1.x))
+ .append(point_plus1.x)
.append(XML_SPACE)
- .append(String.valueOf(point_plus1.y));
+ .append(point_plus1.y);
}
offset++;
} else if (point.onCurve && !point_plus1.onCurve && point_plus2.onCurve) {
// This is a curve with no implied points
sb.append(PATH_QUAD_TO)
- .append(String.valueOf(point_plus1.x))
+ .append(point_plus1.x)
.append(XML_SPACE)
- .append(String.valueOf(point_plus1.y))
+ .append(point_plus1.y)
.append(XML_SPACE)
- .append(String.valueOf(point_plus2.x))
+ .append(point_plus2.x)
.append(XML_SPACE)
- .append(String.valueOf(point_plus2.y));
+ .append(point_plus2.y);
offset+=2;
} else if (point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve) {
// This is a curve with one implied point
sb.append(PATH_QUAD_TO)
- .append(String.valueOf(point_plus1.x))
+ .append(point_plus1.x)
.append(XML_SPACE)
- .append(String.valueOf(point_plus1.y))
+ .append(point_plus1.y)
.append(XML_SPACE)
- .append(String.valueOf(midValue(point_plus1.x, point_plus2.x)))
+ .append(midValue(point_plus1.x, point_plus2.x))
.append(XML_SPACE)
- .append(String.valueOf(midValue(point_plus1.y, point_plus2.y)));
+ .append(midValue(point_plus1.y, point_plus2.y));
offset+=2;
} else if (!point.onCurve && !point_plus1.onCurve) {
// This is a curve with two implied points
sb.append(PATH_SMOOTH_QUAD_TO)
- .append(String.valueOf(midValue(point.x, point_plus1.x)))
+ .append(midValue(point.x, point_plus1.x))
.append(XML_SPACE)
- .append(String.valueOf(midValue(point.y, point_plus1.y)));
+ .append(midValue(point.y, point_plus1.y));
offset++;
} else if (!point.onCurve && point_plus1.onCurve) {
sb.append(PATH_SMOOTH_QUAD_TO)
- .append(String.valueOf(point_plus1.x))
+ .append(point_plus1.x)
.append(XML_SPACE)
- .append(String.valueOf(point_plus1.y));
+ .append(point_plus1.y);
offset++;
} else {
System.out.println("drawGlyph case not catered for!!");
@@ -568,14 +568,19 @@ public class SVGExporter
}
private final TTFont _font;
- private final int _low = 32;
- private int _high = 127;
+ private final int _low;
+ private final int _high;
private String _id;
- private final boolean _ascii = false;
- private final boolean _testCard = true;
+ private final boolean _ascii;
+ private final boolean _testCard;
- public SVGExporter(TTFont font) {
+ public SVGExporter(TTFont font, int low, int high, String id, boolean ascii, boolean testCard) {
_font = font;
+ _low = low;
+ _high = high;
+ _id = id;
+ _ascii = ascii;
+ _testCard = testCard;
}
/**
@@ -587,9 +592,6 @@ public class SVGExporter
public void export(OutputStream os) throws TableException {
PrintStream ps = new PrintStream(os);
- // TESTING
- _high = 65536;
-
// Write the various parts of the SVG file
writeSvgBegin(ps);
writeSvgDefsBegin(ps);
diff --git a/src/main/java/net/java/dev/typecast/ot/TTGlyph.java b/src/main/java/net/java/dev/typecast/ot/TTGlyph.java
index 24a8df6..0752b0b 100644
--- a/src/main/java/net/java/dev/typecast/ot/TTGlyph.java
+++ b/src/main/java/net/java/dev/typecast/ot/TTGlyph.java
@@ -88,8 +88,9 @@ public class TTGlyph extends Glyph {
*/
private void describe(GlyphDescription gd) {
int endPtIndex = 0;
- _points = new Point[gd.getPointCount() + 2];
- for (int i = 0; i < gd.getPointCount(); i++) {
+ int pointCount = gd != null ? gd.getPointCount() : 0;
+ _points = new Point[pointCount + 2];
+ for (int i = 0; i < pointCount; i++) {
boolean endPt = gd.getEndPtOfContours(endPtIndex) == i;
if (endPt) {
endPtIndex++;
@@ -102,7 +103,7 @@ public class TTGlyph extends Glyph {
}
// Append the origin and advanceWidth points (n & n+1)
- _points[gd.getPointCount()] = new Point(0, 0, true, true);
- _points[gd.getPointCount()+1] = new Point(_advanceWidth, 0, true, true);
+ _points[pointCount] = new Point(0, 0, true, true);
+ _points[pointCount+1] = new Point(_advanceWidth, 0, true, true);
}
}
diff --git a/src/main/java/net/java/dev/typecast/exchange/Messages.properties b/src/main/resources/net/java/dev/typecast/exchange/Messages.properties
index ef5e952..ef5e952 100644
--- a/src/main/java/net/java/dev/typecast/exchange/Messages.properties
+++ b/src/main/resources/net/java/dev/typecast/exchange/Messages.properties
diff --git a/src/test/java/net/java/dev/typecast/exchange/SVGExporterTest.java b/src/test/java/net/java/dev/typecast/exchange/SVGExporterTest.java
new file mode 100644
index 0000000..11c8d4a
--- /dev/null
+++ b/src/test/java/net/java/dev/typecast/exchange/SVGExporterTest.java
@@ -0,0 +1,62 @@
+/*
+ * Typecast
+ *
+ * Copyright © 2004-2019 David Schweinsberg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.java.dev.typecast.exchange;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import net.java.dev.typecast.ot.TTFont;
+import net.java.dev.typecast.ot.table.TableException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+
+public class SVGExporterTest extends TestCase {
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public SVGExporterTest(String testName) {
+ super(testName);
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite() {
+ return new TestSuite(SVGExporterTest.class);
+ }
+
+ public void testExportFont() throws URISyntaxException, IOException, TableException {
+ URL url = ClassLoader.getSystemResource("Lato-Regular.ttf");
+ File file = new File(url.toURI());
+ byte[] fontData = Files.readAllBytes(file.toPath());
+ TTFont font = new TTFont(fontData, 0);
+ SVGExporter exporter = new SVGExporter(font, 32, 32, "abc", true, false);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ exporter.export(baos);
+ String svgString = baos.toString();
+ System.out.println(svgString);
+ }
+}
diff --git a/src/test/java/net/java/dev/typecast/ot/OTFontCollectionTest.java b/src/test/java/net/java/dev/typecast/ot/OTFontCollectionTest.java
index 3427d47..324a21d 100644
--- a/src/test/java/net/java/dev/typecast/ot/OTFontCollectionTest.java
+++ b/src/test/java/net/java/dev/typecast/ot/OTFontCollectionTest.java
@@ -20,7 +20,6 @@ package net.java.dev.typecast.ot;
import java.io.File;
import java.io.IOException;
-import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import junit.framework.Test;