2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-07-02 13:56:39 +00:00
|
|
|
|
2017-01-11 17:44:43 +00:00
|
|
|
#include "SkAutoMalloc.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2018-11-12 01:37:45 +00:00
|
|
|
#include "SkFont.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkLayerDrawLooper.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2018-03-06 20:09:27 +00:00
|
|
|
#include "SkPaintPriv.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkPath.h"
|
2013-07-02 13:56:39 +00:00
|
|
|
#include "SkRandom.h"
|
2014-02-21 18:18:05 +00:00
|
|
|
#include "SkReadBuffer.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkTo.h"
|
2013-07-02 13:56:39 +00:00
|
|
|
#include "SkTypeface.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2014-02-21 18:18:05 +00:00
|
|
|
#include "SkWriteBuffer.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2018-07-31 13:44:36 +00:00
|
|
|
#undef ASSERT
|
2013-07-02 13:56:39 +00:00
|
|
|
|
|
|
|
static size_t uni_to_utf8(const SkUnichar src[], void* dst, int count) {
|
|
|
|
char* u8 = (char*)dst;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2018-07-25 20:52:48 +00:00
|
|
|
int n = SkToInt(SkUTF::ToUTF8(src[i], u8));
|
2013-07-02 13:56:39 +00:00
|
|
|
u8 += n;
|
|
|
|
}
|
|
|
|
return u8 - (char*)dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t uni_to_utf16(const SkUnichar src[], void* dst, int count) {
|
|
|
|
uint16_t* u16 = (uint16_t*)dst;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2018-07-25 20:52:48 +00:00
|
|
|
int n = SkToInt(SkUTF::ToUTF16(src[i], u16));
|
2013-07-02 13:56:39 +00:00
|
|
|
u16 += n;
|
|
|
|
}
|
|
|
|
return (char*)u16 - (char*)dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t uni_to_utf32(const SkUnichar src[], void* dst, int count) {
|
|
|
|
SkUnichar* u32 = (SkUnichar*)dst;
|
|
|
|
if (src != u32) {
|
|
|
|
memcpy(u32, src, count * sizeof(SkUnichar));
|
|
|
|
}
|
|
|
|
return count * sizeof(SkUnichar);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkTypeface::Encoding paint2encoding(const SkPaint& paint) {
|
2018-12-03 14:45:17 +00:00
|
|
|
SkTextEncoding enc = (SkTextEncoding)paint.getTextEncoding();
|
|
|
|
SkASSERT(kGlyphID_SkTextEncoding != enc);
|
2013-07-02 13:56:39 +00:00
|
|
|
return (SkTypeface::Encoding)enc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_first_zero(const uint16_t glyphs[], int count) {
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
if (0 == glyphs[i]) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-03-24 23:03:11 +00:00
|
|
|
DEF_TEST(Paint_cmap, reporter) {
|
|
|
|
// need to implement charsToGlyphs on other backends (e.g. linux, win)
|
|
|
|
// before we can run this tests everywhere
|
|
|
|
return;
|
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
static const int NGLYPHS = 64;
|
|
|
|
|
|
|
|
SkUnichar src[NGLYPHS];
|
|
|
|
SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count);
|
2018-12-03 14:45:17 +00:00
|
|
|
SkTextEncoding fEncoding;
|
2013-07-02 13:56:39 +00:00
|
|
|
} gRec[] = {
|
2018-12-03 14:45:17 +00:00
|
|
|
{ uni_to_utf8, kUTF8_SkTextEncoding },
|
|
|
|
{ uni_to_utf16, kUTF16_SkTextEncoding },
|
|
|
|
{ uni_to_utf32, kUTF32_SkTextEncoding },
|
2013-07-02 13:56:39 +00:00
|
|
|
};
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-07-02 13:56:39 +00:00
|
|
|
SkPaint paint;
|
2016-05-12 17:09:30 +00:00
|
|
|
paint.setTypeface(SkTypeface::MakeDefault());
|
2013-07-02 13:56:39 +00:00
|
|
|
SkTypeface* face = paint.getTypeface();
|
|
|
|
|
|
|
|
for (int i = 0; i < 1000; ++i) {
|
|
|
|
// generate some random text
|
|
|
|
for (int j = 0; j < NGLYPHS; ++j) {
|
|
|
|
src[j] = ' ' + j;
|
|
|
|
}
|
|
|
|
// inject some random chars, to sometimes abort early
|
|
|
|
src[rand.nextU() & 63] = rand.nextU() & 0xFFF;
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
for (size_t k = 0; k < SK_ARRAY_COUNT(gRec); ++k) {
|
|
|
|
paint.setTextEncoding(gRec[k].fEncoding);
|
|
|
|
|
|
|
|
size_t len = gRec[k].fSeedTextProc(src, dst, NGLYPHS);
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS];
|
2013-07-03 07:00:57 +00:00
|
|
|
|
2013-07-02 13:56:39 +00:00
|
|
|
bool contains = paint.containsText(dst, len);
|
|
|
|
int nglyphs = paint.textToGlyphs(dst, len, glyphs0);
|
|
|
|
int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS);
|
|
|
|
int index = find_first_zero(glyphs1, NGLYPHS);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, NGLYPHS == nglyphs);
|
|
|
|
REPORTER_ASSERT(reporter, index == first);
|
2014-03-24 23:03:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == memcmp(glyphs0, glyphs1, NGLYPHS * sizeof(uint16_t)));
|
2013-07-02 13:56:39 +00:00
|
|
|
if (contains) {
|
|
|
|
REPORTER_ASSERT(reporter, NGLYPHS == first);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, NGLYPHS > first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-01 17:09:21 +00:00
|
|
|
|
2013-05-22 13:55:54 +00:00
|
|
|
// temparary api for bicubic, just be sure we can set/clear it
|
2015-03-16 17:08:34 +00:00
|
|
|
DEF_TEST(Paint_filterQuality, reporter) {
|
2013-07-22 17:18:18 +00:00
|
|
|
SkPaint p0, p1;
|
2013-07-25 07:01:00 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, kNone_SkFilterQuality == p0.getFilterQuality());
|
2013-07-25 07:01:00 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
static const SkFilterQuality gQualitys[] = {
|
|
|
|
kNone_SkFilterQuality,
|
|
|
|
kLow_SkFilterQuality,
|
|
|
|
kMedium_SkFilterQuality,
|
|
|
|
kHigh_SkFilterQuality
|
2013-07-22 17:18:18 +00:00
|
|
|
};
|
2015-03-16 17:08:34 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) {
|
|
|
|
p0.setFilterQuality(gQualitys[i]);
|
|
|
|
REPORTER_ASSERT(reporter, gQualitys[i] == p0.getFilterQuality());
|
2013-07-22 17:18:18 +00:00
|
|
|
p1 = p0;
|
2015-03-16 17:08:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, gQualitys[i] == p1.getFilterQuality());
|
2013-07-22 17:18:18 +00:00
|
|
|
|
|
|
|
p0.reset();
|
2015-03-16 17:08:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, kNone_SkFilterQuality == p0.getFilterQuality());
|
2013-07-22 17:18:18 +00:00
|
|
|
}
|
2013-05-22 13:55:54 +00:00
|
|
|
}
|
|
|
|
|
2014-03-24 23:03:11 +00:00
|
|
|
DEF_TEST(Paint_copy, reporter) {
|
2011-12-01 17:09:21 +00:00
|
|
|
SkPaint paint;
|
|
|
|
// set a few member variables
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
// set a few pointers
|
2014-04-15 15:48:36 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2016-03-21 20:25:16 +00:00
|
|
|
paint.setLooper(looperBuilder.detach());
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(1)));
|
2011-12-01 17:09:21 +00:00
|
|
|
|
|
|
|
// copy the paint using the copy constructor and check they are the same
|
|
|
|
SkPaint copiedPaint = paint;
|
2013-08-07 22:36:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint == copiedPaint);
|
2011-12-01 17:09:21 +00:00
|
|
|
|
|
|
|
// copy the paint using the equal operator and check they are the same
|
|
|
|
copiedPaint = paint;
|
2013-08-07 22:36:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint == copiedPaint);
|
2011-12-01 17:09:21 +00:00
|
|
|
|
|
|
|
// clean the paint and check they are back to their initial states
|
|
|
|
SkPaint cleanPaint;
|
|
|
|
paint.reset();
|
|
|
|
copiedPaint.reset();
|
2013-08-07 22:36:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, cleanPaint == paint);
|
|
|
|
REPORTER_ASSERT(reporter, cleanPaint == copiedPaint);
|
2011-12-01 17:09:21 +00:00
|
|
|
}
|
2009-06-22 17:38:10 +00:00
|
|
|
|
|
|
|
// found and fixed for webkit: mishandling when we hit recursion limit on
|
|
|
|
// mostly degenerate cubic flatness test
|
2014-03-24 23:03:11 +00:00
|
|
|
DEF_TEST(Paint_regression_cubic, reporter) {
|
2009-06-22 17:38:10 +00:00
|
|
|
SkPath path, stroke;
|
|
|
|
SkPaint paint;
|
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
path.moveTo(460.2881309415525f,
|
|
|
|
303.250847066498f);
|
|
|
|
path.cubicTo(463.36378422175284f,
|
|
|
|
302.1169735073363f,
|
|
|
|
456.32239330810046f,
|
|
|
|
304.720354932878f,
|
|
|
|
453.15255460013304f,
|
|
|
|
305.788586869862f);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2009-06-22 17:38:10 +00:00
|
|
|
SkRect fillR, strokeR;
|
|
|
|
fillR = path.getBounds();
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
paint.getFillPath(path, &stroke);
|
|
|
|
strokeR = stroke.getBounds();
|
|
|
|
|
|
|
|
SkRect maxR = fillR;
|
|
|
|
SkScalar miter = SkMaxScalar(SK_Scalar1, paint.getStrokeMiter());
|
|
|
|
SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ?
|
2017-02-14 15:59:19 +00:00
|
|
|
paint.getStrokeWidth() * miter :
|
2009-06-22 17:38:10 +00:00
|
|
|
paint.getStrokeWidth();
|
|
|
|
maxR.inset(-inset, -inset);
|
|
|
|
|
|
|
|
// test that our stroke didn't explode
|
|
|
|
REPORTER_ASSERT(reporter, maxR.contains(strokeR));
|
|
|
|
}
|
|
|
|
|
2014-04-16 12:58:02 +00:00
|
|
|
DEF_TEST(Paint_flattening, reporter) {
|
2015-03-16 17:08:34 +00:00
|
|
|
const SkFilterQuality levels[] = {
|
|
|
|
kNone_SkFilterQuality,
|
|
|
|
kLow_SkFilterQuality,
|
|
|
|
kMedium_SkFilterQuality,
|
|
|
|
kHigh_SkFilterQuality,
|
2014-04-16 12:58:02 +00:00
|
|
|
};
|
2018-11-08 00:54:33 +00:00
|
|
|
const SkFontHinting hinting[] = {
|
|
|
|
kNo_SkFontHinting,
|
|
|
|
kSlight_SkFontHinting,
|
|
|
|
kNormal_SkFontHinting,
|
|
|
|
kFull_SkFontHinting,
|
2014-04-16 12:58:02 +00:00
|
|
|
};
|
|
|
|
const SkPaint::Cap caps[] = {
|
|
|
|
SkPaint::kButt_Cap,
|
|
|
|
SkPaint::kRound_Cap,
|
|
|
|
SkPaint::kSquare_Cap,
|
|
|
|
};
|
|
|
|
const SkPaint::Join joins[] = {
|
|
|
|
SkPaint::kMiter_Join,
|
|
|
|
SkPaint::kRound_Join,
|
|
|
|
SkPaint::kBevel_Join,
|
|
|
|
};
|
2018-12-03 14:45:17 +00:00
|
|
|
const SkTextEncoding encodings[] = {
|
|
|
|
kUTF8_SkTextEncoding,
|
|
|
|
kUTF16_SkTextEncoding,
|
|
|
|
kUTF32_SkTextEncoding,
|
|
|
|
kGlyphID_SkTextEncoding,
|
2014-04-16 12:58:02 +00:00
|
|
|
};
|
|
|
|
const SkPaint::Style styles[] = {
|
|
|
|
SkPaint::kFill_Style,
|
|
|
|
SkPaint::kStroke_Style,
|
|
|
|
SkPaint::kStrokeAndFill_Style,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FOR_SETUP(index, array, setter) \
|
|
|
|
for (size_t index = 0; index < SK_ARRAY_COUNT(array); ++index) { \
|
|
|
|
paint.setter(array[index]); \
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFlags(0x1234);
|
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
FOR_SETUP(i, levels, setFilterQuality)
|
2014-04-16 12:58:02 +00:00
|
|
|
FOR_SETUP(j, hinting, setHinting)
|
|
|
|
FOR_SETUP(l, caps, setStrokeCap)
|
|
|
|
FOR_SETUP(m, joins, setStrokeJoin)
|
|
|
|
FOR_SETUP(n, encodings, setTextEncoding)
|
|
|
|
FOR_SETUP(p, styles, setStyle)
|
|
|
|
|
2016-05-04 18:06:28 +00:00
|
|
|
SkBinaryWriteBuffer writer;
|
2018-03-06 20:09:27 +00:00
|
|
|
SkPaintPriv::Flatten(paint, writer);
|
2014-04-16 12:58:02 +00:00
|
|
|
|
2016-04-29 20:58:09 +00:00
|
|
|
SkAutoMalloc buf(writer.bytesWritten());
|
|
|
|
writer.writeToMemory(buf.get());
|
|
|
|
SkReadBuffer reader(buf.get(), writer.bytesWritten());
|
2014-04-17 03:05:10 +00:00
|
|
|
|
2014-04-16 12:58:02 +00:00
|
|
|
SkPaint paint2;
|
2018-03-06 20:09:27 +00:00
|
|
|
SkPaintPriv::Unflatten(&paint2, reader);
|
2014-04-16 12:58:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint2 == paint);
|
|
|
|
|
2018-10-27 14:39:00 +00:00
|
|
|
}}}}}}
|
2014-04-16 12:58:02 +00:00
|
|
|
#undef FOR_SETUP
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-04 19:47:42 +00:00
|
|
|
// found and fixed for android: not initializing rect for string's of length 0
|
2014-03-24 23:03:11 +00:00
|
|
|
DEF_TEST(Paint_regression_measureText, reporter) {
|
2013-03-04 19:47:42 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2013-11-25 19:44:07 +00:00
|
|
|
paint.setTextSize(12.0f);
|
2013-03-04 19:47:42 +00:00
|
|
|
|
|
|
|
SkRect r;
|
|
|
|
r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN);
|
|
|
|
|
|
|
|
// test that the rect was reset
|
2014-08-26 18:30:01 +00:00
|
|
|
paint.measureText("", 0, &r);
|
2013-03-04 19:47:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, r.isEmpty());
|
|
|
|
}
|
|
|
|
|
2014-02-21 18:18:05 +00:00
|
|
|
#define ASSERT(expr) REPORTER_ASSERT(r, expr)
|
|
|
|
|
2014-09-25 18:57:53 +00:00
|
|
|
DEF_TEST(Paint_MoreFlattening, r) {
|
2014-02-21 18:18:05 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x00AABBCC);
|
2014-09-22 18:40:33 +00:00
|
|
|
paint.setTextScaleX(1.0f); // Default value, ignored.
|
2014-02-21 18:18:05 +00:00
|
|
|
paint.setTextSize(19);
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kModulate);
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setLooper(nullptr); // Default value, ignored.
|
2014-02-21 18:18:05 +00:00
|
|
|
|
2016-05-04 18:06:28 +00:00
|
|
|
SkBinaryWriteBuffer writer;
|
2018-03-06 20:09:27 +00:00
|
|
|
SkPaintPriv::Flatten(paint, writer);
|
2014-02-21 18:18:05 +00:00
|
|
|
|
2016-04-29 20:58:09 +00:00
|
|
|
SkAutoMalloc buf(writer.bytesWritten());
|
|
|
|
writer.writeToMemory(buf.get());
|
|
|
|
SkReadBuffer reader(buf.get(), writer.bytesWritten());
|
|
|
|
|
2014-02-21 18:18:05 +00:00
|
|
|
SkPaint other;
|
2018-03-06 20:09:27 +00:00
|
|
|
SkPaintPriv::Unflatten(&other, reader);
|
2014-02-21 18:18:05 +00:00
|
|
|
ASSERT(reader.offset() == writer.bytesWritten());
|
|
|
|
|
|
|
|
// No matter the encoding, these must always hold.
|
|
|
|
ASSERT(other.getColor() == paint.getColor());
|
|
|
|
ASSERT(other.getTextScaleX() == paint.getTextScaleX());
|
|
|
|
ASSERT(other.getTextSize() == paint.getTextSize());
|
|
|
|
ASSERT(other.getLooper() == paint.getLooper());
|
2016-10-06 00:33:02 +00:00
|
|
|
ASSERT(other.getBlendMode() == paint.getBlendMode());
|
2014-02-21 18:18:05 +00:00
|
|
|
}
|
2014-10-07 16:26:10 +00:00
|
|
|
|
|
|
|
DEF_TEST(Paint_getHash, r) {
|
|
|
|
// Try not to inspect the actual hash values in here.
|
|
|
|
// We might want to change the hash function.
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
const uint32_t defaultHash = paint.getHash();
|
|
|
|
|
|
|
|
// Check that some arbitrary field affects the hash.
|
|
|
|
paint.setColor(0xFF00FF00);
|
|
|
|
REPORTER_ASSERT(r, paint.getHash() != defaultHash);
|
|
|
|
paint.setColor(SK_ColorBLACK); // Reset to default value.
|
|
|
|
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
|
|
|
|
|
|
|
|
// SkTypeface is the first field we hash, so test it specially.
|
2016-05-12 17:09:30 +00:00
|
|
|
paint.setTypeface(SkTypeface::MakeDefault());
|
2014-10-07 16:26:10 +00:00
|
|
|
REPORTER_ASSERT(r, paint.getHash() != defaultHash);
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setTypeface(nullptr);
|
2014-10-07 16:26:10 +00:00
|
|
|
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
|
|
|
|
|
|
|
|
// This is part of fBitfields, the last field we hash.
|
2018-11-08 00:54:33 +00:00
|
|
|
paint.setHinting(kSlight_SkFontHinting);
|
2014-10-07 16:26:10 +00:00
|
|
|
REPORTER_ASSERT(r, paint.getHash() != defaultHash);
|
2018-11-08 00:54:33 +00:00
|
|
|
paint.setHinting(kNormal_SkFontHinting);
|
2014-10-07 16:26:10 +00:00
|
|
|
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
|
|
|
|
}
|
2014-11-11 20:51:33 +00:00
|
|
|
|
|
|
|
#include "SkColorMatrixFilter.h"
|
|
|
|
|
|
|
|
DEF_TEST(Paint_nothingToDraw, r) {
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, !paint.nothingToDraw());
|
|
|
|
paint.setAlpha(0);
|
|
|
|
REPORTER_ASSERT(r, paint.nothingToDraw());
|
|
|
|
|
|
|
|
paint.setAlpha(0xFF);
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kDst);
|
2014-11-11 20:51:33 +00:00
|
|
|
REPORTER_ASSERT(r, paint.nothingToDraw());
|
|
|
|
|
|
|
|
paint.setAlpha(0);
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kSrcOver);
|
2014-11-11 20:51:33 +00:00
|
|
|
|
|
|
|
SkColorMatrix cm;
|
|
|
|
cm.setIdentity(); // does not change alpha
|
2016-03-22 17:17:23 +00:00
|
|
|
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
2014-11-11 20:51:33 +00:00
|
|
|
REPORTER_ASSERT(r, paint.nothingToDraw());
|
|
|
|
|
|
|
|
cm.postTranslate(0, 0, 0, 1); // wacks alpha
|
2016-03-22 17:17:23 +00:00
|
|
|
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
2014-11-11 20:51:33 +00:00
|
|
|
REPORTER_ASSERT(r, !paint.nothingToDraw());
|
|
|
|
}
|
2018-11-12 01:37:45 +00:00
|
|
|
|
|
|
|
DEF_TEST(Paint_getwidths, r) {
|
|
|
|
SkPaint paint;
|
|
|
|
const char text[] = "Hamburgefons!@#!#23425,./;'[]";
|
|
|
|
int count = paint.countText(text, strlen(text));
|
|
|
|
SkAutoTArray<uint16_t> glyphStorage(count * 2);
|
|
|
|
uint16_t* glyphs = glyphStorage.get();
|
|
|
|
|
|
|
|
(void)paint.textToGlyphs(text, strlen(text), glyphs);
|
2018-12-03 14:45:17 +00:00
|
|
|
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
2018-11-12 01:37:45 +00:00
|
|
|
|
|
|
|
SkAutoTArray<SkScalar> widthStorage(count * 2);
|
|
|
|
SkScalar* widths = widthStorage.get();
|
|
|
|
SkAutoTArray<SkRect> rectStorage(count * 2);
|
|
|
|
SkRect* bounds = rectStorage.get();
|
|
|
|
|
|
|
|
for (bool subpix : { false, true }) {
|
|
|
|
paint.setSubpixelText(subpix);
|
|
|
|
for (auto hint : { kNo_SkFontHinting, kSlight_SkFontHinting, kNormal_SkFontHinting, kFull_SkFontHinting}) {
|
|
|
|
paint.setHinting(hint);
|
|
|
|
for (auto size : { 1.0f, 12.0f, 100.0f }) {
|
|
|
|
paint.setTextSize(size);
|
|
|
|
paint.getTextWidths(glyphs, count * 2, widths, bounds);
|
|
|
|
|
|
|
|
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
|
|
|
|
font.getWidths(glyphs, count, widths + count, bounds + count);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
REPORTER_ASSERT(r, widths[i] == widths[i + count]);
|
|
|
|
REPORTER_ASSERT(r, bounds[i] == bounds[i + count]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-24 18:27:27 +00:00
|
|
|
|
|
|
|
DEF_TEST(Font_getpos, r) {
|
|
|
|
SkFont font;
|
|
|
|
const char text[] = "Hamburgefons!@#!#23425,./;'[]";
|
|
|
|
int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding);
|
|
|
|
SkAutoTArray<uint16_t> glyphStorage(count);
|
|
|
|
uint16_t* glyphs = glyphStorage.get();
|
|
|
|
(void)font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, glyphs, count);
|
|
|
|
|
|
|
|
SkAutoTArray<SkScalar> widthStorage(count);
|
|
|
|
SkAutoTArray<SkScalar> xposStorage(count);
|
|
|
|
SkAutoTArray<SkPoint> posStorage(count);
|
|
|
|
|
|
|
|
SkScalar* widths = widthStorage.get();
|
|
|
|
SkScalar* xpos = xposStorage.get();
|
|
|
|
SkPoint* pos = posStorage.get();
|
|
|
|
|
|
|
|
for (bool subpix : { false, true }) {
|
|
|
|
font.setSubpixel(subpix);
|
|
|
|
for (auto hint : { kNo_SkFontHinting, kSlight_SkFontHinting, kNormal_SkFontHinting, kFull_SkFontHinting}) {
|
|
|
|
font.setHinting(hint);
|
|
|
|
for (auto size : { 1.0f, 12.0f, 100.0f }) {
|
|
|
|
font.setSize(size);
|
|
|
|
|
|
|
|
font.getWidths(glyphs, count, widths);
|
|
|
|
font.getXPos(glyphs, count, xpos, 10);
|
|
|
|
font.getPos(glyphs, count, pos, {10, 20});
|
|
|
|
|
|
|
|
auto nearly_eq = [](SkScalar a, SkScalar b) {
|
|
|
|
return SkScalarAbs(a - b) < 0.000001f;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkScalar x = 10;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
REPORTER_ASSERT(r, nearly_eq(x, xpos[i]));
|
|
|
|
REPORTER_ASSERT(r, nearly_eq(x, pos[i].fX));
|
|
|
|
REPORTER_ASSERT(r, nearly_eq(20, pos[i].fY));
|
|
|
|
x += widths[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|