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 "core/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kPathOperatorSubpath = 'm'; | 36 const char kPathOperatorSubpath = 'm'; |
37 const char kPathOperatorLine = 'l'; | 37 const char kPathOperatorLine = 'l'; |
38 const char kPathOperatorCubicBezier1 = 'c'; | 38 const char kPathOperatorCubicBezier1 = 'c'; |
39 const char kPathOperatorCubicBezier2 = 'v'; | 39 const char kPathOperatorCubicBezier2 = 'v'; |
40 const char kPathOperatorCubicBezier3 = 'y'; | 40 const char kPathOperatorCubicBezier3 = 'y'; |
41 const char kPathOperatorClosePath = 'h'; | 41 const char kPathOperatorClosePath = 'h'; |
42 const char kPathOperatorRectangle[] = "re"; | 42 const char kPathOperatorRectangle[] = "re"; |
43 | 43 |
44 struct _FX_BSTR { | 44 struct PDF_AbbrPair { |
45 const FX_CHAR* m_Ptr; | 45 const FX_CHAR* full_name; |
Tom Sepez
2016/04/04 15:57:30
If you'd like, you might consider flipping these a
dsinclair
2016/04/04 16:26:51
Done.
| |
46 int m_Size; | 46 const FX_CHAR* abbr; |
47 }; | |
48 #define _FX_BSTRC(str) \ | |
49 { str, sizeof(str) - 1 } | |
50 | |
51 struct PDF_AbbrPairs { | |
52 _FX_BSTR full_name; | |
53 _FX_BSTR abbr; | |
54 }; | 47 }; |
55 | 48 |
56 const PDF_AbbrPairs PDF_InlineKeyAbbr[] = { | 49 const PDF_AbbrPair PDF_InlineKeyAbbr[] = { |
57 {_FX_BSTRC("BitsPerComponent"), _FX_BSTRC("BPC")}, | 50 {"BitsPerComponent", "BPC"}, {"ColorSpace", "CS"}, {"Decode", "D"}, |
58 {_FX_BSTRC("ColorSpace"), _FX_BSTRC("CS")}, | 51 {"DecodeParms", "DP"}, {"Filter", "F"}, {"Height", "H"}, |
59 {_FX_BSTRC("Decode"), _FX_BSTRC("D")}, | 52 {"ImageMask", "IM"}, {"Interpolate", "I"}, {"Width", "W"}, |
60 {_FX_BSTRC("DecodeParms"), _FX_BSTRC("DP")}, | |
61 {_FX_BSTRC("Filter"), _FX_BSTRC("F")}, | |
62 {_FX_BSTRC("Height"), _FX_BSTRC("H")}, | |
63 {_FX_BSTRC("ImageMask"), _FX_BSTRC("IM")}, | |
64 {_FX_BSTRC("Interpolate"), _FX_BSTRC("I")}, | |
65 {_FX_BSTRC("Width"), _FX_BSTRC("W")}, | |
66 }; | 53 }; |
67 | 54 |
68 const PDF_AbbrPairs PDF_InlineValueAbbr[] = { | 55 const PDF_AbbrPair PDF_InlineValueAbbr[] = { |
69 {_FX_BSTRC("DeviceGray"), _FX_BSTRC("G")}, | 56 {"DeviceGray", "G"}, {"DeviceRGB", "RGB"}, |
70 {_FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB")}, | 57 {"DeviceCMYK", "CMYK"}, {"Indexed", "I"}, |
71 {_FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK")}, | 58 {"ASCIIHexDecode", "AHx"}, {"ASCII85Decode", "A85"}, |
72 {_FX_BSTRC("Indexed"), _FX_BSTRC("I")}, | 59 {"LZWDecode", "LZW"}, {"FlateDecode", "Fl"}, |
73 {_FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx")}, | 60 {"RunLengthDecode", "RL"}, {"CCITTFaxDecode", "CCF"}, |
74 {_FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85")}, | 61 {"DCTDecode", "DCT"}, |
75 {_FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW")}, | |
76 {_FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl")}, | |
77 {_FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL")}, | |
78 {_FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF")}, | |
79 {_FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT")}, | |
80 }; | 62 }; |
81 | 63 |
82 struct AbbrReplacementOp { | 64 struct AbbrReplacementOp { |
83 bool is_replace_key; | 65 bool is_replace_key; |
84 CFX_ByteString key; | 66 CFX_ByteString key; |
85 CFX_ByteStringC replacement; | 67 CFX_ByteStringC replacement; |
86 }; | 68 }; |
87 | 69 |
88 class CPDF_StreamParserAutoClearer { | 70 class CPDF_StreamParserAutoClearer { |
89 public: | 71 public: |
90 CPDF_StreamParserAutoClearer(CPDF_StreamParser** scoped_variable, | 72 CPDF_StreamParserAutoClearer(CPDF_StreamParser** scoped_variable, |
91 CPDF_StreamParser* new_parser) | 73 CPDF_StreamParser* new_parser) |
92 : scoped_variable_(scoped_variable) { | 74 : scoped_variable_(scoped_variable) { |
93 *scoped_variable_ = new_parser; | 75 *scoped_variable_ = new_parser; |
94 } | 76 } |
95 ~CPDF_StreamParserAutoClearer() { *scoped_variable_ = NULL; } | 77 ~CPDF_StreamParserAutoClearer() { *scoped_variable_ = NULL; } |
96 | 78 |
97 private: | 79 private: |
98 CPDF_StreamParser** scoped_variable_; | 80 CPDF_StreamParser** scoped_variable_; |
99 }; | 81 }; |
100 | 82 |
101 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPairs* table, | 83 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPair* table, |
102 size_t count, | 84 size_t count, |
103 const CFX_ByteStringC& abbr) { | 85 const CFX_ByteStringC& abbr) { |
104 for (size_t i = 0; i < count; ++i) { | 86 auto it = std::find_if( |
105 if (abbr.GetLength() != table[i].abbr.m_Size) | 87 table, table + count, |
106 continue; | 88 [abbr](const PDF_AbbrPair& pair) { return pair.abbr == abbr; }); |
107 if (memcmp(abbr.GetPtr(), table[i].abbr.m_Ptr, abbr.GetLength())) | 89 return it != table + count ? CFX_ByteString(it->full_name) : CFX_ByteString(); |
Tom Sepez
2016/04/04 16:11:37
This should be ByteStringC, not ByteString. argh.
dsinclair
2016/04/04 16:26:52
Good catch. Didn't notice the missing C even revie
| |
108 continue; | |
109 return CFX_ByteStringC(table[i].full_name.m_Ptr, table[i].full_name.m_Size); | |
110 } | |
111 return CFX_ByteStringC(); | |
112 } | 90 } |
113 | 91 |
114 } // namespace | 92 } // namespace |
115 | 93 |
94 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr) { | |
95 return PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), | |
96 abbr); | |
97 } | |
98 | |
99 CFX_ByteStringC PDF_FindValueAbbreviationForTesting( | |
100 const CFX_ByteStringC& abbr) { | |
101 return PDF_FindFullName(PDF_InlineValueAbbr, | |
102 FX_ArraySize(PDF_InlineValueAbbr), abbr); | |
103 } | |
104 | |
116 bool IsPathOperator(const uint8_t* buf, size_t len) { | 105 bool IsPathOperator(const uint8_t* buf, size_t len) { |
117 if (len == 1) { | 106 if (len == 1) { |
118 uint8_t op = buf[0]; | 107 uint8_t op = buf[0]; |
119 if (op == kPathOperatorSubpath || op == kPathOperatorLine || | 108 if (op == kPathOperatorSubpath || op == kPathOperatorLine || |
120 op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 || | 109 op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 || |
121 op == kPathOperatorCubicBezier3) { | 110 op == kPathOperatorCubicBezier3) { |
122 return true; | 111 return true; |
123 } | 112 } |
124 } else if (len == 2) { | 113 } else if (len == 2) { |
125 if (buf[0] == kPathOperatorRectangle[0] && | 114 if (buf[0] == kPathOperatorRectangle[0] && |
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1821 } else { | 1810 } else { |
1822 PDF_ReplaceAbbr(pElement); | 1811 PDF_ReplaceAbbr(pElement); |
1823 } | 1812 } |
1824 } | 1813 } |
1825 break; | 1814 break; |
1826 } | 1815 } |
1827 default: | 1816 default: |
1828 break; | 1817 break; |
1829 } | 1818 } |
1830 } | 1819 } |
OLD | NEW |