1 | /* | |
2 | * Copyright 2004 Paulo Soares | |
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, 2000, 2001, 2002 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, 2001, 2002 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 | * Contributions by: | |
44 | * Lubos Strapko | |
45 | * | |
46 | * If you didn't download this code from the following link, you should check if | |
47 | * you aren't using an obsolete version: | |
48 | * http://www.lowagie.com/iText/ | |
49 | */ | |
50 | ||
51 | package com.lowagie.text.html.simpleparser; | |
52 | ||
53 | import com.lowagie.text.Chunk; | |
54 | import com.lowagie.text.Element; | |
55 | import com.lowagie.text.ElementTags; | |
56 | import com.lowagie.text.Font; | |
57 | import com.lowagie.text.FontFactory; | |
58 | import com.lowagie.text.FontProvider; | |
59 | import com.lowagie.text.ListItem; | |
60 | import com.lowagie.text.Paragraph; | |
61 | import com.lowagie.text.html.HtmlTags; | |
62 | import com.lowagie.text.html.Markup; | |
63 | import com.lowagie.text.pdf.BaseFont; | |
64 | import com.lowagie.text.pdf.HyphenationAuto; | |
65 | import com.lowagie.text.pdf.HyphenationEvent; | |
66 | ||
67 | import java.awt.Color; | |
68 | import java.util.HashMap; | |
69 | import java.util.Map; | |
70 | import java.util.Properties; | |
71 | import java.util.StringTokenizer; | |
72 | ||
73 | /** | |
74 | * | |
75 | * @author psoares | |
76 | */ | |
77 | public class FactoryProperties { | |
78 | ||
79 | /** | |
80 | * @since iText 5.0 This used to be a FontFactoryImp | |
81 | */ | |
82 | private FontProvider fontImp = FontFactory.getFontImp(); | |
83 | ||
84 | /** Creates a new instance of FactoryProperties */ | |
85 | public FactoryProperties() { | |
86 | } | |
87 | ||
88 | public Chunk createChunk(String text, ChainedProperties props) { | |
89 | Font font = getFont(props); | |
90 | float size = font.getSize(); | |
91 |
1
1. createChunk : Replaced float division with multiplication → NO_COVERAGE |
size /= 2; |
92 | Chunk ck = new Chunk(text, font); | |
93 |
1
1. createChunk : negated conditional → NO_COVERAGE |
if (props.hasProperty("sub")) |
94 |
1
1. createChunk : removed negation → NO_COVERAGE |
ck.setTextRise(-size); |
95 |
1
1. createChunk : negated conditional → NO_COVERAGE |
else if (props.hasProperty("sup")) |
96 | ck.setTextRise(size); | |
97 | ck.setHyphenation(getHyphenation(props)); | |
98 |
1
1. createChunk : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::createChunk to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ck; |
99 | } | |
100 | ||
101 | private static void setParagraphLeading(Paragraph p, String leading) { | |
102 |
1
1. setParagraphLeading : negated conditional → NO_COVERAGE |
if (leading == null) { |
103 |
1
1. setParagraphLeading : removed call to com/lowagie/text/Paragraph::setLeading → NO_COVERAGE |
p.setLeading(0, 1.5f); |
104 | return; | |
105 | } | |
106 | try { | |
107 | StringTokenizer tk = new StringTokenizer(leading, " ,"); | |
108 | String v = tk.nextToken(); | |
109 | float v1 = Float.parseFloat(v); | |
110 |
1
1. setParagraphLeading : negated conditional → NO_COVERAGE |
if (!tk.hasMoreTokens()) { |
111 |
1
1. setParagraphLeading : removed call to com/lowagie/text/Paragraph::setLeading → NO_COVERAGE |
p.setLeading(v1, 0); |
112 | return; | |
113 | } | |
114 | v = tk.nextToken(); | |
115 | float v2 = Float.parseFloat(v); | |
116 |
1
1. setParagraphLeading : removed call to com/lowagie/text/Paragraph::setLeading → NO_COVERAGE |
p.setLeading(v1, v2); |
117 | } catch (Exception e) { | |
118 |
1
1. setParagraphLeading : removed call to com/lowagie/text/Paragraph::setLeading → NO_COVERAGE |
p.setLeading(0, 1.5f); |
119 | } | |
120 | } | |
121 | ||
122 | public static void createParagraph(Paragraph p, ChainedProperties props) { | |
123 | String value = props.getProperty("align"); | |
124 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
if (value != null) { |
125 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
if (value.equalsIgnoreCase("center")) |
126 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setAlignment → NO_COVERAGE |
p.setAlignment(Element.ALIGN_CENTER); |
127 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
else if (value.equalsIgnoreCase("right")) |
128 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setAlignment → NO_COVERAGE |
p.setAlignment(Element.ALIGN_RIGHT); |
129 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
else if (value.equalsIgnoreCase("justify")) |
130 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setAlignment → NO_COVERAGE |
p.setAlignment(Element.ALIGN_JUSTIFIED); |
131 | } | |
132 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setHyphenation → NO_COVERAGE |
p.setHyphenation(getHyphenation(props)); |
133 |
1
1. createParagraph : removed call to com/lowagie/text/html/simpleparser/FactoryProperties::setParagraphLeading → NO_COVERAGE |
setParagraphLeading(p, props.getProperty("leading")); |
134 | value = props.getProperty("before"); | |
135 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
if (value != null) { |
136 | try { | |
137 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setSpacingBefore → NO_COVERAGE |
p.setSpacingBefore(Float.parseFloat(value)); |
138 | } catch (Exception e) { | |
139 | } | |
140 | } | |
141 | value = props.getProperty("after"); | |
142 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
if (value != null) { |
143 | try { | |
144 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setSpacingAfter → NO_COVERAGE |
p.setSpacingAfter(Float.parseFloat(value)); |
145 | } catch (Exception e) { | |
146 | } | |
147 | } | |
148 | value = props.getProperty("extraparaspace"); | |
149 |
1
1. createParagraph : negated conditional → NO_COVERAGE |
if (value != null) { |
150 | try { | |
151 |
1
1. createParagraph : removed call to com/lowagie/text/Paragraph::setExtraParagraphSpace → NO_COVERAGE |
p.setExtraParagraphSpace(Float.parseFloat(value)); |
152 | } catch (Exception e) { | |
153 | } | |
154 | } | |
155 | } | |
156 | ||
157 | public static Paragraph createParagraph(ChainedProperties props) { | |
158 | Paragraph p = new Paragraph(); | |
159 |
1
1. createParagraph : removed call to com/lowagie/text/html/simpleparser/FactoryProperties::createParagraph → NO_COVERAGE |
createParagraph(p, props); |
160 |
1
1. createParagraph : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::createParagraph to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return p; |
161 | } | |
162 | ||
163 | public static ListItem createListItem(ChainedProperties props) { | |
164 | ListItem p = new ListItem(); | |
165 |
1
1. createListItem : removed call to com/lowagie/text/html/simpleparser/FactoryProperties::createParagraph → NO_COVERAGE |
createParagraph(p, props); |
166 |
1
1. createListItem : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::createListItem to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return p; |
167 | } | |
168 | ||
169 | public Font getFont(ChainedProperties props) { | |
170 | String face = props.getProperty(ElementTags.FACE); | |
171 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (face != null) { |
172 | StringTokenizer tok = new StringTokenizer(face, ","); | |
173 |
1
1. getFont : negated conditional → NO_COVERAGE |
while (tok.hasMoreTokens()) { |
174 | face = tok.nextToken().trim(); | |
175 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (face.startsWith("\"")) |
176 | face = face.substring(1); | |
177 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (face.endsWith("\"")) |
178 |
1
1. getFont : Replaced integer subtraction with addition → NO_COVERAGE |
face = face.substring(0, face.length() - 1); |
179 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (fontImp.isRegistered(face)) |
180 | break; | |
181 | } | |
182 | } | |
183 | int style = 0; | |
184 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (props.hasProperty(HtmlTags.I)) |
185 |
1
1. getFont : Replaced bitwise OR with AND → NO_COVERAGE |
style |= Font.ITALIC; |
186 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (props.hasProperty(HtmlTags.B)) |
187 |
1
1. getFont : Replaced bitwise OR with AND → NO_COVERAGE |
style |= Font.BOLD; |
188 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (props.hasProperty(HtmlTags.U)) |
189 |
1
1. getFont : Replaced bitwise OR with AND → NO_COVERAGE |
style |= Font.UNDERLINE; |
190 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (props.hasProperty(HtmlTags.S)) |
191 |
1
1. getFont : Replaced bitwise OR with AND → NO_COVERAGE |
style |= Font.STRIKETHRU; |
192 | String value = props.getProperty(ElementTags.SIZE); | |
193 | float size = 12; | |
194 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (value != null) |
195 | size = Float.parseFloat(value); | |
196 | Color color = Markup.decodeColor(props.getProperty("color")); | |
197 | String encoding = props.getProperty("encoding"); | |
198 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (encoding == null) |
199 | encoding = BaseFont.WINANSI; | |
200 |
1
1. getFont : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontImp.getFont(face, encoding, true, size, style, color); |
201 | } | |
202 | ||
203 | /** | |
204 | * Gets a HyphenationEvent based on the hyphenation entry in ChainedProperties. | |
205 | * @param props ChainedProperties | |
206 | * @return a HyphenationEvent | |
207 | * @since 2.1.2 | |
208 | */ | |
209 | public static HyphenationEvent getHyphenation(ChainedProperties props) { | |
210 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getHyphenation(props.getProperty("hyphenation")); |
211 | } | |
212 | ||
213 | /** | |
214 | * Gets a HyphenationEvent based on the hyphenation entry in a HashMap. | |
215 | * @param props a HashMap with properties | |
216 | * @return a HyphenationEvent | |
217 | * @since 2.1.2 | |
218 | */ | |
219 | public static HyphenationEvent getHyphenation(HashMap props) { | |
220 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getHyphenation((String) props.get("hyphenation")); |
221 | } | |
222 | ||
223 | /** | |
224 | * Gets a HyphenationEvent based on a String. | |
225 | * For instance "en_UK,3,2" returns new HyphenationAuto("en", "UK", 3, 2); | |
226 | * @param s a String, for instance "en_UK,2,2" | |
227 | * @return a HyphenationEvent | |
228 | * @since 2.1.2 | |
229 | */ | |
230 | public static HyphenationEvent getHyphenation(String s) { | |
231 |
2
1. getHyphenation : negated conditional → NO_COVERAGE 2. getHyphenation : negated conditional → NO_COVERAGE |
if (s == null || s.length() == 0) { |
232 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
233 | } | |
234 | String lang = s; | |
235 | String country = null; | |
236 | int leftMin = 2; | |
237 | int rightMin = 2; | |
238 | ||
239 | int pos = s.indexOf('_'); | |
240 |
1
1. getHyphenation : negated conditional → NO_COVERAGE |
if (pos == -1) { |
241 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new HyphenationAuto(lang, country, leftMin, rightMin); |
242 | } | |
243 | lang = s.substring(0, pos); | |
244 |
1
1. getHyphenation : Replaced integer addition with subtraction → NO_COVERAGE |
country = s.substring(pos + 1); |
245 | pos = country.indexOf(','); | |
246 |
1
1. getHyphenation : negated conditional → NO_COVERAGE |
if (pos == -1) { |
247 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new HyphenationAuto(lang, country, leftMin, rightMin); |
248 | } | |
249 |
1
1. getHyphenation : Replaced integer addition with subtraction → NO_COVERAGE |
s = country.substring(pos + 1); |
250 | country = country.substring(0, pos); | |
251 | pos = s.indexOf(','); | |
252 |
1
1. getHyphenation : negated conditional → NO_COVERAGE |
if (pos == -1) { |
253 | leftMin = Integer.parseInt(s); | |
254 | } else { | |
255 | leftMin = Integer.parseInt(s.substring(0, pos)); | |
256 |
1
1. getHyphenation : Replaced integer addition with subtraction → NO_COVERAGE |
rightMin = Integer.parseInt(s.substring(pos + 1)); |
257 | } | |
258 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/html/simpleparser/FactoryProperties::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new HyphenationAuto(lang, country, leftMin, rightMin); |
259 | } | |
260 | ||
261 | /** | |
262 | * This method isn't used by iText, but you can use it to analyze | |
263 | * the value of a style attribute inside a HashMap. | |
264 | * The different elements of the style attribute are added to the | |
265 | * HashMap as key-value pairs. | |
266 | * @param h a HashMap that should have at least a key named | |
267 | * style. After this method is invoked, more keys could be added. | |
268 | */ | |
269 | public static void insertStyle(HashMap h) { | |
270 | String style = (String) h.get("style"); | |
271 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (style == null) |
272 | return; | |
273 | Properties prop = Markup.parseAttributes(style); | |
274 | for (Object o : prop.keySet()) { | |
275 | String key = (String) o; | |
276 | switch (key) { | |
277 | case Markup.CSS_KEY_FONTFAMILY: | |
278 | h.put("face", prop.getProperty(key)); | |
279 | break; | |
280 | case Markup.CSS_KEY_FONTSIZE: | |
281 | h.put("size", Markup.parseLength(prop | |
282 | .getProperty(key)) | |
283 | + "pt"); | |
284 | break; | |
285 | case Markup.CSS_KEY_FONTSTYLE: { | |
286 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
287 |
2
1. insertStyle : negated conditional → NO_COVERAGE 2. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals("italic") || ss.equals("oblique")) |
288 | h.put("i", null); | |
289 | break; | |
290 | } | |
291 | case Markup.CSS_KEY_FONTWEIGHT: { | |
292 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
293 |
3
1. insertStyle : negated conditional → NO_COVERAGE 2. insertStyle : negated conditional → NO_COVERAGE 3. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals("bold") || ss.equals("700") || ss.equals("800") |
294 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
|| ss.equals("900")) |
295 | h.put("b", null); | |
296 | break; | |
297 | } | |
298 | case Markup.CSS_KEY_TEXTDECORATION: { | |
299 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
300 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals(Markup.CSS_VALUE_UNDERLINE)) |
301 | h.put("u", null); | |
302 | break; | |
303 | } | |
304 | case Markup.CSS_KEY_COLOR: | |
305 | Color c = Markup.decodeColor(prop.getProperty(key)); | |
306 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (c != null) { |
307 | int hh = c.getRGB(); | |
308 | String hs = Integer.toHexString(hh); | |
309 | hs = "000000" + hs; | |
310 |
1
1. insertStyle : Replaced integer subtraction with addition → NO_COVERAGE |
hs = "#" + hs.substring(hs.length() - 6); |
311 | h.put("color", hs); | |
312 | } | |
313 | break; | |
314 | case Markup.CSS_KEY_LINEHEIGHT: { | |
315 | String ss = prop.getProperty(key).trim(); | |
316 | float v = Markup.parseLength(prop.getProperty(key)); | |
317 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (ss.endsWith("%")) { |
318 |
1
1. insertStyle : Replaced float division with multiplication → NO_COVERAGE |
h.put("leading", "0," + (v / 100)); |
319 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
} else if ("normal".equalsIgnoreCase(ss)) { |
320 | h.put("leading", "0,1.5"); | |
321 | } else { | |
322 | h.put("leading", v + ",0"); | |
323 | } | |
324 | break; | |
325 | } | |
326 | case Markup.CSS_KEY_TEXTALIGN: { | |
327 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
328 | h.put("align", ss); | |
329 | break; | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | ||
335 | /** | |
336 | * New method contributed by Lubos Strapko | |
337 | * @param h | |
338 | * @param cprops | |
339 | * @since 2.1.3 | |
340 | */ | |
341 | public static void insertStyle(Map<String, String> h, ChainedProperties cprops) { | |
342 | String style = h.get("style"); | |
343 |
1
1. insertStyle : negated conditional → KILLED |
if (style == null) |
344 | return; | |
345 | Properties prop = Markup.parseAttributes(style); | |
346 | for (Object o : prop.keySet()) { | |
347 | String key = (String) o; | |
348 | switch (key) { | |
349 | case Markup.CSS_KEY_FONTFAMILY: | |
350 | h.put(ElementTags.FACE, prop.getProperty(key)); | |
351 | break; | |
352 | case Markup.CSS_KEY_FONTSIZE: { | |
353 | float actualFontSize = Markup.parseLength(cprops | |
354 | .getProperty(ElementTags.SIZE), | |
355 | Markup.DEFAULT_FONT_SIZE); | |
356 |
2
1. insertStyle : changed conditional boundary → NO_COVERAGE 2. insertStyle : negated conditional → NO_COVERAGE |
if (actualFontSize <= 0f) |
357 | actualFontSize = Markup.DEFAULT_FONT_SIZE; | |
358 | h.put(ElementTags.SIZE, Markup.parseLength(prop | |
359 | .getProperty(key), actualFontSize) | |
360 | + "pt"); | |
361 | break; | |
362 | } | |
363 | case Markup.CSS_KEY_FONTSTYLE: { | |
364 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
365 |
2
1. insertStyle : negated conditional → NO_COVERAGE 2. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals("italic") || ss.equals("oblique")) |
366 | h.put("i", null); | |
367 | break; | |
368 | } | |
369 | case Markup.CSS_KEY_FONTWEIGHT: { | |
370 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
371 |
3
1. insertStyle : negated conditional → NO_COVERAGE 2. insertStyle : negated conditional → NO_COVERAGE 3. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals("bold") || ss.equals("700") || ss.equals("800") |
372 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
|| ss.equals("900")) |
373 | h.put("b", null); | |
374 | break; | |
375 | } | |
376 | case Markup.CSS_KEY_TEXTDECORATION: { | |
377 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
378 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (ss.equals(Markup.CSS_VALUE_UNDERLINE)) |
379 | h.put("u", null); | |
380 | break; | |
381 | } | |
382 | case Markup.CSS_KEY_COLOR: | |
383 | Color c = Markup.decodeColor(prop.getProperty(key)); | |
384 |
1
1. insertStyle : negated conditional → NO_COVERAGE |
if (c != null) { |
385 | int hh = c.getRGB(); | |
386 | String hs = Integer.toHexString(hh); | |
387 | hs = "000000" + hs; | |
388 |
1
1. insertStyle : Replaced integer subtraction with addition → NO_COVERAGE |
hs = "#" + hs.substring(hs.length() - 6); |
389 | h.put("color", hs); | |
390 | } | |
391 | break; | |
392 | case Markup.CSS_KEY_LINEHEIGHT: { | |
393 | String ss = prop.getProperty(key).trim(); | |
394 | float actualFontSize = Markup.parseLength(cprops | |
395 | .getProperty(ElementTags.SIZE), | |
396 | Markup.DEFAULT_FONT_SIZE); | |
397 |
2
1. insertStyle : changed conditional boundary → SURVIVED 2. insertStyle : negated conditional → SURVIVED |
if (actualFontSize <= 0f) |
398 | actualFontSize = Markup.DEFAULT_FONT_SIZE; | |
399 | float v = Markup.parseLength(prop.getProperty(key), | |
400 | actualFontSize); | |
401 |
1
1. insertStyle : negated conditional → KILLED |
if (ss.endsWith("%")) { |
402 |
1
1. insertStyle : Replaced float division with multiplication → NO_COVERAGE |
h.put("leading", "0," + (v / 100)); |
403 | return; | |
404 | } | |
405 |
1
1. insertStyle : negated conditional → KILLED |
if ("normal".equalsIgnoreCase(ss)) { |
406 | h.put("leading", "0,1.5"); | |
407 | return; | |
408 | } | |
409 | // Covering a case of line-height being a number | |
410 |
3
1. insertStyle : Replaced integer subtraction with addition → KILLED 2. insertStyle : negated conditional → KILLED 3. insertStyle : negated conditional → KILLED |
if (v != 0 && Character.isDigit(ss.charAt(ss.length() - 1))) { |
411 | h.put("leading", "0," + v); | |
412 | } else { | |
413 | h.put("leading", v + ",0"); | |
414 | } | |
415 | break; | |
416 | } | |
417 | case Markup.CSS_KEY_TEXTALIGN: { | |
418 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
419 | h.put("align", ss); | |
420 | break; | |
421 | } | |
422 | case Markup.CSS_KEY_PADDINGLEFT: { | |
423 | String ss = prop.getProperty(key).trim().toLowerCase(); | |
424 | h.put("indent", Float.toString(Markup.parseLength(ss))); | |
425 | break; | |
426 | } | |
427 | } | |
428 | } | |
429 | } | |
430 | ||
431 | public FontProvider getFontImp() { | |
432 | return fontImp; | |
433 | } | |
434 | ||
435 | public void setFontImp(FontProvider fontImp) { | |
436 | this.fontImp = fontImp; | |
437 | } | |
438 | ||
439 | public static HashMap followTags = new HashMap(); | |
440 | static { | |
441 | followTags.put("i", "i"); | |
442 | followTags.put("b", "b"); | |
443 | followTags.put("u", "u"); | |
444 | followTags.put("sub", "sub"); | |
445 | followTags.put("sup", "sup"); | |
446 | followTags.put("em", "i"); | |
447 | followTags.put("strong", "b"); | |
448 | followTags.put("s", "s"); | |
449 | followTags.put("strike", "s"); | |
450 | } | |
451 | } | |
Mutations | ||
91 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
98 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
116 |
1.1 |
|
118 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
135 |
1.1 |
|
137 |
1.1 |
|
142 |
1.1 |
|
144 |
1.1 |
|
149 |
1.1 |
|
151 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
165 |
1.1 |
|
166 |
1.1 |
|
171 |
1.1 |
|
173 |
1.1 |
|
175 |
1.1 |
|
177 |
1.1 |
|
178 |
1.1 |
|
179 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
187 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
191 |
1.1 |
|
194 |
1.1 |
|
198 |
1.1 |
|
200 |
1.1 |
|
210 |
1.1 |
|
220 |
1.1 |
|
231 |
1.1 2.2 |
|
232 |
1.1 |
|
240 |
1.1 |
|
241 |
1.1 |
|
244 |
1.1 |
|
246 |
1.1 |
|
247 |
1.1 |
|
249 |
1.1 |
|
252 |
1.1 |
|
256 |
1.1 |
|
258 |
1.1 |
|
271 |
1.1 |
|
287 |
1.1 2.2 |
|
293 |
1.1 2.2 3.3 |
|
294 |
1.1 |
|
300 |
1.1 |
|
306 |
1.1 |
|
310 |
1.1 |
|
317 |
1.1 |
|
318 |
1.1 |
|
319 |
1.1 |
|
343 |
1.1 |
|
356 |
1.1 2.2 |
|
365 |
1.1 2.2 |
|
371 |
1.1 2.2 3.3 |
|
372 |
1.1 |
|
378 |
1.1 |
|
384 |
1.1 |
|
388 |
1.1 |
|
397 |
1.1 2.2 |
|
401 |
1.1 |
|
402 |
1.1 |
|
405 |
1.1 |
|
410 |
1.1 2.2 3.3 |