• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2011 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkPDFUtils_DEFINED
11 #define SkPDFUtils_DEFINED
12 
13 #include "SkPaint.h"
14 #include "SkPath.h"
15 
16 class SkMatrix;
17 class SkPath;
18 class SkPDFArray;
19 struct SkRect;
20 class SkWStream;
21 
22 #if 0
23 #define PRINT_NOT_IMPL(str) fprintf(stderr, str)
24 #else
25 #define PRINT_NOT_IMPL(str)
26 #endif
27 
28 #define NOT_IMPLEMENTED(condition, assert)                         \
29     do {                                                           \
30         if ((bool)(condition)) {                                   \
31             PRINT_NOT_IMPL("NOT_IMPLEMENTED: " #condition "\n");   \
32             SkDEBUGCODE(SkASSERT(!assert);)                        \
33         }                                                          \
34     } while (0)
35 
36 class SkPDFUtils {
37 public:
38     static SkPDFArray* RectToArray(const SkRect& rect);
39     static SkPDFArray* MatrixToArray(const SkMatrix& matrix);
40     static void AppendTransform(const SkMatrix& matrix, SkWStream* content);
41 
42     static void MoveTo(SkScalar x, SkScalar y, SkWStream* content);
43     static void AppendLine(SkScalar x, SkScalar y, SkWStream* content);
44     static void AppendCubic(SkScalar ctl1X, SkScalar ctl1Y,
45                             SkScalar ctl2X, SkScalar ctl2Y,
46                             SkScalar dstX, SkScalar dstY, SkWStream* content);
47     static void AppendRectangle(const SkRect& rect, SkWStream* content);
48     static void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
49                          bool doConsumeDegerates, SkWStream* content);
EmitPath(const SkPath & path,SkPaint::Style paintStyle,SkWStream * content)50     static void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
51                          SkWStream* content) {
52         SkPDFUtils::EmitPath(path, paintStyle, true, content);
53     }
54     static void ClosePath(SkWStream* content);
55     static void PaintPath(SkPaint::Style style, SkPath::FillType fill,
56                           SkWStream* content);
57     static void StrokePath(SkWStream* content);
58     static void DrawFormXObject(int objectIndex, SkWStream* content);
59     static void ApplyGraphicState(int objectIndex, SkWStream* content);
60     static void ApplyPattern(int objectIndex, SkWStream* content);
61 
62     // 3 = '-', '.', and '\0' characters.
63     // 9 = number of significant digits
64     // abs(FLT_MIN_10_EXP) = number of zeros in FLT_MIN
65     static const size_t kMaximumFloatDecimalLength = 3 + 9 - FLT_MIN_10_EXP;
66     // FloatToDecimal is exposed for unit tests.
67     static size_t FloatToDecimal(float value,
68                                  char output[kMaximumFloatDecimalLength]);
69     static void AppendScalar(SkScalar value, SkWStream* stream);
70     static SkString FormatString(const char* input, size_t len);
71 };
72 
73 #endif
74