diff options
author | Keiron Liddle <keiron@apache.org> | 2002-06-28 07:52:54 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-06-28 07:52:54 +0000 |
commit | 490de46b9eeca6cadf789acc45531f283e79fcbe (patch) | |
tree | 45877b06add37290cd33c8e831752caf6049505f /src/org/apache | |
parent | 9091d3250a9551da1b6af7d3be363c491a6a2e0d (diff) | |
download | xmlgraphics-fop-490de46b9eeca6cadf789acc45531f283e79fcbe.tar.gz xmlgraphics-fop-490de46b9eeca6cadf789acc45531f283e79fcbe.zip |
proper use of font encodings for native fonts
updated xalan
Submitted by: Rainer Garus <rainer.garus@arcor.de>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194932 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/fonts/TTFFile.java | 65 | ||||
-rw-r--r-- | src/org/apache/fop/layout/FontState.java | 15 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/Font.java | 15 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/fonts/SingleByteFont.java | 11 | ||||
-rw-r--r-- | src/org/apache/fop/util/CharUtilities.java | 90 |
5 files changed, 90 insertions, 106 deletions
diff --git a/src/org/apache/fop/fonts/TTFFile.java b/src/org/apache/fop/fonts/TTFFile.java index 7404c7c23..59360955b 100644 --- a/src/org/apache/fop/fonts/TTFFile.java +++ b/src/org/apache/fop/fonts/TTFFile.java @@ -224,29 +224,21 @@ public class TTFFile { // Also add winAnsiWidth - if (false) { - int d = j; - if (j > 127) - d = (int)org.apache.fop.render.pdf.CodePointMapping.map[j]; - if (d < ansiWidth.length) - ansiWidth[d] = mtx_tab[glyphIdx].wx; - } else { - ArrayList v = - (ArrayList)ansiIndex.get(new Integer(j)); - if (v != null) { - for (Iterator e = v.listIterator(); - e.hasNext(); ) { - Integer aIdx = - (Integer)e.next(); - ansiWidth[aIdx.intValue()] = - mtx_tab[glyphIdx].wx; - /* - * System.out.println("Added width "+ - * mtx_tab[glyphIdx].wx + - * " uni: " + j + - * " ansi: " + aIdx.intValue()); - */ - } + ArrayList v = + (ArrayList)ansiIndex.get(new Integer(j)); + if (v != null) { + for (Iterator e = v.listIterator(); + e.hasNext(); ) { + Integer aIdx = + (Integer)e.next(); + ansiWidth[aIdx.intValue()] = + mtx_tab[glyphIdx].wx; + /* + * System.out.println("Added width "+ + * mtx_tab[glyphIdx].wx + + * " uni: " + j + + * " ansi: " + aIdx.intValue()); + */ } } /* @@ -281,24 +273,15 @@ public class TTFFile { // Also add winAnsiWidth - if (false) { - int d = j; - if (j > 127) - d = (int)org.apache.fop.render.pdf.CodePointMapping.map[j]; - - if (d < ansiWidth.length) - ansiWidth[d] = mtx_tab[glyphIdx].wx; - } else { - ArrayList v = - (ArrayList)ansiIndex.get(new Integer(j)); - if (v != null) { - for (Iterator e = v.listIterator(); - e.hasNext(); ) { - Integer aIdx = - (Integer)e.next(); - ansiWidth[aIdx.intValue()] = - mtx_tab[glyphIdx].wx; - } + ArrayList v = + (ArrayList)ansiIndex.get(new Integer(j)); + if (v != null) { + for (Iterator e = v.listIterator(); + e.hasNext(); ) { + Integer aIdx = + (Integer)e.next(); + ansiWidth[aIdx.intValue()] = + mtx_tab[glyphIdx].wx; } } diff --git a/src/org/apache/fop/layout/FontState.java b/src/org/apache/fop/layout/FontState.java index fddd71087..147e1198d 100644 --- a/src/org/apache/fop/layout/FontState.java +++ b/src/org/apache/fop/layout/FontState.java @@ -11,6 +11,7 @@ import java.util.HashMap; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.FontVariant; +import org.apache.fop.render.pdf.CodePointMapping; public class FontState { @@ -109,14 +110,12 @@ public class FontState { } // Use default CodePointMapping - if (c > 127) { - char d = org.apache.fop.render.pdf.CodePointMapping.map[c]; - if (d != 0) { - c = d; - } else { - c = '#'; - } - } + char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c); + if (d != 0) { + c = d; + } else { + c = '#'; + } return c; } diff --git a/src/org/apache/fop/render/pdf/Font.java b/src/org/apache/fop/render/pdf/Font.java index 760200b22..a4f00b24a 100644 --- a/src/org/apache/fop/render/pdf/Font.java +++ b/src/org/apache/fop/render/pdf/Font.java @@ -33,20 +33,9 @@ public abstract class Font implements FontMetric { } /** - * Provide a default mapping + * map a Unicode character to a code point in the font */ - public char mapChar(char c) { - // Use default CodePointMapping - if (c > 127) { - char d = org.apache.fop.render.pdf.CodePointMapping.map[c]; - if (d != 0) { - c = d; - } else { - c = '#'; - } - } - return c; - } + public abstract char mapChar(char c); public boolean isMultiByte() { return false; diff --git a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java b/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java index 7200b92f7..b29ea9b8c 100644 --- a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java +++ b/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java @@ -8,6 +8,7 @@ package org.apache.fop.render.pdf.fonts; import org.apache.fop.render.pdf.Font; +import org.apache.fop.render.pdf.CodePointMapping; import org.apache.fop.layout.FontDescriptor; import org.apache.fop.fonts.Glyphs; import org.apache.fop.pdf.PDFStream; @@ -24,6 +25,8 @@ import java.util.HashMap; public class SingleByteFont extends Font implements FontDescriptor { public String fontName = null; public String encoding = "WinAnsiEncoding"; + private final CodePointMapping mapping + = CodePointMapping.getMapping("WinAnsiEncoding"); public int capHeight = 0; public int xHeight = 0; @@ -237,5 +240,13 @@ public class SingleByteFont extends Font implements FontDescriptor { return arr; } + public char mapChar(char c) { + char d = mapping.mapChar(c); + if(d != 0) + return d; + else + return '#'; + } + } diff --git a/src/org/apache/fop/util/CharUtilities.java b/src/org/apache/fop/util/CharUtilities.java index 14187a5ea..7befd4656 100644 --- a/src/org/apache/fop/util/CharUtilities.java +++ b/src/org/apache/fop/util/CharUtilities.java @@ -47,51 +47,53 @@ public class CharUtilities { * versions of space that might not exists in the font. */ public static int getCharWidth(char c, FontState fs) { - int width = fs.width(fs.mapChar(c)); - if (width <= 0) { - // Estimate the width of spaces not represented in - // the font - int em = fs.width(fs.mapChar('m')); - int en = fs.width(fs.mapChar('n')); - if (em <= 0) - em = 500 * fs.getFontSize(); - if (en <= 0) - en = em - 10; + int width; - if (c == ' ') - width = em; - if (c == '\u2000') - width = en; - if (c == '\u2001') - width = em; - if (c == '\u2002') - width = em / 2; - if (c == '\u2003') - width = fs.getFontSize(); - if (c == '\u2004') - width = em / 3; - if (c == '\u2005') - width = em / 4; - if (c == '\u2006') - width = em / 6; - if (c == '\u2007') - width = getCharWidth(' ', fs); - if (c == '\u2008') - width = getCharWidth('.', fs); - if (c == '\u2009') - width = em / 5; - if (c == '\u200A') - width = 5; - if (c == '\u200B') - width = 100; - if (c == '\u00A0') - width = getCharWidth(' ', fs); - if (c == '\u202F') - width = getCharWidth(' ', fs) / 2; - if (c == '\u3000') - width = getCharWidth(' ', fs) * 2; - if ((c == '\n') || (c == '\r') || (c == '\t')) - width = getCharWidth(' ', fs); + if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) { + width = getCharWidth(' ', fs); + } else { + width = fs.width(fs.mapChar(c)); + if (width <= 0) { + // Estimate the width of spaces not represented in + // the font + int em = fs.width(fs.mapChar('m')); + int en = fs.width(fs.mapChar('n')); + if (em <= 0) + em = 500 * fs.getFontSize(); + if (en <= 0) + en = em - 10; + + if (c == ' ') + width = em; + if (c == '\u2000') + width = en; + if (c == '\u2001') + width = em; + if (c == '\u2002') + width = em / 2; + if (c == '\u2003') + width = fs.getFontSize(); + if (c == '\u2004') + width = em / 3; + if (c == '\u2005') + width = em / 4; + if (c == '\u2006') + width = em / 6; + if (c == '\u2007') + width = getCharWidth(' ', fs); + if (c == '\u2008') + width = getCharWidth('.', fs); + if (c == '\u2009') + width = em / 5; + if (c == '\u200A') + width = 5; + if (c == '\u200B') + width = 100; + if (c == '\u202F') + width = getCharWidth(' ', fs) / 2; + if (c == '\u3000') + width = getCharWidth(' ', fs) * 2; + } } return width; |