mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
loader svg: ++code readability
Use own bit operation helpers.
This commit is contained in:
parent
8a67bff7c9
commit
1e370712e0
4 changed files with 178 additions and 118 deletions
|
@ -32,13 +32,13 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
{
|
{
|
||||||
if (from == nullptr) return;
|
if (from == nullptr) return;
|
||||||
//Copy the properties of 'from' only if they were explicitly set (not the default ones).
|
//Copy the properties of 'from' only if they were explicitly set (not the default ones).
|
||||||
if (from->curColorSet && !((int)to->flags & (int)SvgStyleFlags::Color)) {
|
if (from->curColorSet && !(to->flags & SvgStyleFlags::Color)) {
|
||||||
to->color = from->color;
|
to->color = from->color;
|
||||||
to->curColorSet = true;
|
to->curColorSet = true;
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::Color);
|
to->flags = (to->flags | SvgStyleFlags::Color);
|
||||||
}
|
}
|
||||||
//Fill
|
//Fill
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::Paint) && !((int)to->flags & (int)SvgStyleFlags::Fill)) {
|
if ((from->fill.flags & SvgFillFlags::Paint) && !(to->flags & SvgStyleFlags::Fill)) {
|
||||||
to->fill.paint.color = from->fill.paint.color;
|
to->fill.paint.color = from->fill.paint.color;
|
||||||
to->fill.paint.none = from->fill.paint.none;
|
to->fill.paint.none = from->fill.paint.none;
|
||||||
to->fill.paint.curColor = from->fill.paint.curColor;
|
to->fill.paint.curColor = from->fill.paint.curColor;
|
||||||
|
@ -46,21 +46,21 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
if (to->fill.paint.url) free(to->fill.paint.url);
|
if (to->fill.paint.url) free(to->fill.paint.url);
|
||||||
to->fill.paint.url = strdup(from->fill.paint.url);
|
to->fill.paint.url = strdup(from->fill.paint.url);
|
||||||
}
|
}
|
||||||
to->fill.flags = (SvgFillFlags)((int)to->fill.flags | (int)SvgFillFlags::Paint);
|
to->fill.flags = (to->fill.flags | SvgFillFlags::Paint);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::Fill);
|
to->flags = (to->flags | SvgStyleFlags::Fill);
|
||||||
}
|
}
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::Opacity) && !((int)to->flags & (int)SvgStyleFlags::FillOpacity)) {
|
if ((from->fill.flags & SvgFillFlags::Opacity) && !(to->flags & SvgStyleFlags::FillOpacity)) {
|
||||||
to->fill.opacity = from->fill.opacity;
|
to->fill.opacity = from->fill.opacity;
|
||||||
to->fill.flags = (SvgFillFlags)((int)to->fill.flags | (int)SvgFillFlags::Opacity);
|
to->fill.flags = (to->fill.flags | SvgFillFlags::Opacity);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::FillOpacity);
|
to->flags = (to->flags | SvgStyleFlags::FillOpacity);
|
||||||
}
|
}
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::FillRule) && !((int)to->flags & (int)SvgStyleFlags::FillRule)) {
|
if ((from->fill.flags & SvgFillFlags::FillRule) && !(to->flags & SvgStyleFlags::FillRule)) {
|
||||||
to->fill.fillRule = from->fill.fillRule;
|
to->fill.fillRule = from->fill.fillRule;
|
||||||
to->fill.flags = (SvgFillFlags)((int)to->fill.flags | (int)SvgFillFlags::FillRule);
|
to->fill.flags = (to->fill.flags | SvgFillFlags::FillRule);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::FillRule);
|
to->flags = (to->flags | SvgStyleFlags::FillRule);
|
||||||
}
|
}
|
||||||
//Stroke
|
//Stroke
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Paint) && !((int)to->flags & (int)SvgStyleFlags::Stroke)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Paint) && !(to->flags & SvgStyleFlags::Stroke)) {
|
||||||
to->stroke.paint.color = from->stroke.paint.color;
|
to->stroke.paint.color = from->stroke.paint.color;
|
||||||
to->stroke.paint.none = from->stroke.paint.none;
|
to->stroke.paint.none = from->stroke.paint.none;
|
||||||
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
||||||
|
@ -68,45 +68,45 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
if (to->stroke.paint.url) free(to->stroke.paint.url);
|
if (to->stroke.paint.url) free(to->stroke.paint.url);
|
||||||
to->stroke.paint.url = strdup(from->stroke.paint.url);
|
to->stroke.paint.url = strdup(from->stroke.paint.url);
|
||||||
}
|
}
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Paint);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Paint);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::Stroke);
|
to->flags = (to->flags | SvgStyleFlags::Stroke);
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Opacity) && !((int)to->flags & (int)SvgStyleFlags::StrokeOpacity)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Opacity) && !(to->flags & SvgStyleFlags::StrokeOpacity)) {
|
||||||
to->stroke.opacity = from->stroke.opacity;
|
to->stroke.opacity = from->stroke.opacity;
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Opacity);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Opacity);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::StrokeOpacity);
|
to->flags = (to->flags | SvgStyleFlags::StrokeOpacity);
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Width) && !((int)to->flags & (int)SvgStyleFlags::StrokeWidth)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Width) && !(to->flags & SvgStyleFlags::StrokeWidth)) {
|
||||||
to->stroke.width = from->stroke.width;
|
to->stroke.width = from->stroke.width;
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Width);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Width);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::StrokeWidth);
|
to->flags = (to->flags | SvgStyleFlags::StrokeWidth);
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Dash) && !((int)to->flags & (int)SvgStyleFlags::StrokeDashArray)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Dash) && !(to->flags & SvgStyleFlags::StrokeDashArray)) {
|
||||||
if (from->stroke.dash.array.count > 0) {
|
if (from->stroke.dash.array.count > 0) {
|
||||||
to->stroke.dash.array.clear();
|
to->stroke.dash.array.clear();
|
||||||
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
||||||
for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) {
|
for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) {
|
||||||
to->stroke.dash.array.push(from->stroke.dash.array.data[i]);
|
to->stroke.dash.array.push(from->stroke.dash.array.data[i]);
|
||||||
}
|
}
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Dash);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Dash);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::StrokeDashArray);
|
to->flags = (to->flags | SvgStyleFlags::StrokeDashArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Cap) && !((int)to->flags & (int)SvgStyleFlags::StrokeLineCap)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Cap) && !(to->flags & SvgStyleFlags::StrokeLineCap)) {
|
||||||
to->stroke.cap = from->stroke.cap;
|
to->stroke.cap = from->stroke.cap;
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Cap);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Cap);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::StrokeLineCap);
|
to->flags = (to->flags | SvgStyleFlags::StrokeLineCap);
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Join) && !((int)to->flags & (int)SvgStyleFlags::StrokeLineJoin)) {
|
if ((from->stroke.flags & SvgStrokeFlags::Join) && !(to->flags & SvgStyleFlags::StrokeLineJoin)) {
|
||||||
to->stroke.join = from->stroke.join;
|
to->stroke.join = from->stroke.join;
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)SvgStrokeFlags::Join);
|
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Join);
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::StrokeLineJoin);
|
to->flags = (to->flags | SvgStyleFlags::StrokeLineJoin);
|
||||||
}
|
}
|
||||||
//Opacity
|
//Opacity
|
||||||
//TODO: it can be set to be 255 and shouldn't be changed by attribute 'opacity'
|
//TODO: it can be set to be 255 and shouldn't be changed by attribute 'opacity'
|
||||||
if (from->opacity < 255 && !((int)to->flags & (int)SvgStyleFlags::Opacity)) {
|
if (from->opacity < 255 && !(to->flags & SvgStyleFlags::Opacity)) {
|
||||||
to->opacity = from->opacity;
|
to->opacity = from->opacity;
|
||||||
to->flags = (SvgStyleFlags)((int)to->flags | (int)SvgStyleFlags::Opacity);
|
to->flags = (to->flags | SvgStyleFlags::Opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +118,11 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
|
void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
|
||||||
{
|
{
|
||||||
//Copy matrix attribute
|
//Copy matrix attribute
|
||||||
if (from->transform && !((int)to->style->flags & (int)SvgStyleFlags::Transform)) {
|
if (from->transform && !(to->style->flags & SvgStyleFlags::Transform)) {
|
||||||
to->transform = (Matrix*)malloc(sizeof(Matrix));
|
to->transform = (Matrix*)malloc(sizeof(Matrix));
|
||||||
if (to->transform) {
|
if (to->transform) {
|
||||||
*to->transform = *from->transform;
|
*to->transform = *from->transform;
|
||||||
to->style->flags = (SvgStyleFlags)((int)to->style->flags | (int)SvgStyleFlags::Transform);
|
to->style->flags = (to->style->flags | SvgStyleFlags::Transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Copy style attribute
|
//Copy style attribute
|
||||||
|
|
|
@ -861,16 +861,16 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
|
||||||
|
|
||||||
if (!strcmp(key, "width")) {
|
if (!strcmp(key, "width")) {
|
||||||
doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
|
doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
|
||||||
doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag | (uint32_t)SvgViewFlag::Width);
|
doc->viewFlag = (doc->viewFlag | SvgViewFlag::Width);
|
||||||
} else if (!strcmp(key, "height")) {
|
} else if (!strcmp(key, "height")) {
|
||||||
doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical);
|
doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical);
|
||||||
doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag | (uint32_t)SvgViewFlag::Height);
|
doc->viewFlag = (doc->viewFlag | SvgViewFlag::Height);
|
||||||
} else if (!strcmp(key, "viewBox")) {
|
} else if (!strcmp(key, "viewBox")) {
|
||||||
if (_parseNumber(&value, &doc->vx)) {
|
if (_parseNumber(&value, &doc->vx)) {
|
||||||
if (_parseNumber(&value, &doc->vy)) {
|
if (_parseNumber(&value, &doc->vy)) {
|
||||||
if (_parseNumber(&value, &doc->vw)) {
|
if (_parseNumber(&value, &doc->vw)) {
|
||||||
if (_parseNumber(&value, &doc->vh)) {
|
if (_parseNumber(&value, &doc->vh)) {
|
||||||
doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag | (uint32_t)SvgViewFlag::Viewbox);
|
doc->viewFlag = (doc->viewFlag | SvgViewFlag::Viewbox);
|
||||||
loader->svgParse->global.h = doc->vh;
|
loader->svgParse->global.h = doc->vh;
|
||||||
}
|
}
|
||||||
loader->svgParse->global.w = doc->vw;
|
loader->svgParse->global.w = doc->vw;
|
||||||
|
@ -879,11 +879,11 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
|
||||||
}
|
}
|
||||||
loader->svgParse->global.x = doc->vx;
|
loader->svgParse->global.x = doc->vx;
|
||||||
}
|
}
|
||||||
if (((uint32_t)doc->viewFlag & (uint32_t)SvgViewFlag::Viewbox) && (doc->vw < 0.0f || doc->vh < 0.0f)) {
|
if ((doc->viewFlag & SvgViewFlag::Viewbox) && (doc->vw < 0.0f || doc->vh < 0.0f)) {
|
||||||
doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag & ~(uint32_t)SvgViewFlag::Viewbox);
|
doc->viewFlag = (SvgViewFlag)((uint32_t)doc->viewFlag & ~(uint32_t)SvgViewFlag::Viewbox);
|
||||||
TVGLOG("SVG", "Negative values of the <viewBox> width and/or height - the attribute invalidated.");
|
TVGLOG("SVG", "Negative values of the <viewBox> width and/or height - the attribute invalidated.");
|
||||||
}
|
}
|
||||||
if (!((uint32_t)doc->viewFlag & (uint32_t)SvgViewFlag::Viewbox)) {
|
if (!(doc->viewFlag & SvgViewFlag::Viewbox)) {
|
||||||
loader->svgParse->global.x = loader->svgParse->global.y = 0.0f;
|
loader->svgParse->global.x = loader->svgParse->global.y = 0.0f;
|
||||||
loader->svgParse->global.w = loader->svgParse->global.h = 1.0f;
|
loader->svgParse->global.w = loader->svgParse->global.h = 1.0f;
|
||||||
}
|
}
|
||||||
|
@ -930,7 +930,7 @@ static void _handleColorAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, co
|
||||||
static void _handleFillAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleFillAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
style->fill.flags = (SvgFillFlags)((int)style->fill.flags | (int)SvgFillFlags::Paint);
|
style->fill.flags = (style->fill.flags | SvgFillFlags::Paint);
|
||||||
_handlePaintAttr(&style->fill.paint, value);
|
_handlePaintAttr(&style->fill.paint, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -938,47 +938,47 @@ static void _handleFillAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, con
|
||||||
static void _handleStrokeAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
SvgStyleProperty* style = node->style;
|
SvgStyleProperty* style = node->style;
|
||||||
style->stroke.flags = (SvgStrokeFlags)((int)style->stroke.flags | (int)SvgStrokeFlags::Paint);
|
style->stroke.flags = (style->stroke.flags | SvgStrokeFlags::Paint);
|
||||||
_handlePaintAttr(&style->stroke.paint, value);
|
_handlePaintAttr(&style->stroke.paint, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _handleStrokeOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->stroke.flags = (SvgStrokeFlags)((int)node->style->stroke.flags | (int)SvgStrokeFlags::Opacity);
|
node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Opacity);
|
||||||
node->style->stroke.opacity = _toOpacity(value);
|
node->style->stroke.opacity = _toOpacity(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _handleStrokeDashArrayAttr(SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeDashArrayAttr(SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->stroke.flags = (SvgStrokeFlags)((int)node->style->stroke.flags | (int)SvgStrokeFlags::Dash);
|
node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Dash);
|
||||||
_parseDashArray(loader, value, &node->style->stroke.dash);
|
_parseDashArray(loader, value, &node->style->stroke.dash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _handleStrokeWidthAttr(SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeWidthAttr(SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->stroke.flags = (SvgStrokeFlags)((int)node->style->stroke.flags | (int)SvgStrokeFlags::Width);
|
node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Width);
|
||||||
node->style->stroke.width = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
|
node->style->stroke.width = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _handleStrokeLineCapAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeLineCapAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->stroke.flags = (SvgStrokeFlags)((int)node->style->stroke.flags | (int)SvgStrokeFlags::Cap);
|
node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Cap);
|
||||||
node->style->stroke.cap = _toLineCap(value);
|
node->style->stroke.cap = _toLineCap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _handleStrokeLineJoinAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleStrokeLineJoinAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->stroke.flags = (SvgStrokeFlags)((int)node->style->stroke.flags | (int)SvgStrokeFlags::Join);
|
node->style->stroke.flags = (node->style->stroke.flags | SvgStrokeFlags::Join);
|
||||||
node->style->stroke.join = _toLineJoin(value);
|
node->style->stroke.join = _toLineJoin(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _handleFillRuleAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleFillRuleAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->fill.flags = (SvgFillFlags)((int)node->style->fill.flags | (int)SvgFillFlags::FillRule);
|
node->style->fill.flags = (node->style->fill.flags | SvgFillFlags::FillRule);
|
||||||
node->style->fill.fillRule = _toFillRule(value);
|
node->style->fill.fillRule = _toFillRule(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,7 +991,7 @@ static void _handleOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node,
|
||||||
|
|
||||||
static void _handleFillOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handleFillOpacityAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->fill.flags = (SvgFillFlags)((int)node->style->fill.flags | (int)SvgFillFlags::Opacity);
|
node->style->fill.flags = (node->style->fill.flags | SvgFillFlags::Opacity);
|
||||||
node->style->fill.opacity = _toOpacity(value);
|
node->style->fill.opacity = _toOpacity(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,7 +1043,7 @@ static void _handleDisplayAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node,
|
||||||
|
|
||||||
static void _handlePaintOrderAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
static void _handlePaintOrderAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value)
|
||||||
{
|
{
|
||||||
node->style->flags = (SvgStyleFlags)((int)node->style->flags | (int)SvgStyleFlags::PaintOrder);
|
node->style->flags = (node->style->flags | SvgStyleFlags::PaintOrder);
|
||||||
node->style->paintOrder = _toPaintOrder(value);
|
node->style->paintOrder = _toPaintOrder(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1119,8 +1119,8 @@ static bool _parseStyleAttr(void* data, const char* key, const char* value, bool
|
||||||
if (styleTags[i].sz - 1 == sz && !strncmp(styleTags[i].tag, key, sz)) {
|
if (styleTags[i].sz - 1 == sz && !strncmp(styleTags[i].tag, key, sz)) {
|
||||||
if (style) {
|
if (style) {
|
||||||
styleTags[i].tagHandler(loader, node, value);
|
styleTags[i].tagHandler(loader, node, value);
|
||||||
node->style->flags = (SvgStyleFlags)((int)node->style->flags | (int)styleTags[i].flag);
|
node->style->flags = (node->style->flags | styleTags[i].flag);
|
||||||
} else if (!((int)node->style->flags & (int)styleTags[i].flag)) {
|
} else if (!(node->style->flags & styleTags[i].flag)) {
|
||||||
styleTags[i].tagHandler(loader, node, value);
|
styleTags[i].tagHandler(loader, node, value);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1349,11 +1349,11 @@ static SvgNode* _createSvgNode(SvgLoaderData* loader, SvgNode* parent, const cha
|
||||||
doc->viewFlag = SvgViewFlag::None;
|
doc->viewFlag = SvgViewFlag::None;
|
||||||
func(buf, bufLength, _attrParseSvgNode, loader);
|
func(buf, bufLength, _attrParseSvgNode, loader);
|
||||||
|
|
||||||
if (!((uint32_t)doc->viewFlag & (uint32_t)SvgViewFlag::Viewbox)) {
|
if (!(doc->viewFlag & SvgViewFlag::Viewbox)) {
|
||||||
if ((uint32_t)doc->viewFlag & (uint32_t)SvgViewFlag::Width) {
|
if (doc->viewFlag & SvgViewFlag::Width) {
|
||||||
loader->svgParse->global.w = doc->w;
|
loader->svgParse->global.w = doc->w;
|
||||||
}
|
}
|
||||||
if ((uint32_t)doc->viewFlag & (uint32_t)SvgViewFlag::Height) {
|
if (doc->viewFlag & SvgViewFlag::Height) {
|
||||||
loader->svgParse->global.h = doc->h;
|
loader->svgParse->global.h = doc->h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2176,7 +2176,7 @@ static void _inheritRadialCxAttr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->radial->cx = from->radial->cx;
|
to->radial->cx = from->radial->cx;
|
||||||
to->radial->isCxPercentage = from->radial->isCxPercentage;
|
to->radial->isCxPercentage = from->radial->isCxPercentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Cx);
|
to->flags = (to->flags | SvgGradientFlags::Cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2184,7 +2184,7 @@ static void _inheritRadialCyAttr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->radial->cy = from->radial->cy;
|
to->radial->cy = from->radial->cy;
|
||||||
to->radial->isCyPercentage = from->radial->isCyPercentage;
|
to->radial->isCyPercentage = from->radial->isCyPercentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Cy);
|
to->flags = (to->flags | SvgGradientFlags::Cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2192,7 +2192,7 @@ static void _inheritRadialFxAttr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->radial->fx = from->radial->fx;
|
to->radial->fx = from->radial->fx;
|
||||||
to->radial->isFxPercentage = from->radial->isFxPercentage;
|
to->radial->isFxPercentage = from->radial->isFxPercentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Fx);
|
to->flags = (to->flags | SvgGradientFlags::Fx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2200,7 +2200,7 @@ static void _inheritRadialFyAttr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->radial->fy = from->radial->fy;
|
to->radial->fy = from->radial->fy;
|
||||||
to->radial->isFyPercentage = from->radial->isFyPercentage;
|
to->radial->isFyPercentage = from->radial->isFyPercentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Fy);
|
to->flags = (to->flags | SvgGradientFlags::Fy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2208,7 +2208,7 @@ static void _inheritRadialRAttr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->radial->r = from->radial->r;
|
to->radial->r = from->radial->r;
|
||||||
to->radial->isRPercentage = from->radial->isRPercentage;
|
to->radial->isRPercentage = from->radial->isRPercentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::R);
|
to->flags = (to->flags | SvgGradientFlags::R);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2251,7 +2251,7 @@ static bool _attrParseRadialGradientNode(void* data, const char* key, const char
|
||||||
for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) {
|
for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) {
|
||||||
if (radialTags[i].sz - 1 == sz && !strncmp(radialTags[i].tag, key, sz)) {
|
if (radialTags[i].sz - 1 == sz && !strncmp(radialTags[i].tag, key, sz)) {
|
||||||
radialTags[i].tagHandler(loader, radial, value);
|
radialTags[i].tagHandler(loader, radial, value);
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)radialTags[i].flag);
|
grad->flags = (grad->flags | radialTags[i].flag);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2261,13 +2261,13 @@ static bool _attrParseRadialGradientNode(void* data, const char* key, const char
|
||||||
grad->id = _copyId(value);
|
grad->id = _copyId(value);
|
||||||
} else if (!strcmp(key, "spreadMethod")) {
|
} else if (!strcmp(key, "spreadMethod")) {
|
||||||
grad->spread = _parseSpreadValue(value);
|
grad->spread = _parseSpreadValue(value);
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)SvgGradientFlags::SpreadMethod);
|
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
||||||
} else if (!strcmp(key, "href") || !strcmp(key, "xlink:href")) {
|
} else if (!strcmp(key, "href") || !strcmp(key, "xlink:href")) {
|
||||||
if (grad->ref && value) free(grad->ref);
|
if (grad->ref && value) free(grad->ref);
|
||||||
grad->ref = _idFromHref(value);
|
grad->ref = _idFromHref(value);
|
||||||
} else if (!strcmp(key, "gradientUnits")) {
|
} else if (!strcmp(key, "gradientUnits")) {
|
||||||
if (!strcmp(value, "userSpaceOnUse")) grad->userSpace = true;
|
if (!strcmp(value, "userSpaceOnUse")) grad->userSpace = true;
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)SvgGradientFlags::GradientUnits);
|
grad->flags = (grad->flags | SvgGradientFlags::GradientUnits);
|
||||||
} else if (!strcmp(key, "gradientTransform")) {
|
} else if (!strcmp(key, "gradientTransform")) {
|
||||||
grad->transform = _parseTransformationMatrix(value);
|
grad->transform = _parseTransformationMatrix(value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2326,10 +2326,10 @@ static bool _attrParseStopsStyle(void* data, const char* key, const char* value)
|
||||||
|
|
||||||
if (!strcmp(key, "stop-opacity")) {
|
if (!strcmp(key, "stop-opacity")) {
|
||||||
stop->a = _toOpacity(value);
|
stop->a = _toOpacity(value);
|
||||||
loader->svgParse->flags = (SvgStopStyleFlags)((int)loader->svgParse->flags | (int)SvgStopStyleFlags::StopOpacity);
|
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopOpacity);
|
||||||
} else if (!strcmp(key, "stop-color")) {
|
} else if (!strcmp(key, "stop-color")) {
|
||||||
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
||||||
loader->svgParse->flags = (SvgStopStyleFlags)((int)loader->svgParse->flags | (int)SvgStopStyleFlags::StopColor);
|
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopColor);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2346,11 +2346,11 @@ static bool _attrParseStops(void* data, const char* key, const char* value)
|
||||||
if (!strcmp(key, "offset")) {
|
if (!strcmp(key, "offset")) {
|
||||||
stop->offset = _toOffset(value);
|
stop->offset = _toOffset(value);
|
||||||
} else if (!strcmp(key, "stop-opacity")) {
|
} else if (!strcmp(key, "stop-opacity")) {
|
||||||
if (!((int)loader->svgParse->flags & (int)SvgStopStyleFlags::StopOpacity)) {
|
if (!(loader->svgParse->flags & SvgStopStyleFlags::StopOpacity)) {
|
||||||
stop->a = _toOpacity(value);
|
stop->a = _toOpacity(value);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(key, "stop-color")) {
|
} else if (!strcmp(key, "stop-color")) {
|
||||||
if (!((int)loader->svgParse->flags & (int)SvgStopStyleFlags::StopColor)) {
|
if (!(loader->svgParse->flags & SvgStopStyleFlags::StopColor)) {
|
||||||
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(key, "style")) {
|
} else if (!strcmp(key, "style")) {
|
||||||
|
@ -2451,7 +2451,7 @@ static void _inheritLinearX1Attr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->linear->x1 = from->linear->x1;
|
to->linear->x1 = from->linear->x1;
|
||||||
to->linear->isX1Percentage = from->linear->isX1Percentage;
|
to->linear->isX1Percentage = from->linear->isX1Percentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::X1);
|
to->flags = (to->flags | SvgGradientFlags::X1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2459,7 +2459,7 @@ static void _inheritLinearX2Attr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->linear->x2 = from->linear->x2;
|
to->linear->x2 = from->linear->x2;
|
||||||
to->linear->isX2Percentage = from->linear->isX2Percentage;
|
to->linear->isX2Percentage = from->linear->isX2Percentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::X2);
|
to->flags = (to->flags | SvgGradientFlags::X2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2467,7 +2467,7 @@ static void _inheritLinearY1Attr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->linear->y1 = from->linear->y1;
|
to->linear->y1 = from->linear->y1;
|
||||||
to->linear->isY1Percentage = from->linear->isY1Percentage;
|
to->linear->isY1Percentage = from->linear->isY1Percentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Y1);
|
to->flags = (to->flags | SvgGradientFlags::Y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2475,7 +2475,7 @@ static void _inheritLinearY2Attr(SvgStyleGradient* to, SvgStyleGradient* from)
|
||||||
{
|
{
|
||||||
to->linear->y2 = from->linear->y2;
|
to->linear->y2 = from->linear->y2;
|
||||||
to->linear->isY2Percentage = from->linear->isY2Percentage;
|
to->linear->isY2Percentage = from->linear->isY2Percentage;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::Y2);
|
to->flags = (to->flags | SvgGradientFlags::Y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2517,7 +2517,7 @@ static bool _attrParseLinearGradientNode(void* data, const char* key, const char
|
||||||
for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) {
|
for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) {
|
||||||
if (linear_tags[i].sz - 1 == sz && !strncmp(linear_tags[i].tag, key, sz)) {
|
if (linear_tags[i].sz - 1 == sz && !strncmp(linear_tags[i].tag, key, sz)) {
|
||||||
linear_tags[i].tagHandler(loader, linear, value);
|
linear_tags[i].tagHandler(loader, linear, value);
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)linear_tags[i].flag);
|
grad->flags = (grad->flags | linear_tags[i].flag);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2527,13 +2527,13 @@ static bool _attrParseLinearGradientNode(void* data, const char* key, const char
|
||||||
grad->id = _copyId(value);
|
grad->id = _copyId(value);
|
||||||
} else if (!strcmp(key, "spreadMethod")) {
|
} else if (!strcmp(key, "spreadMethod")) {
|
||||||
grad->spread = _parseSpreadValue(value);
|
grad->spread = _parseSpreadValue(value);
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)SvgGradientFlags::SpreadMethod);
|
grad->flags = (grad->flags | SvgGradientFlags::SpreadMethod);
|
||||||
} else if (!strcmp(key, "href") || !strcmp(key, "xlink:href")) {
|
} else if (!strcmp(key, "href") || !strcmp(key, "xlink:href")) {
|
||||||
if (grad->ref && value) free(grad->ref);
|
if (grad->ref && value) free(grad->ref);
|
||||||
grad->ref = _idFromHref(value);
|
grad->ref = _idFromHref(value);
|
||||||
} else if (!strcmp(key, "gradientUnits")) {
|
} else if (!strcmp(key, "gradientUnits")) {
|
||||||
if (!strcmp(value, "userSpaceOnUse")) grad->userSpace = true;
|
if (!strcmp(value, "userSpaceOnUse")) grad->userSpace = true;
|
||||||
grad->flags = (SvgGradientFlags)((int)grad->flags | (int)SvgGradientFlags::GradientUnits);
|
grad->flags = (grad->flags | SvgGradientFlags::GradientUnits);
|
||||||
} else if (!strcmp(key, "gradientTransform")) {
|
} else if (!strcmp(key, "gradientTransform")) {
|
||||||
grad->transform = _parseTransformationMatrix(value);
|
grad->transform = _parseTransformationMatrix(value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2621,16 +2621,14 @@ static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgSty
|
||||||
{
|
{
|
||||||
if (!to || !from) return;
|
if (!to || !from) return;
|
||||||
|
|
||||||
if (!((int)to->flags & (int)SvgGradientFlags::SpreadMethod) &&
|
if (!(to->flags & SvgGradientFlags::SpreadMethod) && (from->flags & SvgGradientFlags::SpreadMethod)) {
|
||||||
((int)from->flags & (int)SvgGradientFlags::SpreadMethod)) {
|
|
||||||
to->spread = from->spread;
|
to->spread = from->spread;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::SpreadMethod);
|
to->flags = (to->flags | SvgGradientFlags::SpreadMethod);
|
||||||
}
|
}
|
||||||
bool gradUnitSet = (int)to->flags & (int)SvgGradientFlags::GradientUnits;
|
bool gradUnitSet = (to->flags & SvgGradientFlags::GradientUnits);
|
||||||
if (!((int)to->flags & (int)SvgGradientFlags::GradientUnits) &&
|
if (!(to->flags & SvgGradientFlags::GradientUnits) && (from->flags & SvgGradientFlags::GradientUnits)) {
|
||||||
((int)from->flags & (int)SvgGradientFlags::GradientUnits)) {
|
|
||||||
to->userSpace = from->userSpace;
|
to->userSpace = from->userSpace;
|
||||||
to->flags = (SvgGradientFlags)((int)to->flags | (int)SvgGradientFlags::GradientUnits);
|
to->flags = (to->flags | SvgGradientFlags::GradientUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!to->transform && from->transform) {
|
if (!to->transform && from->transform) {
|
||||||
|
@ -2640,8 +2638,8 @@ static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgSty
|
||||||
|
|
||||||
if (to->type == SvgGradientType::Linear && from->type == SvgGradientType::Linear) {
|
if (to->type == SvgGradientType::Linear && from->type == SvgGradientType::Linear) {
|
||||||
for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) {
|
for (unsigned int i = 0; i < sizeof(linear_tags) / sizeof(linear_tags[0]); i++) {
|
||||||
bool coordSet = (int)to->flags & (int)linear_tags[i].flag;
|
bool coordSet = to->flags & linear_tags[i].flag;
|
||||||
if (!((int)to->flags & (int)linear_tags[i].flag) && ((int)from->flags & (int)linear_tags[i].flag)) {
|
if (!(to->flags & linear_tags[i].flag) && (from->flags & linear_tags[i].flag)) {
|
||||||
linear_tags[i].tagInheritHandler(to, from);
|
linear_tags[i].tagInheritHandler(to, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2657,8 +2655,8 @@ static void _inheritGradient(SvgLoaderData* loader, SvgStyleGradient* to, SvgSty
|
||||||
}
|
}
|
||||||
} else if (to->type == SvgGradientType::Radial && from->type == SvgGradientType::Radial) {
|
} else if (to->type == SvgGradientType::Radial && from->type == SvgGradientType::Radial) {
|
||||||
for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) {
|
for (unsigned int i = 0; i < sizeof(radialTags) / sizeof(radialTags[0]); i++) {
|
||||||
bool coordSet = (int)to->flags & (int)radialTags[i].flag;
|
bool coordSet = (to->flags & radialTags[i].flag);
|
||||||
if (!((int)to->flags & (int)radialTags[i].flag) && ((int)from->flags & (int)radialTags[i].flag)) {
|
if (!(to->flags & radialTags[i].flag) && (from->flags & radialTags[i].flag)) {
|
||||||
radialTags[i].tagInheritHandler(to, from);
|
radialTags[i].tagInheritHandler(to, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2728,11 +2726,11 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
child->color = parent->color;
|
child->color = parent->color;
|
||||||
child->curColorSet = parent->curColorSet;
|
child->curColorSet = parent->curColorSet;
|
||||||
}
|
}
|
||||||
if (!((int)child->flags & (int)SvgStyleFlags::PaintOrder)) {
|
if (!(child->flags & SvgStyleFlags::PaintOrder)) {
|
||||||
child->paintOrder = parent->paintOrder;
|
child->paintOrder = parent->paintOrder;
|
||||||
}
|
}
|
||||||
//Fill
|
//Fill
|
||||||
if (!((int)child->fill.flags & (int)SvgFillFlags::Paint)) {
|
if (!(child->fill.flags & SvgFillFlags::Paint)) {
|
||||||
child->fill.paint.color = parent->fill.paint.color;
|
child->fill.paint.color = parent->fill.paint.color;
|
||||||
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;
|
||||||
|
@ -2741,14 +2739,14 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
child->fill.paint.url = _copyId(parent->fill.paint.url);
|
child->fill.paint.url = _copyId(parent->fill.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!((int)child->fill.flags & (int)SvgFillFlags::Opacity)) {
|
if (!(child->fill.flags & SvgFillFlags::Opacity)) {
|
||||||
child->fill.opacity = parent->fill.opacity;
|
child->fill.opacity = parent->fill.opacity;
|
||||||
}
|
}
|
||||||
if (!((int)child->fill.flags & (int)SvgFillFlags::FillRule)) {
|
if (!(child->fill.flags & SvgFillFlags::FillRule)) {
|
||||||
child->fill.fillRule = parent->fill.fillRule;
|
child->fill.fillRule = parent->fill.fillRule;
|
||||||
}
|
}
|
||||||
//Stroke
|
//Stroke
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Paint)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Paint)) {
|
||||||
child->stroke.paint.color = parent->stroke.paint.color;
|
child->stroke.paint.color = parent->stroke.paint.color;
|
||||||
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;
|
||||||
|
@ -2757,13 +2755,13 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
child->stroke.paint.url = _copyId(parent->stroke.paint.url);
|
child->stroke.paint.url = _copyId(parent->stroke.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Opacity)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Opacity)) {
|
||||||
child->stroke.opacity = parent->stroke.opacity;
|
child->stroke.opacity = parent->stroke.opacity;
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Width)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Width)) {
|
||||||
child->stroke.width = parent->stroke.width;
|
child->stroke.width = parent->stroke.width;
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Dash)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Dash)) {
|
||||||
if (parent->stroke.dash.array.count > 0) {
|
if (parent->stroke.dash.array.count > 0) {
|
||||||
child->stroke.dash.array.clear();
|
child->stroke.dash.array.clear();
|
||||||
child->stroke.dash.array.reserve(parent->stroke.dash.array.count);
|
child->stroke.dash.array.reserve(parent->stroke.dash.array.count);
|
||||||
|
@ -2772,10 +2770,10 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Cap)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Cap)) {
|
||||||
child->stroke.cap = parent->stroke.cap;
|
child->stroke.cap = parent->stroke.cap;
|
||||||
}
|
}
|
||||||
if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Join)) {
|
if (!(child->stroke.flags & SvgStrokeFlags::Join)) {
|
||||||
child->stroke.join = parent->stroke.join;
|
child->stroke.join = parent->stroke.join;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2789,12 +2787,12 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->color = from->color;
|
to->color = from->color;
|
||||||
to->curColorSet = true;
|
to->curColorSet = true;
|
||||||
}
|
}
|
||||||
if (((int)from->flags & (int)SvgStyleFlags::PaintOrder)) {
|
if (from->flags & SvgStyleFlags::PaintOrder) {
|
||||||
to->paintOrder = from->paintOrder;
|
to->paintOrder = from->paintOrder;
|
||||||
}
|
}
|
||||||
//Fill
|
//Fill
|
||||||
to->fill.flags = (SvgFillFlags)((int)to->fill.flags | (int)from->fill.flags);
|
to->fill.flags = (to->fill.flags | from->fill.flags);
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::Paint)) {
|
if (from->fill.flags & SvgFillFlags::Paint) {
|
||||||
to->fill.paint.color = from->fill.paint.color;
|
to->fill.paint.color = from->fill.paint.color;
|
||||||
to->fill.paint.none = from->fill.paint.none;
|
to->fill.paint.none = from->fill.paint.none;
|
||||||
to->fill.paint.curColor = from->fill.paint.curColor;
|
to->fill.paint.curColor = from->fill.paint.curColor;
|
||||||
|
@ -2803,15 +2801,15 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->fill.paint.url = _copyId(from->fill.paint.url);
|
to->fill.paint.url = _copyId(from->fill.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::Opacity)) {
|
if (from->fill.flags & SvgFillFlags::Opacity) {
|
||||||
to->fill.opacity = from->fill.opacity;
|
to->fill.opacity = from->fill.opacity;
|
||||||
}
|
}
|
||||||
if (((int)from->fill.flags & (int)SvgFillFlags::FillRule)) {
|
if (from->fill.flags & SvgFillFlags::FillRule) {
|
||||||
to->fill.fillRule = from->fill.fillRule;
|
to->fill.fillRule = from->fill.fillRule;
|
||||||
}
|
}
|
||||||
//Stroke
|
//Stroke
|
||||||
to->stroke.flags = (SvgStrokeFlags)((int)to->stroke.flags | (int)from->stroke.flags);
|
to->stroke.flags = (to->stroke.flags | from->stroke.flags);
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Paint)) {
|
if (from->stroke.flags & SvgStrokeFlags::Paint) {
|
||||||
to->stroke.paint.color = from->stroke.paint.color;
|
to->stroke.paint.color = from->stroke.paint.color;
|
||||||
to->stroke.paint.none = from->stroke.paint.none;
|
to->stroke.paint.none = from->stroke.paint.none;
|
||||||
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
to->stroke.paint.curColor = from->stroke.paint.curColor;
|
||||||
|
@ -2820,13 +2818,13 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
to->stroke.paint.url = _copyId(from->stroke.paint.url);
|
to->stroke.paint.url = _copyId(from->stroke.paint.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Opacity)) {
|
if (from->stroke.flags & SvgStrokeFlags::Opacity) {
|
||||||
to->stroke.opacity = from->stroke.opacity;
|
to->stroke.opacity = from->stroke.opacity;
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Width)) {
|
if (from->stroke.flags & SvgStrokeFlags::Width) {
|
||||||
to->stroke.width = from->stroke.width;
|
to->stroke.width = from->stroke.width;
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Dash)) {
|
if (from->stroke.flags & SvgStrokeFlags::Dash) {
|
||||||
if (from->stroke.dash.array.count > 0) {
|
if (from->stroke.dash.array.count > 0) {
|
||||||
to->stroke.dash.array.clear();
|
to->stroke.dash.array.clear();
|
||||||
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
||||||
|
@ -2835,10 +2833,10 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Cap)) {
|
if (from->stroke.flags & SvgStrokeFlags::Cap) {
|
||||||
to->stroke.cap = from->stroke.cap;
|
to->stroke.cap = from->stroke.cap;
|
||||||
}
|
}
|
||||||
if (((int)from->stroke.flags & (int)SvgStrokeFlags::Join)) {
|
if (from->stroke.flags & SvgStrokeFlags::Join) {
|
||||||
to->stroke.join = from->stroke.join;
|
to->stroke.join = from->stroke.join;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2853,7 +2851,7 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
}
|
}
|
||||||
//Copy style attribute
|
//Copy style attribute
|
||||||
_styleCopy(to->style, from->style);
|
_styleCopy(to->style, from->style);
|
||||||
to->style->flags = (SvgStyleFlags)((int)to->style->flags | (int)from->style->flags);
|
to->style->flags = (to->style->flags | from->style->flags);
|
||||||
if (from->style->clipPath.url) {
|
if (from->style->clipPath.url) {
|
||||||
if (to->style->clipPath.url) free(to->style->clipPath.url);
|
if (to->style->clipPath.url) free(to->style->clipPath.url);
|
||||||
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
||||||
|
@ -3519,21 +3517,21 @@ bool SvgLoader::header()
|
||||||
h = 1.0f;
|
h = 1.0f;
|
||||||
|
|
||||||
//Return the brief resource info such as viewbox:
|
//Return the brief resource info such as viewbox:
|
||||||
if ((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width) {
|
if (viewFlag & SvgViewFlag::Width) {
|
||||||
w = loaderData.doc->node.doc.w;
|
w = loaderData.doc->node.doc.w;
|
||||||
}
|
}
|
||||||
if ((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height) {
|
if (viewFlag & SvgViewFlag::Height) {
|
||||||
h = loaderData.doc->node.doc.h;
|
h = loaderData.doc->node.doc.h;
|
||||||
}
|
}
|
||||||
//Override size
|
//Override size
|
||||||
if ((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox) {
|
if (viewFlag & SvgViewFlag::Viewbox) {
|
||||||
vx = loaderData.doc->node.doc.vx;
|
vx = loaderData.doc->node.doc.vx;
|
||||||
vy = loaderData.doc->node.doc.vy;
|
vy = loaderData.doc->node.doc.vy;
|
||||||
vw = loaderData.doc->node.doc.vw;
|
vw = loaderData.doc->node.doc.vw;
|
||||||
vh = loaderData.doc->node.doc.vh;
|
vh = loaderData.doc->node.doc.vh;
|
||||||
|
|
||||||
if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width)) w = vw;
|
if (!(viewFlag & SvgViewFlag::Width)) w = vw;
|
||||||
if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height)) h = vh;
|
if (!(viewFlag & SvgViewFlag::Height)) h = vh;
|
||||||
} else {
|
} else {
|
||||||
vw = w;
|
vw = w;
|
||||||
vh = h;
|
vh = h;
|
||||||
|
@ -3603,8 +3601,7 @@ bool SvgLoader::read()
|
||||||
{
|
{
|
||||||
if (!content || size == 0) return false;
|
if (!content || size == 0) return false;
|
||||||
|
|
||||||
if (((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox) &&
|
if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vw) <= FLT_EPSILON || fabsf(vh) <= FLT_EPSILON)) {
|
||||||
(fabsf(vw) <= FLT_EPSILON || fabsf(vh) <= FLT_EPSILON)) {
|
|
||||||
TVGLOG("SVG", "The <viewBox> width and/or height set to 0 - rendering disabled.");
|
TVGLOG("SVG", "The <viewBox> width and/or height set to 0 - rendering disabled.");
|
||||||
renderingDisabled = true;
|
renderingDisabled = true;
|
||||||
}
|
}
|
||||||
|
@ -3613,9 +3610,9 @@ bool SvgLoader::read()
|
||||||
|
|
||||||
//In case no viewbox and width/height data is provided the completion of loading
|
//In case no viewbox and width/height data is provided the completion of loading
|
||||||
//has to be forced, in order to establish this data based on the whole picture bounding box.
|
//has to be forced, in order to establish this data based on the whole picture bounding box.
|
||||||
if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox) &&
|
if (!(viewFlag & SvgViewFlag::Viewbox) && (!(viewFlag & SvgViewFlag::Width) || !(viewFlag & SvgViewFlag::Height))) {
|
||||||
(!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width) || !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height)))
|
|
||||||
this->done();
|
this->done();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,16 @@ enum class SvgFillFlags
|
||||||
ClipPath = 0x16
|
ClipPath = 0x16
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgFillFlags a, SvgFillFlags b)
|
||||||
|
{
|
||||||
|
return int(a) & int(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgFillFlags operator |(SvgFillFlags a, SvgFillFlags b)
|
||||||
|
{
|
||||||
|
return SvgFillFlags(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
enum class SvgStrokeFlags
|
enum class SvgStrokeFlags
|
||||||
{
|
{
|
||||||
Paint = 0x1,
|
Paint = 0x1,
|
||||||
|
@ -92,6 +102,17 @@ enum class SvgStrokeFlags
|
||||||
Dash = 0x80,
|
Dash = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgStrokeFlags a, SvgStrokeFlags b)
|
||||||
|
{
|
||||||
|
return int(a) & int(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgStrokeFlags operator |(SvgStrokeFlags a, SvgStrokeFlags b)
|
||||||
|
{
|
||||||
|
return SvgStrokeFlags(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum class SvgGradientType
|
enum class SvgGradientType
|
||||||
{
|
{
|
||||||
Linear,
|
Linear,
|
||||||
|
@ -119,6 +140,16 @@ enum class SvgStyleFlags
|
||||||
PaintOrder = 0x10000
|
PaintOrder = 0x10000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgStyleFlags a, SvgStyleFlags b)
|
||||||
|
{
|
||||||
|
return int(a) & int(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgStyleFlags operator |(SvgStyleFlags a, SvgStyleFlags b)
|
||||||
|
{
|
||||||
|
return SvgStyleFlags(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
enum class SvgStopStyleFlags
|
enum class SvgStopStyleFlags
|
||||||
{
|
{
|
||||||
StopDefault = 0x0,
|
StopDefault = 0x0,
|
||||||
|
@ -126,6 +157,16 @@ enum class SvgStopStyleFlags
|
||||||
StopColor = 0x02
|
StopColor = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgStopStyleFlags a, SvgStopStyleFlags b)
|
||||||
|
{
|
||||||
|
return int(a) & int(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgStopStyleFlags operator |(SvgStopStyleFlags a, SvgStopStyleFlags b)
|
||||||
|
{
|
||||||
|
return SvgStopStyleFlags(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
enum class SvgGradientFlags
|
enum class SvgGradientFlags
|
||||||
{
|
{
|
||||||
None = 0x0,
|
None = 0x0,
|
||||||
|
@ -142,6 +183,16 @@ enum class SvgGradientFlags
|
||||||
Fy = 0x400
|
Fy = 0x400
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgGradientFlags a, SvgGradientFlags b)
|
||||||
|
{
|
||||||
|
return int(a) & int(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgGradientFlags operator |(SvgGradientFlags a, SvgGradientFlags b)
|
||||||
|
{
|
||||||
|
return SvgGradientFlags(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
enum class SvgFillRule
|
enum class SvgFillRule
|
||||||
{
|
{
|
||||||
Winding = 0,
|
Winding = 0,
|
||||||
|
@ -171,6 +222,16 @@ enum class SvgViewFlag
|
||||||
Viewbox = 0x04 //viewBox x,y,w,h - used only if all 4 are correctly set
|
Viewbox = 0x04 //viewBox x,y,w,h - used only if all 4 are correctly set
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr bool operator &(SvgViewFlag a, SvgViewFlag b)
|
||||||
|
{
|
||||||
|
return static_cast<int>(a) & static_cast<int>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr SvgViewFlag operator |(SvgViewFlag a, SvgViewFlag b)
|
||||||
|
{
|
||||||
|
return SvgViewFlag(int(a) | int(b));
|
||||||
|
}
|
||||||
|
|
||||||
enum class AspectRatioAlign
|
enum class AspectRatioAlign
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -450,9 +450,11 @@ enum class imageMimeTypeEncoding
|
||||||
base64 = 0x1,
|
base64 = 0x1,
|
||||||
utf8 = 0x2
|
utf8 = 0x2
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr imageMimeTypeEncoding operator|(imageMimeTypeEncoding a, imageMimeTypeEncoding b) {
|
constexpr imageMimeTypeEncoding operator|(imageMimeTypeEncoding a, imageMimeTypeEncoding b) {
|
||||||
return static_cast<imageMimeTypeEncoding>(static_cast<int>(a) | static_cast<int>(b));
|
return static_cast<imageMimeTypeEncoding>(static_cast<int>(a) | static_cast<int>(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator&(imageMimeTypeEncoding a, imageMimeTypeEncoding b) {
|
constexpr bool operator&(imageMimeTypeEncoding a, imageMimeTypeEncoding b) {
|
||||||
return (static_cast<int>(a) & static_cast<int>(b));
|
return (static_cast<int>(a) & static_cast<int>(b));
|
||||||
}
|
}
|
||||||
|
@ -763,9 +765,9 @@ static unique_ptr<Scene> _sceneBuildHelper(const SvgNode* node, const Box& vBox,
|
||||||
|
|
||||||
static void _applySvgViewFlag(const Scene* scene, float& vx, float& vy, float& vw, float& vh, float& w, float& h, SvgViewFlag viewFlag)
|
static void _applySvgViewFlag(const Scene* scene, float& vx, float& vy, float& vw, float& vh, float& w, float& h, SvgViewFlag viewFlag)
|
||||||
{
|
{
|
||||||
bool noViewbox = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox);
|
bool noViewbox = !(viewFlag & SvgViewFlag::Viewbox);
|
||||||
bool noWidth = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width);
|
bool noWidth = !(viewFlag & SvgViewFlag::Width);
|
||||||
bool noHeight = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height);
|
bool noHeight = !(viewFlag & SvgViewFlag::Height);
|
||||||
|
|
||||||
if (noViewbox) {
|
if (noViewbox) {
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
Loading…
Add table
Reference in a new issue