}
-void SvgTask::run()
-{
- if (!simpleXmlParse(loader->content, loader->size, true, _svgLoaderParser, &(loader->loaderData))) return;
-
- if (loader->loaderData.doc) {
- _updateStyle(loader->loaderData.doc, nullptr);
- auto defs = loader->loaderData.doc->node.doc.defs;
- if (defs) _updateGradient(loader->loaderData.doc, &defs->node.defs.gradients);
- else {
- if (loader->loaderData.gradients.cnt > 0) {
- _updateGradient(loader->loaderData.doc, &loader->loaderData.gradients);
- }
- }
- }
- loader->root = loader->builder.build(loader->loaderData.doc);
-};
-
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
-SvgLoader::SvgLoader() : task(new SvgTask)
+SvgLoader::SvgLoader()
{
- task->loader = this;
+
}
}
+void SvgLoader::run()
+{
+ if (!simpleXmlParse(content, size, true, _svgLoaderParser, &(loaderData))) return;
+
+ if (loaderData.doc) {
+ _updateStyle(loaderData.doc, nullptr);
+ auto defs = loaderData.doc->node.doc.defs;
+ if (defs) _updateGradient(loaderData.doc, &defs->node.defs.gradients);
+ else {
+ if (loaderData.gradients.cnt > 0) {
+ _updateGradient(loaderData.doc, &loaderData.gradients);
+ }
+ }
+ }
+ root = builder.build(loaderData.doc);
+};
+
+
bool SvgLoader::header()
{
//For valid check, only <svg> tag is parsed first.
{
if (!content || size == 0) return false;
- TaskScheduler::request(task);
+ TaskScheduler::request(this);
return true;
}
bool SvgLoader::close()
{
- if (task) {
- task->get();
- delete(task);
- task = nullptr;
- }
+ this->get();
+
if (loaderData.svgParse) {
free(loaderData.svgParse);
loaderData.svgParse = nullptr;
unique_ptr<Scene> SvgLoader::data()
{
- if (task) task->get();
+ this->get();
if (root) return move(root);
else return nullptr;
}
#include "tvgSvgLoaderCommon.h"
#include "tvgSvgSceneBuilder.h"
-class SvgLoader;
-
-struct SvgTask : Task
-{
- SvgLoader* loader = nullptr;
- void run() override;
-};
-
-
-class SvgLoader : public Loader
+class SvgLoader : public Loader, public Task
{
public:
string filePath;
SvgLoaderData loaderData;
SvgSceneBuilder builder;
unique_ptr<Scene> root;
- SvgTask* task = nullptr;
SvgLoader();
~SvgLoader();
bool header();
bool read() override;
bool close() override;
+ void run() override;
+
unique_ptr<Scene> data() override;
};