diff --git a/lib/ttf.jar b/lib/ttf.jar index 4c9f4963a..e07d1e1f4 100644 Binary files a/lib/ttf.jar and b/lib/ttf.jar differ diff --git a/libsrc/ttf/src/fontastic/FContour.java b/libsrc/ttf/src/fontastic/FContour.java index 38745865c..2bdb30997 100644 --- a/libsrc/ttf/src/fontastic/FContour.java +++ b/libsrc/ttf/src/fontastic/FContour.java @@ -1,6 +1,6 @@ package fontastic; -/** +/* * Fontastic * A font file writer to create TTF and WOFF (Webfonts). * http://code.andreaskoller.com/libraries/fontastic @@ -11,69 +11,65 @@ package fontastic; * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - * - * @author Andreas Koller http://andreaskoller.com - * @modified 06/19/2013 - * @version 0.4 (4) + * Boston, MA 02111-1307 USA + * + * @author Andreas Koller http://andreaskoller.com + * @modified 06/19/2013 + * @version 0.4 (4) */ - -import fontastic.FPoint; - import java.util.ArrayList; import java.util.List; /** * Class FContour - * + * * Stores a contour (list of FPoint). - * + * */ public class FContour { - List points; + List points; - FContour() { - this.points = new ArrayList<>(); - } - - FContour(FPoint[] points) { - this.points = new ArrayList<>(); - for (FPoint p : points) { - this.points.add(p); - } - } - - FContour(FPoint[] points, FPoint[] controlpoints) { - this.points = new ArrayList<>(); - for (int i=0; i getPoints() { - return points; - } - - public FPoint[] getPointsArray() { - FPoint[] pointsArray = points.toArray(new FPoint[points.size()]); - return pointsArray; - } - - public void setPoints(FPoint[] points) { - this.points = new ArrayList<>(); - for (FPoint p : points) { - this.points.add(p); - } - } + FContour() { + this.points = new ArrayList<>(); + } -} \ No newline at end of file + FContour(FPoint[] points) { + this.points = new ArrayList<>(); + for (FPoint p : points) { + this.points.add(p); + } + } + + FContour(FPoint[] points, FPoint[] controlpoints) { + this.points = new ArrayList<>(); + for (int i = 0; i < points.length; i++) { + this.points.add(new FPoint(points[i], controlpoints[i])); + } + } + + public List getPoints() { + return points; + } + + public FPoint[] getPointsArray() { + FPoint[] pointsArray = points.toArray(new FPoint[points.size()]); + return pointsArray; + } + + public void setPoints(FPoint[] points) { + this.points = new ArrayList<>(); + for (FPoint p : points) { + this.points.add(p); + } + } +} diff --git a/libsrc/ttf/src/fontastic/FGlyph.java b/libsrc/ttf/src/fontastic/FGlyph.java index e5dacaf7b..817f40533 100644 --- a/libsrc/ttf/src/fontastic/FGlyph.java +++ b/libsrc/ttf/src/fontastic/FGlyph.java @@ -1,6 +1,6 @@ package fontastic; -/** +/* * Fontastic * A font file writer to create TTF and WOFF (Webfonts). * http://code.andreaskoller.com/libraries/fontastic @@ -11,98 +11,97 @@ package fontastic; * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - * - * @author Andreas Koller http://andreaskoller.com - * @modified 06/19/2013 - * @version 0.4 (4) + * Boston, MA 02111-1307 USA + * + * @author Andreas Koller http://andreaskoller.com + * @modified 06/19/2013 + * @version 0.4 (4) */ - - import java.util.ArrayList; import java.util.List; /** * Class FGlyph - * + * * Stores a glyph with all its properties. - * + * */ public class FGlyph { - private char glyphChar; - private List contours; - private int advanceWidth = 512; + private final char glyphChar; - FGlyph(char c) { - glyphChar = c; - this.contours = new ArrayList<>(); - } + private final List contours; - public void addContour() { - contours.add(new FContour()); - } - - public void addContour(FPoint[] points) { - contours.add(new FContour(points)); - } + private int advanceWidth = 512; - public void addContour(FPoint[] points, FPoint[] controlPoints) { - contours.add(new FContour(points, controlPoints)); - } - - public void addContour(FContour contour) { - contours.add(contour); - } + FGlyph(char c) { + glyphChar = c; + this.contours = new ArrayList<>(); + } - public void setAdvanceWidth(int advanceWidth) { - this.advanceWidth = advanceWidth; - } - - public char getGlyphChar() { - return glyphChar; - } - - public int getAdvanceWidth() { - return advanceWidth; - } - - public List getContours() { - return contours; - } + public void addContour() { + contours.add(new FContour()); + } - public FContour[] getContoursArray() { - FContour[] contoursArray = contours.toArray(new FContour[contours.size()]); - return contoursArray; - } - - public FContour getContour(int index) { - return contours.get(index); - } - - public int getContourCount() { - return contours.size(); - } - - public void setContour(int index, FPoint[] points) { - contours.set(index, new FContour(points)); - } + public void addContour(FPoint[] points) { + contours.add(new FContour(points)); + } - public void setContour(int index, FContour contour) { - contours.set(index, contour); - } - - public void clearContours() { - this.contours.clear(); - } - -} \ No newline at end of file + public void addContour(FPoint[] points, FPoint[] controlPoints) { + contours.add(new FContour(points, controlPoints)); + } + + public void addContour(FContour contour) { + contours.add(contour); + } + + public void setAdvanceWidth(int advanceWidth) { + this.advanceWidth = advanceWidth; + } + + public char getGlyphChar() { + return glyphChar; + } + + public int getAdvanceWidth() { + return advanceWidth; + } + + public List getContours() { + return contours; + } + + public FContour[] getContoursArray() { + FContour[] contoursArray = contours.toArray(new FContour[contours.size()]); + return contoursArray; + } + + public FContour getContour(int index) { + return contours.get(index); + } + + public int getContourCount() { + return contours.size(); + } + + public void setContour(int index, FPoint[] points) { + contours.set(index, new FContour(points)); + } + + public void setContour(int index, FContour contour) { + contours.set(index, contour); + } + + public void clearContours() { + this.contours.clear(); + } +} diff --git a/libsrc/ttf/src/fontastic/FPoint.java b/libsrc/ttf/src/fontastic/FPoint.java index c6d98b023..d3538250b 100644 --- a/libsrc/ttf/src/fontastic/FPoint.java +++ b/libsrc/ttf/src/fontastic/FPoint.java @@ -1,6 +1,6 @@ package fontastic; -/** +/* * Fontastic * A font file writer to create TTF and WOFF (Webfonts). * http://code.andreaskoller.com/libraries/fontastic @@ -11,75 +11,71 @@ package fontastic; * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - * - * @author Andreas Koller http://andreaskoller.com - * @modified 06/19/2013 - * @version 0.4 (4) + * Boston, MA 02111-1307 USA + * + * @author Andreas Koller http://andreaskoller.com + * @modified 06/19/2013 + * @version 0.4 (4) */ - - - /** * Class FPoint extends PVector - * - * Stores a point with x and y coordinates and optional PVector controlPoint1 and controlPoint2. - * + * + * Stores a point with x and y coordinates and optional PVector controlPoint1 + * and controlPoint2. + * */ public class FPoint { - public double x; - public double y; + public double x; - public FPoint controlPoint; - - private boolean hasControlPoint; + public double y; - public FPoint() { - } - - public FPoint(FPoint point) { - this.x = point.x; - this.y = point.y; - this.hasControlPoint = false; - } - - public FPoint(double x, double y) { - this.x = x; - this.y = y; - this.hasControlPoint = false; - } - - - public FPoint(FPoint point, FPoint controlPoint) { - this.x = point.x; - this.y = point.y; - this.controlPoint = controlPoint; - this.hasControlPoint = true; - } - - public void setControlPoint(FPoint controlPoint1) { - this.controlPoint = controlPoint1; - this.hasControlPoint = true; - } + public FPoint controlPoint; - public void setControlPoint(float x, float y) { - this.controlPoint = new FPoint(x, y); - this.hasControlPoint = true; - } + private boolean hasControlPoint; - - public boolean hasControlPoint1() { - return hasControlPoint; - } + public FPoint() { + } -} \ No newline at end of file + public FPoint(FPoint point) { + this.x = point.x; + this.y = point.y; + this.hasControlPoint = false; + } + + public FPoint(double x, double y) { + this.x = x; + this.y = y; + this.hasControlPoint = false; + } + + public FPoint(FPoint point, FPoint controlPoint) { + this.x = point.x; + this.y = point.y; + this.controlPoint = controlPoint; + this.hasControlPoint = true; + } + + public void setControlPoint(FPoint controlPoint1) { + this.controlPoint = controlPoint1; + this.hasControlPoint = true; + } + + public void setControlPoint(float x, float y) { + this.controlPoint = new FPoint(x, y); + this.hasControlPoint = true; + } + + public boolean hasControlPoint1() { + return hasControlPoint; + } +} diff --git a/libsrc/ttf/src/fontastic/Fontastic.java b/libsrc/ttf/src/fontastic/Fontastic.java index 45f5106f9..8e62b2030 100644 --- a/libsrc/ttf/src/fontastic/Fontastic.java +++ b/libsrc/ttf/src/fontastic/Fontastic.java @@ -1,4 +1,4 @@ -/** +/* * Fontastic A font file writer to create TTF * http://code.andreaskoller.com/libraries/fontastic * @@ -21,18 +21,21 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Andreas Koller http://andreaskoller.com - * @modified 03/16/2014 JPEXS - removed Woff + * @modified 03/16/2014 JPEXS - removed Woff * @version 0.4 (4) */ package fontastic; -import org.doubletype.ossa.*; -import org.doubletype.ossa.module.*; -import org.doubletype.ossa.adapter.*; - -import java.io.*; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.doubletype.ossa.Engine; +import org.doubletype.ossa.OutOfRangeException; +import org.doubletype.ossa.adapter.EContour; +import org.doubletype.ossa.adapter.EContourPoint; +import org.doubletype.ossa.module.GlyphFile; +import org.doubletype.ossa.module.TypefaceFile; /** * Fontastic A font file writer to create TTF and WOFF (Webfonts). @@ -50,7 +53,9 @@ public class Fontastic { private int advanceWidth = 512; private File ttfFile; + private File outFile; + private File tempDir; /** @@ -83,12 +88,10 @@ public class Fontastic { File temp; temp = File.createTempFile("temp", Long.toString(System.nanoTime())); - - if (!(temp.delete())) { throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); } - + if (!(temp.mkdirs())) { throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); } @@ -103,10 +106,10 @@ public class Fontastic { private void intitialiseFont() throws IOException { tempDir = createTempDirectory(); - + m_engine = new Engine(); m_engine.buildNewTypeface(fontName, tempDir); - + this.setFontFamilyName(fontName); this.setVersion("CC BY-SA 3.0 http://creativecommons.org/licenses/by-sa/3.0/"); // default // license @@ -139,21 +142,21 @@ public class Fontastic { for (FPoint point : contour.points) { - EContourPoint e = new EContourPoint(point.x, point.y, true); + EContourPoint e = new EContourPoint(point.x, point.y, true); if (point.hasControlPoint1()) { - + econtour.addContourPoint(new EContourPoint(point.controlPoint.x, point.controlPoint.y, false)); /*EControlPoint cp1 = new EControlPoint(true, - point.controlPoint1.x, point.controlPoint1.y); - e.setControlPoint1(cp1); - */ + point.controlPoint1.x, point.controlPoint1.y); + e.setControlPoint1(cp1); + */ } -/* - if (point.hasControlPoint2()) { - EControlPoint cp2 = new EControlPoint(false, - point.controlPoint2.x, point.controlPoint2.y); - e.setControlPoint2(cp2); - } */ + /* + if (point.hasControlPoint2()) { + EControlPoint cp2 = new EControlPoint(false, + point.controlPoint2.x, point.controlPoint2.y); + e.setControlPoint2(cp2); + } */ econtour.addContourPoint(e); } @@ -162,11 +165,11 @@ public class Fontastic { } } - m_engine.getTypeface().addRequiredGlyphs(); + m_engine.getTypeface().addRequiredGlyphs(); m_engine.buildTrueType(); // End TTF creation - if(outFile.exists()){ + if (outFile.exists()) { outFile.delete(); } ttfFile.renameTo(outFile); @@ -214,13 +217,6 @@ public class Fontastic { m_engine.setFontFamilyName(fontFamilyName); } - /** - * Sets the sub family of the font. - */ - public void setSubFamily(String subFamily) { - m_engine.getTypeface().setSubFamily(subFamily); - } - /** * Sets the license of the font (default is "CC BY-SA 3.0 * http://creativecommons.org/licenses/by-sa/3.0/") @@ -329,7 +325,7 @@ public class Fontastic { */ public FGlyph addGlyph(char c) { - FGlyph glyph = new FGlyph(c); + FGlyph glyph = new FGlyph(c); glyph.setAdvanceWidth(advanceWidth); glyphs.add(glyph); return glyph; diff --git a/libsrc/ttf/src/fontatest/FontaTest.java b/libsrc/ttf/src/fontatest/FontaTest.java index 3753646f5..462e66aef 100644 --- a/libsrc/ttf/src/fontatest/FontaTest.java +++ b/libsrc/ttf/src/fontatest/FontaTest.java @@ -5,26 +5,24 @@ import fontastic.Fontastic; import java.io.File; import java.io.IOException; - public class FontaTest { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { - File file=new File("example.ttf"); + File file = new File("example.ttf"); file.delete(); - Fontastic f = new Fontastic("ExampleFont",file); + Fontastic f = new Fontastic("ExampleFont", file); f.setAuthor("Nobody"); - FPoint[] points = new FPoint[]{ // Define a FPoint array containing the points of the shape - new FPoint(0, 0), - new FPoint(512,0), - //new FPoint(256, 1024), - new FPoint(new FPoint(256,1024), new FPoint(512,512)), - new FPoint(0, 0) - }; + FPoint[] points = new FPoint[]{ // Define a FPoint array containing the points of the shape + new FPoint(0, 0), + new FPoint(512, 0), + //new FPoint(256, 1024), + new FPoint(new FPoint(256, 1024), new FPoint(512, 512)), + new FPoint(0, 0) + }; f.addGlyph('P').addContour(points); // Assign contour to character A - f.buildFont(); + f.buildFont(); } - } diff --git a/libsrc/ttf/src/org/doubletype/ossa/Engine.java b/libsrc/ttf/src/org/doubletype/ossa/Engine.java index 768b428f4..a3f2d6499 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/Engine.java +++ b/libsrc/ttf/src/org/doubletype/ossa/Engine.java @@ -1,8 +1,8 @@ /* * $Id: Engine.java,v 1.84 2004/12/27 04:56:03 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,232 +25,231 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa; +import java.io.File; +import java.io.FileNotFoundException; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.*; -import java.io.*; +import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; - -import org.doubletype.ossa.module.*; -import org.doubletype.ossa.truetype.*; +import org.doubletype.ossa.module.GlyphFile; +import org.doubletype.ossa.module.TypefaceFile; +import org.doubletype.ossa.truetype.TTCodePage; +import org.doubletype.ossa.truetype.TTUnicodeRange; /** * @author e.e */ public class Engine { - private TypefaceFile m_typeface; - private GlyphFile m_root; - // -------------------------------------------------------------- + private TypefaceFile m_typeface; - public Engine() { - } - - public void setAdvanceWidth(int a_value) { - if (m_root == null) - return; + private GlyphFile m_root; - m_root.setAdvanceWidth(a_value); - } - - public void buildNewTypeface(String a_name, File a_dir) throws FileNotFoundException { - if (a_name == null || a_name.equals("")) { - return; - } - - TypefaceFile typeface = new TypefaceFile(a_name, a_dir); - typeface.setAuthor("no body"); - DateFormat format = new SimpleDateFormat("yyyy"); - typeface.setCopyrightYear(format.format(new Date())); - typeface.setFontFamilyName(a_name); - typeface.setSubFamily("Regular"); - typeface.addCodePage(TTCodePage.US_ASCII.toString()); - typeface.addCodePage(TTCodePage.Latin_1.toString()); + // -------------------------------------------------------------- + public Engine() { + } - setTypeface(typeface); - } + public void setAdvanceWidth(int a_value) { + if (m_root == null) { + return; + } - public void addDefaultGlyphs() { - m_typeface.addRequiredGlyphs(); - m_typeface.addBasicLatinGlyphs(); - } + m_root.setAdvanceWidth(a_value); + } - public void setTypeface(TypefaceFile a_typeface) { - m_typeface = a_typeface; - } + public void buildNewTypeface(String a_name, File a_dir) throws FileNotFoundException { + if (a_name == null || a_name.equals("")) { + return; + } - /** - * Create glyph out of given unicode, and add it to the typeface. - * @param a_unicode - */ - public GlyphFile addNewGlyph(long a_unicode) { - GlyphFile retval; + TypefaceFile typeface = new TypefaceFile(a_name, a_dir); + typeface.setAuthor("no body"); + DateFormat format = new SimpleDateFormat("yyyy"); + typeface.setCopyrightYear(format.format(new Date())); + typeface.setFontFamilyName(a_name); + typeface.addCodePage(TTCodePage.US_ASCII.toString()); + typeface.addCodePage(TTCodePage.Latin_1.toString()); - retval = m_typeface.createGlyph(a_unicode); - addGlyphToTypeface(retval); + setTypeface(typeface); + } - return retval; - } + public void addDefaultGlyphs() { + m_typeface.addRequiredGlyphs(); + m_typeface.addBasicLatinGlyphs(); + } - public void checkUnicodeBlock(long a_unicode) { - TTUnicodeRange range = TTUnicodeRange.of(a_unicode); - if (range == null){ - return; - } + public void setTypeface(TypefaceFile a_typeface) { + m_typeface = a_typeface; + } - if (m_typeface.containsUnicodeRange(range.toString())){ - return; - } - m_typeface.addUnicodeRange(range.toString()); - } + /** + * Create glyph out of given unicode, and add it to the typeface. + * + * @param a_unicode + */ + public GlyphFile addNewGlyph(long a_unicode) { + GlyphFile retval; - private void addGlyphToTypeface(GlyphFile a_file) { - m_typeface.addGlyph(a_file); + retval = m_typeface.createGlyph(a_unicode); + addGlyphToTypeface(retval); - setRoot(a_file); - } + return retval; + } - public void buildTrueType() { - if (m_typeface == null) - return; + public void checkUnicodeBlock(long a_unicode) { + TTUnicodeRange range = TTUnicodeRange.of(a_unicode); + if (range == null) { + return; + } + if (m_typeface.containsUnicodeRange(range.toString())) { + return; + } + m_typeface.addUnicodeRange(range.toString()); + } + private void addGlyphToTypeface(GlyphFile a_file) { + m_typeface.addGlyph(a_file); - try { - m_typeface.buildTTF(); - m_typeface.getFont(); - } catch (Exception e) { - Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null,e); - } // try-catch + setRoot(a_file); + } - return; - } + public void buildTrueType() { + if (m_typeface == null) { + return; + } - public TypefaceFile getTypeface() { - return m_typeface; - } + try { + m_typeface.buildTTF(); + m_typeface.getFont(); + } catch (Exception e) { + Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, e); + } - public File getGlyphPath() { - return m_typeface.getGlyphPath(); - } - + return; + } - public GlyphFile getRoot() { - return m_root; - } + public TypefaceFile getTypeface() { + return m_typeface; + } - public void setRoot(GlyphFile a_file) { - m_root = a_file; - } + public File getGlyphPath() { + return m_typeface.getGlyphPath(); + } - public void addCodePage(String a_codePage) { - if (m_typeface == null) { - return; - } + public GlyphFile getRoot() { + return m_root; + } - m_typeface.addCodePage(a_codePage); - } + public void setRoot(GlyphFile a_file) { + m_root = a_file; + } - public void removeCodePage(String a_codePage) { - if (m_typeface == null) { - return; - } + public void addCodePage(String a_codePage) { + if (m_typeface == null) { + return; + } - m_typeface.removeCodePage(a_codePage); - } + m_typeface.addCodePage(a_codePage); + } - public void setAuthor(String a_value) { - if (m_typeface == null) { - return; - } + public void removeCodePage(String a_codePage) { + if (m_typeface == null) { + return; + } - m_typeface.setAuthor(a_value); - } + m_typeface.removeCodePage(a_codePage); + } - public void setCopyrightYear(String a_value) { - if (m_typeface == null) { - return; - } + public void setAuthor(String a_value) { + if (m_typeface == null) { + return; + } - m_typeface.setCopyrightYear(a_value); - } + m_typeface.setAuthor(a_value); + } - public void setFontFamilyName(String a_value) { - if (m_typeface == null) { - return; - } + public void setCopyrightYear(String a_value) { + if (m_typeface == null) { + return; + } - m_typeface.setFontFamilyName(a_value); - } + m_typeface.setCopyrightYear(a_value); + } - public void setTypefaceLicense(String a_value) { - if (m_typeface == null) { - return; - } + public void setFontFamilyName(String a_value) { + if (m_typeface == null) { + return; + } - m_typeface.setLicense(a_value); - } + m_typeface.setFontFamilyName(a_value); + } - public void setBaseline(double a_value) { - if (m_typeface == null) { - return; - } - - double min = m_typeface.getBottomSideBearing(); - double max = m_typeface.getMeanline(); - - if (a_value < min) { - a_value = min; - } - - if (a_value > max) { - a_value = max; - } - - try { - m_typeface.setDescender(a_value - min); - m_typeface.setAscender(m_typeface.getEm() - - m_typeface.getTopSideBearing() - a_value); - m_typeface.setXHeight(max - a_value); - } - catch (OutOfRangeException e) { - e.printStackTrace(); - } // try-catch - } - - public void setMeanline(double a_value) { - if (m_typeface == null) { - return; - } - - double min = m_typeface.getBaseline(); - double max = m_typeface.getEm() - - m_typeface.getTopSideBearing(); - - if (a_value < min) { - a_value = min; - } - - if (a_value > max) { - a_value = max; - } - - try { - m_typeface.setXHeight(a_value - min); - } - catch (OutOfRangeException e) { - e.printStackTrace(); - } // try-catch - } + public void setTypefaceLicense(String a_value) { + if (m_typeface == null) { + return; + } + + m_typeface.setLicense(a_value); + } + + public void setBaseline(double a_value) { + if (m_typeface == null) { + return; + } + + double min = m_typeface.getBottomSideBearing(); + double max = m_typeface.getMeanline(); + + if (a_value < min) { + a_value = min; + } + + if (a_value > max) { + a_value = max; + } + + try { + m_typeface.setDescender(a_value - min); + m_typeface.setAscender(m_typeface.getEm() + - m_typeface.getTopSideBearing() - a_value); + m_typeface.setXHeight(max - a_value); + } catch (OutOfRangeException e) { + e.printStackTrace(); + } + } + + public void setMeanline(double a_value) { + if (m_typeface == null) { + return; + } + + double min = m_typeface.getBaseline(); + double max = m_typeface.getEm() + - m_typeface.getTopSideBearing(); + + if (a_value < min) { + a_value = min; + } + + if (a_value > max) { + a_value = max; + } + + try { + m_typeface.setXHeight(a_value - min); + } catch (OutOfRangeException e) { + e.printStackTrace(); + } + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/OutOfRangeException.java b/libsrc/ttf/src/org/doubletype/ossa/OutOfRangeException.java index 4016eabe9..5fff226d6 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/OutOfRangeException.java +++ b/libsrc/ttf/src/org/doubletype/ossa/OutOfRangeException.java @@ -1,49 +1,49 @@ -/* - * $Id: OutOfRangeException.java,v 1.1 2004/02/23 14:19:30 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - -package org.doubletype.ossa; - -/** - * @author e.e - */ -public class OutOfRangeException extends Exception { - private double m_value; - - public OutOfRangeException(double a_value) { - super(); - - m_value = a_value; - } -} +/* + * $Id: OutOfRangeException.java,v 1.1 2004/02/23 14:19:30 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2003, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ +package org.doubletype.ossa; + +/** + * @author e.e + */ +public class OutOfRangeException extends Exception { + + private final double value; + + public OutOfRangeException(double value) { + super(); + + this.value = value; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/CubicSegment.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/CubicSegment.java index fd6c14485..43696488e 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/CubicSegment.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/CubicSegment.java @@ -1,8 +1,8 @@ /* * $Id: CubicSegment.java,v 1.2 2004/12/27 04:56:02 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -13,95 +13,99 @@ * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, e.e d3si9n gives permission to * link the code of this program with any Java Platform that is available * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.adapter; -import java.util.*; -import java.awt.geom.*; +import java.awt.geom.Point2D; +import java.util.ArrayList; /** * @author e.e */ public class CubicSegment { + public static final int LINE = 0; + public static final int CURVE = 1; - + /** * converts cubic contour into cubic segments. + * * @param a_contour * @return */ public static ArrayList toSegments(EContour a_contour) { ArrayList retval = new ArrayList<>(); ArrayList points = a_contour.getContourPoints(); - if (points.size() < 2) { - return retval; - } - - EContourPoint startPoint = (EContourPoint) points.get(points.size() - 1); - for (int i = 0; i < points.size(); i++) { - EContourPoint endPoint = (EContourPoint) points.get(i); - retval.add(new CubicSegment(startPoint, endPoint)); - startPoint = endPoint; - } // for - + if (points.size() < 2) { + return retval; + } + + EContourPoint startPoint = (EContourPoint) points.get(points.size() - 1); + for (int i = 0; i < points.size(); i++) { + EContourPoint endPoint = (EContourPoint) points.get(i); + retval.add(new CubicSegment(startPoint, endPoint)); + startPoint = endPoint; + } // for + return retval; } - + private EContourPoint m_startPoint = null; + private EContourPoint m_controlPoint1 = null; + private EContourPoint m_controlPoint2 = null; + private EContourPoint m_endPoint = null; - + private int m_type = LINE; - - + public CubicSegment(EContourPoint a_startPoint, EContourPoint a_endPoint) { m_startPoint = a_startPoint; m_endPoint = a_endPoint; - + if ((!a_startPoint.hasControlPoint2()) && (!a_endPoint.hasControlPoint1())) { m_type = LINE; return; } - + if (a_startPoint.hasControlPoint2() || a_endPoint.hasControlPoint1()) { m_type = CURVE; - + if (a_startPoint.hasControlPoint2()) { m_controlPoint1 = a_startPoint.getControlPoint2().getContourPoint(); } else { m_controlPoint1 = a_startPoint; } - + if (a_endPoint.hasControlPoint1()) { m_controlPoint2 = a_endPoint.getControlPoint1().getContourPoint(); } else { m_controlPoint1 = a_endPoint; - } + } } } - - public CubicSegment(EContourPoint a_startPoint, EContourPoint a_controlPoint1, + + public CubicSegment(EContourPoint a_startPoint, EContourPoint a_controlPoint1, EContourPoint a_controlPoint2, EContourPoint a_endPoint) { m_startPoint = a_startPoint; m_controlPoint1 = a_controlPoint1; @@ -109,18 +113,18 @@ public class CubicSegment { m_endPoint = a_endPoint; m_type = CURVE; } - - public ArrayList toQuadraticSegments() { + + public ArrayList toQuadraticSegments() { ArrayList retval = new ArrayList<>(); - + if (m_type == LINE) { retval.add(new QuadraticSegment(m_startPoint, null, m_endPoint)); return retval; } - + return toQuadraticSegments(0); } - + //JPEXS start private static Point2D.Double movePoint(Point2D point, double dx, double dy) { return new Point2D.Double(point.getX() + dx, point.getY() + dy); @@ -135,6 +139,7 @@ public class CubicSegment { double y = p0.getY() + ((p1.getY() - p0.getY()) * ratio); return new Point2D.Double(x, y); } + private static double[][] approximateCubic(double[] cubicControlPointCoords) { if (cubicControlPointCoords.length < 8) { throw new IllegalArgumentException("Must have at least 8 coordinates"); @@ -180,21 +185,20 @@ public class CubicSegment { {pc3.getX(), pc3.getY(), pa3.getX(), pa3.getY()}, {pc4.getX(), pc4.getY(), p3.getX(), p3.getY()}}; } - + //JPEXS end - private ArrayList toQuadraticSegments(int a_trial) { ArrayList retval = new ArrayList<>(); - - double[][] quadCoords =approximateCubic(new double[]{m_startPoint.getX(),m_startPoint.getY(),m_controlPoint1.getX(),m_controlPoint1.getY(),m_controlPoint2.getX(),m_controlPoint2.getY(),m_endPoint.getX(),m_endPoint.getY()}); - EContourPoint lastPoint=m_startPoint; - for (int i = 0; i < quadCoords.length; i++) { - retval.add(new QuadraticSegment( - lastPoint, - new EContourPoint(quadCoords[i][0], quadCoords[i][1], true), - new EContourPoint(quadCoords[i][2], quadCoords[i][3], false))); - lastPoint = new EContourPoint(quadCoords[i][2],quadCoords[i][3],true); - } + + double[][] quadCoords = approximateCubic(new double[]{m_startPoint.getX(), m_startPoint.getY(), m_controlPoint1.getX(), m_controlPoint1.getY(), m_controlPoint2.getX(), m_controlPoint2.getY(), m_endPoint.getX(), m_endPoint.getY()}); + EContourPoint lastPoint = m_startPoint; + for (int i = 0; i < quadCoords.length; i++) { + retval.add(new QuadraticSegment( + lastPoint, + new EContourPoint(quadCoords[i][0], quadCoords[i][1], true), + new EContourPoint(quadCoords[i][2], quadCoords[i][3], false))); + lastPoint = new EContourPoint(quadCoords[i][2], quadCoords[i][3], true); + } return retval; } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java index 6e2c1b84a..cd6bfdee9 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java @@ -1,8 +1,8 @@ /* * $Id: EContour.java,v 1.11 2004/12/17 04:13:17 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -13,26 +13,25 @@ * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, e.e d3si9n gives permission to * link the code of this program with any Java Platform that is available * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.adapter; import java.util.ArrayList; @@ -41,46 +40,45 @@ import java.util.ArrayList; * @author e.e */ public class EContour { - public static final String k_quadratic = "quadratic"; - public static final String k_cubic = "cubic"; - - private String type; - private ArrayList m_contourPoints = new ArrayList<>(); - - // -------------------------------------------------------------- - - public EContour() { - setType(k_quadratic); - } - - public boolean isCubic() { - return type.equals(k_cubic); - } - - public void setType(String a_type) { - type = a_type; - } - - public void addContourPoint(EContourPoint a_point) { - m_contourPoints.add(a_point); - } - - public ArrayList getContourPoints() { - return m_contourPoints; - } - // -------------------------------------------------------------- - + public static final String k_quadratic = "quadratic"; + + public static final String k_cubic = "cubic"; + + private String type; + + private ArrayList m_contourPoints = new ArrayList<>(); + + public EContour() { + setType(k_quadratic); + } + + public boolean isCubic() { + return type.equals(k_cubic); + } + + public void setType(String a_type) { + type = a_type; + } + + public void addContourPoint(EContourPoint a_point) { + m_contourPoints.add(a_point); + } + + public ArrayList getContourPoints() { + return m_contourPoints; + } + public EContour toQuadratic() { if (!isCubic()) { return this; } - - ArrayList quadraticSegments = new ArrayList<>(); - for (CubicSegment segment: CubicSegment.toSegments(this)) { - quadraticSegments.addAll(segment.toQuadraticSegments()); - } - + + ArrayList quadraticSegments = new ArrayList<>(); + for (CubicSegment segment : CubicSegment.toSegments(this)) { + quadraticSegments.addAll(segment.toQuadraticSegments()); + } + return QuadraticSegment.toContour(quadraticSegments); } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/EContourPoint.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/EContourPoint.java index 07563d1a1..c75ec21aa 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/EContourPoint.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/EContourPoint.java @@ -1,8 +1,8 @@ /* * $Id: EContourPoint.java,v 1.10 2004/12/27 04:56:02 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -13,88 +13,92 @@ * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, e.e d3si9n gives permission to * link the code of this program with any Java Platform that is available * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.adapter; /** * @author e.e */ -public class EContourPoint implements EPoint { - private boolean isOn; - private double x; - private double y; - private EControlPoint controlPoint1; - private EControlPoint controlPoint2; - - public EContourPoint() { - super(); - } - - public EContourPoint(double a_x, double a_y, boolean a_isOn) { - x = a_x; - y = a_y; - - setOn(a_isOn); - } - - public static final int k_defaultPixelSize = 16; +public final class EContourPoint implements EPoint { - public double getX() { - return x; - } - - public double getY() { - return y; - } + private boolean isOn; - public EControlPoint getControlPoint1() { - return controlPoint1; - } - - public EControlPoint getControlPoint2() { - return controlPoint2; - } - - public void setControlPoint1(EControlPoint a_point) { - controlPoint1 = a_point; - } - - public void setControlPoint2(EControlPoint a_point) { - controlPoint2 = a_point; - } - - public boolean hasControlPoint1() { - return getControlPoint1() != null; - } - - public boolean hasControlPoint2() { - return getControlPoint2() != null; - } - - public boolean isOn() { - return isOn; - } - - public void setOn(boolean a_isOnCurve) { - isOn = a_isOnCurve; - } -} \ No newline at end of file + private double x; + + private double y; + + private EControlPoint controlPoint1; + + private EControlPoint controlPoint2; + + public EContourPoint() { + super(); + } + + public EContourPoint(double a_x, double a_y, boolean a_isOn) { + x = a_x; + y = a_y; + + setOn(a_isOn); + } + + public static final int k_defaultPixelSize = 16; + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public EControlPoint getControlPoint1() { + return controlPoint1; + } + + public EControlPoint getControlPoint2() { + return controlPoint2; + } + + public void setControlPoint1(EControlPoint a_point) { + controlPoint1 = a_point; + } + + public void setControlPoint2(EControlPoint a_point) { + controlPoint2 = a_point; + } + + public boolean hasControlPoint1() { + return getControlPoint1() != null; + } + + public boolean hasControlPoint2() { + return getControlPoint2() != null; + } + + public boolean isOn() { + return isOn; + } + + public void setOn(boolean a_isOnCurve) { + isOn = a_isOnCurve; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/EControlPoint.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/EControlPoint.java index d4c3e59f2..c28850583 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/EControlPoint.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/EControlPoint.java @@ -1,8 +1,8 @@ /* * $Id: EControlPoint.java,v 1.6 2004/12/27 04:56:02 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,43 +25,35 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.adapter; -import java.awt.Shape; -import java.awt.geom.AffineTransform; - /** * @author e.e */ public class EControlPoint implements EPoint { - + private EContourPoint contourPoint; - - /** - * - */ + public EControlPoint(double x, double y) { contourPoint = new EContourPoint(x, y, false); } - public double getX() { - return contourPoint.getX(); - } - - public double getY() { - return contourPoint.getY(); - } - - public EContourPoint getContourPoint() { - return contourPoint; - } -} + public double getX() { + return contourPoint.getX(); + } + public double getY() { + return contourPoint.getY(); + } + + public EContourPoint getContourPoint() { + return contourPoint; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java index 4a59fb58a..dce362dc6 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java @@ -1,44 +1,45 @@ -/* - * $Id: EPoint.java,v 1.1 2004/12/27 04:56:02 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2004, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - -package org.doubletype.ossa.adapter; - -/** - * @author e.e - */ -public interface EPoint { - double getX(); - double getY(); -} +/* + * $Id: EPoint.java,v 1.1 2004/12/27 04:56:02 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2004, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ +package org.doubletype.ossa.adapter; + +/** + * @author e.e + */ +public interface EPoint { + + double getX(); + + double getY(); +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/adapter/QuadraticSegment.java b/libsrc/ttf/src/org/doubletype/ossa/adapter/QuadraticSegment.java index 6ab69facd..9ff1b6f91 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/adapter/QuadraticSegment.java +++ b/libsrc/ttf/src/org/doubletype/ossa/adapter/QuadraticSegment.java @@ -1,8 +1,8 @@ /* * $Id: QuadraticSegment.java,v 1.1 2004/12/15 11:54:18 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,42 +25,44 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.adapter; -import java.util.*; +import java.util.ArrayList; /** * @author e.e */ public class QuadraticSegment { + public static final int LINE = 0; + public static final int CURVE = 1; - + /** * converts quadratic contour into a list of quadratic segments. + * * @param a_contour * @return */ public static ArrayList toSegments(EContour a_contour) { ArrayList retval = new ArrayList<>(); - + ArrayList points = toConcreatePoints(a_contour); if (points.size() < 3) { return retval; } - + for (int i = 0; i < points.size() - 1; i++) { EContourPoint startPoint = (EContourPoint) points.get(i); EContourPoint nextPoint = (EContourPoint) points.get(i + 1); - + // if this is a line segment if (nextPoint.isOn()) { retval.add(new QuadraticSegment(startPoint, null, nextPoint)); @@ -71,117 +73,122 @@ public class QuadraticSegment { retval.add(new QuadraticSegment(startPoint, offCurvePoint, nextPoint)); } } - + return retval; } - + /** * converts a list of quadratic segments into a quadratic contour. + * * @param a_segments * @return */ public static EContour toContour(ArrayList a_segments) { EContour retval = new EContour(); retval.setType(EContour.k_quadratic); - - for (QuadraticSegment segment: a_segments) { + + for (QuadraticSegment segment : a_segments) { EContourPoint p = segment.m_startPoint; EContourPoint startPoint = new EContourPoint(p.getX(), p.getY(), p.isOn()); startPoint.setControlPoint1(null); startPoint.setControlPoint2(null); - + if (segment.m_type == LINE) { retval.addContourPoint(startPoint); - + } else { retval.addContourPoint(startPoint); retval.addContourPoint(segment.m_offCurvePoint); } } - + return retval; } - + /** * converts quadratic contour to concreate points by inserting * on-curve point between off-curve points. + * * @param a_contour * @return */ private static ArrayList toConcreatePoints(EContour a_contour) { ArrayList retval = new ArrayList<>(); - + ArrayList points = a_contour.getContourPoints(); - if (points.size() < 3) - return retval; - - EContourPoint fromPoint = (EContourPoint) points.get(points.size() - 1); - for (EContourPoint point: points) { - EContourPoint toPoint = (EContourPoint) point; - if (!toPoint.isOn() && !fromPoint.isOn()) { - double xMidpoint = (toPoint.getX() + fromPoint.getX()) / 2; - double yMidpoint = (toPoint.getY() + fromPoint.getY()) / 2; - retval.add(new EContourPoint(xMidpoint, yMidpoint, true)); - } - - retval.add(toPoint); - fromPoint = toPoint; - } - - // all contours should start with on-curve point - // move off-curve point to the end if a contour starts with one. - EContourPoint firstPoint = (EContourPoint) retval.get(0); - if (!firstPoint.isOn()) { - retval.remove(0); - retval.add(firstPoint); - } - - retval.add(retval.get(0)); - + if (points.size() < 3) { + return retval; + } + + EContourPoint fromPoint = (EContourPoint) points.get(points.size() - 1); + for (EContourPoint point : points) { + EContourPoint toPoint = (EContourPoint) point; + if (!toPoint.isOn() && !fromPoint.isOn()) { + double xMidpoint = (toPoint.getX() + fromPoint.getX()) / 2; + double yMidpoint = (toPoint.getY() + fromPoint.getY()) / 2; + retval.add(new EContourPoint(xMidpoint, yMidpoint, true)); + } + + retval.add(toPoint); + fromPoint = toPoint; + } + + // all contours should start with on-curve point + // move off-curve point to the end if a contour starts with one. + EContourPoint firstPoint = (EContourPoint) retval.get(0); + if (!firstPoint.isOn()) { + retval.remove(0); + retval.add(firstPoint); + } + + retval.add(retval.get(0)); + return retval; } - + private EContourPoint m_startPoint; + private EContourPoint m_offCurvePoint; + private EContourPoint m_endPoint; - + private int m_type = LINE; - + /** - * + * */ public QuadraticSegment(EContourPoint a_startPoint, EContourPoint a_offCurvePoint, - EContourPoint a_endPoint) { + EContourPoint a_endPoint) { m_startPoint = a_startPoint; m_offCurvePoint = a_offCurvePoint; m_endPoint = a_endPoint; - + if (m_offCurvePoint != null) { m_type = CURVE; } } - + /** * Convert quadratic segment to cubic. + * * @param a_segment * @return */ - public CubicSegment toCubicSegment() { + public CubicSegment toCubicSegment() { // if the segment is a line if (m_type == LINE) { return new CubicSegment(m_startPoint, m_endPoint); } - + double x, y; x = m_startPoint.getX() + 2.0 / 3.0 * (m_offCurvePoint.getX() - m_startPoint.getX()); y = m_startPoint.getY() + 2.0 / 3.0 * (m_offCurvePoint.getY() - m_startPoint.getY()); EContourPoint controlPoint1 = new EContourPoint(x, y, false); - + x = m_offCurvePoint.getX() + 1.0 / 3.0 * (m_endPoint.getX() - m_offCurvePoint.getX()); y = m_offCurvePoint.getY() + 1.0 / 3.0 * (m_endPoint.getY() - m_offCurvePoint.getY()); EContourPoint controlPoint2 = new EContourPoint(x, y, false); - - return new CubicSegment(m_startPoint, controlPoint1, controlPoint2, m_endPoint); - } + return new CubicSegment(m_startPoint, controlPoint1, controlPoint2, m_endPoint); + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java b/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java index fa55c4126..0a34ae5cc 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java +++ b/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java @@ -1,6 +1,6 @@ - /* +/* * $Copyright: copyright (c) 2003-2008, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -11,281 +11,280 @@ * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, e.e d3si9n gives permission to * link the code of this program with any Java Platform that is available * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.module; -import org.doubletype.ossa.adapter.*; -import org.doubletype.ossa.truetype.*; - -import java.io.*; -import java.awt.*; - -import java.util.*; +import java.awt.Point; +import java.io.File; +import java.util.ArrayList; import java.util.List; +import org.doubletype.ossa.adapter.EContour; +import org.doubletype.ossa.adapter.EContourPoint; +import org.doubletype.ossa.truetype.TTGlyph; +import org.doubletype.ossa.truetype.TTUnicodeRange; /** * @author e.e */ public class GlyphFile { - private long m_unicode; - private String m_author; - private String m_copyrightYear; - private String m_license; - private Integer m_advanceWidth = null; - private List contours = new ArrayList<>(); - - // -------------------------------------------------------------- - - protected long m_modifiedTime = 0; - protected long m_savedTime = 0; - - private final int k_halfWidth = 512; - private final int k_fullWidth = 1024; - - // -------------------------------------------------------------- - - /** - * creates new file - */ - public GlyphFile(File a_dir, long a_unicode) { - super(); - - init(); - setUnicode(a_unicode); - - setAdvanceWidth(k_fullWidth); - } - - /** - * creates new file - * @param a_dir parent dir - */ - public GlyphFile(File a_dir) { - super(); - init(); - } - - private void init() { - m_savedTime = m_modifiedTime; - } - - /** - * initialize .notdef - */ - public void initNotDef(int a_advanceWidth) { - setAdvanceWidth(a_advanceWidth); - - EContour contour = new EContour(); - contour.setType(EContour.k_cubic); - contour.addContourPoint(new EContourPoint(0.0, 0.0, true)); - contour.addContourPoint(new EContourPoint(438.0, 0.0, true)); - contour.addContourPoint(new EContourPoint(438.0, 683.0, true)); - contour.addContourPoint(new EContourPoint(0.0, 683.0, true)); - addContour(contour); - - contour = new EContour(); - contour.setType(EContour.k_cubic); - contour.addContourPoint(new EContourPoint(365.0, 73.0, true)); - contour.addContourPoint(new EContourPoint(73.0, 73.0, true)); - contour.addContourPoint(new EContourPoint(73.0, 610.0, true)); - contour.addContourPoint(new EContourPoint(365.0, 610.0, true)); - addContour(contour); - } - - public void initNullGlyph() { - setAdvanceWidth(0); - } - - public void initSpace(int a_advanceWidth) { - setAdvanceWidth(a_advanceWidth); - } - - public void beforePush() { - } - - // -------------------------------------------------------------- - - public boolean hasUnsavedChange() { - return (m_savedTime != m_modifiedTime); - } - - public void setAuthor(String a_value) { - m_author = a_value; - } - - public String getAuthor() { - return m_author; - } - - public void setCopyrightYear(String a_value) { - m_copyrightYear = a_value; - } - - public String getCopyrightYear() { - return m_copyrightYear; - } - - public void setAdvanceWidth(int a_width) { - m_advanceWidth = a_width; - } - - public int getAdvanceWidth() { - if (m_advanceWidth == null) { - return k_halfWidth; - } - - return m_advanceWidth; - } - - - // -------------------------------------------------------------- - - public static final int k_defaultPixelSize = 16; //PPM - - // -------------------------------------------------------------- - - /** - * Generates array of XContour from local contours and modules. - * Used for TTF building. - */ - private EContour [] toContours() { - EContour [] retval; - ArrayList list = new ArrayList<>(); - for (EContour contour : contours) { - list.add(contour.toQuadratic()); - } - - if (list.size() == 0) - return null; - - retval = new EContour[list.size()]; - for (int i = 0; i < list.size(); i++) { - retval[i] = list.get(i); - } - - return retval; - } - - // -------------------------------------------------------------- - - /** add contour from clipboard or ContourAction - * @param a_contour - */ - public void addContour(EContour a_contour) { - contours.add(a_contour); - } - + private long m_unicode; - // -------------------------------------------------------------- - - - public long getUnicode() { - return m_unicode; - } - - protected void setUnicode(long a_unicode) { - m_unicode = a_unicode; - } - - public boolean isSimple() { - return true; - } - - public boolean isWhiteSpace() { - long unicode = getUnicode(); - - if (unicode == 0x0020 - || unicode == 0x00a0 - || unicode == 0x200b - || unicode == 0x2060 - || unicode == 0x3000 - || unicode == 0xfeff) - { - return true; - } - - return false; - } - - public void setLicense(String a_value) { - m_license = a_value; - } - - public String getLicense() { - return m_license; - } - - public boolean isRequiredGlyph() { - long unicode = getUnicode(); - - return (unicode == TTUnicodeRange.k_notDef - || unicode == TTUnicodeRange.k_null - || unicode == TTUnicodeRange.k_cr - || unicode == TTUnicodeRange.k_space); - } - - public TTGlyph toSimpleGlyph() { - // convert the file into array of contours - EContour [] contours = toContours(); - if ((contours == null) && (!isRequiredGlyph())) { - return null; - } - - TTGlyph retval = new TTGlyph(); - retval.setSimple(true); - retval.setAdvanceWidth(getAdvanceWidth()); - - if (contours == null) { - return retval; - } - - ArrayList points = new ArrayList<>(); - for (int i = 0; i < contours.length; i++) { - EContour contour = contours[i]; - ArrayList contourPoints = contour.getContourPoints(); - for (int j = 0; j < contourPoints.size(); j++) { - points.add((EContourPoint) contourPoints.get(j)); - } // for j - retval.addEndPoint(points.size() - 1); - } - - for (EContourPoint point: points) { - loadContourPoint(retval, point); - } // for point - - return retval; - } - - private void loadContourPoint(TTGlyph a_glyph, EContourPoint a_point) { - double x = a_point.getX(); - double y = a_point.getY(); - Point p = new Point((int) x, (int) y); - int flag = 0; - if (a_point.isOn()) { - flag = TTGlyph.k_onCurve; - } - - a_glyph.addPoint(p); - a_glyph.addFlag(flag); - } -} \ No newline at end of file + private String m_author; + + private String m_copyrightYear; + + private String m_license; + + private Integer m_advanceWidth = null; + + private List m_contours = new ArrayList<>(); + + // -------------------------------------------------------------- + protected long m_modifiedTime = 0; + + protected long m_savedTime = 0; + + private final int k_halfWidth = 512; + + private final int k_fullWidth = 1024; + + // -------------------------------------------------------------- + /** + * creates new file + */ + public GlyphFile(File a_dir, long a_unicode) { + super(); + + init(); + setUnicode(a_unicode); + + setAdvanceWidth(k_fullWidth); + } + + /** + * creates new file + * + * @param a_dir parent dir + */ + public GlyphFile(File a_dir) { + super(); + init(); + } + + private void init() { + m_savedTime = m_modifiedTime; + } + + /** + * initialize .notdef + */ + public void initNotDef(int a_advanceWidth) { + setAdvanceWidth(a_advanceWidth); + + EContour contour = new EContour(); + contour.setType(EContour.k_cubic); + contour.addContourPoint(new EContourPoint(0.0, 0.0, true)); + contour.addContourPoint(new EContourPoint(438.0, 0.0, true)); + contour.addContourPoint(new EContourPoint(438.0, 683.0, true)); + contour.addContourPoint(new EContourPoint(0.0, 683.0, true)); + addContour(contour); + + contour = new EContour(); + contour.setType(EContour.k_cubic); + contour.addContourPoint(new EContourPoint(365.0, 73.0, true)); + contour.addContourPoint(new EContourPoint(73.0, 73.0, true)); + contour.addContourPoint(new EContourPoint(73.0, 610.0, true)); + contour.addContourPoint(new EContourPoint(365.0, 610.0, true)); + addContour(contour); + } + + public void initNullGlyph() { + setAdvanceWidth(0); + } + + public void initSpace(int a_advanceWidth) { + setAdvanceWidth(a_advanceWidth); + } + + public void beforePush() { + } + + // -------------------------------------------------------------- + public boolean hasUnsavedChange() { + return (m_savedTime != m_modifiedTime); + } + + public void setAuthor(String a_value) { + m_author = a_value; + } + + public String getAuthor() { + return m_author; + } + + public void setCopyrightYear(String a_value) { + m_copyrightYear = a_value; + } + + public String getCopyrightYear() { + return m_copyrightYear; + } + + public void setAdvanceWidth(int a_width) { + m_advanceWidth = a_width; + } + + public int getAdvanceWidth() { + if (m_advanceWidth == null) { + return k_halfWidth; + } + + return m_advanceWidth; + } + + // -------------------------------------------------------------- + public static final int k_defaultPixelSize = 16; //PPM + + // -------------------------------------------------------------- + /** + * Generates array of XContour from local contours and modules. + * Used for TTF building. + */ + private EContour[] toContours() { + EContour[] retval; + ArrayList list = new ArrayList<>(); + for (EContour contour : m_contours) { + list.add(contour.toQuadratic()); + } + + if (list.size() == 0) { + return null; + } + + retval = new EContour[list.size()]; + for (int i = 0; i < list.size(); i++) { + retval[i] = list.get(i); + } + + return retval; + } + + // -------------------------------------------------------------- + /** + * add contour from clipboard or ContourAction + * + * @param a_contour + */ + public void addContour(EContour a_contour) { + m_contours.add(a_contour); + } + + // -------------------------------------------------------------- + public long getUnicode() { + return m_unicode; + } + + protected void setUnicode(long a_unicode) { + m_unicode = a_unicode; + } + + public boolean isSimple() { + return true; + } + + public boolean isWhiteSpace() { + long unicode = getUnicode(); + + if (unicode == 0x0020 + || unicode == 0x00a0 + || unicode == 0x200b + || unicode == 0x2060 + || unicode == 0x3000 + || unicode == 0xfeff) { + return true; + } + + return false; + } + + public void setLicense(String a_value) { + m_license = a_value; + } + + public String getLicense() { + return m_license; + } + + public boolean isRequiredGlyph() { + long unicode = getUnicode(); + + return (unicode == TTUnicodeRange.k_notDef + || unicode == TTUnicodeRange.k_null + || unicode == TTUnicodeRange.k_cr + || unicode == TTUnicodeRange.k_space); + } + + public TTGlyph toSimpleGlyph() { + // convert the file into array of contours + EContour[] contours = toContours(); + if ((contours == null) && (!isRequiredGlyph())) { + return null; + } + + TTGlyph retval = new TTGlyph(); + retval.setSimple(true); + retval.setAdvanceWidth(getAdvanceWidth()); + + if (contours == null) { + return retval; + } + + ArrayList points = new ArrayList<>(); + for (int i = 0; i < contours.length; i++) { + EContour contour = contours[i]; + ArrayList contourPoints = contour.getContourPoints(); + for (int j = 0; j < contourPoints.size(); j++) { + points.add((EContourPoint) contourPoints.get(j)); + } // for j + retval.addEndPoint(points.size() - 1); + } + + for (EContourPoint point : points) { + loadContourPoint(retval, point); + } // for point + + return retval; + } + + private void loadContourPoint(TTGlyph a_glyph, EContourPoint a_point) { + double x = a_point.getX(); + double y = a_point.getY(); + Point p = new Point((int) x, (int) y); + int flag = 0; + if (a_point.isOn()) { + flag = TTGlyph.k_onCurve; + } + + a_glyph.addPoint(p); + a_glyph.addFlag(flag); + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/module/TypefaceFile.java b/libsrc/ttf/src/org/doubletype/ossa/module/TypefaceFile.java index fe5e3824a..11b32267e 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/module/TypefaceFile.java +++ b/libsrc/ttf/src/org/doubletype/ossa/module/TypefaceFile.java @@ -1,6 +1,6 @@ /* * $Copyright: copyright (c) 2003-2008, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -23,346 +23,370 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.module; -import java.io.*; -import java.util.*; - -import org.doubletype.ossa.*; -import org.doubletype.ossa.truetype.*; -import java.awt.*; +import java.awt.Font; +import java.awt.Point; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import org.doubletype.ossa.OutOfRangeException; +import org.doubletype.ossa.truetype.FontFileWriter; +import org.doubletype.ossa.truetype.TTCodePage; +import org.doubletype.ossa.truetype.TTGlyph; +import org.doubletype.ossa.truetype.TTUnicodeRange; /** * @author e.e */ -public class TypefaceFile extends GlyphFile { - private final double k_defaultTopSideBearing = 170; // 2 px - private final double k_defaultAscender = 683; // 8 px - private final double k_defaultXHeight = 424; // 5 px - private final double k_defaultDescender = 171; // 2 px - private final double k_defaultBottomSideBearing = 0; // 0 px - private final double k_em = 1024; - private final int k_defaultAdvanceWidth = 512; - private final String k_dotTtf = ".ttf"; - - private File m_dir; - private File m_ttfFile; - private Font m_font = null; - private List m_glyphFiles = new ArrayList<>(); - private List m_unicodeRanges = new ArrayList<>(); - private List m_codePages = new ArrayList<>(); - private String m_fontFamilyName; - private String m_subFamily; - private String m_version; - private Double m_topSideBearing = null; - private Double m_ascender = null; - private Double m_xHeight = null; - private Double m_descender = null; - private Double m_bottomSideBearing = null; - private String m_name; - - public TypefaceFile(String a_name, File a_dir) throws FileNotFoundException { - super(a_dir); - - m_dir = a_dir; - m_name = a_name; - initFileName(); - } - - public TypefaceFile(File a_file) { - super(a_file); - - m_dir = a_file.getParentFile(); - m_name = a_file.getName(); - - initFileName(); - } - - private void initFileName() { - - String fileName = m_name + k_dotTtf; - m_ttfFile = new File(m_dir, fileName); - } - - public GlyphFile createGlyph(long a_unicode) { - return new GlyphFile(getGlyphPath(), a_unicode); - } - - private GlyphFile getGlyphFileByUnicode(long code) { - for (GlyphFile glyphFile : m_glyphFiles) { - if (glyphFile.getUnicode() == code) { - return glyphFile; - } - } - - return null; - } - - public boolean addRequiredGlyphs() { - boolean retval = false; - - if (getGlyphFileByUnicode(TTUnicodeRange.k_notDef) == null) { - GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_notDef); - glyph.initNotDef(k_defaultAdvanceWidth); - addGlyph(0, glyph); - retval = true; - } - - if (getGlyphFileByUnicode(TTUnicodeRange.k_null) == null) { - GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_null); - glyph.initNullGlyph(); - addGlyph(1, glyph); - retval = true; - } - - if (getGlyphFileByUnicode(TTUnicodeRange.k_cr) == null) { - GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_cr); - glyph.initSpace(k_defaultAdvanceWidth); - addGlyph(2, glyph); - retval = true; - } - - if (getGlyphFileByUnicode(TTUnicodeRange.k_space) == null) { - GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_space); - glyph.initSpace(k_defaultAdvanceWidth); - addGlyph(3, glyph); - retval = true; - } - - return retval; - } - - public void addBasicLatinGlyphs() { - String basicLatin = Character.UnicodeBlock.BASIC_LATIN.toString(); - TTUnicodeRange.find(basicLatin); - TTUnicodeRange range = TTUnicodeRange.getLastFound(); - addUnicodeRange(basicLatin); - for (long i = range.getStartCode(); i <= range.getEndCode(); i++) { - if (i != 0x0020) { - addGlyph(createGlyph(i)); - } - } - } - - public File getGlyphPath() { - return m_dir; - } - - /** - * change glyph's unicode mapping. - * @param a_glyphFile - * @param a_unicode - */ - public void setGlyphUnicode(GlyphFile a_glyphFile, long a_unicode) { - a_glyphFile.setUnicode(a_unicode); - } - - public void addGlyph(GlyphFile a_file) { - m_glyphFiles.add(a_file); - } - - public void addGlyph(int a_index, GlyphFile a_file) { - m_glyphFiles.add(a_index, a_file); - } - - public Object [] getCodePages() { - int i; - Object [] retval; - retval = new Object[0]; - - return retval; - } - - public boolean containsUnicodeRange(String a_unicodeRange) { - return m_unicodeRanges.contains(a_unicodeRange); - } - - public void addUnicodeRange(String a_unicodeRange) { - if (containsUnicodeRange(a_unicodeRange)) { - return; - } - - m_unicodeRanges.add(a_unicodeRange); - } - - public boolean containsCodePage(String a_codePage) { - return m_codePages.contains(a_codePage); - } - - public void addCodePage(String a_codePage) { - if (containsCodePage(a_codePage)) { - return; - } - - m_codePages.add(a_codePage); - } - - public void removeCodePage(String a_codePage) { - if (!containsCodePage(a_codePage)) { - return; - } - - m_codePages.remove(a_codePage); - } - - public void setFontFamilyName(String a_value) { - m_fontFamilyName = a_value; - } - - public String getFontFamilyName() { - return m_fontFamilyName; - } - - public String getVersion() { - return m_version == null ? "0.1" : m_version; - } - - public void setVersion(String a_value) { - m_version = a_value; - } - - public void setSubFamily(String a_value) { - m_subFamily = a_value; - } - - public void setDefaultMetrics() { - m_topSideBearing = k_defaultTopSideBearing; - m_ascender = k_defaultAscender; - m_xHeight = k_defaultXHeight; - m_descender = k_defaultDescender; - m_bottomSideBearing = k_defaultBottomSideBearing; - } - - public double getEm() { - return k_em; - } - - public double getBaseline() { - return getBottomSideBearing() + getDescender(); - } - - public double getMeanline() { - return getBottomSideBearing() - + getDescender() + getXHeight(); - } - - public double getBodyBottom() { - return getBottomSideBearing(); - } - - public double getBodyTop() { - return getEm() - getTopSideBearing(); - } - - public double getTopSideBearing() { - if (m_topSideBearing == null) { - setDefaultMetrics(); - } - - return m_topSideBearing; - } - - public double getAscender() { - if (m_ascender == null) { - setDefaultMetrics(); - } - - return m_ascender; - } - - public double getXHeight() { - if (m_xHeight == null) { - setDefaultMetrics(); - } - - return m_xHeight; - } - - public double getDescender() { - if (m_descender == null) { - setDefaultMetrics(); - } - - return m_descender; - } - - public double getBottomSideBearing() { - if (m_bottomSideBearing == null) { - setDefaultMetrics(); - } - - return m_bottomSideBearing; - } - - public void setTopSideBearing(double a_value) throws OutOfRangeException { - checkBoundary(a_value); - m_topSideBearing = a_value; - } - - private void checkBoundary(double a_value) throws OutOfRangeException { - if (a_value > k_em || a_value < 0) { - throw new OutOfRangeException(a_value); - } - } - - public void setAscender(double a_value) throws OutOfRangeException { - checkBoundary(a_value); - m_ascender = a_value; - } +public class TypefaceFile extends GlyphFile { - public void setXHeight(double a_value) throws OutOfRangeException { - checkBoundary(a_value); - if (a_value > getAscender()) { - throw new OutOfRangeException(a_value); - } - - m_xHeight = a_value; - } - - public void setDescender(double a_value) throws OutOfRangeException { - checkBoundary(a_value); - m_descender = a_value; - } - - public void setBottomSideBearing(double a_value) throws OutOfRangeException { - checkBoundary(a_value); - m_bottomSideBearing = a_value; - } - - public double getBodyHeight() { - return k_em - getTopSideBearing() - getBottomSideBearing(); - } - -// -------------------------------------------------------------------- - - /** - * Calls FontFileWriter to produce TrueType font file. - */ - public void buildTTF() throws Exception { - String randomString = UUID.randomUUID().toString().substring(0, 4); - - File tempFile = new File(m_dir, - m_name + "_" + randomString + k_dotTtf); - File target; - String fontFamilyName; - - target = m_ttfFile; - fontFamilyName = getFontFamilyName(); - - target.delete(); - FontFileWriter writer; + private final double k_defaultTopSideBearing = 170; // 2 px + + private final double k_defaultAscender = 683; // 8 px + + private final double k_defaultXHeight = 424; // 5 px + + private final double k_defaultDescender = 171; // 2 px + + private final double k_defaultBottomSideBearing = 0; // 0 px + + private final double k_em = 1024; + + private final int k_defaultAdvanceWidth = 512; + + private final String k_dotTtf = ".ttf"; + + private File m_dir; + + private File m_ttfFile; + + private Font m_font = null; + + private List m_glyphFiles = new ArrayList<>(); + + private List m_unicodeRanges = new ArrayList<>(); + + private List m_codePages = new ArrayList<>(); + + private String m_fontFamilyName; + + private String m_version; + + private Double m_topSideBearing = null; + + private Double m_ascender = null; + + private Double m_xHeight = null; + + private Double m_descender = null; + + private Double m_bottomSideBearing = null; + + private String m_name; + + public TypefaceFile(String a_name, File a_dir) throws FileNotFoundException { + super(a_dir); + + m_dir = a_dir; + m_name = a_name; + initFileName(); + } + + public TypefaceFile(File a_file) { + super(a_file); + + m_dir = a_file.getParentFile(); + m_name = a_file.getName(); + + initFileName(); + } + + private void initFileName() { + + String fileName = m_name + k_dotTtf; + m_ttfFile = new File(m_dir, fileName); + } + + public GlyphFile createGlyph(long a_unicode) { + return new GlyphFile(getGlyphPath(), a_unicode); + } + + private GlyphFile getGlyphFileByUnicode(long code) { + for (GlyphFile glyphFile : m_glyphFiles) { + if (glyphFile.getUnicode() == code) { + return glyphFile; + } + } + + return null; + } + + public boolean addRequiredGlyphs() { + boolean retval = false; + + if (getGlyphFileByUnicode(TTUnicodeRange.k_notDef) == null) { + GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_notDef); + glyph.initNotDef(k_defaultAdvanceWidth); + addGlyph(0, glyph); + retval = true; + } + + if (getGlyphFileByUnicode(TTUnicodeRange.k_null) == null) { + GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_null); + glyph.initNullGlyph(); + addGlyph(1, glyph); + retval = true; + } + + if (getGlyphFileByUnicode(TTUnicodeRange.k_cr) == null) { + GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_cr); + glyph.initSpace(k_defaultAdvanceWidth); + addGlyph(2, glyph); + retval = true; + } + + if (getGlyphFileByUnicode(TTUnicodeRange.k_space) == null) { + GlyphFile glyph = new GlyphFile(getGlyphPath(), TTUnicodeRange.k_space); + glyph.initSpace(k_defaultAdvanceWidth); + addGlyph(3, glyph); + retval = true; + } + + return retval; + } + + public void addBasicLatinGlyphs() { + String basicLatin = Character.UnicodeBlock.BASIC_LATIN.toString(); + TTUnicodeRange.find(basicLatin); + TTUnicodeRange range = TTUnicodeRange.getLastFound(); + addUnicodeRange(basicLatin); + for (long i = range.getStartCode(); i <= range.getEndCode(); i++) { + if (i != 0x0020) { + addGlyph(createGlyph(i)); + } + } + } + + public File getGlyphPath() { + return m_dir; + } + + /** + * change glyph's unicode mapping. + * + * @param a_glyphFile + * @param a_unicode + */ + public void setGlyphUnicode(GlyphFile a_glyphFile, long a_unicode) { + a_glyphFile.setUnicode(a_unicode); + } + + public void addGlyph(GlyphFile a_file) { + m_glyphFiles.add(a_file); + } + + public void addGlyph(int a_index, GlyphFile a_file) { + m_glyphFiles.add(a_index, a_file); + } + + public Object[] getCodePages() { + int i; + Object[] retval; + retval = new Object[0]; + + return retval; + } + + public boolean containsUnicodeRange(String a_unicodeRange) { + return m_unicodeRanges.contains(a_unicodeRange); + } + + public void addUnicodeRange(String a_unicodeRange) { + if (containsUnicodeRange(a_unicodeRange)) { + return; + } + + m_unicodeRanges.add(a_unicodeRange); + } + + public boolean containsCodePage(String a_codePage) { + return m_codePages.contains(a_codePage); + } + + public void addCodePage(String a_codePage) { + if (containsCodePage(a_codePage)) { + return; + } + + m_codePages.add(a_codePage); + } + + public void removeCodePage(String a_codePage) { + if (!containsCodePage(a_codePage)) { + return; + } + + m_codePages.remove(a_codePage); + } + + public void setFontFamilyName(String a_value) { + m_fontFamilyName = a_value; + } + + public String getFontFamilyName() { + return m_fontFamilyName; + } + + public String getVersion() { + return m_version == null ? "0.1" : m_version; + } + + public void setVersion(String a_value) { + m_version = a_value; + } + + public void setDefaultMetrics() { + m_topSideBearing = k_defaultTopSideBearing; + m_ascender = k_defaultAscender; + m_xHeight = k_defaultXHeight; + m_descender = k_defaultDescender; + m_bottomSideBearing = k_defaultBottomSideBearing; + } + + public double getEm() { + return k_em; + } + + public double getBaseline() { + return getBottomSideBearing() + getDescender(); + } + + public double getMeanline() { + return getBottomSideBearing() + + getDescender() + getXHeight(); + } + + public double getBodyBottom() { + return getBottomSideBearing(); + } + + public double getBodyTop() { + return getEm() - getTopSideBearing(); + } + + public double getTopSideBearing() { + if (m_topSideBearing == null) { + setDefaultMetrics(); + } + + return m_topSideBearing; + } + + public double getAscender() { + if (m_ascender == null) { + setDefaultMetrics(); + } + + return m_ascender; + } + + public double getXHeight() { + if (m_xHeight == null) { + setDefaultMetrics(); + } + + return m_xHeight; + } + + public double getDescender() { + if (m_descender == null) { + setDefaultMetrics(); + } + + return m_descender; + } + + public double getBottomSideBearing() { + if (m_bottomSideBearing == null) { + setDefaultMetrics(); + } + + return m_bottomSideBearing; + } + + public void setTopSideBearing(double a_value) throws OutOfRangeException { + checkBoundary(a_value); + m_topSideBearing = a_value; + } + + private void checkBoundary(double a_value) throws OutOfRangeException { + if (a_value > k_em || a_value < 0) { + throw new OutOfRangeException(a_value); + } + } + + public void setAscender(double a_value) throws OutOfRangeException { + checkBoundary(a_value); + m_ascender = a_value; + } + + public void setXHeight(double a_value) throws OutOfRangeException { + checkBoundary(a_value); + if (a_value > getAscender()) { + throw new OutOfRangeException(a_value); + } + + m_xHeight = a_value; + } + + public void setDescender(double a_value) throws OutOfRangeException { + checkBoundary(a_value); + m_descender = a_value; + } + + public void setBottomSideBearing(double a_value) throws OutOfRangeException { + checkBoundary(a_value); + m_bottomSideBearing = a_value; + } + + public double getBodyHeight() { + return k_em - getTopSideBearing() - getBottomSideBearing(); + } + + // -------------------------------------------------------------------- + /** + * Calls FontFileWriter to produce TrueType font file. + */ + public void buildTTF() throws Exception { + String randomString = UUID.randomUUID().toString().substring(0, 4); + + File tempFile = new File(m_dir, + m_name + "_" + randomString + k_dotTtf); + File target; + String fontFamilyName; + + target = m_ttfFile; + fontFamilyName = getFontFamilyName(); + + target.delete(); + FontFileWriter writer; try (RandomAccessFile randomAccessFile = new RandomAccessFile(target, "rw")) { writer = new FontFileWriter(randomAccessFile); - + writer.setFontFamilyName(fontFamilyName); writer.setCopyrightYear(getCopyrightYear()); writer.setFontVersion(getVersion()); @@ -371,154 +395,154 @@ public class TypefaceFile extends GlyphFile { writer.setXHeight((int) getXHeight()); writer.setDescent((int) getDescender()); writer.setLineGap((int) (getTopSideBearing() + getBottomSideBearing())); - + loadCodePages(writer); loadUnicodeRanges(writer); loadGlyphs(writer); writer.write(); } - if (target.exists()) { - copyFile(target, tempFile); - } - - FileInputStream in = new FileInputStream(tempFile); - m_font = Font.createFont(Font.TRUETYPE_FONT, - (InputStream) in); - in.close(); - } - - private void copyFile(File a_in, File a_out) throws Exception { - FileInputStream in = new FileInputStream(a_in); - FileOutputStream out = new FileOutputStream(a_out); - byte [] buffer = new byte[1024]; - int i = 0; - while ((i = in.read(buffer)) != -1) { - out.write(buffer, 0, i); - } // while - - in.close(); - out.close(); - } - - public Font getFont() { - return m_font; - } - - private void loadCodePages(FontFileWriter a_writer) { - for (String codePageName: m_codePages) { - TTCodePage codePage = TTCodePage.forName(codePageName); - if (codePage == null) { - continue; - } - - a_writer.setCodeRangeFlag(codePage.getOsTwoFlag()); - } // for codePageName - } - - private void loadUnicodeRanges(FontFileWriter a_writer) { - for (String unicodeRange : m_unicodeRanges) { - if (!TTUnicodeRange.find(unicodeRange)) { - continue; - } - - a_writer.addUnicodeRange(TTUnicodeRange.getLastFound()); - } - } - - private void loadGlyphs(FontFileWriter a_writer) throws Exception { - for (GlyphFile glyphFile : m_glyphFiles) { - loadGlyph(glyphFile, a_writer); - } - } - - /** - * load the glyph into FontFileWriter. - * @param a_fileName - * @param a_writer - * @throws Exception - */ - private void loadGlyph(GlyphFile a_glyphFile, FontFileWriter a_writer) throws Exception { - TTGlyph glyph = null; - - if (a_glyphFile.isSimple()) { - // glyph will be null if it is empty - glyph = a_glyphFile.toSimpleGlyph(); - } else { - glyph = createCompoundGlyph(a_glyphFile, a_writer); - } - - if (glyph == null && a_glyphFile.isWhiteSpace()) { - glyph = new TTGlyph(); - } - - if (glyph == null) { - return; - } - - int glyphIndex = a_writer.addGlyph(glyph); - long unicode = a_glyphFile.getUnicode(); - - if (unicode != -1) { - long existingIndex = a_writer.getCharacterMapping(unicode); - if (existingIndex != 0) { - throw new Exception(Long.toHexString(unicode) + " is mapped already."); - } - - a_writer.addCharacterMapping(unicode, glyphIndex); - } - } - - private TTGlyph createCompoundGlyph(GlyphFile a_glyphFile, - FontFileWriter a_writer) throws Exception - { - TTGlyph retval = new TTGlyph(); - ArrayList locs = new ArrayList<>(); - ArrayList indeces = new ArrayList<>(); - - retval.setSimple(false); - retval.setAdvanceWidth(a_glyphFile.getAdvanceWidth()); - - TTGlyph simple = a_glyphFile.toSimpleGlyph(); - if (simple != null) { - int glyphIndex = a_writer.addGlyph(simple); - - locs.add(new Point(0, 0)); - indeces.add(glyphIndex); - } - - int i = 0; - - int flag = TTGlyph.ARG_1_AND_2_ARE_WORDS - | TTGlyph.ARGS_ARE_XY_VALUES - | TTGlyph.ROUND_XY_TO_GRID; - int numOfCompositePoints = 0; - int numOfCompositeContours = 0; - int componentDepth = 0; - - for (int glyfIndex: indeces) { - TTGlyph glyph = a_writer.getGlyph(glyfIndex); - numOfCompositePoints += glyph.getNumOfCompositePoints(); - numOfCompositeContours += glyph.getNumOfCompositeContours(); - if (glyph.getComponentDepth() > componentDepth) { - componentDepth = glyph.getComponentDepth(); - } - - retval.addGlyfIndex(glyfIndex); - if (i < indeces.size() - 1) { - retval.addFlag(flag | TTGlyph.MORE_COMPONENTS); - } else { - retval.addFlag(flag); - } - - Point loc = locs.get(i); - retval.addArg1(loc.x); - retval.addArg2(loc.y); - } // for - - retval.setNumOfCompositePoints(numOfCompositePoints); - retval.setNumOfCompositeContours(numOfCompositeContours); - retval.setComponentDepth(componentDepth + 1); - - return retval; - } + if (target.exists()) { + copyFile(target, tempFile); + } + + FileInputStream in = new FileInputStream(tempFile); + m_font = Font.createFont(Font.TRUETYPE_FONT, + (InputStream) in); + in.close(); + } + + private void copyFile(File a_in, File a_out) throws Exception { + FileInputStream in = new FileInputStream(a_in); + FileOutputStream out = new FileOutputStream(a_out); + byte[] buffer = new byte[1024]; + int i = 0; + while ((i = in.read(buffer)) != -1) { + out.write(buffer, 0, i); + } // while + + in.close(); + out.close(); + } + + public Font getFont() { + return m_font; + } + + private void loadCodePages(FontFileWriter a_writer) { + for (String codePageName : m_codePages) { + TTCodePage codePage = TTCodePage.forName(codePageName); + if (codePage == null) { + continue; + } + + a_writer.setCodeRangeFlag(codePage.getOsTwoFlag()); + } // for codePageName + } + + private void loadUnicodeRanges(FontFileWriter a_writer) { + for (String unicodeRange : m_unicodeRanges) { + if (!TTUnicodeRange.find(unicodeRange)) { + continue; + } + + a_writer.addUnicodeRange(TTUnicodeRange.getLastFound()); + } + } + + private void loadGlyphs(FontFileWriter a_writer) throws Exception { + for (GlyphFile glyphFile : m_glyphFiles) { + loadGlyph(glyphFile, a_writer); + } + } + + /** + * load the glyph into FontFileWriter. + * + * @param a_fileName + * @param a_writer + * @throws Exception + */ + private void loadGlyph(GlyphFile a_glyphFile, FontFileWriter a_writer) throws Exception { + TTGlyph glyph = null; + + if (a_glyphFile.isSimple()) { + // glyph will be null if it is empty + glyph = a_glyphFile.toSimpleGlyph(); + } else { + glyph = createCompoundGlyph(a_glyphFile, a_writer); + } + + if (glyph == null && a_glyphFile.isWhiteSpace()) { + glyph = new TTGlyph(); + } + + if (glyph == null) { + return; + } + + int glyphIndex = a_writer.addGlyph(glyph); + long unicode = a_glyphFile.getUnicode(); + + if (unicode != -1) { + long existingIndex = a_writer.getCharacterMapping(unicode); + if (existingIndex != 0) { + throw new Exception(Long.toHexString(unicode) + " is mapped already."); + } + + a_writer.addCharacterMapping(unicode, glyphIndex); + } + } + + private TTGlyph createCompoundGlyph(GlyphFile a_glyphFile, + FontFileWriter a_writer) throws Exception { + TTGlyph retval = new TTGlyph(); + ArrayList locs = new ArrayList<>(); + ArrayList indeces = new ArrayList<>(); + + retval.setSimple(false); + retval.setAdvanceWidth(a_glyphFile.getAdvanceWidth()); + + TTGlyph simple = a_glyphFile.toSimpleGlyph(); + if (simple != null) { + int glyphIndex = a_writer.addGlyph(simple); + + locs.add(new Point(0, 0)); + indeces.add(glyphIndex); + } + + int i = 0; + + int flag = TTGlyph.ARG_1_AND_2_ARE_WORDS + | TTGlyph.ARGS_ARE_XY_VALUES + | TTGlyph.ROUND_XY_TO_GRID; + int numOfCompositePoints = 0; + int numOfCompositeContours = 0; + int componentDepth = 0; + + for (int glyfIndex : indeces) { + TTGlyph glyph = a_writer.getGlyph(glyfIndex); + numOfCompositePoints += glyph.getNumOfCompositePoints(); + numOfCompositeContours += glyph.getNumOfCompositeContours(); + if (glyph.getComponentDepth() > componentDepth) { + componentDepth = glyph.getComponentDepth(); + } + + retval.addGlyfIndex(glyfIndex); + if (i < indeces.size() - 1) { + retval.addFlag(flag | TTGlyph.MORE_COMPONENTS); + } else { + retval.addFlag(flag); + } + + Point loc = locs.get(i); + retval.addArg1(loc.x); + retval.addArg2(loc.y); + } // for + + retval.setNumOfCompositePoints(numOfCompositePoints); + retval.setNumOfCompositeContours(numOfCompositeContours); + retval.setComponentDepth(componentDepth + 1); + + return retval; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java index b76c0721e..4b32d7788 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/CmapWriter.java @@ -1,8 +1,8 @@ /* * $Id: CmapWriter.java,v 1.8 2004/01/27 00:35:08 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,291 +25,308 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author e.e */ public class CmapWriter extends FontFormatWriter { - final long k_basicLatinStart = 0x20; - final long k_basicLatinEnd = 0x7e; - final long k_tableEnd = 0xffff; - final int k_unmappedChar = 0x0; - - private OS2Writer m_os2; - private List m_unicodes = new ArrayList<>(); - private List m_startCodes = new ArrayList<>(); - private List m_endCodes = new ArrayList<>(); - private Hashtable m_unicode2glyph = new Hashtable<>(); - private List m_unicodeRanges = new ArrayList<>(); - private List m_idDeltas = new ArrayList<>(); - private List m_idRangeOffsets = new ArrayList<>(); - private boolean m_isIncludeVersion0; - private byte [] m_version0; - private byte [] m_version4; - private byte [] m_version12; - - public CmapWriter(OS2Writer a_os2) { - super(); - - m_os2 = a_os2; - m_isIncludeVersion0 = false; - } - - private void prepare() { - Collections.sort(m_unicodeRanges); - - TTUnicodeRange range = (TTUnicodeRange) m_unicodeRanges.get(0); - m_os2.m_usFirstCharIndex = (int) range.getStartCode(); - m_os2.m_usLastCharIndex = (int) range.getEndCode(); - - int i; - for (i = 0; i < m_unicodeRanges.size(); i++) { - range = m_unicodeRanges.get(i); - - m_startCodes.add(range.getStartCode()); - m_endCodes.add(range.getEndCode()); - m_idDeltas.add(0L); - m_idRangeOffsets.add( - 2L * (m_unicodeRanges.size() - i) + 2L - + 2L * (m_unicodes.size())); - - m_os2.m_usLastCharIndex = (int) range.getEndCode(); - m_os2.setUnicodeRangeFlag(range.getOsTwoFlag()); - - for (long unicode = range.getStartCode(); - unicode <= range.getEndCode(); unicode++) - { - m_unicodes.add(unicode); - } // for unicode - } - - m_startCodes.add(k_tableEnd); - m_endCodes.add(k_tableEnd); - m_idDeltas.add(1L); - m_idRangeOffsets.add(0L); - } - - public void write() throws IOException { - prepare(); - - if (m_isIncludeVersion0) { - storeVersion0(); - } - storeVersion4(); - - reset(); - - writeUInt16(0); // table version number - writeUInt16(getNumOfEncoding()); // num of encodings - - if (m_isIncludeVersion0) { - writeUInt16(TTName.k_macintosh); - writeUInt16(TTName.k_macRomanEncode); - writeUInt32(size() + 4 + 8); - } - - writeUInt16(TTName.k_microsoft); - writeUInt16(TTName.k_winUnicodeEncode); - int version4Offset = size() + 4; - if (m_isIncludeVersion0) { - version4Offset += m_version0.length; - } - writeUInt32(version4Offset); - - if (m_isIncludeVersion0) { - m_buffer.write(m_version0); - } - - m_buffer.write(m_version4); - pad(); - } - - private int getNumOfEncoding() { - if (m_isIncludeVersion0) { - return 2; - } - - return 1; - } - - public void addUnicodeRange(TTUnicodeRange a_range) { - m_unicodeRanges.add(a_range); - } - - public void addMapping(long a_unicode, long a_glyfIndex) { - m_unicode2glyph.put(a_unicode, a_glyfIndex); - } - - /** - * Find 'glyf' index for the given unicode. - * This method returns 0, if a_key was not found, which will be treated - * as unmapped character. - * @param a_key Long object with unicode value. - * @return 'glyf' index if a_key was found; 0 otherwise. - */ - public long getGlyfIndex(Long a_key) { - long retval = 0; - - if (m_unicode2glyph.containsKey(a_key)) { - retval = m_unicode2glyph.get(a_key); - } - - return retval; - } - - private void storeVersion0() throws IOException { - reset(); - writeVersion0(); - m_version0 = toByteArray(); - reset(); - } - - private void storeVersion4() throws IOException { - reset(); - writeVersion4(); - m_version4 = toByteArray(); - reset(); - } - - private void storeVersion12() throws IOException { - reset(); - writeVersion12(); - m_version12 = toByteArray(); - reset(); - } - - protected String getTag() { - return "cmap"; - } - - private void writeVersion0() throws IOException { - writeUInt16(0); - writeUInt16(262); - writeUInt16(0); - int i; - for (i = 0; i < 256; i++) { - if ((i == 0x000) || (i == 0x0008) || (i == 0x001D)) { - writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_null)); // .null - } - else if ((i == 0x0009) || (i == 0x000d)) { - writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_cr)); // CR - } - else { - writeUInt8((int) getGlyfIndex((long) i)); - } - } - } - - private void writeVersion4() throws IOException { - int segCount = m_startCodes.size(); - int i; - - // endCount - for (i = 0; i < segCount; i++) { - Long n = (Long) m_endCodes.get(i); - writeUInt16(n.intValue()); - } - - // reserverdPad - writeUInt16(0); - - // startCount - for (i = 0; i < segCount; i++) { - Long n = m_startCodes.get(i); - writeUInt16(n.intValue()); - } - - // idDelta - for (i = 0; i < segCount; i++) { - Long n = m_idDeltas.get(i); - writeInt16(n.intValue()); - } - - // idRangeOffset - for (i = 0; i < segCount; i++) { - Long n = m_idRangeOffsets.get(i); - writeInt16(n.intValue()); - } - - // glyphIdArray 2 bytes each - for (i = 0; i < m_unicodes.size(); i++) { - Long unicode = m_unicodes.get(i); - writeUInt16((int) getGlyfIndex(unicode)); - } - - byte [] bytes = m_bytes.toByteArray(); - - reset(); - - writeUInt16(4); - writeUInt16(bytes.length + 14); - writeUInt16(0); - writeUInt16(segCount * 2); - - int searchRange = getSearchRange(segCount); - writeUInt16(searchRange); - writeUInt16(getEntrySelector(searchRange)); - writeUInt16(getRangeShift(segCount, searchRange)); - m_buffer.write(bytes); - } - - public void writeVersion12() throws IOException { - ArrayList startCharCode = new ArrayList<>(); - ArrayList endCharCode = new ArrayList<>(); - ArrayList startGlyphCode = new ArrayList<>(); - - // TODO: map to real one - startCharCode.add(k_basicLatinStart); - endCharCode.add(k_basicLatinEnd); - startGlyphCode.add(1L); - - long length = 16 + 12 * startCharCode.size(); - - writeFixed32(12.0); - writeUInt32(length); - writeUInt32(0); - writeUInt32(startCharCode.size()); - - int i; - for (i = 0; i < startCharCode.size(); i++) { - writeUInt32(startCharCode.get(i)); - writeUInt32(endCharCode.get(i)); - writeUInt32(startGlyphCode.get(i)); - } - } - - /** - * Used for searchRange - * @param a_value - * @return - */ - private int getSearchRange(int a_value) { - int retval - = (int) Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2))); - return 2 * retval; - } - - private int getEntrySelector(int a_searchRange) { - int retval - = (int) (Math.log(a_searchRange / 2) / Math.log(2)); - return retval; - } - - private int getRangeShift(int a_value, int a_searchRange) { - int retval - = 2 * a_value - a_searchRange; - return retval; - } + + final long k_basicLatinStart = 0x20; + + final long k_basicLatinEnd = 0x7e; + + final long k_tableEnd = 0xffff; + + final int k_unmappedChar = 0x0; + + private OS2Writer m_os2; + + private List m_unicodes = new ArrayList<>(); + + private List m_startCodes = new ArrayList<>(); + + private List m_endCodes = new ArrayList<>(); + + private Map m_unicode2glyph = new HashMap<>(); + + private List m_unicodeRanges = new ArrayList<>(); + + private List m_idDeltas = new ArrayList<>(); + + private List m_idRangeOffsets = new ArrayList<>(); + + private boolean m_isIncludeVersion0; + + private byte[] m_version0; + + private byte[] m_version4; + + private byte[] m_version12; + + public CmapWriter(OS2Writer a_os2) { + super(); + + m_os2 = a_os2; + m_isIncludeVersion0 = false; + } + + private void prepare() { + Collections.sort(m_unicodeRanges); + + TTUnicodeRange range = (TTUnicodeRange) m_unicodeRanges.get(0); + m_os2.m_usFirstCharIndex = (int) range.getStartCode(); + m_os2.m_usLastCharIndex = (int) range.getEndCode(); + + int i; + for (i = 0; i < m_unicodeRanges.size(); i++) { + range = m_unicodeRanges.get(i); + + m_startCodes.add(range.getStartCode()); + m_endCodes.add(range.getEndCode()); + m_idDeltas.add(0L); + m_idRangeOffsets.add( + 2L * (m_unicodeRanges.size() - i) + 2L + + 2L * (m_unicodes.size())); + + m_os2.m_usLastCharIndex = (int) range.getEndCode(); + m_os2.setUnicodeRangeFlag(range.getOsTwoFlag()); + + for (long unicode = range.getStartCode(); + unicode <= range.getEndCode(); unicode++) { + m_unicodes.add(unicode); + } // for unicode + } + + m_startCodes.add(k_tableEnd); + m_endCodes.add(k_tableEnd); + m_idDeltas.add(1L); + m_idRangeOffsets.add(0L); + } + + public void write() throws IOException { + prepare(); + + if (m_isIncludeVersion0) { + storeVersion0(); + } + storeVersion4(); + + reset(); + + writeUInt16(0); // table version number + writeUInt16(getNumOfEncoding()); // num of encodings + + if (m_isIncludeVersion0) { + writeUInt16(TTName.k_macintosh); + writeUInt16(TTName.k_macRomanEncode); + writeUInt32(size() + 4 + 8); + } + + writeUInt16(TTName.k_microsoft); + writeUInt16(TTName.k_winUnicodeEncode); + int version4Offset = size() + 4; + if (m_isIncludeVersion0) { + version4Offset += m_version0.length; + } + writeUInt32(version4Offset); + + if (m_isIncludeVersion0) { + m_buffer.write(m_version0); + } + + m_buffer.write(m_version4); + pad(); + } + + private int getNumOfEncoding() { + if (m_isIncludeVersion0) { + return 2; + } + + return 1; + } + + public void addUnicodeRange(TTUnicodeRange a_range) { + m_unicodeRanges.add(a_range); + } + + public void addMapping(long a_unicode, long a_glyfIndex) { + m_unicode2glyph.put(a_unicode, a_glyfIndex); + } + + /** + * Find 'glyf' index for the given unicode. + * This method returns 0, if a_key was not found, which will be treated + * as unmapped character. + * + * @param a_key Long object with unicode value. + * @return 'glyf' index if a_key was found; 0 otherwise. + */ + public long getGlyfIndex(Long a_key) { + long retval = 0; + + if (m_unicode2glyph.containsKey(a_key)) { + retval = m_unicode2glyph.get(a_key); + } + + return retval; + } + + private void storeVersion0() throws IOException { + reset(); + writeVersion0(); + m_version0 = toByteArray(); + reset(); + } + + private void storeVersion4() throws IOException { + reset(); + writeVersion4(); + m_version4 = toByteArray(); + reset(); + } + + private void storeVersion12() throws IOException { + reset(); + writeVersion12(); + m_version12 = toByteArray(); + reset(); + } + + protected String getTag() { + return "cmap"; + } + + private void writeVersion0() throws IOException { + writeUInt16(0); + writeUInt16(262); + writeUInt16(0); + int i; + for (i = 0; i < 256; i++) { + if ((i == 0x000) || (i == 0x0008) || (i == 0x001D)) { + writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_null)); // .null + } else if ((i == 0x0009) || (i == 0x000d)) { + writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_cr)); // CR + } else { + writeUInt8((int) getGlyfIndex((long) i)); + } + } + } + + private void writeVersion4() throws IOException { + int segCount = m_startCodes.size(); + int i; + + // endCount + for (i = 0; i < segCount; i++) { + Long n = (Long) m_endCodes.get(i); + writeUInt16(n.intValue()); + } + + // reserverdPad + writeUInt16(0); + + // startCount + for (i = 0; i < segCount; i++) { + Long n = m_startCodes.get(i); + writeUInt16(n.intValue()); + } + + // idDelta + for (i = 0; i < segCount; i++) { + Long n = m_idDeltas.get(i); + writeInt16(n.intValue()); + } + + // idRangeOffset + for (i = 0; i < segCount; i++) { + Long n = m_idRangeOffsets.get(i); + writeInt16(n.intValue()); + } + + // glyphIdArray 2 bytes each + for (i = 0; i < m_unicodes.size(); i++) { + Long unicode = m_unicodes.get(i); + writeUInt16((int) getGlyfIndex(unicode)); + } + + byte[] bytes = m_bytes.toByteArray(); + + reset(); + + writeUInt16(4); + writeUInt16(bytes.length + 14); + writeUInt16(0); + writeUInt16(segCount * 2); + + int searchRange = getSearchRange(segCount); + writeUInt16(searchRange); + writeUInt16(getEntrySelector(searchRange)); + writeUInt16(getRangeShift(segCount, searchRange)); + m_buffer.write(bytes); + } + + public void writeVersion12() throws IOException { + ArrayList startCharCode = new ArrayList<>(); + ArrayList endCharCode = new ArrayList<>(); + ArrayList startGlyphCode = new ArrayList<>(); + + // TODO: map to real one + startCharCode.add(k_basicLatinStart); + endCharCode.add(k_basicLatinEnd); + startGlyphCode.add(1L); + + long length = 16 + 12 * startCharCode.size(); + + writeFixed32(12.0); + writeUInt32(length); + writeUInt32(0); + writeUInt32(startCharCode.size()); + + int i; + for (i = 0; i < startCharCode.size(); i++) { + writeUInt32(startCharCode.get(i)); + writeUInt32(endCharCode.get(i)); + writeUInt32(startGlyphCode.get(i)); + } + } + + /** + * Used for searchRange + * + * @param a_value + * @return + */ + private int getSearchRange(int a_value) { + int retval + = (int) Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2))); + return 2 * retval; + } + + private int getEntrySelector(int a_searchRange) { + int retval + = (int) (Math.log(a_searchRange / 2) / Math.log(2)); + return retval; + } + + private int getRangeShift(int a_value, int a_searchRange) { + int retval + = 2 * a_value - a_searchRange; + return retval; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java index 4d182d965..5a56238e1 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFileWriter.java @@ -1,8 +1,8 @@ /* * $Id: FontFileWriter.java,v 1.15 2004/10/04 02:25:39 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,262 +25,278 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; /** * @author e.e */ public class FontFileWriter extends FontFormatWriter { - private CmapWriter m_cmap; - private GlyfWriter m_glyf; - private LocaWriter m_loca; - private HeadWriter m_head; - private HdmxWriter m_hdmx; - private HheaWriter m_hhea; - private HmtxWriter m_hmtx; - private MaxpWriter m_maxp; - private NameWriter m_name; - private PostWriter m_post; - private OS2Writer m_os2; - - protected RandomAccessFile m_file; - private ArrayList m_tables = new ArrayList<>(); - - public FontFileWriter(RandomAccessFile a_file) { - super(); - - m_file = a_file; - - m_loca = new LocaWriter(); - m_maxp = new MaxpWriter(); - m_head = new HeadWriter(); - m_hdmx = new HdmxWriter(); - m_os2 = new OS2Writer(m_head); - m_cmap = new CmapWriter(m_os2); - - m_glyf = new GlyfWriter(m_loca, m_maxp, - m_head, m_hdmx); - - m_hhea = new HheaWriter(m_glyf, m_head); - m_hmtx = new HmtxWriter(m_glyf, m_hhea); - m_name = new NameWriter(); - m_post = new PostWriter(); - - // http://www.microsoft.com/typography/otspec/recom.htm - // head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, - // fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG + + private CmapWriter m_cmap; + + private GlyfWriter m_glyf; + + private LocaWriter m_loca; + + private HeadWriter m_head; + + private HdmxWriter m_hdmx; + + private HheaWriter m_hhea; + + private HmtxWriter m_hmtx; + + private MaxpWriter m_maxp; + + private NameWriter m_name; + + private PostWriter m_post; + + private OS2Writer m_os2; + + protected RandomAccessFile m_file; + + private ArrayList m_tables = new ArrayList<>(); + + public FontFileWriter(RandomAccessFile a_file) { + super(); + + m_file = a_file; + + m_loca = new LocaWriter(); + m_maxp = new MaxpWriter(); + m_head = new HeadWriter(); + m_hdmx = new HdmxWriter(); + m_os2 = new OS2Writer(m_head); + m_cmap = new CmapWriter(m_os2); + + m_glyf = new GlyfWriter(m_loca, m_maxp, + m_head, m_hdmx); + + m_hhea = new HheaWriter(m_glyf, m_head); + m_hmtx = new HmtxWriter(m_glyf, m_hhea); + m_name = new NameWriter(); + m_post = new PostWriter(); + + // http://www.microsoft.com/typography/otspec/recom.htm + // head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, + // fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG /* - m_tables.add(m_head); - m_tables.add(m_hhea); - m_tables.add(m_maxp); - m_tables.add(m_os2); - m_tables.add(m_hmtx); - m_tables.add(m_hdmx); - m_tables.add(m_cmap); - m_tables.add(m_loca); - m_tables.add(m_glyf); - m_tables.add(m_name); - m_tables.add(m_post); - */ - - // Verdana has head, hhea, maxp, OS/2, gasp, name, cmap, loca - // LTSH, VDMX, prep, fpgm, cvt, hmtx, hdmx, glyf, post, kern, edt0, DSIG - m_tables.add(m_head); - m_tables.add(m_hhea); - m_tables.add(m_maxp); - m_tables.add(m_os2); - m_tables.add(m_name); - m_tables.add(m_cmap); - m_tables.add(m_loca); - - m_tables.add(m_hmtx); - m_tables.add(m_hdmx); - m_tables.add(m_glyf); - m_tables.add(m_post); - } - - /** - * write TrueType file to the random access file - */ - public void write() throws IOException { - m_cmap.write(); - // hmtx must be written before hhea - m_hmtx.write(); - m_hhea.write(); - - m_glyf.write(); - m_loca.write(); - - m_head.setCheckSumAdjustment(0); - m_head.write(); - m_maxp.write(); // must be written after m_glyf - m_hdmx.write(); - m_name.write(); - m_post.write(); - m_os2.write(); - - writeTableDirectory(); - byte [] tableDir = toByteArray(); - for (FontFormatWriter table: m_tables) { - m_buffer.write(table.toByteArray()); - } // for table - - long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum()); - m_head.setCheckSumAdjustment(checkSum); - m_head.reset(); - m_head.write(); - - reset(); - - m_buffer.write(tableDir); - for (FontFormatWriter table: m_tables) { - m_buffer.write(table.toByteArray()); - } // for table - - m_file.write(toByteArray()); - m_file.close(); - } - - public void setAscent(int a_value) { - m_os2.setTypoAscender(a_value); - m_os2.setCapHeight(a_value); - } - - public void setDescent(int a_value) { - m_os2.setTypoDescender(-a_value); - } - - public void setXHeight(int a_value) { - m_os2.setXHeight(a_value); - } - - public void setLineGap(int a_value) { - m_os2.setTypoLineGap(a_value); - m_hhea.setLineGap(a_value); - } - - public void setFontFamilyName(String a_name) { - m_name.m_familyName = a_name; - } - - public void setCopyrightYear(String a_year) { - m_name.m_year = a_year; - } - - public void setManufacturer(String a_manufacturer) { - m_name.m_manufacturer = a_manufacturer; - } - - public void setFontVersion(String a_version) { - m_name.m_version = a_version; - } - - public void addUnicodeRange(TTUnicodeRange a_range) { - m_cmap.addUnicodeRange(a_range); - } - - /** - * http://www.microsoft.com/typography/otspec/os2.htm - * @param a_codeRange position of the bit. For example, JIS will be 17. - */ - public void setCodeRangeFlag(int a_codeRange) { - m_os2.setCodePageRangeFlag(a_codeRange); - } - - /** - * adds glyph to the 'glyf' subtable. - * @param a_glyph the glyph to be added. - * @return 'glyf' index of the added glyph. - */ - public int addGlyph(TTGlyph a_glyph) { - return m_glyf.add(a_glyph); - } - - public TTGlyph getGlyph(int a_index) { - return m_glyf.getGlyph(a_index); - } - - /** - * adds character mapping to - * @param a_unicode unicode of the character - * @param a_glyfIndex 'glyf' index obtained from #addGlyph - */ - public void addCharacterMapping(long a_unicode, long a_glyfIndex) { - m_cmap.addMapping(a_unicode, a_glyfIndex); - } - - public long getCharacterMapping(long a_unicode) { - return m_cmap.getGlyfIndex(new Long(a_unicode)); - } - - /** - * writes table directory. - * @throws IOException - */ - private void writeTableDirectory() throws IOException { - int headerLength = m_tables.size() * 16 + 16; - int tableOffset = headerLength; - for (FontFormatWriter table: m_tables) { - table.setOffset(tableOffset); - tableOffset += table.size(); - } // for table - - @SuppressWarnings("unchecked") - ArrayList tables = (ArrayList) m_tables.clone(); - Collections.sort(tables, new Comparator() { - public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) { - return a_lhs.getTag().compareTo(a_rhs.getTag()); - } - - public boolean equals(Object a_value) { - return false; - } - }); - - writeFixed32(1.0); - - int numOfTables = tables.size(); - writeUInt16(numOfTables); - int searchRange = getSearchRange(numOfTables); - writeUInt16(searchRange); - int entrySelector = getEntrySelector(numOfTables); - writeUInt16(entrySelector); - writeUInt16(numOfTables * 16 - searchRange); - - for (FontFormatWriter table: tables) { - writeTag(table.getTag()); - writeUInt32(table.getCheckSum()); - writeUInt32(table.getOffset()); - writeUInt32(table.size()); - } // for - - // padding is always 4 zeros - for (int i = 0; i < 4; i++) { - writeUInt8(0); - } - } - - private int getSearchRange(int a_value) { - int retval - = (int) (Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2)))); - return 16 * retval; - } - - private int getEntrySelector(int a_value) { - int retval - = (int) Math.floor(Math.log(a_value) / Math.log(2)); - return retval; - } + m_tables.add(m_head); + m_tables.add(m_hhea); + m_tables.add(m_maxp); + m_tables.add(m_os2); + m_tables.add(m_hmtx); + m_tables.add(m_hdmx); + m_tables.add(m_cmap); + m_tables.add(m_loca); + m_tables.add(m_glyf); + m_tables.add(m_name); + m_tables.add(m_post); + */ + // Verdana has head, hhea, maxp, OS/2, gasp, name, cmap, loca + // LTSH, VDMX, prep, fpgm, cvt, hmtx, hdmx, glyf, post, kern, edt0, DSIG + m_tables.add(m_head); + m_tables.add(m_hhea); + m_tables.add(m_maxp); + m_tables.add(m_os2); + m_tables.add(m_name); + m_tables.add(m_cmap); + m_tables.add(m_loca); + + m_tables.add(m_hmtx); + m_tables.add(m_hdmx); + m_tables.add(m_glyf); + m_tables.add(m_post); + } + + /** + * write TrueType file to the random access file + */ + public void write() throws IOException { + m_cmap.write(); + // hmtx must be written before hhea + m_hmtx.write(); + m_hhea.write(); + + m_glyf.write(); + m_loca.write(); + + m_head.setCheckSumAdjustment(0); + m_head.write(); + m_maxp.write(); // must be written after m_glyf + m_hdmx.write(); + m_name.write(); + m_post.write(); + m_os2.write(); + + writeTableDirectory(); + byte[] tableDir = toByteArray(); + for (FontFormatWriter table : m_tables) { + m_buffer.write(table.toByteArray()); + } // for table + + long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum()); + m_head.setCheckSumAdjustment(checkSum); + m_head.reset(); + m_head.write(); + + reset(); + + m_buffer.write(tableDir); + for (FontFormatWriter table : m_tables) { + m_buffer.write(table.toByteArray()); + } // for table + + m_file.write(toByteArray()); + m_file.close(); + } + + public void setAscent(int a_value) { + m_os2.setTypoAscender(a_value); + m_os2.setCapHeight(a_value); + } + + public void setDescent(int a_value) { + m_os2.setTypoDescender(-a_value); + } + + public void setXHeight(int a_value) { + m_os2.setXHeight(a_value); + } + + public void setLineGap(int a_value) { + m_os2.setTypoLineGap(a_value); + m_hhea.setLineGap(a_value); + } + + public void setFontFamilyName(String a_name) { + m_name.m_familyName = a_name; + } + + public void setCopyrightYear(String a_year) { + m_name.m_year = a_year; + } + + public void setManufacturer(String a_manufacturer) { + m_name.m_manufacturer = a_manufacturer; + } + + public void setFontVersion(String a_version) { + m_name.m_version = a_version; + } + + public void addUnicodeRange(TTUnicodeRange a_range) { + m_cmap.addUnicodeRange(a_range); + } + + /** + * http://www.microsoft.com/typography/otspec/os2.htm + * + * @param a_codeRange position of the bit. For example, JIS will be 17. + */ + public void setCodeRangeFlag(int a_codeRange) { + m_os2.setCodePageRangeFlag(a_codeRange); + } + + /** + * adds glyph to the 'glyf' subtable. + * + * @param a_glyph the glyph to be added. + * @return 'glyf' index of the added glyph. + */ + public int addGlyph(TTGlyph a_glyph) { + return m_glyf.add(a_glyph); + } + + public TTGlyph getGlyph(int a_index) { + return m_glyf.getGlyph(a_index); + } + + /** + * adds character mapping to + * + * @param a_unicode unicode of the character + * @param a_glyfIndex 'glyf' index obtained from #addGlyph + */ + public void addCharacterMapping(long a_unicode, long a_glyfIndex) { + m_cmap.addMapping(a_unicode, a_glyfIndex); + } + + public long getCharacterMapping(long a_unicode) { + return m_cmap.getGlyfIndex(new Long(a_unicode)); + } + + /** + * writes table directory. + * + * @throws IOException + */ + private void writeTableDirectory() throws IOException { + int headerLength = m_tables.size() * 16 + 16; + int tableOffset = headerLength; + for (FontFormatWriter table : m_tables) { + table.setOffset(tableOffset); + tableOffset += table.size(); + } // for table + + @SuppressWarnings("unchecked") + ArrayList tables = (ArrayList) m_tables.clone(); + Collections.sort(tables, new Comparator() { + public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) { + return a_lhs.getTag().compareTo(a_rhs.getTag()); + } + + public boolean equals(Object a_value) { + return false; + } + }); + + writeFixed32(1.0); + + int numOfTables = tables.size(); + writeUInt16(numOfTables); + int searchRange = getSearchRange(numOfTables); + writeUInt16(searchRange); + int entrySelector = getEntrySelector(numOfTables); + writeUInt16(entrySelector); + writeUInt16(numOfTables * 16 - searchRange); + + for (FontFormatWriter table : tables) { + writeTag(table.getTag()); + writeUInt32(table.getCheckSum()); + writeUInt32(table.getOffset()); + writeUInt32(table.size()); + } // for + + // padding is always 4 zeros + for (int i = 0; i < 4; i++) { + writeUInt8(0); + } + } + + private int getSearchRange(int a_value) { + int retval + = (int) (Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2)))); + return 16 * retval; + } + + private int getEntrySelector(int a_value) { + int retval + = (int) Math.floor(Math.log(a_value) / Math.log(2)); + return retval; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFormatWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFormatWriter.java index c4f3dd3e0..8091c6784 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFormatWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/FontFormatWriter.java @@ -1,8 +1,8 @@ /* * $Id: FontFormatWriter.java,v 1.6 2004/01/28 11:44:08 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,149 +25,154 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Date; /** * @author e.e */ public class FontFormatWriter { - protected DataOutputStream m_buffer; - protected ByteArrayOutputStream m_bytes; - private int m_offset; - - public FontFormatWriter() { - init(); - } - - protected void init() { - m_bytes = new ByteArrayOutputStream(); - m_buffer = new DataOutputStream(m_bytes); - m_offset = 0; - } - - public void write() throws IOException { - } - - public byte[] toByteArray() { - return m_bytes.toByteArray(); - } - - /** - * Size of buffer in bytes. - * @return size of buffer in bytes. - */ - public int size() { - return m_bytes.size(); - } - - public void reset() { - m_bytes.reset(); - } - - protected void writeFixed32(double a_value) throws IOException { - final int k_denom = 16384; - - short mantissa = (short) Math.floor(a_value); - int fraction = (int) ((a_value - mantissa) * k_denom); - if (fraction > k_denom) { - fraction = 0; - mantissa++; - } - - m_buffer.writeShort(mantissa); - m_buffer.writeShort(fraction); - } - - protected void writeUInt16(int a_value) throws IOException { - writeInt16((short) (0xffff & a_value)); - } - - protected void writeInt16(int a_value) throws IOException { - m_buffer.writeShort((short) a_value); - } - - protected void writeFWord(int a_value) throws IOException { - writeInt16(a_value); - } - - protected void writeUFWord(int a_value) throws IOException { - writeUInt16(a_value); - } - - protected void writeUInt32 (long a_value) throws IOException { - writeInt32((int) (0xffffffff & a_value)); - } - - protected void writeInt32(int a_value) throws IOException { - m_buffer.writeInt(a_value); - } - - protected void writeUInt8(int a_byte) throws IOException { - m_buffer.writeByte(a_byte); - } - - protected void writeTag(String a_value) throws IOException { - String s = a_value + " "; - - int i; - for (i = 0; i < 4; i++) { - writeUInt8(s.charAt(i)); - } - } - - protected void writeLongDateTime(Date a_date) throws IOException { - long sec = a_date.getTime() / 1000; - sec += (1970 - 1904) * 365 * 24 * 60 * 60; - m_buffer.writeLong(sec); - } - - protected String getTag() { - throw new RuntimeException("unimplemnted call to getTag"); - } - - protected long getCheckSum() { - long retval = 0; - byte [] bytes = toByteArray(); - - for (int i = 0; i < bytes.length / 4; i++) { - long n = 0; - for (int j = 0; j < 4; j++) { - n += bytes[4 * i + j] << ((4 - j) * 8); - } // for j - retval += n; - } - - return retval; - } - - protected void pad() throws IOException { - int align = 4; - int numOfPad = align - m_bytes.size() % align; - if (numOfPad == align) - return; - - int i; - for (i = 0; i < numOfPad; i++) { - writeUInt8(0); - } - } - - public int getOffset() { - return m_offset; - } - - public void setOffset(int a_value) { - m_offset = a_value; - } + + protected DataOutputStream m_buffer; + + protected ByteArrayOutputStream m_bytes; + + private int m_offset; + + public FontFormatWriter() { + init(); + } + + protected void init() { + m_bytes = new ByteArrayOutputStream(); + m_buffer = new DataOutputStream(m_bytes); + m_offset = 0; + } + + public void write() throws IOException { + } + + public byte[] toByteArray() { + return m_bytes.toByteArray(); + } + + /** + * Size of buffer in bytes. + * + * @return size of buffer in bytes. + */ + public int size() { + return m_bytes.size(); + } + + public void reset() { + m_bytes.reset(); + } + + protected void writeFixed32(double a_value) throws IOException { + final int k_denom = 16384; + + short mantissa = (short) Math.floor(a_value); + int fraction = (int) ((a_value - mantissa) * k_denom); + if (fraction > k_denom) { + fraction = 0; + mantissa++; + } + + m_buffer.writeShort(mantissa); + m_buffer.writeShort(fraction); + } + + protected void writeUInt16(int a_value) throws IOException { + writeInt16((short) (0xffff & a_value)); + } + + protected void writeInt16(int a_value) throws IOException { + m_buffer.writeShort((short) a_value); + } + + protected void writeFWord(int a_value) throws IOException { + writeInt16(a_value); + } + + protected void writeUFWord(int a_value) throws IOException { + writeUInt16(a_value); + } + + protected void writeUInt32(long a_value) throws IOException { + writeInt32((int) (0xffffffff & a_value)); + } + + protected void writeInt32(int a_value) throws IOException { + m_buffer.writeInt(a_value); + } + + protected void writeUInt8(int a_byte) throws IOException { + m_buffer.writeByte(a_byte); + } + + protected void writeTag(String a_value) throws IOException { + String s = a_value + " "; + + int i; + for (i = 0; i < 4; i++) { + writeUInt8(s.charAt(i)); + } + } + + protected void writeLongDateTime(Date a_date) throws IOException { + long sec = a_date.getTime() / 1000; + sec += (1970 - 1904) * 365 * 24 * 60 * 60; + m_buffer.writeLong(sec); + } + + protected String getTag() { + throw new RuntimeException("unimplemnted call to getTag"); + } + + protected long getCheckSum() { + long retval = 0; + byte[] bytes = toByteArray(); + + for (int i = 0; i < bytes.length / 4; i++) { + long n = 0; + for (int j = 0; j < 4; j++) { + n += bytes[4 * i + j] << ((4 - j) * 8); + } // for j + retval += n; + } + + return retval; + } + + protected void pad() throws IOException { + int align = 4; + int numOfPad = align - m_bytes.size() % align; + if (numOfPad == align) { + return; + } + + for (int i = 0; i < numOfPad; i++) { + writeUInt8(0); + } + } + + public int getOffset() { + return m_offset; + } + + public void setOffset(int a_value) { + m_offset = a_value; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/GlyfWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/GlyfWriter.java index 16b9ca46f..bb373e13d 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/GlyfWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/GlyfWriter.java @@ -1,8 +1,8 @@ /* * $Id: GlyfWriter.java,v 1.17 2004/09/23 07:47:39 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,180 +25,182 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.awt.*; -import java.util.*; +import java.awt.Point; +import java.io.IOException; +import java.util.ArrayList; /** * @author e.e */ public class GlyfWriter extends FontFormatWriter { - private ArrayList m_glyphs; - - private LocaWriter m_loca; - private MaxpWriter m_maxp; - private HeadWriter m_head; - private HdmxWriter m_hdmx; - - public GlyfWriter(LocaWriter a_loca, MaxpWriter a_maxp, - HeadWriter a_head, HdmxWriter a_hdmx) { - super(); - - m_loca = a_loca; - m_maxp = a_maxp; - m_head = a_head; - m_hdmx = a_hdmx; - m_glyphs = new ArrayList<>(); - } - - public void write() throws IOException { - m_hdmx.setNumGlyphs(numOfGlyph()); - m_maxp.setNumGlyphs(numOfGlyph()); - m_loca.m_offsets.clear(); - - for (int i = 0; i < m_glyphs.size(); i++) { - TTGlyph glyph = m_glyphs.get(i); - writeGlyph(glyph); - m_hdmx.updatePixelWidth(i, glyph); - } - - m_loca.m_offsets.add(size()); - } - - public int add(TTGlyph a_glyph) { - m_head.updateMax(a_glyph.getMax()); - m_head.updateMin(a_glyph.getMin()); - - m_glyphs.add(a_glyph); - return m_glyphs.size() - 1; - } - - public int numOfGlyph() { - return m_glyphs.size(); - } - - public TTGlyph getGlyph(int a_index) { - return m_glyphs.get(a_index); - } - - private void writeGlyph(TTGlyph a_glyph) throws IOException { - m_loca.m_offsets.add(size()); - - if (a_glyph == null) { - return; - } - - if (a_glyph.isSimple()) { - writeSimpleGlyph(a_glyph); - } else { - writeCompoundGlyph(a_glyph); - } - - pad(); - } - - /** - * @param a_glyph - * @throws IOException - */ - private void writeSimpleGlyph(TTGlyph a_glyph) throws IOException { - if (a_glyph.getNumOfContours() == 0) { - return; - } - - m_maxp.updateNumOfContours(a_glyph.getNumOfContours()); - writeInt16(a_glyph.getNumOfContours()); - writeMinMax(a_glyph); - - int i; - for (i = 0; i < a_glyph.getNumOfContours(); i++) { - writeUInt16(a_glyph.getEndPoint(i)); - } - - int numOfInst = a_glyph.getNumOfInstructions(); - m_maxp.updateSizeOfInstructions(numOfInst); - - writeUInt16(numOfInst); - for (i = 0; i < numOfInst; i++) { - writeUInt8(a_glyph.getInstruction(i)); - } - - for (i = 0; i < a_glyph.getNumOfFlags(); i++) { - int flag = a_glyph.getFlag(i); - writeUInt8(flag); - } - - // update num of points - m_maxp.updateNumOfPoints(a_glyph.getNumOfPoints()); - - int lastX = 0; - for (i = 0; i < a_glyph.getNumOfPoints(); i++) { - Point point = a_glyph.getPoint(i); - - writeInt16(point.x - lastX); - lastX = point.x; - } - - int lastY = 0; - for (i = 0; i < a_glyph.getNumOfPoints(); i++) { - Point point = a_glyph.getPoint(i); - - writeInt16(point.y - lastY); - lastY = point.y; - } - } - - /** - * @param a_glyph - * @throws IOException - */ - private void writeCompoundGlyph(TTGlyph a_glyph) throws IOException { - int i; - - m_maxp.updateNumOfCompositePoints(a_glyph.getNumOfCompositePoints()); - m_maxp.updateNumOfCompositeContours(a_glyph.getNumOfCompositeContours()); - - writeInt16(-1); - writeMinMax(a_glyph); - - int numOfGlyphs = a_glyph.getNumOfFlags(); - m_maxp.updateNumOfComponentElements(numOfGlyphs); - m_maxp.updateComponentDepth(a_glyph.getComponentDepth()); - - for (i = 0; i < numOfGlyphs; i++) { - writeUInt16(a_glyph.getFlag(i)); - writeUInt16(a_glyph.getGlyfIndex(i)); - writeInt16(a_glyph.getArg1(i)); - writeInt16(a_glyph.getArg2(i)); - } - } - /** - * @param a_glyph - * @throws IOException - */ - private void writeMinMax(TTGlyph a_glyph) throws IOException { - Point min = a_glyph.getMin(); - Point max = a_glyph.getMax(); - - writeFWord(min.x); - writeFWord(min.y); - writeFWord(max.x); - writeFWord(max.y); - } + private ArrayList m_glyphs; - protected String getTag() { - return "glyf"; - } + private LocaWriter m_loca; + + private MaxpWriter m_maxp; + + private HeadWriter m_head; + + private HdmxWriter m_hdmx; + + public GlyfWriter(LocaWriter a_loca, MaxpWriter a_maxp, + HeadWriter a_head, HdmxWriter a_hdmx) { + super(); + + m_loca = a_loca; + m_maxp = a_maxp; + m_head = a_head; + m_hdmx = a_hdmx; + m_glyphs = new ArrayList<>(); + } + + public void write() throws IOException { + m_hdmx.setNumGlyphs(numOfGlyph()); + m_maxp.setNumGlyphs(numOfGlyph()); + m_loca.m_offsets.clear(); + + for (int i = 0; i < m_glyphs.size(); i++) { + TTGlyph glyph = m_glyphs.get(i); + writeGlyph(glyph); + m_hdmx.updatePixelWidth(i, glyph); + } + + m_loca.m_offsets.add(size()); + } + + public int add(TTGlyph a_glyph) { + m_head.updateMax(a_glyph.getMax()); + m_head.updateMin(a_glyph.getMin()); + + m_glyphs.add(a_glyph); + return m_glyphs.size() - 1; + } + + public int numOfGlyph() { + return m_glyphs.size(); + } + + public TTGlyph getGlyph(int a_index) { + return m_glyphs.get(a_index); + } + + private void writeGlyph(TTGlyph a_glyph) throws IOException { + m_loca.m_offsets.add(size()); + + if (a_glyph == null) { + return; + } + + if (a_glyph.isSimple()) { + writeSimpleGlyph(a_glyph); + } else { + writeCompoundGlyph(a_glyph); + } + + pad(); + } + + /** + * @param a_glyph + * @throws IOException + */ + private void writeSimpleGlyph(TTGlyph a_glyph) throws IOException { + if (a_glyph.getNumOfContours() == 0) { + return; + } + + m_maxp.updateNumOfContours(a_glyph.getNumOfContours()); + writeInt16(a_glyph.getNumOfContours()); + writeMinMax(a_glyph); + + int i; + for (i = 0; i < a_glyph.getNumOfContours(); i++) { + writeUInt16(a_glyph.getEndPoint(i)); + } + + int numOfInst = a_glyph.getNumOfInstructions(); + m_maxp.updateSizeOfInstructions(numOfInst); + + writeUInt16(numOfInst); + for (i = 0; i < numOfInst; i++) { + writeUInt8(a_glyph.getInstruction(i)); + } + + for (i = 0; i < a_glyph.getNumOfFlags(); i++) { + int flag = a_glyph.getFlag(i); + writeUInt8(flag); + } + + // update num of points + m_maxp.updateNumOfPoints(a_glyph.getNumOfPoints()); + + int lastX = 0; + for (i = 0; i < a_glyph.getNumOfPoints(); i++) { + Point point = a_glyph.getPoint(i); + + writeInt16(point.x - lastX); + lastX = point.x; + } + + int lastY = 0; + for (i = 0; i < a_glyph.getNumOfPoints(); i++) { + Point point = a_glyph.getPoint(i); + + writeInt16(point.y - lastY); + lastY = point.y; + } + } + + /** + * @param a_glyph + * @throws IOException + */ + private void writeCompoundGlyph(TTGlyph a_glyph) throws IOException { + int i; + + m_maxp.updateNumOfCompositePoints(a_glyph.getNumOfCompositePoints()); + m_maxp.updateNumOfCompositeContours(a_glyph.getNumOfCompositeContours()); + + writeInt16(-1); + writeMinMax(a_glyph); + + int numOfGlyphs = a_glyph.getNumOfFlags(); + m_maxp.updateNumOfComponentElements(numOfGlyphs); + m_maxp.updateComponentDepth(a_glyph.getComponentDepth()); + + for (i = 0; i < numOfGlyphs; i++) { + writeUInt16(a_glyph.getFlag(i)); + writeUInt16(a_glyph.getGlyfIndex(i)); + writeInt16(a_glyph.getArg1(i)); + writeInt16(a_glyph.getArg2(i)); + } + } + + /** + * @param a_glyph + * @throws IOException + */ + private void writeMinMax(TTGlyph a_glyph) throws IOException { + Point min = a_glyph.getMin(); + Point max = a_glyph.getMax(); + + writeFWord(min.x); + writeFWord(min.y); + writeFWord(max.x); + writeFWord(max.y); + } + + protected String getTag() { + return "glyf"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/HdmxWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/HdmxWriter.java index 83561fd20..04cc95ef9 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/HdmxWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/HdmxWriter.java @@ -1,6 +1,6 @@ /* * $Copyright: copyright (c) 2003-2008, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -23,95 +23,96 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; /** * HtmxWriter depends on GlyfWriter. - * + * * @author e.e */ -public class HdmxWriter extends FontFormatWriter { - static public int getNumOfPixelSizes() { - return TTPixelSize.getList().size(); - } - - static public ArrayList getPixelSizes() { - return TTPixelSize.getList(); - } - - private int m_numGlyphs = 98; // set by GlyfWriter - - public HdmxWriter() { - super(); - } - - /** set the number of glyphs in the font */ - public void setNumGlyphs(int a_value) { - m_numGlyphs = a_value; - - for (TTPixelSize pixelSize: getPixelSizes()) { - pixelSize.setPixelWidthsSize(a_value); - } // for pixelSize - } - - public void updatePixelWidth(int a_glyphIndex, TTGlyph a_glyph) { - double advanceWidth = a_glyph.getAdvanceWidth(); - double em = TTPixelSize.getEm(); - - for (TTPixelSize pixelSize: TTPixelSize.getList()) { - int width = (int) Math.round(((double) pixelSize.getPixel() * advanceWidth) / em); - pixelSize.setPixelWidth(a_glyphIndex, width); - } // pixelSize - } - - /** - * writes htmx record. - * The size of a device record is calculated to align it to 32bit boundary. - */ - public void write() throws IOException { - int numOfPads = 4 - ((m_numGlyphs + 2) % 4); - if (numOfPads == 4) { - numOfPads = 0; - } - int size = m_numGlyphs + 2 + numOfPads; // 2 comes from the ppem and max - - // format version number - writeInt16(0); - - // number of device records - writeInt16(getNumOfPixelSizes()); +public class HdmxWriter extends FontFormatWriter { + + static public int getNumOfPixelSizes() { + return TTPixelSize.getList().size(); + } + + static public ArrayList getPixelSizes() { + return TTPixelSize.getList(); + } + + private int m_numGlyphs = 98; // set by GlyfWriter + + public HdmxWriter() { + super(); + } + + /** + * set the number of glyphs in the font + */ + public void setNumGlyphs(int a_value) { + m_numGlyphs = a_value; + + for (TTPixelSize pixelSize : getPixelSizes()) { + pixelSize.setPixelWidthsSize(a_value); + } // for pixelSize + } + + public void updatePixelWidth(int a_glyphIndex, TTGlyph a_glyph) { + double advanceWidth = a_glyph.getAdvanceWidth(); + double em = TTPixelSize.getEm(); + + for (TTPixelSize pixelSize : TTPixelSize.getList()) { + int width = (int) Math.round(((double) pixelSize.getPixel() * advanceWidth) / em); + pixelSize.setPixelWidth(a_glyphIndex, width); + } // pixelSize + } + + /** + * writes htmx record. + * The size of a device record is calculated to align it to 32bit boundary. + */ + public void write() throws IOException { + int numOfPads = 4 - ((m_numGlyphs + 2) % 4); + if (numOfPads == 4) { + numOfPads = 0; + } + int size = m_numGlyphs + 2 + numOfPads; // 2 comes from the ppem and max + + // format version number + writeInt16(0); + + // number of device records + writeInt16(getNumOfPixelSizes()); //System.out.printf("num of pixel sizes %d\n", getNumOfPixelSizes()); - // size of device record - writeInt32(size); - //System.out.printf("num of glyphs %d\n", m_numGlyphs); - for (TTPixelSize pixelSize: getPixelSizes()) { - writeUInt8(pixelSize.getPixel()); - writeUInt8(pixelSize.getMaxPixelWidth()); - for (int pixelWidth: pixelSize.getPixelWidths()) { - writeUInt8(pixelWidth); - } // for pixelWidth - - for (int j = 0; j < numOfPads; j++) { - writeUInt8(0); - } // for j - } // for pixelSize - - pad(); - } - - protected String getTag() { - return "hdmx"; - } + // size of device record + writeInt32(size); + //System.out.printf("num of glyphs %d\n", m_numGlyphs); + for (TTPixelSize pixelSize : getPixelSizes()) { + writeUInt8(pixelSize.getPixel()); + writeUInt8(pixelSize.getMaxPixelWidth()); + for (int pixelWidth : pixelSize.getPixelWidths()) { + writeUInt8(pixelWidth); + } // for pixelWidth + + for (int j = 0; j < numOfPads; j++) { + writeUInt8(0); + } // for j + } // for pixelSize + + pad(); + } + + protected String getTag() { + return "hdmx"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/HeadWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/HeadWriter.java index 80c13c4f6..4716deebf 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/HeadWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/HeadWriter.java @@ -1,8 +1,8 @@ /* * $Id: HeadWriter.java,v 1.7 2004/09/26 09:15:48 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,132 +25,139 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; -import java.awt.*; +import java.awt.Point; +import java.io.IOException; +import java.util.Date; /** * @author e.e */ public class HeadWriter extends FontFormatWriter { - static public final int k_yZeroIsBaseLine = 0x1; // bit 0 - static public final int k_xLeftMostBlackIsLsb = 0x2; // bit 1 - static public final int k_scaledPointDiffer = 0x4; // bit 2 - static public final int k_useIntegerScaling = 0x8; // bit 3 - - // used by microsoft - static public final int k_scaleLinear = 0x10; - - // for vertical fonts - static public final int k_xZeroIsBaseLine = 0x20; - // 0x40 - static public final int k_linguisticRendering = 0x80; - static public final int k_defaultMetamorphosis = 0x100; - static public final int k_rightToLeft = 0x200; - static public final int k_indicRearrangement = 0x400; - - - private final long k_magicNumber = 0x5f0f3cf5; - - private long m_checkSumAdjustment = 0; - private Point m_min = new Point(0, 0); - private Point m_max = new Point(0, 0); - - public HeadWriter() { - super(); - } - - void setCheckSumAdjustment(long a_value) { - m_checkSumAdjustment = a_value; - } - - public Point getMin() { - return m_min; - } - - public Point getMax() { - return m_max; - } - - public void updateMin(Point a_value) { - if (a_value.x < m_min.x) { - m_min.x = a_value.x; - } - - if (a_value.y < m_min.y) { - m_min.y = a_value.y; - } - } - - public void updateMax(Point a_value) { - if (a_value.x > m_max.x) { - m_max.x = a_value.x; - } - - if (a_value.y > m_max.y) { - m_max.y = a_value.y; - } - } - - public void write() throws IOException { - // table version number - writeFixed32(1.0); - - // fontRevision - writeFixed32(1.0); - - writeUInt32(m_checkSumAdjustment); - writeUInt32(k_magicNumber); - - // LSB is the distance from 0, 0 to the left of the glyph bounds. - // flags - writeUInt16(k_yZeroIsBaseLine - | k_xLeftMostBlackIsLsb - | k_scaledPointDiffer);; - - // unitsPerEm - writeUInt16(1024); - - // created, modified - writeLongDateTime(new Date()); - writeLongDateTime(new Date()); - - writeFWord(m_min.x); - writeFWord(m_min.y); - writeFWord(m_max.x); - writeFWord(m_max.y); - - // macStyle - writeUInt16(0); - - // lowestRecPPEM - writeUInt16(11); - - // font direction hint - // 2, for strongly left to right - // but also contains neutrals - writeInt16(2); - - // indexToLocFormat. 1, for long - writeInt16(1); - - // glyfDataFormat - writeInt16(0); - pad(); - } - - protected String getTag() { - return "head"; - } + + static public final int k_yZeroIsBaseLine = 0x1; // bit 0 + + static public final int k_xLeftMostBlackIsLsb = 0x2; // bit 1 + + static public final int k_scaledPointDiffer = 0x4; // bit 2 + + static public final int k_useIntegerScaling = 0x8; // bit 3 + + // used by microsoft + static public final int k_scaleLinear = 0x10; + + // for vertical fonts + static public final int k_xZeroIsBaseLine = 0x20; + + // 0x40 + static public final int k_linguisticRendering = 0x80; + + static public final int k_defaultMetamorphosis = 0x100; + + static public final int k_rightToLeft = 0x200; + + static public final int k_indicRearrangement = 0x400; + + private final long k_magicNumber = 0x5f0f3cf5; + + private long m_checkSumAdjustment = 0; + + private Point m_min = new Point(0, 0); + + private Point m_max = new Point(0, 0); + + public HeadWriter() { + super(); + } + + void setCheckSumAdjustment(long a_value) { + m_checkSumAdjustment = a_value; + } + + public Point getMin() { + return m_min; + } + + public Point getMax() { + return m_max; + } + + public void updateMin(Point a_value) { + if (a_value.x < m_min.x) { + m_min.x = a_value.x; + } + + if (a_value.y < m_min.y) { + m_min.y = a_value.y; + } + } + + public void updateMax(Point a_value) { + if (a_value.x > m_max.x) { + m_max.x = a_value.x; + } + + if (a_value.y > m_max.y) { + m_max.y = a_value.y; + } + } + + public void write() throws IOException { + // table version number + writeFixed32(1.0); + + // fontRevision + writeFixed32(1.0); + + writeUInt32(m_checkSumAdjustment); + writeUInt32(k_magicNumber); + + // LSB is the distance from 0, 0 to the left of the glyph bounds. + // flags + writeUInt16(k_yZeroIsBaseLine + | k_xLeftMostBlackIsLsb + | k_scaledPointDiffer);; + + // unitsPerEm + writeUInt16(1024); + + // created, modified + writeLongDateTime(new Date()); + writeLongDateTime(new Date()); + + writeFWord(m_min.x); + writeFWord(m_min.y); + writeFWord(m_max.x); + writeFWord(m_max.y); + + // macStyle + writeUInt16(0); + + // lowestRecPPEM + writeUInt16(11); + + // font direction hint + // 2, for strongly left to right + // but also contains neutrals + writeInt16(2); + + // indexToLocFormat. 1, for long + writeInt16(1); + + // glyfDataFormat + writeInt16(0); + pad(); + } + + protected String getTag() { + return "head"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/HheaWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/HheaWriter.java index 8320314fe..9b96b71e5 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/HheaWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/HheaWriter.java @@ -1,8 +1,8 @@ /* * $Id: HheaWriter.java,v 1.5 2004/09/26 09:15:48 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,84 +25,87 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; +import java.io.IOException; /** * HheaWriter depends on HtmxWriter. + * * @author e.e */ -public class HheaWriter extends FontFormatWriter { +public class HheaWriter extends FontFormatWriter { + private GlyfWriter m_glyf; + private HeadWriter m_head; - - private int m_lineGap = 0; - private int m_maxAdvanceWidth = 0; - private int m_minRightSideBearing = 0; - - public HheaWriter(GlyfWriter a_glyf, HeadWriter a_head) { - super(); - - m_glyf = a_glyf; - m_head = a_head; - } - - public void setLineGap(int a_value) { - m_lineGap = a_value; - } - - public void setMaxAdvanceWidth(int a_value) { - m_maxAdvanceWidth = a_value; - } - - public void setMinRightSideBearing(int a_value) { - m_minRightSideBearing = a_value; - } - - public void write() throws IOException { - // table version number - writeFixed32(1.0); - - writeFWord(m_head.getMax().y); - writeFWord(m_head.getMin().y); - writeFWord(m_lineGap); - writeUFWord(m_maxAdvanceWidth); - - int minLeftSideBearing = m_head.getMin().x; - writeFWord(minLeftSideBearing); - writeFWord(m_minRightSideBearing); - - int xMaxExtent = m_head.getMax().x - m_head.getMin().x; - writeFWord(xMaxExtent); - - // caratSlopeRise - writeInt16(1); - writeInt16(0); - - // reserved - for (int i = 0; i < 5; i++) { - writeInt16(0); - } - - writeInt16(0); - - int numOfHMetrics = m_glyf.numOfGlyph(); - writeUInt16(numOfHMetrics); - - pad(); - } - - protected String getTag() { - return "hhea"; - } + + private int m_lineGap = 0; + + private int m_maxAdvanceWidth = 0; + + private int m_minRightSideBearing = 0; + + public HheaWriter(GlyfWriter a_glyf, HeadWriter a_head) { + super(); + + m_glyf = a_glyf; + m_head = a_head; + } + + public void setLineGap(int a_value) { + m_lineGap = a_value; + } + + public void setMaxAdvanceWidth(int a_value) { + m_maxAdvanceWidth = a_value; + } + + public void setMinRightSideBearing(int a_value) { + m_minRightSideBearing = a_value; + } + + public void write() throws IOException { + // table version number + writeFixed32(1.0); + + writeFWord(m_head.getMax().y); + writeFWord(m_head.getMin().y); + writeFWord(m_lineGap); + writeUFWord(m_maxAdvanceWidth); + + int minLeftSideBearing = m_head.getMin().x; + writeFWord(minLeftSideBearing); + writeFWord(m_minRightSideBearing); + + int xMaxExtent = m_head.getMax().x - m_head.getMin().x; + writeFWord(xMaxExtent); + + // caratSlopeRise + writeInt16(1); + writeInt16(0); + + // reserved + for (int i = 0; i < 5; i++) { + writeInt16(0); + } + + writeInt16(0); + + int numOfHMetrics = m_glyf.numOfGlyph(); + writeUInt16(numOfHMetrics); + + pad(); + } + + protected String getTag() { + return "hhea"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/HmtxWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/HmtxWriter.java index f74bab3d2..c9e9f342b 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/HmtxWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/HmtxWriter.java @@ -1,8 +1,8 @@ /* * $Id: HmtxWriter.java,v 1.10 2004/10/04 02:25:39 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,65 +25,65 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; +import java.io.IOException; /** * HtmxWriter depends on GlyfWriter. - * + * * @author e.e */ -public class HmtxWriter extends FontFormatWriter { - HheaWriter m_hhea; - GlyfWriter m_glyf; - - public HmtxWriter(GlyfWriter a_glyf, HheaWriter a_hhea) { - super(); - - m_hhea = a_hhea; - m_glyf = a_glyf; - } - - public void write() throws IOException { - int i; - - TTGlyph glyphZero = m_glyf.getGlyph(0); - int maxWidth = glyphZero.getAdvanceWidth(); - int minRightSideBearing = glyphZero.getRightSideBearing(); - for (i = 0; i < m_glyf.numOfGlyph(); i++) { - TTGlyph glyph = m_glyf.getGlyph(i); - - if (glyph.getAdvanceWidth() > maxWidth) { - maxWidth = glyph.getAdvanceWidth(); - } - - if (glyph.getRightSideBearing() < minRightSideBearing) { - minRightSideBearing = glyph.getRightSideBearing(); - } - - writeUFWord(glyph.getAdvanceWidth()); - writeFWord(glyph.getLeftSideBearing()); - } - - writeFWord(0); - - m_hhea.setMaxAdvanceWidth(maxWidth); - m_hhea.setMinRightSideBearing(minRightSideBearing); - - pad(); - } - - protected String getTag() { - return "hmtx"; - } +public class HmtxWriter extends FontFormatWriter { + + HheaWriter m_hhea; + + GlyfWriter m_glyf; + + public HmtxWriter(GlyfWriter a_glyf, HheaWriter a_hhea) { + super(); + + m_hhea = a_hhea; + m_glyf = a_glyf; + } + + public void write() throws IOException { + int i; + + TTGlyph glyphZero = m_glyf.getGlyph(0); + int maxWidth = glyphZero.getAdvanceWidth(); + int minRightSideBearing = glyphZero.getRightSideBearing(); + for (i = 0; i < m_glyf.numOfGlyph(); i++) { + TTGlyph glyph = m_glyf.getGlyph(i); + + if (glyph.getAdvanceWidth() > maxWidth) { + maxWidth = glyph.getAdvanceWidth(); + } + + if (glyph.getRightSideBearing() < minRightSideBearing) { + minRightSideBearing = glyph.getRightSideBearing(); + } + + writeUFWord(glyph.getAdvanceWidth()); + writeFWord(glyph.getLeftSideBearing()); + } + + writeFWord(0); + + m_hhea.setMaxAdvanceWidth(maxWidth); + m_hhea.setMinRightSideBearing(minRightSideBearing); + + pad(); + } + + protected String getTag() { + return "hmtx"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/LocaWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/LocaWriter.java index 857634e6b..bd44ec497 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/LocaWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/LocaWriter.java @@ -1,8 +1,8 @@ /* * $Id: LocaWriter.java,v 1.3 2004/01/15 07:06:27 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,43 +25,42 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; /** * @author e.e */ public class LocaWriter extends FontFormatWriter { - public ArrayList m_offsets = new ArrayList<>(); - - public LocaWriter() { - super(); - } - - public void write() throws IOException { + + public ArrayList m_offsets = new ArrayList<>(); + + public LocaWriter() { + super(); + } + + public void write() throws IOException { // assume glyf table is already written, - // and offsets are stored in m_offsets - - int i; - for (i = 0; i < m_offsets.size(); i++) { - writeUInt32(m_offsets.get(i)); - } - - pad(); - } - - protected String getTag() { - return "loca"; - } + // and offsets are stored in m_offsets + + int i; + for (i = 0; i < m_offsets.size(); i++) { + writeUInt32(m_offsets.get(i)); + } + + pad(); + } + + protected String getTag() { + return "loca"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/MaxpWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/MaxpWriter.java index b82b035b1..a537352f3 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/MaxpWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/MaxpWriter.java @@ -1,8 +1,8 @@ /* * $Id: MaxpWriter.java,v 1.11 2004/06/27 07:26:46 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,113 +25,132 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; +import java.io.IOException; /** * @author e.e */ -public class MaxpWriter extends FontFormatWriter { - private int m_numGlyphs = 98; // set by GlyfWriter - private int m_maxPoints = 0; - private int m_maxContours = 0; - private int m_maxCompositePoints = 0; - private int m_maxCompositeContours = 0; - private int m_maxZones = 2; - private int m_maxTwilightPoints = 128; - private int m_maxStorage = 64; - private int m_maxFunctionDefs = 128; - private int m_maxInstructionDefs = 128; - private int m_maxStackElements = 128; - private int m_maxSizeOfInstructions = 128; - private int m_maxComponentElements = 128; - private int m_maxComponentDepth = 0; - - public MaxpWriter() { - super(); - } - - public void write() throws IOException { - writeFixed32(1.0); - writeUInt16(m_numGlyphs); - writeUInt16(m_maxPoints); - writeUInt16(m_maxContours); - writeUInt16(m_maxCompositePoints); - writeUInt16(m_maxCompositeContours); - writeUInt16(m_maxZones); - writeUInt16(m_maxTwilightPoints); - writeUInt16(m_maxStorage); - writeUInt16(m_maxFunctionDefs); - writeUInt16(m_maxInstructionDefs); - writeUInt16(m_maxStackElements); - writeUInt16(m_maxSizeOfInstructions); - writeUInt16(m_maxComponentElements); - writeUInt16(m_maxComponentDepth); - pad(); - } - - protected String getTag() { - return "maxp"; - } - - /** set the number of glyphs in the font */ - public void setNumGlyphs(int a_value) { - m_numGlyphs = a_value; - } - - /** update points in non-compound glyph */ - public void updateNumOfPoints(int a_value) { - if (a_value > m_maxPoints) { - m_maxPoints = a_value; - } - } - - /** update points in non-compound glyph */ - public void updateNumOfContours(int a_value) { - if (a_value > m_maxContours) { - m_maxContours = a_value; - } - } - - public void updateNumOfCompositePoints(int a_value) { - if (a_value > m_maxCompositePoints) { - m_maxCompositePoints = a_value; - } - } - - public void updateNumOfCompositeContours(int a_value) { - if (a_value > m_maxCompositeContours) { - m_maxCompositeContours = a_value; - } - } - - /** update byte count for glyph instructions */ - public void updateSizeOfInstructions(int a_value) { - if (a_value > m_maxSizeOfInstructions) { - m_maxSizeOfInstructions = a_value; - } - } - - public void updateNumOfComponentElements(int a_value) { - if (a_value > m_maxComponentElements) { - m_maxComponentElements = a_value; - } - } - - public void updateComponentDepth(int a_value) { - if (a_value > m_maxComponentDepth) { - m_maxComponentDepth = a_value; - } - } +public class MaxpWriter extends FontFormatWriter { + private int m_numGlyphs = 98; // set by GlyfWriter + + private int m_maxPoints = 0; + + private int m_maxContours = 0; + + private int m_maxCompositePoints = 0; + + private int m_maxCompositeContours = 0; + + private int m_maxZones = 2; + + private int m_maxTwilightPoints = 128; + + private int m_maxStorage = 64; + + private int m_maxFunctionDefs = 128; + + private int m_maxInstructionDefs = 128; + + private int m_maxStackElements = 128; + + private int m_maxSizeOfInstructions = 128; + + private int m_maxComponentElements = 128; + + private int m_maxComponentDepth = 0; + + public MaxpWriter() { + super(); + } + + public void write() throws IOException { + writeFixed32(1.0); + writeUInt16(m_numGlyphs); + writeUInt16(m_maxPoints); + writeUInt16(m_maxContours); + writeUInt16(m_maxCompositePoints); + writeUInt16(m_maxCompositeContours); + writeUInt16(m_maxZones); + writeUInt16(m_maxTwilightPoints); + writeUInt16(m_maxStorage); + writeUInt16(m_maxFunctionDefs); + writeUInt16(m_maxInstructionDefs); + writeUInt16(m_maxStackElements); + writeUInt16(m_maxSizeOfInstructions); + writeUInt16(m_maxComponentElements); + writeUInt16(m_maxComponentDepth); + pad(); + } + + protected String getTag() { + return "maxp"; + } + + /** + * set the number of glyphs in the font + */ + public void setNumGlyphs(int a_value) { + m_numGlyphs = a_value; + } + + /** + * update points in non-compound glyph + */ + public void updateNumOfPoints(int a_value) { + if (a_value > m_maxPoints) { + m_maxPoints = a_value; + } + } + + /** + * update points in non-compound glyph + */ + public void updateNumOfContours(int a_value) { + if (a_value > m_maxContours) { + m_maxContours = a_value; + } + } + + public void updateNumOfCompositePoints(int a_value) { + if (a_value > m_maxCompositePoints) { + m_maxCompositePoints = a_value; + } + } + + public void updateNumOfCompositeContours(int a_value) { + if (a_value > m_maxCompositeContours) { + m_maxCompositeContours = a_value; + } + } + + /** + * update byte count for glyph instructions + */ + public void updateSizeOfInstructions(int a_value) { + if (a_value > m_maxSizeOfInstructions) { + m_maxSizeOfInstructions = a_value; + } + } + + public void updateNumOfComponentElements(int a_value) { + if (a_value > m_maxComponentElements) { + m_maxComponentElements = a_value; + } + } + + public void updateComponentDepth(int a_value) { + if (a_value > m_maxComponentDepth) { + m_maxComponentDepth = a_value; + } + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/NameWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/NameWriter.java index cfe93a533..71dd048fe 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/NameWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/NameWriter.java @@ -1,8 +1,8 @@ /* * $Id: NameWriter.java,v 1.9 2004/06/16 07:02:52 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,159 +25,168 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.ArrayList; /** * @author e.e */ -public class NameWriter extends FontFormatWriter { - public static final String k_regular = "Regular"; - private static final String k_utf16be = "UTF-16BE"; - private static final String k_iso8859_1 = "ISO-8859-1"; - - String m_copyright = "\u00A9 Copyright"; - String m_familyName = "Temp"; - String m_subFamilyName = k_regular; - String m_unique = "eed3si9n: Temp Regular: 2003"; - String m_fullFontName = "Temp"; - String m_version = "0.00"; - String m_psName = "Temp"; - String m_tradeMark = ""; - String m_manufacturer = "eed3si9n"; - String m_year = "2004"; - String m_sample = "The quick brown fox jumps over the lazy dog."; - - private ArrayList m_names = new ArrayList<>(); - - public NameWriter() { - super(); - } - - private void prepare() { - m_copyright = "\u00A9 Copyright " - + m_year - + ", " - + m_manufacturer - + "."; - m_unique = "dtype: " - + m_manufacturer + ": " - + m_familyName + " " - + m_subFamilyName + ": " - + "Version " + m_version + ": " - + m_year; - m_fullFontName = m_familyName; - m_psName = m_fullFontName; - - if (m_tradeMark.length() == 0) { - m_tradeMark = "n/a"; - } - - m_names.clear(); - addNames(); - } - - private void addNames() { - addMacintoshRomanEnglish(0, m_copyright); - addMacintoshRomanEnglish(1, m_familyName); - addMacintoshRomanEnglish(2, m_subFamilyName); - addMacintoshRomanEnglish(3, m_unique); - addMacintoshRomanEnglish(4, m_fullFontName); - addMacintoshRomanEnglish(5, "Version " + m_version); - addMacintoshRomanEnglish(6, m_psName); - addMacintoshRomanEnglish(7, m_tradeMark); - addMacintoshRomanEnglish(8, m_manufacturer); - - addMicrosoftUnicodeEnglish(0, m_copyright); - addMicrosoftUnicodeEnglish(1, m_familyName); - addMicrosoftUnicodeEnglish(2, m_subFamilyName); - addMicrosoftUnicodeEnglish(3, m_unique); - addMicrosoftUnicodeEnglish(4, m_fullFontName); - addMicrosoftUnicodeEnglish(5, "Version " + m_version); - addMicrosoftUnicodeEnglish(6, m_psName); - addMicrosoftUnicodeEnglish(7, m_tradeMark); - addMicrosoftUnicodeEnglish(8, m_manufacturer); - // addMicrosoftUnicodeEnglish(19, m_sample); - } - - private void addMacintoshRomanEnglish(int a_nameId, String a_value) { - try { - add(TTName.k_macintosh, - TTName.k_macRomanEncode, - TTName.k_macEnglishLang, - a_nameId, - a_value.getBytes(k_iso8859_1)); - } - catch (IOException e) { - e.printStackTrace(); - } // try-catch - } - - private void addMicrosoftUnicodeEnglish(int a_nameId, String a_value) { - try { - add(TTName.k_microsoft, - TTName.k_winUnicodeEncode, - TTName.k_winEnglishLang, - a_nameId, - a_value.getBytes(k_utf16be)); - } - catch (IOException e) { - e.printStackTrace(); - } - } - - private void add(int a_platformId, int a_encodingId, int a_languageId, - int a_nameId, byte a_bytes[]) { - TTName name = new TTName(a_platformId, - a_encodingId, - a_languageId, - a_nameId, - a_bytes); - m_names.add(name); - } - - public void write() throws IOException { - prepare(); - - // table version number - writeUInt16(0); - - // number of name records - writeUInt16(m_names.size()); - - // Offset to start of string storage (from start of table). - writeUInt16(12 * m_names.size() + 6); - - int offset = 0; - for (TTName name: m_names) { - writeUInt16(name.getPlatformId()); - writeUInt16(name.getEncodingId()); - writeUInt16(name.getLanguageId()); - writeUInt16(name.getNameId()); - writeUInt16(name.getStringLength()); - writeUInt16(offset); - offset += name.getStringLength(); - } - - for (TTName name: m_names) { - m_buffer.write(name.getBytes()); - } - - pad(); - } - - protected String getTag() { - return "name"; - } +public class NameWriter extends FontFormatWriter { + + public static final String k_regular = "Regular"; + + private static final String k_utf16be = "UTF-16BE"; + + private static final String k_iso8859_1 = "ISO-8859-1"; + + String m_copyright = "\u00A9 Copyright"; + + String m_familyName = "Temp"; + + String m_subFamilyName = k_regular; + + String m_unique = "eed3si9n: Temp Regular: 2003"; + + String m_fullFontName = "Temp"; + + String m_version = "0.00"; + + String m_psName = "Temp"; + + String m_tradeMark = ""; + + String m_manufacturer = "eed3si9n"; + + String m_year = "2004"; + + String m_sample = "The quick brown fox jumps over the lazy dog."; + + private ArrayList m_names = new ArrayList<>(); + + public NameWriter() { + super(); + } + + private void prepare() { + m_copyright = "\u00A9 Copyright " + + m_year + + ", " + + m_manufacturer + + "."; + m_unique = "dtype: " + + m_manufacturer + ": " + + m_familyName + " " + + m_subFamilyName + ": " + + "Version " + m_version + ": " + + m_year; + m_fullFontName = m_familyName; + m_psName = m_fullFontName; + + if (m_tradeMark.length() == 0) { + m_tradeMark = "n/a"; + } + + m_names.clear(); + addNames(); + } + + private void addNames() { + addMacintoshRomanEnglish(0, m_copyright); + addMacintoshRomanEnglish(1, m_familyName); + addMacintoshRomanEnglish(2, m_subFamilyName); + addMacintoshRomanEnglish(3, m_unique); + addMacintoshRomanEnglish(4, m_fullFontName); + addMacintoshRomanEnglish(5, "Version " + m_version); + addMacintoshRomanEnglish(6, m_psName); + addMacintoshRomanEnglish(7, m_tradeMark); + addMacintoshRomanEnglish(8, m_manufacturer); + + addMicrosoftUnicodeEnglish(0, m_copyright); + addMicrosoftUnicodeEnglish(1, m_familyName); + addMicrosoftUnicodeEnglish(2, m_subFamilyName); + addMicrosoftUnicodeEnglish(3, m_unique); + addMicrosoftUnicodeEnglish(4, m_fullFontName); + addMicrosoftUnicodeEnglish(5, "Version " + m_version); + addMicrosoftUnicodeEnglish(6, m_psName); + addMicrosoftUnicodeEnglish(7, m_tradeMark); + addMicrosoftUnicodeEnglish(8, m_manufacturer); + // addMicrosoftUnicodeEnglish(19, m_sample); + } + + private void addMacintoshRomanEnglish(int a_nameId, String a_value) { + try { + add(TTName.k_macintosh, + TTName.k_macRomanEncode, + TTName.k_macEnglishLang, + a_nameId, + a_value.getBytes(k_iso8859_1)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void addMicrosoftUnicodeEnglish(int a_nameId, String a_value) { + try { + add(TTName.k_microsoft, + TTName.k_winUnicodeEncode, + TTName.k_winEnglishLang, + a_nameId, + a_value.getBytes(k_utf16be)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void add(int a_platformId, int a_encodingId, int a_languageId, + int a_nameId, byte a_bytes[]) { + TTName name = new TTName(a_platformId, + a_encodingId, + a_languageId, + a_nameId, + a_bytes); + m_names.add(name); + } + + public void write() throws IOException { + prepare(); + + // table version number + writeUInt16(0); + + // number of name records + writeUInt16(m_names.size()); + + // Offset to start of string storage (from start of table). + writeUInt16(12 * m_names.size() + 6); + + int offset = 0; + for (TTName name : m_names) { + writeUInt16(name.getPlatformId()); + writeUInt16(name.getEncodingId()); + writeUInt16(name.getLanguageId()); + writeUInt16(name.getNameId()); + writeUInt16(name.getStringLength()); + writeUInt16(offset); + offset += name.getStringLength(); + } + + for (TTName name : m_names) { + m_buffer.write(name.getBytes()); + } + + pad(); + } + + protected String getTag() { + return "name"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java index c846bff26..a1f7e3c20 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java @@ -1,8 +1,8 @@ /* * $Id: OS2Writer.java,v 1.11 2004/10/04 02:25:39 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,218 +25,267 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; +import java.io.IOException; /** * @author e.e */ -public class OS2Writer extends FontFormatWriter { - final int FW_THIN = 100; - final int FW_EXTRALIGHT = 200; - final int FW_LIGHT = 300; - final int FW_NORMAL = 400; - final int FW_MEDIUM = 500; - final int FW_SEMIBOLD = 600; - final int FW_BOLD = 700; - final int FW_EXTRABOLD = 800; - final int FW_BLACK = 900; - - final int FWIDTH_NORMAL = 5; - - final int k_editableEmbedding = 0x0008; - - final int k_sansSerif = 0x0800; - - // unicode - final int k_basicLatin = 0x0001; - final int k_latin1Supplement = 0x0002; - - final int k_regular = 0x40; - final int k_basicLatinStart = 0x0020; - final int k_basciLatinEnd = 0x007e; - - private HeadWriter m_head; - - int m_xAvgCharWidth = 512; - int m_usWeightClass = FW_NORMAL; - int m_usWidthClass = FWIDTH_NORMAL; - int m_fsType = 0; - int m_ySubscriptXSize = 128; - int m_ySubscriptYSize = 128; - int m_ySubscriptXOffset = 0; - int m_ySubscriptYOffset = -64; - int m_ySuperscriptXSize = 128; - int m_ySuperscriptYSize = 128; - int m_ySuperscriptXOffset = 0; - int m_ySuperscriptYOffset = 64; - int m_yStrikeoutSize = 51; - int m_yStrikeoutPosition = 512; - int m_sFamilyClass = k_sansSerif; - - long m_ulUnicodeRange1 = k_basicLatin | k_latin1Supplement; - long m_ulUnicodeRange2 = 0; - long m_ulUnicodeRange3 = 0; - long m_ulUnicodeRange4 = 0; - String m_vendId = "dtyp"; - int m_fsSelection = k_regular; - int m_usFirstCharIndex = k_basicLatinStart; - int m_usLastCharIndex = k_basciLatinEnd; - private int m_sTypoAscender = 1024; - private int m_sTypoDescender = 0; - private int m_sTypoLineGap = 0; - private int m_usWinAscent = 1024; - private int m_usWinDescent = 0; - long m_ulCodePageRange1 = 0; - long m_ulCodePageRange2 = 0; - private int m_sxHeight = 512; - private int m_sCapHeight = 1024; - int m_usDefaultChar = 0x0; - int m_usBreakChar = 0x20; - int m_usMaxContext = 1; - - public OS2Writer(HeadWriter a_head) { - super(); - - m_head = a_head; - } - - public void setCapHeight(int a_value) { - m_sCapHeight = a_value; - } - - public void setXHeight(int a_value) { - m_sxHeight = a_value; - } - - public void setTypoAscender(int a_value) { - m_sTypoAscender = a_value; - } - - public void setTypoDescender(int a_value) { - m_sTypoDescender = a_value; - } - - public void setTypoLineGap(int a_value) { - m_sTypoLineGap = a_value; - } - - public void setUnicodeRangeFlag(int a_pos) { - int which = a_pos / 32; - int where = a_pos % 32; - long what = 0x1 << where; - - switch (which) { - case 0: { - m_ulUnicodeRange1 |= what; - } break; - - case 1: { - m_ulUnicodeRange2 |= what; - } break; - - case 2: { - m_ulUnicodeRange3 |= what; - } break; - - case 3: { - m_ulUnicodeRange4 |= what; - } break; - } // switch - } - - public void setCodePageRangeFlag(int a_pos) { - int which = a_pos / 32; - int where = a_pos % 32; - long what = 0x1 << where; - - switch (which) { - case 0: { - m_ulCodePageRange1 |= what; - } break; - - case 1: { - m_ulCodePageRange2 |= what; - } break; - } // switch - } - - public void write() throws IOException { - m_usWinAscent = m_head.getMax().y; - m_usWinDescent = 0; - if (m_head.getMin().y < 0) { - m_usWinDescent = -m_head.getMin().y; - } - - // table version number - writeUInt16(0x02); - - writeInt16(m_xAvgCharWidth); - writeUInt16(m_usWeightClass); - writeUInt16(m_usWidthClass); - writeInt16(m_fsType); - writeInt16(m_ySubscriptXSize); - writeInt16(m_ySubscriptYSize); - writeInt16(m_ySubscriptXOffset); - writeInt16(m_ySubscriptYOffset); - writeInt16(m_ySuperscriptXSize); - writeInt16(m_ySuperscriptYSize); - writeInt16(m_ySuperscriptXOffset); - writeInt16(m_ySuperscriptYOffset); - writeInt16(m_yStrikeoutSize); - writeInt16(m_yStrikeoutPosition); - writeInt16(m_sFamilyClass); - - writePanose(); - - writeUInt32(m_ulUnicodeRange1); - writeUInt32(m_ulUnicodeRange2); - writeUInt32(m_ulUnicodeRange3); - writeUInt32(m_ulUnicodeRange4); - writeTag(m_vendId); - writeUInt16(m_fsSelection); - writeUInt16(m_usFirstCharIndex); - writeUInt16(m_usLastCharIndex); - writeUInt16(m_sTypoAscender); - writeUInt16(m_sTypoDescender); - writeUInt16(m_sTypoLineGap); - writeUInt16(m_usWinAscent); - writeUInt16(m_usWinDescent); - writeUInt32(m_ulCodePageRange1); - writeUInt32(m_ulCodePageRange2); - writeInt16(m_sxHeight); - writeInt16(m_sCapHeight); - writeUInt16(m_usDefaultChar); - writeUInt16(m_usBreakChar); - writeUInt16(m_usMaxContext); - - pad(); - } - - private void writePanose() throws IOException { - writeUInt8(0); // family - writeUInt8(0); // serif - writeUInt8(0); // weight - writeUInt8(0); // proportion - writeUInt8(0); // contrast - writeUInt8(0); // stroke - writeUInt8(0); // arm style - writeUInt8(0); // letterform - writeUInt8(0); // midline - writeUInt8(0); // x-height - } - - protected String getTag() { - return "OS/2 "; - } +public class OS2Writer extends FontFormatWriter { + + final int FW_THIN = 100; + + final int FW_EXTRALIGHT = 200; + + final int FW_LIGHT = 300; + + final int FW_NORMAL = 400; + + final int FW_MEDIUM = 500; + + final int FW_SEMIBOLD = 600; + + final int FW_BOLD = 700; + + final int FW_EXTRABOLD = 800; + + final int FW_BLACK = 900; + + final int FWIDTH_NORMAL = 5; + + final int k_editableEmbedding = 0x0008; + + final int k_sansSerif = 0x0800; + + // unicode + final int k_basicLatin = 0x0001; + + final int k_latin1Supplement = 0x0002; + + final int k_regular = 0x40; + + final int k_basicLatinStart = 0x0020; + + final int k_basciLatinEnd = 0x007e; + + private HeadWriter m_head; + + int m_xAvgCharWidth = 512; + + int m_usWeightClass = FW_NORMAL; + + int m_usWidthClass = FWIDTH_NORMAL; + + int m_fsType = 0; + + int m_ySubscriptXSize = 128; + + int m_ySubscriptYSize = 128; + + int m_ySubscriptXOffset = 0; + + int m_ySubscriptYOffset = -64; + + int m_ySuperscriptXSize = 128; + + int m_ySuperscriptYSize = 128; + + int m_ySuperscriptXOffset = 0; + + int m_ySuperscriptYOffset = 64; + + int m_yStrikeoutSize = 51; + + int m_yStrikeoutPosition = 512; + + int m_sFamilyClass = k_sansSerif; + + long m_ulUnicodeRange1 = k_basicLatin | k_latin1Supplement; + + long m_ulUnicodeRange2 = 0; + + long m_ulUnicodeRange3 = 0; + + long m_ulUnicodeRange4 = 0; + + String m_vendId = "dtyp"; + + int m_fsSelection = k_regular; + + int m_usFirstCharIndex = k_basicLatinStart; + + int m_usLastCharIndex = k_basciLatinEnd; + + private int m_sTypoAscender = 1024; + + private int m_sTypoDescender = 0; + + private int m_sTypoLineGap = 0; + + private int m_usWinAscent = 1024; + + private int m_usWinDescent = 0; + + long m_ulCodePageRange1 = 0; + + long m_ulCodePageRange2 = 0; + + private int m_sxHeight = 512; + + private int m_sCapHeight = 1024; + + int m_usDefaultChar = 0x0; + + int m_usBreakChar = 0x20; + + int m_usMaxContext = 1; + + public OS2Writer(HeadWriter a_head) { + super(); + + m_head = a_head; + } + + public void setCapHeight(int a_value) { + m_sCapHeight = a_value; + } + + public void setXHeight(int a_value) { + m_sxHeight = a_value; + } + + public void setTypoAscender(int a_value) { + m_sTypoAscender = a_value; + } + + public void setTypoDescender(int a_value) { + m_sTypoDescender = a_value; + } + + public void setTypoLineGap(int a_value) { + m_sTypoLineGap = a_value; + } + + public void setUnicodeRangeFlag(int a_pos) { + int which = a_pos / 32; + int where = a_pos % 32; + long what = 0x1 << where; + + switch (which) { + case 0: { + m_ulUnicodeRange1 |= what; + } + break; + + case 1: { + m_ulUnicodeRange2 |= what; + } + break; + + case 2: { + m_ulUnicodeRange3 |= what; + } + break; + + case 3: { + m_ulUnicodeRange4 |= what; + } + break; + } // switch + } + + public void setCodePageRangeFlag(int a_pos) { + int which = a_pos / 32; + int where = a_pos % 32; + long what = 0x1 << where; + + switch (which) { + case 0: { + m_ulCodePageRange1 |= what; + } + break; + + case 1: { + m_ulCodePageRange2 |= what; + } + break; + } // switch + } + + public void write() throws IOException { + m_usWinAscent = m_head.getMax().y; + m_usWinDescent = 0; + if (m_head.getMin().y < 0) { + m_usWinDescent = -m_head.getMin().y; + } + + // table version number + writeUInt16(0x02); + + writeInt16(m_xAvgCharWidth); + writeUInt16(m_usWeightClass); + writeUInt16(m_usWidthClass); + writeInt16(m_fsType); + writeInt16(m_ySubscriptXSize); + writeInt16(m_ySubscriptYSize); + writeInt16(m_ySubscriptXOffset); + writeInt16(m_ySubscriptYOffset); + writeInt16(m_ySuperscriptXSize); + writeInt16(m_ySuperscriptYSize); + writeInt16(m_ySuperscriptXOffset); + writeInt16(m_ySuperscriptYOffset); + writeInt16(m_yStrikeoutSize); + writeInt16(m_yStrikeoutPosition); + writeInt16(m_sFamilyClass); + + writePanose(); + + writeUInt32(m_ulUnicodeRange1); + writeUInt32(m_ulUnicodeRange2); + writeUInt32(m_ulUnicodeRange3); + writeUInt32(m_ulUnicodeRange4); + writeTag(m_vendId); + writeUInt16(m_fsSelection); + writeUInt16(m_usFirstCharIndex); + writeUInt16(m_usLastCharIndex); + writeUInt16(m_sTypoAscender); + writeUInt16(m_sTypoDescender); + writeUInt16(m_sTypoLineGap); + writeUInt16(m_usWinAscent); + writeUInt16(m_usWinDescent); + writeUInt32(m_ulCodePageRange1); + writeUInt32(m_ulCodePageRange2); + writeInt16(m_sxHeight); + writeInt16(m_sCapHeight); + writeUInt16(m_usDefaultChar); + writeUInt16(m_usBreakChar); + writeUInt16(m_usMaxContext); + + pad(); + } + + private void writePanose() throws IOException { + writeUInt8(0); // family + writeUInt8(0); // serif + writeUInt8(0); // weight + writeUInt8(0); // proportion + writeUInt8(0); // contrast + writeUInt8(0); // stroke + writeUInt8(0); // arm style + writeUInt8(0); // letterform + writeUInt8(0); // midline + writeUInt8(0); // x-height + } + + protected String getTag() { + return "OS/2 "; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/PostWriter.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/PostWriter.java index b7ac25959..e7eee79ab 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/PostWriter.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/PostWriter.java @@ -1,8 +1,8 @@ /* * $Id: PostWriter.java,v 1.3 2004/01/11 13:14:45 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,52 +25,51 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - - package org.doubletype.ossa.truetype; -import java.io.*; +import java.io.IOException; /** * @author e.e */ -public class PostWriter extends FontFormatWriter { - boolean m_isMonospaced = false; - - public PostWriter() { - super(); - } - - public void write() throws IOException { - // table version number - writeFixed32(1.0); - writeFixed32(10.0); // italic angle - writeFWord(0); // underline pos - writeFWord(60); // underline thickness - - if (m_isMonospaced) { - writeUInt32(1); // fixed pitch - } else { - writeUInt32(0); - } - - // vm memory stuff - writeUInt32(0); - writeUInt32(0); - writeUInt32(0); - writeUInt32(0); - - pad(); - } - - protected String getTag() { - return "post"; - } +public class PostWriter extends FontFormatWriter { + + boolean m_isMonospaced = false; + + public PostWriter() { + super(); + } + + public void write() throws IOException { + // table version number + writeFixed32(1.0); + writeFixed32(10.0); // italic angle + writeFWord(0); // underline pos + writeFWord(60); // underline thickness + + if (m_isMonospaced) { + writeUInt32(1); // fixed pitch + } else { + writeUInt32(0); + } + + // vm memory stuff + writeUInt32(0); + writeUInt32(0); + writeUInt32(0); + writeUInt32(0); + + pad(); + } + + protected String getTag() { + return "post"; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTCodePage.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTCodePage.java index b619a1e1c..9d3dd14ee 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTCodePage.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTCodePage.java @@ -1,8 +1,8 @@ /* * $Id: TTCodePage.java,v 1.3 2004/05/16 12:59:07 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,165 +25,136 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.truetype; -import java.util.*; -import java.nio.charset.*; +import java.nio.charset.Charset; +import java.util.ArrayList; /** * @author e.e */ public class TTCodePage { - static public TTCodePage US_ASCII = new TTCodePage("US-ASCII", - "US-ASCII", - 64); - static public TTCodePage Latin_1 = new TTCodePage("windows-1252", - "Latin 1 windows-1252", - 0); - static private boolean s_isInitialized = false; - static private ArrayList s_list = new ArrayList<>(); - - static public String [] getNames() { - initList(); - String [] retval = new String[s_list.size()]; - int i; - for (i = 0; i < s_list.size(); i++) { - TTCodePage codePage = (TTCodePage) s_list.get(i); - retval[i] = codePage.getName(); - } - - return retval; - } - - static public TTCodePage forName(String a_name) { - initList(); - - TTCodePage retval = null; - for (TTCodePage codePage: s_list) { - if (codePage.getName().equals(a_name)) { - return codePage; - } - } // for - - for (TTCodePage codePage: s_list) { - if (codePage.getCharset() == null) { - continue; - } - - if (codePage.getCharset().name().equals(a_name)) { - return codePage; - } - } // for - - return retval; - } - - static private void initList() { - if (s_isInitialized) - return; - - s_isInitialized = true; - - s_list.add(US_ASCII); - s_list.add(Latin_1); - s_list.add(new TTCodePage("ISO-2022-JP", - "Japan-JIS", - 17)); - s_list.add(new TTCodePage("windows-1250", - "Latin 2: Eastern Europe windows-1250", - 1)); - s_list.add(new TTCodePage("windows-1251", - "Cyrillic windows-1251", - 2)); - s_list.add(new TTCodePage("windows-1253", - "Greek windows-1253", - 3)); - s_list.add(new TTCodePage("windows-1254", - "Turkish windows-1254", - 4)); - s_list.add(new TTCodePage("windows-1258", - "Vietnamese windows-1258", - 8)); - - - // extended - s_list.add(new TTCodePage("windows-1255", - "Hebrew windows-1255", - 5)); - s_list.add(new TTCodePage("windows-1256", - "Arabic windows-1256", - 6)); - s_list.add(new TTCodePage("windows-1257", - "Windows Baltic", - 7)); - - // TODO: 16 Thai 874 - s_list.add(new TTCodePage( - "Thai windows-874", - 16)); - - s_list.add(new TTCodePage("x-mswin-936", - "Chinese: Simplified", - 18)); - - // TODO: 19 Korean Wansung - s_list.add(new TTCodePage( - "Korean Wansung", - 19)); - - s_list.add(new TTCodePage("x-windows-950", - "Chinese: Traditional", - 20)); - } - - - private String m_name; - - /** http://www.microsoft.com/typography/otspec/os2.htm - */ - private int m_osTwoFlag = 0; - private Charset m_charset = null; - - public TTCodePage(String a_charsetName, String a_name, - int a_osTwoFlag) - { - if (Charset.isSupported(a_charsetName)) { - m_charset = Charset.forName(a_charsetName); - } - - m_name = a_name; - m_osTwoFlag = a_osTwoFlag; - } - - public TTCodePage(String a_name, - int a_osTwoFlag) - { - m_name = a_name; - m_osTwoFlag = a_osTwoFlag; - } - - public String toString() { - return m_name; - } - - public String getName() { - return m_name; - } - - - public Charset getCharset() { - return m_charset; - } - - public int getOsTwoFlag() { - return m_osTwoFlag; - } + + static public TTCodePage US_ASCII = new TTCodePage("US-ASCII", "US-ASCII", 64); + + static public TTCodePage Latin_1 = new TTCodePage("windows-1252", "Latin 1 windows-1252", 0); + + static private boolean s_isInitialized = false; + + static private ArrayList s_list = new ArrayList<>(); + + static public String[] getNames() { + initList(); + String[] retval = new String[s_list.size()]; + int i; + for (i = 0; i < s_list.size(); i++) { + TTCodePage codePage = (TTCodePage) s_list.get(i); + retval[i] = codePage.getName(); + } + + return retval; + } + + static public TTCodePage forName(String a_name) { + initList(); + + TTCodePage retval = null; + for (TTCodePage codePage : s_list) { + if (codePage.getName().equals(a_name)) { + return codePage; + } + } // for + + for (TTCodePage codePage : s_list) { + if (codePage.getCharset() == null) { + continue; + } + + if (codePage.getCharset().name().equals(a_name)) { + return codePage; + } + } // for + + return retval; + } + + static private void initList() { + if (s_isInitialized) { + return; + } + + s_isInitialized = true; + + s_list.add(US_ASCII); + s_list.add(Latin_1); + s_list.add(new TTCodePage("ISO-2022-JP", "Japan-JIS", 17)); + s_list.add(new TTCodePage("windows-1250", "Latin 2: Eastern Europe windows-1250", 1)); + s_list.add(new TTCodePage("windows-1251", "Cyrillic windows-1251", 2)); + s_list.add(new TTCodePage("windows-1253", "Greek windows-1253", 3)); + s_list.add(new TTCodePage("windows-1254", "Turkish windows-1254", 4)); + s_list.add(new TTCodePage("windows-1258", "Vietnamese windows-1258", 8)); + + // extended + s_list.add(new TTCodePage("windows-1255", "Hebrew windows-1255", 5)); + s_list.add(new TTCodePage("windows-1256", "Arabic windows-1256", 6)); + s_list.add(new TTCodePage("windows-1257", "Windows Baltic", 7)); + + // TODO: 16 Thai 874 + s_list.add(new TTCodePage("Thai windows-874", 16)); + + s_list.add(new TTCodePage("x-mswin-936", "Chinese: Simplified", 18)); + + // TODO: 19 Korean Wansung + s_list.add(new TTCodePage("Korean Wansung", 19)); + + s_list.add(new TTCodePage("x-windows-950", "Chinese: Traditional", 20)); + } + + private String m_name; + + /** + * http://www.microsoft.com/typography/otspec/os2.htm + */ + private int m_osTwoFlag = 0; + + private Charset m_charset = null; + + public TTCodePage(String a_charsetName, String a_name, + int a_osTwoFlag) { + if (Charset.isSupported(a_charsetName)) { + m_charset = Charset.forName(a_charsetName); + } + + m_name = a_name; + m_osTwoFlag = a_osTwoFlag; + } + + public TTCodePage(String a_name, + int a_osTwoFlag) { + m_name = a_name; + m_osTwoFlag = a_osTwoFlag; + } + + public String toString() { + return m_name; + } + + public String getName() { + return m_name; + } + + public Charset getCharset() { + return m_charset; + } + + public int getOsTwoFlag() { + return m_osTwoFlag; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java index 775f0a977..996bbd561 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java @@ -1,6 +1,6 @@ /* * $Copyright: copyright (c) 2003-2008, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -23,369 +23,418 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.truetype; -import java.awt.*; -import java.util.*; +import java.awt.Point; +import java.util.ArrayList; /** * @author e.e */ public class TTGlyph { - // -------------------------------------------------------------- - public static final int k_onCurve = 0x1; - - public static final int ARG_1_AND_2_ARE_WORDS = 0x1; - public static final int ARGS_ARE_XY_VALUES = 0x2; - public static final int ROUND_XY_TO_GRID = 0x4; - public static final int WE_HAVE_A_SCALE = 0x8; - // 0x10 is obsolete - public static final int MORE_COMPONENTS = 0x20; - public static final int WE_HAVE_AN_X_AND_Y_SCALE = 0x40; - public static final int WE_HAVE_A_TWO_BY_TWO = 0x80; - public static final int WE_HAVE_INSTRUCTIONS = 0x100; - public static final int USE_MY_METRICS = 0x200; - public static final int OVERLAP_COMPOUND = 0x400; - - /** Move Direct Absolute Point - do not round */ - public static final int MDAP0 = 0x2E; - - /** Move Direct Absolute Point - round the value */ - public static final int MDAP1 = 0x2F; - - /** Interpolate Untouched Points through the outline - y-direction */ - public static final int IUP0 = 0x30; - - /** Interpolate Untouched Points through the outline - x-direction */ - public static final int IUP1 = 0x31; - - /** push one byte */ - public static final int PUSHB000 = 0xB0; - - /** push two bytes */ - public static final int PUSHB001 = 0xB1; - - /** push three bytes */ - public static final int PUSHB010 = 0xB2; - public static final int PUSHB011 = 0xB3; - public static final int PUSHB100 = 0xB4; - public static final int PUSHB101 = 0xB5; - public static final int PUSHB110 = 0xB6; - public static final int PUSHB111 = 0xB7; - - /** set vector to y-axis. */ - public static final int SVTCA0 = 0x00; - - /** set vector to x-axis. */ - public static final int SVTCA1 = 0x01; - public static final int SPVFS = 0x0A; // set projection vector - public static final int SFVFS = 0x0B; // set freedom vector - public static final int SFVTPV = 0x0E; - public static final int DELTAP1 = 0x5D; - public static final int DELTAP2 = 0x71; - public static final int DELTAP3 = 0x72; - - /** set delta base */ - public static final int SDB = 0x5E; - - // -------------------------------------------------------------- - - /** - * converts double into F2Dot14, 16 bit fixed point format. - * @param a_value - * @return - */ - public static int toF2Dot14(double a_value) { - int retval = 0; - - if (a_value >= 2.0 || a_value < -2.0) { - throw new RuntimeException(Double.toString(a_value) + " out of range"); - } - - int mantissa = (int) Math.floor(a_value); - int fraction = (int) Math.floor((a_value - mantissa) * 16384); - - int twoBitPart = mantissa; - if (mantissa < 0) { - twoBitPart = 4 + mantissa; - } - - retval = (twoBitPart << 14) | fraction; - - return retval; - } - - public static int toDeltaArg(int a_relativePpem, int a_step) { - int retval = 0; - - if (a_step < -8 || a_step > 8 || a_step == 0) { - throw new RuntimeException("Out of range"); - } - - int selector = 0; - if (a_step > 0) { - selector = a_step + 7; - } else { - selector = a_step + 8; - } - - retval = (a_relativePpem << 4) | (selector); - - return retval; - } - - // -------------------------------------------------------------- - - private ArrayList m_points = new ArrayList<>(); - private ArrayList m_endPtsOfContours = new ArrayList<>(); - private ArrayList m_instructions = new ArrayList<>(); - private ArrayList m_flags = new ArrayList<>(); - private ArrayList m_glyfIndeces = new ArrayList<>(); - private ArrayList m_arg1s = new ArrayList<>(); - private ArrayList m_arg2s = new ArrayList<>(); - - private boolean m_isSimple = true; - private int m_advanceWidth = 512; - - private int m_numOfCompositePoints = 0; - private int m_numOfCompositeContours = 0; - private int m_componentDepth = 0; - - private Point m_min = null; - private Point m_max = null; - - // -------------------------------------------------------------- - - public TTGlyph() { - init(); - } - - public void init() { - m_isSimple = true; - m_points.clear(); - m_endPtsOfContours.clear(); - m_instructions.clear(); - m_flags.clear(); - m_glyfIndeces.clear(); - m_arg1s.clear(); - m_arg2s.clear(); - m_advanceWidth = 512; - } - - public void buildCompound() { - init(); - - m_isSimple = false; - - addFlag(ARG_1_AND_2_ARE_WORDS - | ARGS_ARE_XY_VALUES - | ROUND_XY_TO_GRID - | MORE_COMPONENTS); - addFlag(ARG_1_AND_2_ARE_WORDS - | ARGS_ARE_XY_VALUES - | ROUND_XY_TO_GRID); - - addGlyfIndex(3); - addGlyfIndex(3); - - addArg1(0); - addArg2(0); - addArg1(0); - addArg2(500); - } - - /** - * add the index of the last point in the contour - * @param a_index - */ - public void addEndPoint(int a_value) { - m_endPtsOfContours.add(a_value); - } - - public int getNumOfContours() { - if (isSimple()) { - return m_endPtsOfContours.size(); - } else { - return -1; - } - } - - public int getEndPoint(int a_index) { - return m_endPtsOfContours.get(a_index); - } - - public int getAdvanceWidth() { - return m_advanceWidth; - } - - public void setAdvanceWidth(int a_value) { - m_advanceWidth = a_value; - } - - public Point getMax() { - if (m_max == null) { - m_max = new Point(0, 0); - } - - return m_max; - } - public Point getMin() { - if (m_min == null) { - m_min = new Point(0, 0); - } - - return m_min; - } - - public boolean isSimple() { - return m_isSimple; - } - - public void setSimple(boolean a_isSimple) { - m_isSimple = a_isSimple; - } - - public void addInstruction(int a_value) { - m_instructions.add(a_value); - } - - public int getInstruction(int a_index) { - return m_instructions.get(a_index); - } - - public int getNumOfInstructions() { - return m_instructions.size(); - } - - public void addFlag(int a_value) { - m_flags.add(a_value); - } - - public int getFlag(int a_index) { - return m_flags.get(a_index); - } - - public int getNumOfFlags() { - return m_flags.size(); - } - - public void addPoint(Point a_value) { - m_points.add(a_value); - updateMinMax(a_value); - } - - private void updateMinMax(Point a_value) { - if (m_max == null) { - m_max = new Point(a_value); - } - - if (m_min == null) { - m_min = new Point(a_value); - } - - if (a_value.x > m_max.x) { - m_max.x = a_value.x; - } - - if (a_value.x < m_min.x) { - m_min.x = a_value.x; - } - - if (a_value.y > m_max.y) { - m_max.y = a_value.y; - } - - if (a_value.y < m_min.y) { - m_min.y = a_value.y; - } - } - - public Point getPoint(int a_index) { - return m_points.get(a_index); - } - - public int getNumOfPoints() { - return m_points.size(); - } - - public int getLastIndex() { - return m_points.size() - 1; - } - - public void addGlyfIndex(int a_value) { - m_glyfIndeces.add(a_value); - } - - public int getGlyfIndex(int a_index) { - return m_glyfIndeces.get(a_index); - } - - public void addArg1(int a_value) { - m_arg1s.add(a_value); - } - - public int getArg1(int a_index) { - return m_arg1s.get(a_index); - } - - public void addArg2(int a_value) { - m_arg2s.add(a_value); - } - - public int getArg2(int a_index) { - return m_arg2s.get(a_index); - } - - public int getNumOfCompositePoints() { - if (isSimple()) { - return getNumOfPoints(); - } else { - return m_numOfCompositePoints; - } - } - - public void setNumOfCompositePoints(int a_value) { - m_numOfCompositePoints = a_value; - } - - public int getNumOfCompositeContours() { - if (isSimple()) { - return getNumOfContours(); - } else { - return m_numOfCompositeContours; - } - } - - public void setNumOfCompositeContours(int a_value) { - m_numOfCompositeContours = a_value; - } - - public int getComponentDepth() { - if (isSimple()) { - return 0; - } else { - return m_componentDepth; - } - } - - public void setComponentDepth(int a_value) { - m_componentDepth = a_value; - } - - public int getLeftSideBearing() { - return getMin().x; - } - - public int getRightSideBearing() { - return getAdvanceWidth() - getMax().x; - } + // -------------------------------------------------------------- + public static final int k_onCurve = 0x1; + + public static final int ARG_1_AND_2_ARE_WORDS = 0x1; + + public static final int ARGS_ARE_XY_VALUES = 0x2; + + public static final int ROUND_XY_TO_GRID = 0x4; + + public static final int WE_HAVE_A_SCALE = 0x8; + + // 0x10 is obsolete + public static final int MORE_COMPONENTS = 0x20; + + public static final int WE_HAVE_AN_X_AND_Y_SCALE = 0x40; + + public static final int WE_HAVE_A_TWO_BY_TWO = 0x80; + + public static final int WE_HAVE_INSTRUCTIONS = 0x100; + + public static final int USE_MY_METRICS = 0x200; + + public static final int OVERLAP_COMPOUND = 0x400; + + /** + * Move Direct Absolute Point - do not round + */ + public static final int MDAP0 = 0x2E; + + /** + * Move Direct Absolute Point - round the value + */ + public static final int MDAP1 = 0x2F; + + /** + * Interpolate Untouched Points through the outline - y-direction + */ + public static final int IUP0 = 0x30; + + /** + * Interpolate Untouched Points through the outline - x-direction + */ + public static final int IUP1 = 0x31; + + /** + * push one byte + */ + public static final int PUSHB000 = 0xB0; + + /** + * push two bytes + */ + public static final int PUSHB001 = 0xB1; + + /** + * push three bytes + */ + public static final int PUSHB010 = 0xB2; + + public static final int PUSHB011 = 0xB3; + + public static final int PUSHB100 = 0xB4; + + public static final int PUSHB101 = 0xB5; + + public static final int PUSHB110 = 0xB6; + + public static final int PUSHB111 = 0xB7; + + /** + * set vector to y-axis. + */ + public static final int SVTCA0 = 0x00; + + /** + * set vector to x-axis. + */ + public static final int SVTCA1 = 0x01; + + public static final int SPVFS = 0x0A; // set projection vector + + public static final int SFVFS = 0x0B; // set freedom vector + + public static final int SFVTPV = 0x0E; + + public static final int DELTAP1 = 0x5D; + + public static final int DELTAP2 = 0x71; + + public static final int DELTAP3 = 0x72; + + /** + * set delta base + */ + public static final int SDB = 0x5E; + + // -------------------------------------------------------------- + /** + * converts double into F2Dot14, 16 bit fixed point format. + * + * @param a_value + * @return + */ + public static int toF2Dot14(double a_value) { + int retval = 0; + + if (a_value >= 2.0 || a_value < -2.0) { + throw new RuntimeException(Double.toString(a_value) + " out of range"); + } + + int mantissa = (int) Math.floor(a_value); + int fraction = (int) Math.floor((a_value - mantissa) * 16384); + + int twoBitPart = mantissa; + if (mantissa < 0) { + twoBitPart = 4 + mantissa; + } + + retval = (twoBitPart << 14) | fraction; + + return retval; + } + + public static int toDeltaArg(int a_relativePpem, int a_step) { + int retval = 0; + + if (a_step < -8 || a_step > 8 || a_step == 0) { + throw new RuntimeException("Out of range"); + } + + int selector = 0; + if (a_step > 0) { + selector = a_step + 7; + } else { + selector = a_step + 8; + } + + retval = (a_relativePpem << 4) | (selector); + + return retval; + } + + // -------------------------------------------------------------- + private ArrayList m_points = new ArrayList<>(); + + private ArrayList m_endPtsOfContours = new ArrayList<>(); + + private ArrayList m_instructions = new ArrayList<>(); + + private ArrayList m_flags = new ArrayList<>(); + + private ArrayList m_glyfIndeces = new ArrayList<>(); + + private ArrayList m_arg1s = new ArrayList<>(); + + private ArrayList m_arg2s = new ArrayList<>(); + + private boolean m_isSimple = true; + + private int m_advanceWidth = 512; + + private int m_numOfCompositePoints = 0; + + private int m_numOfCompositeContours = 0; + + private int m_componentDepth = 0; + + private Point m_min = null; + + private Point m_max = null; + + // -------------------------------------------------------------- + public TTGlyph() { + init(); + } + + public void init() { + m_isSimple = true; + m_points.clear(); + m_endPtsOfContours.clear(); + m_instructions.clear(); + m_flags.clear(); + m_glyfIndeces.clear(); + m_arg1s.clear(); + m_arg2s.clear(); + m_advanceWidth = 512; + } + + public void buildCompound() { + init(); + + m_isSimple = false; + + addFlag(ARG_1_AND_2_ARE_WORDS + | ARGS_ARE_XY_VALUES + | ROUND_XY_TO_GRID + | MORE_COMPONENTS); + addFlag(ARG_1_AND_2_ARE_WORDS + | ARGS_ARE_XY_VALUES + | ROUND_XY_TO_GRID); + + addGlyfIndex(3); + addGlyfIndex(3); + + addArg1(0); + addArg2(0); + addArg1(0); + addArg2(500); + } + + /** + * add the index of the last point in the contour + * + * @param a_index + */ + public void addEndPoint(int a_value) { + m_endPtsOfContours.add(a_value); + } + + public int getNumOfContours() { + if (isSimple()) { + return m_endPtsOfContours.size(); + } else { + return -1; + } + } + + public int getEndPoint(int a_index) { + return m_endPtsOfContours.get(a_index); + } + + public int getAdvanceWidth() { + return m_advanceWidth; + } + + public void setAdvanceWidth(int a_value) { + m_advanceWidth = a_value; + } + + public Point getMax() { + if (m_max == null) { + m_max = new Point(0, 0); + } + + return m_max; + } + + public Point getMin() { + if (m_min == null) { + m_min = new Point(0, 0); + } + + return m_min; + } + + public boolean isSimple() { + return m_isSimple; + } + + public void setSimple(boolean a_isSimple) { + m_isSimple = a_isSimple; + } + + public void addInstruction(int a_value) { + m_instructions.add(a_value); + } + + public int getInstruction(int a_index) { + return m_instructions.get(a_index); + } + + public int getNumOfInstructions() { + return m_instructions.size(); + } + + public void addFlag(int a_value) { + m_flags.add(a_value); + } + + public int getFlag(int a_index) { + return m_flags.get(a_index); + } + + public int getNumOfFlags() { + return m_flags.size(); + } + + public void addPoint(Point a_value) { + m_points.add(a_value); + updateMinMax(a_value); + } + + private void updateMinMax(Point a_value) { + if (m_max == null) { + m_max = new Point(a_value); + } + + if (m_min == null) { + m_min = new Point(a_value); + } + + if (a_value.x > m_max.x) { + m_max.x = a_value.x; + } + + if (a_value.x < m_min.x) { + m_min.x = a_value.x; + } + + if (a_value.y > m_max.y) { + m_max.y = a_value.y; + } + + if (a_value.y < m_min.y) { + m_min.y = a_value.y; + } + } + + public Point getPoint(int a_index) { + return m_points.get(a_index); + } + + public int getNumOfPoints() { + return m_points.size(); + } + + public int getLastIndex() { + return m_points.size() - 1; + } + + public void addGlyfIndex(int a_value) { + m_glyfIndeces.add(a_value); + } + + public int getGlyfIndex(int a_index) { + return m_glyfIndeces.get(a_index); + } + + public void addArg1(int a_value) { + m_arg1s.add(a_value); + } + + public int getArg1(int a_index) { + return m_arg1s.get(a_index); + } + + public void addArg2(int a_value) { + m_arg2s.add(a_value); + } + + public int getArg2(int a_index) { + return m_arg2s.get(a_index); + } + + public int getNumOfCompositePoints() { + if (isSimple()) { + return getNumOfPoints(); + } else { + return m_numOfCompositePoints; + } + } + + public void setNumOfCompositePoints(int a_value) { + m_numOfCompositePoints = a_value; + } + + public int getNumOfCompositeContours() { + if (isSimple()) { + return getNumOfContours(); + } else { + return m_numOfCompositeContours; + } + } + + public void setNumOfCompositeContours(int a_value) { + m_numOfCompositeContours = a_value; + } + + public int getComponentDepth() { + if (isSimple()) { + return 0; + } else { + return m_componentDepth; + } + } + + public void setComponentDepth(int a_value) { + m_componentDepth = a_value; + } + + public int getLeftSideBearing() { + return getMin().x; + } + + public int getRightSideBearing() { + return getAdvanceWidth() - getMax().x; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTName.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTName.java index 659712f16..4fe4be223 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTName.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTName.java @@ -1,93 +1,105 @@ -/* - * $Id: TTName.java,v 1.2 2005/01/21 05:37:26 eed3si9n Exp $ - * - * $Copyright: copyright (c) 2004, e.e d3si9n $ - * $License: - * This source code is part of DoubleType. - * DoubleType is a graphical typeface designer. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, e.e d3si9n gives permission to - * link the code of this program with any Java Platform that is available - * to public with free of charge, including but not limited to - * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), - * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, - * you may extend this exception to your version of the file, but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. - * $ - */ - -package org.doubletype.ossa.truetype; - -public class TTName { - public static final int k_unicode = 0; - public static final int k_unicodeDefaultEncode = 0; - - public static final int k_macintosh = 1; - public static final int k_macRomanEncode = 0; - public static final int k_macEnglishLang = 0; - - public static final int k_microsoft = 3; - public static final int k_winSymbolEncode = 0; - public static final int k_winUnicodeEncode = 1; - public static final int k_winShiftJisEncode = 2; - public static final int k_winEnglishLang = 0x409; - private int m_platformId; - private int m_encodingId; - private int m_languageId; - private int m_nameId; - private byte m_bytes[]; - - public TTName(int a_platformId, - int a_encodingId, - int a_languageId, - int a_nameId, - byte a_bytes[]) { - m_platformId = a_platformId; - m_encodingId = a_encodingId; - m_languageId = a_languageId; - m_nameId = a_nameId; - m_bytes = a_bytes; - } - - public int getPlatformId() { - return m_platformId; - } - - public int getEncodingId() { - return m_encodingId; - } - - public int getLanguageId() { - return m_languageId; - } - - public int getNameId() { - return m_nameId; - } - - // BUGFIX 958996 - public byte[] getBytes() { - return m_bytes; - } - - public int getStringLength() { - return m_bytes.length; - } -} +/* + * $Id: TTName.java,v 1.2 2005/01/21 05:37:26 eed3si9n Exp $ + * + * $Copyright: copyright (c) 2004, e.e d3si9n $ + * $License: + * This source code is part of DoubleType. + * DoubleType is a graphical typeface designer. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, e.e d3si9n gives permission to + * link the code of this program with any Java Platform that is available + * to public with free of charge, including but not limited to + * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), + * and distribute linked combinations including the two. + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, + * you may extend this exception to your version of the file, but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. + * $ + */ +package org.doubletype.ossa.truetype; + +public class TTName { + + public static final int k_unicode = 0; + + public static final int k_unicodeDefaultEncode = 0; + + public static final int k_macintosh = 1; + + public static final int k_macRomanEncode = 0; + + public static final int k_macEnglishLang = 0; + + public static final int k_microsoft = 3; + + public static final int k_winSymbolEncode = 0; + + public static final int k_winUnicodeEncode = 1; + + public static final int k_winShiftJisEncode = 2; + + public static final int k_winEnglishLang = 0x409; + + private int m_platformId; + + private int m_encodingId; + + private int m_languageId; + + private int m_nameId; + + private byte m_bytes[]; + + public TTName(int a_platformId, + int a_encodingId, + int a_languageId, + int a_nameId, + byte a_bytes[]) { + m_platformId = a_platformId; + m_encodingId = a_encodingId; + m_languageId = a_languageId; + m_nameId = a_nameId; + m_bytes = a_bytes; + } + + public int getPlatformId() { + return m_platformId; + } + + public int getEncodingId() { + return m_encodingId; + } + + public int getLanguageId() { + return m_languageId; + } + + public int getNameId() { + return m_nameId; + } + + // BUGFIX 958996 + public byte[] getBytes() { + return m_bytes; + } + + public int getStringLength() { + return m_bytes.length; + } +} diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTPixelSize.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTPixelSize.java index a417d40f3..1e731507d 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTPixelSize.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTPixelSize.java @@ -3,105 +3,112 @@ package org.doubletype.ossa.truetype; import java.util.ArrayList; public class TTPixelSize { - static private int s_em = 1024; - static private boolean s_isInitialized = false; - static private ArrayList s_list = new ArrayList<>(); - - static public int getEm() { - return s_em; - } - - static public ArrayList getList() { - initList(); - return s_list; - } - - static private void initList() { - if (s_isInitialized) - return; - - s_isInitialized = true; - - // s_list.add(new TTPixelSize(9, "9px: 7pt(96dpi)/9pt(72dpi)")); - // s_list.add(new TTPixelSize(10, "10px: 7.5pt(96dpi)/10pt(72dpi)")); - s_list.add(new TTPixelSize(11, "11px: 8pt(96dpi)/11pt(72dpi)")); - s_list.add(new TTPixelSize(12, "12px: 9pt(96dpi)/12pt(72dpi)")); - s_list.add(new TTPixelSize(13, "13px: 10pt(96dpi)/13pt(72dpi)")); - s_list.add(new TTPixelSize(14, "14px: 10.5pt(96dpi)/14pt(72dpi)")); - s_list.add(new TTPixelSize(15, "15px: 11pt(96dpi)/15pt(72dpi)")); - s_list.add(new TTPixelSize(16, "16px: 12pt(96dpi)/16pt(72dpi)")); - s_list.add(new TTPixelSize(17, "17px: 13pt(96dpi)/17pt(72dpi)")); - s_list.add(new TTPixelSize(18, "18px: 13.5pt(96dpi)/18pt(72dpi)")); - s_list.add(new TTPixelSize(19, "19px: 14pt(96dpi)/14pt(72dpi)")); - s_list.add(new TTPixelSize(20, "20px: 15pt(96dpi)/20pt(72dpi)")); - s_list.add(new TTPixelSize(21, "21px: 16pt(96dpi)/21pt(72dpi)")); - s_list.add(new TTPixelSize(22, "22px: 16.5pt(96dpi)/22pt(72dpi)")); - s_list.add(new TTPixelSize(23, "23px: 17pt(96dpi)/23pt(72dpi)")); - s_list.add(new TTPixelSize(24, "24px: 18pt(96dpi)/24pt(72dpi)")); - s_list.add(new TTPixelSize(27, "27px: 20pt(96dpi)")); - s_list.add(new TTPixelSize(29, "29px: 22pt(96dpi)")); - s_list.add(new TTPixelSize(32, "32px: 24pt(96dpi)")); - s_list.add(new TTPixelSize(33, "33px: 8pt(300dpi) ")); - // s_list.add(new TTPixelSize(35, "35px: 26pt(96dpi) ")); - s_list.add(new TTPixelSize(37, "37px: 28pt(96dpi)")); - // s_list.add(new TTPixelSize(38, "38px: 9pt(300dpi)"); - s_list.add(new TTPixelSize(42, "42px: 10pt(300dpi)")); - // s_list.add(new TTPixelSize(44, "44px: 10.5pt(300dpi)")); - s_list.add(new TTPixelSize(46, "46px: 11pt(300dpi)")); - s_list.add(new TTPixelSize(50, "50px: 12pt(300dpi)")); - s_list.add(new TTPixelSize(54, "54px: 13pt(300dpi)")); - s_list.add(new TTPixelSize(58, "58px: 14pt(300dpi)")); - s_list.add(new TTPixelSize(67, "67px: 16pt(300dpi)")); - s_list.add(new TTPixelSize(75, "75px: 18pt(300dpi)")); - s_list.add(new TTPixelSize(83, "83px: 20pt(300dpi)")); - s_list.add(new TTPixelSize(92, "92px: 22pt(300dpi)")); - s_list.add(new TTPixelSize(100, "100px: 24pt(300dpi)")); - } - - private int m_pixel; - private String m_description; - private int m_pixelWidths[]; - private int m_maxPixelWidth = 0; - - public TTPixelSize(int a_pixel, String a_description) - { - m_pixel = a_pixel; - m_description = a_description; - } - - public int getPixel() { - return m_pixel; - } - - public String getDescription() { - return m_description; - } - - /** - * sets the size of the pixel widths. Use num of glyphs. - * @param a_size - */ - public void setPixelWidthsSize(int a_size) { - m_pixelWidths = new int[a_size]; - m_maxPixelWidth = 0; - } - - public void setPixelWidth(int a_glyphIndex, int a_value) { - m_pixelWidths[a_glyphIndex] = a_value; - if (a_value > m_maxPixelWidth) { - m_maxPixelWidth = a_value; - } - } - - public int [] getPixelWidths() { - return m_pixelWidths; - } - - public int getPixelWidth(int a_glyphIndex) { - return m_pixelWidths[a_glyphIndex]; - } - - public int getMaxPixelWidth() { - return m_maxPixelWidth; - } + + static private int s_em = 1024; + + static private boolean s_isInitialized = false; + + static private ArrayList s_list = new ArrayList<>(); + + static public int getEm() { + return s_em; + } + + static public ArrayList getList() { + initList(); + return s_list; + } + + static private void initList() { + if (s_isInitialized) { + return; + } + + s_isInitialized = true; + + // s_list.add(new TTPixelSize(9, "9px: 7pt(96dpi)/9pt(72dpi)")); + // s_list.add(new TTPixelSize(10, "10px: 7.5pt(96dpi)/10pt(72dpi)")); + s_list.add(new TTPixelSize(11, "11px: 8pt(96dpi)/11pt(72dpi)")); + s_list.add(new TTPixelSize(12, "12px: 9pt(96dpi)/12pt(72dpi)")); + s_list.add(new TTPixelSize(13, "13px: 10pt(96dpi)/13pt(72dpi)")); + s_list.add(new TTPixelSize(14, "14px: 10.5pt(96dpi)/14pt(72dpi)")); + s_list.add(new TTPixelSize(15, "15px: 11pt(96dpi)/15pt(72dpi)")); + s_list.add(new TTPixelSize(16, "16px: 12pt(96dpi)/16pt(72dpi)")); + s_list.add(new TTPixelSize(17, "17px: 13pt(96dpi)/17pt(72dpi)")); + s_list.add(new TTPixelSize(18, "18px: 13.5pt(96dpi)/18pt(72dpi)")); + s_list.add(new TTPixelSize(19, "19px: 14pt(96dpi)/14pt(72dpi)")); + s_list.add(new TTPixelSize(20, "20px: 15pt(96dpi)/20pt(72dpi)")); + s_list.add(new TTPixelSize(21, "21px: 16pt(96dpi)/21pt(72dpi)")); + s_list.add(new TTPixelSize(22, "22px: 16.5pt(96dpi)/22pt(72dpi)")); + s_list.add(new TTPixelSize(23, "23px: 17pt(96dpi)/23pt(72dpi)")); + s_list.add(new TTPixelSize(24, "24px: 18pt(96dpi)/24pt(72dpi)")); + s_list.add(new TTPixelSize(27, "27px: 20pt(96dpi)")); + s_list.add(new TTPixelSize(29, "29px: 22pt(96dpi)")); + s_list.add(new TTPixelSize(32, "32px: 24pt(96dpi)")); + s_list.add(new TTPixelSize(33, "33px: 8pt(300dpi) ")); + // s_list.add(new TTPixelSize(35, "35px: 26pt(96dpi) ")); + s_list.add(new TTPixelSize(37, "37px: 28pt(96dpi)")); + // s_list.add(new TTPixelSize(38, "38px: 9pt(300dpi)"); + s_list.add(new TTPixelSize(42, "42px: 10pt(300dpi)")); + // s_list.add(new TTPixelSize(44, "44px: 10.5pt(300dpi)")); + s_list.add(new TTPixelSize(46, "46px: 11pt(300dpi)")); + s_list.add(new TTPixelSize(50, "50px: 12pt(300dpi)")); + s_list.add(new TTPixelSize(54, "54px: 13pt(300dpi)")); + s_list.add(new TTPixelSize(58, "58px: 14pt(300dpi)")); + s_list.add(new TTPixelSize(67, "67px: 16pt(300dpi)")); + s_list.add(new TTPixelSize(75, "75px: 18pt(300dpi)")); + s_list.add(new TTPixelSize(83, "83px: 20pt(300dpi)")); + s_list.add(new TTPixelSize(92, "92px: 22pt(300dpi)")); + s_list.add(new TTPixelSize(100, "100px: 24pt(300dpi)")); + } + + private int m_pixel; + + private String m_description; + + private int m_pixelWidths[]; + + private int m_maxPixelWidth = 0; + + public TTPixelSize(int a_pixel, String a_description) { + m_pixel = a_pixel; + m_description = a_description; + } + + public int getPixel() { + return m_pixel; + } + + public String getDescription() { + return m_description; + } + + /** + * sets the size of the pixel widths. Use num of glyphs. + * + * @param a_size + */ + public void setPixelWidthsSize(int a_size) { + m_pixelWidths = new int[a_size]; + m_maxPixelWidth = 0; + } + + public void setPixelWidth(int a_glyphIndex, int a_value) { + m_pixelWidths[a_glyphIndex] = a_value; + if (a_value > m_maxPixelWidth) { + m_maxPixelWidth = a_value; + } + } + + public int[] getPixelWidths() { + return m_pixelWidths; + } + + public int getPixelWidth(int a_glyphIndex) { + return m_pixelWidths[a_glyphIndex]; + } + + public int getMaxPixelWidth() { + return m_maxPixelWidth; + } } diff --git a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java index 95e5c8df1..2e4e0a0e3 100644 --- a/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java +++ b/libsrc/ttf/src/org/doubletype/ossa/truetype/TTUnicodeRange.java @@ -1,8 +1,8 @@ /* * $Id: TTUnicodeRange.java,v 1.1 2004/01/25 11:00:10 eed3si9n Exp $ - * + * * $Copyright: copyright (c) 2003-2004, e.e d3si9n $ - * $License: + * $License: * This source code is part of DoubleType. * DoubleType is a graphical typeface designer. * @@ -25,356 +25,357 @@ * to public with free of charge, including but not limited to * Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE), * and distribute linked combinations including the two. - * You must obey the GNU General Public License in all respects for all - * of the code used other than Java Platform. If you modify this file, + * You must obey the GNU General Public License in all respects for all + * of the code used other than Java Platform. If you modify this file, * you may extend this exception to your version of the file, but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. * $ */ - package org.doubletype.ossa.truetype; -import java.util.*; - import java.lang.Character.UnicodeBlock; +import java.util.ArrayList; /** * @author e.e */ public class TTUnicodeRange implements Comparable { - public static final long k_notDef = 0x0001; - public static final long k_null = 0x0000; - public static final long k_cr = 0x000D; - public static final long k_space = 0x0020; - - static private boolean s_isInitialized = false; - static private ArrayList s_list = new ArrayList<>(); - static private TTUnicodeRange s_selected = null; - - static public TTUnicodeRange of(long a_unicode) { - initList(); - - TTUnicodeRange retval = null; - UnicodeBlock block = UnicodeBlock.of((int)a_unicode); - if (block == null) - return retval; - - int i; - for (i = 0; i < s_list.size(); i++) { - TTUnicodeRange range = s_list.get(i); - if (range.m_block.equals(block)) { - return range; - } - } - - return retval; - } - - static public TTUnicodeRange getLastFound() { - return s_selected; - } - - static private void initList() { - if (s_isInitialized) - return; - - s_isInitialized = true; - - s_list.add(new TTUnicodeRange( - UnicodeBlock.BASIC_LATIN, 0x0020, 0x007F, 0, 63)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_1_SUPPLEMENT, 0x0080, 0x00FF, 1, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_A, 0x0100, 0x017f, 2)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_B, 0x0180, 0x024f, 3)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.IPA_EXTENSIONS, 0x0250, 0x02af, 4)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SPACING_MODIFIER_LETTERS, 0x02B0, 0x02FF, 5)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_DIACRITICAL_MARKS, 0x0300, 0x036F, 6)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GREEK, 0x0370, 0x03FF, 7, 3)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CYRILLIC, 0x0400, 0x04FF, 9, 2)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARMENIAN, 0x0530, 0x058F, 10)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HEBREW, 0x0590, 0x05FF, 11, 5)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC, 0x0600, 0x06FF, 13, 6)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SYRIAC, 0x0700, 0x074F, 71)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.THAANA, 0x0780, 0x07BF, 72)); - - s_list.add(new TTUnicodeRange( - UnicodeBlock.DEVANAGARI, 0x0900, 0x097F, 15)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BENGALI, 0x0980, 0x09FF, 16)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GURMUKHI, 0x0A00, 0x0A7F, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GUJARATI, 0x0A80, 0x0AFF, 18)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ORIYA, 0x0B00, 0x0B7F, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TAMIL, 0x0B80, 0x0BFF, 20)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TELUGU, 0x0C00, 0x0C7F, 21)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANNADA, 0x0C80, 0x0CFF, 22)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MALAYALAM, 0x0D00, 0x0D7F, 23)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SINHALA, 0x0D80, 0x0DFF, 73)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.THAI, 0x0E00, 0x0E7F, 24, 16)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LAO, 0x0E80, 0x0EFF, 25)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.TIBETAN, 0x0F00, 0x0FFF, 70)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MYANMAR, 0x1000, 0x109F, 74)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GEORGIAN, 0x10A0, 0x10FF, 26)); - // TODO: wansung or johab? - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_JAMO, 0x1100, 0x11FF, 28, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ETHIOPIC, 0x1200, 0x137F, 75)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CHEROKEE, 0x13A0, 0x13FF, 76)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, 0x1400, 0x167F, 77)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.OGHAM, 0x1680, 0x169F, 78)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.RUNIC, 0x16A0, 0x16FF, 79)); - + + public static final long k_notDef = 0x0001; + + public static final long k_null = 0x0000; + + public static final long k_cr = 0x000D; + + public static final long k_space = 0x0020; + + static private boolean s_isInitialized = false; + + static private ArrayList s_list = new ArrayList<>(); + + static private TTUnicodeRange s_selected = null; + + static public TTUnicodeRange of(long a_unicode) { + initList(); + + TTUnicodeRange retval = null; + UnicodeBlock block = UnicodeBlock.of((int) a_unicode); + if (block == null) { + return retval; + } + + int i; + for (i = 0; i < s_list.size(); i++) { + TTUnicodeRange range = s_list.get(i); + if (range.m_block.equals(block)) { + return range; + } + } + + return retval; + } + + static public TTUnicodeRange getLastFound() { + return s_selected; + } + + static private void initList() { + if (s_isInitialized) { + return; + } + + s_isInitialized = true; + + s_list.add(new TTUnicodeRange( + UnicodeBlock.BASIC_LATIN, 0x0020, 0x007F, 0, 63)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_1_SUPPLEMENT, 0x0080, 0x00FF, 1, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_A, 0x0100, 0x017f, 2)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_B, 0x0180, 0x024f, 3)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.IPA_EXTENSIONS, 0x0250, 0x02af, 4)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SPACING_MODIFIER_LETTERS, 0x02B0, 0x02FF, 5)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_DIACRITICAL_MARKS, 0x0300, 0x036F, 6)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GREEK, 0x0370, 0x03FF, 7, 3)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CYRILLIC, 0x0400, 0x04FF, 9, 2)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARMENIAN, 0x0530, 0x058F, 10)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HEBREW, 0x0590, 0x05FF, 11, 5)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC, 0x0600, 0x06FF, 13, 6)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SYRIAC, 0x0700, 0x074F, 71)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.THAANA, 0x0780, 0x07BF, 72)); + + s_list.add(new TTUnicodeRange( + UnicodeBlock.DEVANAGARI, 0x0900, 0x097F, 15)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BENGALI, 0x0980, 0x09FF, 16)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GURMUKHI, 0x0A00, 0x0A7F, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GUJARATI, 0x0A80, 0x0AFF, 18)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ORIYA, 0x0B00, 0x0B7F, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TAMIL, 0x0B80, 0x0BFF, 20)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TELUGU, 0x0C00, 0x0C7F, 21)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANNADA, 0x0C80, 0x0CFF, 22)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MALAYALAM, 0x0D00, 0x0D7F, 23)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SINHALA, 0x0D80, 0x0DFF, 73)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.THAI, 0x0E00, 0x0E7F, 24, 16)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LAO, 0x0E80, 0x0EFF, 25)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.TIBETAN, 0x0F00, 0x0FFF, 70)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MYANMAR, 0x1000, 0x109F, 74)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GEORGIAN, 0x10A0, 0x10FF, 26)); + // TODO: wansung or johab? + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_JAMO, 0x1100, 0x11FF, 28, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ETHIOPIC, 0x1200, 0x137F, 75)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CHEROKEE, 0x13A0, 0x13FF, 76)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, 0x1400, 0x167F, 77)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.OGHAM, 0x1680, 0x169F, 78)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.RUNIC, 0x16A0, 0x16FF, 79)); + // TODO: tagalog, hanunoo, buhid, tagbanwa - - s_list.add(new TTUnicodeRange( - UnicodeBlock.KHMER, 0x1780, 0x17FF, 80)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MONGOLIAN, 0x1800, 0x18AF, 81)); - - // linbu, tai le, khmer symbol, phonetic extensions, - - s_list.add(new TTUnicodeRange( - UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, 0x1E00, 0x1EFF, 29)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GREEK_EXTENDED, 0x1F00, 0x1FFF, 30)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GENERAL_PUNCTUATION, 0x2000, 0x206F, 31)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, 0x2070, 0x209F, 32)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CURRENCY_SYMBOLS, 0x20A0, 0x20CF, 33)); - - // combining diacritical marks - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, 0x20D0, 0x20FF, 34)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LETTERLIKE_SYMBOLS, 0x2100, 0x214F, 35)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.NUMBER_FORMS, 0x2150, 0x218F, 36)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARROWS, 0x2190, 0x21FF, 37)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MATHEMATICAL_OPERATORS, 0x2200, 0x22FF, 38)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MISCELLANEOUS_TECHNICAL, 0x2300, 0x23FF, 39)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CONTROL_PICTURES, 0x2400, 0x243F, 40)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, 0x2440, 0x245F, 41)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ENCLOSED_ALPHANUMERICS, 0x2460, 0x24FF, 42)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOX_DRAWING, 0x2500, 0x257F, 43)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BLOCK_ELEMENTS, 0x2580, 0x259F, 44)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.GEOMETRIC_SHAPES, 0x25A0, 0x25FF, 45)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.MISCELLANEOUS_SYMBOLS, 0x2600, 0x26FF, 46)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.DINGBATS, 0x2700, 0x27BF, 47)); - - // TODO: mics. math symbols A, supplemental arrows A - - s_list.add(new TTUnicodeRange( - UnicodeBlock.BRAILLE_PATTERNS, 0x2800, 0x28FF, 82)); - + s_list.add(new TTUnicodeRange( + UnicodeBlock.KHMER, 0x1780, 0x17FF, 80)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MONGOLIAN, 0x1800, 0x18AF, 81)); + + // linbu, tai le, khmer symbol, phonetic extensions, + s_list.add(new TTUnicodeRange( + UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, 0x1E00, 0x1EFF, 29)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GREEK_EXTENDED, 0x1F00, 0x1FFF, 30)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GENERAL_PUNCTUATION, 0x2000, 0x206F, 31)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, 0x2070, 0x209F, 32)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CURRENCY_SYMBOLS, 0x20A0, 0x20CF, 33)); + + // combining diacritical marks + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, 0x20D0, 0x20FF, 34)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LETTERLIKE_SYMBOLS, 0x2100, 0x214F, 35)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.NUMBER_FORMS, 0x2150, 0x218F, 36)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARROWS, 0x2190, 0x21FF, 37)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MATHEMATICAL_OPERATORS, 0x2200, 0x22FF, 38)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MISCELLANEOUS_TECHNICAL, 0x2300, 0x23FF, 39)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CONTROL_PICTURES, 0x2400, 0x243F, 40)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, 0x2440, 0x245F, 41)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ENCLOSED_ALPHANUMERICS, 0x2460, 0x24FF, 42)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOX_DRAWING, 0x2500, 0x257F, 43)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BLOCK_ELEMENTS, 0x2580, 0x259F, 44)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.GEOMETRIC_SHAPES, 0x25A0, 0x25FF, 45)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.MISCELLANEOUS_SYMBOLS, 0x2600, 0x26FF, 46)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.DINGBATS, 0x2700, 0x27BF, 47)); + + // TODO: mics. math symbols A, supplemental arrows A + s_list.add(new TTUnicodeRange( + UnicodeBlock.BRAILLE_PATTERNS, 0x2800, 0x28FF, 82)); + // TODO: supplemental arrows B, mics. math symbols B, - // supplemental math op., mics. symbols and arrows - - -// CJKV supplements - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_RADICALS_SUPPLEMENT, 0x2E80, 0x2EFF, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANGXI_RADICALS, 0x2F00, 0x2FDF, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, 0x2FF0, 0x2FFF, 59)); + // supplemental math op., mics. symbols and arrows +// CJKV supplements + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_RADICALS_SUPPLEMENT, 0x2E80, 0x2EFF, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANGXI_RADICALS, 0x2F00, 0x2FDF, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, 0x2FF0, 0x2FFF, 59)); - - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, 0x3000, 0x303f, 48)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIRAGANA, 0x3040, 0x309f, 49, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KATAKANA, 0x30a0, 0x30ff, 50, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOPOMOFO, 0x3100, 0x312f, 51)); - // TODO: wansung or johab? - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, 0x3130, 0x0318F, 52, 19)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KANBUN, 0x3190, 0x319F, 59)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.BOPOMOFO_EXTENDED, 0x31A0, 0x31BF, 51)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, 0x31F0, 0x31FF, 50, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, 0x3200, 0x32FF, 54)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY, 0x3300, 0x33ff, 55)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, 0x03400, 0x4dbf, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, 0x3000, 0x303f, 48)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIRAGANA, 0x3040, 0x309f, 49, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KATAKANA, 0x30a0, 0x30ff, 50, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOPOMOFO, 0x3100, 0x312f, 51)); + // TODO: wansung or johab? + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, 0x3130, 0x0318F, 52, 19)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KANBUN, 0x3190, 0x319F, 59)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.BOPOMOFO_EXTENDED, 0x31A0, 0x31BF, 51)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, 0x31F0, 0x31FF, 50, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, 0x3200, 0x32FF, 54)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY, 0x3300, 0x33ff, 55)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, 0x03400, 0x4dbf, 59)); // TODO: yijing hex symbols - - // the kanji characters - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, 0x4e00, 0x9fff, 59, 17)); - - s_list.add(new TTUnicodeRange( - UnicodeBlock.YI_SYLLABLES, 0xA000, 0xA48F, 83)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.YI_RADICALS, 0xA490, 0xA4CF, 83)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HANGUL_SYLLABLES, 0xAC00, 0xD7AF, 56)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIGH_SURROGATES, 0xD800, 0xDB7F, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, 0xDB80, 0xDBFF, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.LOW_SURROGATES, 0xDC00, 0xDFFF, 0)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.PRIVATE_USE_AREA, 0xE000, 0xF8FF, 60)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, 0xf900, 0xfaff, 61)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, 0xFB00, 0xFB4F, 62)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, 0xFB50, 0xFDFF, 62)); - - // TODO: variation selectors - - s_list.add(new TTUnicodeRange( - UnicodeBlock.COMBINING_HALF_MARKS, 0xFE20, 0xFE2F, 64)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.CJK_COMPATIBILITY_FORMS, 0xFE30, 0xFE4F, 65)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SMALL_FORM_VARIANTS, 0xFE50, 0xFE6F, 66)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, 0xFE70, 0xFEFF, 67)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, 0xFF00, 0xFFEF, 68, 17)); - s_list.add(new TTUnicodeRange( - UnicodeBlock.SPECIALS, 0xFFF0, 0xFFFF, 69)); - } - - static public boolean find(String a_unicodeRange) { - initList(); - - s_selected = null; - - int i; - for (i = 0; i < s_list.size(); i++) { - TTUnicodeRange range = (TTUnicodeRange) s_list.get(i); - if (range.m_block.toString().equals(a_unicodeRange)) { - s_selected = range; - - return true; - } - } - - return false; - } - - private UnicodeBlock m_block = null; - private long m_start = 0; - private long m_end = 0; - - /** http://www.microsoft.com/typography/otspec/os2.htm - */ - private int m_osTwoFlag = 0; - - /** http://www.microsoft.com/typography/otspec/os2.htm - */ - private int m_codePageFlag = 0; - - public TTUnicodeRange(UnicodeBlock a_block, - long a_start, - long a_end, - int a_osTwoFlag) - { - m_block = a_block; - m_start = a_start; - m_end = a_end; - m_osTwoFlag = a_osTwoFlag; - } - - public TTUnicodeRange(UnicodeBlock a_block, - long a_start, - long a_end, - int a_osTwoFlag, - int a_codePageFlag) - { - m_block = a_block; - m_start = a_start; - m_end = a_end; - m_osTwoFlag = a_osTwoFlag; - m_codePageFlag = a_codePageFlag; - } - - public boolean equals(Object a_object) { - TTUnicodeRange object = (TTUnicodeRange) a_object; - return (m_start == object.m_start); - } - - public int compareTo(TTUnicodeRange a_object) { - TTUnicodeRange object = a_object; - if (this.m_start < object.m_start) { - return -1; - } else if (this.m_start == object.m_start) { - return 0; - } else - return 1; - } - - public String toString() { - return m_block.toString(); - } - - public long getStartCode() { - return m_start; - } - - public long getEndCode() { - return m_end; - } - - public int getOsTwoFlag() { - return m_osTwoFlag; - } - - public int getCodeRangeFlag() { - return m_codePageFlag; - } + // the kanji characters + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, 0x4e00, 0x9fff, 59, 17)); + + s_list.add(new TTUnicodeRange( + UnicodeBlock.YI_SYLLABLES, 0xA000, 0xA48F, 83)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.YI_RADICALS, 0xA490, 0xA4CF, 83)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HANGUL_SYLLABLES, 0xAC00, 0xD7AF, 56)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIGH_SURROGATES, 0xD800, 0xDB7F, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, 0xDB80, 0xDBFF, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.LOW_SURROGATES, 0xDC00, 0xDFFF, 0)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.PRIVATE_USE_AREA, 0xE000, 0xF8FF, 60)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, 0xf900, 0xfaff, 61)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, 0xFB00, 0xFB4F, 62)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, 0xFB50, 0xFDFF, 62)); + + // TODO: variation selectors + s_list.add(new TTUnicodeRange( + UnicodeBlock.COMBINING_HALF_MARKS, 0xFE20, 0xFE2F, 64)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.CJK_COMPATIBILITY_FORMS, 0xFE30, 0xFE4F, 65)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SMALL_FORM_VARIANTS, 0xFE50, 0xFE6F, 66)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, 0xFE70, 0xFEFF, 67)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, 0xFF00, 0xFFEF, 68, 17)); + s_list.add(new TTUnicodeRange( + UnicodeBlock.SPECIALS, 0xFFF0, 0xFFFF, 69)); + } + + static public boolean find(String a_unicodeRange) { + initList(); + + s_selected = null; + + int i; + for (i = 0; i < s_list.size(); i++) { + TTUnicodeRange range = (TTUnicodeRange) s_list.get(i); + if (range.m_block.toString().equals(a_unicodeRange)) { + s_selected = range; + + return true; + } + } + + return false; + } + + private UnicodeBlock m_block = null; + + private long m_start = 0; + + private long m_end = 0; + + /** + * http://www.microsoft.com/typography/otspec/os2.htm + */ + private int m_osTwoFlag = 0; + + /** + * http://www.microsoft.com/typography/otspec/os2.htm + */ + private int m_codePageFlag = 0; + + public TTUnicodeRange(UnicodeBlock a_block, + long a_start, + long a_end, + int a_osTwoFlag) { + m_block = a_block; + m_start = a_start; + m_end = a_end; + m_osTwoFlag = a_osTwoFlag; + } + + public TTUnicodeRange(UnicodeBlock a_block, + long a_start, + long a_end, + int a_osTwoFlag, + int a_codePageFlag) { + m_block = a_block; + m_start = a_start; + m_end = a_end; + m_osTwoFlag = a_osTwoFlag; + m_codePageFlag = a_codePageFlag; + } + + public boolean equals(Object a_object) { + TTUnicodeRange object = (TTUnicodeRange) a_object; + return (m_start == object.m_start); + } + + public int compareTo(TTUnicodeRange a_object) { + TTUnicodeRange object = a_object; + if (this.m_start < object.m_start) { + return -1; + } else if (this.m_start == object.m_start) { + return 0; + } else { + return 1; + } + } + + public String toString() { + return m_block.toString(); + } + + public long getStartCode() { + return m_start; + } + + public long getEndCode() { + return m_end; + } + + public int getOsTwoFlag() { + return m_osTwoFlag; + } + + public int getCodeRangeFlag() { + return m_codePageFlag; + } }