1 47 48 package com.lowagie.text.pdf; 49 import java.util.HashMap ; 50 51 import com.lowagie.text.Rectangle; 52 53 56 57 public class PdfAppearance extends PdfTemplate { 58 59 public static final HashMap stdFieldFontNames = new HashMap (); 60 static { 61 stdFieldFontNames.put("Courier-BoldOblique", new PdfName("CoBO")); 62 stdFieldFontNames.put("Courier-Bold", new PdfName("CoBo")); 63 stdFieldFontNames.put("Courier-Oblique", new PdfName("CoOb")); 64 stdFieldFontNames.put("Courier", new PdfName("Cour")); 65 stdFieldFontNames.put("Helvetica-BoldOblique", new PdfName("HeBO")); 66 stdFieldFontNames.put("Helvetica-Bold", new PdfName("HeBo")); 67 stdFieldFontNames.put("Helvetica-Oblique", new PdfName("HeOb")); 68 stdFieldFontNames.put("Helvetica", PdfName.HELV); 69 stdFieldFontNames.put("Symbol", new PdfName("Symb")); 70 stdFieldFontNames.put("Times-BoldItalic", new PdfName("TiBI")); 71 stdFieldFontNames.put("Times-Bold", new PdfName("TiBo")); 72 stdFieldFontNames.put("Times-Italic", new PdfName("TiIt")); 73 stdFieldFontNames.put("Times-Roman", new PdfName("TiRo")); 74 stdFieldFontNames.put("ZapfDingbats", PdfName.ZADB); 75 stdFieldFontNames.put("HYSMyeongJo-Medium", new PdfName("HySm")); 76 stdFieldFontNames.put("HYGoThic-Medium", new PdfName("HyGo")); 77 stdFieldFontNames.put("HeiseiKakuGo-W5", new PdfName("KaGo")); 78 stdFieldFontNames.put("HeiseiMin-W3", new PdfName("KaMi")); 79 stdFieldFontNames.put("MHei-Medium", new PdfName("MHei")); 80 stdFieldFontNames.put("MSung-Light", new PdfName("MSun")); 81 stdFieldFontNames.put("STSong-Light", new PdfName("STSo")); 82 stdFieldFontNames.put("MSungStd-Light", new PdfName("MSun")); 83 stdFieldFontNames.put("STSongStd-Light", new PdfName("STSo")); 84 stdFieldFontNames.put("HYSMyeongJoStd-Medium", new PdfName("HySm")); 85 stdFieldFontNames.put("KozMinPro-Regular", new PdfName("KaMi")); 86 } 87 88 91 92 PdfAppearance() { 93 super(); 94 separator = ' '; 95 } 96 97 PdfAppearance(PdfIndirectReference iref) { 98 thisReference = iref; 99 } 100 101 106 107 PdfAppearance(PdfWriter wr) { 108 super(wr); 109 separator = ' '; 110 } 111 112 120 public static PdfAppearance createAppearance(PdfWriter writer, float width, float height) { 121 return createAppearance(writer, width, height, null); 122 } 123 124 static PdfAppearance createAppearance(PdfWriter writer, float width, float height, PdfName forcedName) { 125 PdfAppearance template = new PdfAppearance(writer); 126 template.setWidth(width); 127 template.setHeight(height); 128 writer.addDirectTemplateSimple(template, forcedName); 129 return template; 130 } 131 132 138 public void setFontAndSize(BaseFont bf, float size) { 139 checkWriter(); 140 state.size = size; 141 if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { 142 state.fontDetails = new FontDetails(null, ((DocumentFont)bf).getIndirectReference(), bf); 143 } 144 else 145 state.fontDetails = writer.addSimple(bf); 146 PdfName psn = (PdfName)stdFieldFontNames.get(bf.getPostscriptFontName()); 147 if (psn == null) { 148 if (bf.isSubset() && bf.getFontType() == BaseFont.FONT_TYPE_TTUNI) 149 psn = state.fontDetails.getFontName(); 150 else { 151 psn = new PdfName(bf.getPostscriptFontName()); 152 state.fontDetails.setSubset(false); 153 } 154 } 155 PageResources prs = getPageResources(); 156 prs.addFont(psn, state.fontDetails.getIndirectReference()); 158 content.append(psn.getBytes()).append(' ').append(size).append(" Tf").append_i(separator); 159 } 160 161 public PdfContentByte getDuplicate() { 162 PdfAppearance tpl = new PdfAppearance(); 163 tpl.writer = writer; 164 tpl.pdf = pdf; 165 tpl.thisReference = thisReference; 166 tpl.pageResources = pageResources; 167 tpl.bBox = new Rectangle(bBox); 168 tpl.group = group; 169 tpl.layer = layer; 170 if (matrix != null) { 171 tpl.matrix = new PdfArray(matrix); 172 } 173 tpl.separator = separator; 174 return tpl; 175 } 176 } | Popular Tags |