mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
common: code refactoring
replaced internal string usage with char*
This commit is contained in:
parent
9b9a0308c8
commit
4aaa0dafc4
23 changed files with 64 additions and 63 deletions
|
@ -1260,10 +1260,10 @@ public:
|
|||
*
|
||||
* @warning It's the user responsibility to release the @p data memory.
|
||||
*
|
||||
* @note If you are unsure about the MIME type, you can provide an empty value like @c "", and thorvg will attempt to figure it out.
|
||||
* @note If you are unsure about the MIME type, you can provide an empty value like @c nullptr, and thorvg will attempt to figure it out.
|
||||
* @since 0.5
|
||||
*/
|
||||
Result load(const char* data, uint32_t size, const char* mimeType, const char* rpath = "", bool copy = false) noexcept;
|
||||
Result load(const char* data, uint32_t size, const char* mimeType, const char* rpath = nullptr, bool copy = false) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Resizes the picture content to the given width and height.
|
||||
|
@ -1540,7 +1540,7 @@ public:
|
|||
* @warning It's the user responsibility to release the @p data memory.
|
||||
*
|
||||
* @note To unload the font data loaded using this API, pass the proper @p name and @c nullptr as @p data.
|
||||
* @note If you are unsure about the MIME type, you can provide an empty value like @c "", and thorvg will attempt to figure it out.
|
||||
* @note If you are unsure about the MIME type, you can provide an empty value like @c nullptr, and thorvg will attempt to figure it out.
|
||||
* @see Text::font(const char* name, float size, const char* style)
|
||||
*
|
||||
* @note 0.15
|
||||
|
|
|
@ -57,9 +57,9 @@ JpgLoader::~JpgLoader()
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const string& path)
|
||||
bool JpgLoader::open(const char* path)
|
||||
{
|
||||
auto jpegFile = fopen(path.c_str(), "rb");
|
||||
auto jpegFile = fopen(path, "rb");
|
||||
if (!jpegFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
@ -97,7 +97,7 @@ finalize:
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
int width, height, subSample, colorSpace;
|
||||
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &subSample, &colorSpace) < 0) return false;
|
||||
|
|
|
@ -34,8 +34,8 @@ public:
|
|||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -52,11 +52,11 @@ PngLoader::~PngLoader()
|
|||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const string& path)
|
||||
bool PngLoader::open(const char* path)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
|
||||
if (!png_image_begin_read_from_file(image, path.c_str())) return false;
|
||||
if (!png_image_begin_read_from_file(image, path)) return false;
|
||||
|
||||
w = (float)image->width;
|
||||
h = (float)image->height;
|
||||
|
@ -65,7 +65,7 @@ bool PngLoader::open(const string& path)
|
|||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
image->opaque = NULL;
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ public:
|
|||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -66,9 +66,9 @@ WebpLoader::~WebpLoader()
|
|||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const string& path)
|
||||
bool WebpLoader::open(const char* path)
|
||||
{
|
||||
auto webpFile = fopen(path.c_str(), "rb");
|
||||
auto webpFile = fopen(path, "rb");
|
||||
if (!webpFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
@ -99,7 +99,7 @@ finalize:
|
|||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
this->data = (unsigned char *) malloc(size);
|
||||
|
|
|
@ -32,8 +32,8 @@ public:
|
|||
WebpLoader();
|
||||
~WebpLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
RenderSurface* bitmap() override;
|
||||
|
|
|
@ -68,10 +68,10 @@ JpgLoader::~JpgLoader()
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const string& path)
|
||||
bool JpgLoader::open(const char* path)
|
||||
{
|
||||
int width, height;
|
||||
decoder = jpgdHeader(path.c_str(), &width, &height);
|
||||
decoder = jpgdHeader(path, &width, &height);
|
||||
if (!decoder) return false;
|
||||
|
||||
w = static_cast<float>(width);
|
||||
|
@ -81,7 +81,7 @@ bool JpgLoader::open(const string& path)
|
|||
}
|
||||
|
||||
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
this->data = (char *) malloc(size);
|
||||
|
|
|
@ -41,8 +41,8 @@ public:
|
|||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ bool LottieLoader::header()
|
|||
}
|
||||
|
||||
|
||||
bool LottieLoader::open(const char* data, uint32_t size, const std::string& rpath, bool copy)
|
||||
bool LottieLoader::open(const char* data, uint32_t size, const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
content = (char*)malloc(size + 1);
|
||||
|
@ -207,16 +207,16 @@ bool LottieLoader::open(const char* data, uint32_t size, const std::string& rpat
|
|||
this->size = size;
|
||||
this->copy = copy;
|
||||
|
||||
if (rpath.empty()) this->dirName = strdup(".");
|
||||
else this->dirName = strdup(rpath.c_str());
|
||||
if (!rpath) this->dirName = strdup(".");
|
||||
else this->dirName = strdup(rpath);
|
||||
|
||||
return header();
|
||||
}
|
||||
|
||||
|
||||
bool LottieLoader::open(const string& path)
|
||||
bool LottieLoader::open(const char* path)
|
||||
{
|
||||
auto f = fopen(path.c_str(), "r");
|
||||
auto f = fopen(path, "r");
|
||||
if (!f) return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
@ -238,7 +238,7 @@ bool LottieLoader::open(const string& path)
|
|||
|
||||
fclose(f);
|
||||
|
||||
this->dirName = strDirname(path.c_str());
|
||||
this->dirName = strDirname(path);
|
||||
this->content = content;
|
||||
this->copy = true;
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ public:
|
|||
LottieLoader();
|
||||
~LottieLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const std::string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool resize(Paint* paint, float w, float h) override;
|
||||
bool read() override;
|
||||
Paint* paint() override;
|
||||
|
|
|
@ -68,9 +68,9 @@ PngLoader::~PngLoader()
|
|||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const string& path)
|
||||
bool PngLoader::open(const char* path)
|
||||
{
|
||||
auto pngFile = fopen(path.c_str(), "rb");
|
||||
auto pngFile = fopen(path, "rb");
|
||||
if (!pngFile) return false;
|
||||
|
||||
auto ret = false;
|
||||
|
@ -105,7 +105,7 @@ finalize:
|
|||
}
|
||||
|
||||
|
||||
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
unsigned int width, height;
|
||||
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
|
||||
|
|
|
@ -41,8 +41,8 @@ public:
|
|||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
|
||||
RenderSurface* bitmap() override;
|
||||
|
|
|
@ -3869,7 +3869,7 @@ bool SvgLoader::header()
|
|||
}
|
||||
|
||||
|
||||
bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
clear();
|
||||
|
||||
|
@ -3887,7 +3887,7 @@ bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& r
|
|||
}
|
||||
|
||||
|
||||
bool SvgLoader::open(const string& path)
|
||||
bool SvgLoader::open(const char* path)
|
||||
{
|
||||
clear();
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ public:
|
|||
SvgLoader();
|
||||
~SvgLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool resize(Paint* paint, float w, float h) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
|
|
@ -85,11 +85,11 @@ static void _unmap(TtfLoader* loader)
|
|||
|
||||
#elif defined(__linux__)
|
||||
|
||||
static bool _map(TtfLoader* loader, const string& path)
|
||||
static bool _map(TtfLoader* loader, const char* path)
|
||||
{
|
||||
auto& reader = loader->reader;
|
||||
|
||||
auto fd = open(path.c_str(), O_RDONLY);
|
||||
auto fd = open(path, O_RDONLY);
|
||||
if (fd < 0) return false;
|
||||
|
||||
struct stat info;
|
||||
|
@ -116,11 +116,11 @@ static void _unmap(TtfLoader* loader)
|
|||
reader.size = 0;
|
||||
}
|
||||
#else
|
||||
static bool _map(TtfLoader* loader, const string& path)
|
||||
static bool _map(TtfLoader* loader, const char* path)
|
||||
{
|
||||
auto& reader = loader->reader;
|
||||
|
||||
auto f = fopen(path.c_str(), "rb");
|
||||
auto f = fopen(path, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
@ -234,7 +234,7 @@ TtfLoader::~TtfLoader()
|
|||
}
|
||||
|
||||
|
||||
bool TtfLoader::open(const string& path)
|
||||
bool TtfLoader::open(const char* path)
|
||||
{
|
||||
clear();
|
||||
if (!_map(this, path)) return false;
|
||||
|
@ -242,7 +242,7 @@ bool TtfLoader::open(const string& path)
|
|||
}
|
||||
|
||||
|
||||
bool TtfLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool TtfLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
reader.size = size;
|
||||
nomap = true;
|
||||
|
|
|
@ -43,8 +43,8 @@ struct TtfLoader : public FontLoader
|
|||
~TtfLoader();
|
||||
|
||||
using FontLoader::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char *data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char *data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool transform(Paint* paint, float fontSize, bool italic) override;
|
||||
bool request(Shape* shape, char* text) override;
|
||||
bool read() override;
|
||||
|
|
|
@ -69,9 +69,9 @@ WebpLoader::~WebpLoader()
|
|||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const string& path)
|
||||
bool WebpLoader::open(const char* path)
|
||||
{
|
||||
auto f = fopen(path.c_str(), "rb");
|
||||
auto f = fopen(path, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
@ -104,7 +104,7 @@ bool WebpLoader::open(const string& path)
|
|||
}
|
||||
|
||||
|
||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
|
||||
bool WebpLoader::open(const char* data, uint32_t size, TVG_UNUSED const char* rpath, bool copy)
|
||||
{
|
||||
if (copy) {
|
||||
this->data = (uint8_t*) malloc(size);
|
||||
|
|
|
@ -37,8 +37,8 @@ public:
|
|||
WebpLoader();
|
||||
~WebpLoader();
|
||||
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
|
||||
bool open(const char* path) override;
|
||||
bool open(const char* data, uint32_t size, const char* rpath, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ struct LoadModule
|
|||
if (pathcache) free(hashpath);
|
||||
}
|
||||
|
||||
virtual bool open(const string& path) { return false; }
|
||||
virtual bool open(const char* data, uint32_t size, const string& rpath, bool copy) { return false; }
|
||||
virtual bool open(const char* path) { return false; }
|
||||
virtual bool open(const char* data, uint32_t size, const char* rpath, bool copy) { return false; }
|
||||
virtual bool resize(Paint* paint, float w, float h) { return false; }
|
||||
virtual void sync() {}; //finish immediately if any async update jobs.
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ class SaveModule
|
|||
public:
|
||||
virtual ~SaveModule() {}
|
||||
|
||||
virtual bool save(Paint* paint, Paint* bg, const string& path, uint32_t quality) = 0;
|
||||
virtual bool save(Animation* animation, Paint* bg, const string& path, uint32_t quality, uint32_t fps) = 0;
|
||||
virtual bool save(Paint* paint, Paint* bg, const char* filename, uint32_t quality) = 0;
|
||||
virtual bool save(Animation* animation, Paint* bg, const char* filename, uint32_t quality, uint32_t fps) = 0;
|
||||
virtual bool close() = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -113,14 +113,14 @@ bool GifSaver::close()
|
|||
}
|
||||
|
||||
|
||||
bool GifSaver::save(TVG_UNUSED Paint* paint, TVG_UNUSED Paint* bg, TVG_UNUSED const string& path, TVG_UNUSED uint32_t quality)
|
||||
bool GifSaver::save(TVG_UNUSED Paint* paint, TVG_UNUSED Paint* bg, TVG_UNUSED const char* filename, TVG_UNUSED uint32_t quality)
|
||||
{
|
||||
TVGLOG("GIF_SAVER", "Paint is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool GifSaver::save(Animation* animation, Paint* bg, const string& path, TVG_UNUSED uint32_t quality, uint32_t fps)
|
||||
bool GifSaver::save(Animation* animation, Paint* bg, const char* filename, TVG_UNUSED uint32_t quality, uint32_t fps)
|
||||
{
|
||||
close();
|
||||
|
||||
|
@ -138,10 +138,11 @@ bool GifSaver::save(Animation* animation, Paint* bg, const string& path, TVG_UNU
|
|||
return false;
|
||||
}
|
||||
|
||||
this->path = strdup(path.c_str());
|
||||
if (!this->path) return false;
|
||||
if (!filename) return false;
|
||||
this->path = strdup(filename);
|
||||
|
||||
this->animation = animation;
|
||||
|
||||
if (bg) this->bg = bg->duplicate();
|
||||
this->fps = static_cast<float>(fps);
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ private:
|
|||
public:
|
||||
~GifSaver();
|
||||
|
||||
bool save(Paint* paint, Paint* bg, const string& path, uint32_t quality) override;
|
||||
bool save(Animation* animation, Paint* bg, const string& path, uint32_t quality, uint32_t fps) override;
|
||||
bool save(Paint* paint, Paint* bg, const char* filename, uint32_t quality) override;
|
||||
bool save(Animation* animation, Paint* bg, const char* filename, uint32_t quality, uint32_t fps) override;
|
||||
bool close() override;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue