| OLD | NEW |
| 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 "SkPDFCatalog.h" | 10 #include "SkPDFCatalog.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 Append(fValue, stream); | 133 Append(fValue, stream); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | 136 // static |
| 137 void SkPDFScalar::Append(SkScalar value, SkWStream* stream) { | 137 void SkPDFScalar::Append(SkScalar value, SkWStream* stream) { |
| 138 // The range of reals in PDF/A is the same as SkFixed: +/- 32,767 and | 138 // The range of reals in PDF/A is the same as SkFixed: +/- 32,767 and |
| 139 // +/- 1/65,536 (though integers can range from 2^31 - 1 to -2^31). | 139 // +/- 1/65,536 (though integers can range from 2^31 - 1 to -2^31). |
| 140 // When using floats that are outside the whole value range, we can use | 140 // When using floats that are outside the whole value range, we can use |
| 141 // integers instead. | 141 // integers instead. |
| 142 | 142 |
| 143 | |
| 144 #if defined(SK_SCALAR_IS_FIXED) | |
| 145 stream->writeScalarAsText(value); | |
| 146 return; | |
| 147 #endif // SK_SCALAR_IS_FIXED | |
| 148 | |
| 149 #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) | 143 #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) |
| 150 if (value > 32767 || value < -32767) { | 144 if (value > 32767 || value < -32767) { |
| 151 stream->writeDecAsText(SkScalarRound(value)); | 145 stream->writeDecAsText(SkScalarRound(value)); |
| 152 return; | 146 return; |
| 153 } | 147 } |
| 154 | 148 |
| 155 char buffer[SkStrAppendScalar_MaxSize]; | 149 char buffer[SkStrAppendScalar_MaxSize]; |
| 156 char* end = SkStrAppendFixed(buffer, SkScalarToFixed(value)); | 150 char* end = SkStrAppendFixed(buffer, SkScalarToFixed(value)); |
| 157 stream->write(buffer, end - buffer); | 151 stream->write(buffer, end - buffer); |
| 158 return; | 152 return; |
| 159 #endif // !SK_ALLOW_LARGE_PDF_SCALARS | 153 #endif // !SK_ALLOW_LARGE_PDF_SCALARS |
| 160 | 154 |
| 161 #if defined(SK_SCALAR_IS_FLOAT) && defined(SK_ALLOW_LARGE_PDF_SCALARS) | 155 #if defined(SK_ALLOW_LARGE_PDF_SCALARS) |
| 162 // Floats have 24bits of significance, so anything outside that range is | 156 // Floats have 24bits of significance, so anything outside that range is |
| 163 // no more precise than an int. (Plus PDF doesn't support scientific | 157 // no more precise than an int. (Plus PDF doesn't support scientific |
| 164 // notation, so this clamps to SK_Max/MinS32). | 158 // notation, so this clamps to SK_Max/MinS32). |
| 165 if (value > (1 << 24) || value < -(1 << 24)) { | 159 if (value > (1 << 24) || value < -(1 << 24)) { |
| 166 stream->writeDecAsText(value); | 160 stream->writeDecAsText(value); |
| 167 return; | 161 return; |
| 168 } | 162 } |
| 169 // Continue to enforce the PDF limits for small floats. | 163 // Continue to enforce the PDF limits for small floats. |
| 170 if (value < 1.0f/65536 && value > -1.0f/65536) { | 164 if (value < 1.0f/65536 && value > -1.0f/65536) { |
| 171 stream->writeDecAsText(0); | 165 stream->writeDecAsText(0); |
| 172 return; | 166 return; |
| 173 } | 167 } |
| 174 // SkStrAppendFloat might still use scientific notation, so use snprintf | 168 // SkStrAppendFloat might still use scientific notation, so use snprintf |
| 175 // directly.. | 169 // directly.. |
| 176 static const int kFloat_MaxSize = 19; | 170 static const int kFloat_MaxSize = 19; |
| 177 char buffer[kFloat_MaxSize]; | 171 char buffer[kFloat_MaxSize]; |
| 178 int len = SNPRINTF(buffer, kFloat_MaxSize, "%#.8f", value); | 172 int len = SNPRINTF(buffer, kFloat_MaxSize, "%#.8f", value); |
| 179 // %f always prints trailing 0s, so strip them. | 173 // %f always prints trailing 0s, so strip them. |
| 180 for (; buffer[len - 1] == '0' && len > 0; len--) { | 174 for (; buffer[len - 1] == '0' && len > 0; len--) { |
| 181 buffer[len - 1] = '\0'; | 175 buffer[len - 1] = '\0'; |
| 182 } | 176 } |
| 183 if (buffer[len - 1] == '.') { | 177 if (buffer[len - 1] == '.') { |
| 184 buffer[len - 1] = '\0'; | 178 buffer[len - 1] = '\0'; |
| 185 } | 179 } |
| 186 stream->writeText(buffer); | 180 stream->writeText(buffer); |
| 187 return; | 181 return; |
| 188 #endif // SK_SCALAR_IS_FLOAT && SK_ALLOW_LARGE_PDF_SCALARS | 182 #endif // SK_ALLOW_LARGE_PDF_SCALARS |
| 189 } | 183 } |
| 190 | 184 |
| 191 SkPDFString::SkPDFString(const char value[]) | 185 SkPDFString::SkPDFString(const char value[]) |
| 192 : fValue(FormatString(value, strlen(value))) { | 186 : fValue(FormatString(value, strlen(value))) { |
| 193 } | 187 } |
| 194 | 188 |
| 195 SkPDFString::SkPDFString(const SkString& value) | 189 SkPDFString::SkPDFString(const SkString& value) |
| 196 : fValue(FormatString(value.c_str(), value.size())) { | 190 : fValue(FormatString(value.c_str(), value.size())) { |
| 197 } | 191 } |
| 198 | 192 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 SkPDFName* SkPDFDict::Iter::next(SkPDFObject** value) { | 476 SkPDFName* SkPDFDict::Iter::next(SkPDFObject** value) { |
| 483 if (fIter != fStop) { | 477 if (fIter != fStop) { |
| 484 const Rec* cur = fIter; | 478 const Rec* cur = fIter; |
| 485 fIter++; | 479 fIter++; |
| 486 *value = cur->value; | 480 *value = cur->value; |
| 487 return cur->key; | 481 return cur->key; |
| 488 } | 482 } |
| 489 *value = NULL; | 483 *value = NULL; |
| 490 return NULL; | 484 return NULL; |
| 491 } | 485 } |
| OLD | NEW |