mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 20:44:52 +00:00
svg_loader: styling++ (no logical changes)
This commit is contained in:
parent
4a7310756d
commit
863a98870f
4 changed files with 13 additions and 18 deletions
|
@ -75,13 +75,13 @@
|
||||||
#define PX_PER_MM 3.779528f //1 in = 25.4 mm -> PX_PER_IN/25.4
|
#define PX_PER_MM 3.779528f //1 in = 25.4 mm -> PX_PER_IN/25.4
|
||||||
#define PX_PER_CM 37.79528f //1 in = 2.54 cm -> PX_PER_IN/2.54
|
#define PX_PER_CM 37.79528f //1 in = 2.54 cm -> PX_PER_IN/2.54
|
||||||
|
|
||||||
|
typedef bool (*parseAttributes)(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data);
|
||||||
typedef bool (*parseAttributes)(const char*, unsigned, simpleXMLAttributeCb, const void*);
|
|
||||||
typedef SvgNode* (*FactoryMethod)(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func);
|
typedef SvgNode* (*FactoryMethod)(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func);
|
||||||
typedef SvgStyleGradient* (*GradientFactoryMethod)(SvgLoaderData* loader, const char* buf, unsigned bufLength);
|
typedef SvgStyleGradient* (*GradientFactoryMethod)(SvgLoaderData* loader, const char* buf, unsigned bufLength);
|
||||||
|
|
||||||
static void _postponeCloneNode(Array<SvgNodeIdPair>* nodes, SvgNode *node, char* id);
|
static void _postponeCloneNode(Array<SvgNodeIdPair>* nodes, SvgNode *node, char* id);
|
||||||
|
|
||||||
|
|
||||||
static char* _skipSpace(const char* str, const char* end)
|
static char* _skipSpace(const char* str, const char* end)
|
||||||
{
|
{
|
||||||
while (((end && str < end) || (!end && *str != '\0')) && isspace(*str)) {
|
while (((end && str < end) || (!end && *str != '\0')) && isspace(*str)) {
|
||||||
|
@ -1055,7 +1055,6 @@ static void _cssStyleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: check SVG2 standard - should the geometric properties be copied?
|
|
||||||
static void _copyCssStyleAttr(SvgNode* to, const SvgNode* from)
|
static void _copyCssStyleAttr(SvgNode* to, const SvgNode* from)
|
||||||
{
|
{
|
||||||
//Copy matrix attribute
|
//Copy matrix attribute
|
||||||
|
@ -2812,20 +2811,17 @@ static void _svgLoaderParserXmlCssStyle(SvgLoaderData* loader, const char* conte
|
||||||
|
|
||||||
while (auto next = simpleXmlParseCSSAttribute(content, length, &tag, &name, &attrs, &attrsLength)) {
|
while (auto next = simpleXmlParseCSSAttribute(content, length, &tag, &name, &attrs, &attrsLength)) {
|
||||||
if ((method = _findGroupFactory(tag))) {
|
if ((method = _findGroupFactory(tag))) {
|
||||||
//TODO - node->id ??? add additional var for svgnode?
|
TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag);
|
||||||
if ((node = method(loader, loader->cssStyle, attrs, attrsLength, simpleXmlParseW3CAttribute))) node->id = _copyId(name);
|
|
||||||
} else if ((method = _findGraphicsFactory(tag))) {
|
} else if ((method = _findGraphicsFactory(tag))) {
|
||||||
if ((node = method(loader, loader->cssStyle, attrs, attrsLength, simpleXmlParseW3CAttribute))) node->id = _copyId(name);
|
if ((node = method(loader, loader->cssStyle, attrs, attrsLength, simpleXmlParseW3CAttribute))) node->id = _copyId(name);
|
||||||
//TODO - implement
|
|
||||||
} else if ((gradientMethod = _findGradientFactory(tag))) {
|
} else if ((gradientMethod = _findGradientFactory(tag))) {
|
||||||
//TODO - implement
|
TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag);
|
||||||
//SvgStyleGradient* gradient = gradientMethod(loader, attrs, attrsLength);
|
|
||||||
} else if (!strcmp(tag, "stop")) {
|
} else if (!strcmp(tag, "stop")) {
|
||||||
//TODO - implement
|
TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag);
|
||||||
} else if (!strcmp(tag, "all")) {
|
} else if (!strcmp(tag, "all")) {
|
||||||
if ((node = _createCssStyleNode(loader, loader->cssStyle, attrs, attrsLength, simpleXmlParseW3CAttribute))) node->id = _copyId(name);
|
if ((node = _createCssStyleNode(loader, loader->cssStyle, attrs, attrsLength, simpleXmlParseW3CAttribute))) node->id = _copyId(name);
|
||||||
} else if (!isIgnoreUnsupportedLogElements(tag)) {
|
} else if (!isIgnoreUnsupportedLogElements(tag)) {
|
||||||
TVGLOG("SVG", "Unsupported elements used [Elements: %s]", tag);
|
TVGLOG("SVG", "Unsupported elements used in the internal CSS style sheets [Elements: %s]", tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
length -= next - content;
|
length -= next - content;
|
||||||
|
@ -3215,7 +3211,6 @@ void SvgLoader::run(unsigned tid)
|
||||||
if (defs) _updateGradient(loaderData.doc, &defs->node.defs.gradients);
|
if (defs) _updateGradient(loaderData.doc, &defs->node.defs.gradients);
|
||||||
|
|
||||||
if (loaderData.nodesToStyle.count > 0) _stylePostponedNodes(&loaderData.nodesToStyle, loaderData.cssStyle);
|
if (loaderData.nodesToStyle.count > 0) _stylePostponedNodes(&loaderData.nodesToStyle, loaderData.cssStyle);
|
||||||
//TODO: defs should be updated as well?
|
|
||||||
if (loaderData.cssStyle) _updateCssStyle(loaderData.doc, loaderData.cssStyle);
|
if (loaderData.cssStyle) _updateCssStyle(loaderData.doc, loaderData.cssStyle);
|
||||||
}
|
}
|
||||||
root = svgSceneBuild(loaderData.doc, vx, vy, vw, vh, w, h, preserveAspect, svgPath);
|
root = svgSceneBuild(loaderData.doc, vx, vy, vw, vh, w, h, preserveAspect, svgPath);
|
||||||
|
|
|
@ -416,7 +416,7 @@ struct SvgLoaderData
|
||||||
Array<SvgNodeIdPair> nodesToStyle;
|
Array<SvgNodeIdPair> nodesToStyle;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
bool style = false; //TODO: find a better sollution?
|
bool style = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -458,7 +458,7 @@ bool simpleXmlParse(const char* buf, unsigned bufLength, bool strip, simpleXMLCb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool simpleXmlParseW3CAttribute(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data)
|
bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data)
|
||||||
{
|
{
|
||||||
const char* end;
|
const char* end;
|
||||||
char* key;
|
char* key;
|
||||||
|
@ -467,7 +467,7 @@ bool simpleXmlParseW3CAttribute(const char* buf, unsigned buflen, simpleXMLAttri
|
||||||
|
|
||||||
if (!buf) return false;
|
if (!buf) return false;
|
||||||
|
|
||||||
end = buf + buflen;
|
end = buf + bufLength;
|
||||||
key = (char*)alloca(end - buf + 1);
|
key = (char*)alloca(end - buf + 1);
|
||||||
val = (char*)alloca(end - buf + 1);
|
val = (char*)alloca(end - buf + 1);
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,11 @@ enum class SimpleXMLType
|
||||||
typedef bool (*simpleXMLCb)(void* data, SimpleXMLType type, const char* content, unsigned int length);
|
typedef bool (*simpleXMLCb)(void* data, SimpleXMLType type, const char* content, unsigned int length);
|
||||||
typedef bool (*simpleXMLAttributeCb)(void* data, const char* key, const char* value);
|
typedef bool (*simpleXMLAttributeCb)(void* data, const char* key, const char* value);
|
||||||
|
|
||||||
bool simpleXmlParseAttributes(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data);
|
bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data);
|
||||||
bool simpleXmlParse(const char* buf, unsigned buflen, bool strip, simpleXMLCb func, const void* data);
|
bool simpleXmlParse(const char* buf, unsigned bufLength, bool strip, simpleXMLCb func, const void* data);
|
||||||
bool simpleXmlParseW3CAttribute(const char* buf, unsigned buflen, simpleXMLAttributeCb func, const void* data);
|
bool simpleXmlParseW3CAttribute(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data);
|
||||||
const char* simpleXmlParseCSSAttribute(const char* buf, unsigned bufLength, char** tag, char** name, const char** attrs, unsigned* attrsLength);
|
const char* simpleXmlParseCSSAttribute(const char* buf, unsigned bufLength, char** tag, char** name, const char** attrs, unsigned* attrsLength);
|
||||||
const char* simpleXmlFindAttributesTag(const char* buf, unsigned buflen);
|
const char* simpleXmlFindAttributesTag(const char* buf, unsigned bufLength);
|
||||||
bool isIgnoreUnsupportedLogElements(const char* tagName);
|
bool isIgnoreUnsupportedLogElements(const char* tagName);
|
||||||
const char* simpleXmlNodeTypeToString(SvgNodeType type);
|
const char* simpleXmlNodeTypeToString(SvgNodeType type);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue