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

Side by Side Diff: tests/FontObjTest.cpp

Issue 245953003: Test font created from paint (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« include/core/SkFont.h ('K') | « src/core/SkPaint.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkFont.h"
9 #include "SkPaint.h"
10 #include "SkTypeface.h"
11 #include "Test.h"
12
13 static bool use_nonlinear_metrics(const SkPaint& paint) {
bungeman-skia 2014/05/30 14:33:51 These sound imperative instead of interrogative.
reed1 2014/05/30 14:38:59 Done.
14 return !paint.isSubpixelText() && !paint.isLinearText();
15 }
16
17 static bool enable_auto_hints(const SkPaint& paint) {
18 return paint.isAutohinted();
19 }
20
21 static bool enable_bytecode_hints(const SkPaint& paint) {
22 return paint.getHinting() >= SkPaint::kFull_Hinting;
23 }
24
25 static void test_cachedfont(skiatest::Reporter* reporter, const SkPaint& paint) {
26 SkFont* font = const_cast<SkPaint*>(&paint)->testing_getCachedFont();
27
28 REPORTER_ASSERT(reporter, font->getTypeface() == paint.getTypeface());
29 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
30 REPORTER_ASSERT(reporter, font->getScaleX() == paint.getTextScaleX());
31 REPORTER_ASSERT(reporter, font->getSkewX() == paint.getTextSkewX());
32
33 REPORTER_ASSERT(reporter, font->isVertical() == paint.isVerticalText());
34 REPORTER_ASSERT(reporter, font->isEmbolden() == paint.isFakeBoldText());
35
36 REPORTER_ASSERT(reporter, font->isUseNonLinearMetrics() == use_nonlinear_met rics(paint));
37 REPORTER_ASSERT(reporter, font->isEnableAutoHints() == enable_auto_hints(pai nt));
38 REPORTER_ASSERT(reporter, font->isEnableByteCodeHints() == enable_bytecode_h ints(paint));
39 }
40
41 static void test_cachedfont(skiatest::Reporter* reporter) {
42 static const char* const faces[] = {
43 NULL, // default font
44 "Arial", "Times", "Times New Roman", "Helvetica", "Courier",
45 "Courier New", "Verdana", "monospace",
46 };
47
48 static const struct {
49 SkPaint::Hinting hinting;
50 unsigned flags;
51 } settings[] = {
52 { SkPaint::kNo_Hinting, 0 },
53 { SkPaint::kNo_Hinting, SkPaint::kLinearText_Flag },
54 { SkPaint::kNo_Hinting, SkPaint::kSubpixelText_Flag },
55 { SkPaint::kSlight_Hinting, 0 },
56 { SkPaint::kSlight_Hinting, SkPaint::kLinearText_Flag },
57 { SkPaint::kSlight_Hinting, SkPaint::kSubpixelText_Flag },
58 { SkPaint::kNormal_Hinting, 0 },
59 { SkPaint::kNormal_Hinting, SkPaint::kLinearText_Flag },
60 { SkPaint::kNormal_Hinting, SkPaint::kSubpixelText_Flag },
61 };
62
63 static const struct {
64 SkScalar fScaleX;
65 SkScalar fSkewX;
66 } gScaleRec[] = {
67 { SK_Scalar1, 0 },
68 { SK_Scalar1/2, 0 },
69 // these two exercise obliquing (skew)
70 { SK_Scalar1, -SK_Scalar1/4 },
71 { SK_Scalar1/2, -SK_Scalar1/4 },
72 };
73
74 SkPaint paint;
75 char txt[] = "long.text.with.lots.of.dots.";
76
77 for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
78 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTyp eface::kNormal));
79 paint.setTypeface(face);
80
81 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
82 paint.setHinting(settings[j].hinting);
83 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0);
84 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl ag) != 0);
85
86 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
87 paint.setTextScaleX(gScaleRec[k].fScaleX);
88 paint.setTextSkewX(gScaleRec[k].fSkewX);
89
90 test_cachedfont(reporter, paint);
91
92 SkRect bounds;
93
94 // For no hinting and light hinting this should take the
95 // optimized generateAdvance path.
96 SkScalar width1 = paint.measureText(txt, strlen(txt));
97
98 // Requesting the bounds forces a generateMetrics call.
99 SkScalar width2 = paint.measureText(txt, strlen(txt), &bounds);
100
101 REPORTER_ASSERT(reporter, width1 == width2);
102
103 SkFont* font = paint.testing_getCachedFont();
104 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8 _SkTextEncoding);
105 // measureText not yet implemented...
106 SkASSERT(font_width1 == -1);
107 // REPORTER_ASSERT(reporter, width1 == font_width1);
108 }
109 }
110 }
111 }
112
113 DEF_TEST(FontObj, reporter) {
114 test_cachedfont(reporter);
115 }
116
117 // need tests for SkStrSearch
OLDNEW
« include/core/SkFont.h ('K') | « src/core/SkPaint.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698