1 | /* | |
2 | * Copyright 2002 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 | * 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 | ||
48 | package com.lowagie.text.pdf; | |
49 | ||
50 | import java.util.HashMap; | |
51 | import java.util.Map; | |
52 | ||
53 | import com.lowagie.text.Rectangle; | |
54 | ||
55 | /** | |
56 | * Implements the appearance stream to be used with form fields.. | |
57 | */ | |
58 | ||
59 | public class PdfAppearance extends PdfTemplate { | |
60 | ||
61 | public static final Map<String, PdfName> stdFieldFontNames = new HashMap<>(); | |
62 | static { | |
63 | stdFieldFontNames.put("Courier-BoldOblique", new PdfName("CoBO")); | |
64 | stdFieldFontNames.put("Courier-Bold", new PdfName("CoBo")); | |
65 | stdFieldFontNames.put("Courier-Oblique", new PdfName("CoOb")); | |
66 | stdFieldFontNames.put("Courier", new PdfName("Cour")); | |
67 | stdFieldFontNames.put("Helvetica-BoldOblique", new PdfName("HeBO")); | |
68 | stdFieldFontNames.put("Helvetica-Bold", new PdfName("HeBo")); | |
69 | stdFieldFontNames.put("Helvetica-Oblique", new PdfName("HeOb")); | |
70 | stdFieldFontNames.put("Helvetica", PdfName.HELV); | |
71 | stdFieldFontNames.put("Symbol", new PdfName("Symb")); | |
72 | stdFieldFontNames.put("Times-BoldItalic", new PdfName("TiBI")); | |
73 | stdFieldFontNames.put("Times-Bold", new PdfName("TiBo")); | |
74 | stdFieldFontNames.put("Times-Italic", new PdfName("TiIt")); | |
75 | stdFieldFontNames.put("Times-Roman", new PdfName("TiRo")); | |
76 | stdFieldFontNames.put("ZapfDingbats", PdfName.ZADB); | |
77 | stdFieldFontNames.put("HYSMyeongJo-Medium", new PdfName("HySm")); | |
78 | stdFieldFontNames.put("HYGoThic-Medium", new PdfName("HyGo")); | |
79 | stdFieldFontNames.put("HeiseiKakuGo-W5", new PdfName("KaGo")); | |
80 | stdFieldFontNames.put("HeiseiMin-W3", new PdfName("KaMi")); | |
81 | stdFieldFontNames.put("MHei-Medium", new PdfName("MHei")); | |
82 | stdFieldFontNames.put("MSung-Light", new PdfName("MSun")); | |
83 | stdFieldFontNames.put("STSong-Light", new PdfName("STSo")); | |
84 | stdFieldFontNames.put("MSungStd-Light", new PdfName("MSun")); | |
85 | stdFieldFontNames.put("STSongStd-Light", new PdfName("STSo")); | |
86 | stdFieldFontNames.put("HYSMyeongJoStd-Medium", new PdfName("HySm")); | |
87 | stdFieldFontNames.put("KozMinPro-Regular", new PdfName("KaMi")); | |
88 | } | |
89 | | |
90 | /** | |
91 | *Creates a <CODE>PdfAppearance</CODE>. | |
92 | */ | |
93 | | |
94 | PdfAppearance() { | |
95 | super(); | |
96 | separator = ' '; | |
97 | } | |
98 | | |
99 | PdfAppearance(PdfIndirectReference iref) { | |
100 | thisReference = iref; | |
101 | } | |
102 | | |
103 | /** | |
104 | * Creates new PdfTemplate | |
105 | * | |
106 | * @param wr the <CODE>PdfWriter</CODE> | |
107 | */ | |
108 | | |
109 | PdfAppearance(PdfWriter wr) { | |
110 | super(wr); | |
111 | separator = ' '; | |
112 | } | |
113 | | |
114 | /** | |
115 | * Creates a new appearance to be used with form fields. | |
116 | * | |
117 | * @param writer the PdfWriter to use | |
118 | * @param width the bounding box width | |
119 | * @param height the bounding box height | |
120 | * @return the appearance created | |
121 | */ | |
122 | public static PdfAppearance createAppearance(PdfWriter writer, float width, float height) { | |
123 |
1
1. createAppearance : mutated return of Object value for com/lowagie/text/pdf/PdfAppearance::createAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createAppearance(writer, width, height, null); |
124 | } | |
125 | ||
126 | private static PdfAppearance createAppearance(PdfWriter writer, float width, float height, PdfName forcedName) { | |
127 | PdfAppearance template = new PdfAppearance(writer); | |
128 |
1
1. createAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::setWidth → NO_COVERAGE |
template.setWidth(width); |
129 |
1
1. createAppearance : removed call to com/lowagie/text/pdf/PdfAppearance::setHeight → NO_COVERAGE |
template.setHeight(height); |
130 | writer.addDirectTemplateSimple(template, forcedName); | |
131 |
1
1. createAppearance : mutated return of Object value for com/lowagie/text/pdf/PdfAppearance::createAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return template; |
132 | } | |
133 | ||
134 | /** | |
135 | * Set the font and the size for the subsequent text writing. | |
136 | * | |
137 | * @param bf the font | |
138 | * @param size the font size in points | |
139 | */ | |
140 | public void setFontAndSize(BaseFont bf, float size) { | |
141 |
1
1. setFontAndSize : removed call to com/lowagie/text/pdf/PdfAppearance::checkWriter → NO_COVERAGE |
checkWriter(); |
142 | state.size = size; | |
143 |
1
1. setFontAndSize : negated conditional → NO_COVERAGE |
if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) { |
144 | state.fontDetails = new FontDetails(null, ((DocumentFont)bf).getIndirectReference(), bf); | |
145 | } | |
146 | else | |
147 | state.fontDetails = writer.addSimple(bf); | |
148 | PdfName psn = stdFieldFontNames.get(bf.getPostscriptFontName()); | |
149 |
1
1. setFontAndSize : negated conditional → NO_COVERAGE |
if (psn == null) { |
150 |
2
1. setFontAndSize : negated conditional → NO_COVERAGE 2. setFontAndSize : negated conditional → NO_COVERAGE |
if (bf.isSubset() && bf.getFontType() == BaseFont.FONT_TYPE_TTUNI) |
151 | psn = state.fontDetails.getFontName(); | |
152 | else { | |
153 | psn = new PdfName(bf.getPostscriptFontName()); | |
154 |
1
1. setFontAndSize : removed call to com/lowagie/text/pdf/FontDetails::setSubset → NO_COVERAGE |
state.fontDetails.setSubset(false); |
155 | } | |
156 | } | |
157 | PageResources prs = getPageResources(); | |
158 | // PdfName name = state.fontDetails.getFontName(); | |
159 | prs.addFont(psn, state.fontDetails.getIndirectReference()); | |
160 | content.append(psn.getBytes()).append(' ').append(size).append(" Tf").append_i(separator); | |
161 | } | |
162 | ||
163 | public PdfContentByte getDuplicate() { | |
164 | PdfAppearance tpl = new PdfAppearance(); | |
165 | tpl.writer = writer; | |
166 | tpl.pdf = pdf; | |
167 | tpl.thisReference = thisReference; | |
168 | tpl.pageResources = pageResources; | |
169 | tpl.bBox = new Rectangle(bBox); | |
170 | tpl.group = group; | |
171 | tpl.layer = layer; | |
172 |
1
1. getDuplicate : negated conditional → NO_COVERAGE |
if (matrix != null) { |
173 | tpl.matrix = new PdfArray(matrix); | |
174 | } | |
175 | tpl.separator = separator; | |
176 |
1
1. getDuplicate : mutated return of Object value for com/lowagie/text/pdf/PdfAppearance::getDuplicate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return tpl; |
177 | } | |
178 | } | |
Mutations | ||
123 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
131 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 2.2 |
|
154 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |