From 2552afe8be2f5182c1981e42544b25df9fff0208 Mon Sep 17 00:00:00 2001 From: twanvl Date: Tue, 19 Dec 2006 17:53:02 +0000 Subject: [PATCH] fixed alignment of empty text git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@129 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/render/text/viewer.cpp | 13 +++++++++++-- src/render/text/viewer.hpp | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/render/text/viewer.cpp b/src/render/text/viewer.cpp index b807d40b..0795da89 100644 --- a/src/render/text/viewer.cpp +++ b/src/render/text/viewer.cpp @@ -128,7 +128,7 @@ void TextViewer::prepare(RotatedDC& dc, const String& text, const TextStyle& sty // not prepared yet Rotater r(dc, style.getRotation()); prepareElements(text, style, ctx); - prepareLines(dc, text, style); + prepareLines(dc, text, style, ctx); } } void TextViewer::reset() { @@ -243,13 +243,22 @@ void TextViewer::prepareElements(const String& text, const TextStyle& style, Con // ----------------------------------------------------------------------------- : Layout -void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle& style) { +void TextViewer::prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) { scale = 1; // find character sizes vector chars; 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) { + if (style.always_symbol && style.symbol_font.valid()) { + lines[0].line_height = style.symbol_font.font->defaultSymbolSize(ctx, style.symbol_font.size).height; + } else { + dc.SetFont(style.font.font); + lines[0].line_height = dc.GetTextExtent(_(" ")).height; + } + } // align alignLines(dc, chars, style); } diff --git a/src/render/text/viewer.hpp b/src/render/text/viewer.hpp index 2417048a..8070a0f4 100644 --- a/src/render/text/viewer.hpp +++ b/src/render/text/viewer.hpp @@ -104,7 +104,7 @@ class TextViewer { vector lines; ///< The lines in the text box /// Prepare the lines, layout the text - void prepareLines(RotatedDC& dc, const String& text, const TextStyle& style); + void prepareLines(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx); /// Prepare the lines, layout the text; at a specific scale bool prepareLinesScale(RotatedDC& dc, const vector& chars, const TextStyle& style, bool stop_if_too_long); /// Align the lines within the textbox