diff options
author | Sven Gothel <[email protected]> | 2011-03-30 06:59:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-03-30 06:59:43 +0200 |
commit | 55356d999638491980a90cb2263b55c5d2e53e91 (patch) | |
tree | 711457c8b1bedcf1d71fd0ba0252155b2895ce7f /src/jogamp | |
parent | 5f0293b84d0146d9e750ea7e75caaa101ae3b3c3 (diff) |
Font Refactoring ; Misc Changes ; Demo/Test Update
Font Refactoring
- Notion of distributed FontSet
- FontFactory may produce FontSet and/or a Font by absolute ttf file path
- Adding support for free Ubuntu fonts
- Remove Vertex.Factory dependency for Font creation
- Typecast Impl
- Fix CmapTable selection
- Fix horizontal spacing of space
-
Misc Changes
- HwTextRenderer
- Offer reshape for perspective and orthogonal view
- Expose PMVMatrix, allowing user to setup their own view math.
Demo Update
- Dump font set a-zA-Z...
- Dump 'lazy dog ..' text
- Action:
- s: toogle 'font set'
- f: toggle fps
- v: toggle v-sync
- space: toggle font (ubuntu/java)
- formated screenshot filename w/ font name
Test Update:
- add font set iteration
Diffstat (limited to 'src/jogamp')
-rw-r--r-- | src/jogamp/graph/font/FontConstructor.java | 34 | ||||
-rw-r--r-- | src/jogamp/graph/font/FontInt.java | 6 | ||||
-rw-r--r-- | src/jogamp/graph/font/JavaFontLoader.java | 157 | ||||
-rw-r--r-- | src/jogamp/graph/font/UbuntuFontLoader.java | 115 | ||||
-rw-r--r-- | src/jogamp/graph/font/typecast/TypecastFont.java | 148 | ||||
-rw-r--r-- | src/jogamp/graph/font/typecast/TypecastFontConstructor.java (renamed from src/jogamp/graph/font/typecast/TypecastFontFactory.java) | 43 | ||||
-rw-r--r-- | src/jogamp/graph/font/typecast/TypecastHMetrics.java (renamed from src/jogamp/graph/font/typecast/TypecastMetrics.java) | 11 | ||||
-rw-r--r-- | src/jogamp/graph/font/typecast/TypecastRenderer.java | 14 | ||||
-rw-r--r-- | src/jogamp/graph/geom/plane/AffineTransform.java | 7 |
9 files changed, 364 insertions, 171 deletions
diff --git a/src/jogamp/graph/font/FontConstructor.java b/src/jogamp/graph/font/FontConstructor.java new file mode 100644 index 000000000..a382d292e --- /dev/null +++ b/src/jogamp/graph/font/FontConstructor.java @@ -0,0 +1,34 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.graph.font; + +import com.jogamp.graph.font.Font; + +public interface FontConstructor { + Font create(String name); +} diff --git a/src/jogamp/graph/font/FontInt.java b/src/jogamp/graph/font/FontInt.java index c18787723..4d9390da2 100644 --- a/src/jogamp/graph/font/FontInt.java +++ b/src/jogamp/graph/font/FontInt.java @@ -35,6 +35,12 @@ import com.jogamp.graph.font.Font; public interface FontInt extends Font { public interface Glyph extends Font.Glyph { + // reserved special glyph IDs + // http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08#ba57949e + public static final int ID_UNKNOWN = 0; + public static final int ID_CR = 2; + public static final int ID_SPACE = 3; + public Path2D getPath(); // unscaled path public Path2D getPath(float pixelSize); } diff --git a/src/jogamp/graph/font/JavaFontLoader.java b/src/jogamp/graph/font/JavaFontLoader.java index f6954944d..6769a691a 100644 --- a/src/jogamp/graph/font/JavaFontLoader.java +++ b/src/jogamp/graph/font/JavaFontLoader.java @@ -27,85 +27,92 @@ */ package jogamp.graph.font; -public class JavaFontLoader { +import com.jogamp.common.util.IntObjectHashMap; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.font.FontFactory; - static String javaFontPath; - static - { - javaFontPath = System.getProperty("java.home") + "/lib/fonts/"; - } +public class JavaFontLoader implements FontSet { + + final static FontSet fontLoader = new JavaFontLoader(); - public static final int MAX_BITMAP_FONT_SIZE = 120; + public static FontSet get() { + return fontLoader; + } + + final static String availableFontFileNames[] = + { + /* 00 */ "LucidaBrightRegular.ttf", + /* 01 */ "LucidaBrightItalic.ttf", + /* 02 */ "LucidaBrightDemiBold.ttf", + /* 03 */ "LucidaBrightDemiItalic.ttf", + /* 04 */ "LucidaSansRegular.ttf", + /* 05 */ "LucidaSansDemiBold.ttf", + /* 06 */ "LucidaTypewriterRegular.ttf", + /* 07 */ "LucidaTypewriterBold.ttf", + }; + + final String javaFontPath; + + private JavaFontLoader() { + javaFontPath = System.getProperty("java.home") + "/lib/fonts/"; + } - public static final int MONOSPACED = 1; - public static final int SERIF = 2; - public static final int SANSERIF = 3; - public static final int CURSIVE = 4; - public static final int FANTASY = 5; - - final static String availableJavaFontNames[] = - { - "Lucida Bright Regular", - "Lucida Bright Italic", - "Lucida Bright Demibold", - "Lucida Bright Demibold Italic", - "Lucida Sans Regular", - "Lucida Sans Demibold", - "Lucida Sans Typewriter Regular", - "Lucida Sans Typewriter Bold", - }; - static public String[] getAvailableNames() - { - return availableJavaFontNames; - } - - final static String availableJavaFontFileNames[] = - { - "LucidaBrightRegular.ttf", - "LucidaBrightItalic.ttf", - "LucidaBrightDemiBold.ttf", - "LucidaBrightDemiItalic.ttf", - "LucidaSansRegular.ttf", - "LucidaSansDemiBold.ttf", - "LucidaTypewriterRegular.ttf", - "LucidaTypewriterBold.ttf", - }; + static final IntObjectHashMap fontMap = new IntObjectHashMap(); + + public Font getDefault() { + return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular + } + + public Font get(int family, int style) { + Font font = (Font)fontMap.get( ( family << 8 ) | style ); + if (font != null) { + return font; + } - static public String get(int type) - { - String font = null; - - switch (type) - { - case MONOSPACED: - font = getByName("Lucida Sans Typewriter Regular"); - break; - case SERIF: - font = getByName("Lucida Bright Regular"); - break; - case SANSERIF: - font = getByName("Lucida Sans Regular"); - break; - case CURSIVE: - font = getByName("Lucida Bright Regular"); - break; - case FANTASY: - font = getByName("Lucida Sans Regular"); - break; - } + // 1st process Sans Serif (2 fonts) + if( 0 == ( style & STYLE_SERIF ) ) { + if( 0 != ( style & STYLE_BOLD ) ) { + font = abspath(availableFontFileNames[5]); + } else { + font = abspath(availableFontFileNames[4]); + } + return font; + } + + // Serif Fonts .. + switch (family) { + case FAMILY_LIGHT: + case FAMILY_MEDIUM: + case FAMILY_CONDENSED: + case FAMILY_REGULAR: + if( 0 != ( style & STYLE_BOLD ) ) { + if( 0 != ( style & STYLE_ITALIC ) ) { + font = abspath(availableFontFileNames[3]); + } else { + font = abspath(availableFontFileNames[2]); + } + } else if( 0 != ( style & STYLE_ITALIC ) ) { + font = abspath(availableFontFileNames[1]); + } else { + font = abspath(availableFontFileNames[0]); + } + break; + + case FAMILY_MONOSPACED: + if( 0 != ( style & STYLE_BOLD ) ) { + font = abspath(availableFontFileNames[7]); + } else { + font = abspath(availableFontFileNames[6]); + } + break; + } - return font; - } + return font; + } + + Font abspath(String fname) { + return FontFactory.getFontConstr().create(javaFontPath+fname); + } - static public String getByName(String name) - { - for (int i=0; i<availableJavaFontNames.length; i++) - { - if (name.equals(availableJavaFontNames[i]) == true) - { - return javaFontPath+availableJavaFontFileNames[i]; - } - } - return null; - } } diff --git a/src/jogamp/graph/font/UbuntuFontLoader.java b/src/jogamp/graph/font/UbuntuFontLoader.java new file mode 100644 index 000000000..77d2cea03 --- /dev/null +++ b/src/jogamp/graph/font/UbuntuFontLoader.java @@ -0,0 +1,115 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.graph.font; + +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.opengl.util.Locator; + +public class UbuntuFontLoader implements FontSet { + + final static FontSet fontLoader = new UbuntuFontLoader(); + + public static FontSet get() { + return fontLoader; + } + + final static String availableFontFileNames[] = + { + /* 00 */ "Ubuntu-R.ttf", // regular + /* 01 */ "Ubuntu-RI.ttf", // regular italic + /* 02 */ "Ubuntu-B.ttf", // bold + /* 03 */ "Ubuntu-BI.ttf", // bold italic + /* 04 */ "Ubuntu-L.ttf", // light + /* 05 */ "Ubuntu-LI.ttf", // light italic + /* 06 */ "Ubuntu-M.ttf", // medium + /* 07 */ "Ubuntu-MI.ttf", // medium italic + + }; + + final static String relPath = "fonts/ubuntu/" ; + + private UbuntuFontLoader() { + } + + static boolean is(int bits, int bit) { + return 0 != ( bits & bit ) ; + } + + public Font getDefault() { + return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular + } + + public Font get(int family, int style) + { + Font font = null; + + switch (family) { + case FAMILY_MONOSPACED: + case FAMILY_CONDENSED: + case FAMILY_REGULAR: + if( is(style, STYLE_BOLD) ) { + if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[3]); + } else { + font = abspath(availableFontFileNames[2]); + } + } else if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[1]); + } else { + font = abspath(availableFontFileNames[0]); + } + break; + + case FAMILY_LIGHT: + if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[5]); + } else { + font = abspath(availableFontFileNames[4]); + } + break; + + case FAMILY_MEDIUM: + if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[6]); + } else { + font = abspath(availableFontFileNames[7]); + } + break; + } + + return font; + } + + Font abspath(String fname) { + return FontFactory.getFontConstr().create( + Locator.getResource(UbuntuFontLoader.class, relPath+fname).getPath() ); + } + +} diff --git a/src/jogamp/graph/font/typecast/TypecastFont.java b/src/jogamp/graph/font/typecast/TypecastFont.java index c5e291a55..546eb85e3 100644 --- a/src/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogamp/graph/font/typecast/TypecastFont.java @@ -27,74 +27,92 @@ */ package jogamp.graph.font.typecast; -import java.io.File; -import java.io.IOException; - import jogamp.graph.font.FontInt; -import jogamp.graph.font.JavaFontLoader; import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; import net.java.dev.typecast.ot.OTFont; import net.java.dev.typecast.ot.OTFontCollection; import net.java.dev.typecast.ot.table.CmapFormat; +import net.java.dev.typecast.ot.table.CmapIndexEntry; import net.java.dev.typecast.ot.table.CmapTable; import net.java.dev.typecast.ot.table.HdmxTable; import net.java.dev.typecast.ot.table.ID; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.geom.AABBox; -import com.jogamp.graph.geom.Vertex; class TypecastFont implements FontInt { static final boolean DEBUG = false; - final Vertex.Factory<? extends Vertex> pointFactory; final OTFontCollection fontset; final OTFont font; - TypecastMetrics metrics; + TypecastHMetrics metrics; final CmapFormat cmapFormat; int cmapentries; - // final IntIntHashMap char2Code; IntObjectHashMap char2Glyph; - public static TypecastFont create(Vertex.Factory<? extends Vertex> factory, String name) { - String path = JavaFontLoader.getByName(name); - if(null == path) { - path = name; - } - OTFontCollection fontset; - try { - fontset = OTFontCollection.create(new File(path)); - return new TypecastFont(factory, fontset); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public TypecastFont(Vertex.Factory<? extends Vertex> factory, OTFontCollection fontset) { - this.pointFactory = factory; + public TypecastFont(OTFontCollection fontset) { this.fontset = fontset; this.font = fontset.getFont(0); + // FIXME: Generic attempt to find the best CmapTable, + // which is assumed to be the one with the most entries (stupid 'eh?) CmapTable cmapTable = font.getCmapTable(); - CmapFormat _cmapFormat = null; - /* - if(null == _cmapFormat) { - _cmapFormat = cmapTable.getCmapFormat(ID.platformMacintosh, ID.encodingASCII); - } */ - if(null == _cmapFormat) { - // default unicode - _cmapFormat = cmapTable.getCmapFormat(ID.platformMicrosoft, ID.encodingUnicode); - } - if(null == _cmapFormat) { - // maybe a symbol font ? - _cmapFormat = cmapTable.getCmapFormat(ID.platformMicrosoft, ID.encodingSymbol); - } - if(null == _cmapFormat) { - throw new RuntimeException("Cannot find a suitable cmap table for font "+font); + CmapFormat[] _cmapFormatP = { null, null, null, null }; + int platform = -1; + int platformLength = -1; + int encoding = -1; + for(int i=0; i<cmapTable.getNumTables(); i++) { + CmapIndexEntry cmapIdxEntry = cmapTable.getCmapIndexEntry(i); + int pidx = cmapIdxEntry.getPlatformId(); + CmapFormat cf = cmapIdxEntry.getFormat(); + if(DEBUG) { + System.err.println("CmapFormat["+i+"]: platform " + pidx + + ", encoding "+cmapIdxEntry.getEncodingId() + ": "+cf); + } + if( _cmapFormatP[pidx] == null || + _cmapFormatP[pidx].getLength() < cf.getLength() ) { + _cmapFormatP[pidx] = cf; + if( cf.getLength() > platformLength ) { + platformLength = cf.getLength() ; + platform = pidx; + encoding = cmapIdxEntry.getEncodingId(); + } + } } - cmapFormat = _cmapFormat; + if(0 <= platform) { + cmapFormat = _cmapFormatP[platform]; + if(DEBUG) { + System.err.println("Selected CmapFormat: platform " + platform + + ", encoding "+encoding + ": "+cmapFormat); + } + } else { + CmapFormat _cmapFormat = null; + /*if(null == _cmapFormat) { + platform = ID.platformMacintosh; + encoding = ID.encodingASCII; + _cmapFormat = cmapTable.getCmapFormat(platform, encoding); + } */ + if(null == _cmapFormat) { + // default unicode + platform = ID.platformMicrosoft; + encoding = ID.encodingUnicode; + _cmapFormat = cmapTable.getCmapFormat((short)platform, (short)encoding); + } + if(null == _cmapFormat) { + // maybe a symbol font ? + platform = ID.platformMicrosoft; + encoding = ID.encodingSymbol; + _cmapFormat = cmapTable.getCmapFormat((short)platform, (short)encoding); + } + if(null == _cmapFormat) { + throw new RuntimeException("Cannot find a suitable cmap table for font "+font); + } + cmapFormat = _cmapFormat; + if(DEBUG) { + System.err.println("Selected CmapFormat (2): platform " + platform + ", encoding "+encoding + ": "+cmapFormat); + } + } cmapentries = 0; for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { @@ -104,21 +122,18 @@ class TypecastFont implements FontInt { if(DEBUG) { System.err.println("num glyphs: "+font.getNumGlyphs()); System.err.println("num cmap entries: "+cmapentries); - } - - /* - char2Code = new IntIntHashMap(cmapentries + cmapentries/4); - for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { - CmapFormat.Range range = cmapFormat.getRange(i); - for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) { - final int code = cmapFormat.mapCharCode(j); - char2Code.put(j, code); - if(code < 50) { - System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code); - } + System.err.println("num cmap ranges: "+cmapFormat.getRangeCount()); + + for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { + CmapFormat.Range range = cmapFormat.getRange(i); + for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) { + final int code = cmapFormat.mapCharCode(j); + if(code < 15) { + System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code); + } + } } } - */ char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4); } @@ -128,7 +143,7 @@ class TypecastFont implements FontInt { public Metrics getMetrics() { if (metrics == null) { - metrics = new TypecastMetrics(this); + metrics = new TypecastHMetrics(this); } return metrics; } @@ -137,15 +152,30 @@ class TypecastFont implements FontInt { TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); if (null == result) { // final short code = (short) char2Code.get(symbol); - final short code = (short) cmapFormat.mapCharCode(symbol); + short code = (short) cmapFormat.mapCharCode(symbol); + if(0 == code && 0 != symbol) { + // reserved special glyph IDs by convention + switch(symbol) { + case ' ': code = Glyph.ID_SPACE; break; + case '\n': code = Glyph.ID_CR; break; + default: code = Glyph.ID_UNKNOWN; + } + } + net.java.dev.typecast.ot.OTGlyph glyph = font.getGlyph(code); - final Path2D path = TypecastRenderer.buildPath(glyph); + if(null == glyph) { + glyph = font.getGlyph(Glyph.ID_UNKNOWN); + } + if(null == glyph) { + throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code); + } + Path2D path = TypecastRenderer.buildPath(glyph); result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path); if(DEBUG) { System.err.println("New glyph: " + (int)symbol + " ( " + (char)symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path); } final HdmxTable hdmx = font.getHdmxTable(); - if (null != hdmx) { + if (null!= result && null != hdmx) { /*if(DEBUG) { System.err.println("hdmx "+hdmx); }*/ @@ -164,7 +194,7 @@ class TypecastFont implements FontInt { } public void getOutline(String string, float pixelSize, AffineTransform transform, Path2D[] result) { - TypecastRenderer.getOutline(pointFactory, this, string, pixelSize, transform, result); + TypecastRenderer.getOutline(this, string, pixelSize, transform, result); } public float getStringWidth(String string, float pixelSize) { diff --git a/src/jogamp/graph/font/typecast/TypecastFontFactory.java b/src/jogamp/graph/font/typecast/TypecastFontConstructor.java index 04559a138..5fb9d32f7 100644 --- a/src/jogamp/graph/font/typecast/TypecastFontFactory.java +++ b/src/jogamp/graph/font/typecast/TypecastFontConstructor.java @@ -27,38 +27,27 @@ */ package jogamp.graph.font.typecast; -import java.util.HashMap; -import java.util.Map; +import java.io.File; +import java.io.IOException; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.Vertex.Factory; -import com.jogamp.graph.geom.Vertex; +import jogamp.graph.font.FontConstructor; +import net.java.dev.typecast.ot.OTFontCollection; -public class TypecastFontFactory implements FontFactory { +import com.jogamp.graph.font.Font; - Map<String, Font> fonts = new HashMap<String, Font>(); - - public Font createFont(Factory<? extends Vertex> factory, String name) { - Font result = fonts.get(name); - if (result == null) { - result = TypecastFont.create(factory, name); - if(result != null) { - fonts.put(name, result); - } - } - return result; - } +public class TypecastFontConstructor implements FontConstructor { - public Font createFont(Factory<? extends Vertex> factory, - String[] families, - String style, - String variant, - String weight) { - throw new Error("not implemented"); + public Font create(String path) { + OTFontCollection fontset; + try { + fontset = OTFontCollection.create(new File(path)); + return new TypecastFont(fontset); + } catch (IOException e) { + e.printStackTrace(); + } + return null; } - - + }
\ No newline at end of file diff --git a/src/jogamp/graph/font/typecast/TypecastMetrics.java b/src/jogamp/graph/font/typecast/TypecastHMetrics.java index 9ca1e3bf7..cd8595498 100644 --- a/src/jogamp/graph/font/typecast/TypecastMetrics.java +++ b/src/jogamp/graph/font/typecast/TypecastHMetrics.java @@ -29,11 +29,10 @@ package jogamp.graph.font.typecast; import net.java.dev.typecast.ot.table.HeadTable; import net.java.dev.typecast.ot.table.HheaTable; - import com.jogamp.graph.font.Font.Metrics; import com.jogamp.graph.geom.AABBox; -class TypecastMetrics implements Metrics { +class TypecastHMetrics implements Metrics { private final TypecastFont fontImpl; // HeadTable @@ -42,11 +41,14 @@ class TypecastMetrics implements Metrics { private final AABBox bbox; // HheaTable private final HheaTable hheaTable; + // VheaTable (for horizontal fonts) + // private final VheaTable vheaTable; - public TypecastMetrics(TypecastFont fontImpl) { + public TypecastHMetrics(TypecastFont fontImpl) { this.fontImpl = fontImpl; headTable = this.fontImpl.font.getHeadTable(); hheaTable = this.fontImpl.font.getHheaTable(); + // vheaTable = this.fontImpl.font.getVheaTable(); unitsPerEM_Inv = 1.0f / ( (float) headTable.getUnitsPerEm() ); int maxWidth = headTable.getXMax() - headTable.getXMin(); @@ -67,6 +69,9 @@ class TypecastMetrics implements Metrics { public final float getLineGap(float pixelSize) { return getScale(pixelSize) * -hheaTable.getLineGap(); // invert } + public final float getMaxExtend(float pixelSize) { + return getScale(pixelSize) * hheaTable.getXMaxExtent(); + } public final float getScale(float pixelSize) { return pixelSize * unitsPerEM_Inv; } diff --git a/src/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogamp/graph/font/typecast/TypecastRenderer.java index 11f1ec028..410f5b73a 100644 --- a/src/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogamp/graph/font/typecast/TypecastRenderer.java @@ -31,9 +31,6 @@ import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Vertex.Factory; - import net.java.dev.typecast.ot.Point; import net.java.dev.typecast.ot.OTGlyph; @@ -43,7 +40,7 @@ import net.java.dev.typecast.ot.OTGlyph; */ public class TypecastRenderer { - public static void getOutline(Factory<? extends Vertex> factory, TypecastFont font, + public static void getOutline(TypecastFont font, String string, float pixelSize, AffineTransform transform, Path2D[] p) { if (string == null) { @@ -55,9 +52,9 @@ public class TypecastRenderer { float ascent = metrics.getAscent(pixelSize) ; float descent = metrics.getDescent(pixelSize) ; if (transform == null) { - transform = new AffineTransform(factory); + transform = new AffineTransform(); } - AffineTransform t = new AffineTransform(factory); + AffineTransform t = new AffineTransform(); float advanceY = lineGap - descent + ascent; float y = 0; @@ -71,7 +68,10 @@ public class TypecastRenderer { y -= advanceY; advanceTotal = 0; continue; - } + } else if (character == ' ') { + advanceTotal += font.font.getHmtxTable().getAdvanceWidth(TypecastGlyph.ID_SPACE) * metrics.getScale(pixelSize); + continue; + } TypecastGlyph glyph = (TypecastGlyph) font.getGlyph(character); Path2D gp = glyph.getPath(); float scale = metrics.getScale(pixelSize); diff --git a/src/jogamp/graph/geom/plane/AffineTransform.java b/src/jogamp/graph/geom/plane/AffineTransform.java index de13ff9de..2ba9f8d06 100644 --- a/src/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/jogamp/graph/geom/plane/AffineTransform.java @@ -72,6 +72,13 @@ public class AffineTransform implements Cloneable, Serializable { */ transient int type; + public AffineTransform() { + pointFactory = null; + type = TYPE_IDENTITY; + m00 = m11 = 1.0f; + m10 = m01 = m02 = m12 = 0.0f; + } + public AffineTransform(Factory<? extends Vertex> factory) { pointFactory = factory; type = TYPE_IDENTITY; |