From 4b814826897b33ee88565bc72dca10d99473e187 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 19 Feb 2023 05:26:26 +0100 Subject: Graph Font: Simplify CmapFormat selection (cmap symbol -> glyph-idx), just use Unicode and if not available use a symbol font --- .../jogamp/graph/font/typecast/TypecastFont.java | 75 +++++++--------------- 1 file changed, 24 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 916e71b67..7b701c03b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -60,68 +60,40 @@ class TypecastFont implements Font { private final TypecastHMetrics metrics; // FIXME: Add cache size to limit memory usage ?? + private static final boolean forceAscii = false; // FIXME ??? (ASCII/Macintosh cmap format) + public TypecastFont(final 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?) final CmapTable cmapTable = font.getCmapTable(); - final CmapFormat[] _cmapFormatP = { null, null, null, null }; int platform = -1; - int platformLength = -1; int encoding = -1; - for(int i=0; i platformLength ) { - platformLength = cf.getLength() ; - platform = pidx; - encoding = cmapIdxEntry.getEncodingId(); - } - } - } - if(0 <= platform) { - cmapFormat = _cmapFormatP[platform]; - if(DEBUG) { - System.err.println("Selected CmapFormat: platform " + platform + - ", encoding "+encoding + ": "+cmapFormat); - } + + // Decide upon a cmap table to use for our character to glyph look-up + CmapFormat cmapFmt; + platform = ID.platformMicrosoft; + if (forceAscii) { + // We've been asked to use the ASCII/Macintosh cmap format + encoding = ID.encodingRoman; + cmapFmt = cmapTable.getCmapFormat(ID.platformMacintosh, ID.encodingRoman); } 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; + // The default behaviour is to use the Unicode cmap encoding + encoding = ID.encodingUnicode; + cmapFmt = cmapTable.getCmapFormat(ID.platformMicrosoft, ID.encodingUnicode); + if (cmapFmt == null) { + // This might be a symbol font 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); + cmapFmt = cmapTable.getCmapFormat(ID.platformMicrosoft, ID.encodingSymbol); } } + if (cmapFmt == null) { + throw new RuntimeException("Cannot find a suitable cmap table"); + } + cmapFormat = cmapFmt; + if(DEBUG) { + System.err.println("Selected CmapFormat: platform " + platform + ", encoding "+encoding + ": "+cmapFormat); + } { int _cmapentries = 0; @@ -326,6 +298,7 @@ class TypecastFont implements Font { } temp1.translate(advanceTotal, y, temp2); res.resize(temp1.transform(glyph.getBBoxFU(), temp_box)); + advanceTotal += glyph.getAdvanceFU(); left_glyph = glyph; } -- cgit v1.2.3