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(PaintOperation nOperation) { |
| 54 if (m_csDA.IsEmpty()) |
| 55 return FALSE; |
| 56 |
| 57 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 58 if (syntax.FindTagParamFromStart( |
| 59 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 60 return TRUE; |
| 61 } |
| 62 if (syntax.FindTagParamFromStart( |
| 63 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 64 return TRUE; |
| 65 } |
| 66 return syntax.FindTagParamFromStart( |
| 67 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4); |
| 68 } |
| 69 |
| 70 CFX_ByteString CPDF_DefaultAppearance::GetColorString( |
| 71 PaintOperation nOperation) { |
| 72 CFX_ByteString csColor; |
| 73 if (m_csDA.IsEmpty()) |
| 74 return csColor; |
| 75 |
| 76 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 77 if (syntax.FindTagParamFromStart( |
| 78 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 79 csColor += syntax.GetWord(); |
| 80 csColor += " "; |
| 81 csColor += syntax.GetWord(); |
| 82 return csColor; |
| 83 } |
| 84 if (syntax.FindTagParamFromStart( |
| 85 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 86 csColor += syntax.GetWord(); |
| 87 csColor += " "; |
| 88 csColor += syntax.GetWord(); |
| 89 csColor += " "; |
| 90 csColor += syntax.GetWord(); |
| 91 csColor += " "; |
| 92 csColor += syntax.GetWord(); |
| 93 return csColor; |
| 94 } |
| 95 if (syntax.FindTagParamFromStart( |
| 96 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 97 csColor += syntax.GetWord(); |
| 98 csColor += " "; |
| 99 csColor += syntax.GetWord(); |
| 100 csColor += " "; |
| 101 csColor += syntax.GetWord(); |
| 102 csColor += " "; |
| 103 csColor += syntax.GetWord(); |
| 104 csColor += " "; |
| 105 csColor += syntax.GetWord(); |
| 106 } |
| 107 return csColor; |
| 108 } |
| 109 |
| 110 void CPDF_DefaultAppearance::GetColor(int& iColorType, |
| 111 FX_FLOAT fc[4], |
| 112 PaintOperation nOperation) { |
| 113 iColorType = COLORTYPE_TRANSPARENT; |
| 114 for (int c = 0; c < 4; c++) |
| 115 fc[c] = 0; |
| 116 |
| 117 if (m_csDA.IsEmpty()) |
| 118 return; |
| 119 |
| 120 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 121 if (syntax.FindTagParamFromStart( |
| 122 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 123 iColorType = COLORTYPE_GRAY; |
| 124 fc[0] = FX_atof(syntax.GetWord()); |
| 125 return; |
| 126 } |
| 127 if (syntax.FindTagParamFromStart( |
| 128 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 129 iColorType = COLORTYPE_RGB; |
| 130 fc[0] = FX_atof(syntax.GetWord()); |
| 131 fc[1] = FX_atof(syntax.GetWord()); |
| 132 fc[2] = FX_atof(syntax.GetWord()); |
| 133 return; |
| 134 } |
| 135 if (syntax.FindTagParamFromStart( |
| 136 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 137 iColorType = COLORTYPE_CMYK; |
| 138 fc[0] = FX_atof(syntax.GetWord()); |
| 139 fc[1] = FX_atof(syntax.GetWord()); |
| 140 fc[2] = FX_atof(syntax.GetWord()); |
| 141 fc[3] = FX_atof(syntax.GetWord()); |
| 142 } |
| 143 } |
| 144 |
| 145 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, |
| 146 int& iColorType, |
| 147 PaintOperation nOperation) { |
| 148 color = 0; |
| 149 iColorType = COLORTYPE_TRANSPARENT; |
| 150 if (m_csDA.IsEmpty()) |
| 151 return; |
| 152 |
| 153 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 154 if (syntax.FindTagParamFromStart( |
| 155 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 156 iColorType = COLORTYPE_GRAY; |
| 157 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 158 color = ArgbEncode(255, (int)g, (int)g, (int)g); |
| 159 return; |
| 160 } |
| 161 if (syntax.FindTagParamFromStart( |
| 162 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 163 iColorType = COLORTYPE_RGB; |
| 164 FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 165 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 166 FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 167 color = ArgbEncode(255, (int)r, (int)g, (int)b); |
| 168 return; |
| 169 } |
| 170 if (syntax.FindTagParamFromStart( |
| 171 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 172 iColorType = COLORTYPE_CMYK; |
| 173 FX_FLOAT c = FX_atof(syntax.GetWord()); |
| 174 FX_FLOAT m = FX_atof(syntax.GetWord()); |
| 175 FX_FLOAT y = FX_atof(syntax.GetWord()); |
| 176 FX_FLOAT k = FX_atof(syntax.GetWord()); |
| 177 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); |
| 178 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); |
| 179 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); |
| 180 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), |
| 181 (int)(b * 255 + 0.5f)); |
| 182 } |
| 183 } |
| 184 |
| 185 FX_BOOL CPDF_DefaultAppearance::HasTextMatrix() { |
| 186 if (m_csDA.IsEmpty()) |
| 187 return FALSE; |
| 188 |
| 189 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 190 return syntax.FindTagParamFromStart("Tm", 6); |
| 191 } |
| 192 |
| 193 CFX_ByteString CPDF_DefaultAppearance::GetTextMatrixString() { |
| 194 CFX_ByteString csTM; |
| 195 if (m_csDA.IsEmpty()) |
| 196 return csTM; |
| 197 |
| 198 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 199 if (syntax.FindTagParamFromStart("Tm", 6)) { |
| 200 for (int i = 0; i < 6; i++) { |
| 201 csTM += syntax.GetWord(); |
| 202 csTM += " "; |
| 203 } |
| 204 csTM += syntax.GetWord(); |
| 205 } |
| 206 return csTM; |
| 207 } |
| 208 |
| 209 CFX_Matrix CPDF_DefaultAppearance::GetTextMatrix() { |
| 210 CFX_Matrix tm; |
| 211 if (m_csDA.IsEmpty()) |
| 212 return tm; |
| 213 |
| 214 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 215 if (syntax.FindTagParamFromStart("Tm", 6)) { |
| 216 FX_FLOAT f[6]; |
| 217 for (int i = 0; i < 6; i++) |
| 218 f[i] = FX_atof(syntax.GetWord()); |
| 219 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); |
| 220 } |
| 221 return tm; |
| 222 } |
OLD | NEW |