KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > common > PDMatrix


1 /**
2  * Copyright (c) 2004, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.common;
32
33 import org.pdfbox.cos.COSArray;
34 import org.pdfbox.cos.COSBase;
35 import org.pdfbox.cos.COSFloat;
36 import org.pdfbox.cos.COSNumber;
37
38 /**
39  * This class will be used for matrix manipulation.
40  *
41  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
42  * @version $Revision: 1.3 $
43  */

44 public class PDMatrix implements Cloneable JavaDoc, COSObjectable
45 {
46     private COSArray matrix;
47
48     /**
49      * Constructor.
50      */

51     public PDMatrix()
52     {
53         matrix = new COSArray();
54         matrix.add( new COSFloat( 1.0f ) );
55         matrix.add( new COSFloat( 0.0f ) );
56         matrix.add( new COSFloat( 0.0f ) );
57         matrix.add( new COSFloat( 0.0f ) );
58         matrix.add( new COSFloat( 1.0f ) );
59         matrix.add( new COSFloat( 0.0f ) );
60         matrix.add( new COSFloat( 0.0f ) );
61         matrix.add( new COSFloat( 0.0f ) );
62         matrix.add( new COSFloat( 1.0f ) );
63     }
64
65     /**
66      * Constructor.
67      *
68      * @param array The array that describes the matrix.
69      */

70     public PDMatrix( COSArray array )
71     {
72         matrix = array;
73     }
74
75     /**
76      * This will get the underlying array value.
77      *
78      * @return The cos object that this object wraps.
79      */

80     public COSArray getCOSArray()
81     {
82         return matrix;
83     }
84     
85     /**
86      * Convert this standard java object to a COS object.
87      *
88      * @return The cos object that matches this Java object.
89      */

90     public COSBase getCOSObject()
91     {
92         return matrix;
93     }
94     
95
96     /**
97      * This will get a matrix value at some point.
98      *
99      * @param row The row to get the value from.
100      * @param column The column to get the value from.
101      *
102      * @return The value at the row/column position.
103      */

104     public float getValue( int row, int column )
105     {
106         return ((COSNumber)matrix.get( row*3 + column )).floatValue();
107     }
108
109     /**
110      * This will set a value at a position.
111      *
112      * @param row The row to set the value at.
113      * @param column the column to set the value at.
114      * @param value The value to set at the position.
115      */

116     public void setValue( int row, int column, float value )
117     {
118         matrix.set( row*3+column, new COSFloat( value ) );
119     }
120 }
Popular Tags