KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > util > TextPosition


1 /**
2  * Copyright (c) 2003-2005, 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.util;
32
33 import org.pdfbox.pdmodel.font.PDFont;
34
35 /**
36  * This represents a character and a position on the screen of those characters.
37  *
38  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
39  * @version $Revision: 1.11 $
40  */

41 public class TextPosition
42 {
43     private float x;
44     private float y;
45     private float xScale;
46     private float yScale;
47     private float width;
48     private float height;
49     private float widthOfSpace;
50     private String JavaDoc c;
51     private PDFont font;
52     private float fontSize;
53     private float wordSpacing;
54
55     /**
56      * Constructor.
57      *
58      * @param xPos The x coordinate of the character.
59      * @param yPos The y coordinate of the character.
60      * @param xScl The x scaling of the character.
61      * @param yScl The y scaling of the character.
62      * @param widthValue The width of the character.
63      * @param heightValue The height of the character.
64      * @param spaceWidth The width of the space character.
65      * @param string The character to be displayed.
66      * @param currentFont The current for for this text position.
67      * @param fontSizeValue The new font size.
68      * @param ws The word spacing parameter
69      */

70     public TextPosition(
71         float xPos,
72         float yPos,
73         float xScl,
74         float yScl,
75         float widthValue,
76         float heightValue,
77         float spaceWidth,
78         String JavaDoc string,
79         PDFont currentFont,
80         float fontSizeValue,
81         float ws
82         )
83     {
84         this.x = xPos;
85         this.y = yPos;
86         this.xScale = xScl;
87         this.yScale = yScl;
88         this.width = widthValue;
89         this.height = heightValue;
90         this.widthOfSpace = spaceWidth;
91         this.c = string;
92         this.font = currentFont;
93         this.fontSize = fontSizeValue;
94         this.wordSpacing = ws;
95     }
96
97     /**
98      * This will the character that will be displayed on the screen.
99      *
100      * @return The character on the screen.
101      */

102     public String JavaDoc getCharacter()
103     {
104         return c;
105     }
106
107     /**
108      * This will get the x position of the character.
109      *
110      * @return The x coordinate of the character.
111      */

112     public float getX()
113     {
114         return x;
115     }
116
117     /**
118      * This will get the y position of the character.
119      *
120      * @return The y coordinate of the character.
121      */

122     public float getY()
123     {
124         return y;
125     }
126
127     /**
128      * This will get the width of this character.
129      *
130      * @return The width of this character.
131      */

132     public float getWidth()
133     {
134         return width;
135     }
136     
137     /**
138      * This will get the maximum height of all characters in this string.
139      *
140      * @return The maximum height of all characters in this string.
141      */

142     public float getHeight()
143     {
144         return height;
145     }
146
147     /**
148      * This will get the font size that this object is
149      * suppose to be drawn at.
150      *
151      * @return The font size.
152      */

153     public float getFontSize()
154     {
155         return fontSize;
156     }
157
158     /**
159      * This will get the font for the text being drawn.
160      *
161      * @return The font size.
162      */

163     public PDFont getFont()
164     {
165         return font;
166     }
167
168     /**
169      * This will get the current word spacing.
170      *
171      * @return The current word spacing.
172      */

173     public float getWordSpacing()
174     {
175         return wordSpacing;
176     }
177
178     /**
179      * This will get the width of a space character. This is useful for some
180      * algorithms such as the text stripper, that need to know the width of a
181      * space character.
182      *
183      * @return The width of a space character.
184      */

185     public float getWidthOfSpace()
186     {
187         return widthOfSpace;
188     }
189     /**
190      * @return Returns the xScale.
191      */

192     public float getXScale()
193     {
194         return xScale;
195     }
196     /**
197      * @param scale The xScale to set.
198      */

199     public void setXScale(float scale)
200     {
201         xScale = scale;
202     }
203     /**
204      * @return Returns the yScale.
205      */

206     public float getYScale()
207     {
208         return yScale;
209     }
210     /**
211      * @param scale The yScale to set.
212      */

213     public void setYScale(float scale)
214     {
215         yScale = scale;
216     }
217 }
Popular Tags