mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Margin top in <margin> tag
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ Template features:
|
|||||||
* Added <font:...> tag to change the font inside a text field.
|
* Added <font:...> tag to change the font inside a text field.
|
||||||
* Added <margin:...> tag to change the margins of a block of text.
|
* Added <margin:...> tag to change the margins of a block of text.
|
||||||
* Added <align:...> tag to change the horizontal alignment of a block of text.
|
* Added <align:...> tag to change the horizontal alignment of a block of text.
|
||||||
* Added <li> tag for list bullet points.
|
* Added <li> tag for list bullet points. (Experimental!)
|
||||||
* Colors can now be written using hex notation, #rrggbb / #rrggbbaa, and short hex notation (#rgb / #rgba)
|
* Colors can now be written using hex notation, #rrggbb / #rrggbbaa, and short hex notation (#rgb / #rgba)
|
||||||
|
|
||||||
Scripting:
|
Scripting:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ This is written as the character with code 1 in files.
|
|||||||
| @<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.
|
| @<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.
|
||||||
| @<font:???>@ The text inside the tag is rendered with the given font family.
|
| @<font:???>@ The text inside the tag is rendered with the given font family.
|
||||||
| @<align:???>@ The block inside the tag is aligned with the given horizontal [[type:alignment]]
|
| @<align:???>@ The block inside the tag is aligned with the given horizontal [[type:alignment]]
|
||||||
| @<margin:??:??>@ The block inside the tag has additional left and right (optional) margins of the specified size in pixels.
|
| @<margin:??:??>@ The block inside the tag has additional left, right (optional), and top (optional) margins of the specified size in pixels.
|
||||||
| @<li>@ The text inside the tag is treated as a list marker, meaning that if the line wraps it will be indented to match the content of the @<li>@ tag.
|
| @<li>@ The text inside the tag is treated as a list marker, meaning that if the line wraps it will be indented to match the content of the @<li>@ tag.
|
||||||
| @<line>@ Line breaks inside this tag use the [[prop:style:line height line]], and they show a horizontal line.
|
| @<line>@ Line breaks inside this tag use the [[prop:style:line height line]], and they show a horizontal line.
|
||||||
| @<soft-line>@ Line breaks inside this tag use the [[prop:style:soft line height]].
|
| @<soft-line>@ Line breaks inside this tag use the [[prop:style:soft line height]].
|
||||||
|
|||||||
+21
-12
@@ -27,6 +27,10 @@ Color param_colors[] =
|
|||||||
};
|
};
|
||||||
const size_t param_colors_count = sizeof(param_colors) / sizeof(param_colors[0]);
|
const size_t param_colors_count = sizeof(param_colors) / sizeof(param_colors[0]);
|
||||||
|
|
||||||
|
struct Margins {
|
||||||
|
double left, right, top;
|
||||||
|
};
|
||||||
|
|
||||||
// Helper class for TextElements::fromString, to allow persistent formating state accross recusive calls
|
// Helper class for TextElements::fromString, to allow persistent formating state accross recusive calls
|
||||||
struct TextElementsFromString {
|
struct TextElementsFromString {
|
||||||
// What formatting is enabled?
|
// What formatting is enabled?
|
||||||
@@ -37,7 +41,7 @@ struct TextElementsFromString {
|
|||||||
vector<Color> colors;
|
vector<Color> colors;
|
||||||
vector<double> sizes;
|
vector<double> sizes;
|
||||||
vector<String> fonts;
|
vector<String> fonts;
|
||||||
vector<pair<double,double>> margins;
|
vector<Margins> margins;
|
||||||
vector<Alignment> aligns;
|
vector<Alignment> aligns;
|
||||||
|
|
||||||
const TextStyle& style;
|
const TextStyle& style;
|
||||||
@@ -168,17 +172,21 @@ private:
|
|||||||
} else if (is_substr(text, tag_start, _("<margin"))) {
|
} else if (is_substr(text, tag_start, _("<margin"))) {
|
||||||
size_t colon = text.find_first_of(_(">:"), tag_start);
|
size_t colon = text.find_first_of(_(">:"), tag_start);
|
||||||
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
|
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
|
||||||
size_t colon2 = text.find_first_of(_(">:"), colon+1);
|
size_t colon2 = text.find_first_of(_(">:"), colon + 1);
|
||||||
double margin_left = 0., margin_right = 0.;
|
size_t colon3 = colon2 < pos-1 ? text.find_first_of(_(">:"), colon2 + 1) : colon2;
|
||||||
text.substr(colon + 1, colon2 - colon - 2).ToDouble(&margin_left);
|
Margins m = {0.,0.,0.};
|
||||||
text.substr(colon2 + 1, pos - colon2 - 2).ToDouble(&margin_right);
|
text.substr(colon + 1, colon2 - colon - 2).ToDouble(&m.left);
|
||||||
|
text.substr(colon2 + 1, colon3 - colon2 - 2).ToDouble(&m.right);
|
||||||
|
text.substr(colon3 + 1, pos - colon3 - 2).ToDouble(&m.top);
|
||||||
if (!margins.empty()) {
|
if (!margins.empty()) {
|
||||||
margin_left += margins.back().first;
|
m.left += margins.back().left;
|
||||||
margin_right += margins.back().second;
|
m.right += margins.back().right;
|
||||||
|
m.top += margins.back().top;
|
||||||
}
|
}
|
||||||
margins.emplace_back(margin_left, margin_right);
|
margins.emplace_back(m);
|
||||||
paragraphs.back().margin_left = margin_left;
|
paragraphs.back().margin_left = m.left;
|
||||||
paragraphs.back().margin_right = margin_right;
|
paragraphs.back().margin_right = m.right;
|
||||||
|
paragraphs.back().margin_top = m.top;
|
||||||
}
|
}
|
||||||
} else if (is_substr(text, tag_start, _("</margin"))) {
|
} else if (is_substr(text, tag_start, _("</margin"))) {
|
||||||
if (!margins.empty()) margins.pop_back();
|
if (!margins.empty()) margins.pop_back();
|
||||||
@@ -267,8 +275,9 @@ private:
|
|||||||
paragraphs.back().start = i + 1;
|
paragraphs.back().start = i + 1;
|
||||||
paragraphs.back().margin_end_char = i + 1;
|
paragraphs.back().margin_end_char = i + 1;
|
||||||
if (!margins.empty()) {
|
if (!margins.empty()) {
|
||||||
paragraphs.back().margin_left = margins.back().first;
|
paragraphs.back().margin_left = margins.back().left;
|
||||||
paragraphs.back().margin_right = margins.back().second;
|
paragraphs.back().margin_right = margins.back().right;
|
||||||
|
paragraphs.back().margin_top = margins.back().top;
|
||||||
}
|
}
|
||||||
if (!aligns.empty()) {
|
if (!aligns.empty()) {
|
||||||
paragraphs.back().alignment = aligns.back();
|
paragraphs.back().alignment = aligns.back();
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class TextParagraph {
|
|||||||
public:
|
public:
|
||||||
optional<Alignment> alignment;
|
optional<Alignment> alignment;
|
||||||
double margin_left = 0., margin_right = 0.;
|
double margin_left = 0., margin_right = 0.;
|
||||||
//double margin_top = 0., margin_bottom = 0.; // TODO: more margin options?
|
double margin_top = 0.; //, margin_bottom = 0.; // TODO: more margin options?
|
||||||
size_t start = String::npos, end = String::npos;
|
size_t start = String::npos, end = String::npos;
|
||||||
size_t margin_end_char = 0; // end position of characters that are added to the margin (i.e. bullet points)
|
size_t margin_end_char = 0; // end position of characters that are added to the margin (i.e. bullet points)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -691,6 +691,7 @@ bool TextViewer::prepareLinesAtScale(RotatedDC& dc, const vector<CharInfo>& char
|
|||||||
assert(elements.paragraphs[i_para].start == i + 1);
|
assert(elements.paragraphs[i_para].start == i + 1);
|
||||||
line.margin_left = elements.paragraphs[i_para].margin_left;
|
line.margin_left = elements.paragraphs[i_para].margin_left;
|
||||||
line.margin_right = elements.paragraphs[i_para].margin_right;
|
line.margin_right = elements.paragraphs[i_para].margin_right;
|
||||||
|
line.top += elements.paragraphs[i_para].margin_top;
|
||||||
line.alignment = elements.paragraphs[i_para].alignment;
|
line.alignment = elements.paragraphs[i_para].alignment;
|
||||||
}
|
}
|
||||||
line.break_after = LineBreak::NO;
|
line.break_after = LineBreak::NO;
|
||||||
|
|||||||
Reference in New Issue
Block a user