Repository navigation
Expand file tree
/
Copy pathfont.cpp
More file actions
59 lines (52 loc) · 2.29 KB
/
Copy pathfont.cpp
File metadata and controls
59 lines (52 loc) · 2.29 KB
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
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <render/text/element.hpp>
#include <data/font.hpp>
using std::max;
using std::min;
// ----------------------------------------------------------------------------- : FontTextElement
void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const {
if ((what & draw_as) != draw_as) return; // don't draw
// text
String text = content.substr(start - this->start, end - start);
if (!text.empty() && text.GetChar(text.size() - 1) == _('\n')) {
text = text.substr(0, text.size() - 1); // don't draw last \n
}
// draw
dc.SetFont(*font, scale);
dc.DrawTextWithShadow(text, *font, rect.position());
}
void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
// font
dc.SetFont(*font, scale);
// find sizes & breaks
double prev_width = 0;
size_t line_start = start; // start of the current line
for (size_t i = start ; i < end ; ++i) {
Char c = content.GetChar(i - this->start);
if (c == _('\n')) {
out.push_back(CharInfo(RealSize(0, dc.GetCharHeight()), break_style, draw_as == DRAW_ACTIVE));
line_start = i + 1;
prev_width = 0;
} else {
RealSize s = dc.GetTextExtent(content.substr(line_start - this->start, i - line_start + 1));
out.push_back(CharInfo(
RealSize(s.width - prev_width, s.height),
c == _(' ') ? BREAK_SPACE : BREAK_MAYBE,
draw_as == DRAW_ACTIVE // from <soft> tag
));
prev_width = s.width;
}
}
}
double FontTextElement::minScale() const {
return min(font->size(), font->scale_down_to) / max(0.01, font->size());
}
double FontTextElement::scaleStep() const {
return 1. / max(font->size() * 4, 1.);
}