You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2011/08/25 18:34:42 UTC
svn commit: r1161633 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/ pdmodel/
pdmodel/graphics/shading/
Author: lehmi
Date: Thu Aug 25 16:34:41 2011
New Revision: 1161633
URL: http://svn.apache.org/viewvc?rev=1161633&view=rev
Log:
PDFBOX-615: added support for shading resources
Added:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java (with props)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java (with props)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java (with props)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java (with props)
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html (with props)
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1161633&r1=1161632&r2=1161633&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Thu Aug 25 16:34:41 2011
@@ -60,7 +60,7 @@ public final class COSName extends COSBa
*/
public static final COSName ACRO_FORM = new COSName( "AcroForm" );
/**
- * "ActualText"
+ * A common COSName value.
*/
public static final COSName ACTUAL_TEXT = new COSName("ActualText");
/**
@@ -68,11 +68,11 @@ public final class COSName extends COSBa
*/
public static final COSName AIS = new COSName( "AIS" );
/**
- * "Alt"
+ * A common COSName value.
*/
public static final COSName ALT = new COSName("Alt");
/**
- * "Alt"
+ * A common COSName value.
*/
public static final COSName ALTERNATE = new COSName("Alternate");
/**
@@ -92,7 +92,7 @@ public final class COSName extends COSBa
*/
public static final COSName AP_REF = new COSName( "APRef" );
/**
- * "Artifact"
+ * A common COSName value.
*/
public static final COSName ARTIFACT = new COSName("Artifact");
/**
@@ -112,7 +112,7 @@ public final class COSName extends COSBa
*/
public static final COSName ASCII85_DECODE_ABBREVIATION = new COSName( "A85" );
/**
- * "Attached"
+ * A common COSName value.
*/
public static final COSName ATTACHED = new COSName("Attached");
/**
@@ -128,7 +128,9 @@ public final class COSName extends COSBa
*/
public static final COSName ASCII_HEX_DECODE_ABBREVIATION = new COSName( "AHx" );
- /** "AP" */
+ /**
+ * A common COSName value.
+ */
public static final COSName AP = new COSName( "AP" );
/**
@@ -148,6 +150,10 @@ public final class COSName extends COSBa
/**
* A common COSName value.
*/
+ public static final COSName BACKGROUND = new COSName( "Background" );
+ /**
+ * A common COSName value.
+ */
public static final COSName BASE_ENCODING = new COSName( "BaseEncoding" );
/**
* A common COSName value.
@@ -195,7 +201,7 @@ public final class COSName extends COSBa
*/
public static final COSName CATALOG = new COSName( "Catalog" );
/**
- * "C"
+ * A common COSName value.
*/
public static final COSName C = new COSName("C");
/**
@@ -311,17 +317,17 @@ public final class COSName extends COSBa
*/
public static final COSName CROP_BOX = new COSName( "CropBox" );
/**
- * The Crypt filter.
+ * A common COSName value.
*/
public static final COSName CRYPT = new COSName( "Crypt" );
/**
* A common COSName value.
*/
public static final COSName CS = new COSName( "CS" );
-
- /** "D" */
+ /**
+ * A common COSName value.
+ */
public static final COSName D = new COSName( "D" );
-
/**
* A common COSName value.
*/
@@ -339,7 +345,9 @@ public final class COSName extends COSBa
* A common COSName value.
*/
public static final COSName DECODE = new COSName( "Decode" );
- /** "DecodeParms" */
+ /**
+ * A common COSName value.
+ */
public static final COSName DECODE_PARMS = new COSName( "DecodeParms" );
/**
@@ -355,7 +363,9 @@ public final class COSName extends COSBa
*/
public static final COSName DEST = new COSName( "Dest" );
- /** "Dests" */
+ /**
+ * A common COSName value.
+ */
public static final COSName DESTS = new COSName( "Dests" );
/**
@@ -379,7 +389,9 @@ public final class COSName extends COSBa
*/
public static final COSName DIFFERENCES = new COSName( "Differences" );
- /** "DL" */
+ /**
+ * A common COSName value.
+ */
public static final COSName DL = new COSName( "DL" );
/**
@@ -387,7 +399,9 @@ public final class COSName extends COSBa
*/
public static final COSName DOMAIN = new COSName( "Domain" );
- /** "DP" */
+ /**
+ * A common COSName value.
+ */
public static final COSName DP = new COSName( "DP" );
/**
@@ -404,11 +418,13 @@ public final class COSName extends COSBa
public static final COSName DW = new COSName( "DW" );
/**
- * "E"
+ * A common COSName value.
*/
public static final COSName E = new COSName("E");
- /** "EmbeddedFiles" */
+ /**
+ * A common COSName value.
+ */
public static final COSName EMBEDDED_FILES = new COSName( "EmbeddedFiles" );
/**
@@ -436,13 +452,19 @@ public final class COSName extends COSBa
*/
public static final COSName ENCODING_ETEN_B5_V = new COSName( "ETen?B5?V" );
- /** "Encrypt" */
+ /**
+ * A common COSName value.
+ */
public static final COSName ENCRYPT = new COSName( "Encrypt" );
- /** "EncryptMetaData" */
+ /**
+ * A common COSName value.
+ */
public static final COSName ENCRYPT_META_DATA = new COSName( "EncryptMetadata" );
- /** "ExtGState" */
+ /**
+ * A common COSName value.
+ */
public static final COSName EXT_G_STATE = new COSName( "ExtGState" );
/**
@@ -450,16 +472,24 @@ public final class COSName extends COSBa
*/
public static final COSName EXTEND = new COSName( "Extend" );
- /** "Extends" */
+ /**
+ * A common COSName value.
+ */
public static final COSName EXTENDS = new COSName( "Extends" );
- /** "F" */
+ /**
+ * A common COSName value.
+ */
public static final COSName F = new COSName( "F" );
- /** "FDecodeParms" */
+ /**
+ * A common COSName value.
+ */
public static final COSName F_DECODE_PARMS = new COSName( "FDecodeParms" );
- /** "FFilter" */
+ /**
+ * A common COSName value.
+ */
public static final COSName F_FILTER = new COSName( "FFilter" );
/**
@@ -583,10 +613,14 @@ public final class COSName extends COSBa
*/
public static final COSName ICCBASED = new COSName( "ICCBased" );
- /** "ID" */
+ /**
+ * A common COSName value.
+ */
public static final COSName ID = new COSName("ID");
- /** "IDTree" */
+ /**
+ * A common COSName value.
+ */
public static final COSName ID_TREE = new COSName("IDTree");
/**
@@ -606,7 +640,9 @@ public final class COSName extends COSBa
*/
public static final COSName IMAGE_MASK = new COSName( "ImageMask" );
- /** "Index" */
+ /**
+ * A common COSName value.
+ */
public static final COSName INDEX = new COSName( "Index" );
/**
@@ -622,7 +658,9 @@ public final class COSName extends COSBa
*/
public static final COSName ITALIC_ANGLE = new COSName( "ItalicAngle" );
- /** "JavaScript" */
+ /**
+ * A common COSName value.
+ */
public static final COSName JAVA_SCRIPT = new COSName( "JavaScript" );
/**
@@ -634,7 +672,9 @@ public final class COSName extends COSBa
*/
public static final COSName JPX_DECODE = new COSName( "JPXDecode" );
- /** "K" */
+ /**
+ * A common COSName value.
+ */
public static final COSName K = new COSName("K");
/**
@@ -642,7 +682,9 @@ public final class COSName extends COSBa
*/
public static final COSName KEYWORDS = new COSName( "Keywords" );
- /** "Kids" */
+ /**
+ * A common COSName value.
+ */
public static final COSName KIDS = new COSName( "Kids" );
/**
@@ -650,7 +692,9 @@ public final class COSName extends COSBa
*/
public static final COSName LAB = new COSName( "Lab" );
- /** "Lang" */
+ /**
+ * A common COSName value.
+ */
public static final COSName LANG = new COSName("Lang");
/**
@@ -674,7 +718,9 @@ public final class COSName extends COSBa
*/
public static final COSName LENGTH1 = new COSName( "Length1" );
- /** "Limits" */
+ /**
+ * A common COSName value.
+ */
public static final COSName LIMITS = new COSName( "Limits" );
/**
* A common COSName value.
@@ -701,7 +747,9 @@ public final class COSName extends COSBa
*/
public static final COSName MAC_ROMAN_ENCODING = new COSName( "MacRomanEncoding" );
- /** "MarkInfo" */
+ /**
+ * A common COSName value.
+ */
public static final COSName MARK_INFO = new COSName("MarkInfo");
/**
@@ -717,7 +765,7 @@ public final class COSName extends COSBa
*/
public static final COSName MAX_WIDTH = new COSName( "MaxWidth" );
/**
- * "MCID"
+ * A common COSName value.
*/
public static final COSName MCID = new COSName("MCID");
/**
@@ -753,7 +801,9 @@ public final class COSName extends COSBa
*/
public static final COSName NAME = new COSName( "Name" );
- /** "Names" */
+ /**
+ * A common COSName value.
+ */
public static final COSName NAMES = new COSName( "Names" );
/**
@@ -764,16 +814,17 @@ public final class COSName extends COSBa
* A common COSName value.
*/
public static final COSName NM = new COSName( "NM" );
- /** "Nums" */
+ /**
+ * A common COSName value.
+ */
public static final COSName NUMS = new COSName( "Nums" );
/**
- * "O"
+ * A common COSName value.
*/
public static final COSName O = new COSName("O");
-
/**
- * "Obj"
+ * A common COSName value.
*/
public static final COSName OBJ = new COSName("Obj");
@@ -812,10 +863,14 @@ public final class COSName extends COSBa
* A common COSName value.
*/
public static final COSName OPT = new COSName( "Opt" );
- /** "Outlines" */
+ /**
+ * A common COSName value.
+ */
public static final COSName OUTLINES = new COSName("Outlines");
- /** "OpenAction" */
+ /**
+ * A common COSName value.
+ */
public static final COSName OPEN_ACTION = new COSName("OpenAction");
/** A common COSName value. */
@@ -834,13 +889,19 @@ public final class COSName extends COSBa
*/
public static final COSName PAGE = new COSName( "Page" );
- /** "PageLabels" */
+ /**
+ * A common COSName value.
+ */
public static final COSName PAGE_LABELS = new COSName("PageLabels");
- /** "PageLayout" */
+ /**
+ * A common COSName value.
+ */
public static final COSName PAGE_LAYOUT = new COSName("PageLayout");
- /** "PageMode" */
+ /**
+ * A common COSName value.
+ */
public static final COSName PAGE_MODE = new COSName("PageMode");
/**
@@ -856,7 +917,7 @@ public final class COSName extends COSBa
*/
public static final COSName PARENT = new COSName( "Parent" );
/**
- * "ParentTreeNextKey"
+ * A common COSName value.
*/
public static final COSName PARENT_TREE_NEXT_KEY = new COSName("ParentTreeNextKey");
/**
@@ -872,7 +933,7 @@ public final class COSName extends COSBa
*/
public static final COSName PDF_DOC_ENCODING = new COSName( "PDFDocEncoding" );
/**
- * "Pg"
+ * A common COSName value.
*/
public static final COSName PG = new COSName("Pg");
/**
@@ -924,7 +985,7 @@ public final class COSName extends COSBa
*/
public static final COSName RESOURCES = new COSName( "Resources" );
/**
- * "RoleMap"
+ * A common COSName value.
*/
public static final COSName RI = new COSName( "RI" );
/**
@@ -956,7 +1017,7 @@ public final class COSName extends COSBa
*/
public static final COSName RV = new COSName( "RV" );
/**
- * "S"
+ * A common COSName value.
*/
public static final COSName S = new COSName("S");
/**
@@ -980,7 +1041,9 @@ public final class COSName extends COSBa
*/
public static final COSName SET_FF = new COSName( "SetFf" );
- /** "Shading" */
+ /**
+ * A common COSName value.
+ */
public static final COSName SHADING = new COSName( "Shading" );
/**
* A common COSName value.
@@ -994,7 +1057,9 @@ public final class COSName extends COSBa
* A common COSName value.
*/
public static final COSName SMASK = new COSName( "SMask" );
- /** "Size" */
+ /**
+ * A common COSName value.
+ */
public static final COSName SIZE = new COSName( "Size" );
/**
@@ -1022,7 +1087,9 @@ public final class COSName extends COSBa
*/
public static final COSName STR_F = new COSName( "StrF" );
- /** "StructTreeRoot" */
+ /**
+ * A common COSName value.
+ */
public static final COSName STRUCT_TREE_ROOT = new COSName("StructTreeRoot");
/**
@@ -1047,11 +1114,13 @@ public final class COSName extends COSBa
public static final COSName SUBTYPE = new COSName( "Subtype" );
/**
- * "T"
+ * A common COSName value.
*/
public static final COSName T = new COSName("T");
- /** "Threads" */
+ /**
+ * A common COSName value.
+ */
public static final COSName THREADS = new COSName("Threads");
/**
@@ -1109,7 +1178,9 @@ public final class COSName extends COSBa
public static final COSName U = new COSName( "U" );
/** the COSName for the "Unchanged" value. */
public static final COSName UNCHANGED = new COSName("Unchanged");
- /** "URI" */
+ /**
+ * A common COSName value.
+ */
public static final COSName URI = new COSName("URI");
/**
@@ -1121,7 +1192,9 @@ public final class COSName extends COSBa
*/
public static final COSName VERSION = new COSName( "Version" );
- /** "ViewerPreferences" */
+ /**
+ * A common COSName value.
+ */
public static final COSName VIEWER_PREFERENCES = new COSName("ViewerPreferences");
/**
@@ -1150,7 +1223,9 @@ public final class COSName extends COSBa
*/
public static final COSName XHEIGHT = new COSName( "XHeight" );
- /** "XObject" */
+ /**
+ * A common COSName value.
+ */
public static final COSName XOBJECT = new COSName( "XObject" );
/**
* A common COSName value.
@@ -1202,7 +1277,7 @@ public final class COSName extends COSBa
*/
public static final COSName ADBE_PKCS7_DETACHED = new COSName("adbe.pkcs7.detached");
/**
- * A signature subfilter value.www
+ * A signature subfilter value.
*/
public static final COSName ADBE_PKCS7_SHA1 = new COSName("adbe.pkcs7.sha1");
/**
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java?rev=1161633&r1=1161632&r2=1161633&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDResources.java Thu Aug 25 16:34:41 2011
@@ -33,6 +33,7 @@ import org.apache.pdfbox.pdmodel.graphic
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDPatternResources;
+import org.apache.pdfbox.pdmodel.graphics.shading.PDShadingResources;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
import org.apache.pdfbox.pdmodel.markedcontent.PDPropertyList;
@@ -362,10 +363,54 @@ public class PDResources implements COSO
while( iter.hasNext() )
{
String name = iter.next();
- PDPatternResources state = patterns.get( name );
- dic.setItem( COSName.getPDFName( name ), state.getCOSObject() );
+ PDPatternResources pattern = patterns.get( name );
+ dic.setItem( COSName.getPDFName( name ), pattern.getCOSObject() );
}
resources.setItem( COSName.PATTERN, dic );
}
+ /**
+ * This will get the map of shadings. This will return null if the underlying
+ * resources dictionary does not have a shading dictionary. The keys are the shading
+ * name as a String and the values are PDShadingResources objects.
+ *
+ * @return The map of shading resources objects.
+ *
+ * @throws IOException If there is an error getting the shading resources.
+ */
+ public Map<String,PDShadingResources> getShadings() throws IOException
+ {
+ Map<String,PDShadingResources> retval = null;
+ COSDictionary shadings = (COSDictionary)resources.getDictionaryObject( COSName.SHADING );
+
+ if( shadings != null )
+ {
+ Map<String,PDShadingResources> actuals = new HashMap<String,PDShadingResources>();
+ retval = new COSDictionaryMap( actuals, shadings );
+ for( COSName name : shadings.keySet() )
+ {
+ COSDictionary dictionary = (COSDictionary)shadings.getDictionaryObject( name );
+ actuals.put( name.getName(), PDShadingResources.create( dictionary ) );
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * This will set the map of shadings.
+ *
+ * @param shadings The new map of shadings.
+ */
+ public void setShadings( Map<String,PDShadingResources> shadings )
+ {
+ Iterator<String> iter = shadings.keySet().iterator();
+ COSDictionary dic = new COSDictionary();
+ while( iter.hasNext() )
+ {
+ String name = iter.next();
+ PDShadingResources shading = shadings.get( name );
+ dic.setItem( COSName.getPDFName( name ), shading.getCOSObject() );
+ }
+ resources.setItem( COSName.SHADING, dic );
+ }
}
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java?rev=1161633&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java Thu Aug 25 16:34:41 2011
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
+
+/**
+ * This represents resources for a shading.
+ *
+ * @version $Revision: 1.0 $
+ */
+public abstract class PDShadingResources implements COSObjectable
+{
+ private COSDictionary dictionary;
+ private COSArray background = null;
+ private PDRectangle bBox = null;
+ private PDColorSpace colorspace = null;
+
+ /**
+ * shading type 1 = function based shading.
+ */
+ public static final int SHADING_TYPE1 = 1;
+ /**
+ * shading type 2 = axial shading.
+ */
+ public static final int SHADING_TYPE2 = 2;
+ /**
+ * shading type 3 = radial shading.
+ */
+ public static final int SHADING_TYPE3 = 3;
+ /**
+ * shading type 4 = Free-Form Gouraud-Shaded Triangle Meshes.
+ */
+ public static final int SHADING_TYPE4 = 4;
+ /**
+ * shading type 5 = Lattice-Form Gouraud-Shaded Triangle Meshes.
+ */
+ public static final int SHADING_TYPE5 = 5;
+ /**
+ * shading type 6 = Coons Patch Meshes.
+ */
+ public static final int SHADING_TYPE6 = 6;
+ /**
+ * shading type 7 = Tensor-Product Patch Meshes.
+ */
+ public static final int SHADING_TYPE7 = 7;
+
+ /**
+ * Log instance.
+ */
+ private static final Log log = LogFactory.getLog(PDShadingResources.class);
+
+ /**
+ * Default constructor.
+ */
+ public PDShadingResources()
+ {
+ dictionary = new COSDictionary();
+ }
+
+ /**
+ * Constructor using the given shading dictionary.
+ *
+ * @param shadingDictionary The dictionary for this shading.
+ */
+ public PDShadingResources( COSDictionary shadingDictionary )
+ {
+ dictionary = shadingDictionary;
+ }
+
+ /**
+ * This will get the underlying dictionary.
+ *
+ * @return The dictionary for this shading.
+ */
+ public COSDictionary getCOSDictionary()
+ {
+ return dictionary;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return dictionary;
+ }
+
+ /**
+ * This will return the type.
+ *
+ * @return The type of object that this is.
+ */
+ public String getType()
+ {
+ return COSName.SHADING.getName();
+ }
+
+ /**
+ * This will set the shading type.
+ *
+ * @param shadingType The new shading type.
+ */
+ public void setShadingType(int shadingType)
+ {
+ dictionary.setInt(COSName.SHADING_TYPE, shadingType);
+ }
+
+ /**
+ * This will return the shading type.
+ *
+ * @return The shading type
+ */
+ public abstract int getShadingType();
+
+ /**
+ * This will set the background.
+ *
+ * @param newBackground The new background.
+ */
+ public void setBackground(COSArray newBackground)
+ {
+ background = newBackground;
+ dictionary.setItem(COSName.BACKGROUND, newBackground);
+ }
+
+ /**
+ * This will return the background.
+ *
+ * @return The background
+ */
+ public COSArray getBackground()
+ {
+ if (background == null)
+ {
+ background = (COSArray)dictionary.getDictionaryObject( COSName.BACKGROUND );
+ }
+ return background;
+ }
+
+ /**
+ * An array of four numbers in the form coordinate system (see
+ * below), giving the coordinates of the left, bottom, right, and top edges,
+ * respectively, of the shadings's bounding box.
+ *
+ * @return The BBox of the form.
+ */
+ public PDRectangle getBBox()
+ {
+ if (bBox == null)
+ {
+ COSArray array = (COSArray)dictionary.getDictionaryObject( COSName.BBOX );
+ if( array != null )
+ {
+ bBox = new PDRectangle( array );
+ }
+ }
+ return bBox;
+ }
+
+ /**
+ * This will set the BBox (bounding box) for this Shading.
+ *
+ * @param newBBox The new BBox.
+ */
+ public void setBBox(PDRectangle newBBox)
+ {
+ bBox = newBBox;
+ if( bBox == null )
+ {
+ dictionary.removeItem( COSName.BBOX );
+ }
+ else
+ {
+ dictionary.setItem( COSName.BBOX, bBox.getCOSArray() );
+ }
+ }
+
+ /**
+ * This will set the AntiAlias value.
+ *
+ * @param antiAlias The new AntiAlias value.
+ */
+ public void setAntiAlias(boolean antiAlias)
+ {
+ dictionary.setBoolean(COSName.ANTI_ALIAS, antiAlias);
+ }
+
+ /**
+ * This will return the AntiAlias value.
+ *
+ * @return The AntiAlias value
+ */
+ public boolean getAntiAlias()
+ {
+ return dictionary.getBoolean( COSName.ANTI_ALIAS, false );
+ }
+
+ /**
+ * This will get the color space or null if none exists.
+ *
+ * @return The color space for the shading.
+ *
+ * @throws IOException If there is an error getting the colorspace.
+ */
+ public PDColorSpace getColorSpace() throws IOException
+ {
+ if( colorspace == null )
+ {
+ COSBase colorSpaceDictionary = dictionary.getDictionaryObject( COSName.CS, COSName.COLORSPACE );
+ colorspace = PDColorSpaceFactory.createColorSpace( colorSpaceDictionary );
+ }
+ return colorspace;
+ }
+
+ /**
+ * This will set the color space for the shading.
+ *
+ * @param newColorspace The color space
+ */
+ public void setColorSpace( PDColorSpace newColorspace )
+ {
+ colorspace = newColorspace;
+ if( newColorspace != null )
+ {
+ dictionary.setItem( COSName.COLORSPACE, newColorspace.getCOSObject() );
+ }
+ else
+ {
+ dictionary.removeItem( COSName.COLORSPACE );
+ }
+ }
+
+ /**
+ * Create the correct PD Model shading based on the COS base shading.
+ *
+ * @param resourceDictionary the COS shading dictionary
+ *
+ * @return the newly created shading resources object
+ *
+ * @throws IOException If we are unable to create the PDShading object.
+ */
+ public static PDShadingResources create(COSDictionary resourceDictionary) throws IOException
+ {
+ PDShadingResources shading = null;
+ int shadingType = resourceDictionary.getInt( COSName.SHADING_TYPE, 0 );
+ switch (shadingType)
+ {
+ case SHADING_TYPE1:
+ shading = new PDShadingType1(resourceDictionary);
+ break;
+ case SHADING_TYPE2:
+ shading = new PDShadingType2(resourceDictionary);
+ break;
+ case SHADING_TYPE3:
+ shading = new PDShadingType3(resourceDictionary);
+ break;
+ case SHADING_TYPE4:
+ case SHADING_TYPE5:
+ case SHADING_TYPE6:
+ case SHADING_TYPE7:
+ log.debug( "Error: Unsupported shading type " + shadingType );
+ break;
+ default:
+ throw new IOException( "Error: Unknown shading type " + shadingType );
+ }
+ return shading;
+ }
+
+}
Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingResources.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java?rev=1161633&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java Thu Aug 25 16:34:41 2011
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+
+
+import java.awt.geom.AffineTransform;
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSFloat;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
+import org.apache.pdfbox.pdmodel.common.function.PDFunction;
+import org.apache.pdfbox.util.Matrix;
+
+/**
+ * This represents resources for a function based shading.
+ *
+ * @version $Revision: 1.0 $
+ */
+public class PDShadingType1 extends PDShadingResources
+{
+
+ private COSArray domain = null;
+ private PDFunction function = null;
+
+ /**
+ * Constructor using the given shading dictionary.
+ *
+ * @param shadingDictionary The dictionary for this shading.
+ */
+ public PDShadingType1( COSDictionary shadingDictionary )
+ {
+ super(shadingDictionary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getShadingType()
+ {
+ return PDShadingResources.SHADING_TYPE1;
+ }
+
+ /**
+ * This will get the optional Matrix of a function based shading.
+ *
+ * @return the matrix
+ */
+ public Matrix getMatrix()
+ {
+ Matrix retval = null;
+ COSArray array = (COSArray)getCOSDictionary().getDictionaryObject( COSName.MATRIX );
+ if( array != null )
+ {
+ retval = new Matrix();
+ retval.setValue(0, 0, ((COSNumber) array.get(0)).floatValue());
+ retval.setValue(0, 1, ((COSNumber) array.get(1)).floatValue());
+ retval.setValue(1, 0, ((COSNumber) array.get(2)).floatValue());
+ retval.setValue(1, 1, ((COSNumber) array.get(3)).floatValue());
+ retval.setValue(2, 0, ((COSNumber) array.get(4)).floatValue());
+ retval.setValue(2, 1, ((COSNumber) array.get(5)).floatValue());
+ }
+ return retval;
+ }
+
+ /**
+ * Sets the optional Matrix entry for the function based shading.
+ *
+ * @param transform the transformation matrix
+ */
+ public void setMatrix(AffineTransform transform)
+ {
+ COSArray matrix = new COSArray();
+ double[] values = new double[6];
+ transform.getMatrix(values);
+ for (double v : values)
+ {
+ matrix.add(new COSFloat((float)v));
+ }
+ getCOSDictionary().setItem(COSName.MATRIX, matrix);
+ }
+
+ /**
+ * This will get the optional Domain values of a function based shading.
+ *
+ * @return the domain values
+ */
+ public COSArray getDomain()
+ {
+ if (domain == null)
+ {
+ domain = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DOMAIN );
+ }
+ return domain;
+ }
+
+ /**
+ * Sets the optional Domain entry for the function based shading.
+ *
+ * @param newDomain the domain array
+ */
+ public void setDomain(COSArray newDomain)
+ {
+ domain = newDomain;
+ getCOSDictionary().setItem(COSName.DOMAIN, newDomain);
+ }
+
+ /**
+ * This will set the function for the color conversion.
+ *
+ * @param newFunction The new function.
+ */
+ public void setFunction(PDFunction newFunction)
+ {
+ function = newFunction;
+ getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
+ }
+
+ /**
+ * This will return the function used to convert the color values.
+ *
+ * @return The function
+ * @exception IOException If we are unable to create the PDFunction object.
+ */
+ public PDFunction getFunction() throws IOException
+ {
+ if (function == null)
+ {
+ function = PDFunction.create(getCOSDictionary().getDictionaryObject(COSName.FUNCTION));
+ }
+ return function;
+ }
+
+}
Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java?rev=1161633&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java Thu Aug 25 16:34:41 2011
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+
+
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.function.PDFunction;
+
+/**
+ * This represents resources for an axial shading.
+ *
+ * @version $Revision: 1.0 $
+ */
+public class PDShadingType2 extends PDShadingResources
+{
+
+ private COSArray coords = null;
+ private COSArray domain = null;
+ private COSArray extend = null;
+ private PDFunction function = null;
+
+ /**
+ * Constructor using the given shading dictionary.
+ *
+ * @param shadingDictionary The dictionary for this shading.
+ */
+ public PDShadingType2( COSDictionary shadingDictionary )
+ {
+ super(shadingDictionary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getShadingType()
+ {
+ return PDShadingResources.SHADING_TYPE2;
+ }
+
+ /**
+ * This will get the optional Extend values for this shading.
+ *
+ * @return the extend values
+ */
+ public COSArray getExtend()
+ {
+ if (extend == null)
+ {
+ extend = (COSArray)getCOSDictionary().getDictionaryObject( COSName.DOMAIN );
+ }
+ return extend;
+ }
+
+ /**
+ * Sets the optional Extend entry for this shading.
+ *
+ * @param newExtend the extend array
+ */
+ public void setExtend(COSArray newExtend)
+ {
+ this.extend = domain;
+ getCOSDictionary().setItem(COSName.EXTEND, newExtend);
+ }
+
+ /**
+ * This will get the optional Domain values for this shading.
+ *
+ * @return the domain values
+ */
+ public COSArray getDomain()
+ {
+ if (domain == null)
+ {
+ domain = (COSArray)getCOSDictionary().getDictionaryObject( COSName.EXTEND );
+ }
+ return domain;
+ }
+
+ /**
+ * Sets the optional Domain entry for this shading.
+ *
+ * @param newDomain the domain array
+ */
+ public void setDomain(COSArray newDomain)
+ {
+ this.domain = newDomain;
+ getCOSDictionary().setItem(COSName.DOMAIN, newDomain);
+ }
+
+ /**
+ * This will get the Coords values for this shading.
+ *
+ * @return the coords values
+ */
+ public COSArray getCoords()
+ {
+ if (coords == null)
+ {
+ coords = (COSArray)getCOSDictionary().getDictionaryObject( COSName.COORDS );
+ }
+ return coords;
+ }
+
+ /**
+ * Sets the Coords entry for this shading.
+ *
+ * @param newCoords the coords array
+ */
+ public void setCoords(COSArray newCoords)
+ {
+ this.coords = newCoords;
+ getCOSDictionary().setItem(COSName.COORDS, newCoords);
+ }
+
+ /**
+ * This will set the function for the color conversion.
+ *
+ * @param newFunction The new function.
+ */
+ public void setFunction(PDFunction newFunction)
+ {
+ this.function = newFunction;
+ getCOSDictionary().setItem(COSName.FUNCTION, newFunction);
+ }
+
+ /**
+ * This will return the function used to convert the color values.
+ *
+ * @return The function
+ *
+ * @exception IOException If we are unable to create the PDFunction object.
+ *
+ */
+ public PDFunction getFunction() throws IOException
+ {
+ if (function == null)
+ {
+ function = PDFunction.create(getCOSDictionary().getDictionaryObject(COSName.FUNCTION));
+ }
+ return function;
+ }
+
+}
Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java?rev=1161633&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java Thu Aug 25 16:34:41 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.graphics.shading;
+
+
+
+import org.apache.pdfbox.cos.COSDictionary;
+
+/**
+ * This represents resources for a radial shading.
+ *
+ * @version $Revision: 1.0 $
+ */
+public class PDShadingType3 extends PDShadingType2
+{
+
+ /**
+ * Constructor using the given shading dictionary.
+ *
+ * @param shadingDictionary The dictionary for this shading.
+ */
+ public PDShadingType3( COSDictionary shadingDictionary )
+ {
+ super(shadingDictionary);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getShadingType()
+ {
+ return PDShadingResources.SHADING_TYPE3;
+ }
+
+}
Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType3.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html?rev=1161633&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html Thu Aug 25 16:34:41 2011
@@ -0,0 +1,25 @@
+<!--
+ ! Licensed to the Apache Software Foundation (ASF) under one or more
+ ! contributor license agreements. See the NOTICE file distributed with
+ ! this work for additional information regarding copyright ownership.
+ ! The ASF licenses this file to You under the Apache License, Version 2.0
+ ! (the "License"); you may not use this file except in compliance with
+ ! the License. You may obtain a copy of the License at
+ !
+ ! http://www.apache.org/licenses/LICENSE-2.0
+ !
+ ! Unless required by applicable law or agreed to in writing, software
+ ! distributed under the License is distributed on an "AS IS" BASIS,
+ ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ! See the License for the specific language governing permissions and
+ ! limitations under the License.
+ !-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+
+</head>
+<body>
+This package deals with shadings which are used for filling instead of a color.
+</body>
+</html>
Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/package.html
------------------------------------------------------------------------------
svn:eol-style = native