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

Side by Side Diff: src/pdf/SkPDFTypes.cpp

Issue 1064013003: SkPDF: SkPDFString is no longer aware of wide strings. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-07 (Tuesday) 10:52:40 EDT Created 5 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
« src/pdf/SkPDFDevice.cpp ('K') | « src/pdf/SkPDFTypes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPDFTypes.h" 10 #include "SkPDFTypes.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 //////////////////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////////////////
127 127
128 SkPDFString::SkPDFString(const char value[]) 128 SkPDFString::SkPDFString(const char value[])
129 : fValue(FormatString(value, strlen(value))) { 129 : fValue(FormatString(value, strlen(value))) {
130 } 130 }
131 131
132 SkPDFString::SkPDFString(const SkString& value) 132 SkPDFString::SkPDFString(const SkString& value)
133 : fValue(FormatString(value.c_str(), value.size())) { 133 : fValue(FormatString(value.c_str(), value.size())) {
134 } 134 }
135 135
136 SkPDFString::SkPDFString(const uint16_t* value, size_t len, bool wideChars)
137 : fValue(FormatString(value, len, wideChars)) {
138 }
139
140 SkPDFString::~SkPDFString() {} 136 SkPDFString::~SkPDFString() {}
141 137
142 void SkPDFString::emitObject(SkWStream* stream, 138 void SkPDFString::emitObject(SkWStream* stream,
143 const SkPDFObjNumMap&, 139 const SkPDFObjNumMap&,
144 const SkPDFSubstituteMap&) { 140 const SkPDFSubstituteMap&) {
145 stream->write(fValue.c_str(), fValue.size()); 141 stream->write(fValue.c_str(), fValue.size());
146 } 142 }
147 143
148 // static 144 // static
149 SkString SkPDFString::FormatString(const char* input, size_t len) { 145 SkString SkPDFString::FormatString(const char* cin, size_t len) {
150 return DoFormatString(input, len, false, false);
151 }
152
153 SkString SkPDFString::FormatString(const uint16_t* input, size_t len,
154 bool wideChars) {
155 return DoFormatString(input, len, true, wideChars);
156 }
157
158 // static
159 SkString SkPDFString::DoFormatString(const void* input, size_t len,
160 bool wideInput, bool wideOutput) {
161 SkASSERT(len <= kMaxLen); 146 SkASSERT(len <= kMaxLen);
162 const uint16_t* win = (const uint16_t*) input;
163 const char* cin = (const char*) input;
164
165 if (wideOutput) {
166 SkASSERT(wideInput);
167 SkString result;
168 result.append("<");
169 for (size_t i = 0; i < len; i++) {
170 result.appendHex(win[i], 4);
171 }
172 result.append(">");
173 return result;
174 }
175 147
176 // 7-bit clean is a heuristic to decide what string format to use; 148 // 7-bit clean is a heuristic to decide what string format to use;
177 // a 7-bit clean string should require little escaping. 149 // a 7-bit clean string should require little escaping.
178 bool sevenBitClean = true; 150 bool sevenBitClean = true;
179 for (size_t i = 0; i < len; i++) { 151 for (size_t i = 0; i < len; i++) {
180 SkASSERT(!wideInput || !(win[i] & ~0xFF)); 152 if (cin[i] > '~' || cin[i] < ' ') {
181 char val = wideInput ? win[i] : cin[i];
182 if (val > '~' || val < ' ') {
183 sevenBitClean = false; 153 sevenBitClean = false;
184 break; 154 break;
185 } 155 }
186 } 156 }
187
188 SkString result; 157 SkString result;
189 if (sevenBitClean) { 158 if (sevenBitClean) {
190 result.append("("); 159 result.append("(");
191 for (size_t i = 0; i < len; i++) { 160 for (size_t i = 0; i < len; i++) {
192 SkASSERT(!wideInput || !(win[i] & ~0xFF)); 161 if (cin[i] == '\\' || cin[i] == '(' || cin[i] == ')') {
193 char val = wideInput ? win[i] : cin[i];
194 if (val == '\\' || val == '(' || val == ')') {
195 result.append("\\"); 162 result.append("\\");
196 } 163 }
197 result.append(&val, 1); 164 result.append(&cin[i], 1);
198 } 165 }
199 result.append(")"); 166 result.append(")");
200 } else { 167 } else {
201 result.append("<"); 168 result.append("<");
202 for (size_t i = 0; i < len; i++) { 169 for (size_t i = 0; i < len; i++) {
203 SkASSERT(!wideInput || !(win[i] & ~0xFF)); 170 result.appendHex(static_cast<unsigned char>(cin[i]), 2);
204 unsigned char val = wideInput ? win[i] : cin[i];
205 result.appendHex(val, 2);
206 } 171 }
207 result.append(">"); 172 result.append(">");
208 } 173 }
209
210 return result; 174 return result;
211 } 175 }
212 176
213 //////////////////////////////////////////////////////////////////////////////// 177 ////////////////////////////////////////////////////////////////////////////////
214 178
215 SkPDFName::SkPDFName(const char name[]) : fValue(FormatName(SkString(name))) {} 179 SkPDFName::SkPDFName(const char name[]) : fValue(FormatName(SkString(name))) {}
216 SkPDFName::SkPDFName(const SkString& name) : fValue(FormatName(name)) {} 180 SkPDFName::SkPDFName(const SkString& name) : fValue(FormatName(name)) {}
217 SkPDFName::~SkPDFName() {} 181 SkPDFName::~SkPDFName() {}
218 182
219 bool SkPDFName::operator==(const SkPDFName& b) const { 183 bool SkPDFName::operator==(const SkPDFName& b) const {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 fObjects.push(obj); 408 fObjects.push(obj);
445 return true; 409 return true;
446 } 410 }
447 411
448 int32_t SkPDFObjNumMap::getObjectNumber(SkPDFObject* obj) const { 412 int32_t SkPDFObjNumMap::getObjectNumber(SkPDFObject* obj) const {
449 int32_t* objectNumberFound = fObjectNumbers.find(obj); 413 int32_t* objectNumberFound = fObjectNumbers.find(obj);
450 SkASSERT(objectNumberFound); 414 SkASSERT(objectNumberFound);
451 return *objectNumberFound; 415 return *objectNumberFound;
452 } 416 }
453 417
OLDNEW
« src/pdf/SkPDFDevice.cpp ('K') | « src/pdf/SkPDFTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698