選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PDFFontDescriptor.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.pdf;
  18. import org.apache.fop.fonts.FontType;
  19. /**
  20. * Class representing a font descriptor (/FontDescriptor object).
  21. * <p>
  22. * Font descriptors are specified on page 222 and onwards of the PDF 1.3 spec.
  23. */
  24. public class PDFFontDescriptor extends PDFObject {
  25. // Required fields
  26. private int ascent;
  27. private int capHeight;
  28. private int descent;
  29. private int flags;
  30. private PDFRectangle fontBBox;
  31. private String basefont; // PDF-spec: FontName
  32. private int italicAngle;
  33. private int stemV;
  34. // Optional fields
  35. private int stemH = 0;
  36. private int xHeight = 0;
  37. private int leading = 0;
  38. private int avgWidth = 0;
  39. private int maxWidth = 0;
  40. private int missingWidth = 0;
  41. private AbstractPDFStream fontfile;
  42. // private String charSet = null;
  43. private FontType subtype;
  44. /**
  45. * Create the /FontDescriptor object
  46. *
  47. * @param ascent the maximum height above the baseline
  48. * @param descent the maximum depth below the baseline
  49. * @param capHeight height of the capital letters
  50. * @param flags various characteristics of the font
  51. * @param fontBBox the bounding box for the described font
  52. * @param basefont the base font name
  53. * @param italicAngle the angle of the vertical dominant strokes
  54. * @param stemV the width of the dominant vertical stems of glyphs
  55. */
  56. public PDFFontDescriptor(String basefont, int ascent,
  57. int descent, int capHeight, int flags,
  58. PDFRectangle fontBBox, int italicAngle,
  59. int stemV) {
  60. /* generic creation of PDF object */
  61. super();
  62. /* set fields using paramaters */
  63. this.basefont = basefont;
  64. this.ascent = ascent;
  65. this.descent = descent;
  66. this.capHeight = capHeight;
  67. this.flags = flags;
  68. this.fontBBox = fontBBox;
  69. this.italicAngle = italicAngle;
  70. this.stemV = stemV;
  71. }
  72. /**
  73. * Set the optional metrics.
  74. * @param avgWidth The average width of characters in this font.
  75. * The default value is 0.
  76. * @param maxWidth The maximum width of characters in this font.
  77. * The default value is 0.
  78. * @param missingWidth missing width
  79. * @param leading the desired spacing between lines of text.
  80. * The default value is 0.
  81. * @param stemH The vertical width of the dominant horizontal stems of
  82. * glyphs in the font. The default value is 0.
  83. * @param xHeight The y-coordinate of the top of flat non-ascending
  84. * lowercase letters, measured from the baseline. The default value is 0.
  85. */
  86. public void setMetrics(int avgWidth, int maxWidth, int missingWidth,
  87. int leading, int stemH, int xHeight) {
  88. this.avgWidth = avgWidth;
  89. this.maxWidth = maxWidth;
  90. this.missingWidth = missingWidth;
  91. this.leading = leading;
  92. this.stemH = stemH;
  93. this.xHeight = xHeight;
  94. }
  95. /**
  96. * Set the optional font file stream
  97. *
  98. * @param subtype the font type defined in the font stream
  99. * @param fontfile the stream containing an embedded font
  100. */
  101. public void setFontFile(FontType subtype, AbstractPDFStream fontfile) {
  102. this.subtype = subtype;
  103. this.fontfile = fontfile;
  104. }
  105. // public void setCharSet(){}//for subset fonts
  106. /**
  107. * @see org.apache.fop.pdf.PDFObject#toPDFString()
  108. */
  109. public String toPDFString() {
  110. StringBuffer p = new StringBuffer(128);
  111. p.append(getObjectID()
  112. + "<< /Type /FontDescriptor"
  113. + "\n/FontName /" + this.basefont);
  114. p.append("\n/FontBBox ");
  115. p.append(fontBBox.toPDFString());
  116. p.append("\n/Flags ");
  117. p.append(flags);
  118. p.append("\n/CapHeight ");
  119. p.append(capHeight);
  120. p.append("\n/Ascent ");
  121. p.append(ascent);
  122. p.append("\n/Descent ");
  123. p.append(descent);
  124. p.append("\n/ItalicAngle ");
  125. p.append(italicAngle);
  126. p.append("\n/StemV ");
  127. p.append(stemV);
  128. // optional fields
  129. if (stemH != 0) {
  130. p.append("\n/StemH ");
  131. p.append(stemH);
  132. }
  133. if (xHeight != 0) {
  134. p.append("\n/XHeight ");
  135. p.append(xHeight);
  136. }
  137. if (avgWidth != 0) {
  138. p.append("\n/AvgWidth ");
  139. p.append(avgWidth);
  140. }
  141. if (maxWidth != 0) {
  142. p.append("\n/MaxWidth ");
  143. p.append(maxWidth);
  144. }
  145. if (missingWidth != 0) {
  146. p.append("\n/MissingWidth ");
  147. p.append(missingWidth);
  148. }
  149. if (leading != 0) {
  150. p.append("\n/Leading ");
  151. p.append(leading);
  152. }
  153. if (fontfile != null) {
  154. if (subtype == FontType.TYPE1) {
  155. p.append("\n/FontFile ");
  156. } else {
  157. p.append("\n/FontFile2 ");
  158. }
  159. p.append(fontfile.referencePDF());
  160. }
  161. // charSet for subset fonts // not yet implemented
  162. // CID optional field
  163. fillInPDF(p);
  164. p.append(" >>\nendobj\n");
  165. return p.toString();
  166. }
  167. /**
  168. * Fill in the specifics for the font's descriptor.
  169. * <p>
  170. * The given buffer already contains the fields common to all descriptors.
  171. *
  172. * @param begin the buffer to be completed with the specific fields
  173. */
  174. protected void fillInPDF(StringBuffer begin) {
  175. //nop
  176. }
  177. }