001: /**
002: * Copyright (c) 2003-2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.util;
031:
032: import org.pdfbox.pdmodel.font.PDFont;
033:
034: /**
035: * This represents a character and a position on the screen of those characters.
036: *
037: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
038: * @version $Revision: 1.11 $
039: */
040: public class TextPosition {
041: private float x;
042: private float y;
043: private float xScale;
044: private float yScale;
045: private float width;
046: private float height;
047: private float widthOfSpace;
048: private String c;
049: private PDFont font;
050: private float fontSize;
051: private float wordSpacing;
052:
053: /**
054: * Constructor.
055: *
056: * @param xPos The x coordinate of the character.
057: * @param yPos The y coordinate of the character.
058: * @param xScl The x scaling of the character.
059: * @param yScl The y scaling of the character.
060: * @param widthValue The width of the character.
061: * @param heightValue The height of the character.
062: * @param spaceWidth The width of the space character.
063: * @param string The character to be displayed.
064: * @param currentFont The current for for this text position.
065: * @param fontSizeValue The new font size.
066: * @param ws The word spacing parameter
067: */
068: public TextPosition(float xPos, float yPos, float xScl, float yScl,
069: float widthValue, float heightValue, float spaceWidth,
070: String string, PDFont currentFont, float fontSizeValue,
071: float ws) {
072: this .x = xPos;
073: this .y = yPos;
074: this .xScale = xScl;
075: this .yScale = yScl;
076: this .width = widthValue;
077: this .height = heightValue;
078: this .widthOfSpace = spaceWidth;
079: this .c = string;
080: this .font = currentFont;
081: this .fontSize = fontSizeValue;
082: this .wordSpacing = ws;
083: }
084:
085: /**
086: * This will the character that will be displayed on the screen.
087: *
088: * @return The character on the screen.
089: */
090: public String getCharacter() {
091: return c;
092: }
093:
094: /**
095: * This will get the x position of the character.
096: *
097: * @return The x coordinate of the character.
098: */
099: public float getX() {
100: return x;
101: }
102:
103: /**
104: * This will get the y position of the character.
105: *
106: * @return The y coordinate of the character.
107: */
108: public float getY() {
109: return y;
110: }
111:
112: /**
113: * This will get the width of this character.
114: *
115: * @return The width of this character.
116: */
117: public float getWidth() {
118: return width;
119: }
120:
121: /**
122: * This will get the maximum height of all characters in this string.
123: *
124: * @return The maximum height of all characters in this string.
125: */
126: public float getHeight() {
127: return height;
128: }
129:
130: /**
131: * This will get the font size that this object is
132: * suppose to be drawn at.
133: *
134: * @return The font size.
135: */
136: public float getFontSize() {
137: return fontSize;
138: }
139:
140: /**
141: * This will get the font for the text being drawn.
142: *
143: * @return The font size.
144: */
145: public PDFont getFont() {
146: return font;
147: }
148:
149: /**
150: * This will get the current word spacing.
151: *
152: * @return The current word spacing.
153: */
154: public float getWordSpacing() {
155: return wordSpacing;
156: }
157:
158: /**
159: * This will get the width of a space character. This is useful for some
160: * algorithms such as the text stripper, that need to know the width of a
161: * space character.
162: *
163: * @return The width of a space character.
164: */
165: public float getWidthOfSpace() {
166: return widthOfSpace;
167: }
168:
169: /**
170: * @return Returns the xScale.
171: */
172: public float getXScale() {
173: return xScale;
174: }
175:
176: /**
177: * @param scale The xScale to set.
178: */
179: public void setXScale(float scale) {
180: xScale = scale;
181: }
182:
183: /**
184: * @return Returns the yScale.
185: */
186: public float getYScale() {
187: return yScale;
188: }
189:
190: /**
191: * @param scale The yScale to set.
192: */
193: public void setYScale(float scale) {
194: yScale = scale;
195: }
196: }
|