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 
46 namespace Pt {
47 
48 namespace Gfx {
49 
50 class BitmapSurface;
51 
59 class PT_GFX_API Bitmap : public PaintSurface
60 {
61  public:
64  Bitmap();
65 
68  Bitmap(const Gfx::SizeF& size, std::size_t stride = 0);
69 
72  virtual ~Bitmap();
73 
76  void reset();
77 
80  void reset(const Gfx::Image& image);
81 
84  void reset(const Gfx::SizeF&, std::size_t stride = 0);
85 
88  bool empty() const;
89 
92  const Gfx::Image& image() const;
93 
96  void setScaleFactor(double scaleFactor);
97 
100  void drawBitmap(const Pt::Gfx::PointF& to, const Bitmap& image,
101  const Gfx::Paint& paint, const Gfx::RectF* rect = 0);
102 
103  protected:
104  virtual const Gfx::ImageFormat& onGetFormat() const;
105 
106  virtual const Gfx::SizeF& onGetSize() const;
107 
108  virtual const Scaling& onGetScaling() const;
109 
110  protected:
111  virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) override;
112 
113  virtual void onReleaseCanvas() override;
114 
115  virtual void onSync() override;
116 
117  virtual void onFinish() override;
118 
119  public:
122  static const std::string& defaultFont();
123 
126  static void setDefaultFont(const std::string& family);
127 
130  static std::vector<std::string> fontFamilies();
131 
134  static std::vector<FontFace> fontFaces(const std::string& family);
135 
136  private:
137  BitmapSurface* _surface;
138 };
139 
140 } // namespace
141 
142 } // namespace
143 
144 #endif
145 
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.
Core module.
Definition: Allocator.h:33
virtual Gfx::Canvas * onCreateCanvas(Gfx::Canvas *reuse) override
Creates a Canvas.
Paint state used by drawing operations.
Definition: Paint.h:50
void reset()
Resets to empty state.
static std::vector< FontFace > fontFaces(const std::string &family)
Returns the font faces of a family.
Backend canvas for drawing commands.
Definition: Canvas.h:66
static void setDefaultFont(const std::string &family)
Sets the default font family used by the backend.
virtual void onReleaseCanvas() override
Releases the current Canvas.
Logical-to-physical unit conversion.
Definition: Scaling.h:49
bool empty() const
Returns true if no image data is available.
Size with floating-point width and height.
Definition: Size.h:45
Point with floating-point X and Y coordinates.
Definition: Point.h:45
Image format.
Definition: ImageFormat.h:53
virtual const Gfx::ImageFormat & onGetFormat() const
Returns the image format.
void reset(const Gfx::Image &image)
Replaces the bitmap with an existing image.
Abstract target for drawing operations.
Definition: PaintSurface.h:55
static const std::string & defaultFont()
Returns the default font family used by the backend.
void reset(const Gfx::SizeF &, std::size_t stride=0)
Resets the bitmap to a new size in physical pixels.
virtual const Scaling & onGetScaling() const
Returns the scaling fro logical to physical pixels.
virtual ~Bitmap()
Destroys the bitmap.
Basic image.
Definition: Image.h:52
virtual void onFinish() override
Finishes painting to the surface.
void setScaleFactor(double scaleFactor)
Sets the target scale factor.
Bitmap()
Constructs an empty bitmap.
virtual const Gfx::SizeF & onGetSize() const
Returns the size in physical pixel.
virtual void onSync() override
Synchronizes pending operations to the surface.
Rect with floating-point coordinates.
Definition: Rect.h:45
Off-screen drawing surface backed by an image.
Definition: Bitmap.h:60
Bitmap(const Gfx::SizeF &size, std::size_t stride=0)
Constructs a bitmap with the given size and optional stride.
const Gfx::Image & image() const
Returns the underlying image.
static std::vector< std::string > fontFamilies()
Returns the available font families.