mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
svg_loader: code refactoring
use color structure to keep neat & compact code.
This commit is contained in:
parent
8dc5d5204b
commit
3e7888b538
3 changed files with 19 additions and 24 deletions
|
@ -774,7 +774,7 @@ static void _handlePaintAttr(SvgPaint* paint, const char* value)
|
||||||
paint->curColor = true;
|
paint->curColor = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_toColor(value, &paint->r, &paint->g, &paint->b, &paint->url);
|
_toColor(value, &paint->color.r, &paint->color.g, &paint->color.b, &paint->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -782,7 +782,7 @@ static void _handleColorAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, co
|
||||||
{
|
{
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
style->curColorSet = true;
|
style->curColorSet = true;
|
||||||
_toColor(value, &style->r, &style->g, &style->b, nullptr);
|
_toColor(value, &style->color.r, &style->color.g, &style->color.b, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2286,16 +2286,12 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
//Inherit the property of parent if not present in child.
|
//Inherit the property of parent if not present in child.
|
||||||
//Fill
|
//Fill
|
||||||
if (!((int)child->fill.flags & (int)SvgFillFlags::Paint)) {
|
if (!((int)child->fill.flags & (int)SvgFillFlags::Paint)) {
|
||||||
child->fill.paint.r = parent->fill.paint.r;
|
child->fill.paint.color = parent->fill.paint.color;
|
||||||
child->fill.paint.g = parent->fill.paint.g;
|
|
||||||
child->fill.paint.b = parent->fill.paint.b;
|
|
||||||
child->fill.paint.none = parent->fill.paint.none;
|
child->fill.paint.none = parent->fill.paint.none;
|
||||||
child->fill.paint.curColor = parent->fill.paint.curColor;
|
child->fill.paint.curColor = parent->fill.paint.curColor;
|
||||||
if (parent->fill.paint.url) child->fill.paint.url = _copyId(parent->fill.paint.url->c_str());
|
if (parent->fill.paint.url) child->fill.paint.url = _copyId(parent->fill.paint.url->c_str());
|
||||||
} else if (child->fill.paint.curColor && !child->curColorSet) {
|
} else if (child->fill.paint.curColor && !child->curColorSet) {
|
||||||
child->r = parent->r;
|
child->color = parent->color;
|
||||||
child->g = parent->g;
|
|
||||||
child->b = parent->b;
|
|
||||||
}
|
}
|
||||||
if (!((int)child->fill.flags & (int)SvgFillFlags::Opacity)) {
|
if (!((int)child->fill.flags & (int)SvgFillFlags::Opacity)) {
|
||||||
child->fill.opacity = parent->fill.opacity;
|
child->fill.opacity = parent->fill.opacity;
|
||||||
|
@ -2305,16 +2301,12 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
}
|
}
|
||||||
//Stroke
|
//Stroke
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Paint)) {
|
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Paint)) {
|
||||||
child->stroke.paint.r = parent->stroke.paint.r;
|
child->stroke.paint.color = parent->stroke.paint.color;
|
||||||
child->stroke.paint.g = parent->stroke.paint.g;
|
|
||||||
child->stroke.paint.b = parent->stroke.paint.b;
|
|
||||||
child->stroke.paint.none = parent->stroke.paint.none;
|
child->stroke.paint.none = parent->stroke.paint.none;
|
||||||
child->stroke.paint.curColor = parent->stroke.paint.curColor;
|
child->stroke.paint.curColor = parent->stroke.paint.curColor;
|
||||||
child->stroke.paint.url = parent->stroke.paint.url ? _copyId(parent->stroke.paint.url->c_str()) : nullptr;
|
child->stroke.paint.url = parent->stroke.paint.url ? _copyId(parent->stroke.paint.url->c_str()) : nullptr;
|
||||||
} else if (child->stroke.paint.curColor && !child->curColorSet) {
|
} else if (child->stroke.paint.curColor && !child->curColorSet) {
|
||||||
child->r = parent->r;
|
child->color = parent->color;
|
||||||
child->g = parent->g;
|
|
||||||
child->b = parent->b;
|
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Opacity)) {
|
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Opacity)) {
|
||||||
child->stroke.opacity = parent->stroke.opacity;
|
child->stroke.opacity = parent->stroke.opacity;
|
||||||
|
|
|
@ -219,13 +219,18 @@ struct SvgComposite
|
||||||
SvgNode* node;
|
SvgNode* node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SvgColor
|
||||||
|
{
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t b;
|
||||||
|
};
|
||||||
|
|
||||||
struct SvgPaint
|
struct SvgPaint
|
||||||
{
|
{
|
||||||
SvgStyleGradient* gradient;
|
SvgStyleGradient* gradient;
|
||||||
string *url;
|
string *url;
|
||||||
uint8_t r;
|
SvgColor color;
|
||||||
uint8_t g;
|
|
||||||
uint8_t b;
|
|
||||||
bool none;
|
bool none;
|
||||||
bool curColor;
|
bool curColor;
|
||||||
};
|
};
|
||||||
|
@ -277,9 +282,7 @@ struct SvgStyleProperty
|
||||||
SvgStyleStroke stroke;
|
SvgStyleStroke stroke;
|
||||||
SvgComposite comp;
|
SvgComposite comp;
|
||||||
int opacity;
|
int opacity;
|
||||||
uint8_t r;
|
SvgColor color;
|
||||||
uint8_t g;
|
|
||||||
uint8_t b;
|
|
||||||
bool curColorSet;
|
bool curColorSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -219,10 +219,10 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
|
||||||
}
|
}
|
||||||
} else if (style->fill.paint.curColor) {
|
} else if (style->fill.paint.curColor) {
|
||||||
//Apply the current style color
|
//Apply the current style color
|
||||||
vg->fill(style->r, style->g, style->b, style->fill.opacity);
|
vg->fill(style->color.r, style->color.g, style->color.b, style->fill.opacity);
|
||||||
} else {
|
} else {
|
||||||
//Apply the fill color
|
//Apply the fill color
|
||||||
vg->fill(style->fill.paint.r, style->fill.paint.g, style->fill.paint.b, style->fill.opacity);
|
vg->fill(style->fill.paint.color.r, style->fill.paint.color.g, style->fill.paint.color.b, style->fill.opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Apply the fill rule
|
//Apply the fill rule
|
||||||
|
@ -258,10 +258,10 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
|
||||||
//TODO: Apply the color pointed by url
|
//TODO: Apply the color pointed by url
|
||||||
} else if (style->stroke.paint.curColor) {
|
} else if (style->stroke.paint.curColor) {
|
||||||
//Apply the current style color
|
//Apply the current style color
|
||||||
vg->stroke(style->r, style->g, style->b, style->stroke.opacity);
|
vg->stroke(style->color.r, style->color.g, style->color.b, style->stroke.opacity);
|
||||||
} else {
|
} else {
|
||||||
//Apply the stroke color
|
//Apply the stroke color
|
||||||
vg->stroke(style->stroke.paint.r, style->stroke.paint.g, style->stroke.paint.b, style->stroke.opacity);
|
vg->stroke(style->stroke.paint.color.r, style->stroke.paint.color.g, style->stroke.paint.color.b, style->stroke.opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyComposition(vg, node, vx, vy, vw, vh);
|
_applyComposition(vg, node, vx, vy, vw, vh);
|
||||||
|
|
Loading…
Add table
Reference in a new issue