Skip to content

Commit dbb6d34

Browse files
committed
Add <font:$family> tag, closes #24
1 parent 41ed84e commit dbb6d34

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

CHANGES.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Bug fixes:
1717
* length function now gives correct results for maps
1818
* substr("foo",begin:3) now returns "" instead of true
1919

20+
Template features:
21+
* Added <font:...> tag to change the font inside a text field.
22+
2023
Scripting:
2124
* Added type_name function
2225
* nil != "", so missing values are no longer equal to the empty string
@@ -26,7 +29,7 @@ Scripting:
2629

2730
Internal:
2831
* Switch build system to to CMake
29-
* Update code to work with wxWidgets 3.0/3.1 and C++ 17
32+
* Update code to work with wxWidgets 3.1 and C++ 17
3033
* Lots of code cleanup
3134

3235
------------------------------------------------------------------------------

doc/type/tagged_string.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is written as the character with code 1 in files.
1717
| @<sym>@ The text inside the tag is rendered as symbols, if a [[prop:style:symbol font]] is set for the text box.
1818
| @<color:???>@ The text inside the tag is rendered with the given [[type:color]].
1919
| @<size:???>@ The text inside the tag is rendered with the given font size in points, for example @"<size:12>text</size>"@ makes the text 12 points. The text is scaled down proportionally when it does not fit in a text box and the @scale down to@ attribute allows it.
20+
| @<font:???>@ The text inside the tag is rendered with the given font family.
2021
| @<line>@ Line breaks inside this tag use the [[prop:style:line height line]], and they show a horizontal line.
2122
| @<soft-line>@ Line breaks inside this tag use the [[prop:style:soft line height]].
2223
| @<atom>@ An atomic piece of text. The cursor can never be inside it; it is selected as a whole.

src/data/font.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const {
5050
shadow_color.initDependencies(ctx, dep);
5151
}
5252

53-
FontP Font::make(int add_flags, Color* other_color, double* other_size) const {
53+
FontP Font::make(int add_flags, String const* other_family, Color const* other_color, double const* other_size) const {
5454
FontP f(new Font(*this));
5555
f->flags |= add_flags;
5656
if (add_flags & FONT_CODE_STRING) {
@@ -73,6 +73,9 @@ FontP Font::make(int add_flags, Color* other_color, double* other_size) const {
7373
if (other_size) {
7474
f->size = *other_size;
7575
}
76+
if (other_family && !other_family->empty()) {
77+
f->name = *other_family;
78+
}
7679
return f;
7780
}
7881

src/data/font.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Font : public IntrusivePtrBase<Font> {
5959
return shadow_displacement.width != 0 || shadow_displacement.height != 0;
6060
}
6161

62-
/// Add style to a font, and optionally change the color and size
63-
FontP make(int add_flags, Color* other_color, double* other_size) const;
62+
/// Add style to a font, and optionally change the font family, color and size
63+
FontP make(int add_flags, String const* other_family, Color const* other_color, double const* other_size) const;
6464

6565
/// Convert this font to a wxFont
6666
wxFont toWxFont(double scale) const;

src/render/text/element.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct TextElementsFromString {
7878
int param_id;
7979
vector<Color> colors;
8080
vector<double> sizes;
81+
vector<String> fonts;
8182
/// put angle brackets around the text?
8283
bool bracket;
8384

@@ -138,6 +139,14 @@ struct TextElementsFromString {
138139
} else if (is_substr(text, tag_start, _("</color"))) {
139140
if (!colors.empty()) colors.pop_back();
140141
}
142+
else if (is_substr(text, tag_start, _( "<font"))) {
143+
size_t colon = text.find_first_of(_(">:"), tag_start);
144+
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
145+
fonts.push_back(text.substr(colon+1, pos-colon-2));
146+
}
147+
} else if (is_substr(text, tag_start, _("</font"))) {
148+
if (!fonts.empty()) fonts.pop_back();
149+
}
141150
else if (is_substr(text, tag_start, _( "<size"))) {
142151
size_t colon = text.find_first_of(_(">:"), tag_start);
143152
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
@@ -251,6 +260,7 @@ struct TextElementsFromString {
251260
(code > 0 ? FONT_CODE : FONT_NORMAL) |
252261
(code_kw > 0 ? FONT_CODE_KW : FONT_NORMAL) |
253262
(code_string > 0 ? FONT_CODE_STRING : FONT_NORMAL),
263+
fonts.empty() ? nullptr : &fonts.back(),
254264
param > 0 || param_ref > 0
255265
? &param_colors[(param_id++) % param_colors_count]
256266
: !colors.empty()

src/util/tagged_string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void check_tagged(const String& str, bool check_balance) {
613613
}
614614
for (size_t j = i + 1 ; j + 1 < end ; ++j) {
615615
Char c = str.GetChar(j);
616-
if (c == _(' ') || c == _('<')) {
616+
if (c == ESCAPED_LANGLE || c == _('<')) {
617617
queue_message(MESSAGE_WARNING, _("Invalid character in tag"));
618618
}
619619
}

0 commit comments

Comments
 (0)