Beispiel #1
0
void SVGStyle::parseNode(xmlNodePtr node, map<string, SVGGradient*> &gradients) {
	AttributeParser parser;
	parser.parseNode(node);

	const map<string, vector<string> > &attributes = parser.getAttributes();
	for(map<string, vector<string> >::const_iterator iter = attributes.begin(); iter != attributes.end(); iter++) {
		const string &attribute = (*iter).first;
		const vector<string> &values = (*iter).second;



		for (vector<string>::const_iterator iterValue = values.begin (); iterValue != values.end (); iterValue ++)
		{
			const string &valueStr = (*iterValue);
			const char *value = valueStr.c_str ();

			bool fParsed = true;
			
			if(attribute == "stroke") {
				SVGGradient *gradient = getGradient(valueStr, gradients);
				if(gradient) {
					strokeGradient = gradient;
					_hasStrokeGradient = true;
					_hasStroke = true;
					fParsed = true;
				} else {
					fParsed = setStrokeColor(value);
				}
			} else if(attribute == "stroke-width") {
				setStrokeWidth(atof(value));
			} else if(attribute == "stroke-opacity") {
				setStrokeAlpha(atof(value));
			} else if(attribute == "stroke-linecap") {
				fParsed = setLineCap(value);
			} else if(attribute == "stroke-linejoin") {
				fParsed = setLineJoin(value);
			} else if(attribute == "stroke-miterlimit") {
				setMiterLimit(atof(value));
			} else if(attribute == "fill") {
				SVGGradient *gradient = getGradient(valueStr, gradients);
				if(gradient) {
					fillGradient = gradient;
					_hasFillGradient = true;
					_hasFill = true;
					fParsed = true;
				} else {
					fParsed = setFillColor(value);
				}
			} else if(attribute == "fill-opacity") {
				setFillAlpha(atof(value));
			} else if(attribute == "opacity") {
				setOpacity(atof(value));
			}

			if (fParsed) {
				break;
			}
		}
	}
}
Beispiel #2
0
SkPaint OsmAnd::TextRasterizer_P::getHaloPaint(const SkPaint& paint, const Style& style) const
{
    auto haloPaint = paint;
    haloPaint.setStyle(SkPaint::kStroke_Style);
    haloPaint.setColor(style.haloColor.toSkColor());
    haloPaint.setStrokeWidth(style.haloRadius);

    return haloPaint;
}
Beispiel #3
0
    void onOnceBeforeDraw() override {
        const SkRect fieldBounds = kBounds.makeOutset(kBallSize / 2, kBallSize / 2);
        const SkRRect ball = SkRRect::MakeOval(SkRect::MakeWH(kBallSize, kBallSize));
        const SkRRect paddle = SkRRect::MakeRectXY(SkRect::MakeWH(kPaddleSize.width(),
                                                                  kPaddleSize.height()),
                                                   kPaddleSize.width() / 2,
                                                   kPaddleSize.width() / 2);
        fBall.initialize(ball,
                         SkPoint::Make(kBounds.centerX(), kBounds.centerY()),
                         SkVector::Make(fRand.nextRangeScalar(kBallSpeedMin, kBallSpeedMax),
                                        fRand.nextRangeScalar(kBallSpeedMin, kBallSpeedMax)));
        fPaddle0.initialize(paddle,
                            SkPoint::Make(fieldBounds.left() - kPaddleSize.width() / 2,
                                          fieldBounds.centerY()),
                            SkVector::Make(0, 0));
        fPaddle1.initialize(paddle,
                            SkPoint::Make(fieldBounds.right() + kPaddleSize.width() / 2,
                                          fieldBounds.centerY()),
                            SkVector::Make(0, 0));

        // Background decoration.
        SkPath bgPath;
        bgPath.moveTo(kBounds.left() , fieldBounds.top());
        bgPath.lineTo(kBounds.right(), fieldBounds.top());
        bgPath.moveTo(kBounds.left() , fieldBounds.bottom());
        bgPath.lineTo(kBounds.right(), fieldBounds.bottom());
        // TODO: stroke-dash support would come in handy right about now.
        for (uint32_t i = 0; i < kBackgroundDashCount; ++i) {
            bgPath.moveTo(kBounds.centerX(),
                          kBounds.top() + (i + 0.25f) * kBounds.height() / kBackgroundDashCount);
            bgPath.lineTo(kBounds.centerX(),
                          kBounds.top() + (i + 0.75f) * kBounds.height() / kBackgroundDashCount);
        }

        auto bg_path  = sksg::Path::Make(bgPath);
        auto bg_paint = sksg::Color::Make(SK_ColorBLACK);
        bg_paint->setStyle(SkPaint::kStroke_Style);
        bg_paint->setStrokeWidth(kBackgroundStroke);

        auto ball_paint    = sksg::Color::Make(SK_ColorGREEN),
             paddle0_paint = sksg::Color::Make(SK_ColorBLUE),
             paddle1_paint = sksg::Color::Make(SK_ColorRED),
             shadow_paint  = sksg::Color::Make(SK_ColorBLACK);
        ball_paint->setAntiAlias(true);
        paddle0_paint->setAntiAlias(true);
        paddle1_paint->setAntiAlias(true);
        shadow_paint->setAntiAlias(true);
        shadow_paint->setOpacity(kShadowOpacity);

        // Build the scene graph.
        auto group = sksg::Group::Make();
        group->addChild(sksg::Draw::Make(std::move(bg_path), std::move(bg_paint)));
        group->addChild(sksg::Draw::Make(fPaddle0.shadowNode, shadow_paint));
        group->addChild(sksg::Draw::Make(fPaddle1.shadowNode, shadow_paint));
        group->addChild(sksg::Draw::Make(fBall.shadowNode, shadow_paint));
        group->addChild(sksg::Draw::Make(fPaddle0.objectNode, paddle0_paint));
        group->addChild(sksg::Draw::Make(fPaddle1.objectNode, paddle1_paint));
        group->addChild(sksg::Draw::Make(fBall.objectNode, ball_paint));

        // Handle everything in a normalized 1x1 space.
        fContentMatrix = sksg::Matrix<SkMatrix>::Make(
            SkMatrix::MakeRectToRect(SkRect::MakeWH(1, 1),
                                     SkRect::MakeIWH(this->width(), this->height()),
                                     SkMatrix::kFill_ScaleToFit));
        auto root = sksg::TransformEffect::Make(std::move(group), fContentMatrix);
        fScene = sksg::Scene::Make(std::move(root), sksg::AnimatorList());

        // Off we go.
        this->updatePaddleStrategy();
    }
Beispiel #4
0
void Shape::setStrokeWidth(const CSSParams & params)
{
    if (params.empty())
        return;
    setStrokeWidth(CSSUtils::CSSStrToPX(params[0]));
}