wxMaxima
SvgBitmap.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2019 Gunter Königsmann <wxMaxima@physikbuch.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // SPDX-License-Identifier: GPL-2.0+
21 
28 #ifndef SVGBITMAP_H
29 #define SVGBITMAP_H
30 
31 #include "Cell.h"
32 
33 #include "precomp.h"
34 #include <wx/bitmap.h>
35 #define NANOSVG_ALL_COLOR_KEYWORDS
36 #include "nanoSVG/nanosvg.h"
37 #include "nanoSVG/nanosvgrast.h"
38 
41 class SvgBitmap: public wxBitmap
42 {
43 public:
45  SvgBitmap(const unsigned char *data, size_t len, int width = 640, int height = 480, int scaleFactor = 1);
46  SvgBitmap(const unsigned char *data, size_t len, wxSize siz, int scaleFactor = 1);
47  ~SvgBitmap() override;
48  SvgBitmap(SvgBitmap &&) = delete;
49  SvgBitmap &operator=(SvgBitmap &&o);
50 
52  static wxBitmap RGBA2wxBitmap(const unsigned char imgdata[],const int &width, const int &height, const int &scaleFactor = 1);
54  const SvgBitmap& SetSize(int width, int height);
56  const SvgBitmap& SetSize(wxSize siz){return SetSize(siz.x, siz.y);}
58  wxSize GetOriginalSize() const
59  { return m_svgImage ? wxSize(m_svgImage->width, m_svgImage->height) : wxDefaultSize; }
68  static wxBitmap GetInvalidBitmap(int targetSize);
69 private:
71  int m_scaleFactor;
73  static struct NSVGrasterizer* m_svgRast;
75  std::unique_ptr<NSVGimage, decltype(std::free)*> m_svgImage{nullptr, std::free};
76 };
77 
78 #endif // SVGBITMAP_H
SvgBitmap::SetSize
const SvgBitmap & SetSize(wxSize siz)
Sets the bitmap to a new size and renders the svg image at this size.
Definition: SvgBitmap.h:56
Cell.h
SvgBitmap::GetOriginalSize
wxSize GetOriginalSize() const
Gets the original size of the svg image.
Definition: SvgBitmap.h:58
SvgBitmap::GetInvalidBitmap
static wxBitmap GetInvalidBitmap(int targetSize)
Definition: SvgBitmap.cpp:121
SvgBitmap::SvgBitmap
SvgBitmap(const unsigned char *data, size_t len, int width=640, int height=480, int scaleFactor=1)
A constructor that loads the data into a wxBitmap.
Definition: SvgBitmap.cpp:36
SvgBitmap::RGBA2wxBitmap
static wxBitmap RGBA2wxBitmap(const unsigned char imgdata[], const int &width, const int &height, const int &scaleFactor=1)
Converts rgba data to a wxBitmap.
Definition: SvgBitmap.cpp:130
SvgBitmap
Definition: SvgBitmap.h:41
SvgBitmap::SetSize
const SvgBitmap & SetSize(int width, int height)
Sets the bitmap to a new size and renders the svg image at this size.
Definition: SvgBitmap.cpp:70
NSVGimage
Definition: nanosvg.h:158