You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

font-file.xsl 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!--
  2. Copyright 1999-2004 The Apache Software Foundation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. -->
  13. <!-- $Id$ -->
  14. <!-- This file writes the class files for the fonts (Courier.java,
  15. Helvetica.java etc.). It uses the information in the font
  16. description files (Courier.xml, Helvetica.xml) to do this. In these
  17. font description files each character is referenced by its adobe
  18. glyph name:
  19. <char name="A" width="667"/>
  20. To resolve this name and to find the code for this character it looks
  21. up the adobe name in the file encodings.xml and extracts the appropriate
  22. code. -->
  23. <xsl:stylesheet version="1.0"
  24. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  25. <xsl:output method="text"/>
  26. <xsl:param name="encoding" select="/font-metrics/encoding"/>
  27. <xsl:variable name="native-encoding" select="/font-metrics/encoding"/>
  28. <xsl:variable name="glyphs" select="document('encodings.xml')/encoding-set/encoding[@id=$encoding]/glyph"/>
  29. <xsl:template match="font-metrics">
  30. package org.apache.fop.fonts.base14;
  31. import org.apache.fop.fonts.FontType;
  32. import org.apache.fop.fonts.Typeface;
  33. import org.apache.fop.fonts.CodePointMapping;
  34. public class <xsl:value-of select="class-name"/> extends Typeface {
  35. private final static String fontName = "<xsl:value-of select="font-name"/>";
  36. private final static String encoding = <xsl:choose><xsl:when test="$encoding != $native-encoding">"<xsl:value-of select="$encoding"/>"</xsl:when><xsl:otherwise>null</xsl:otherwise></xsl:choose>;
  37. private final static int capHeight = <xsl:value-of select="cap-height"/>;
  38. private final static int xHeight = <xsl:value-of select="x-height"/>;
  39. private final static int ascender = <xsl:value-of select="ascender"/>;
  40. private final static int descender = <xsl:value-of select="descender"/>;
  41. private final static int firstChar = <xsl:value-of select="first-char"/>;
  42. private final static int lastChar = <xsl:value-of select="last-char"/>;
  43. private final static int[] width;
  44. private final CodePointMapping mapping =
  45. CodePointMapping.getMapping("<xsl:value-of select="$encoding"/>");
  46. static {
  47. width = new int[256];
  48. <xsl:apply-templates select="widths"/>
  49. }
  50. public String getEncoding() {
  51. return encoding;
  52. }
  53. public String getFontName() {
  54. return fontName;
  55. }
  56. public FontType getFontType() {
  57. return FontType.TYPE1;
  58. }
  59. public int getAscender(int size) {
  60. return size * ascender;
  61. }
  62. public int getCapHeight(int size) {
  63. return size * capHeight;
  64. }
  65. public int getDescender(int size) {
  66. return size * descender;
  67. }
  68. public int getXHeight(int size) {
  69. return size * xHeight;
  70. }
  71. public int getFirstChar() {
  72. return firstChar;
  73. }
  74. public int getLastChar() {
  75. return lastChar;
  76. }
  77. public int getWidth(int i,int size) {
  78. return size * width[i];
  79. }
  80. public int[] getWidths() {
  81. int[] arr = new int[getLastChar()-getFirstChar()+1];
  82. System.arraycopy(width, getFirstChar(), arr, 0, getLastChar()-getFirstChar()+1);
  83. //for( int i = 0; i &lt; arr.length; i++) arr[i] *= size;
  84. return arr;
  85. }
  86. public boolean hasKerningInfo() {
  87. return false;
  88. }
  89. public java.util.Map getKerningInfo() {
  90. return java.util.Collections.EMPTY_MAP;
  91. }
  92. public char mapChar(char c) {
  93. char d = mapping.mapChar(c);
  94. if(d != 0) {
  95. return d;
  96. } else {
  97. return '#';
  98. }
  99. }
  100. }
  101. </xsl:template>
  102. <xsl:template match="widths/char"><xsl:variable name="char-name" select="@name"/><xsl:variable name="char-num" select="$glyphs[@name = $char-name]/@codepoint"/><xsl:if test="$char-num!=''"> width[0x<xsl:value-of select="$char-num"/>] = <xsl:value-of select="@width"/>;</xsl:if></xsl:template>
  103. </xsl:stylesheet>