1 31 package org.pdfbox.pdmodel.graphics; 32 33 import org.pdfbox.cos.COSArray; 34 import org.pdfbox.cos.COSBase; 35 import org.pdfbox.cos.COSDictionary; 36 import org.pdfbox.cos.COSFloat; 37 import org.pdfbox.cos.COSNumber; 38 39 import org.pdfbox.pdmodel.common.COSObjectable; 40 41 import org.pdfbox.pdmodel.font.PDFont; 42 import org.pdfbox.pdmodel.font.PDFontFactory; 43 44 import java.io.IOException ; 45 46 53 public class PDFontSetting implements COSObjectable 54 { 55 private COSArray fontSetting = null; 56 57 60 public PDFontSetting() 61 { 62 fontSetting = new COSArray(); 63 fontSetting.add( null ); 64 fontSetting.add( new COSFloat( 1 ) ); 65 } 66 67 72 public PDFontSetting( COSArray fs ) 73 { 74 fontSetting = fs; 75 } 76 77 80 public COSBase getCOSObject() 81 { 82 return fontSetting; 83 } 84 85 92 public PDFont getFont() throws IOException 93 { 94 PDFont retval = null; 95 COSBase font = fontSetting.get( 0 ); 96 if( font instanceof COSDictionary ) 97 { 98 retval = PDFontFactory.createFont( (COSDictionary)font ); 99 } 100 return retval; 101 } 102 103 108 public void setFont( PDFont font ) 109 { 110 fontSetting.set( 0, font ); 111 } 112 113 118 public float getFontSize() 119 { 120 COSNumber size = (COSNumber)fontSetting.get( 1 ); 121 return size.floatValue(); 122 } 123 124 129 public void setFontSize( float size ) 130 { 131 fontSetting.set( 1, new COSFloat( size ) ); 132 } 133 } | Popular Tags |