Added <soft> tag that takes up no space for alignment purposes;

used this tag for magic creature types;
Added correct handling of Tribal sub types;
Fixed sort_index use by spoiler export template

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@637 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-08-28 20:49:25 +00:00
parent a360b334c5
commit 087af8360d
11 changed files with 94 additions and 66 deletions
+1 -1
View File
@@ -1297,7 +1297,7 @@ void TextValueEditor::clearWordListIndicators(RotatedDC& dc) {
}
// restore background
if (wl->behind.Ok()) {
dc.DrawBitmap(wl->behind, wl->rect.topRight() + RealSize(0,-1));
dc.DrawPreRotatedBitmap(wl->behind, wl->rect.topRight() + RealSize(0,-1));
}
}
}
+4 -2
View File
@@ -33,12 +33,12 @@ void TextElements::getCharInfo(RotatedDC& dc, double scale, size_t start, size_t
FOR_EACH_CONST(e, elements) {
// characters before this element, after the previous
while (out.size() < e->start) {
out.push_back(CharInfo(RealSize(0,0), BREAK_NO));
out.push_back(CharInfo());
}
e->getCharInfo(dc, scale, out);
}
while (out.size() < end) {
out.push_back(CharInfo(RealSize(0,0), BREAK_NO));
out.push_back(CharInfo());
}
}
@@ -100,6 +100,8 @@ struct TextElementsFromString {
else if (is_substr(text, tag_start, _("</sym"))) symbol -= 1;
else if (is_substr(text, tag_start, _( "<sep-soft"))) soft += 1;
else if (is_substr(text, tag_start, _("</sep-soft"))) soft -= 1;
else if (is_substr(text, tag_start, _( "<soft"))) soft += 1;
else if (is_substr(text, tag_start, _("</soft"))) soft -= 1;
else if (is_substr(text, tag_start, _( "<atom-kwpph"))) kwpph += 1;
else if (is_substr(text, tag_start, _("</atom-kwpph"))) kwpph -= 1;
else if (is_substr(text, tag_start, _( "<code-kw"))) code_kw += 1;
+10 -4
View File
@@ -42,10 +42,16 @@ enum LineBreak
/// Information on a character in a TextElement
struct CharInfo {
RealSize size;
LineBreak break_after;
RealSize size; ///< Size of this character
LineBreak break_after : 31; ///< How/when to break after it?
bool soft : 1; ///< Is this a 'soft' character? soft characters are ignored for alignment
inline CharInfo(RealSize size, LineBreak break_after) : size(size), break_after(break_after) {}
explicit CharInfo()
: break_after(BREAK_NO), soft(true)
{}
inline CharInfo(RealSize size, LineBreak break_after, bool soft = false)
: size(size), break_after(break_after), soft(soft)
{}
};
/// A section of text that can be rendered using a TextViewer
@@ -74,7 +80,7 @@ class TextElement : public IntrusivePtrBase<TextElement> {
// ----------------------------------------------------------------------------- : TextElements
/// A list of text elements
class TextElements : public vector<TextElementP> {
class TextElements {
public:
/// Draw all the elements (as need to show the range start..end)
void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const;
+5 -3
View File
@@ -37,13 +37,15 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>&
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));
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
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;
}
+23 -17
View File
@@ -16,6 +16,7 @@ DECLARE_TYPEOF_COLLECTION(double);
struct TextViewer::Line {
size_t start; ///< Index of the first character in this line
size_t end_or_soft; ///< Index just beyond the last non-soft character
vector<double> positions; ///< x position of each character in this line, gives the number of characters + 1, never empty
double top; ///< y position of (the top of) this line
double line_height; ///< The height of this line in pixels
@@ -23,13 +24,13 @@ struct TextViewer::Line {
//% Alignment alignment; ///< Alignment of this line
Line()
: start(0), top(0), line_height(0), break_after(BREAK_NO)
: start(0), end_or_soft(0), top(0), line_height(0), break_after(BREAK_NO)
{}
/// The position (just beyond) the bottom of this line
double bottom() const { return top + line_height; }
/// The width of this line
double width() const { return positions.back() - positions.front(); }
double width() const { return positions[end_or_soft-start] - positions.front(); }
/// Index just beyond the last character on this line
size_t end() const { return start + positions.size() - 1; }
/// Find the index of the character at the given position on this line
@@ -158,7 +159,7 @@ bool TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Co
}
}
void TextViewer::reset(bool related) {
elements.clear();
elements.elements.clear();
lines.clear();
if (!related) scale = 1.0;
}
@@ -169,6 +170,7 @@ bool TextViewer::prepared() const {
// ----------------------------------------------------------------------------- : Positions
const TextViewer::Line& TextViewer::findLine(size_t index) const {
assert(!lines.empty());
FOR_EACH_CONST(l, lines) {
if (l.end() >= index) return l;
}
@@ -295,6 +297,7 @@ void TextViewer::scrollBy(double delta) {
}
bool TextViewer::ensureVisible(double height, size_t char_id) {
if (lines.empty()) return true;
const Line& line = findLine(char_id);
if (line.top < 0) {
// scroll up
@@ -511,6 +514,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
// The word we are currently reading
RealSize word_size;
vector<double> positions_word; // positios for this word
size_t word_end_or_soft = 0;
size_t word_start = 0;
// For each character ...
for(size_t i = 0 ; i < chars.size() ; ++i) {
@@ -539,6 +543,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
word_size = add_horizontal(word_size, c.size);
}
positions_word.push_back(word_size.width);
if (!c.soft) word_end_or_soft = i + 1;
// Did the word become too long?
if (style.field().multi_line && !break_now) {
double max_width = lineRight(dc, style, line.top);
@@ -565,11 +570,13 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
FOR_EACH(p, positions_word) {
line.positions.push_back(line_size.width + p);
}
// add size; next word
if (word_end_or_soft != 0) line.end_or_soft = word_end_or_soft;
line_size = add_horizontal(line_size, word_size);
// next word
word_size = RealSize(0, 0);
word_start = i + 1;
positions_word.clear();
word_end_or_soft = 0;
}
// Breaking (ending the current line)
if (break_now) {
@@ -583,10 +590,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
} else {
line.line_height = line_size.height;
}
// // too low?
// if (stop_if_too_long && line.bottom() > dc.getInternalSize().height - style.padding_bottom) {
// return false;
// }
line.end_or_soft = max(line.start, min(line.end_or_soft, line.end()));
// push
lines.push_back(line);
// reset line object for next line
@@ -612,6 +616,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
FOR_EACH(p, positions_word) {
line.positions.push_back(line_size.width + p);
}
if (word_end_or_soft != 0) line.end_or_soft = word_end_or_soft;
line_size = add_horizontal(line_size, word_size);
// the last line
if (line_size.height < 0.01 && !lines.empty()) {
@@ -619,6 +624,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
} else {
line.line_height = line_size.height;
}
line.end_or_soft = max(line.start, min(line.end_or_soft, line.end()));
lines.push_back(line);
// does it fit vertically?
return lines.empty() ||
@@ -688,14 +694,14 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
FOR_EACH(l, lines) {
l.top += vdelta;
// amount to shift all characters horizontally
double width = l.positions.back();
double width = l.positions[l.end_or_soft - l.start];
if ((style.alignment & ALIGN_JUSTIFY) ||
(style.alignment & ALIGN_JUSTIFY_OVERFLOW && width > s.width)) {
// justify text
justifying = true;
double hdelta = s.width - width; // amount of space to distribute
int count = (int)l.positions.size() - 1; // distribute it among this many characters
if (count == 0) count = 1; // prevent div by 0
double hdelta = s.width - width; // amount of space to distribute
int count = (int)(l.end_or_soft - l.start); // distribute it among this many characters
if (count <= 0) count = 1; // prevent div by 0
int i = 0;
FOR_EACH(c, l.positions) {
c += hdelta * i++ / count;
@@ -703,16 +709,16 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
} else if (style.alignment & ALIGN_JUSTIFY_WORDS) {
// justify text, by words
justifying = true;
double hdelta = s.width - width; // amount of space to distribute
int count = 0; // distribute it among this many words
for (size_t k = l.start + 1 ; k < l.end() - 1 ; ++k) {
double hdelta = s.width - width; // amount of space to distribute
int count = 0; // distribute it among this many words
for (size_t k = l.start + 1 ; k < l.end_or_soft - 1 ; ++k) {
if (chars[k].break_after == BREAK_SPACE) ++count;
}
if (count == 0) count = 1; // prevent div by 0
if (count == 0) count = 1; // prevent div by 0
int i = 0; size_t j = l.start;
FOR_EACH(c, l.positions) {
c += hdelta * i / count;
if (j < l.end() && chars[j++].break_after == BREAK_SPACE) i++;
if (j < l.end_or_soft && chars[j++].break_after == BREAK_SPACE) i++;
}
} else {
// simple alignment
+1 -1
View File
@@ -190,7 +190,7 @@ void TokenIterator::readToken() {
filename = include_file;
InputStreamP is = packages.openFileFromPackage(include_file);
input = read_utf8_line(*is, true, true);
} else if (isAlpha(c)) {
} else if (isAlpha(c) || c == _('_')) {
// name
size_t start = pos - 1;
while (pos < input.size() && isAlnum_(input.GetChar(pos))) ++pos;
+4 -4
View File
@@ -153,7 +153,7 @@ void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_ra
void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
if (angle == 0) {
RealPoint p_ext = tr(pos);
dc.DrawBitmap(bitmap, (int) p_ext.x, (int) p_ext.y, true);
dc.DrawBitmap(bitmap, to_int(p_ext.x), to_int(p_ext.y), true);
} else {
DrawImage(bitmap.ConvertToImage(), pos);
}
@@ -161,15 +161,15 @@ void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
void RotatedDC::DrawImage (const Image& image, const RealPoint& pos, ImageCombine combine, int angle) {
Image rotated = rotate_image(image, angle + this->angle);
wxRect r = trNoNegNoZoom(RealRect(pos, RealSize(image)));
draw_combine_image(dc, r.x, r.y, rotated, combine);
draw_combine_image(dc, to_int(r.x), to_int(r.y), rotated, combine);
}
void RotatedDC::DrawPreRotatedBitmap(const Bitmap& bitmap, const RealPoint& pos) {
RealPoint p_ext = tr(pos) - RealSize(revX()?bitmap.GetWidth():0, revY()?bitmap.GetHeight():0);
dc.DrawBitmap(bitmap, (int) p_ext.x, (int) p_ext.y, true);
dc.DrawBitmap(bitmap, to_int(p_ext.x), to_int(p_ext.y), true);
}
void RotatedDC::DrawPreRotatedImage (const Image& image, const RealPoint& pos, ImageCombine combine) {
RealPoint p_ext = tr(pos) - RealSize(revX()?image.GetWidth():0, revY()?image.GetHeight():0);
draw_combine_image(dc, p_ext.x, p_ext.y, image, combine);
draw_combine_image(dc, to_int(p_ext.x), to_int(p_ext.y), image, combine);
}
void RotatedDC::DrawLine (const RealPoint& p1, const RealPoint& p2) {
+1 -1
View File
@@ -166,7 +166,7 @@ String cannocial_name_form(const String& str) {
bool leading = true;
FOR_EACH_CONST(c, str) {
if ((c == _('_') || c == _(' '))) {
if (!leading) ret += _(' ');
ret += leading ? c : _(' ');
} else {
ret += c;
leading = false;