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 #ifndef SkPDFUtils_DEFINED | 9 #ifndef SkPDFUtils_DEFINED |
10 #define SkPDFUtils_DEFINED | 10 #define SkPDFUtils_DEFINED |
11 | 11 |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkPath.h" | 13 #include "SkPath.h" |
| 14 #include "SkStream.h" |
14 | 15 |
15 class SkMatrix; | 16 class SkMatrix; |
16 class SkPDFArray; | 17 class SkPDFArray; |
17 struct SkRect; | 18 struct SkRect; |
18 class SkWStream; | |
19 | 19 |
20 #if 0 | 20 #if 0 |
21 #define PRINT_NOT_IMPL(str) fprintf(stderr, str) | 21 #define PRINT_NOT_IMPL(str) fprintf(stderr, str) |
22 #else | 22 #else |
23 #define PRINT_NOT_IMPL(str) | 23 #define PRINT_NOT_IMPL(str) |
24 #endif | 24 #endif |
25 | 25 |
26 #define NOT_IMPLEMENTED(condition, assert) \ | 26 #define NOT_IMPLEMENTED(condition, assert) \ |
27 do { \ | 27 do { \ |
28 if ((bool)(condition)) { \ | 28 if ((bool)(condition)) { \ |
29 PRINT_NOT_IMPL("NOT_IMPLEMENTED: " #condition "\n"); \ | 29 PRINT_NOT_IMPL("NOT_IMPLEMENTED: " #condition "\n"); \ |
30 SkDEBUGCODE(SkASSERT(!assert);) \ | 30 SkDEBUGCODE(SkASSERT(!assert);) \ |
31 } \ | 31 } \ |
32 } while (0) | 32 } while (0) |
33 | 33 |
34 class SkPDFUtils { | 34 namespace SkPDFUtils { |
35 public: | |
36 static sk_sp<SkPDFArray> RectToArray(const SkRect& rect); | |
37 static sk_sp<SkPDFArray> MatrixToArray(const SkMatrix& matrix); | |
38 static void AppendTransform(const SkMatrix& matrix, SkWStream* content); | |
39 | 35 |
40 static void MoveTo(SkScalar x, SkScalar y, SkWStream* content); | 36 sk_sp<SkPDFArray> RectToArray(const SkRect& rect); |
41 static void AppendLine(SkScalar x, SkScalar y, SkWStream* content); | 37 sk_sp<SkPDFArray> MatrixToArray(const SkMatrix& matrix); |
42 static void AppendCubic(SkScalar ctl1X, SkScalar ctl1Y, | 38 void AppendTransform(const SkMatrix& matrix, SkWStream* content); |
43 SkScalar ctl2X, SkScalar ctl2Y, | |
44 SkScalar dstX, SkScalar dstY, SkWStream* content); | |
45 static void AppendRectangle(const SkRect& rect, SkWStream* content); | |
46 static void EmitPath(const SkPath& path, SkPaint::Style paintStyle, | |
47 bool doConsumeDegerates, SkWStream* content); | |
48 static void EmitPath(const SkPath& path, SkPaint::Style paintStyle, | |
49 SkWStream* content) { | |
50 SkPDFUtils::EmitPath(path, paintStyle, true, content); | |
51 } | |
52 static void ClosePath(SkWStream* content); | |
53 static void PaintPath(SkPaint::Style style, SkPath::FillType fill, | |
54 SkWStream* content); | |
55 static void StrokePath(SkWStream* content); | |
56 static void DrawFormXObject(int objectIndex, SkWStream* content); | |
57 static void ApplyGraphicState(int objectIndex, SkWStream* content); | |
58 static void ApplyPattern(int objectIndex, SkWStream* content); | |
59 | 39 |
60 // 3 = '-', '.', and '\0' characters. | 40 void MoveTo(SkScalar x, SkScalar y, SkWStream* content); |
61 // 9 = number of significant digits | 41 void AppendLine(SkScalar x, SkScalar y, SkWStream* content); |
62 // abs(FLT_MIN_10_EXP) = number of zeros in FLT_MIN | 42 void AppendCubic(SkScalar ctl1X, SkScalar ctl1Y, |
63 static const size_t kMaximumFloatDecimalLength = 3 + 9 - FLT_MIN_10_EXP; | 43 SkScalar ctl2X, SkScalar ctl2Y, |
64 // FloatToDecimal is exposed for unit tests. | 44 SkScalar dstX, SkScalar dstY, SkWStream* content); |
65 static size_t FloatToDecimal(float value, | 45 void AppendRectangle(const SkRect& rect, SkWStream* content); |
66 char output[kMaximumFloatDecimalLength]); | 46 void EmitPath(const SkPath& path, SkPaint::Style paintStyle, |
67 static void AppendScalar(SkScalar value, SkWStream* stream); | 47 bool doConsumeDegerates, SkWStream* content); |
68 static void WriteString(SkWStream* wStream, const char* input, size_t len); | 48 inline void EmitPath(const SkPath& path, SkPaint::Style paintStyle, |
69 }; | 49 SkWStream* content) { |
| 50 SkPDFUtils::EmitPath(path, paintStyle, true, content); |
| 51 } |
| 52 void ClosePath(SkWStream* content); |
| 53 void PaintPath(SkPaint::Style style, SkPath::FillType fill, |
| 54 SkWStream* content); |
| 55 void StrokePath(SkWStream* content); |
| 56 void DrawFormXObject(int objectIndex, SkWStream* content); |
| 57 void ApplyGraphicState(int objectIndex, SkWStream* content); |
| 58 void ApplyPattern(int objectIndex, SkWStream* content); |
| 59 |
| 60 // 3 = '-', '.', and '\0' characters. |
| 61 // 9 = number of significant digits |
| 62 // abs(FLT_MIN_10_EXP) = number of zeros in FLT_MIN |
| 63 const size_t kMaximumFloatDecimalLength = 3 + 9 - FLT_MIN_10_EXP; |
| 64 // FloatToDecimal is exposed for unit tests. |
| 65 size_t FloatToDecimal(float value, |
| 66 char output[kMaximumFloatDecimalLength]); |
| 67 void AppendScalar(SkScalar value, SkWStream* stream); |
| 68 void WriteString(SkWStream* wStream, const char* input, size_t len); |
| 69 |
| 70 inline void WriteUInt16BE(SkDynamicMemoryWStream* wStream, uint16_t value) { |
| 71 static const char gHex[] = "0123456789ABCDEF"; |
| 72 char result[4]; |
| 73 result[0] = gHex[ value >> 12 ]; |
| 74 result[1] = gHex[0xF & (value >> 8 )]; |
| 75 result[2] = gHex[0xF & (value >> 4 )]; |
| 76 result[3] = gHex[0xF & (value )]; |
| 77 wStream->write(result, 4); |
| 78 } |
| 79 |
| 80 } // namespace SkPDFUtils |
70 | 81 |
71 #endif | 82 #endif |
OLD | NEW |