OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fpdfdoc/include/cpdf_defaultappearance.h" | |
8 | |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | |
10 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | |
11 #include "core/fpdfdoc/include/cpdf_formcontrol.h" | |
12 | |
13 FX_BOOL CPDF_DefaultAppearance::HasFont() { | |
14 if (m_csDA.IsEmpty()) | |
15 return FALSE; | |
16 | |
17 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
18 return syntax.FindTagParamFromStart("Tf", 2); | |
19 } | |
20 | |
21 CFX_ByteString CPDF_DefaultAppearance::GetFontString() { | |
22 CFX_ByteString csFont; | |
23 if (m_csDA.IsEmpty()) | |
24 return csFont; | |
25 | |
26 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
27 if (syntax.FindTagParamFromStart("Tf", 2)) { | |
28 csFont += syntax.GetWord(); | |
29 csFont += " "; | |
30 csFont += syntax.GetWord(); | |
31 csFont += " "; | |
32 csFont += syntax.GetWord(); | |
33 } | |
34 return csFont; | |
35 } | |
36 | |
37 void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag, | |
38 FX_FLOAT& fFontSize) { | |
39 csFontNameTag = ""; | |
40 fFontSize = 0; | |
41 if (m_csDA.IsEmpty()) | |
42 return; | |
43 | |
44 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
45 if (syntax.FindTagParamFromStart("Tf", 2)) { | |
46 csFontNameTag = CFX_ByteString(syntax.GetWord()); | |
47 csFontNameTag.Delete(0, 1); | |
48 fFontSize = FX_atof(syntax.GetWord()); | |
49 } | |
50 csFontNameTag = PDF_NameDecode(csFontNameTag); | |
51 } | |
52 | |
53 FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) { | |
54 if (m_csDA.IsEmpty()) | |
55 return FALSE; | |
56 | |
57 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
58 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) | |
59 return TRUE; | |
60 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) | |
61 return TRUE; | |
62 return syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4); | |
63 } | |
64 | |
65 CFX_ByteString CPDF_DefaultAppearance::GetColorString( | |
66 FX_BOOL bStrokingOperation) { | |
67 CFX_ByteString csColor; | |
68 if (m_csDA.IsEmpty()) | |
69 return csColor; | |
70 | |
71 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
72 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | |
73 csColor += syntax.GetWord(); | |
74 csColor += " "; | |
75 csColor += syntax.GetWord(); | |
76 return csColor; | |
77 } | |
78 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | |
79 csColor += syntax.GetWord(); | |
80 csColor += " "; | |
81 csColor += syntax.GetWord(); | |
82 csColor += " "; | |
83 csColor += syntax.GetWord(); | |
84 csColor += " "; | |
85 csColor += syntax.GetWord(); | |
86 return csColor; | |
87 } | |
88 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | |
89 csColor += syntax.GetWord(); | |
90 csColor += " "; | |
91 csColor += syntax.GetWord(); | |
92 csColor += " "; | |
93 csColor += syntax.GetWord(); | |
94 csColor += " "; | |
95 csColor += syntax.GetWord(); | |
96 csColor += " "; | |
97 csColor += syntax.GetWord(); | |
98 } | |
99 return csColor; | |
100 } | |
101 | |
102 void CPDF_DefaultAppearance::GetColor(int& iColorType, | |
103 FX_FLOAT fc[4], | |
104 FX_BOOL bStrokingOperation) { | |
105 iColorType = COLORTYPE_TRANSPARENT; | |
106 for (int c = 0; c < 4; c++) | |
107 fc[c] = 0; | |
108 | |
109 if (m_csDA.IsEmpty()) | |
110 return; | |
111 | |
112 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
113 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | |
114 iColorType = COLORTYPE_GRAY; | |
115 fc[0] = FX_atof(syntax.GetWord()); | |
116 return; | |
117 } | |
118 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | |
119 iColorType = COLORTYPE_RGB; | |
120 fc[0] = FX_atof(syntax.GetWord()); | |
121 fc[1] = FX_atof(syntax.GetWord()); | |
122 fc[2] = FX_atof(syntax.GetWord()); | |
123 return; | |
124 } | |
125 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | |
126 iColorType = COLORTYPE_CMYK; | |
127 fc[0] = FX_atof(syntax.GetWord()); | |
128 fc[1] = FX_atof(syntax.GetWord()); | |
129 fc[2] = FX_atof(syntax.GetWord()); | |
130 fc[3] = FX_atof(syntax.GetWord()); | |
131 } | |
132 } | |
133 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, | |
Lei Zhang
2016/07/28 22:15:06
missed a new line here
dsinclair
2016/08/02 18:12:32
Done.
| |
134 int& iColorType, | |
135 FX_BOOL bStrokingOperation) { | |
136 color = 0; | |
137 iColorType = COLORTYPE_TRANSPARENT; | |
138 if (m_csDA.IsEmpty()) | |
139 return; | |
140 | |
141 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
142 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | |
143 iColorType = COLORTYPE_GRAY; | |
144 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; | |
145 color = ArgbEncode(255, (int)g, (int)g, (int)g); | |
146 return; | |
147 } | |
148 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | |
149 iColorType = COLORTYPE_RGB; | |
150 FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f; | |
151 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; | |
152 FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f; | |
153 color = ArgbEncode(255, (int)r, (int)g, (int)b); | |
154 return; | |
155 } | |
156 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | |
157 iColorType = COLORTYPE_CMYK; | |
158 FX_FLOAT c = FX_atof(syntax.GetWord()); | |
159 FX_FLOAT m = FX_atof(syntax.GetWord()); | |
160 FX_FLOAT y = FX_atof(syntax.GetWord()); | |
161 FX_FLOAT k = FX_atof(syntax.GetWord()); | |
162 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); | |
163 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); | |
164 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); | |
165 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), | |
166 (int)(b * 255 + 0.5f)); | |
167 } | |
168 } | |
169 | |
170 FX_BOOL CPDF_DefaultAppearance::HasTextMatrix() { | |
171 if (m_csDA.IsEmpty()) | |
172 return FALSE; | |
173 | |
174 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
175 return syntax.FindTagParamFromStart("Tm", 6); | |
176 } | |
177 | |
178 CFX_ByteString CPDF_DefaultAppearance::GetTextMatrixString() { | |
179 CFX_ByteString csTM; | |
180 if (m_csDA.IsEmpty()) | |
181 return csTM; | |
182 | |
183 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
184 if (syntax.FindTagParamFromStart("Tm", 6)) { | |
185 for (int i = 0; i < 6; i++) { | |
186 csTM += syntax.GetWord(); | |
187 csTM += " "; | |
188 } | |
189 csTM += syntax.GetWord(); | |
190 } | |
191 return csTM; | |
192 } | |
193 | |
194 CFX_Matrix CPDF_DefaultAppearance::GetTextMatrix() { | |
195 CFX_Matrix tm; | |
196 if (m_csDA.IsEmpty()) | |
197 return tm; | |
198 | |
199 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | |
200 if (syntax.FindTagParamFromStart("Tm", 6)) { | |
201 FX_FLOAT f[6]; | |
202 for (int i = 0; i < 6; i++) | |
203 f[i] = FX_atof(syntax.GetWord()); | |
204 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); | |
205 } | |
206 return tm; | |
207 } | |
OLD | NEW |