-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdwrapper.h
110 lines (82 loc) · 2.55 KB
/
gdwrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* See the files COPYING and README for copyright information and how to reach
* the author.
*
* $Id: gdwrapper.h,v 1.4 2006/09/16 18:33:36 lordjaxom Exp $
*/
#ifndef VDR_BURN_GDWRAPPER_H
#define VDR_BURN_GDWRAPPER_H
#include <string>
#include <gd.h>
namespace gdwrapper
{
// --- font_spec ----------------------------------------------------------
struct font_spec
{
std::string face;
double size;
font_spec( const std::string& face_, double size_ ): face( face_ ), size( size_ ) {}
};
// --- point --------------------------------------------------------------
struct point
{
int x;
int y;
point( int x_, int y_ ): x( x_ ), y( y_ ) {}
};
// --- rectangle ----------------------------------------------------------
struct rectangle
{
int x;
int y;
int width;
int height;
rectangle( int x_, int y_, int width_, int height_ ): x( x_ ), y( y_ ), width( width_ ), height( height_ ) {}
};
// --- color --------------------------------------------------------------
struct color
{
int red;
int green;
int blue;
int alpha;
color( int red_, int green_, int blue_, int alpha_ = 0 ): red( red_ ), green( green_ ), blue( blue_ ), alpha( alpha_ ) {}
};
// --- text_spec ----------------------------------------------------------
struct text_spec
{
rectangle boundaries;
font_spec font;
color forecolor;
int align;
text_spec( const rectangle& boundaries_, const font_spec& font_, const color& forecolor_, int align_ = 0 ):
boundaries( boundaries_ ), font( font_ ), forecolor( forecolor_ ), align( align_ ) {}
};
// --- image --------------------------------------------------------------
class image
{
public:
image( int width, int height, bool alphaBlending = false );
image( const std::string& filename, bool alphaBlending = false );
~image();
void draw_image( const point& position, const image& image_ );
void fill_rectangle( const rectangle& rectangle, const color& color );
int draw_text( const text_spec& region, const std::string& text, int firstLine = 0 );
void save( const std::string& filename );
protected:
static std::string wrap_text( int width, int& lineHeight, const std::string& text, const font_spec& font );
private:
gdImagePtr m_image;
};
// --- setup --------------------------------------------------------------
class setup
{
public:
static void set_font_path( const std::string& path );
static const std::string& get_font_path() { return instance().m_fontPath; }
private:
std::string m_fontPath;
static setup& instance();
};
}
#endif // VDR_BURN_GDWRAPPER_H