Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/page/cpdf_streamcontentparser.h" | 7 #include "core/fpdfapi/page/cpdf_streamcontentparser.h" |
| 8 | 8 |
| 9 #include <memory> | |
| 10 #include <utility> | |
| 11 #include <vector> | |
| 12 | |
| 9 #include "core/fpdfapi/font/cpdf_font.h" | 13 #include "core/fpdfapi/font/cpdf_font.h" |
| 10 #include "core/fpdfapi/font/cpdf_type3font.h" | 14 #include "core/fpdfapi/font/cpdf_type3font.h" |
| 11 #include "core/fpdfapi/page/cpdf_allstates.h" | 15 #include "core/fpdfapi/page/cpdf_allstates.h" |
| 12 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 16 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 13 #include "core/fpdfapi/page/cpdf_form.h" | 17 #include "core/fpdfapi/page/cpdf_form.h" |
| 14 #include "core/fpdfapi/page/cpdf_formobject.h" | 18 #include "core/fpdfapi/page/cpdf_formobject.h" |
| 15 #include "core/fpdfapi/page/cpdf_image.h" | 19 #include "core/fpdfapi/page/cpdf_image.h" |
| 16 #include "core/fpdfapi/page/cpdf_imageobject.h" | 20 #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 17 #include "core/fpdfapi/page/cpdf_meshstream.h" | 21 #include "core/fpdfapi/page/cpdf_meshstream.h" |
| 18 #include "core/fpdfapi/page/cpdf_pageobject.h" | 22 #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 19 #include "core/fpdfapi/page/cpdf_pathobject.h" | 23 #include "core/fpdfapi/page/cpdf_pathobject.h" |
| 20 #include "core/fpdfapi/page/cpdf_shadingobject.h" | 24 #include "core/fpdfapi/page/cpdf_shadingobject.h" |
| 21 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 25 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
| 22 #include "core/fpdfapi/page/cpdf_textobject.h" | 26 #include "core/fpdfapi/page/cpdf_textobject.h" |
| 23 #include "core/fpdfapi/page/pageint.h" | 27 #include "core/fpdfapi/page/pageint.h" |
| 24 #include "core/fpdfapi/parser/cpdf_array.h" | 28 #include "core/fpdfapi/parser/cpdf_array.h" |
| 29 #include "core/fpdfapi/parser/cpdf_dictionary.h" | |
| 25 #include "core/fpdfapi/parser/cpdf_document.h" | 30 #include "core/fpdfapi/parser/cpdf_document.h" |
| 26 #include "core/fpdfapi/parser/cpdf_name.h" | 31 #include "core/fpdfapi/parser/cpdf_name.h" |
| 27 #include "core/fpdfapi/parser/cpdf_number.h" | 32 #include "core/fpdfapi/parser/cpdf_number.h" |
| 33 #include "core/fpdfapi/parser/cpdf_stream.h" | |
| 28 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 34 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 29 #include "core/fxcrt/fx_safe_types.h" | 35 #include "core/fxcrt/fx_safe_types.h" |
| 36 #include "core/fxge/cfx_graphstatedata.h" | |
| 30 #include "third_party/base/ptr_util.h" | 37 #include "third_party/base/ptr_util.h" |
| 31 | 38 |
| 32 namespace { | 39 namespace { |
| 33 | 40 |
| 34 const int kMaxFormLevel = 30; | 41 const int kMaxFormLevel = 30; |
| 35 | 42 |
| 36 const int kSingleCoordinatePair = 1; | 43 const int kSingleCoordinatePair = 1; |
| 37 const int kTensorCoordinatePairs = 16; | 44 const int kTensorCoordinatePairs = 16; |
| 38 const int kCoonsCoordinatePairs = 12; | 45 const int kCoonsCoordinatePairs = 12; |
| 39 const int kSingleColorPerPatch = 1; | 46 const int kSingleColorPerPatch = 1; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 break; | 122 break; |
| 116 | 123 |
| 117 stream.BitStream()->SkipBits(nBits.ValueOrDie()); | 124 stream.BitStream()->SkipBits(nBits.ValueOrDie()); |
| 118 if (bGouraud) | 125 if (bGouraud) |
| 119 stream.BitStream()->ByteAlign(); | 126 stream.BitStream()->ByteAlign(); |
| 120 } | 127 } |
| 121 rect.Transform(&matrix); | 128 rect.Transform(&matrix); |
| 122 return rect; | 129 return rect; |
| 123 } | 130 } |
| 124 | 131 |
| 132 struct PDF_AbbrPair { | |
| 133 const FX_CHAR* abbr; | |
| 134 const FX_CHAR* full_name; | |
| 135 }; | |
| 136 | |
| 137 const PDF_AbbrPair PDF_InlineKeyAbbr[] = { | |
|
dsinclair
2016/11/07 14:19:54
nit: Since these are all in the anonymous namespac
npm
2016/11/07 16:18:39
Done.
| |
| 138 {"BPC", "BitsPerComponent"}, {"CS", "ColorSpace"}, {"D", "Decode"}, | |
| 139 {"DP", "DecodeParms"}, {"F", "Filter"}, {"H", "Height"}, | |
| 140 {"IM", "ImageMask"}, {"I", "Interpolate"}, {"W", "Width"}, | |
| 141 }; | |
| 142 | |
| 143 const PDF_AbbrPair PDF_InlineValueAbbr[] = { | |
| 144 {"G", "DeviceGray"}, {"RGB", "DeviceRGB"}, | |
| 145 {"CMYK", "DeviceCMYK"}, {"I", "Indexed"}, | |
| 146 {"AHx", "ASCIIHexDecode"}, {"A85", "ASCII85Decode"}, | |
| 147 {"LZW", "LZWDecode"}, {"Fl", "FlateDecode"}, | |
| 148 {"RL", "RunLengthDecode"}, {"CCF", "CCITTFaxDecode"}, | |
| 149 {"DCT", "DCTDecode"}, | |
| 150 }; | |
| 151 | |
| 152 struct AbbrReplacementOp { | |
| 153 bool is_replace_key; | |
| 154 CFX_ByteString key; | |
| 155 CFX_ByteStringC replacement; | |
| 156 }; | |
| 157 | |
| 158 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPair* table, | |
| 159 size_t count, | |
| 160 const CFX_ByteStringC& abbr) { | |
| 161 auto it = std::find_if( | |
| 162 table, table + count, | |
| 163 [abbr](const PDF_AbbrPair& pair) { return pair.abbr == abbr; }); | |
| 164 return it != table + count ? CFX_ByteStringC(it->full_name) | |
| 165 : CFX_ByteStringC(); | |
| 166 } | |
| 167 | |
| 168 void PDF_ReplaceAbbr(CPDF_Object* pObj) { | |
| 169 switch (pObj->GetType()) { | |
| 170 case CPDF_Object::DICTIONARY: { | |
| 171 CPDF_Dictionary* pDict = pObj->AsDictionary(); | |
| 172 std::vector<AbbrReplacementOp> replacements; | |
| 173 for (const auto& it : *pDict) { | |
| 174 CFX_ByteString key = it.first; | |
| 175 CPDF_Object* value = it.second; | |
| 176 CFX_ByteStringC fullname = | |
| 177 PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), | |
| 178 key.AsStringC()); | |
| 179 if (!fullname.IsEmpty()) { | |
| 180 AbbrReplacementOp op; | |
| 181 op.is_replace_key = true; | |
| 182 op.key = key; | |
| 183 op.replacement = fullname; | |
| 184 replacements.push_back(op); | |
| 185 key = fullname; | |
| 186 } | |
| 187 | |
| 188 if (value->IsName()) { | |
| 189 CFX_ByteString name = value->GetString(); | |
| 190 fullname = PDF_FindFullName(PDF_InlineValueAbbr, | |
| 191 FX_ArraySize(PDF_InlineValueAbbr), | |
| 192 name.AsStringC()); | |
| 193 if (!fullname.IsEmpty()) { | |
| 194 AbbrReplacementOp op; | |
| 195 op.is_replace_key = false; | |
| 196 op.key = key; | |
| 197 op.replacement = fullname; | |
| 198 replacements.push_back(op); | |
| 199 } | |
| 200 } else { | |
| 201 PDF_ReplaceAbbr(value); | |
| 202 } | |
| 203 } | |
| 204 for (const auto& op : replacements) { | |
| 205 if (op.is_replace_key) | |
| 206 pDict->ReplaceKey(op.key, CFX_ByteString(op.replacement)); | |
| 207 else | |
| 208 pDict->SetNameFor(op.key, CFX_ByteString(op.replacement)); | |
| 209 } | |
| 210 break; | |
| 211 } | |
| 212 case CPDF_Object::ARRAY: { | |
| 213 CPDF_Array* pArray = pObj->AsArray(); | |
| 214 for (size_t i = 0; i < pArray->GetCount(); i++) { | |
| 215 CPDF_Object* pElement = pArray->GetObjectAt(i); | |
| 216 if (pElement->IsName()) { | |
| 217 CFX_ByteString name = pElement->GetString(); | |
| 218 CFX_ByteStringC fullname = PDF_FindFullName( | |
| 219 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), | |
| 220 name.AsStringC()); | |
| 221 if (!fullname.IsEmpty()) | |
| 222 pArray->SetAt(i, new CPDF_Name(CFX_ByteString(fullname))); | |
| 223 } else { | |
| 224 PDF_ReplaceAbbr(pElement); | |
| 225 } | |
| 226 } | |
| 227 break; | |
| 228 } | |
| 229 default: | |
| 230 break; | |
| 231 } | |
| 232 } | |
| 233 | |
| 125 } // namespace | 234 } // namespace |
| 126 | 235 |
| 236 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr) { | |
| 237 return PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), | |
| 238 abbr); | |
| 239 } | |
| 240 | |
| 241 CFX_ByteStringC PDF_FindValueAbbreviationForTesting( | |
| 242 const CFX_ByteStringC& abbr) { | |
| 243 return PDF_FindFullName(PDF_InlineValueAbbr, | |
| 244 FX_ArraySize(PDF_InlineValueAbbr), abbr); | |
| 245 } | |
| 246 | |
| 127 CPDF_StreamContentParser::CPDF_StreamContentParser( | 247 CPDF_StreamContentParser::CPDF_StreamContentParser( |
| 128 CPDF_Document* pDocument, | 248 CPDF_Document* pDocument, |
| 129 CPDF_Dictionary* pPageResources, | 249 CPDF_Dictionary* pPageResources, |
| 130 CPDF_Dictionary* pParentResources, | 250 CPDF_Dictionary* pParentResources, |
| 131 const CFX_Matrix* pmtContentToUser, | 251 const CFX_Matrix* pmtContentToUser, |
| 132 CPDF_PageObjectHolder* pObjHolder, | 252 CPDF_PageObjectHolder* pObjHolder, |
| 133 CPDF_Dictionary* pResources, | 253 CPDF_Dictionary* pResources, |
| 134 CFX_FloatRect* pBBox, | 254 CFX_FloatRect* pBBox, |
| 135 CPDF_AllStates* pStates, | 255 CPDF_AllStates* pStates, |
| 136 int level) | 256 int level) |
| (...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1555 } | 1675 } |
| 1556 default: | 1676 default: |
| 1557 bProcessed = false; | 1677 bProcessed = false; |
| 1558 } | 1678 } |
| 1559 if (!bProcessed) { | 1679 if (!bProcessed) { |
| 1560 m_pSyntax->SetPos(last_pos); | 1680 m_pSyntax->SetPos(last_pos); |
| 1561 return; | 1681 return; |
| 1562 } | 1682 } |
| 1563 } | 1683 } |
| 1564 } | 1684 } |
| OLD | NEW |