git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@196579 13f79535-47bb-0310-9956-ffa450edef68tags/Alt-Design_pre_src-java-org
@@ -2,7 +2,7 @@ | |||
<font-metrics> | |||
<font-name>Courier</font-name> | |||
<class-name>Courier</class-name> | |||
<encoding>WinAnsiEncoding</encoding> | |||
<encoding>StandardEncoding</encoding> | |||
<cap-height>562</cap-height> | |||
<x-height>426</x-height> | |||
<ascender>629</ascender> | |||
@@ -28,6 +28,7 @@ | |||
<char name="Edieresis" width="600"/> | |||
<char name="Egrave" width="600"/> | |||
<char name="Eth" width="600"/> | |||
<char name="Euro" width="600"/> | |||
<char name="F" width="600"/> | |||
<char name="G" width="600"/> | |||
<char name="Gcaron" width="600"/> |
@@ -2,7 +2,7 @@ | |||
<font-metrics> | |||
<font-name>Helvetica</font-name> | |||
<class-name>Helvetica</class-name> | |||
<encoding>WinAnsiEncoding</encoding> | |||
<encoding>StandardEncoding</encoding> | |||
<cap-height>718</cap-height> | |||
<x-height>523</x-height> | |||
<ascender>718</ascender> | |||
@@ -28,6 +28,7 @@ | |||
<char name="Edieresis" width="667"/> | |||
<char name="Egrave" width="667"/> | |||
<char name="Eth" width="722"/> | |||
<char name="Euro" width="556"/> | |||
<char name="F" width="611"/> | |||
<char name="G" width="778"/> | |||
<char name="H" width="722"/> |
@@ -1,8 +1,8 @@ | |||
<font-metrics> | |||
<font-name>Symbol</font-name> | |||
<class-name>Symbol</class-name> | |||
<encoding>StandardEncoding</encoding> | |||
<cap-height>1010</cap-height> | |||
<encoding>SymbolEncoding</encoding> | |||
<cap-height>1010</cap-height> | |||
<x-height>520</x-height> | |||
<ascender>1010</ascender> | |||
<descender>-293</descender> |
@@ -1,8 +1,8 @@ | |||
<font-metrics> | |||
<font-name>ZapfDingbats</font-name> | |||
<class-name>ZapfDingbats</class-name> | |||
<encoding>StandardEncoding</encoding> | |||
<cap-height>820</cap-height> | |||
<encoding>ZapfDingbatsEncoding</encoding> | |||
<cap-height>820</cap-height> | |||
<x-height>426</x-height> | |||
<ascender>820</ascender> | |||
<descender>-143</descender> |
@@ -439,7 +439,7 @@ | |||
<map adobe-name="a189" win-ansi="0x00FC" unicode="0x27BC" unicodeName="WEDGE-TAILED RIGHTWARDS ARROW"/> | |||
<map adobe-name="a190" win-ansi="0x00FD" unicode="0x27BD" unicodeName="HEAVY WEDGE-TAILED RIGHTWARDS ARROW"/> | |||
<map adobe-name="a191" win-ansi="0x00FE" unicode="0x27BE" unicodeName="OPEN-OUTLINED RIGHTWARDS ARROW"/> | |||
<!-- the following mappings are used for the Symbol font | |||
<!-- the following mappings are used for the Symbol font | |||
TBD: remove doublettes --> | |||
<map adobe-name="universal" win-ansi="0x22" unicode="0x2200"/> | |||
<map adobe-name="existential" win-ansi="0x24" unicode="0x2203"/> | |||
@@ -592,21 +592,21 @@ | |||
</font-mappings> | |||
<!-- I couldn't find the following characters in the unicode tables --> | |||
<!-- | |||
<map adobe-name="center" win-ansi="-1" unicode=""/> | |||
<map adobe-name="dectab" win-ansi="-1" unicode=""/> | |||
<map adobe-name="down" win-ansi="-1" unicode=""/> | |||
<map adobe-name="format" win-ansi="-1" unicode=""/> | |||
<map adobe-name="graybox" win-ansi="-1" unicode=""/> | |||
<map adobe-name="indent" win-ansi="-1" unicode=""/> | |||
<map adobe-name="largebullet" win-ansi="-1" unicode=""/> | |||
<map adobe-name="left" win-ansi="-1" unicode=""/> | |||
<map adobe-name="ll" win-ansi="-1" unicode=""/> | |||
<map adobe-name="LL" win-ansi="-1" unicode=""/> | |||
<map adobe-name="merge" win-ansi="-1" unicode=""/> | |||
<map adobe-name="notegraphic" win-ansi="-1" unicode=""/> | |||
<map adobe-name="overscore" win-ansi="-1" unicode=""/> | |||
<map adobe-name="prescription" win-ansi="-1" unicode=""/> | |||
<map adobe-name="return" win-ansi="-1" unicode=""/> | |||
<map adobe-name="center" win-ansi="-1" unicode=""/> | |||
<map adobe-name="dectab" win-ansi="-1" unicode=""/> | |||
<map adobe-name="down" win-ansi="-1" unicode=""/> | |||
<map adobe-name="format" win-ansi="-1" unicode=""/> | |||
<map adobe-name="graybox" win-ansi="-1" unicode=""/> | |||
<map adobe-name="indent" win-ansi="-1" unicode=""/> | |||
<map adobe-name="largebullet" win-ansi="-1" unicode=""/> | |||
<map adobe-name="left" win-ansi="-1" unicode=""/> | |||
<map adobe-name="ll" win-ansi="-1" unicode=""/> | |||
<map adobe-name="LL" win-ansi="-1" unicode=""/> | |||
<map adobe-name="merge" win-ansi="-1" unicode=""/> | |||
<map adobe-name="notegraphic" win-ansi="-1" unicode=""/> | |||
<map adobe-name="overscore" win-ansi="-1" unicode=""/> | |||
<map adobe-name="prescription" win-ansi="-1" unicode=""/> | |||
<map adobe-name="return" win-ansi="-1" unicode=""/> | |||
<map adobe-name="square" win-ansi="-1" unicode=""/> | |||
<map adobe-name="stop" win-ansi="-1" unicode=""/> | |||
<map adobe-name="tab" win-ansi="-1" unicode=""/> |
@@ -1,24 +1,153 @@ | |||
<!-- | |||
$Id$ | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, 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. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "FOP" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, 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. | |||
============================================================================ | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
--> | |||
<xsl:stylesheet version="1.0" | |||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |||
xmlns:lxslt="http://xml.apache.org/xslt" | |||
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect" | |||
extension-element-prefixes="redirect"> | |||
<xsl:output method="text" /> | |||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |||
<xsl:output method="text"/> | |||
<xsl:variable name='glyphlists' | |||
select="document('glyphlist.xml')/glyphlist-set"/> | |||
<xsl:template match="font-mappings"> | |||
<!-- <redirect:write file="org/apache/fop/render/pdf/CodePointMapping.java"> --> | |||
package org.apache.fop.render.pdf; | |||
<xsl:template match="encoding-set"> | |||
package org.apache.fop.fonts; | |||
import java.util.Map; | |||
import java.util.Collections; | |||
public class CodePointMapping { | |||
public static char[] map; | |||
private char[] latin1Map; | |||
private char[] characters; | |||
private char[] codepoints; | |||
private CodePointMapping(int [] table) { | |||
int nonLatin1 = 0; | |||
latin1Map = new char[256]; | |||
for(int i = 0; i < table.length; i += 2) { | |||
if(table[i+1] < 256) | |||
latin1Map[table[i+1]] = (char) table[i]; | |||
else | |||
++nonLatin1; | |||
} | |||
characters = new char[nonLatin1]; | |||
codepoints = new char[nonLatin1]; | |||
int top = 0; | |||
for(int i = 0; i < table.length; i += 2) { | |||
char c = (char) table[i+1]; | |||
if(c >= 256) { | |||
++top; | |||
for(int j = top - 1; j >= 0; --j) { | |||
if(j > 0 && characters[j-1] >= c) { | |||
characters[j] = characters[j-1]; | |||
codepoints[j] = codepoints[j-1]; | |||
} else { | |||
characters[j] = c; | |||
codepoints[j] = (char) table[i]; | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
public final char mapChar(char c) { | |||
if(c < 256) { | |||
return latin1Map[c]; | |||
} else { | |||
int bot = 0, top = characters.length - 1; | |||
while(top >= bot) { | |||
int mid = (bot + top) / 2; | |||
char mc = characters[mid]; | |||
if(c == mc) | |||
return codepoints[mid]; | |||
else if(c < mc) | |||
top = mid - 1; | |||
else | |||
bot = mid + 1; | |||
} | |||
return 0; | |||
} | |||
} | |||
static { | |||
map = new char[65536]; | |||
<xsl:for-each select="map[@unicode!='-1' and @win-ansi!='-1']"> map[<xsl:value-of select="@unicode"/>] = <xsl:value-of select="@win-ansi"/>; | |||
</xsl:for-each> | |||
private static Map mappings; | |||
static { | |||
mappings = Collections.synchronizedMap(new java.util.HashMap()); | |||
} | |||
public static CodePointMapping getMapping(String encoding) { | |||
CodePointMapping mapping = (CodePointMapping) mappings.get(encoding); | |||
if(mapping != null) { | |||
return mapping; | |||
} <xsl:apply-templates mode="get"/> | |||
else { | |||
return null; | |||
} | |||
} | |||
<xsl:apply-templates mode="table"/> | |||
} | |||
<!-- </redirect:write>--> | |||
</xsl:template> | |||
</xsl:stylesheet> | |||
</xsl:template> | |||
<xsl:template match="encoding" mode="get"> | |||
else if(encoding.equals("<xsl:value-of select="@id"/>")) { | |||
mapping = new CodePointMapping(enc<xsl:value-of select="@id"/>); | |||
mappings.put("<xsl:value-of select="@id"/>", mapping); | |||
return mapping; | |||
} | |||
</xsl:template> | |||
<xsl:template match="encoding" mode="table"> | |||
<xsl:variable name="glyphlist-name" select="@glyphlist"/> | |||
<xsl:variable name="glyphlist" | |||
select="$glyphlists/glyphlist[@id=$glyphlist-name]"/> | |||
private static final int[] enc<xsl:value-of select="@id"/> | |||
= {<xsl:for-each select="glyph"> | |||
<xsl:variable name="codepoint" select="@codepoint"/> | |||
<xsl:variable name="name" select="@name"/><xsl:for-each select="$glyphlist/glyph[@name=$name]"> | |||
0x<xsl:value-of select="$codepoint"/>, 0x<xsl:value-of select="@codepoint"/>, // <xsl:value-of select="$name"/> | |||
</xsl:for-each></xsl:for-each> | |||
}; | |||
</xsl:template> | |||
</xsl:stylesheet> |
@@ -1,4 +1,54 @@ | |||
<!-- | |||
<!-- | |||
$Id$ | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, 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. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "FOP" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, 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. | |||
============================================================================ | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
--> | |||
<!-- | |||
This files writes the class files for the Adobe Type 1 fonts. | |||
It uses the information in the font description files (Courier.xml, Helvetica.xml) to this | |||
In these font description files each character is referenced by its adobe name: | |||
@@ -27,7 +77,7 @@ import org.apache.fop.pdf.PDFT1Stream; | |||
import java.io.InputStream; | |||
import java.io.FileInputStream; | |||
import java.io.BufferedInputStream; | |||
import java.util.Hashtable; | |||
import java.util.HashMap; | |||
public class <xsl:value-of select="class-name"/> extends Font implements FontDescriptor { | |||
private final static String fontName = "<xsl:value-of select="font-name"/>"; | |||
@@ -44,31 +94,31 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
}; | |||
private final static String embedFileName = <xsl:value-of select="embedFile"/>; | |||
private final static String embedResourceName = <xsl:value-of select="embedResource"/>; | |||
private static PDFT1Stream embeddedFont=null; | |||
private static PDFT1Stream embeddedFont=null; | |||
private final static int flags = <xsl:value-of select="flags"/>; | |||
private final static int stemV = <xsl:value-of select="stemv"/>; | |||
private final static int italicAngle = <xsl:value-of select="italicangle"/>; | |||
private final static int firstChar = <xsl:value-of select="first-char"/>; | |||
private final static int lastChar = <xsl:value-of select="last-char"/>; | |||
private final static int[] width; | |||
private final static Hashtable kerning=new Hashtable(); | |||
private final static HashMap kerning=new HashMap(); | |||
static { | |||
width = new int[256]; | |||
<xsl:for-each select="widths/char"><xsl:variable name="char-name" select="@name"/><xsl:variable name="char-num" select="document('charlist.xml')/font-mappings/map[@adobe-name=$char-name]/@win-ansi"/><xsl:if test="$char-num!='-1'"> width[<xsl:value-of select="$char-num"/>] = <xsl:value-of select="@width"/>; | |||
</xsl:if></xsl:for-each> | |||
Hashtable tmptable; | |||
HashMap tmptable; | |||
<xsl:for-each select="kerning"> | |||
<xsl:variable name="kpx1-name" select="@kpx1"/> | |||
tmptable=new Hashtable();<xsl:for-each select="pair"><xsl:variable name="kpx2-name" select="@kpx2"/><xsl:variable name="kern-name" select="@kern"/> | |||
tmptable=new HashMap();<xsl:for-each select="pair"><xsl:variable name="kpx2-name" select="@kpx2"/><xsl:variable name="kern-name" select="@kern"/> | |||
tmptable.put(Glyphs.glyphToString("<xsl:value-of select="$kpx2-name"/>"), new Integer(<xsl:value-of select="$kern-name"/>));</xsl:for-each> | |||
kerning.put(Glyphs.glyphToString("<xsl:value-of select="$kpx1-name"/>"), tmptable); | |||
</xsl:for-each> | |||
} | |||
public final boolean hasKerningInfo() {return kerning.isEmpty();} | |||
public final java.util.Hashtable getKerningInfo() {return kerning;} | |||
public final java.util.HashMap getKerningInfo() {return kerning;} | |||
public byte getSubType() {return org.apache.fop.pdf.PDFFont.TYPE1;} | |||
public boolean isEmbeddable() { | |||
@@ -77,7 +127,7 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
public PDFStream getFontFile(int i) { | |||
InputStream instream=null; | |||
// Get file first | |||
if (embedFileName!=null) | |||
try { | |||
@@ -85,7 +135,7 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
} catch (Exception e) { | |||
System.out.println("Failed to embed fontfile: "+embedFileName); | |||
} | |||
// Get resource | |||
if (instream==null && embedResourceName!=null) | |||
try { | |||
@@ -93,10 +143,10 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
} catch (Exception e) { | |||
System.out.println("Failed to embed fontresource: "+embedResourceName); | |||
} | |||
if (instream==null) | |||
return (PDFStream)null; | |||
// Read fontdata | |||
byte[] file = new byte[128000]; | |||
int fsize = 0; | |||
@@ -104,29 +154,29 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
try { | |||
int l = instream.read(file, 0, 128000); | |||
fsize += l; | |||
if (l==128000) { | |||
// More to read - needs to extend | |||
byte[] tmpbuf; | |||
while (l > 0) { | |||
tmpbuf = new byte[file.length + 64000]; | |||
System.arraycopy(file, 0, tmpbuf, 0, file.length); | |||
l=instream.read(tmpbuf, file.length, 64000); | |||
fsize += l; | |||
file = tmpbuf; | |||
if (l < 64000) // whole file read. No need to loop again | |||
l=0; | |||
} | |||
} | |||
embeddedFont=new PDFT1Stream(i, fsize); | |||
embeddedFont.addFilter("flate"); | |||
embeddedFont.addFilter("ascii-85"); | |||
embeddedFont.setData(file, fsize); | |||
instream.close(); | |||
} catch (Exception e) {} | |||
} catch (Exception e) {} | |||
return (PDFStream) embeddedFont; | |||
} | |||
@@ -134,7 +184,7 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
public String encoding() { | |||
return encoding; | |||
} | |||
public String fontName() { | |||
return fontName; | |||
} |
@@ -1,4 +1,54 @@ | |||
<!-- | |||
<!-- | |||
$Id$ | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, 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. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "FOP" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, 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. | |||
============================================================================ | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
--> | |||
<!-- | |||
This files writes the class files for the Adobe Type 1 fonts. | |||
It uses the information in the font description files (Courier.xml, Helvetica.xml) to this | |||
In these font description files each character is referenced by its adobe name: | |||
@@ -27,7 +77,7 @@ import org.apache.fop.pdf.PDFTTFStream; | |||
import java.io.InputStream; | |||
import java.io.FileInputStream; | |||
import java.io.BufferedInputStream; | |||
import java.util.Hashtable; | |||
import java.util.HashMap; | |||
public class <xsl:value-of select="class-name"/> extends Font implements FontDescriptor { | |||
private final static String fontName = "<xsl:value-of select="font-name"/>"; | |||
@@ -45,31 +95,31 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
private final static String embedFileName = <xsl:value-of select="embedFile"/>; | |||
private final static String embedResourceName = <xsl:value-of select="embedResource"/>; | |||
private static PDFTTFStream embeddedFont=null; | |||
private static PDFTTFStream embeddedFont=null; | |||
private final static int flags = <xsl:value-of select="flags"/>; | |||
private final static int stemV = <xsl:value-of select="stemv"/>; | |||
private final static int italicAngle = <xsl:value-of select="italicangle"/>; | |||
private final static int firstChar = <xsl:value-of select="first-char"/>; | |||
private final static int lastChar = <xsl:value-of select="last-char"/>; | |||
private final static int[] width; | |||
private final static Hashtable kerning=new Hashtable(); | |||
private final static HashMap kerning=new HashMap(); | |||
static { | |||
width = new int[256]; | |||
<!--<xsl:for-each select="widths/char"><xsl:variable name="char-name" select="@name"/><xsl:variable name="char-num" select="document('charlist.xml')/font-mappings/map[@adobe-name=$char-name]/@win-ansi"/><xsl:if test="$char-num!='-1'"> width[<xsl:value-of select="$char-num"/>] = <xsl:value-of select="@width"/>;</xsl:if>--> | |||
<xsl:for-each select="widths/char"><xsl:variable name="char-name" select="@name"/> width[<xsl:value-of select="$char-name"/>] = <xsl:value-of select="@width"/>; | |||
</xsl:for-each> | |||
Hashtable tmptable; | |||
HashMap tmptable; | |||
<xsl:for-each select="kerning"> | |||
<xsl:variable name="kpx1-name" select="@kpx1"/> | |||
tmptable=new Hashtable();<xsl:for-each select="pair"><xsl:variable name="kpx2-name" select="@kpx2"/><xsl:variable name="kern-name" select="@kern"/> | |||
tmptable=new HashMap();<xsl:for-each select="pair"><xsl:variable name="kpx2-name" select="@kpx2"/><xsl:variable name="kern-name" select="@kern"/> | |||
tmptable.put(Glyphs.glyphToString("<xsl:value-of select="$kpx2-name"/>"), new Integer(<xsl:value-of select="$kern-name"/>));</xsl:for-each> | |||
kerning.put(Glyphs.glyphToString("<xsl:value-of select="$kpx1-name"/>"), tmptable); | |||
</xsl:for-each> | |||
} | |||
public final boolean hasKerningInfo() {return kerning.isEmpty();} | |||
public final java.util.Hashtable getKerningInfo() {return kerning;} | |||
public final java.util.HashMap getKerningInfo() {return kerning;} | |||
public byte getSubType() {return org.apache.fop.pdf.PDFFont.TRUETYPE;} | |||
public boolean isEmbeddable() { | |||
@@ -77,7 +127,7 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
} | |||
public PDFStream getFontFile(int i) { | |||
InputStream instream=null; | |||
// Get file first | |||
if (embedFileName!=null) | |||
try { | |||
@@ -85,7 +135,7 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
} catch (Exception e) { | |||
System.out.println("Failed to embed fontfile: "+embedFileName); | |||
} | |||
// Get resource | |||
if (instream==null && embedResourceName!=null) | |||
try { | |||
@@ -93,10 +143,10 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
} catch (Exception e) { | |||
System.out.println("Failed to embed fontresource: "+embedResourceName); | |||
} | |||
if (instream==null) | |||
return (PDFStream)null; | |||
// Read fontdata | |||
byte[] file = new byte[128000]; | |||
int fsize = 0; | |||
@@ -104,36 +154,36 @@ public class <xsl:value-of select="class-name"/> extends Font implements FontDes | |||
try { | |||
int l = instream.read(file, 0, 128000); | |||
fsize += l; | |||
if (l==128000) { | |||
// More to read - needs to extend | |||
byte[] tmpbuf; | |||
while (l > 0) { | |||
tmpbuf = new byte[file.length + 64000]; | |||
System.arraycopy(file, 0, tmpbuf, 0, file.length); | |||
l=instream.read(tmpbuf, file.length, 64000); | |||
fsize += l; | |||
file = tmpbuf; | |||
if (l < 64000) // whole file read. No need to loop again | |||
l=0; | |||
} | |||
} | |||
embeddedFont=new PDFTTFStream(i, fsize); | |||
embeddedFont.addFilter("flate"); | |||
embeddedFont.addFilter("ascii-85"); | |||
embeddedFont.setData(file, fsize); | |||
instream.close(); | |||
} catch (Exception e) {} | |||
} catch (Exception e) {} | |||
return (PDFStream) embeddedFont; | |||
} | |||
public String encoding() { | |||
return encoding; | |||
} | |||
public String fontName() { | |||
return fontName; | |||
} |