static SkPathEffect* make_warp_pe() { SkPath path; path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); path.close(); path.offset(SkIntToScalar(-6), 0); SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style); SkPathEffect* inner = new SkCornerPathEffect(SkIntToScalar(CORNER_RADIUS)); SkPathEffect* pe = new SkComposePathEffect(outer, inner); outer->unref(); inner->unref(); return pe; }
static void compose_pe(SkPaint* paint) { SkPathEffect* pe = paint->getPathEffect(); SkPathEffect* corner = SkCornerPathEffect::Create(25); SkPathEffect* compose; if (pe) { compose = SkComposePathEffect::Create(pe, corner); corner->unref(); } else { compose = corner; } paint->setPathEffect(compose)->unref(); }
void WRasterImage::setChanged(WFlags<ChangeFlag> flags) { if (flags & Clipping) { if (painter()->hasClipping()) { impl_->setTransform(painter()->clipPathTransform()); SkPath clipPath; impl_->drawPlainPath(clipPath, painter()->clipPath()); impl_->canvas_->clipPath(clipPath, SkRegion::kReplace_Op); } else { impl_->canvas_->restore(); impl_->canvas_->save(); } impl_->setTransform(painter()->combinedTransform()); } if (flags & Transform) { impl_->setTransform(painter()->combinedTransform()); flags = Pen | Brush | Font | Hints; } if (flags & Hints) { if (!(painter()->renderHints() & WPainter::Antialiasing)) { impl_->strokePaint_.setAntiAlias(false); impl_->fillPaint_.setAntiAlias(false); impl_->textPaint_.setAntiAlias(false); } else { impl_->strokePaint_.setAntiAlias(true); impl_->fillPaint_.setAntiAlias(true); impl_->textPaint_.setAntiAlias(true); } } if (flags & Pen) { const WPen& pen = painter()->pen(); if (pen.style() != NoPen) { const WColor& color = pen.color(); impl_->strokePaint_.setColor(fromWColor(color)); WLength w = pen.width(); impl_->strokePaint_.setStrokeWidth(SkIntToScalar(w.toPixels())); switch (pen.capStyle()) { case FlatCap: impl_->strokePaint_.setStrokeCap(SkPaint::kButt_Cap); break; case SquareCap: impl_->strokePaint_.setStrokeCap(SkPaint::kSquare_Cap); break; case RoundCap: impl_->strokePaint_.setStrokeCap(SkPaint::kRound_Cap); break; } switch (pen.joinStyle()) { case MiterJoin: impl_->strokePaint_.setStrokeJoin(SkPaint::kMiter_Join); break; case BevelJoin: impl_->strokePaint_.setStrokeJoin(SkPaint::kBevel_Join); break; case RoundJoin: impl_->strokePaint_.setStrokeJoin(SkPaint::kRound_Join); break; } SkPathEffect *pe = impl_->strokePaint_.setPathEffect(0); if (pe) pe->unref(); switch (pen.style()) { case NoPen: break; case SolidLine: break; case DashLine: { const SkScalar dasharray[] = { SkIntToScalar(4), SkIntToScalar(2) }; impl_->strokePaint_.setPathEffect(new SkDashPathEffect(dasharray, 2, false))->unref(); break; } case DotLine: { const SkScalar dasharray[] = { SkIntToScalar(1), SkIntToScalar(2) }; impl_->strokePaint_.setPathEffect(new SkDashPathEffect(dasharray, 2, false))->unref(); break; } case DashDotLine: { const SkScalar dasharray[] = { SkIntToScalar(4), SkIntToScalar(2), SkIntToScalar(1), SkIntToScalar(2) }; impl_->strokePaint_.setPathEffect(new SkDashPathEffect(dasharray, 4, false))->unref(); break; } case DashDotDotLine: { const SkScalar dasharray[] = { SkIntToScalar(4), SkIntToScalar(2), SkIntToScalar(1), SkIntToScalar(2), SkIntToScalar(1), SkIntToScalar(2) }; impl_->strokePaint_.setPathEffect(new SkDashPathEffect(dasharray, 6, false))->unref(); break; } } } } if (flags & Brush) { const WBrush& brush = painter()->brush(); if (brush.style() != NoBrush) { const WColor& color = painter()->brush().color(); impl_->fillPaint_.setColor(fromWColor(color)); } } if (flags & Font) { const WFont& font = painter()->font(); const char *base = 0; switch (font.genericFamily()) { case WFont::Default: case WFont::Serif: base = "Times"; break; case WFont::SansSerif: base = "Helvetica"; break; case WFont::Monospace: base = "Courier"; break; case WFont::Fantasy: // Not really ! base = "Symbol"; break; case WFont::Cursive: // Not really ! base = "ZapfDingbats"; } int style = SkTypeface::kNormal; if (font.style() != WFont::NormalStyle) style |= SkTypeface::kItalic; if (font.weight() == WFont::Bold || font.weight() == WFont::Bolder) style |= SkTypeface::kBold; impl_->textPaint_.setTypeface(SkTypeface::CreateFromName(base, (SkTypeface::Style)style))->unref(); impl_->textPaint_.setTextSize(SkIntToScalar(font.sizeLength(12).toPixels())); } }