Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 1847333004: Remove _FXBSTR* and calls to FX_BSTRC. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/fpdf_page_parser_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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* abbr;
46 int m_Size; 46 const FX_CHAR* full_name;
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 {"BPC", "BitsPerComponent"}, {"CS", "ColorSpace"}, {"D", "Decode"},
Tom Sepez 2016/04/04 16:29:26 That's so much better in that order, it gives a cl
58 {_FX_BSTRC("ColorSpace"), _FX_BSTRC("CS")}, 51 {"DP", "DecodeParms"}, {"F", "Filter"}, {"H", "Height"},
59 {_FX_BSTRC("Decode"), _FX_BSTRC("D")}, 52 {"IM", "ImageMask"}, {"I", "Interpolate"}, {"W", "Width"},
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 {"G", "DeviceGray"}, {"RGB", "DeviceRGB"},
70 {_FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB")}, 57 {"CMYK", "DeviceCMYK"}, {"I", "Indexed"},
71 {_FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK")}, 58 {"AHx", "ASCIIHexDecode"}, {"A85", "ASCII85Decode"},
72 {_FX_BSTRC("Indexed"), _FX_BSTRC("I")}, 59 {"LZW", "LZWDecode"}, {"Fl", "FlateDecode"},
73 {_FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx")}, 60 {"RL", "RunLengthDecode"}, {"CCF", "CCITTFaxDecode"},
74 {_FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85")}, 61 {"DCT", "DCTDecode"},
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_ByteStringC(it->full_name)
Tom Sepez 2016/04/04 16:29:26 I'm going to try to make the ctor explicit. Its l
108 continue; 90 : CFX_ByteStringC();
109 return CFX_ByteStringC(table[i].full_name.m_Ptr, table[i].full_name.m_Size);
110 }
111 return CFX_ByteStringC();
112 } 91 }
113 92
114 } // namespace 93 } // namespace
115 94
95 CFX_ByteStringC PDF_FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr) {
96 return PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr),
97 abbr);
98 }
99
100 CFX_ByteStringC PDF_FindValueAbbreviationForTesting(
101 const CFX_ByteStringC& abbr) {
102 return PDF_FindFullName(PDF_InlineValueAbbr,
103 FX_ArraySize(PDF_InlineValueAbbr), abbr);
104 }
105
116 bool IsPathOperator(const uint8_t* buf, size_t len) { 106 bool IsPathOperator(const uint8_t* buf, size_t len) {
117 if (len == 1) { 107 if (len == 1) {
118 uint8_t op = buf[0]; 108 uint8_t op = buf[0];
119 if (op == kPathOperatorSubpath || op == kPathOperatorLine || 109 if (op == kPathOperatorSubpath || op == kPathOperatorLine ||
120 op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 || 110 op == kPathOperatorCubicBezier1 || op == kPathOperatorCubicBezier2 ||
121 op == kPathOperatorCubicBezier3) { 111 op == kPathOperatorCubicBezier3) {
122 return true; 112 return true;
123 } 113 }
124 } else if (len == 2) { 114 } else if (len == 2) {
125 if (buf[0] == kPathOperatorRectangle[0] && 115 if (buf[0] == kPathOperatorRectangle[0] &&
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 } else { 1811 } else {
1822 PDF_ReplaceAbbr(pElement); 1812 PDF_ReplaceAbbr(pElement);
1823 } 1813 }
1824 } 1814 }
1825 break; 1815 break;
1826 } 1816 }
1827 default: 1817 default:
1828 break; 1818 break;
1829 } 1819 }
1830 } 1820 }
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/fpdf_page_parser_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698