Fix svg memory issue
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.cpp
index d9ca38b..fccd5e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
 #include <dali/public-api/math/vector4.h>
 #include <dali/devel-api/images/texture-set-image.h>
 #include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
@@ -203,8 +204,13 @@ void SvgVisual::ParseFromUrl( const VisualUrl& imageUrl )
   if( mImageUrl.IsLocalResource() )
   {
     Vector2 dpi = Stage::GetCurrent().GetDpi();
-    float meanDpi = (dpi.height + dpi.width) * 0.5f;
-    mParsedImage = nsvgParseFromFile( mImageUrl.GetUrl().c_str(), UNITS, meanDpi );
+    float meanDpi = ( dpi.height + dpi.width ) * 0.5f;
+    Dali::Vector<char> buffer;
+    if ( Dali::FileLoader::ReadFile( mImageUrl.GetUrl(), buffer ) )
+    {
+      buffer.PushBack( '\0' );
+      mParsedImage = nsvgParse( buffer.Begin(), UNITS, meanDpi );
+    }
   }
 }