common loader: return viewbox info from the vector resource.

if a scene loads a vector resource, it must have viewbox info from the design,
That viewbox will be used as bounding box so that user can scale up/down
the scene by its requirements.

Change-Id: Iafa39af23118a03de207c745364d56c837892e1b
This commit is contained in:
Hermet Park 2020-07-07 15:12:11 +09:00
parent d37cdaf57c
commit 6967b998b6
3 changed files with 52 additions and 32 deletions

View file

@ -23,6 +23,12 @@ namespace tvg
class Loader
{
public:
//default view box, if any.
float vx = 0;
float vy = 0;
float vw = 0;
float vh = 0;
virtual ~Loader() {}
virtual bool open(const char* path) = 0;

View file

@ -74,11 +74,12 @@ struct Scene::Impl
{
if (loader) {
auto scene = loader->data();
if (scene) {
auto p = scene.release();
if (!p) return false;
paints.push_back(p);
loader->close();
loader.reset(nullptr);
}
}
if (flag & RenderUpdateFlag::Transform) {
@ -121,6 +122,12 @@ struct Scene::Impl
bool bounds(float* px, float* py, float* pw, float* ph)
{
if (loader) {
if (px) *px = loader->vx;
if (py) *py = loader->vy;
if (pw) *pw = loader->vw;
if (ph) *ph = loader->vh;
} else {
auto x = FLT_MAX;
auto y = FLT_MAX;
auto w = 0.0f;
@ -152,7 +159,7 @@ struct Scene::Impl
if (py) *py = y;
if (pw) *pw = w;
if (ph) *ph = h;
}
return true;
}

View file

@ -2262,6 +2262,13 @@ bool SvgLoader::open(const char* path)
if (content.empty()) return false;
}
//FIXME: Verify this resource is normal SVG, otherwise return false
//Also, return the brief resource info such as viewbox:
//this->vx = ?
//this->vy = ?
//this->vw = ?
//this->vh = ?
return true;
}