1 31 package org.pdfbox.pdmodel.documentinterchange.prepress; 32 33 import org.pdfbox.cos.COSArray; 34 import org.pdfbox.cos.COSBase; 35 import org.pdfbox.cos.COSDictionary; 36 import org.pdfbox.cos.COSInteger; 37 import org.pdfbox.pdmodel.common.COSObjectable; 38 import org.pdfbox.pdmodel.graphics.PDLineDashPattern; 39 import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; 40 import org.pdfbox.pdmodel.graphics.color.PDDeviceRGB; 41 42 48 public class PDBoxStyle implements COSObjectable 49 { 50 53 public static final String GUIDELINE_STYLE_SOLID = "S"; 54 57 public static final String GUIDELINE_STYLE_DASHED = "D"; 58 59 private COSDictionary dictionary; 60 61 65 public PDBoxStyle() 66 { 67 dictionary = new COSDictionary(); 68 } 69 70 75 public PDBoxStyle( COSDictionary dic ) 76 { 77 dictionary = dic; 78 } 79 80 85 public COSBase getCOSObject() 86 { 87 return dictionary; 88 } 89 90 95 public COSDictionary getDictionary() 96 { 97 return dictionary; 98 } 99 100 107 public PDColorSpaceInstance getGuidelineColor() 108 { 109 COSArray colorValues = (COSArray)dictionary.getDictionaryObject( "C" ); 110 if( colorValues == null ) 111 { 112 colorValues = new COSArray(); 113 colorValues.add( COSInteger.ZERO ); 114 colorValues.add( COSInteger.ZERO ); 115 colorValues.add( COSInteger.ZERO ); 116 dictionary.setItem( "C", colorValues ); 117 } 118 PDColorSpaceInstance instance = new PDColorSpaceInstance( colorValues ); 119 instance.setColorSpace( PDDeviceRGB.INSTANCE ); 120 return instance; 121 } 122 123 129 public void setGuideLineColor( PDColorSpaceInstance color ) 130 { 131 COSArray values = null; 132 if( color != null ) 133 { 134 values = color.getCOSColorSpaceValue(); 135 } 136 dictionary.setItem( "C", values ); 137 } 138 139 145 public float getGuidelineWidth() 146 { 147 return dictionary.getFloat( "W", 1 ); 148 } 149 150 155 public void setGuidelineWidth( float width ) 156 { 157 dictionary.setFloat( "W", width ); 158 } 159 160 167 public String getGuidelineStyle() 168 { 169 return dictionary.getNameAsString( "S", GUIDELINE_STYLE_SOLID ); 170 } 171 172 179 public void setGuidelineStyle( String style ) 180 { 181 dictionary.setName( "S", style ); 182 } 183 184 190 public PDLineDashPattern getLineDashPattern() 191 { 192 PDLineDashPattern pattern = null; 193 COSArray d = (COSArray)dictionary.getDictionaryObject( "D" ); 194 if( d == null ) 195 { 196 d = new COSArray(); 197 d.add( new COSInteger(3) ); 198 dictionary.setItem( "D", d ); 199 } 200 COSArray lineArray = new COSArray(); 201 lineArray.add( d ); 202 lineArray.add( new COSInteger( 0 ) ); 204 pattern = new PDLineDashPattern( lineArray ); 205 return pattern; 206 } 207 208 213 public void setLineDashPattern( PDLineDashPattern pattern ) 214 { 215 COSArray array = null; 216 if( pattern != null ) 217 { 218 array = pattern.getCOSDashPattern(); 219 } 220 dictionary.setItem( "D", array ); 221 } 222 } | Popular Tags |