Chromium Code Reviews| Index: src/pdf/SkPDFUtils.cpp |
| diff --git a/src/pdf/SkPDFUtils.cpp b/src/pdf/SkPDFUtils.cpp |
| index b8d65092b07e8065f8cce15e2ba60fbf3eff7cc3..4d02aaadc750e2134c0110c97f15fe38f35f09db 100644 |
| --- a/src/pdf/SkPDFUtils.cpp |
| +++ b/src/pdf/SkPDFUtils.cpp |
| @@ -251,6 +251,29 @@ void SkPDFUtils::ApplyPattern(int objectIndex, SkWStream* content) { |
| content->writeText(" scn\n"); |
| } |
| +size_t SkPDFUtils::ColorToDecimal(uint8_t value, char result[5]) { |
| + if (value == 255 || value == 0) { |
| + result[0] = value ? '1' : '0'; |
| + result[1] = '\0'; |
| + return 1; |
| + } |
| + int x = (((1000 << 20) / 255) * value + (1 << 19)) >> 20; |
| + // ((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
|
| + result[0] = '.'; |
| + for (int i = 3; i > 0; --i) { |
| + result[i] = '0' + x % 10; |
| + x /= 10; |
| + } |
| + int j; |
| + 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
|
| + if (result[j] != '0') { |
| + break; |
| + } |
| + } |
| + result[j + 1] = '\0'; |
| + return j + 1; |
| +} |
| + |
| void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) { |
| char result[kMaximumFloatDecimalLength]; |
| size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result); |