aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/FontMgrTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-08 15:04:29 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-08 15:04:29 +0000
commit43c27586e8b02243c16649de1cd7d95dcea0a712 (patch)
tree33e2ac282ac7e0683dadca9a9c658fd4beb7da04 /tests/FontMgrTest.cpp
parent667240a2e8dbe24b805d466e5bd0307ab2898418 (diff)
WIP -- SkFont
BUG=skia: R=bungeman@google.com, fmalita@chromium.org Review URL: https://codereview.chromium.org/185293018 git-svn-id: http://skia.googlecode.com/svn/trunk@14090 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/FontMgrTest.cpp')
-rw-r--r--tests/FontMgrTest.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp
index 6e59364684..69e2088c66 100644
--- a/tests/FontMgrTest.cpp
+++ b/tests/FontMgrTest.cpp
@@ -10,6 +10,44 @@
#include "SkTypeface.h"
#include "Test.h"
+#include "SkFont.h"
+#include "SkPaint.h"
+static void test_font(skiatest::Reporter* reporter) {
+ uint32_t flags = 0;
+ SkAutoTUnref<SkFont> font(SkFont::Create(NULL, 24, SkFont::kA8_MaskType, flags));
+
+ REPORTER_ASSERT(reporter, NULL != font->getTypeface());
+ REPORTER_ASSERT(reporter, 24 == font->getSize());
+ REPORTER_ASSERT(reporter, 1 == font->getScaleX());
+ REPORTER_ASSERT(reporter, 0 == font->getSkewX());
+ REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType());
+
+ uint16_t glyphs[5];
+ sk_bzero(glyphs, sizeof(glyphs));
+
+ int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs));
+
+ REPORTER_ASSERT(reporter, 5 == count);
+ for (int i = 0; i < count; ++i) {
+ REPORTER_ASSERT(reporter, 0 != glyphs[i]);
+ }
+ REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
+ REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
+
+ SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36));
+ REPORTER_ASSERT(reporter, newFont.get());
+ REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
+ REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we haven't changed
+ REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven't changed
+
+ SkPaint paint;
+ paint.setTextSize(18);
+ font.reset(SkFont::Testing_CreateFromPaint(paint));
+ REPORTER_ASSERT(reporter, font.get());
+ REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
+ REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
+}
+
/*
* If the font backend is going to "alias" some font names to other fonts
* (e.g. sans -> Arial) then we want to at least get the same typeface back
@@ -78,4 +116,5 @@ DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
DEF_TEST(FontMgr, reporter) {
test_fontiter(reporter, FLAGS_verboseFontMgr);
test_alias_names(reporter);
+ test_font(reporter);
}