| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | 112 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 113 if (syntax.FindTagParamFromStart("Tf", 2)) { | 113 if (syntax.FindTagParamFromStart("Tf", 2)) { |
| 114 csFontNameTag = CFX_ByteString(syntax.GetWord()); | 114 csFontNameTag = CFX_ByteString(syntax.GetWord()); |
| 115 csFontNameTag.Delete(0, 1); | 115 csFontNameTag.Delete(0, 1); |
| 116 fFontSize = FX_atof(syntax.GetWord()); | 116 fFontSize = FX_atof(syntax.GetWord()); |
| 117 } | 117 } |
| 118 csFontNameTag = PDF_NameDecode(csFontNameTag); | 118 csFontNameTag = PDF_NameDecode(csFontNameTag); |
| 119 } | 119 } |
| 120 FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) { | 120 FX_BOOL CPDF_DefaultAppearance::HasColor(PaintOperation nOperation) { |
| 121 if (m_csDA.IsEmpty()) { | 121 if (m_csDA.IsEmpty()) { |
| 122 return FALSE; | 122 return FALSE; |
| 123 } | 123 } |
| 124 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | 124 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 125 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | 125 if (syntax.FindTagParamFromStart( |
| 126 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 126 return TRUE; | 127 return TRUE; |
| 127 } | 128 } |
| 128 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | 129 if (syntax.FindTagParamFromStart( |
| 130 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 129 return TRUE; | 131 return TRUE; |
| 130 } | 132 } |
| 131 return syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4); | 133 return syntax.FindTagParamFromStart( |
| 134 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4); |
| 132 } | 135 } |
| 133 CFX_ByteString CPDF_DefaultAppearance::GetColorString( | 136 CFX_ByteString CPDF_DefaultAppearance::GetColorString( |
| 134 FX_BOOL bStrokingOperation) { | 137 PaintOperation nOperation) { |
| 135 CFX_ByteString csColor; | 138 CFX_ByteString csColor; |
| 136 if (m_csDA.IsEmpty()) { | 139 if (m_csDA.IsEmpty()) { |
| 137 return csColor; | 140 return csColor; |
| 138 } | 141 } |
| 139 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | 142 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 140 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | 143 if (syntax.FindTagParamFromStart( |
| 144 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 141 csColor += syntax.GetWord(); | 145 csColor += syntax.GetWord(); |
| 142 csColor += " "; | 146 csColor += " "; |
| 143 csColor += syntax.GetWord(); | 147 csColor += syntax.GetWord(); |
| 144 return csColor; | 148 return csColor; |
| 145 } | 149 } |
| 146 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | 150 if (syntax.FindTagParamFromStart( |
| 151 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 147 csColor += syntax.GetWord(); | 152 csColor += syntax.GetWord(); |
| 148 csColor += " "; | 153 csColor += " "; |
| 149 csColor += syntax.GetWord(); | 154 csColor += syntax.GetWord(); |
| 150 csColor += " "; | 155 csColor += " "; |
| 151 csColor += syntax.GetWord(); | 156 csColor += syntax.GetWord(); |
| 152 csColor += " "; | 157 csColor += " "; |
| 153 csColor += syntax.GetWord(); | 158 csColor += syntax.GetWord(); |
| 154 return csColor; | 159 return csColor; |
| 155 } | 160 } |
| 156 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | 161 if (syntax.FindTagParamFromStart( |
| 162 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 157 csColor += syntax.GetWord(); | 163 csColor += syntax.GetWord(); |
| 158 csColor += " "; | 164 csColor += " "; |
| 159 csColor += syntax.GetWord(); | 165 csColor += syntax.GetWord(); |
| 160 csColor += " "; | 166 csColor += " "; |
| 161 csColor += syntax.GetWord(); | 167 csColor += syntax.GetWord(); |
| 162 csColor += " "; | 168 csColor += " "; |
| 163 csColor += syntax.GetWord(); | 169 csColor += syntax.GetWord(); |
| 164 csColor += " "; | 170 csColor += " "; |
| 165 csColor += syntax.GetWord(); | 171 csColor += syntax.GetWord(); |
| 166 } | 172 } |
| 167 return csColor; | 173 return csColor; |
| 168 } | 174 } |
| 169 void CPDF_DefaultAppearance::GetColor(int& iColorType, | 175 void CPDF_DefaultAppearance::GetColor(int& iColorType, |
| 170 FX_FLOAT fc[4], | 176 FX_FLOAT fc[4], |
| 171 FX_BOOL bStrokingOperation) { | 177 PaintOperation nOperation) { |
| 172 iColorType = COLORTYPE_TRANSPARENT; | 178 iColorType = COLORTYPE_TRANSPARENT; |
| 173 for (int c = 0; c < 4; c++) { | 179 for (int c = 0; c < 4; c++) { |
| 174 fc[c] = 0; | 180 fc[c] = 0; |
| 175 } | 181 } |
| 176 if (m_csDA.IsEmpty()) { | 182 if (m_csDA.IsEmpty()) { |
| 177 return; | 183 return; |
| 178 } | 184 } |
| 179 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | 185 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 180 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | 186 if (syntax.FindTagParamFromStart( |
| 187 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 181 iColorType = COLORTYPE_GRAY; | 188 iColorType = COLORTYPE_GRAY; |
| 182 fc[0] = FX_atof(syntax.GetWord()); | 189 fc[0] = FX_atof(syntax.GetWord()); |
| 183 return; | 190 return; |
| 184 } | 191 } |
| 185 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | 192 if (syntax.FindTagParamFromStart( |
| 193 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 186 iColorType = COLORTYPE_RGB; | 194 iColorType = COLORTYPE_RGB; |
| 187 fc[0] = FX_atof(syntax.GetWord()); | 195 fc[0] = FX_atof(syntax.GetWord()); |
| 188 fc[1] = FX_atof(syntax.GetWord()); | 196 fc[1] = FX_atof(syntax.GetWord()); |
| 189 fc[2] = FX_atof(syntax.GetWord()); | 197 fc[2] = FX_atof(syntax.GetWord()); |
| 190 return; | 198 return; |
| 191 } | 199 } |
| 192 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | 200 if (syntax.FindTagParamFromStart( |
| 201 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 193 iColorType = COLORTYPE_CMYK; | 202 iColorType = COLORTYPE_CMYK; |
| 194 fc[0] = FX_atof(syntax.GetWord()); | 203 fc[0] = FX_atof(syntax.GetWord()); |
| 195 fc[1] = FX_atof(syntax.GetWord()); | 204 fc[1] = FX_atof(syntax.GetWord()); |
| 196 fc[2] = FX_atof(syntax.GetWord()); | 205 fc[2] = FX_atof(syntax.GetWord()); |
| 197 fc[3] = FX_atof(syntax.GetWord()); | 206 fc[3] = FX_atof(syntax.GetWord()); |
| 198 } | 207 } |
| 199 } | 208 } |
| 200 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, | 209 void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, |
| 201 int& iColorType, | 210 int& iColorType, |
| 202 FX_BOOL bStrokingOperation) { | 211 PaintOperation nOperation) { |
| 203 color = 0; | 212 color = 0; |
| 204 iColorType = COLORTYPE_TRANSPARENT; | 213 iColorType = COLORTYPE_TRANSPARENT; |
| 205 if (m_csDA.IsEmpty()) { | 214 if (m_csDA.IsEmpty()) { |
| 206 return; | 215 return; |
| 207 } | 216 } |
| 208 CPDF_SimpleParser syntax(m_csDA.AsStringC()); | 217 CPDF_SimpleParser syntax(m_csDA.AsStringC()); |
| 209 if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { | 218 if (syntax.FindTagParamFromStart( |
| 219 (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { |
| 210 iColorType = COLORTYPE_GRAY; | 220 iColorType = COLORTYPE_GRAY; |
| 211 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; | 221 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 212 color = ArgbEncode(255, (int)g, (int)g, (int)g); | 222 color = ArgbEncode(255, (int)g, (int)g, (int)g); |
| 213 return; | 223 return; |
| 214 } | 224 } |
| 215 if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { | 225 if (syntax.FindTagParamFromStart( |
| 226 (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { |
| 216 iColorType = COLORTYPE_RGB; | 227 iColorType = COLORTYPE_RGB; |
| 217 FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f; | 228 FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 218 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; | 229 FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 219 FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f; | 230 FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f; |
| 220 color = ArgbEncode(255, (int)r, (int)g, (int)b); | 231 color = ArgbEncode(255, (int)r, (int)g, (int)b); |
| 221 return; | 232 return; |
| 222 } | 233 } |
| 223 if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { | 234 if (syntax.FindTagParamFromStart( |
| 235 (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { |
| 224 iColorType = COLORTYPE_CMYK; | 236 iColorType = COLORTYPE_CMYK; |
| 225 FX_FLOAT c = FX_atof(syntax.GetWord()); | 237 FX_FLOAT c = FX_atof(syntax.GetWord()); |
| 226 FX_FLOAT m = FX_atof(syntax.GetWord()); | 238 FX_FLOAT m = FX_atof(syntax.GetWord()); |
| 227 FX_FLOAT y = FX_atof(syntax.GetWord()); | 239 FX_FLOAT y = FX_atof(syntax.GetWord()); |
| 228 FX_FLOAT k = FX_atof(syntax.GetWord()); | 240 FX_FLOAT k = FX_atof(syntax.GetWord()); |
| 229 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); | 241 FX_FLOAT r = 1.0f - std::min(1.0f, c + k); |
| 230 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); | 242 FX_FLOAT g = 1.0f - std::min(1.0f, m + k); |
| 231 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); | 243 FX_FLOAT b = 1.0f - std::min(1.0f, y + k); |
| 232 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), | 244 color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), |
| 233 (int)(b * 255 + 0.5f)); | 245 (int)(b * 255 + 0.5f)); |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); | 761 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); |
| 750 if (pAttr) { | 762 if (pAttr) { |
| 751 return pAttr; | 763 return pAttr; |
| 752 } | 764 } |
| 753 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); | 765 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); |
| 754 if (!pParent) { | 766 if (!pParent) { |
| 755 return nullptr; | 767 return nullptr; |
| 756 } | 768 } |
| 757 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 769 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 758 } | 770 } |
| OLD | NEW |