Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: gm/pdf_never_embed.cpp

Issue 1401763002: SkPDF: fall back on paths for unembeddable fonts. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-10-12 (Monday) 15:54:45 EDT Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | resources/fonts/Roboto2-Regular_NoEmbed.ttf » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/pdf_never_embed.cpp
diff --git a/gm/pdf_never_embed.cpp b/gm/pdf_never_embed.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ef7974e3d7f131bd9bf534cfda34c3233310e9f3
--- /dev/null
+++ b/gm/pdf_never_embed.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Resources.h"
+#include "SkTypeface.h"
+#include "gm.h"
+
+static void excercise_draw_pos_text(SkCanvas* canvas,
+ const char* text,
+ SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ size_t textLen = strlen(text);
+ SkAutoTArray<SkScalar> widths(SkToInt(textLen));
+ paint.getTextWidths(text, textLen, &widths[0]);
+ SkAutoTArray<SkPoint> pos(SkToInt(textLen));
+ for (int i = 0; i < SkToInt(textLen); ++i) {
+ pos[i].set(x, y);
+ x += widths[i];
+ }
+ canvas->drawPosText(text, textLen, &pos[0], paint);
+}
+
+DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
+ const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
+ SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface(resource));
+ if (!typeface) {
+ return;
+ }
+ SkPaint p;
+ p.setTextSize(60);
+ p.setTypeface(typeface);
+ p.setAntiAlias(true);
+
+ const char text[] = "HELLO, WORLD!";
+
+ canvas->drawColor(SK_ColorWHITE);
+ excercise_draw_pos_text(canvas, text, 30, 90, p);
+
+ canvas->save();
+ canvas->rotate(45.0f);
+ p.setColor(0xF0800000);
+ excercise_draw_pos_text(canvas, text, 30, 45, p);
+ canvas->restore();
+
+ canvas->save();
+ canvas->scale(1, 4.0);
+ p.setColor(0xF0008000);
+ excercise_draw_pos_text(canvas, text, 15, 70, p);
+ canvas->restore();
+
+ canvas->scale(1.0, 0.5);
+ p.setColor(0xF0000080);
+ canvas->drawText(text, strlen(text), 30, 700, p);
+}
« no previous file with comments | « no previous file | resources/fonts/Roboto2-Regular_NoEmbed.ttf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698