Detect when the caller was hairline AND strokeandfill, and resolve that into FILL

This fixes the unittests on WIN in the trybot for DEPS roll 4048
Review URL: https://codereview.appspot.com/6242057

git-svn-id: http://skia.googlecode.com/svn/trunk@4057 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-05-29 12:03:46 +00:00
parent 398b1bcb7d
commit 8b06f1a7ff
3 changed files with 56 additions and 9 deletions

View File

@ -46,14 +46,16 @@ public:
bool isFillStyle() const {
return kFill_Style == this->getStyle();
}
void setFillStyle();
void setHairlineStyle() { fWidth = 0; }
void setStrokeStyle(SkScalar width, bool strokeAndFill = false) {
fWidth = width;
fStrokeAndFill = strokeAndFill;
}
void setFillStyle();
void setHairlineStyle();
/**
* Specify the strokewidth, and optionally if you want stroke + fill.
* Note, if width==0, then this request is taken to mean:
* strokeAndFill==true -> new style will be Fill
* strokeAndFill==false -> new style will be Hairline
*/
void setStrokeStyle(SkScalar width, bool strokeAndFill = false);
void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) {
fCap = cap;

View File

@ -38,8 +38,14 @@ SkStrokeRec::SkStrokeRec(const SkPaint& paint) {
fStrokeAndFill = false;
break;
case SkPaint::kStrokeAndFill_Style:
fWidth = paint.getStrokeWidth();
fStrokeAndFill = true;
if (0 == paint.getStrokeWidth()) {
// hairline+fill == fill
fWidth = kStrokeRec_FillStyleWidth;
fStrokeAndFill = false;
} else {
fWidth = paint.getStrokeWidth();
fStrokeAndFill = true;
}
break;
default:
SkASSERT(!"unknown paint style");
@ -67,6 +73,22 @@ SkStrokeRec::Style SkStrokeRec::getStyle() const {
void SkStrokeRec::setFillStyle() {
fWidth = kStrokeRec_FillStyleWidth;
fStrokeAndFill = false;
}
void SkStrokeRec::setHairlineStyle() {
fWidth = 0;
fStrokeAndFill = false;
}
void SkStrokeRec::setStrokeStyle(SkScalar width, bool strokeAndFill) {
if (strokeAndFill && (0 == width)) {
// hairline+fill == fill
this->setFillStyle();
} else {
fWidth = width;
fStrokeAndFill = strokeAndFill;
}
}
#include "SkStroke.h"

View File

@ -10,11 +10,32 @@
#include "SkPath.h"
#include "SkParse.h"
#include "SkParsePath.h"
#include "SkPathEffect.h"
#include "SkRandom.h"
#include "SkReader32.h"
#include "SkSize.h"
#include "SkWriter32.h"
static void test_strokerec(skiatest::Reporter* reporter) {
SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
REPORTER_ASSERT(reporter, rec.isFillStyle());
rec.setHairlineStyle();
REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rec.setStrokeStyle(SK_Scalar1, false);
REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rec.setStrokeStyle(SK_Scalar1, true);
REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rec.setStrokeStyle(0, false);
REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rec.setStrokeStyle(0, true);
REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
}
/**
* cheapIsDirection can take a shortcut when a path is marked convex.
* This function ensures that we always test cheapIsDirection when the path
@ -1377,6 +1398,8 @@ void TestPath(skiatest::Reporter* reporter) {
test_raw_iter(reporter);
test_circle(reporter);
test_oval(reporter);
test_strokerec(reporter);
}
#include "TestClassDef.h"