Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkPDFUtils_DEFINED
8#define SkPDFUtils_DEFINED
9
11#include "include/core/SkPath.h"
15#include "src/base/SkUTF.h"
16#include "src/base/SkUtils.h"
17#include "src/pdf/SkPDFTypes.h"
20
21class SkBitmap;
22class SkMatrix;
23class SkPDFArray;
24struct SkRect;
25
26template <typename T>
27bool SkPackedArrayEqual(T* u, T* v, size_t n) {
28 SkASSERT(u);
29 SkASSERT(v);
30 return 0 == memcmp(u, v, n * sizeof(T));
31}
32
33#if 0
34#define PRINT_NOT_IMPL(str) fprintf(stderr, str)
35#else
36#define PRINT_NOT_IMPL(str)
37#endif
38
39#define NOT_IMPLEMENTED(condition, assert) \
40 do { \
41 if ((bool)(condition)) { \
42 PRINT_NOT_IMPL("NOT_IMPLEMENTED: " #condition "\n"); \
43 SkDEBUGCODE(SkASSERT(!assert);) \
44 } \
45 } while (0)
46
47namespace SkPDFUtils {
48
49const char* BlendModeName(SkBlendMode);
50
51std::unique_ptr<SkPDFArray> RectToArray(const SkRect& rect);
52std::unique_ptr<SkPDFArray> MatrixToArray(const SkMatrix& matrix);
53
56void AppendRectangle(const SkRect& rect, SkWStream* content);
57void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
58 bool doConsumeDegerates, SkWStream* content, SkScalar tolerance = 0.25f);
59inline void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
60 SkWStream* content, SkScalar tolerance = 0.25f) {
61 SkPDFUtils::EmitPath(path, paintStyle, true, content, tolerance);
62}
66void ApplyGraphicState(int objectIndex, SkWStream* content);
67void ApplyPattern(int objectIndex, SkWStream* content);
68
69// Converts (value / 255.0) with three significant digits of accuracy.
70// Writes value as string into result. Returns strlen() of result.
71size_t ColorToDecimal(uint8_t value, char result[5]);
72
73static constexpr unsigned kFloatColorDecimalCount = 4;
74size_t ColorToDecimalF(float value, char result[kFloatColorDecimalCount + 2]);
75inline void AppendColorComponent(uint8_t value, SkWStream* wStream) {
76 char buffer[5];
78 wStream->write(buffer, len);
79}
80inline void AppendColorComponentF(float value, SkWStream* wStream) {
83 wStream->write(buffer, len);
84}
85
86inline void AppendScalar(SkScalar value, SkWStream* stream) {
88 size_t len = SkFloatToDecimal(value, result);
90 stream->write(result, len);
91}
92
93inline void WriteUInt16BE(SkWStream* wStream, uint16_t value) {
94 char result[4] = { SkHexadecimalDigits::gUpper[ value >> 12 ],
98 wStream->write(result, 4);
99}
100
101inline void WriteUInt8(SkWStream* wStream, uint8_t value) {
102 char result[2] = { SkHexadecimalDigits::gUpper[value >> 4],
104 wStream->write(result, 2);
105}
106
107inline void WriteUTF16beHex(SkWStream* wStream, SkUnichar utf32) {
108 uint16_t utf16[2] = {0, 0};
109 size_t len = SkUTF::ToUTF16(utf32, utf16);
110 SkASSERT(len == 1 || len == 2);
111 SkPDFUtils::WriteUInt16BE(wStream, utf16[0]);
112 if (len == 2) {
113 SkPDFUtils::WriteUInt16BE(wStream, utf16[1]);
114 }
115}
116
118 SkMatrix localMatrix;
119 if (sk_sp<SkShader> s = as_SB(shader)->makeAsALocalMatrixShader(&localMatrix)) {
120 return localMatrix;
121 }
122 return SkMatrix::I();
123}
124bool InverseTransformBBox(const SkMatrix& matrix, SkRect* bbox);
126 SkRect& bbox,
127 std::unique_ptr<SkPDFDict> resources,
128 const SkMatrix& matrix);
129
130bool ToBitmap(const SkImage* img, SkBitmap* dst);
131
132#ifdef SK_PDF_BASE85_BINARY
133void Base85Encode(std::unique_ptr<SkStreamAsset> src, SkDynamicMemoryWStream* dst);
134#endif // SK_PDF_BASE85_BINARY
135
136void AppendTransform(const SkMatrix&, SkWStream*);
137
138// Takes SkTime::GetNSecs() [now] and puts it into the provided struct.
140
141} // namespace SkPDFUtils
142
143#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
SkBlendMode
Definition SkBlendMode.h:38
unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength])
constexpr unsigned kMaximumSkFloatToDecimalLength
bool SkPackedArrayEqual(T *u, T *v, size_t n)
Definition SkPDFUtils.h:27
SkPathFillType
Definition SkPathTypes.h:11
SkShaderBase * as_SB(SkShader *shader)
int32_t SkUnichar
Definition SkTypes.h:175
static const SkMatrix & I()
virtual bool write(const void *buffer, size_t size)=0
float SkScalar
Definition extension.cpp:12
struct MyStruct s
static const uint8_t buffer[]
uint8_t value
GAsyncResult * result
union flutter::testing::@2838::KeyboardChange::@76 content
double y
double x
const char gUpper[16]
Definition SkUtils.cpp:10
void GetDateTime(SkPDF::DateTime *)
void ApplyGraphicState(int objectIndex, SkWStream *content)
void PopulateTilingPatternDict(SkPDFDict *pattern, SkRect &bbox, std::unique_ptr< SkPDFDict > resources, const SkMatrix &matrix)
void WriteUInt8(SkWStream *wStream, uint8_t value)
Definition SkPDFUtils.h:101
size_t ColorToDecimalF(float value, char result[kFloatColorDecimalCount+2])
size_t ColorToDecimal(uint8_t value, char result[5])
void AppendColorComponent(uint8_t value, SkWStream *wStream)
Definition SkPDFUtils.h:75
const char * BlendModeName(SkBlendMode)
std::unique_ptr< SkPDFArray > MatrixToArray(const SkMatrix &matrix)
void EmitPath(const SkPath &path, SkPaint::Style paintStyle, bool doConsumeDegerates, SkWStream *content, SkScalar tolerance=0.25f)
void AppendRectangle(const SkRect &rect, SkWStream *content)
void PaintPath(SkPaint::Style style, SkPathFillType fill, SkWStream *content)
void AppendScalar(SkScalar value, SkWStream *stream)
Definition SkPDFUtils.h:86
void MoveTo(SkScalar x, SkScalar y, SkWStream *content)
void AppendLine(SkScalar x, SkScalar y, SkWStream *content)
void WriteUInt16BE(SkWStream *wStream, uint16_t value)
Definition SkPDFUtils.h:93
void AppendTransform(const SkMatrix &, SkWStream *)
SkMatrix GetShaderLocalMatrix(const SkShader *shader)
Definition SkPDFUtils.h:117
void ApplyPattern(int objectIndex, SkWStream *content)
bool ToBitmap(const SkImage *img, SkBitmap *dst)
void AppendColorComponentF(float value, SkWStream *wStream)
Definition SkPDFUtils.h:80
bool InverseTransformBBox(const SkMatrix &matrix, SkRect *bbox)
void ClosePath(SkWStream *content)
static constexpr unsigned kFloatColorDecimalCount
Definition SkPDFUtils.h:73
void StrokePath(SkWStream *content)
std::unique_ptr< SkPDFArray > RectToArray(const SkRect &rect)
void WriteUTF16beHex(SkWStream *wStream, SkUnichar utf32)
Definition SkPDFUtils.h:107
SK_SPI size_t ToUTF16(SkUnichar uni, uint16_t utf16[2]=nullptr)
Definition SkUTF.cpp:243
#define T