OLD | NEW |
(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 is_use_nonlinear_metrics(const SkPaint& paint) { |
| 14 return !paint.isSubpixelText() && !paint.isLinearText(); |
| 15 } |
| 16 |
| 17 static bool is_enable_auto_hints(const SkPaint& paint) { |
| 18 return paint.isAutohinted(); |
| 19 } |
| 20 |
| 21 static bool is_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 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); |
| 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() == is_use_nonlinear_
metrics(paint)); |
| 37 REPORTER_ASSERT(reporter, font->isEnableAutoHints() == is_enable_auto_hints(
paint)); |
| 38 REPORTER_ASSERT(reporter, font->isEnableByteCodeHints() == is_enable_bytecod
e_hints(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 SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint)
); |
| 104 SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8
_SkTextEncoding); |
| 105 // measureText not yet implemented... |
| 106 REPORTER_ASSERT(reporter, 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 |
OLD | NEW |