72static bool eq(
const SkString& str,
const char* strPtr,
size_t len) {
73 return len == str.
size() && 0 == memcmp(str.
c_str(), strPtr, len);
80 if (!
eq(skString, str, len)) {
82 "'%*s' != '%s'", (
int)len, str, skString.
c_str()));
89 assert_eql(
reporter, skString, str, strlen(str));
105static void test_issue1083() {
108 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
110 uint16_t glyphID = 65000;
120 float value =
static_cast<float>(std::atof(
result.c_str()));
121 if (value != number) {
129 assert_emit_eq(
reporter, boolTrue,
"true");
132 assert_emit_eq(
reporter, boolFalse,
"false");
135 assert_emit_eq(
reporter, int42,
"42");
138 assert_emit_eq_number(
reporter, 110999.75f);
139 assert_emit_eq_number(
reporter, 50000000.1f);
140 assert_emit_eq_number(
reporter, 1.0f / 65536);
143 assert_emit_eq(
reporter, stringSimple,
"(test \\) string \\( foo)");
145 SkString stringComplexInput(
"\ttest ) string ( foo");
147 assert_emit_eq(
reporter, stringComplex,
"(\\011test \\) string \\( foo)");
149 SkString binaryStringInput(
"\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17\20");
151 assert_emit_eq(
reporter, binaryString,
"<0102030405060708090A0B0C0D0E0F10>");
153 SkString nameInput(
"Test name\twith#tab");
155 assert_emit_eq(
reporter,
name,
"/Test#20name#09with#23tab");
157 SkString nameInput2(
"A#/%()<>[]{}B");
159 assert_emit_eq(
reporter, name2,
"/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB");
162 assert_emit_eq(
reporter, name3,
"/SimpleNameWithOnlyPrintableASCII");
165 SkString highBitString(
"\xDE\xAD" "be\xEF");
167 assert_emit_eq(
reporter, highBitName,
"/#DE#ADbe#EF");
172 const char nameInput4[] =
"Test name with nil\0";
174 assert_emit_eq(
reporter, name4,
"/Test#20name#20with#20nil");
178 std::unique_ptr<SkPDFArray> array(
new SkPDFArray);
179 assert_emit_eq(
reporter, *array,
"[]");
181 array->appendInt(42);
182 assert_emit_eq(
reporter, *array,
"[42]");
185 assert_emit_eq(
reporter, *array,
"[42 .5]");
188 assert_emit_eq(
reporter, *array,
"[42 .5 0]");
190 array->appendBool(
true);
191 assert_emit_eq(
reporter, *array,
"[42 .5 0 true]");
193 array->appendName(
"ThisName");
194 assert_emit_eq(
reporter, *array,
"[42 .5 0 true /ThisName]");
196 array->appendName(
SkString(
"AnotherName"));
197 assert_emit_eq(
reporter, *array,
"[42 .5 0 true /ThisName /AnotherName]");
199 array->appendTextString(
"This String");
201 "[42 .5 0 true /ThisName /AnotherName (This String)]");
203 array->appendByteString(
SkString(
"Another String"));
205 "[42 .5 0 true /ThisName /AnotherName (This String) "
206 "(Another String)]");
208 std::unique_ptr<SkPDFArray> innerArray(
new SkPDFArray);
209 innerArray->appendInt(-1);
210 array->appendObject(std::move(innerArray));
212 "[42 .5 0 true /ThisName /AnotherName (This String) "
213 "(Another String) [-1]]");
217 std::unique_ptr<SkPDFDict> dict(
new SkPDFDict);
218 assert_emit_eq(
reporter, *dict,
"<<>>");
221 assert_emit_eq(
reporter, *dict,
"<</n1 42>>");
223 dict = std::make_unique<SkPDFDict>();
224 assert_emit_eq(
reporter, *dict,
"<<>>");
226 dict->insertInt(
"n1", 42);
227 assert_emit_eq(
reporter, *dict,
"<</n1 42>>");
232 std::unique_ptr<SkPDFArray> innerArray(
new SkPDFArray);
233 innerArray->appendInt(-100);
234 dict->insertObject(n3, std::move(innerArray));
235 assert_emit_eq(
reporter, *dict,
"<</n1 42\n/n2 .5\n/n3 [-100]>>");
237 dict = std::make_unique<SkPDFDict>();
238 assert_emit_eq(
reporter, *dict,
"<<>>");
240 dict->insertInt(
"n1", 24);
241 assert_emit_eq(
reporter, *dict,
"<</n1 24>>");
244 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99>>");
247 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99\n/n3 .5>>");
249 dict->insertName(
"n4",
"AName");
250 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName>>");
252 dict->insertName(
"n5",
SkString(
"AnotherName"));
253 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
254 "/n5 /AnotherName>>");
256 dict->insertTextString(
"n6",
"A String");
257 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
258 "/n5 /AnotherName\n/n6 (A String)>>");
260 dict->insertByteString(
"n7",
SkString(
"Another String"));
261 assert_emit_eq(
reporter, *dict,
"<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
262 "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>");
264 dict = std::make_unique<SkPDFDict>(
"DType");
265 assert_emit_eq(
reporter, *dict,
"<</Type /DType>>");
281 bool visited()
const {
return fVisited; }
284 Factory getFactory()
const override {
285 SK_ABORT(
"Does not participate in serialization");
288 const char* getTypeName()
const override {
return "TestImageFilter"; }
299 return desiredOutput;
302 std::optional<skif::LayerSpace<SkIRect>> onGetOutputLayerBounds(
305 return contentBounds;
308 mutable bool fVisited;
319 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
326 paint.setImageFilter(filter);
340 const char resource[] =
"fonts/Roboto2-Regular_NoEmbed.ttf";
342 if (noEmbedTypeface) {
353static void check_pdf_scalar_serialization(
357 if (len >=
sizeof(floatString)) {
361 if (floatString[len] !=
'\0' || strlen(floatString) != len) {
366 SkDebugf(
"%15.9g = \"%s\"\n", inputFloat, floatString);
368 float roundTripFloat;
369 if (1 != sscanf(floatString,
"%f", &roundTripFloat)) {
373 if (
SkIsFinite(inputFloat) && roundTripFloat != inputFloat) {
375 roundTripFloat, inputFloat);
382 int iterationCount = 512;
383 while (iterationCount-- > 0) {
384 union { uint32_t u;
float f; };
386 static_assert(
sizeof(
float) ==
sizeof(uint32_t),
"");
387 check_pdf_scalar_serialization(
reporter, f);
389 float alwaysCheck[] = {
390 0.0f, -0.0f, 1.0f, -1.0f,
SK_ScalarPI, 0.1f, FLT_MIN, FLT_MAX,
391 -FLT_MIN, -FLT_MAX, FLT_MIN / 16.0f, -FLT_MIN / 16.0f,
395 for (
float inputFloat: alwaysCheck) {
396 check_pdf_scalar_serialization(
reporter, inputFloat);
403 for (
int i = 0; i < 256; ++i) {
408 int roundTrip = (
int)(0.5 + f * 255);
414 const SkFont& font,
const uint32_t* clusters,
415 size_t utf8TextByteLength,
const char* utf8Text) {
427 constexpr unsigned len = 11;
428 const uint32_t clusters[
len] = { 3, 2, 2, 1, 0, 4, 4, 7, 6, 6, 5 };
429 const SkGlyphID glyphs[
len] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
430 SkPoint pos[
len] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
431 {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}};
432 const char text[] =
"abcdefgh";
443 {&
text[5], 1, 10, 1},
446 for (
const auto& expectation : expectations) {
451 constexpr unsigned len = 5;
452 const uint32_t clusters[
len] = { 0, 1, 4, 5, 6 };
455 const char text[] =
"Ha\xCC\x8A" "llo";
466 for (
const auto& expectation : expectations) {
476 SkCanvas* canvas = doc->beginPage(128, 160);
480 SkPaint layerPaint({0, 0, 0, 0});
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
#define SK_ABORT(message,...)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength])
constexpr unsigned kMaximumSkFloatToDecimalLength
constexpr float SK_FloatInfinity
static bool SkIsFinite(T x, Pack... values)
constexpr float SK_FloatNaN
constexpr float SK_FloatNegativeInfinity
@ kGlyphID
uses two byte words to represent glyph indices
SK_API SkString static SkString SkStringPrintf()
constexpr size_t SkToSizeT(S x)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
#define REPORT_FAILURE(reporter, cond, message)
Type::kYUV Type::kRGBA() int(0.7 *637)
int saveLayer(const SkRect *bounds, const SkPaint *paint)
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static bool CanEmbedTypeface(SkTypeface *, SkPDFDocument *)
static SkPDFUnion Bool(bool)
static SkPDFUnion Int(int32_t)
static SkPDFUnion TextString(const char *)
static SkPDFUnion ByteString(const char *)
static SkPDFUnion Name(const char *)
static SkPDFUnion Scalar(SkScalar)
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
const char * c_str() const
const FilterResult & source() const
static const uint8_t buffer[]
size_t ColorToDecimal(uint8_t value, char result[5])
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
SK_API sk_sp< SkShader > MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
SKSHAPER_API sk_sp< Factory > Factory()
font
Font Metadata and Metrics.
static constexpr SkRect MakeWH(float w, float h)