From ca3b7b91b4534b7fcf80227f015eecc5ac7fbe5d Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 24 Dec 2006 15:03:52 +0000 Subject: [PATCH] support git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@166 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field/text.cpp | 2 +- src/render/text/element.cpp | 5 ++++- src/render/text/element.hpp | 4 ++-- src/render/text/font.cpp | 15 ++++++--------- src/render/text/symbol.cpp | 2 +- src/render/text/viewer.cpp | 14 ++++++++++++-- src/util/tagged_string.cpp | 4 ++++ 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/data/field/text.cpp b/src/data/field/text.cpp index 3557bb0f..d83d0d9a 100644 --- a/src/data/field/text.cpp +++ b/src/data/field/text.cpp @@ -91,7 +91,7 @@ IMPLEMENT_REFLECTION(TextStyle) { // ----------------------------------------------------------------------------- : TextValue String TextValue::toString() const { - return untag(value()); + return untag_hide_sep(value()); } bool TextValue::update(Context& ctx) { Value::update(ctx); diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp index 85a07a9d..137a85e6 100644 --- a/src/render/text/element.cpp +++ b/src/render/text/element.cpp @@ -100,7 +100,10 @@ struct TextElementsFromString { if (symbol > 0 && style.symbol_font.valid()) { te.elements.push_back(new_shared5(text, pos, pos + 1, style.symbol_font, &ctx)); } else { - te.elements.push_back(new_shared5 (text, pos, pos + 1, style.font.make(bold > 0, italic > 0), line > 0 ? BREAK_LINE : BREAK_HARD)); + te.elements.push_back(new_shared6 (text, pos, pos + 1, + style.font.make(bold > 0, italic > 0), + soft > 0 ? DRAW_ACTIVE : DRAW_NORMAL, + line > 0 ? BREAK_LINE : BREAK_HARD)); } } pos += 1; diff --git a/src/render/text/element.hpp b/src/render/text/element.hpp index fac8e7d9..348b1bc5 100644 --- a/src/render/text/element.hpp +++ b/src/render/text/element.hpp @@ -126,9 +126,9 @@ class SimpleTextElement : public TextElement { /// A text element that uses a normal font class FontTextElement : public SimpleTextElement { public: - FontTextElement(const String& text, size_t start ,size_t end, const FontP& font, LineBreak break_style) + FontTextElement(const String& text, size_t start ,size_t end, const FontP& font, DrawWhat draw_as, LineBreak break_style) : SimpleTextElement(text, start, end) - , font(font), break_style(break_style) + , font(font), draw_as(draw_as), break_style(break_style) {} virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; diff --git a/src/render/text/font.cpp b/src/render/text/font.cpp index 08b3383e..998a77ca 100644 --- a/src/render/text/font.cpp +++ b/src/render/text/font.cpp @@ -12,17 +12,14 @@ // ----------------------------------------------------------------------------- : 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 dc.SetFont(font->font, font->size * scale); - if (end != start && text.substr(end-1, 1) == _("\n")) end -= 1; // don't draw the newline character at the end -/* if ((draw & DRAW_NORMAL) != DRAW_NORMAL) { - // don't draw - if (what == DRAW_ACTIVE) { + if (draw_as == DRAW_ACTIVE) { // we are drawing a separator dc.SetTextForeground(font->separator_color); - dc.DrawText(text.substr(start, end-start), rect.position); - } - } else {*/ + dc.DrawText(text.substr(start, end-start), rect.position()); + } else { // draw normally // draw shadow if (font->hasShadow()) { @@ -32,7 +29,7 @@ void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co // draw dc.SetTextForeground(font->color); dc.DrawText(text.substr(start, end - start), rect.position()); -// } + } } void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector& out) const { @@ -52,5 +49,5 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector& } double FontTextElement::minScale() const { - return 1; // TODO + return min(font->size, font->scale_down_to) / max(0.01, font->size); } diff --git a/src/render/text/symbol.cpp b/src/render/text/symbol.cpp index 0cf34652..421a0bdf 100644 --- a/src/render/text/symbol.cpp +++ b/src/render/text/symbol.cpp @@ -24,5 +24,5 @@ void SymbolTextElement::getCharInfo(RotatedDC& dc, double scale, vector chars; + // try to layout, at different scales + scale = 1; +// double min_scale = elements.minScale(); +// while + chars.clear(); elements.getCharInfo(dc, scale, 0, text.size(), chars); - // try to layout prepareLinesScale(dc, chars, style, false); // no text, find a dummy height for the single line we have if (lines.size() == 1 && lines[0].width() < 0.0001) { @@ -321,6 +324,13 @@ void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle } // align alignLines(dc, chars, style); + // HACK : fix empty first line before , do this after align, so layout is not affected + if (lines.size() > 1 && lines[0].line_height == 0) { + dc.SetFont(style.font.font); + double h = dc.GetCharHeight(); + lines[0].line_height = h; + lines[0].top -= h; + } } bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector& chars, const TextStyle& style, bool stop_if_too_long) { diff --git a/src/util/tagged_string.cpp b/src/util/tagged_string.cpp index 0b0547da..5f9109cd 100644 --- a/src/util/tagged_string.cpp +++ b/src/util/tagged_string.cpp @@ -33,6 +33,10 @@ String untag_no_escape(const String& str) { return ret; } +String untag_hide_sep(const String& str) { + return untag(remove_tag_contents(str,_("