2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/devel-api/adaptor-framework/file-loader.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/internal/visuals/svg/svg-visual.h>
35 SvgTask::SvgTask(VectorImageRenderer vectorRenderer, CallbackBase* callback, AsyncTask::PriorityType priorityType)
36 : AsyncTask(callback, priorityType),
37 mVectorRenderer(vectorRenderer),
42 PixelData SvgTask::GetPixelData() const
47 bool SvgTask::HasSucceeded() const
52 VectorImageRenderer SvgTask::GetRenderer()
54 return mVectorRenderer;
57 SvgLoadingTask::SvgLoadingTask(VectorImageRenderer vectorRenderer, const VisualUrl& url, float dpi, CallbackBase* callback)
58 : SvgTask(vectorRenderer, callback, url.GetProtocolType() == VisualUrl::ProtocolType::REMOTE ? AsyncTask::PriorityType::LOW : AsyncTask::PriorityType::HIGH),
64 SvgLoadingTask::~SvgLoadingTask()
68 void SvgLoadingTask::Process()
70 if(mVectorRenderer.IsLoaded())
77 Dali::Vector<uint8_t> buffer;
79 if(!mUrl.IsLocalResource())
81 if(!Dali::FileLoader::DownloadFileSynchronously(mUrl.GetUrl(), buffer))
83 DALI_LOG_ERROR("Failed to download file! [%s]\n", mUrl.GetUrl().c_str());
89 if(!Dali::FileLoader::ReadFile(mUrl.GetUrl(), buffer))
91 DALI_LOG_ERROR("Failed to read file! [%s]\n", mUrl.GetUrl().c_str());
96 buffer.PushBack('\0');
98 if(!mVectorRenderer.Load(buffer, mDpi))
100 DALI_LOG_ERROR("Failed to load data! [%s]\n", mUrl.GetUrl().c_str());
104 mHasSucceeded = true;
107 bool SvgLoadingTask::IsReady()
112 SvgRasterizingTask::SvgRasterizingTask(VectorImageRenderer vectorRenderer, uint32_t width, uint32_t height, CallbackBase* callback)
113 : SvgTask(vectorRenderer, callback),
119 SvgRasterizingTask::~SvgRasterizingTask()
123 void SvgRasterizingTask::Process()
125 if(!mVectorRenderer.IsLoaded())
127 DALI_LOG_ERROR("File is not loaded!\n");
131 Devel::PixelBuffer pixelBuffer = mVectorRenderer.Rasterize(mWidth, mHeight);
134 DALI_LOG_ERROR("Rasterize is failed!\n");
138 mPixelData = Devel::PixelBuffer::Convert(pixelBuffer);
139 mHasSucceeded = true;
142 bool SvgRasterizingTask::IsReady()
144 return mVectorRenderer.IsLoaded();
147 PixelData SvgRasterizingTask::GetPixelData() const
152 } // namespace Internal
154 } // namespace Toolkit