Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 SkString resourceName = SkPDFResourceDict::getResourceName( | 244 SkString resourceName = SkPDFResourceDict::getResourceName( |
| 245 SkPDFResourceDict::kPattern_ResourceType, | 245 SkPDFResourceDict::kPattern_ResourceType, |
| 246 objectIndex); | 246 objectIndex); |
| 247 content->writeText("/Pattern CS/Pattern cs/"); | 247 content->writeText("/Pattern CS/Pattern cs/"); |
| 248 content->writeText(resourceName.c_str()); | 248 content->writeText(resourceName.c_str()); |
| 249 content->writeText(" SCN/"); | 249 content->writeText(" SCN/"); |
| 250 content->writeText(resourceName.c_str()); | 250 content->writeText(resourceName.c_str()); |
| 251 content->writeText(" scn\n"); | 251 content->writeText(" scn\n"); |
| 252 } | 252 } |
| 253 | 253 |
| 254 size_t SkPDFUtils::ColorToDecimal(uint8_t value, char result[5]) { | |
| 255 if (value == 255 || value == 0) { | |
| 256 result[0] = value ? '1' : '0'; | |
| 257 result[1] = '\0'; | |
| 258 return 1; | |
| 259 } | |
| 260 int x = (((1000 << 20) / 255) * value + (1 << 19)) >> 20; | |
| 261 // ((int)(0.5 + (1000.0 / 255.0) * value) == x); | |
|
tomhudson
2016/07/15 19:20:18
Not sure what the comment is doing here - it's mos
hal.canary
2016/07/15 19:46:42
To make this more clear, I am switching to SkFixed
| |
| 262 result[0] = '.'; | |
| 263 for (int i = 3; i > 0; --i) { | |
| 264 result[i] = '0' + x % 10; | |
| 265 x /= 10; | |
| 266 } | |
| 267 int j; | |
| 268 for (j = 3; j > 1; --j) { | |
|
tomhudson
2016/07/15 19:20:17
Trimming off trailing zeroes? Is this important?
hal.canary
2016/07/15 19:46:42
it's cheap to do here, and everyone wants smaller
| |
| 269 if (result[j] != '0') { | |
| 270 break; | |
| 271 } | |
| 272 } | |
| 273 result[j + 1] = '\0'; | |
| 274 return j + 1; | |
| 275 } | |
| 276 | |
| 254 void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) { | 277 void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) { |
| 255 char result[kMaximumFloatDecimalLength]; | 278 char result[kMaximumFloatDecimalLength]; |
| 256 size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result); | 279 size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result); |
| 257 SkASSERT(len < kMaximumFloatDecimalLength); | 280 SkASSERT(len < kMaximumFloatDecimalLength); |
| 258 stream->write(result, len); | 281 stream->write(result, len); |
| 259 } | 282 } |
| 260 | 283 |
| 261 /** Write a string into result, includeing a terminating '\0' (for | 284 /** Write a string into result, includeing a terminating '\0' (for |
| 262 unit testing). Return strlen(result) (for SkWStream::write) The | 285 unit testing). Return strlen(result) (for SkWStream::write) The |
| 263 resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and | 286 resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 uint8_t c = static_cast<uint8_t>(cin[i]); | 429 uint8_t c = static_cast<uint8_t>(cin[i]); |
| 407 static const char gHex[] = "0123456789ABCDEF"; | 430 static const char gHex[] = "0123456789ABCDEF"; |
| 408 char hexValue[2]; | 431 char hexValue[2]; |
| 409 hexValue[0] = gHex[(c >> 4) & 0xF]; | 432 hexValue[0] = gHex[(c >> 4) & 0xF]; |
| 410 hexValue[1] = gHex[ c & 0xF]; | 433 hexValue[1] = gHex[ c & 0xF]; |
| 411 wStream->write(hexValue, 2); | 434 wStream->write(hexValue, 2); |
| 412 } | 435 } |
| 413 wStream->writeText(">"); | 436 wStream->writeText(">"); |
| 414 } | 437 } |
| 415 } | 438 } |
| OLD | NEW |