1 31 package org.pdfbox.pdmodel.font; 32 33 import java.io.IOException ; 34 import java.util.Map ; 35 36 import org.pdfbox.cos.COSDictionary; 37 import org.pdfbox.cos.COSName; 38 39 45 public class PDFontFactory 46 { 47 50 private PDFontFactory() 51 { 52 } 53 54 63 public static PDFont createFont( COSDictionary dic, Map fontCache ) throws IOException 64 { 65 PDFont font = null; 66 if( fontCache != null ) 67 { 68 font = (PDFont)fontCache.get( dic ); 69 } 70 if( font == null ) 71 { 72 font = createFont( dic ); 73 if( fontCache != null ) 74 { 75 fontCache.put( dic, font ); 76 } 77 } 78 return font; 79 } 80 81 90 public static PDFont createFont( COSDictionary dic ) throws IOException 91 { 92 PDFont retval = null; 93 94 COSName type = (COSName)dic.getDictionaryObject( COSName.TYPE ); 95 if( !type.equals( COSName.FONT ) ) 96 { 97 throw new IOException ( "Cannot create font if /Type is not /Font. Actual=" +type ); 98 } 99 100 COSName subType = (COSName)dic.getDictionaryObject( COSName.SUBTYPE ); 101 if( subType.equals( COSName.getPDFName( "Type1" ) ) ) 102 { 103 retval = new PDType1Font( dic ); 104 } 105 else if( subType.equals( COSName.getPDFName( "MMType1" ) ) ) 106 { 107 retval = new PDMMType1Font( dic ); 108 } 109 else if( subType.equals( COSName.getPDFName( "TrueType" ) ) ) 110 { 111 retval = new PDTrueTypeFont( dic ); 112 } 113 else if( subType.equals( COSName.getPDFName( "Type3" ) ) ) 114 { 115 retval = new PDType3Font( dic ); 116 } 117 else if( subType.equals( COSName.getPDFName( "Type0" ) ) ) 118 { 119 retval = new PDType0Font( dic ); 120 } 121 else if( subType.equals( COSName.getPDFName( "CIDFontType0" ) ) ) 122 { 123 retval = new PDCIDFontType0Font( dic ); 124 } 125 else if( subType.equals( COSName.getPDFName( "CIDFontType2" ) ) ) 126 { 127 retval = new PDCIDFontType2Font( dic ); 128 } 129 else 130 { 131 throw new IOException ( "Unknown font subtype=" + subType ); 132 } 133 134 return retval; 135 } 136 } | Popular Tags |