1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.annotation; 18 19 import org.apache.pdfbox.cos.COSBase; 20 import org.apache.pdfbox.cos.COSDictionary; 21 import org.apache.pdfbox.cos.COSArray; 22 import org.apache.pdfbox.cos.COSInteger; 23 24 import org.apache.pdfbox.pdmodel.common.COSObjectable; 25 import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern; 26 27 /** 28 * This class represents a PDF /BS entry the border style dictionary. 29 * 30 * @author Paul King 31 * @version $Revision: 1.1 $ 32 */ 33 public class PDBorderStyleDictionary implements COSObjectable 34 { 35 36 /* 37 * The various values of the style for the border as defined in the PDF 1.6 38 * reference Table 8.13 39 */ 40 41 /** 42 * Constant for the name of a solid style. 43 */ 44 public static final String STYLE_SOLID = "S"; 45 46 /** 47 * Constant for the name of a dashed style. 48 */ 49 public static final String STYLE_DASHED = "D"; 50 51 /** 52 * Constant for the name of a beveled style. 53 */ 54 public static final String STYLE_BEVELED = "B"; 55 56 /** 57 * Constant for the name of a inset style. 58 */ 59 public static final String STYLE_INSET = "I"; 60 61 /** 62 * Constant for the name of a underline style. 63 */ 64 public static final String STYLE_UNDERLINE = "U"; 65 66 private COSDictionary dictionary; 67 68 /** 69 * Constructor. 70 */ 71 public PDBorderStyleDictionary() 72 { 73 dictionary = new COSDictionary(); 74 } 75 76 /** 77 * Constructor. 78 * 79 * @param dict 80 * a border style dictionary. 81 */ 82 public PDBorderStyleDictionary( COSDictionary dict ) 83 { 84 dictionary = dict; 85 } 86 87 /** 88 * returns the dictionary. 89 * 90 * @return the dictionary 91 */ 92 public COSDictionary getDictionary() 93 { 94 return dictionary; 95 } 96 97 /** 98 * returns the dictionary. 99 * 100 * @return the dictionary 101 */ 102 public COSBase getCOSObject() 103 { 104 return dictionary; 105 } 106 107 /** 108 * This will set the border width in points, 0 = no border. 109 * 110 * @param w 111 * float the width in points 112 */ 113 public void setWidth( float w ) 114 { 115 getDictionary().setFloat( "W", w ); 116 } 117 118 /** 119 * This will retrieve the border width in points, 0 = no border. 120 * 121 * @return flaot the width of the border in points 122 */ 123 public float getWidth() 124 { 125 return getDictionary().getFloat( "W", 1 ); 126 } 127 128 /** 129 * This will set the border style, see the STYLE_* constants for valid values. 130 * 131 * @param s 132 * the border style to use 133 */ 134 public void setStyle( String s ) 135 { 136 getDictionary().setName( "S", s ); 137 } 138 139 /** 140 * This will retrieve the border style, see the STYLE_* constants for valid 141 * values. 142 * 143 * @return the style of the border 144 */ 145 public String getStyle() 146 { 147 return getDictionary().getNameAsString( "S", STYLE_SOLID ); 148 } 149 150 /** 151 * This will set the dash style used for drawing the border. 152 * 153 * @param d 154 * the dash style to use 155 */ 156 public void setDashStyle( PDLineDashPattern d ) 157 { 158 COSArray array = null; 159 if( d != null ) 160 { 161 array = d.getCOSDashPattern(); 162 } 163 getDictionary().setItem( "D", array ); 164 } 165 166 /** 167 * This will retrieve the dash style used for drawing the border. 168 * 169 * @return the dash style of the border 170 */ 171 public PDLineDashPattern getDashStyle() 172 { 173 COSArray d = (COSArray) getDictionary().getDictionaryObject( "D" ); 174 if (d == null) 175 { 176 d = new COSArray(); 177 d.add( COSInteger.THREE ); 178 getDictionary().setItem( "D", d ); 179 } 180 return new PDLineDashPattern( d, 0 ); 181 } 182 183 }