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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf;
19 import org.apache.pdfbox.cos.COSArray;
20 import org.apache.pdfbox.cos.COSBase;
21 import org.apache.pdfbox.cos.COSNull;
22 import org.apache.pdfbox.pdmodel.common.COSObjectable;
23 import org.apache.pdfbox.pdmodel.graphics.color.PDGamma;
26 * An object for four colours.
28 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
29 * @version $Revision: $
31 public class PDFourColours implements COSObjectable
34 private COSArray array;
36 public PDFourColours()
38 this.array = new COSArray();
39 this.array.add(COSNull.NULL);
40 this.array.add(COSNull.NULL);
41 this.array.add(COSNull.NULL);
42 this.array.add(COSNull.NULL);
45 public PDFourColours(COSArray array)
48 // ensure that array has 4 items
49 if (this.array.size() < 4)
51 for (int i = (this.array.size() - 1); i < 4; i++)
53 this.array.add(COSNull.NULL);
60 * Gets the colour for the before edge.
62 * @return the colour for the before edge
64 public PDGamma getBeforeColour()
66 return this.getColourByIndex(0);
70 * Sets the colour for the before edge.
72 * @param colour the colour for the before edge
74 public void setBeforeColour(PDGamma colour)
76 this.setColourByIndex(0, colour);
80 * Gets the colour for the after edge.
82 * @return the colour for the after edge
84 public PDGamma getAfterColour()
86 return this.getColourByIndex(1);
90 * Sets the colour for the after edge.
92 * @param colour the colour for the after edge
94 public void setAfterColour(PDGamma colour)
96 this.setColourByIndex(1, colour);
100 * Gets the colour for the start edge.
102 * @return the colour for the start edge
104 public PDGamma getStartColour()
106 return this.getColourByIndex(2);
110 * Sets the colour for the start edge.
112 * @param colour the colour for the start edge
114 public void setStartColour(PDGamma colour)
116 this.setColourByIndex(2, colour);
120 * Gets the colour for the end edge.
122 * @return the colour for the end edge
124 public PDGamma getEndColour()
126 return this.getColourByIndex(3);
130 * Sets the colour for the end edge.
132 * @param colour the colour for the end edge
134 public void setEndColour(PDGamma colour)
136 this.setColourByIndex(3, colour);
143 public COSBase getCOSObject()
150 * Gets the colour by edge index.
152 * @param index edge index
155 private PDGamma getColourByIndex(int index)
157 PDGamma retval = null;
158 COSBase item = this.array.getObject(index);
159 if (item instanceof COSArray)
161 retval = new PDGamma((COSArray) item);
167 * Sets the colour by edge index.
169 * @param index the edge index
170 * @param colour the colour
172 private void setColourByIndex(int index, PDGamma colour)
181 base = colour.getCOSArray();
183 this.array.set(index, base);