mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
svg_loader: append text to the SvgTextNode
Text can be added in parts due to the presence of the <tspan> tag. This requires that each subsequent piece of text is appended rather than overwriting the previous one.
This commit is contained in:
parent
6775f6e463
commit
bf9f5ab1c5
3 changed files with 11 additions and 2 deletions
|
@ -219,6 +219,14 @@ char* strDuplicate(const char *str, size_t n)
|
|||
return (char *) memcpy(ret, str, n);
|
||||
}
|
||||
|
||||
char* strAppend(char* lhs, const char* rhs, size_t n)
|
||||
{
|
||||
if (!rhs) return lhs;
|
||||
if (!lhs) return strDuplicate(rhs, n);
|
||||
lhs = (char*)realloc(lhs, strlen(lhs) + n + 1);
|
||||
return strncat(lhs, rhs, n);
|
||||
}
|
||||
|
||||
char* strDirname(const char* path)
|
||||
{
|
||||
const char *ptr = strrchr(path, '/');
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace tvg
|
|||
|
||||
float strToFloat(const char *nPtr, char **endPtr); //convert to float
|
||||
char* strDuplicate(const char *str, size_t n); //copy the string
|
||||
char* strAppend(char* lhs, const char* rhs, size_t n); //append the rhs to the lhs
|
||||
char* strDirname(const char* path); //return the full directory name
|
||||
|
||||
}
|
||||
|
|
|
@ -2183,6 +2183,7 @@ static SvgNode* _createTextNode(SvgLoaderData* loader, SvgNode* parent, const ch
|
|||
//TODO: support the def font and size as used in a system?
|
||||
loader->svgParse->node->node.text.fontSize = 10.0f;
|
||||
loader->svgParse->node->node.text.fontFamily = nullptr;
|
||||
loader->svgParse->node->node.text.text = nullptr;
|
||||
|
||||
func(buf, bufLength, _attrParseTextNode, loader);
|
||||
|
||||
|
@ -3400,8 +3401,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
|
|||
static void _svgLoaderParserText(SvgLoaderData* loader, const char* content, unsigned int length)
|
||||
{
|
||||
auto text = &loader->svgParse->node->node.text;
|
||||
if (text->text) free(text->text);
|
||||
text->text = strDuplicate(content, length);
|
||||
text->text = strAppend(text->text, content, length);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue