1 51 package org.apache.fop.render.pdf.fonts; 52 53 import org.apache.fop.render.pdf.Font; 54 import org.apache.fop.layout.FontDescriptor; 55 import org.apache.fop.pdf.PDFStream; 56 import org.apache.fop.messaging.MessageHandler; 57 58 import java.util.Map ; 59 import java.net.URL ; 60 61 import org.apache.fop.render.pdf.FontReader; 62 63 public class LazyFont extends Font implements FontDescriptor { 64 65 private URL metricsFile = null; 66 private URL fontEmbedPath = null; 67 private boolean useKerning = false; 68 69 private boolean isMetricsLoaded = false; 70 private Font realFont = null; 71 private FontDescriptor realFontDescriptor = null; 72 73 public LazyFont(URL fontEmbedPath, URL metricsFile, boolean useKerning){ 74 this.metricsFile = metricsFile; 75 this.fontEmbedPath = fontEmbedPath; 76 this.useKerning = useKerning; 77 } 78 79 private void load(){ 80 if (!isMetricsLoaded) { 81 isMetricsLoaded = true; 82 try{ 83 FontReader reader = new FontReader(metricsFile); 84 reader.useKerning(useKerning); 85 reader.setFontEmbedPath(fontEmbedPath); 86 realFont = reader.getFont(); 87 if(realFont instanceof FontDescriptor){ 88 realFontDescriptor = (FontDescriptor) realFont; 89 } 90 } catch (Exception ex) { 92 MessageHandler.error("Failed to read font metrics file " 93 + metricsFile.toExternalForm() 94 + ": " + ex.getMessage()); 95 } 96 } 97 } 98 99 public Font getRealFont(){ 100 return realFont; 101 } 102 103 public String encoding(){ 105 load(); 106 return realFont.encoding(); 107 } 108 109 public String fontName(){ 110 load(); 111 return realFont.fontName(); 112 } 113 114 public byte getSubType(){ 115 load(); 116 return realFont.getSubType(); 117 } 118 119 public char mapChar(char c){ 120 load(); 121 return realFont.mapChar(c); 122 } 123 124 public int getAscender(int size){ 126 load(); 127 return realFont.getAscender(size); 128 } 129 130 public int getCapHeight(int size){ 131 load(); 132 return realFont.getCapHeight(size); 133 } 134 135 public int getDescender(int size){ 136 load(); 137 return realFont.getDescender(size); 138 } 139 140 public int getXHeight(int size){ 141 load(); 142 return realFont.getXHeight(size); 143 } 144 145 public int getFirstChar(){ 146 load(); 147 return realFont.getFirstChar(); 148 } 149 150 public int getLastChar(){ 151 load(); 152 return realFont.getLastChar(); 153 } 154 155 public int width(int i, int size){ 156 load(); 157 return realFont.width(i, size); 158 } 159 160 public int[] getWidths(int size){ 161 load(); 162 return realFont.getWidths(size); 163 } 164 165 public int getCapHeight(){ 167 load(); 168 return realFontDescriptor.getCapHeight(); 169 } 170 171 public int getDescender(){ 172 load(); 173 return realFontDescriptor.getDescender(); 174 } 175 176 public int getAscender(){ 177 load(); 178 return realFontDescriptor.getAscender(); 179 } 180 181 public int getFlags(){ 182 load(); 183 return realFontDescriptor.getFlags(); 184 } 185 186 public int[] getFontBBox(){ 187 load(); 188 return realFontDescriptor.getFontBBox(); 189 } 190 191 public int getItalicAngle(){ 192 load(); 193 return realFontDescriptor.getItalicAngle(); 194 } 195 196 public int getStemV(){ 197 load(); 198 return realFontDescriptor.getStemV(); 199 } 200 201 public boolean hasKerningInfo(){ 202 load(); 203 return realFontDescriptor.hasKerningInfo(); 204 } 205 206 public Map getKerningInfo(){ 207 load(); 208 return realFontDescriptor.getKerningInfo(); 209 } 210 211 public boolean isEmbeddable(){ 212 load(); 213 return realFontDescriptor.isEmbeddable(); 214 } 215 216 public PDFStream getFontFile(int objNum){ 217 load(); 218 return realFontDescriptor.getFontFile(objNum); 219 } 220 } 221 222 | Popular Tags |