Flutter Engine
The Flutter Engine
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
17#include "src/base/SkUTF.h"
18#include "src/base/SkUtils.h"
21
22#include <cstdint>
23#include <cstring>
24#include <memory>
25
26class SkBitmap;
27class SkImage;
28class SkPDFArray;
29class SkPDFDict;
30class SkPath;
31class SkShader;
32enum class SkBlendMode;
33enum class SkPathFillType;
34struct SkRect;
35
36namespace SkPDF { struct DateTime; }
37
38template <typename T>
39bool SkPackedArrayEqual(T* u, T* v, size_t n) {
40 SkASSERT(u);
41 SkASSERT(v);
42 return 0 == memcmp(u, v, n * sizeof(T));
43}
44
45#if 0
46#define PRINT_NOT_IMPL(str) fprintf(stderr, str)
47#else
48#define PRINT_NOT_IMPL(str)
49#endif
50
51#define NOT_IMPLEMENTED(condition, assertion) \
52 do { \
53 if ((bool)(condition)) { \
54 PRINT_NOT_IMPL("NOT_IMPLEMENTED: " #condition "\n"); \
55 SkDEBUGCODE(SkASSERT(!assertion);) \
56 } \
57 } while (0)
58
59namespace SkPDFUtils {
60
61const char* BlendModeName(SkBlendMode);
62
63std::unique_ptr<SkPDFArray> RectToArray(const SkRect& rect);
64std::unique_ptr<SkPDFArray> MatrixToArray(const SkMatrix& matrix);
65
69void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
70 bool doConsumeDegerates, SkWStream* content, SkScalar tolerance = 0.25f);
71inline void EmitPath(const SkPath& path, SkPaint::Style paintStyle,
72 SkWStream* content, SkScalar tolerance = 0.25f) {
73 SkPDFUtils::EmitPath(path, paintStyle, true, content, tolerance);
74}
78void ApplyGraphicState(int objectIndex, SkWStream* content);
79void ApplyPattern(int objectIndex, SkWStream* content);
80
81// Converts (value / 255.0) with three significant digits of accuracy.
82// Writes value as string into result. Returns strlen() of result.
83size_t ColorToDecimal(uint8_t value, char result[5]);
84
85static constexpr unsigned kFloatColorDecimalCount = 4;
87inline void AppendColorComponent(uint8_t value, SkWStream* wStream) {
88 char buffer[5];
90 wStream->write(buffer, len);
91}
92inline void AppendColorComponentF(float value, SkWStream* wStream) {
95 wStream->write(buffer, len);
96}
97
100 size_t len = SkFloatToDecimal(value, result);
102 stream->write(result, len);
103}
104
105inline void WriteUInt16BE(SkWStream* wStream, uint16_t value) {
106 char result[4] = { SkHexadecimalDigits::gUpper[ value >> 12 ],
107 SkHexadecimalDigits::gUpper[0xF & (value >> 8 )],
108 SkHexadecimalDigits::gUpper[0xF & (value >> 4 )],
110 wStream->write(result, 4);
111}
112
113inline void WriteUInt8(SkWStream* wStream, uint8_t value) {
114 char result[2] = { SkHexadecimalDigits::gUpper[value >> 4],
116 wStream->write(result, 2);
117}
118
119inline void WriteUTF16beHex(SkWStream* wStream, SkUnichar utf32) {
120 uint16_t utf16[2] = {0, 0};
121 size_t len = SkUTF::ToUTF16(utf32, utf16);
122 SkASSERT(len == 1 || len == 2);
123 SkPDFUtils::WriteUInt16BE(wStream, utf16[0]);
124 if (len == 2) {
125 SkPDFUtils::WriteUInt16BE(wStream, utf16[1]);
126 }
127}
128
130 SkMatrix localMatrix;
131 if (sk_sp<SkShader> s = as_SB(shader)->makeAsALocalMatrixShader(&localMatrix)) {
132 return localMatrix;
133 }
134 return SkMatrix::I();
135}
136bool InverseTransformBBox(const SkMatrix& matrix, SkRect* bbox);
138 SkRect& bbox,
139 std::unique_ptr<SkPDFDict> resources,
140 const SkMatrix& matrix);
141
142bool ToBitmap(const SkImage* img, SkBitmap* dst);
143
144#ifdef SK_PDF_BASE85_BINARY
145void Base85Encode(std::unique_ptr<SkStreamAsset> src, SkDynamicMemoryWStream* dst);
146#endif // SK_PDF_BASE85_BINARY
147
148void AppendTransform(const SkMatrix&, SkWStream*);
149
150// Takes SkTime::GetNSecs() [now] and puts it into the provided struct.
152
153} // namespace SkPDFUtils
154
155#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:39
SkPathFillType
Definition: SkPathTypes.h:11
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
int32_t SkUnichar
Definition: SkTypes.h:175
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
Definition: SkPath.h:59
virtual bool write(const void *buffer, size_t size)=0
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
uint8_t value
GAsyncResult * result
union flutter::testing::@2836::KeyboardChange::@76 content
double y
double x
const char gUpper[16]
Definition: SkUtils.cpp:10
void GetDateTime(SkPDF::DateTime *)
Definition: SkPDFUtils.cpp:431
void ApplyGraphicState(int objectIndex, SkWStream *content)
Definition: SkPDFUtils.cpp:254
void PopulateTilingPatternDict(SkPDFDict *pattern, SkRect &bbox, std::unique_ptr< SkPDFDict > resources, const SkMatrix &matrix)
Definition: SkPDFUtils.cpp:327
void WriteUInt8(SkWStream *wStream, uint8_t value)
Definition: SkPDFUtils.h:113
size_t ColorToDecimalF(float value, char result[kFloatColorDecimalCount+2])
Definition: SkPDFUtils.cpp:296
size_t ColorToDecimal(uint8_t value, char result[5])
Definition: SkPDFUtils.cpp:307
void AppendColorComponent(uint8_t value, SkWStream *wStream)
Definition: SkPDFUtils.h:87
const char * BlendModeName(SkBlendMode)
Definition: SkPDFUtils.cpp:37
std::unique_ptr< SkPDFArray > MatrixToArray(const SkMatrix &matrix)
Definition: SkPDFUtils.cpp:67
void EmitPath(const SkPath &path, SkPaint::Style paintStyle, bool doConsumeDegerates, SkWStream *content, SkScalar tolerance=0.25f)
Definition: SkPDFUtils.cpp:132
void AppendRectangle(const SkRect &rect, SkWStream *content)
Definition: SkPDFUtils.cpp:118
void PaintPath(SkPaint::Style style, SkPathFillType fill, SkWStream *content)
Definition: SkPDFUtils.cpp:231
void AppendScalar(SkScalar value, SkWStream *stream)
Definition: SkPDFUtils.h:98
void MoveTo(SkScalar x, SkScalar y, SkWStream *content)
Definition: SkPDFUtils.cpp:75
void AppendLine(SkScalar x, SkScalar y, SkWStream *content)
Definition: SkPDFUtils.cpp:82
void WriteUInt16BE(SkWStream *wStream, uint16_t value)
Definition: SkPDFUtils.h:105
void AppendTransform(const SkMatrix &, SkWStream *)
Definition: SkPDFUtils.cpp:399
SkMatrix GetShaderLocalMatrix(const SkShader *shader)
Definition: SkPDFUtils.h:129
void ApplyPattern(int objectIndex, SkWStream *content)
Definition: SkPDFUtils.cpp:259
bool ToBitmap(const SkImage *img, SkBitmap *dst)
Definition: SkPDFUtils.cpp:348
void AppendColorComponentF(float value, SkWStream *wStream)
Definition: SkPDFUtils.h:92
bool InverseTransformBBox(const SkMatrix &matrix, SkRect *bbox)
Definition: SkPDFUtils.cpp:318
void ClosePath(SkWStream *content)
Definition: SkPDFUtils.cpp:227
static constexpr unsigned kFloatColorDecimalCount
Definition: SkPDFUtils.h:85
void StrokePath(SkWStream *content)
Definition: SkPDFUtils.cpp:250
std::unique_ptr< SkPDFArray > RectToArray(const SkRect &rect)
Definition: SkPDFUtils.cpp:63
void WriteUTF16beHex(SkWStream *wStream, SkUnichar utf32)
Definition: SkPDFUtils.h:119
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SK_SPI size_t ToUTF16(SkUnichar uni, uint16_t utf16[2]=nullptr)
Definition: SkUTF.cpp:243
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
dst
Definition: cp.py:12
#define T
Definition: precompiler.cc:65