1 29 30 package com.caucho.quercus.lib.pdf; 31 32 import com.caucho.util.L10N; 33 34 import java.io.IOException ; 35 import java.util.logging.Logger ; 36 37 40 public class PDFFont extends PDFObject { 41 private static final Logger log 42 = Logger.getLogger(PDFFont.class.getName()); 43 private static final L10N L = new L10N(PDFFont.class); 44 45 private int _id; 46 47 private final Font _face; 48 49 private final String _encoding; 50 private final String _opt; 51 52 PDFFont(Font face, String encoding, String opt) 53 { 54 _face = face; 55 _encoding = encoding; 56 _opt = opt; 57 } 58 59 void setId(int id) 60 { 61 _id = id; 62 } 63 64 public int getId() 65 { 66 return _id; 67 } 68 69 public String getFontName() 70 { 71 return _face.getFontName(); 72 } 73 74 public String getFontStyle() 75 { 76 return _face.getWeight(); 77 } 78 79 public double getAscender() 80 { 81 return _face.getAscender(); 82 } 83 84 public double getCapHeight() 85 { 86 return _face.getCapHeight(); 87 } 88 89 public double getDescender() 90 { 91 return _face.getDescender(); 92 } 93 94 public double stringWidth(String text) 95 { 96 return _face.stringWidth(text); 97 } 98 99 public String getPDFName() 100 { 101 return "F" + _id; 102 } 103 104 String getResource() 105 { 106 return("/Font << /F" + _id + " " + _id + " 0 R>>"); 107 } 108 109 public void writeObject(PDFWriter out) 110 throws IOException 111 { 112 out.println("<< /Type /Font"); 113 out.println(" /Subtype /Type1"); 114 out.println(" /Name /" + _face.getFontName()); 115 out.println(" /BaseFont /Helvetica"); 116 out.println(" /Encoding /MacRomanEncoding"); 117 out.println(">>"); 118 } 119 120 public int hashCode() 121 { 122 int hash = 37; 123 124 hash = 65521 * hash + _face.hashCode(); 125 hash = 65521 * hash + _encoding.hashCode(); 126 hash = 65521 * hash + _opt.hashCode(); 127 128 return hash; 129 } 130 131 public boolean equals(Object o) 132 { 133 if (this == o) 134 return true; 135 else if (! (o instanceof PDFFont)) 136 return false; 137 138 PDFFont font = (PDFFont) o; 139 140 return (_face == font._face && 141 _encoding.equals(font._encoding) && 142 _opt.equals(font._opt)); 143 } 144 145 public String toString() 146 { 147 return "PDFFont[" + _face.getFontName() + "," + _encoding + "," + _opt + "]"; 148 } 149 } 150 | Popular Tags |