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