From b933819b0b0f07d4f2aef590f76898b35fdea607 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 22 Oct 2010 12:15:58 +0000 Subject: (svn r21006) -Fix (r21004): don't print the text direction character when ICU isn't linked and thus doesn't remove them --- src/gfx.cpp | 12 ++++++------ src/string_func.h | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 51778a70c..78fd33278 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -380,7 +380,7 @@ static int TruncateString(char *str, int maxw, bool ignore_setxy, FontSize start ddd_w = ddd = GetCharacterWidth(size, '.') * 3; for (ddd_pos = str; (c = Utf8Consume(const_cast(&str))) != '\0'; ) { - if (IsPrintable(c)) { + if (IsPrintable(c) && !IsTextDirectionChar(c)) { w += GetCharacterWidth(size, c); if (w > maxw) { @@ -437,7 +437,7 @@ static int GetStringWidth(const UChar *str, FontSize start_fontsize) for (;;) { c = *str++; if (c == 0) break; - if (IsPrintable(c)) { + if (IsPrintable(c) && !IsTextDirectionChar(c)) { width += GetCharacterWidth(size, c); } else { switch (c) { @@ -687,7 +687,7 @@ uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize si /* whitespace is where we will insert the line-break */ if (IsWhitespace(c)) last_space = str; - if (IsPrintable(c)) { + if (IsPrintable(c) && !IsTextDirectionChar(c)) { int char_w = GetCharacterWidth(size, c); w += char_w; if (w > maxw) { @@ -982,7 +982,7 @@ Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize) for (;;) { c = Utf8Consume(&str); if (c == 0) break; - if (IsPrintable(c)) { + if (IsPrintable(c) && !IsTextDirectionChar(c)) { br.width += GetCharacterWidth(size, c); } else { switch (c) { @@ -1081,7 +1081,7 @@ skip_cont:; if (c == 0) { return x; // Nothing more to draw, get out. And here is the new x position } - if (IsPrintable(c)) { + if (IsPrintable(c) && !IsTextDirectionChar(c)) { if (x >= dpi->left + dpi->width) goto skip_char; if (x + _max_char_width >= dpi->left) { GfxMainBlitter(GetGlyph(params.fontsize, c), x, y, BM_COLOUR_REMAP); @@ -1104,7 +1104,7 @@ skip_cont:; params.SetFontSize(FS_SMALL); } else if (c == SCC_BIGFONT) { // {BIGFONT} params.SetFontSize(FS_LARGE); - } else { + } else if (!IsTextDirectionChar(c)) { DEBUG(misc, 0, "[utf8] unknown string command character %d", c); } } diff --git a/src/string_func.h b/src/string_func.h index 082543dae..b2e88f52b 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -224,6 +224,28 @@ static inline char *Utf8PrevChar(char *s) return ret; } +/** + * Is the given character a text direction character. + * @param c The character to test. + * @return true iff the character is used to influence + * the text direction. + */ +static inline bool IsTextDirectionChar(WChar c) +{ + switch (c) { + case CHAR_TD_LRM: + case CHAR_TD_RLM: + case CHAR_TD_LRE: + case CHAR_TD_RLE: + case CHAR_TD_LRO: + case CHAR_TD_RLO: + case CHAR_TD_PDF: + return true; + + default: + return false; + } +} static inline bool IsPrintable(WChar c) { -- cgit v1.2.3-54-g00ecf