Posted by
gouessej on
Sep 15, 2010; 1:27pm
URL: https://forum.jogamp.org/Re-JogAmp-tp1169507p1479735.html
Hi
I have ported my fix to JOGL 2 (and using Java 1.4 instead of Java 1.6). As I did it at work and for my work, please at least put my full name into the commit comment in order to allow me to have a trace of it for my boss. Please find the whole source code below (Edit.: rather the patch):
1558a1559,1560
> HashMap/*<String, GlyphVector>*/fullGlyphVectorCache = new HashMap/*<String, GlyphVector>*/();
> HashMap/*<Character, GlyphMetrics>*/glyphMetricsCache = new HashMap/*<Character, GlyphMetrics>*/();
1574,1575c1576,1582
< iter.initFromCharSequence(inString);
< GlyphVector fullRunGlyphVector = font.createGlyphVector(getFontRenderContext(), iter);
---
> GlyphVector fullRunGlyphVector;
> fullRunGlyphVector = (GlyphVector) fullGlyphVectorCache.get(inString.toString());
> if (fullRunGlyphVector == null) {
> iter.initFromCharSequence(inString);
> fullRunGlyphVector = font.createGlyphVector(getFontRenderContext(), iter);
> fullGlyphVectorCache.put(inString.toString(), fullRunGlyphVector);
> }
1586c1593,1599
< Glyph glyph = getGlyph(inString, fullRunGlyphVector, i);
---
> Character letter = CharacterCache.valueOf(inString.charAt(i));
> GlyphMetrics metrics = (GlyphMetrics) glyphMetricsCache.get(letter);
> if (metrics == null) {
> metrics = fullRunGlyphVector.getGlyphMetrics(i);
> glyphMetricsCache.put(letter, metrics);
> }
> Glyph glyph = getGlyph(inString, metrics, i);
1590c1603,1604
< } else {
---
> }
> else {
1594,1595c1608,1609
< while (i < lengthInGlyphs &&
< getGlyph(inString, fullRunGlyphVector, i) == null) {
---
> while (i < lengthInGlyphs
> && getGlyph(inString, fullRunGlyphVector.getGlyphMetrics(i), i) == null) {
1599,1600c1613,1614
< // Any more glyphs after this run?
< i < lengthInGlyphs));
---
> // Any more glyphs after this run?
> i < lengthInGlyphs));
1642c1656
< // Returns a glyph object for this single glyph. Returns null
---
> // Returns a glyph object for this single glyph. Returns null
1645,1647c1659,1660
< private Glyph getGlyph(CharSequence inString,
< GlyphVector fullRunGlyphVector,
< int index) {
---
> private Glyph getGlyph(CharSequence inString, /*GlyphVector fullRunGlyphVector*/
> GlyphMetrics glyphMetrics, int index) {
1662c1675,1676
< return getGlyph(unicodeID, gv, fullRunGlyphVector.getGlyphMetrics(index));
---
> return getGlyph(unicodeID, gv, /*fullRunGlyphVector.getGlyphMetrics(index)*/
> glyphMetrics);
1698a1713,1732
>
> private static class CharacterCache {
> private CharacterCache() {
> }
>
> static final Character cache[] = new Character[127 + 1];
>
> static {
> for (int i = 0; i < cache.length; i++) {
> cache[i] = new Character((char) i);
> }
> }
>
> public static Character valueOf(char c) {
> if (c <= 127) { // must cache
> return CharacterCache.cache[c];
> }
> return new Character(c);
> }
> }