1 | /* | |
2 | * Copyright 2008 by Kevin Day. | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999-2008 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000-2008 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * If you didn't download this code from the following link, you should check if | |
44 | * you aren't using an obsolete version: | |
45 | * http://www.lowagie.com/iText/ | |
46 | */ | |
47 | package com.lowagie.text.pdf.parser; | |
48 | ||
49 | import com.lowagie.text.pdf.CMapAwareDocumentFont; | |
50 | import com.lowagie.text.pdf.DocumentFont; | |
51 | ||
52 | /** | |
53 | * Keeps all the parameters of the graphics state. | |
54 | * | |
55 | * @since 2.1.4 | |
56 | */ | |
57 | @SuppressWarnings("WeakerAccess") | |
58 | public class GraphicsState { | |
59 | /** | |
60 | * The current transformation matrix. | |
61 | */ | |
62 | private Matrix ctm; | |
63 | /** | |
64 | * The current character spacing. | |
65 | */ | |
66 | private float characterSpacing; | |
67 | /** | |
68 | * The current word spacing. | |
69 | */ | |
70 | private float wordSpacing; | |
71 | /** | |
72 | * The current horizontal scaling | |
73 | */ | |
74 | private float horizontalScaling; | |
75 | /** | |
76 | * The current leading. | |
77 | */ | |
78 | private float leading; | |
79 | /** | |
80 | * The active font. | |
81 | */ | |
82 | private CMapAwareDocumentFont font; | |
83 | /** | |
84 | * The current font size. | |
85 | */ | |
86 | private float fontSize; | |
87 | /** | |
88 | * The current render mode. | |
89 | */ | |
90 | private int renderMode; | |
91 | /** | |
92 | * The current text rise | |
93 | */ | |
94 | private float rise; | |
95 | /** | |
96 | * The current knockout value. | |
97 | */ | |
98 | private boolean knockout; | |
99 | ||
100 | /** | |
101 | * Constructs a new Graphics State object with the default values. | |
102 | */ | |
103 | public GraphicsState() { | |
104 | ctm = new Matrix(); | |
105 | characterSpacing = 0; | |
106 | wordSpacing = 0; | |
107 | horizontalScaling = 1.0f; | |
108 | leading = 0; | |
109 | font = null; | |
110 | fontSize = 0; | |
111 | renderMode = 0; | |
112 | rise = 0; | |
113 | knockout = true; | |
114 | } | |
115 | ||
116 | /** | |
117 | * Copy constructor. | |
118 | * | |
119 | * @param source another GraphicsState object | |
120 | */ | |
121 | public GraphicsState(GraphicsState source) { | |
122 | // note: all of the following are immutable, with the possible exception of font | |
123 | // so it is safe to copy them as-is | |
124 | ctm = source.ctm; | |
125 | characterSpacing = source.characterSpacing; | |
126 | wordSpacing = source.wordSpacing; | |
127 | horizontalScaling = source.horizontalScaling; | |
128 | leading = source.leading; | |
129 | font = source.font; | |
130 | fontSize = source.fontSize; | |
131 | renderMode = source.renderMode; | |
132 | rise = source.rise; | |
133 | knockout = source.knockout; | |
134 | } | |
135 | ||
136 | /** | |
137 | * Get the current transformation matrix. | |
138 | * | |
139 | * @return current transformation matrix | |
140 | */ | |
141 | public Matrix getCtm() { | |
142 | return ctm; | |
143 | } | |
144 | ||
145 | public float getCharacterSpacing() { | |
146 | return characterSpacing; | |
147 | } | |
148 | ||
149 | public void setCharacterSpacing(float characterSpacing) { | |
150 | this.characterSpacing = characterSpacing; | |
151 | } | |
152 | ||
153 | public float getWordSpacing() { | |
154 | return wordSpacing; | |
155 | } | |
156 | ||
157 | public void setWordSpacing(float wordSpacing) { | |
158 | this.wordSpacing = wordSpacing; | |
159 | } | |
160 | ||
161 | public float getHorizontalScaling() { | |
162 | return horizontalScaling; | |
163 | } | |
164 | ||
165 | public void setHorizontalScaling(float horizontalScaling) { | |
166 | this.horizontalScaling = horizontalScaling; | |
167 | } | |
168 | ||
169 | public float getLeading() { | |
170 | return leading; | |
171 | } | |
172 | ||
173 | public void setLeading(float leading) { | |
174 | this.leading = leading; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Get maximum height above the baseline reached by glyphs in this font, | |
179 | * excluding the height of glyphs for accented characters. | |
180 | * | |
181 | * @return ascent descriptor value | |
182 | */ | |
183 | public float getFontAscentDescriptor() { | |
184 |
1
1. getFontAscentDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/GraphicsState::getFontAscentDescriptor → NO_COVERAGE |
return font.getFontDescriptor(DocumentFont.ASCENT, fontSize); |
185 | } | |
186 | ||
187 | /** | |
188 | * Get maximum depth below the baseline reached by glyphs in this font. The | |
189 | * value is a negative number | |
190 | * | |
191 | * @return descent descriptor value | |
192 | */ | |
193 | public float getFontDescentDescriptor() { | |
194 |
1
1. getFontDescentDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/GraphicsState::getFontDescentDescriptor → NO_COVERAGE |
return font.getFontDescriptor(DocumentFont.DESCENT, fontSize); |
195 | } | |
196 | ||
197 | public float calculateCharacterWidthWithSpace(float charFontWidth) { | |
198 |
5
1. calculateCharacterWidthWithSpace : Replaced float multiplication with division → NO_COVERAGE 2. calculateCharacterWidthWithSpace : Replaced float addition with subtraction → NO_COVERAGE 3. calculateCharacterWidthWithSpace : Replaced float addition with subtraction → NO_COVERAGE 4. calculateCharacterWidthWithSpace : Replaced float multiplication with division → NO_COVERAGE 5. calculateCharacterWidthWithSpace : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/GraphicsState::calculateCharacterWidthWithSpace → NO_COVERAGE |
return (charFontWidth * fontSize + characterSpacing + wordSpacing) * horizontalScaling; |
199 | } | |
200 | ||
201 | public float calculateCharacterWidthWithoutSpace(float charFontWidth) { | |
202 |
4
1. calculateCharacterWidthWithoutSpace : Replaced float multiplication with division → NO_COVERAGE 2. calculateCharacterWidthWithoutSpace : Replaced float addition with subtraction → NO_COVERAGE 3. calculateCharacterWidthWithoutSpace : Replaced float multiplication with division → NO_COVERAGE 4. calculateCharacterWidthWithoutSpace : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/GraphicsState::calculateCharacterWidthWithoutSpace → NO_COVERAGE |
return (charFontWidth * fontSize + characterSpacing) * horizontalScaling; |
203 | } | |
204 | ||
205 | public CMapAwareDocumentFont getFont() { | |
206 | return font; | |
207 | } | |
208 | ||
209 | public void setFont(CMapAwareDocumentFont font) { | |
210 | this.font = font; | |
211 | } | |
212 | ||
213 | public float getFontSize() { | |
214 | return fontSize; | |
215 | } | |
216 | ||
217 | public void setFontSize(float fontSize) { | |
218 | this.fontSize = fontSize; | |
219 | } | |
220 | ||
221 | public int getRenderMode() { | |
222 | return renderMode; | |
223 | } | |
224 | ||
225 | public void setRenderMode(int renderMode) { | |
226 | this.renderMode = renderMode; | |
227 | } | |
228 | ||
229 | public float getRise() { | |
230 | return rise; | |
231 | } | |
232 | ||
233 | public void setRise(float rise) { | |
234 | this.rise = rise; | |
235 | } | |
236 | ||
237 | public boolean isKnockout() { | |
238 | return knockout; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Multiply transformation matrix and get result. Result would be also stored in this {@link GraphicsState} instance | |
243 | * | |
244 | * @param matrix multiply by matrix | |
245 | * @return result matrix | |
246 | */ | |
247 | public Matrix multiplyCtm(Matrix matrix) { | |
248 | ctm = ctm.multiply(matrix); | |
249 |
1
1. multiplyCtm : mutated return of Object value for com/lowagie/text/pdf/parser/GraphicsState::multiplyCtm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ctm; |
250 | } | |
251 | } | |
Mutations | ||
184 |
1.1 |
|
194 |
1.1 |
|
198 |
1.1 2.2 3.3 4.4 5.5 |
|
202 |
1.1 2.2 3.3 4.4 |
|
249 |
1.1 |