mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-17 13:34:57 +00:00
svg_loader: code refactoring
keep clean & neat code. Change-Id: Ia17139a291fc9934fe2f8d5e51417c44ec50f2ed
This commit is contained in:
parent
33b067eb0a
commit
231b3779b1
1 changed files with 19 additions and 20 deletions
|
@ -118,14 +118,14 @@ unique_ptr<LinearGradient> _applyLinearGradientProperty(SvgStyleGradient* g, Sha
|
||||||
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
|
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
|
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
|
||||||
for (vector<Fill::ColorStop*>::iterator itrStop = g->stops.begin(); itrStop != g->stops.end(); itrStop++) {
|
for (auto colorStop : g->stops) {
|
||||||
//Use premultiplied color
|
//Use premultiplied color
|
||||||
opacity = ((float)(*itrStop)->a / 255) * fopacity;
|
opacity = ((float)colorStop->a / 255.0f) * fopacity;
|
||||||
stops[i].r = ((*itrStop)->r * opacity);
|
stops[i].r = colorStop->r * opacity;
|
||||||
stops[i].g = ((*itrStop)->g * opacity);
|
stops[i].g = colorStop->g * opacity;
|
||||||
stops[i].b = ((*itrStop)->b * opacity);
|
stops[i].b = colorStop->b * opacity;
|
||||||
stops[i].a = ((*itrStop)->a * fopacity);
|
stops[i].a = colorStop->a * fopacity;
|
||||||
stops[i].offset = (*itrStop)->offset;
|
stops[i].offset = colorStop->offset;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
fillGrad->colorStops(stops, stopCount);
|
fillGrad->colorStops(stops, stopCount);
|
||||||
|
@ -204,14 +204,14 @@ unique_ptr<RadialGradient> _applyRadialGradientProperty(SvgStyleGradient* g, Sha
|
||||||
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
|
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
|
||||||
int i = 0;
|
int i = 0;
|
||||||
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
|
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
|
||||||
for (vector<Fill::ColorStop*>::iterator itrStop = g->stops.begin(); itrStop != g->stops.end(); itrStop++) {
|
for (auto colorStop : g->stops) {
|
||||||
//Use premultiplied color
|
//Use premultiplied color
|
||||||
opacity = ((float)(*itrStop)->a / 255) * fopacity;
|
opacity = ((float)colorStop->a / 255.0f) * fopacity;
|
||||||
stops[i].r = ((*itrStop)->r * opacity);
|
stops[i].r = colorStop->r * opacity;
|
||||||
stops[i].g = ((*itrStop)->g * opacity);
|
stops[i].g = colorStop->g * opacity;
|
||||||
stops[i].b = ((*itrStop)->b * opacity);
|
stops[i].b = colorStop->b * opacity;
|
||||||
stops[i].a = ((*itrStop)->a * fopacity);
|
stops[i].a = colorStop->a * fopacity;
|
||||||
stops[i].offset = (*itrStop)->offset;
|
stops[i].offset = colorStop->offset;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
fillGrad->colorStops(stops, stopCount);
|
fillGrad->colorStops(stops, stopCount);
|
||||||
|
@ -366,12 +366,11 @@ unique_ptr<Scene> _sceneBuildHelper(SvgNode* node, float vx, float vy, float vw,
|
||||||
if (!(fmod(fabsf(z), 360.0) <= FLT_EPSILON)) scene->rotate(fmod(z, 360.0));
|
if (!(fmod(fabsf(z), 360.0) <= FLT_EPSILON)) scene->rotate(fmod(z, 360.0));
|
||||||
if (!(fabsf(tx) <= FLT_EPSILON) && !(fabsf(ty) <= FLT_EPSILON)) scene->translate(tx, ty);
|
if (!(fabsf(tx) <= FLT_EPSILON) && !(fabsf(ty) <= FLT_EPSILON)) scene->translate(tx, ty);
|
||||||
}
|
}
|
||||||
node->style->opacity = (node->style->opacity * parentOpacity) / 255;
|
node->style->opacity = (node->style->opacity * parentOpacity) / 255.0f;
|
||||||
for (vector<SvgNode*>::iterator itrChild = node->child.begin(); itrChild != node->child.end(); itrChild++) {
|
for (auto child : node->child) {
|
||||||
SvgNode* child = *itrChild;
|
child->style->opacity = (child->style->opacity * node->style->opacity) / 255.0f;
|
||||||
child->style->opacity = (child->style->opacity * node->style->opacity) / 255;
|
if (child->type == SvgNodeType::Doc || child->type == SvgNodeType::G) scene->push(_sceneBuildHelper(child, vx, vy, vw, vh, node->style->opacity));
|
||||||
if (child->type == SvgNodeType::Doc || child->type == SvgNodeType::G) scene->push(_sceneBuildHelper(*itrChild, vx, vy, vw, vh, node->style->opacity));
|
else scene->push(_shapeBuildHelper(child, vx, vy, vw, vh));
|
||||||
else scene->push(_shapeBuildHelper(*itrChild, vx, vy, vw, vh));
|
|
||||||
}
|
}
|
||||||
return move(scene);
|
return move(scene);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue