Bitmap.h
1/* Copyright (C) 2015 Marc Boris Duerner
2 Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef PT_GFX_BITMAP_H
31#define PT_GFX_BITMAP_H
32
33#include <Pt/Gfx/Api.h>
34#include <Pt/Gfx/FontFace.h>
35#include <Pt/Gfx/PaintSurface.h>
36#include <Pt/Gfx/Paint.h>
37#include <Pt/Gfx/Point.h>
38#include <Pt/Gfx/Size.h>
39#include <Pt/Gfx/Rect.h>
40#include <Pt/System/Path.h>
41
42#include <string>
43#include <vector>
44#include <cstddef>
45
46namespace Pt {
47
48namespace Gfx {
49
50class BitmapSurface;
51
70class PT_GFX_API Bitmap : public PaintSurface
71{
72 public:
76
79 Bitmap(const Gfx::SizeF& size, std::size_t stride = 0);
80
83 virtual ~Bitmap();
84
87 void reset();
88
94 void reset(const Gfx::Image& image);
95
101 void reset(const Gfx::SizeF&, std::size_t stride = 0);
102
105 bool empty() const;
106
109 const Gfx::Image& image() const;
110
113 void setScaleFactor(double scaleFactor);
114
117 void drawBitmap(const Pt::Gfx::PointF& to, const Bitmap& image,
118 const Gfx::Paint& paint, const Gfx::RectF* rect = 0);
119
120 protected:
121 virtual const Gfx::ImageFormat& onGetFormat() const;
122
123 virtual const Gfx::SizeF& onGetSize() const;
124
125 virtual const Scaling& onGetScaling() const;
126
127 protected:
128 virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) override;
129
130 virtual void onReleaseCanvas() override;
131
132 virtual void onSync() override;
133
134 virtual void onFinish() override;
135
136 public:
139 static const std::string& defaultFont();
140
143 static void setDefaultFont(const std::string& family);
144
147 static std::vector<std::string> fontFamilies();
148
151 static std::vector<FontFace> fontFaces(const std::string& family);
152
153 private:
154 BitmapSurface* _surface;
155};
156
157} // namespace
158
159} // namespace
160
161#endif
162
void drawBitmap(const Pt::Gfx::PointF &to, const Bitmap &image, const Gfx::Paint &paint, const Gfx::RectF *rect=0)
Draws another bitmap into this bitmap.
virtual void onReleaseCanvas() override
Releases the current Canvas.
void reset(const Gfx::SizeF &, std::size_t stride=0)
Resets the bitmap to a new size in physical pixels.
void reset(const Gfx::Image &image)
Replaces the bitmap with an existing image.
static std::vector< FontFace > fontFaces(const std::string &family)
Returns the font faces of a family.
virtual Gfx::Canvas * onCreateCanvas(Gfx::Canvas *reuse) override
Creates a Canvas.
virtual void onFinish() override
Finishes painting to the surface.
void setScaleFactor(double scaleFactor)
Sets the target scale factor.
Bitmap(const Gfx::SizeF &size, std::size_t stride=0)
Constructs a bitmap with the given size and optional stride.
virtual const Gfx::ImageFormat & onGetFormat() const
Returns the image format.
bool empty() const
Returns true if no image data is available.
virtual const Gfx::SizeF & onGetSize() const
Returns the size in physical pixel.
virtual void onSync() override
Synchronizes pending operations to the surface.
virtual const Scaling & onGetScaling() const
Returns the scaling fro logical to physical pixels.
virtual ~Bitmap()
Destroys the bitmap.
static const std::string & defaultFont()
Returns the default font family used by the backend.
static std::vector< std::string > fontFamilies()
Returns the available font families.
static void setDefaultFont(const std::string &family)
Sets the default font family used by the backend.
void reset()
Resets to empty state.
const Gfx::Image & image() const
Returns the underlying image.
Bitmap()
Constructs an empty bitmap.
Backend that executes drawing commands.
Definition Canvas.h:66
Runtime pixel format.
Definition ImageFormat.h:72
PaintSurface()
Default constructor.
const Gfx::SizeF & size() const
Returns the size in physical pixels.
Pen, brush, font and composition mode.
Definition Paint.h:53
Conversion between logical units and pixels.
Definition Scaling.h:52
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33