1 | /* | |
2 | * $Id: MetaFont.java 3373 2008-05-12 16:21:24Z xlv $ | |
3 | * | |
4 | * Copyright 2001, 2002 Paulo Soares | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text.pdf.codec.wmf; | |
51 | import com.lowagie.text.Document; | |
52 | import java.io.IOException; | |
53 | import java.io.UnsupportedEncodingException; | |
54 | import java.util.Locale; | |
55 | ||
56 | ||
57 | import com.lowagie.text.Font; | |
58 | import com.lowagie.text.FontFactory; | |
59 | import com.lowagie.text.ExceptionConverter; | |
60 | import com.lowagie.text.pdf.BaseFont; | |
61 | ||
62 | public class MetaFont extends MetaObject { | |
63 | static final String[] fontNames = { | |
64 | "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", | |
65 | "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique", | |
66 | "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", | |
67 | "Symbol", "ZapfDingbats"}; | |
68 | ||
69 | static final int MARKER_BOLD = 1; | |
70 | static final int MARKER_ITALIC = 2; | |
71 | static final int MARKER_COURIER = 0; | |
72 | static final int MARKER_HELVETICA = 4; | |
73 | static final int MARKER_TIMES = 8; | |
74 | static final int MARKER_SYMBOL = 12; | |
75 | ||
76 | static final int DEFAULT_PITCH = 0; | |
77 | static final int FIXED_PITCH = 1; | |
78 | static final int VARIABLE_PITCH = 2; | |
79 | static final int FF_DONTCARE = 0; | |
80 | static final int FF_ROMAN = 1; | |
81 | static final int FF_SWISS = 2; | |
82 | static final int FF_MODERN = 3; | |
83 | static final int FF_SCRIPT = 4; | |
84 | static final int FF_DECORATIVE = 5; | |
85 | static final int BOLDTHRESHOLD = 600; | |
86 | static final int nameSize = 32; | |
87 | static final int ETO_OPAQUE = 2; | |
88 | static final int ETO_CLIPPED = 4; | |
89 | ||
90 | int height; | |
91 | float angle; | |
92 | int bold; | |
93 | int italic; | |
94 | boolean underline; | |
95 | boolean strikeout; | |
96 | int charset; | |
97 | int pitchAndFamily; | |
98 | String faceName = "arial"; | |
99 | BaseFont font = null; | |
100 | ||
101 | public MetaFont() { | |
102 | type = META_FONT; | |
103 | } | |
104 | ||
105 | public void init(InputMeta in) throws IOException { | |
106 | height = Math.abs(in.readShort()); | |
107 |
1
1. init : removed call to com/lowagie/text/pdf/codec/wmf/InputMeta::skip → NO_COVERAGE |
in.skip(2); |
108 |
2
1. init : Replaced double division with multiplication → NO_COVERAGE 2. init : Replaced double multiplication with division → NO_COVERAGE |
angle = (float)(in.readShort() / 1800.0 * Math.PI); |
109 |
1
1. init : removed call to com/lowagie/text/pdf/codec/wmf/InputMeta::skip → NO_COVERAGE |
in.skip(2); |
110 |
2
1. init : changed conditional boundary → NO_COVERAGE 2. init : negated conditional → NO_COVERAGE |
bold = (in.readShort() >= BOLDTHRESHOLD ? MARKER_BOLD : 0); |
111 |
1
1. init : negated conditional → NO_COVERAGE |
italic = (in.readByte() != 0 ? MARKER_ITALIC : 0); |
112 |
1
1. init : negated conditional → NO_COVERAGE |
underline = (in.readByte() != 0); |
113 |
1
1. init : negated conditional → NO_COVERAGE |
strikeout = (in.readByte() != 0); |
114 | charset = in.readByte(); | |
115 |
1
1. init : removed call to com/lowagie/text/pdf/codec/wmf/InputMeta::skip → NO_COVERAGE |
in.skip(3); |
116 | pitchAndFamily = in.readByte(); | |
117 | byte[] name = new byte[nameSize]; | |
118 | int k; | |
119 |
3
1. init : changed conditional boundary → NO_COVERAGE 2. init : Changed increment from 1 to -1 → NO_COVERAGE 3. init : negated conditional → NO_COVERAGE |
for (k = 0; k < nameSize; ++k) { |
120 | int c = in.readByte(); | |
121 |
1
1. init : negated conditional → NO_COVERAGE |
if (c == 0) { |
122 | break; | |
123 | } | |
124 | name[k] = (byte)c; | |
125 | } | |
126 | try { | |
127 | faceName = new String(name, 0, k, "Cp1252"); | |
128 | } | |
129 | catch (UnsupportedEncodingException e) { | |
130 | faceName = new String(name, 0, k); | |
131 | } | |
132 | faceName = faceName.toLowerCase(Locale.ROOT); | |
133 | } | |
134 | | |
135 | public BaseFont getFont() { | |
136 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (font != null) |
137 |
1
1. getFont : mutated return of Object value for com/lowagie/text/pdf/codec/wmf/MetaFont::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return font; |
138 |
3
1. getFont : Replaced bitwise OR with AND → NO_COVERAGE 2. getFont : negated conditional → NO_COVERAGE 3. getFont : negated conditional → NO_COVERAGE |
Font ff2 = FontFactory.getFont(faceName, BaseFont.CP1252, true, 10, ((italic != 0) ? Font.ITALIC : 0) | ((bold != 0) ? Font.BOLD : 0)); |
139 | font = ff2.getBaseFont(); | |
140 |
1
1. getFont : negated conditional → NO_COVERAGE |
if (font != null) |
141 |
1
1. getFont : mutated return of Object value for com/lowagie/text/pdf/codec/wmf/MetaFont::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return font; |
142 | String fontName; | |
143 |
2
1. getFont : negated conditional → NO_COVERAGE 2. getFont : negated conditional → NO_COVERAGE |
if (faceName.contains("courier") || faceName.contains("terminal") |
144 |
1
1. getFont : negated conditional → NO_COVERAGE |
|| faceName.contains("fixedsys")) { |
145 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_COURIER + italic + bold]; |
146 | } | |
147 |
2
1. getFont : negated conditional → NO_COVERAGE 2. getFont : negated conditional → NO_COVERAGE |
else if (faceName.contains("ms sans serif") || faceName.contains("arial") |
148 |
1
1. getFont : negated conditional → NO_COVERAGE |
|| faceName.contains("system")) { |
149 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_HELVETICA + italic + bold]; |
150 | } | |
151 |
1
1. getFont : negated conditional → NO_COVERAGE |
else if (faceName.contains("arial black")) { |
152 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_HELVETICA + italic + MARKER_BOLD]; |
153 | } | |
154 |
2
1. getFont : negated conditional → NO_COVERAGE 2. getFont : negated conditional → NO_COVERAGE |
else if (faceName.contains("times") || faceName.contains("ms serif") |
155 |
1
1. getFont : negated conditional → NO_COVERAGE |
|| faceName.contains("roman")) { |
156 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_TIMES + italic + bold]; |
157 | } | |
158 |
1
1. getFont : negated conditional → NO_COVERAGE |
else if (faceName.contains("symbol")) { |
159 | fontName = fontNames[MARKER_SYMBOL]; | |
160 | } | |
161 | else { | |
162 |
1
1. getFont : Replaced bitwise AND with OR → NO_COVERAGE |
int pitch = pitchAndFamily & 3; |
163 |
2
1. getFont : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getFont : Replaced bitwise AND with OR → NO_COVERAGE |
int family = (pitchAndFamily >> 4) & 7; |
164 | switch (family) { | |
165 | case FF_MODERN: | |
166 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_COURIER + italic + bold]; |
167 | break; | |
168 | case FF_ROMAN: | |
169 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_TIMES + italic + bold]; |
170 | break; | |
171 | case FF_SWISS: | |
172 | case FF_SCRIPT: | |
173 | case FF_DECORATIVE: | |
174 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_HELVETICA + italic + bold]; |
175 | break; | |
176 | default: | |
177 | { | |
178 | switch (pitch) { | |
179 | case FIXED_PITCH: | |
180 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_COURIER + italic + bold]; |
181 | break; | |
182 | default: | |
183 |
2
1. getFont : Replaced integer addition with subtraction → NO_COVERAGE 2. getFont : Replaced integer addition with subtraction → NO_COVERAGE |
fontName = fontNames[MARKER_HELVETICA + italic + bold]; |
184 | break; | |
185 | } | |
186 | } | |
187 | } | |
188 | } | |
189 | try { | |
190 | font = BaseFont.createFont(fontName, "Cp1252", false); | |
191 | } | |
192 | catch (Exception e) { | |
193 | throw new ExceptionConverter(e); | |
194 | } | |
195 | | |
196 |
1
1. getFont : mutated return of Object value for com/lowagie/text/pdf/codec/wmf/MetaFont::getFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return font; |
197 | } | |
198 | | |
199 | public float getAngle() { | |
200 | return angle; | |
201 | } | |
202 | | |
203 | public boolean isUnderline() { | |
204 | return underline; | |
205 | } | |
206 | | |
207 | public boolean isStrikeout() { | |
208 | return strikeout; | |
209 | } | |
210 | | |
211 | public float getFontSize(MetaState state) { | |
212 |
3
1. getFontSize : Replaced float subtraction with addition → NO_COVERAGE 2. getFontSize : Replaced float multiplication with division → NO_COVERAGE 3. getFontSize : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaFont::getFontSize → NO_COVERAGE |
return Math.abs(state.transformY(height) - state.transformY(0)) * Document.wmfFontCorrection; |
213 | } | |
214 | } | |
Mutations | ||
107 |
1.1 |
|
108 |
1.1 2.2 |
|
109 |
1.1 |
|
110 |
1.1 2.2 |
|
111 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
115 |
1.1 |
|
119 |
1.1 2.2 3.3 |
|
121 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
138 |
1.1 2.2 3.3 |
|
140 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 2.2 |
|
144 |
1.1 |
|
145 |
1.1 2.2 |
|
147 |
1.1 2.2 |
|
148 |
1.1 |
|
149 |
1.1 2.2 |
|
151 |
1.1 |
|
152 |
1.1 2.2 |
|
154 |
1.1 2.2 |
|
155 |
1.1 |
|
156 |
1.1 2.2 |
|
158 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 2.2 |
|
166 |
1.1 2.2 |
|
169 |
1.1 2.2 |
|
174 |
1.1 2.2 |
|
180 |
1.1 2.2 |
|
183 |
1.1 2.2 |
|
196 |
1.1 |
|
212 |
1.1 2.2 3.3 |