mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
svg_loader: proper handling width/height units (#851)
Units of the svg width and height tags were incorrectly assigned. Percentage values will be handled separately.
This commit is contained in:
parent
5b7f94a527
commit
875e5bd058
2 changed files with 10 additions and 8 deletions
|
@ -697,6 +697,8 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO - remove?
|
||||||
static constexpr struct
|
static constexpr struct
|
||||||
{
|
{
|
||||||
const char* tag;
|
const char* tag;
|
||||||
|
@ -712,7 +714,6 @@ static constexpr struct
|
||||||
LENGTH_DEF(in, SvgLengthType::In)
|
LENGTH_DEF(in, SvgLengthType::In)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static float _parseLength(const char* str, SvgLengthType* type)
|
static float _parseLength(const char* str, SvgLengthType* type)
|
||||||
{
|
{
|
||||||
float value;
|
float value;
|
||||||
|
@ -725,7 +726,7 @@ static float _parseLength(const char* str, SvgLengthType* type)
|
||||||
value = svgUtilStrtof(str, nullptr);
|
value = svgUtilStrtof(str, nullptr);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static bool _parseStyleAttr(void* data, const char* key, const char* value);
|
static bool _parseStyleAttr(void* data, const char* key, const char* value);
|
||||||
static bool _parseStyleAttr(void* data, const char* key, const char* value, bool style);
|
static bool _parseStyleAttr(void* data, const char* key, const char* value, bool style);
|
||||||
|
@ -736,13 +737,11 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
|
||||||
SvgLoaderData* loader = (SvgLoaderData*)data;
|
SvgLoaderData* loader = (SvgLoaderData*)data;
|
||||||
SvgNode* node = loader->svgParse->node;
|
SvgNode* node = loader->svgParse->node;
|
||||||
SvgDocNode* doc = &(node->node.doc);
|
SvgDocNode* doc = &(node->node.doc);
|
||||||
SvgLengthType type;
|
|
||||||
|
|
||||||
//TODO: handle length unit.
|
|
||||||
if (!strcmp(key, "width")) {
|
if (!strcmp(key, "width")) {
|
||||||
doc->w = _parseLength(value, &type);
|
doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
|
||||||
} else if (!strcmp(key, "height")) {
|
} else if (!strcmp(key, "height")) {
|
||||||
doc->h = _parseLength(value, &type);
|
doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical);
|
||||||
} 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)) {
|
||||||
|
@ -761,8 +760,8 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
|
||||||
return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader);
|
return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader);
|
||||||
}
|
}
|
||||||
#ifdef THORVG_LOG_ENABLED
|
#ifdef THORVG_LOG_ENABLED
|
||||||
else if (!strcmp(key, "x") || !strcmp(key, "y")) {
|
else if ((!strcmp(key, "x") || !strcmp(key, "y")) && fabsf(svgUtilStrtof(value, nullptr)) > FLT_EPSILON ) {
|
||||||
if (0.0f == _parseLength(value, &type)) TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value);
|
TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -54,6 +54,8 @@ enum class SvgNodeType
|
||||||
Unknown
|
Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO - remove?
|
||||||
enum class SvgLengthType
|
enum class SvgLengthType
|
||||||
{
|
{
|
||||||
Percent,
|
Percent,
|
||||||
|
@ -64,6 +66,7 @@ enum class SvgLengthType
|
||||||
Cm,
|
Cm,
|
||||||
In,
|
In,
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
enum class SvgFillFlags
|
enum class SvgFillFlags
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue