OpenCPN Partial API docs
Loading...
Searching...
No Matches
svg_utils.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2018 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
26#ifndef OPENCPN_SVG_UTILS_H
27#define OPENCPN_SVG_UTILS_H
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/wx.h>
33#endif // precompiled headers
34
35#include <string>
36#include <mutex>
37#include <unordered_map>
38
39#include <wx/string.h>
40
46wxBitmap LoadSVG(const wxString filename, const unsigned int width,
47 const unsigned int height, wxBitmap* default_bitmap = NULL,
48 bool use_cache = true);
49
56bool SVGDocumentPixelSize(const wxString filename, unsigned int& width,
57 unsigned int& height);
58
60unsigned int SVGPixelsToDisplay(unsigned int svg_px);
61
67wxBitmap LoadSvgStdIcon(const std::string& svg_file, const wxWindow* w,
68 bool touch);
69
72public:
73 static SVGBitmapCache& GetInstance() {
74 static SVGBitmapCache instance;
75 return instance;
76 }
77 SVGBitmapCache(SVGBitmapCache const&) = delete;
78 void operator=(SVGBitmapCache const&) = delete;
79
80 void Clear(bool disk = true) {
81 items.clear(); /*TODO: clear the disk cache as well*/
82 };
83
84 std::string MakeKey(wxString file_path, const int width, const int height);
85
86 bool HasKey(const wxString key);
87
88 wxBitmap Get(const wxString key);
89
90 void Add(const wxString, const wxBitmap bmp);
91
92private:
94 wxString cache_directory;
95 std::mutex sync;
96 std::unordered_map<std::string, wxBitmap> items;
97};
98
99#endif // OPENCPN_SVG_UTILS_H
Manage memory and disk cache for rendered bitmaps.
Definition svg_utils.h:71
wxBitmap LoadSVG(const wxString filename, const unsigned int width, const unsigned int height, wxBitmap *default_bitmap=NULL, bool use_cache=true)
Load SVG file and return it's bitmap representation of requested size In case file can't be loaded an...
Definition svg_utils.cpp:65
wxBitmap LoadSvgStdIcon(const std::string &svg_file, const wxWindow *w, bool touch)
Load an svg icon from standard path, roughly scaled to the height of a char.
bool SVGDocumentPixelSize(const wxString filename, unsigned int &width, unsigned int &height)
Return the size of the SVG document in standard 96 DPI pixels https://developer.mozilla....
unsigned int SVGPixelsToDisplay(unsigned int svg_px)
Recalculate the length in standard 96 DPI pixels to actual display pixels.