-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttontext.hh
74 lines (58 loc) · 2.03 KB
/
buttontext.hh
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
#ifndef _BUTTONTEXT_HH
#define _BUTTONTEXT_HH 1
#include <algorithm>
#include <cstdint>
#include <limits>
#include <tuple>
#include <vector>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <Magick++.h>
struct render_to_image {
render_to_image(const Magick::Color& background_, unsigned targetwidth_, unsigned targetheight_)
: background(Magick::Geometry(targetwidth_, targetheight_), background_), targetwidth(targetwidth_ ?: std::numeric_limits<unsigned>::max()), targetheight(targetheight_ ?: std::numeric_limits<unsigned>::max())
{
}
render_to_image(const Magick::Image& background_, double widthfactor = 1.0, double heightfactor = 1.0)
: background(background_), targetwidth(background.columns() * std::clamp(widthfactor, 0.0, 1.0)), targetheight(background.rows() * std::clamp(heightfactor, 0.0, 1.0))
{
}
void start() { lines.emplace_back(); }
void operator()(FT_GlyphSlot slot, FT_Int x){ render(slot, x); }
std::pair<double,FT_UInt> first_font_size();
void compute_dimensions();
std::pair<bool,double> check_size();
bool goodenough(unsigned w, unsigned h) const;
Magick::Image finish(Magick::Color foreground = Magick::Color("black"), double posx = 0.5, double posy = 0.5);
void reset() {
lines.clear();
}
private:
void render(FT_GlyphSlot slot, FT_Int x);
// Magick::Color background;
Magick::Image background;
unsigned targetwidth;
unsigned targetheight;
double current_fontsize = 0;
using experiment_type = std::tuple<double,unsigned,unsigned>;
std::vector<experiment_type> experiments;
struct slice {
slice(int x_, int y_, FT_GlyphSlot slot_);
int x;
int y;
unsigned width;
unsigned height;
std::vector<uint8_t> bitmap;
};
struct line_type {
std::vector<slice> slices;
int ymin = std::numeric_limits<int>::max();
int ymax = std::numeric_limits<int>::min();
};
std::vector<line_type> lines;
static constexpr double frac_linesep = 0.15;
unsigned maxwidth = 0;
unsigned totalheight = 0;
unsigned linesep = 0;
};
#endif // buttontext.hh