2015-10-12 20:05:04 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2018-12-24 19:52:46 +00:00
|
|
|
#include "SkTextBlob.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkTo.h"
|
2015-10-12 20:05:04 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
static void excercise_draw_pos_text(SkCanvas* canvas,
|
|
|
|
const char* text,
|
|
|
|
SkScalar x, SkScalar y,
|
2018-12-24 19:52:46 +00:00
|
|
|
const SkFont& font,
|
2015-10-12 20:05:04 +00:00
|
|
|
const SkPaint& paint) {
|
2018-12-24 19:52:46 +00:00
|
|
|
const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding);
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
auto rec = builder.allocRunPos(font, count);
|
|
|
|
font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count);
|
2019-01-01 20:40:28 +00:00
|
|
|
font.getPos(rec.glyphs, count, rec.points());
|
2018-12-24 19:52:46 +00:00
|
|
|
canvas->drawTextBlob(builder.make(), x, y, paint);
|
2015-10-12 20:05:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) {
|
2015-10-12 20:05:04 +00:00
|
|
|
SkPaint p;
|
|
|
|
|
2018-12-24 19:52:46 +00:00
|
|
|
SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
|
2019-01-22 19:45:16 +00:00
|
|
|
if (!font.getTypefaceOrDefault()) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not load fonts/Roboto2-Regular_NoEmbed.ttf. "
|
|
|
|
"Did you forget to set the resourcePath?";
|
|
|
|
return skiagm::DrawResult::kFail;
|
2016-05-12 17:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-10-12 20:05:04 +00:00
|
|
|
const char text[] = "HELLO, WORLD!";
|
|
|
|
|
|
|
|
canvas->drawColor(SK_ColorWHITE);
|
2018-12-24 19:52:46 +00:00
|
|
|
excercise_draw_pos_text(canvas, text, 30, 90, font, p);
|
2015-10-12 20:05:04 +00:00
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->rotate(45.0f);
|
|
|
|
p.setColor(0xF0800000);
|
2018-12-24 19:52:46 +00:00
|
|
|
excercise_draw_pos_text(canvas, text, 30, 45, font, p);
|
2015-10-12 20:05:04 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(1, 4.0);
|
|
|
|
p.setColor(0xF0008000);
|
2018-12-24 19:52:46 +00:00
|
|
|
excercise_draw_pos_text(canvas, text, 15, 70, font, p);
|
2015-10-12 20:05:04 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->scale(1.0, 0.5);
|
|
|
|
p.setColor(0xF0000080);
|
2018-12-24 19:52:46 +00:00
|
|
|
canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p);
|
2019-02-07 23:20:09 +00:00
|
|
|
return skiagm::DrawResult::kOk;
|
2015-10-12 20:05:04 +00:00
|
|
|
}
|
2018-03-09 17:16:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
// should draw completely white.
|
|
|
|
DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) {
|
|
|
|
canvas->clipRect({-1, -1, 613, 793}, false);
|
|
|
|
canvas->translate(-571, 0);
|
|
|
|
canvas->scale(0.75, 0.75);
|
|
|
|
canvas->clipRect({-1, -1, 613, 793}, false);
|
|
|
|
canvas->translate(0, -816);
|
|
|
|
canvas->drawRect({0, 0, 1224, 1500}, SkPaint());
|
|
|
|
}
|