1 /* 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 */ 17 package org.apache.pdfbox.pdmodel.text; 18 19 import org.apache.pdfbox.pdmodel.font.PDFont; 20 21 /** 22 * This class will hold the current state of the text parameters when executing a 23 * content stream. 24 * 25 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 26 * @version $Revision: 1.4 $ 27 */ 28 public class PDTextState implements Cloneable 29 { 30 /** 31 * See PDF Reference 1.5 Table 5.3. 32 */ 33 public static final int RENDERING_MODE_FILL_TEXT = 0; 34 /** 35 * See PDF Reference 1.5 Table 5.3. 36 */ 37 public static final int RENDERING_MODE_STROKE_TEXT = 1; 38 /** 39 * See PDF Reference 1.5 Table 5.3. 40 */ 41 public static final int RENDERING_MODE_FILL_THEN_STROKE_TEXT = 2; 42 /** 43 * See PDF Reference 1.5 Table 5.3. 44 */ 45 public static final int RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT = 3; 46 /** 47 * See PDF Reference 1.5 Table 5.3. 48 */ 49 public static final int RENDERING_MODE_FILL_TEXT_AND_ADD_TO_PATH_FOR_CLIPPING = 4; 50 /** 51 * See PDF Reference 1.5 Table 5.3. 52 */ 53 public static final int RENDERING_MODE_STROKE_TEXT_AND_ADD_TO_PATH_FOR_CLIPPING = 5; 54 /** 55 * See PDF Reference 1.5 Table 5.3. 56 */ 57 public static final int RENDERING_MODE_FILL_THEN_STROKE_TEXT_AND_ADD_TO_PATH_FOR_CLIPPING = 6; 58 /** 59 * See PDF Reference 1.5 Table 5.3. 60 */ 61 public static final int RENDERING_MODE_ADD_TEXT_TO_PATH_FOR_CLIPPING = 7; 62 63 64 //these are set default according to PDF Reference 1.5 section 5.2 65 private float characterSpacing = 0; 66 private float wordSpacing = 0; 67 private float horizontalScaling = 100; 68 private float leading = 0; 69 private PDFont font; 70 private float fontSize; 71 private int renderingMode = 0; 72 private float rise = 0; 73 private boolean knockout = true; 74 75 /** 76 * Get the value of the characterSpacing. 77 * 78 * @return The current characterSpacing. 79 */ 80 public float getCharacterSpacing() 81 { 82 return characterSpacing; 83 } 84 85 /** 86 * Set the value of the characterSpacing. 87 * 88 * @param value The characterSpacing. 89 */ 90 public void setCharacterSpacing(float value) 91 { 92 characterSpacing = value; 93 } 94 95 /** 96 * Get the value of the wordSpacing. 97 * 98 * @return The wordSpacing. 99 */ 100 public float getWordSpacing() 101 { 102 return wordSpacing; 103 } 104 105 /** 106 * Set the value of the wordSpacing. 107 * 108 * @param value The wordSpacing. 109 */ 110 public void setWordSpacing(float value) 111 { 112 wordSpacing = value; 113 } 114 115 /** 116 * Get the value of the horizontalScaling. The default is 100. This value 117 * is the percentage value 0-100 and not 0-1. So for mathematical operations 118 * you will probably need to divide by 100 first. 119 * 120 * @return The horizontalScaling. 121 */ 122 public float getHorizontalScalingPercent() 123 { 124 return horizontalScaling; 125 } 126 127 /** 128 * Set the value of the horizontalScaling. 129 * 130 * @param value The horizontalScaling. 131 */ 132 public void setHorizontalScalingPercent(float value) 133 { 134 horizontalScaling = value; 135 } 136 137 /** 138 * Get the value of the leading. 139 * 140 * @return The leading. 141 */ 142 public float getLeading() 143 { 144 return leading; 145 } 146 147 /** 148 * Set the value of the leading. 149 * 150 * @param value The leading. 151 */ 152 public void setLeading(float value) 153 { 154 leading = value; 155 } 156 157 /** 158 * Get the value of the font. 159 * 160 * @return The font. 161 */ 162 public PDFont getFont() 163 { 164 return font; 165 } 166 167 /** 168 * Set the value of the font. 169 * 170 * @param value The font. 171 */ 172 public void setFont(PDFont value) 173 { 174 font = value; 175 } 176 177 /** 178 * Get the value of the fontSize. 179 * 180 * @return The fontSize. 181 */ 182 public float getFontSize() 183 { 184 return fontSize; 185 } 186 187 /** 188 * Set the value of the fontSize. 189 * 190 * @param value The fontSize. 191 */ 192 public void setFontSize(float value) 193 { 194 fontSize = value; 195 } 196 197 /** 198 * Get the value of the renderingMode. 199 * 200 * @return The renderingMode. 201 */ 202 public int getRenderingMode() 203 { 204 return renderingMode; 205 } 206 207 /** 208 * Set the value of the renderingMode. 209 * 210 * @param value The renderingMode. 211 */ 212 public void setRenderingMode(int value) 213 { 214 renderingMode = value; 215 } 216 217 /** 218 * Get the value of the rise. 219 * 220 * @return The rise. 221 */ 222 public float getRise() 223 { 224 return rise; 225 } 226 227 /** 228 * Set the value of the rise. 229 * 230 * @param value The rise. 231 */ 232 public void setRise(float value) 233 { 234 rise = value; 235 } 236 237 /** 238 * Get the value of the knockout. 239 * 240 * @return The knockout. 241 */ 242 public boolean getKnockoutFlag() 243 { 244 return knockout; 245 } 246 247 /** 248 * Set the value of the knockout. 249 * 250 * @param value The knockout. 251 */ 252 public void setKnockoutFlag(boolean value) 253 { 254 knockout = value; 255 } 256 257 /** 258 * {@inheritDoc} 259 */ 260 public Object clone() 261 { 262 try 263 { 264 return super.clone(); 265 } 266 catch (CloneNotSupportedException ignore) 267 { 268 //ignore 269 } 270 return null; 271 } 272 }