Commit d79c79bf authored by twanvl's avatar twanvl

<sep-soft> support

parent e18faefd
...@@ -91,7 +91,7 @@ IMPLEMENT_REFLECTION(TextStyle) { ...@@ -91,7 +91,7 @@ IMPLEMENT_REFLECTION(TextStyle) {
// ----------------------------------------------------------------------------- : TextValue // ----------------------------------------------------------------------------- : TextValue
String TextValue::toString() const { String TextValue::toString() const {
return untag(value()); return untag_hide_sep(value());
} }
bool TextValue::update(Context& ctx) { bool TextValue::update(Context& ctx) {
Value::update(ctx); Value::update(ctx);
......
...@@ -100,7 +100,10 @@ struct TextElementsFromString { ...@@ -100,7 +100,10 @@ struct TextElementsFromString {
if (symbol > 0 && style.symbol_font.valid()) { if (symbol > 0 && style.symbol_font.valid()) {
te.elements.push_back(new_shared5<SymbolTextElement>(text, pos, pos + 1, style.symbol_font, &ctx)); te.elements.push_back(new_shared5<SymbolTextElement>(text, pos, pos + 1, style.symbol_font, &ctx));
} else { } else {
te.elements.push_back(new_shared5<FontTextElement> (text, pos, pos + 1, style.font.make(bold > 0, italic > 0), line > 0 ? BREAK_LINE : BREAK_HARD)); te.elements.push_back(new_shared6<FontTextElement> (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; pos += 1;
......
...@@ -126,9 +126,9 @@ class SimpleTextElement : public TextElement { ...@@ -126,9 +126,9 @@ class SimpleTextElement : public TextElement {
/// A text element that uses a normal font /// A text element that uses a normal font
class FontTextElement : public SimpleTextElement { class FontTextElement : public SimpleTextElement {
public: 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) : 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; virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const;
......
...@@ -12,17 +12,14 @@ ...@@ -12,17 +12,14 @@
// ----------------------------------------------------------------------------- : FontTextElement // ----------------------------------------------------------------------------- : FontTextElement
void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { 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); 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 (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) { if (draw_as == DRAW_ACTIVE) {
// don't draw
if (what == DRAW_ACTIVE) {
// we are drawing a separator // we are drawing a separator
dc.SetTextForeground(font->separator_color); dc.SetTextForeground(font->separator_color);
dc.DrawText(text.substr(start, end-start), rect.position); dc.DrawText(text.substr(start, end-start), rect.position());
} } else {
} else {*/
// draw normally // draw normally
// draw shadow // draw shadow
if (font->hasShadow()) { if (font->hasShadow()) {
...@@ -32,7 +29,7 @@ void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co ...@@ -32,7 +29,7 @@ void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co
// draw // draw
dc.SetTextForeground(font->color); dc.SetTextForeground(font->color);
dc.DrawText(text.substr(start, end - start), rect.position()); dc.DrawText(text.substr(start, end - start), rect.position());
// } }
} }
void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const { void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
...@@ -52,5 +49,5 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& ...@@ -52,5 +49,5 @@ void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>&
} }
double FontTextElement::minScale() const { double FontTextElement::minScale() const {
return 1; // TODO return min(font->size, font->scale_down_to) / max(0.01, font->size);
} }
...@@ -24,5 +24,5 @@ void SymbolTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo ...@@ -24,5 +24,5 @@ void SymbolTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo
} }
double SymbolTextElement::minScale() const { double SymbolTextElement::minScale() const {
return font.size / min(0.001, min(font.size, font.scale_down_to)); return min(font.size, font.scale_down_to) / max(0.01, font.size);
} }
...@@ -304,11 +304,14 @@ void TextViewer::prepareElements(const String& text, const TextStyle& style, Con ...@@ -304,11 +304,14 @@ void TextViewer::prepareElements(const String& text, const TextStyle& style, Con
// ----------------------------------------------------------------------------- : Layout // ----------------------------------------------------------------------------- : Layout
void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) { void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) {
scale = 1;
// find character sizes // find character sizes
vector<CharInfo> chars; vector<CharInfo> 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); elements.getCharInfo(dc, scale, 0, text.size(), chars);
// try to layout
prepareLinesScale(dc, chars, style, false); prepareLinesScale(dc, chars, style, false);
// no text, find a dummy height for the single line we have // no text, find a dummy height for the single line we have
if (lines.size() == 1 && lines[0].width() < 0.0001) { if (lines.size() == 1 && lines[0].width() < 0.0001) {
...@@ -321,6 +324,13 @@ void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle ...@@ -321,6 +324,13 @@ void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle
} }
// align // align
alignLines(dc, chars, style); alignLines(dc, chars, style);
// HACK : fix empty first line before <line>, 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<CharInfo>& chars, const TextStyle& style, bool stop_if_too_long) { bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars, const TextStyle& style, bool stop_if_too_long) {
......
...@@ -33,6 +33,10 @@ String untag_no_escape(const String& str) { ...@@ -33,6 +33,10 @@ String untag_no_escape(const String& str) {
return ret; return ret;
} }
String untag_hide_sep(const String& str) {
return untag(remove_tag_contents(str,_("<sep-soft")));
}
String escape(const String& str) { String escape(const String& str) {
String ret; ret.reserve(str.size()); String ret; ret.reserve(str.size());
FOR_EACH_CONST(c, str) { FOR_EACH_CONST(c, str) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment