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, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef OPENCPN_SVG_UTILS_H
25#define OPENCPN_SVG_UTILS_H
26
27#include <wx/wxprec.h>
28
29#ifndef WX_PRECOMP
30#include <wx/wx.h>
31#endif // precompiled headers
32
33#include <string>
34#include <mutex>
35#include <unordered_map>
36
37#include <wx/string.h>
38
44wxBitmap LoadSVG(const wxString filename, const unsigned int width,
45 const unsigned int height, wxBitmap* default_bitmap = NULL,
46 bool use_cache = true);
47
54bool SVGDocumentPixelSize(const wxString filename, unsigned int& width,
55 unsigned int& height);
56
58unsigned int SVGPixelsToDisplay(unsigned int svg_px);
59
65wxBitmap LoadSvgStdIcon(const std::string& svg_file, const wxWindow* w,
66 bool touch);
67
70public:
71 static SVGBitmapCache& GetInstance() {
72 static SVGBitmapCache instance;
73 return instance;
74 }
75 SVGBitmapCache(SVGBitmapCache const&) = delete;
76 void operator=(SVGBitmapCache const&) = delete;
77
78 void Clear(bool disk = true) {
79 items.clear(); /*TODO: clear the disk cache as well*/
80 };
81
82 std::string MakeKey(wxString file_path, const int width, const int height);
83
84 bool HasKey(const wxString key);
85
86 wxBitmap Get(const wxString key);
87
88 void Add(const wxString, const wxBitmap bmp);
89
90private:
92 wxString cache_directory;
93 std::mutex sync;
94 std::unordered_map<std::string, wxBitmap> items;
95};
96
97#endif // OPENCPN_SVG_UTILS_H
Manage memory and disk cache for rendered bitmaps.
Definition svg_utils.h:69
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:59
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.