blob: 361da74e6b81272e015a080a2c9db871ce5e0452 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.coma0f5d152009-06-22 17:38:10 +00008#include "Test.h"
9#include "SkPath.h"
10#include "SkPaint.h"
11
12// found and fixed for webkit: mishandling when we hit recursion limit on
13// mostly degenerate cubic flatness test
14static void regression_cubic(skiatest::Reporter* reporter) {
15 SkPath path, stroke;
16 SkPaint paint;
17
reed@android.comd4134452011-02-09 02:24:26 +000018 path.moveTo(SkFloatToFixed(460.2881309415525f),
19 SkFloatToFixed(303.250847066498));
20 path.cubicTo(SkFloatToFixed(463.36378422175284),
21 SkFloatToFixed(302.1169735073363),
22 SkFloatToFixed(456.32239330810046),
23 SkFloatToFixed(304.720354932878),
24 SkFloatToFixed(453.15255460013304),
25 SkFloatToFixed(305.788586869862));
reed@android.coma0f5d152009-06-22 17:38:10 +000026
27 SkRect fillR, strokeR;
28 fillR = path.getBounds();
29
30 paint.setStyle(SkPaint::kStroke_Style);
31 paint.setStrokeWidth(SkIntToScalar(2));
32 paint.getFillPath(path, &stroke);
33 strokeR = stroke.getBounds();
34
35 SkRect maxR = fillR;
36 SkScalar miter = SkMaxScalar(SK_Scalar1, paint.getStrokeMiter());
37 SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ?
38 SkScalarMul(paint.getStrokeWidth(), miter) :
39 paint.getStrokeWidth();
40 maxR.inset(-inset, -inset);
41
42 // test that our stroke didn't explode
43 REPORTER_ASSERT(reporter, maxR.contains(strokeR));
44}
45
46static void TestPaint(skiatest::Reporter* reporter) {
47 // TODO add general paint tests
48
49 // regression tests
50 regression_cubic(reporter);
51}
52
53#include "TestClassDef.h"
54DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint)