epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
reed@google.com | bcb42ae | 2013-07-02 13:56:39 +0000 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkFont.h" |
| 9 | #include "include/core/SkMaskFilter.h" |
| 10 | #include "include/core/SkPath.h" |
| 11 | #include "include/core/SkTypeface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/SkTo.h" |
| 13 | #include "include/utils/SkRandom.h" |
| 14 | #include "src/core/SkAutoMalloc.h" |
| 15 | #include "src/core/SkBlurMask.h" |
| 16 | #include "src/core/SkPaintPriv.h" |
| 17 | #include "src/core/SkReadBuffer.h" |
| 18 | #include "src/core/SkWriteBuffer.h" |
| 19 | #include "src/utils/SkUTF.h" |
| 20 | #include "tests/Test.h" |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 21 | #undef ASSERT |
reed@google.com | bcb42ae | 2013-07-02 13:56:39 +0000 | [diff] [blame] | 22 | |
reed@google.com | 25b3bd5 | 2013-05-22 13:55:54 +0000 | [diff] [blame] | 23 | // temparary api for bicubic, just be sure we can set/clear it |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 24 | DEF_TEST(Paint_filterQuality, reporter) { |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 25 | SkPaint p0, p1; |
skia.committer@gmail.com | 5c561cb | 2013-07-25 07:01:00 +0000 | [diff] [blame] | 26 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 27 | REPORTER_ASSERT(reporter, kNone_SkFilterQuality == p0.getFilterQuality()); |
skia.committer@gmail.com | 5c561cb | 2013-07-25 07:01:00 +0000 | [diff] [blame] | 28 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 29 | static const SkFilterQuality gQualitys[] = { |
| 30 | kNone_SkFilterQuality, |
| 31 | kLow_SkFilterQuality, |
| 32 | kMedium_SkFilterQuality, |
| 33 | kHigh_SkFilterQuality |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 34 | }; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 35 | for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { |
| 36 | p0.setFilterQuality(gQualitys[i]); |
| 37 | REPORTER_ASSERT(reporter, gQualitys[i] == p0.getFilterQuality()); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 38 | p1 = p0; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 39 | REPORTER_ASSERT(reporter, gQualitys[i] == p1.getFilterQuality()); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 40 | |
| 41 | p0.reset(); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, kNone_SkFilterQuality == p0.getFilterQuality()); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 43 | } |
reed@google.com | 25b3bd5 | 2013-05-22 13:55:54 +0000 | [diff] [blame] | 44 | } |
| 45 | |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 46 | DEF_TEST(Paint_copy, reporter) { |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 47 | SkPaint paint; |
| 48 | // set a few member variables |
| 49 | paint.setStyle(SkPaint::kStrokeAndFill_Style); |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 50 | paint.setStrokeWidth(SkIntToScalar(2)); |
| 51 | // set a few pointers |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 52 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 53 | SkBlurMask::ConvertRadiusToSigma(1))); |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 54 | |
| 55 | // copy the paint using the copy constructor and check they are the same |
| 56 | SkPaint copiedPaint = paint; |
Mike Reed | 5f528e5 | 2019-01-28 10:57:28 -0500 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, paint.getHash() == copiedPaint.getHash()); |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, paint == copiedPaint); |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 59 | |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 60 | // copy the paint using the equal operator and check they are the same |
| 61 | copiedPaint = paint; |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, paint == copiedPaint); |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 63 | |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 64 | // clean the paint and check they are back to their initial states |
| 65 | SkPaint cleanPaint; |
| 66 | paint.reset(); |
| 67 | copiedPaint.reset(); |
robertphillips@google.com | b265741 | 2013-08-07 22:36:29 +0000 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, cleanPaint == paint); |
| 69 | REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); |
djsollen@google.com | b44cd65 | 2011-12-01 17:09:21 +0000 | [diff] [blame] | 70 | } |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 71 | |
| 72 | // found and fixed for webkit: mishandling when we hit recursion limit on |
| 73 | // mostly degenerate cubic flatness test |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 74 | DEF_TEST(Paint_regression_cubic, reporter) { |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 75 | SkPath path, stroke; |
| 76 | SkPaint paint; |
| 77 | |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 78 | path.moveTo(460.2881309415525f, |
| 79 | 303.250847066498f); |
| 80 | path.cubicTo(463.36378422175284f, |
| 81 | 302.1169735073363f, |
| 82 | 456.32239330810046f, |
| 83 | 304.720354932878f, |
| 84 | 453.15255460013304f, |
| 85 | 305.788586869862f); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 86 | |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 87 | SkRect fillR, strokeR; |
| 88 | fillR = path.getBounds(); |
| 89 | |
| 90 | paint.setStyle(SkPaint::kStroke_Style); |
| 91 | paint.setStrokeWidth(SkIntToScalar(2)); |
| 92 | paint.getFillPath(path, &stroke); |
| 93 | strokeR = stroke.getBounds(); |
| 94 | |
| 95 | SkRect maxR = fillR; |
Brian Osman | 116b33e | 2020-02-05 13:34:09 -0500 | [diff] [blame] | 96 | SkScalar miter = std::max(SK_Scalar1, paint.getStrokeMiter()); |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 97 | SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ? |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 98 | paint.getStrokeWidth() * miter : |
reed@android.com | a0f5d15 | 2009-06-22 17:38:10 +0000 | [diff] [blame] | 99 | paint.getStrokeWidth(); |
| 100 | maxR.inset(-inset, -inset); |
| 101 | |
| 102 | // test that our stroke didn't explode |
| 103 | REPORTER_ASSERT(reporter, maxR.contains(strokeR)); |
| 104 | } |
| 105 | |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 106 | DEF_TEST(Paint_flattening, reporter) { |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 107 | const SkFilterQuality levels[] = { |
| 108 | kNone_SkFilterQuality, |
| 109 | kLow_SkFilterQuality, |
| 110 | kMedium_SkFilterQuality, |
| 111 | kHigh_SkFilterQuality, |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 112 | }; |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 113 | const SkPaint::Cap caps[] = { |
| 114 | SkPaint::kButt_Cap, |
| 115 | SkPaint::kRound_Cap, |
| 116 | SkPaint::kSquare_Cap, |
| 117 | }; |
| 118 | const SkPaint::Join joins[] = { |
| 119 | SkPaint::kMiter_Join, |
| 120 | SkPaint::kRound_Join, |
| 121 | SkPaint::kBevel_Join, |
| 122 | }; |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 123 | const SkPaint::Style styles[] = { |
| 124 | SkPaint::kFill_Style, |
| 125 | SkPaint::kStroke_Style, |
| 126 | SkPaint::kStrokeAndFill_Style, |
| 127 | }; |
| 128 | |
| 129 | #define FOR_SETUP(index, array, setter) \ |
| 130 | for (size_t index = 0; index < SK_ARRAY_COUNT(array); ++index) { \ |
Mike Reed | 74b7677 | 2019-01-04 14:01:06 -0500 | [diff] [blame] | 131 | paint.setter(array[index]); |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 132 | |
| 133 | SkPaint paint; |
Mike Reed | 74b7677 | 2019-01-04 14:01:06 -0500 | [diff] [blame] | 134 | paint.setAntiAlias(true); |
| 135 | |
| 136 | // we don't serialize hinting or encoding -- soon to be removed from paint |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 137 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 138 | FOR_SETUP(i, levels, setFilterQuality) |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 139 | FOR_SETUP(l, caps, setStrokeCap) |
| 140 | FOR_SETUP(m, joins, setStrokeJoin) |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 141 | FOR_SETUP(p, styles, setStyle) |
| 142 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 143 | SkBinaryWriteBuffer writer; |
Cary Clark | 60ca867 | 2018-03-06 15:09:27 -0500 | [diff] [blame] | 144 | SkPaintPriv::Flatten(paint, writer); |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 145 | |
mtklein | b4c899d | 2016-04-29 13:58:09 -0700 | [diff] [blame] | 146 | SkAutoMalloc buf(writer.bytesWritten()); |
| 147 | writer.writeToMemory(buf.get()); |
| 148 | SkReadBuffer reader(buf.get(), writer.bytesWritten()); |
skia.committer@gmail.com | 667b98d | 2014-04-17 03:05:10 +0000 | [diff] [blame] | 149 | |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 150 | SkPaint paint2; |
Mike Reed | 31ba6fe | 2019-01-14 17:36:54 -0500 | [diff] [blame] | 151 | SkPaintPriv::Unflatten(&paint2, reader, nullptr); |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 152 | REPORTER_ASSERT(reporter, paint2 == paint); |
| 153 | |
Mike Reed | 74b7677 | 2019-01-04 14:01:06 -0500 | [diff] [blame] | 154 | }}}} |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 155 | #undef FOR_SETUP |
| 156 | |
| 157 | } |
| 158 | |
djsollen@google.com | 46348e2 | 2013-03-04 19:47:42 +0000 | [diff] [blame] | 159 | // found and fixed for android: not initializing rect for string's of length 0 |
commit-bot@chromium.org | e8807f4 | 2014-03-24 23:03:11 +0000 | [diff] [blame] | 160 | DEF_TEST(Paint_regression_measureText, reporter) { |
djsollen@google.com | 46348e2 | 2013-03-04 19:47:42 +0000 | [diff] [blame] | 161 | |
Mike Reed | 2e6db18 | 2018-12-15 13:45:33 -0500 | [diff] [blame] | 162 | SkFont font; |
| 163 | font.setSize(12.0f); |
djsollen@google.com | 46348e2 | 2013-03-04 19:47:42 +0000 | [diff] [blame] | 164 | |
| 165 | SkRect r; |
| 166 | r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); |
| 167 | |
| 168 | // test that the rect was reset |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 169 | font.measureText("", 0, SkTextEncoding::kUTF8, &r); |
djsollen@google.com | 46348e2 | 2013-03-04 19:47:42 +0000 | [diff] [blame] | 170 | REPORTER_ASSERT(reporter, r.isEmpty()); |
| 171 | } |
| 172 | |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 173 | #define ASSERT(expr) REPORTER_ASSERT(r, expr) |
| 174 | |
mtklein | 610a015 | 2014-09-25 11:57:53 -0700 | [diff] [blame] | 175 | DEF_TEST(Paint_MoreFlattening, r) { |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 176 | SkPaint paint; |
| 177 | paint.setColor(0x00AABBCC); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 178 | paint.setBlendMode(SkBlendMode::kModulate); |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 179 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 180 | SkBinaryWriteBuffer writer; |
Cary Clark | 60ca867 | 2018-03-06 15:09:27 -0500 | [diff] [blame] | 181 | SkPaintPriv::Flatten(paint, writer); |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 182 | |
mtklein | b4c899d | 2016-04-29 13:58:09 -0700 | [diff] [blame] | 183 | SkAutoMalloc buf(writer.bytesWritten()); |
| 184 | writer.writeToMemory(buf.get()); |
| 185 | SkReadBuffer reader(buf.get(), writer.bytesWritten()); |
| 186 | |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 187 | SkPaint other; |
Mike Reed | 31ba6fe | 2019-01-14 17:36:54 -0500 | [diff] [blame] | 188 | SkPaintPriv::Unflatten(&other, reader, nullptr); |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 189 | ASSERT(reader.offset() == writer.bytesWritten()); |
| 190 | |
| 191 | // No matter the encoding, these must always hold. |
| 192 | ASSERT(other.getColor() == paint.getColor()); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 193 | ASSERT(other.getBlendMode() == paint.getBlendMode()); |
commit-bot@chromium.org | aca1c01 | 2014-02-21 18:18:05 +0000 | [diff] [blame] | 194 | } |
mtklein | fb1fe4f | 2014-10-07 09:26:10 -0700 | [diff] [blame] | 195 | |
| 196 | DEF_TEST(Paint_getHash, r) { |
| 197 | // Try not to inspect the actual hash values in here. |
| 198 | // We might want to change the hash function. |
| 199 | |
| 200 | SkPaint paint; |
| 201 | const uint32_t defaultHash = paint.getHash(); |
| 202 | |
| 203 | // Check that some arbitrary field affects the hash. |
| 204 | paint.setColor(0xFF00FF00); |
| 205 | REPORTER_ASSERT(r, paint.getHash() != defaultHash); |
| 206 | paint.setColor(SK_ColorBLACK); // Reset to default value. |
| 207 | REPORTER_ASSERT(r, paint.getHash() == defaultHash); |
| 208 | |
Mike Reed | 3c03c85 | 2019-01-28 15:02:01 +0000 | [diff] [blame] | 209 | // This is part of fBitfields, the last field we hash. |
Mike Reed | 5f528e5 | 2019-01-28 10:57:28 -0500 | [diff] [blame] | 210 | paint.setBlendMode(SkBlendMode::kSrc); |
Mike Reed | 3c03c85 | 2019-01-28 15:02:01 +0000 | [diff] [blame] | 211 | REPORTER_ASSERT(r, paint.getHash() != defaultHash); |
Mike Reed | 5f528e5 | 2019-01-28 10:57:28 -0500 | [diff] [blame] | 212 | paint.setBlendMode(SkBlendMode::kSrcOver); |
mtklein | fb1fe4f | 2014-10-07 09:26:10 -0700 | [diff] [blame] | 213 | REPORTER_ASSERT(r, paint.getHash() == defaultHash); |
| 214 | } |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 215 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 216 | #include "include/effects/SkColorMatrixFilter.h" |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 217 | |
| 218 | DEF_TEST(Paint_nothingToDraw, r) { |
| 219 | SkPaint paint; |
| 220 | |
| 221 | REPORTER_ASSERT(r, !paint.nothingToDraw()); |
| 222 | paint.setAlpha(0); |
| 223 | REPORTER_ASSERT(r, paint.nothingToDraw()); |
| 224 | |
| 225 | paint.setAlpha(0xFF); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 226 | paint.setBlendMode(SkBlendMode::kDst); |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 227 | REPORTER_ASSERT(r, paint.nothingToDraw()); |
| 228 | |
| 229 | paint.setAlpha(0); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 230 | paint.setBlendMode(SkBlendMode::kSrcOver); |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 231 | |
| 232 | SkColorMatrix cm; |
| 233 | cm.setIdentity(); // does not change alpha |
Mike Reed | 50d79af | 2019-04-21 22:17:03 -0400 | [diff] [blame] | 234 | paint.setColorFilter(SkColorFilters::Matrix(cm)); |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 235 | REPORTER_ASSERT(r, paint.nothingToDraw()); |
| 236 | |
Mike Reed | 68eb8c2 | 2019-05-02 11:31:43 -0400 | [diff] [blame] | 237 | cm.postTranslate(0, 0, 0, 1.0f/255); // wacks alpha |
Mike Reed | 50d79af | 2019-04-21 22:17:03 -0400 | [diff] [blame] | 238 | paint.setColorFilter(SkColorFilters::Matrix(cm)); |
reed | f539b8c | 2014-11-11 12:51:33 -0800 | [diff] [blame] | 239 | REPORTER_ASSERT(r, !paint.nothingToDraw()); |
| 240 | } |
Mike Reed | 477fb91 | 2018-11-11 20:37:45 -0500 | [diff] [blame] | 241 | |
Mike Reed | c16abee | 2018-11-24 13:27:27 -0500 | [diff] [blame] | 242 | DEF_TEST(Font_getpos, r) { |
| 243 | SkFont font; |
| 244 | const char text[] = "Hamburgefons!@#!#23425,./;'[]"; |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 245 | int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); |
Mike Reed | c16abee | 2018-11-24 13:27:27 -0500 | [diff] [blame] | 246 | SkAutoTArray<uint16_t> glyphStorage(count); |
| 247 | uint16_t* glyphs = glyphStorage.get(); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 248 | (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, glyphs, count); |
Mike Reed | c16abee | 2018-11-24 13:27:27 -0500 | [diff] [blame] | 249 | |
| 250 | SkAutoTArray<SkScalar> widthStorage(count); |
| 251 | SkAutoTArray<SkScalar> xposStorage(count); |
| 252 | SkAutoTArray<SkPoint> posStorage(count); |
| 253 | |
| 254 | SkScalar* widths = widthStorage.get(); |
| 255 | SkScalar* xpos = xposStorage.get(); |
| 256 | SkPoint* pos = posStorage.get(); |
| 257 | |
| 258 | for (bool subpix : { false, true }) { |
| 259 | font.setSubpixel(subpix); |
Ben Wagner | 5785e4a | 2019-05-07 16:50:29 -0400 | [diff] [blame] | 260 | for (auto hint : { SkFontHinting::kNone, SkFontHinting::kSlight, SkFontHinting::kNormal, SkFontHinting::kFull}) { |
Mike Reed | c16abee | 2018-11-24 13:27:27 -0500 | [diff] [blame] | 261 | font.setHinting(hint); |
| 262 | for (auto size : { 1.0f, 12.0f, 100.0f }) { |
| 263 | font.setSize(size); |
| 264 | |
| 265 | font.getWidths(glyphs, count, widths); |
| 266 | font.getXPos(glyphs, count, xpos, 10); |
| 267 | font.getPos(glyphs, count, pos, {10, 20}); |
| 268 | |
| 269 | auto nearly_eq = [](SkScalar a, SkScalar b) { |
| 270 | return SkScalarAbs(a - b) < 0.000001f; |
| 271 | }; |
| 272 | |
| 273 | SkScalar x = 10; |
| 274 | for (int i = 0; i < count; ++i) { |
| 275 | REPORTER_ASSERT(r, nearly_eq(x, xpos[i])); |
| 276 | REPORTER_ASSERT(r, nearly_eq(x, pos[i].fX)); |
| 277 | REPORTER_ASSERT(r, nearly_eq(20, pos[i].fY)); |
| 278 | x += widths[i]; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |