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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!-- This file writes the class files for the fonts (Courier.java,
  2. Helvetica.java etc.). It uses the information in the font
  3. description files (Courier.xml, Helvetica.xml) to do this. In these
  4. font description files each character is referenced by its adobe
  5. glyph name:
  6. <char name="A" width="667"/>
  7. To resolve this name and to find the code for this character it looks
  8. up the adobe name in the file encodings.xml and extracts the appropriate
  9. code. -->
  10. <xsl:stylesheet version="1.0"
  11. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  12. <xsl:output method="text"/>
  13. <xsl:param name="encoding" select="/font-metrics/encoding"/>
  14. <xsl:variable name="native-encoding" select="/font-metrics/encoding"/>
  15. <xsl:variable name="glyphs" select="document('encodings.xml')/encoding-set/encoding[@id=$encoding]/glyph"/>
  16. <xsl:template match="font-metrics">
  17. package org.apache.fop.render.pdf.fonts;
  18. import org.apache.fop.render.pdf.Font;
  19. import org.apache.fop.render.pdf.CodePointMapping;
  20. public class <xsl:value-of select="class-name"/> extends Font {
  21. private final static String fontName = "<xsl:value-of select="font-name"/>";
  22. 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>;
  23. private final static int capHeight = <xsl:value-of select="cap-height"/>;
  24. private final static int xHeight = <xsl:value-of select="x-height"/>;
  25. private final static int ascender = <xsl:value-of select="ascender"/>;
  26. private final static int descender = <xsl:value-of select="descender"/>;
  27. private final static int firstChar = <xsl:value-of select="first-char"/>;
  28. private final static int lastChar = <xsl:value-of select="last-char"/>;
  29. private final static int[] width;
  30. private final CodePointMapping mapping
  31. = CodePointMapping.getMapping("<xsl:value-of select="$encoding"/>");
  32. static {
  33. width = new int[256];
  34. <xsl:apply-templates select="widths"/>
  35. }
  36. public String encoding() {
  37. return encoding;
  38. }
  39. public String fontName() {
  40. return fontName;
  41. }
  42. public int getAscender(int size) {
  43. return size * ascender;
  44. }
  45. public int getCapHeight(int size) {
  46. return size * capHeight;
  47. }
  48. public int getDescender(int size) {
  49. return size * descender;
  50. }
  51. public int getXHeight(int size) {
  52. return size * xHeight;
  53. }
  54. public int getFirstChar() {
  55. return firstChar;
  56. }
  57. public int getLastChar() {
  58. return lastChar;
  59. }
  60. public int width(int i,int size) {
  61. return size * width[i];
  62. }
  63. public int[] getWidths(int size) {
  64. int[] arr = new int[getLastChar()-getFirstChar()+1];
  65. System.arraycopy(width, getFirstChar(), arr, 0, getLastChar()-getFirstChar()+1);
  66. for( int i = 0; i &lt; arr.length; i++) arr[i] *= size;
  67. return arr;
  68. }
  69. public char mapChar(char c) {
  70. char d = mapping.mapChar(c);
  71. if(d != 0)
  72. return d;
  73. else
  74. return '#';
  75. }
  76. }
  77. </xsl:template>
  78. <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>
  79. </xsl:stylesheet>