#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkImage.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathTypes.h"
#include "include/core/SkRect.h"
#include "include/core/SkSize.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/docs/SkPDFDocument.h"
#include "include/private/base/SkFixed.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkPoint_impl.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkGeometry.h"
#include "src/core/SkPathPriv.h"
#include "src/image/SkImage_Base.h"
#include "src/pdf/SkPDFResourceDict.h"
#include "src/pdf/SkPDFTypes.h"
#include "src/pdf/SkPDFUtils.h"
#include <algorithm>
#include <ctime>
#include <utility>
#if defined(SK_BUILD_FOR_WIN)
#include "src/base/SkLeanWindows.h"
#endif
const char* SkPDFUtils::BlendModeName(SkBlendMode mode) { … }
std::unique_ptr<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& r) { … }
std::unique_ptr<SkPDFArray> SkPDFUtils::MatrixToArray(const SkMatrix& matrix) { … }
void SkPDFUtils::MoveTo(SkScalar x, SkScalar y, SkWStream* content) { … }
void SkPDFUtils::AppendLine(SkScalar x, SkScalar y, SkWStream* content) { … }
static void append_cubic(SkScalar ctl1X, SkScalar ctl1Y,
SkScalar ctl2X, SkScalar ctl2Y,
SkScalar dstX, SkScalar dstY, SkWStream* content) { … }
static void append_quad(const SkPoint quad[], SkWStream* content) { … }
void SkPDFUtils::AppendRectangle(const SkRect& rect, SkWStream* content) { … }
void SkPDFUtils::EmitPath(const SkPath& path, SkPaint::Style paintStyle,
bool doConsumeDegerates, SkWStream* content,
SkScalar tolerance) { … }
void SkPDFUtils::ClosePath(SkWStream* content) { … }
void SkPDFUtils::PaintPath(SkPaint::Style style, SkPathFillType fill, SkWStream* content) { … }
void SkPDFUtils::StrokePath(SkWStream* content) { … }
void SkPDFUtils::ApplyGraphicState(int objectIndex, SkWStream* content) { … }
void SkPDFUtils::ApplyPattern(int objectIndex, SkWStream* content) { … }
static size_t print_permil_as_decimal(int x, char* result, unsigned places) { … }
static constexpr int int_pow(int base, unsigned exp, int acc = 1) { … }
size_t SkPDFUtils::ColorToDecimalF(float value, char result[kFloatColorDecimalCount + 2]) { … }
size_t SkPDFUtils::ColorToDecimal(uint8_t value, char result[5]) { … }
bool SkPDFUtils::InverseTransformBBox(const SkMatrix& matrix, SkRect* bbox) { … }
void SkPDFUtils::PopulateTilingPatternDict(SkPDFDict* pattern,
SkRect& bbox,
std::unique_ptr<SkPDFDict> resources,
const SkMatrix& matrix) { … }
bool SkPDFUtils::ToBitmap(const SkImage* img, SkBitmap* dst) { … }
#ifdef SK_PDF_BASE85_BINARY
void SkPDFUtils::Base85Encode(std::unique_ptr<SkStreamAsset> stream, SkDynamicMemoryWStream* dst) {
SkASSERT(dst);
SkASSERT(stream);
dst->writeText("\n");
int column = 0;
while (true) {
uint8_t src[4] = {0, 0, 0, 0};
size_t count = stream->read(src, 4);
SkASSERT(count < 5);
if (0 == count) {
dst->writeText("~>\n");
return;
}
uint32_t v = ((uint32_t)src[0] << 24) | ((uint32_t)src[1] << 16) |
((uint32_t)src[2] << 8) | src[3];
if (v == 0 && count == 4) {
dst->writeText("z");
column += 1;
} else {
char buffer[5];
for (int n = 4; n > 0; --n) {
buffer[n] = (v % 85) + '!';
v /= 85;
}
buffer[0] = v + '!';
dst->write(buffer, count + 1);
column += count + 1;
}
if (column > 74) {
dst->writeText("\n");
column = 0;
}
}
}
#endif
void SkPDFUtils::AppendTransform(const SkMatrix& matrix, SkWStream* content) { … }
#if defined(SK_BUILD_FOR_WIN)
void SkPDFUtils::GetDateTime(SkPDF::DateTime* dt) {
if (dt) {
SYSTEMTIME st;
GetSystemTime(&st);
dt->fTimeZoneMinutes = 0;
dt->fYear = st.wYear;
dt->fMonth = SkToU8(st.wMonth);
dt->fDayOfWeek = SkToU8(st.wDayOfWeek);
dt->fDay = SkToU8(st.wDay);
dt->fHour = SkToU8(st.wHour);
dt->fMinute = SkToU8(st.wMinute);
dt->fSecond = SkToU8(st.wSecond);
}
}
#else
void SkPDFUtils::GetDateTime(SkPDF::DateTime* dt) { … }
#endif