mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
svg_loader: improved clarity, no logical changes
Unnecessary structure removed, typos corrected, comment added, an unused function argument removed.
This commit is contained in:
parent
d2c0428a99
commit
a0490fd026
3 changed files with 24 additions and 39 deletions
|
@ -175,14 +175,14 @@ static float _toFloat(const SvgParser* svgParse, const char* str, SvgParserLengt
|
|||
else if (strstr(str, "pc")) parsedValue *= PX_PER_PC;
|
||||
else if (strstr(str, "in")) parsedValue *= PX_PER_IN;
|
||||
else if (strstr(str, "%")) {
|
||||
if (type == SvgParserLengthType::Vertical) parsedValue = (parsedValue / 100.0) * svgParse->global.h;
|
||||
else if (type == SvgParserLengthType::Horizontal) parsedValue = (parsedValue / 100.0) * svgParse->global.w;
|
||||
else //if other then it's radius
|
||||
if (type == SvgParserLengthType::Vertical) parsedValue = (parsedValue / 100.0f) * svgParse->global.h;
|
||||
else if (type == SvgParserLengthType::Horizontal) parsedValue = (parsedValue / 100.0f) * svgParse->global.w;
|
||||
else //if other than it's radius
|
||||
{
|
||||
float max = svgParse->global.w;
|
||||
if (max < svgParse->global.h)
|
||||
max = svgParse->global.h;
|
||||
parsedValue = (parsedValue / 100.0) * max;
|
||||
parsedValue = (parsedValue / 100.0f) * max;
|
||||
}
|
||||
}
|
||||
//TODO: Implement 'em', 'ex' attributes
|
||||
|
@ -580,7 +580,7 @@ static constexpr struct
|
|||
};
|
||||
|
||||
|
||||
static bool _hslToRgb(float hue, float satuation, float brightness, uint8_t* red, uint8_t* green, uint8_t* blue)
|
||||
static bool _hslToRgb(float hue, float saturation, float brightness, uint8_t* red, uint8_t* green, uint8_t* blue)
|
||||
{
|
||||
if (!red || !green || !blue) return false;
|
||||
|
||||
|
@ -588,12 +588,12 @@ static bool _hslToRgb(float hue, float satuation, float brightness, uint8_t* red
|
|||
float _red = 0, _green = 0, _blue = 0;
|
||||
uint32_t i = 0;
|
||||
|
||||
if (mathZero(satuation)) _red = _green = _blue = brightness;
|
||||
if (mathZero(saturation)) _red = _green = _blue = brightness;
|
||||
else {
|
||||
if (mathEqual(hue, 360.0)) hue = 0.0f;
|
||||
hue /= 60.0f;
|
||||
|
||||
v = (brightness <= 0.5f) ? (brightness * (1.0f + satuation)) : (brightness + satuation - (brightness * satuation));
|
||||
v = (brightness <= 0.5f) ? (brightness * (1.0f + saturation)) : (brightness + saturation - (brightness * saturation));
|
||||
p = brightness + brightness - v;
|
||||
|
||||
if (!mathZero(v)) sv = (v - p) / v;
|
||||
|
@ -662,7 +662,7 @@ static bool _toColor(const char* str, uint8_t* r, uint8_t* g, uint8_t* b, char**
|
|||
unsigned char tr, tg, tb;
|
||||
|
||||
if (len == 4 && str[0] == '#') {
|
||||
//Case for "#456" should be interprete as "#445566"
|
||||
//Case for "#456" should be interpreted as "#445566"
|
||||
if (isxdigit(str[1]) && isxdigit(str[2]) && isxdigit(str[3])) {
|
||||
char tmp[3] = { '\0', '\0', '\0' };
|
||||
tmp[0] = str[1];
|
||||
|
@ -709,8 +709,8 @@ static bool _toColor(const char* str, uint8_t* r, uint8_t* g, uint8_t* b, char**
|
|||
*ref = _idFromUrl((const char*)(str + 3));
|
||||
return true;
|
||||
} else if (len >= 10 && (str[0] == 'h' || str[0] == 'H') && (str[1] == 's' || str[1] == 'S') && (str[2] == 'l' || str[2] == 'L') && str[3] == '(' && str[len - 1] == ')') {
|
||||
float_t th, ts, tb;
|
||||
const char *content, *hue, *satuation, *brightness;
|
||||
float th, ts, tb;
|
||||
const char *content, *hue, *saturation, *brightness;
|
||||
content = str + 4;
|
||||
content = _skipSpace(content, nullptr);
|
||||
if (_parseNumber(&content, &hue, &th) && hue) {
|
||||
|
@ -718,12 +718,12 @@ static bool _toColor(const char* str, uint8_t* r, uint8_t* g, uint8_t* b, char**
|
|||
hue = _skipSpace(hue, nullptr);
|
||||
hue = (char*)_skipComma(hue);
|
||||
hue = _skipSpace(hue, nullptr);
|
||||
if (_parseNumber(&hue, &satuation, &ts) && satuation && *satuation == '%') {
|
||||
if (_parseNumber(&hue, &saturation, &ts) && saturation && *saturation == '%') {
|
||||
ts /= 100.0f;
|
||||
satuation = _skipSpace(satuation + 1, nullptr);
|
||||
satuation = (char*)_skipComma(satuation);
|
||||
satuation = _skipSpace(satuation, nullptr);
|
||||
if (_parseNumber(&satuation, &brightness, &tb) && brightness && *brightness == '%') {
|
||||
saturation = _skipSpace(saturation + 1, nullptr);
|
||||
saturation = (char*)_skipComma(saturation);
|
||||
saturation = _skipSpace(saturation, nullptr);
|
||||
if (_parseNumber(&saturation, &brightness, &tb) && brightness && *brightness == '%') {
|
||||
tb /= 100.0f;
|
||||
brightness = _skipSpace(brightness + 1, nullptr);
|
||||
if (brightness && brightness[0] == ')' && brightness[1] == '\0') {
|
||||
|
@ -3174,27 +3174,12 @@ static void _clonePostponedNodes(Array<SvgNodeIdPair>* cloneNodes, SvgNode* doc)
|
|||
}
|
||||
|
||||
|
||||
static constexpr struct
|
||||
{
|
||||
const char* tag;
|
||||
size_t sz;
|
||||
} popArray[] = {
|
||||
{"g", sizeof("g")},
|
||||
{"svg", sizeof("svg")},
|
||||
{"defs", sizeof("defs")},
|
||||
{"mask", sizeof("mask")},
|
||||
{"clipPath", sizeof("clipPath")},
|
||||
{"style", sizeof("style")},
|
||||
{"symbol", sizeof("symbol")}
|
||||
};
|
||||
|
||||
|
||||
static void _svgLoaderParserXmlClose(SvgLoaderData* loader, const char* content)
|
||||
{
|
||||
content = _skipSpace(content, nullptr);
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(popArray) / sizeof(popArray[0]); i++) {
|
||||
if (!strncmp(content, popArray[i].tag, popArray[i].sz - 1)) {
|
||||
for (unsigned int i = 0; i < sizeof(groupTags) / sizeof(groupTags[0]); i++) {
|
||||
if (!strncmp(content, groupTags[i].tag, groupTags[i].sz - 1)) {
|
||||
loader->stack.pop();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ struct SvgLoaderData
|
|||
{
|
||||
Array<SvgNode*> stack;
|
||||
SvgNode* doc = nullptr;
|
||||
SvgNode* def = nullptr;
|
||||
SvgNode* def = nullptr; //also used to store nested graphic nodes
|
||||
SvgNode* cssStyle = nullptr;
|
||||
Array<SvgStyleGradient*> gradients;
|
||||
SvgStyleGradient* latestGradient = nullptr; //For stops
|
||||
|
|
|
@ -79,7 +79,7 @@ static void _transformMultiply(const Matrix* mBBox, Matrix* gradTransf)
|
|||
}
|
||||
|
||||
|
||||
static unique_ptr<LinearGradient> _applyLinearGradientProperty(SvgStyleGradient* g, const Shape* vg, const Box& vBox, int opacity)
|
||||
static unique_ptr<LinearGradient> _applyLinearGradientProperty(SvgStyleGradient* g, const Box& vBox, int opacity)
|
||||
{
|
||||
Fill::ColorStop* stops;
|
||||
int stopCount = 0;
|
||||
|
@ -134,7 +134,7 @@ static unique_ptr<LinearGradient> _applyLinearGradientProperty(SvgStyleGradient*
|
|||
}
|
||||
|
||||
|
||||
static unique_ptr<RadialGradient> _applyRadialGradientProperty(SvgStyleGradient* g, const Shape* vg, const Box& vBox, int opacity)
|
||||
static unique_ptr<RadialGradient> _applyRadialGradientProperty(SvgStyleGradient* g, const Box& vBox, int opacity)
|
||||
{
|
||||
Fill::ColorStop *stops;
|
||||
int stopCount = 0;
|
||||
|
@ -320,10 +320,10 @@ static void _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg,
|
|||
if (!style->fill.paint.gradient->userSpace) bBox = _boundingBox(vg);
|
||||
|
||||
if (style->fill.paint.gradient->type == SvgGradientType::Linear) {
|
||||
auto linear = _applyLinearGradientProperty(style->fill.paint.gradient, vg, bBox, style->fill.opacity);
|
||||
auto linear = _applyLinearGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity);
|
||||
vg->fill(std::move(linear));
|
||||
} else if (style->fill.paint.gradient->type == SvgGradientType::Radial) {
|
||||
auto radial = _applyRadialGradientProperty(style->fill.paint.gradient, vg, bBox, style->fill.opacity);
|
||||
auto radial = _applyRadialGradientProperty(style->fill.paint.gradient, bBox, style->fill.opacity);
|
||||
vg->fill(std::move(radial));
|
||||
}
|
||||
} else if (style->fill.paint.url) {
|
||||
|
@ -363,10 +363,10 @@ static void _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg,
|
|||
if (!style->stroke.paint.gradient->userSpace) bBox = _boundingBox(vg);
|
||||
|
||||
if (style->stroke.paint.gradient->type == SvgGradientType::Linear) {
|
||||
auto linear = _applyLinearGradientProperty(style->stroke.paint.gradient, vg, bBox, style->stroke.opacity);
|
||||
auto linear = _applyLinearGradientProperty(style->stroke.paint.gradient, bBox, style->stroke.opacity);
|
||||
vg->stroke(std::move(linear));
|
||||
} else if (style->stroke.paint.gradient->type == SvgGradientType::Radial) {
|
||||
auto radial = _applyRadialGradientProperty(style->stroke.paint.gradient, vg, bBox, style->stroke.opacity);
|
||||
auto radial = _applyRadialGradientProperty(style->stroke.paint.gradient, bBox, style->stroke.opacity);
|
||||
vg->stroke(std::move(radial));
|
||||
}
|
||||
} else if (style->stroke.paint.url) {
|
||||
|
|
Loading…
Add table
Reference in a new issue