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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "tools/Resources.h"
|
2015-10-12 20:05:04 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-10-12 20:05:04 +00:00
|
|
|
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) {
|
2019-05-07 19:38:46 +00:00
|
|
|
const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
|
2018-12-24 19:52:46 +00:00
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
auto rec = builder.allocRunPos(font, count);
|
2019-05-07 19:38:46 +00:00
|
|
|
font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, 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);
|
2019-05-07 19:38:46 +00:00
|
|
|
canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 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());
|
|
|
|
}
|