diff options
author | Michael Lutz <michi@icosahedron.de> | 2018-05-26 16:13:12 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2018-06-06 21:37:09 +0200 |
commit | 768a31bfe3bc8da1482e0c7115bc46bf90b1e7ec (patch) | |
tree | bf5534df4faf1a9d48edbf355b8e7c1fa2ef2cb9 /src/gfx_layout.cpp | |
parent | a4278c302b7721d22e4501315b5a1713f5471163 (diff) | |
download | openttd-768a31bfe3bc8da1482e0c7115bc46bf90b1e7ec.tar.xz |
Add: [Win32] Text layout using the native Windows Uniscribe library.
Uniscribe is sometimes producing different results compared to ICU, especially
when RTL and LTR content is mixed. Comparing the results to other programs
(like editors or web browsers) leads me to believe that the result are at least
not worse than ICU and possibly better.
Diffstat (limited to 'src/gfx_layout.cpp')
-rw-r--r-- | src/gfx_layout.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 53de0e768..1d9fc7c31 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -21,6 +21,10 @@ #include <unicode/ustring.h> #endif /* WITH_ICU_LAYOUT */ +#ifdef WITH_UNISCRIBE +#include "os/windows/string_uniscribe.h" +#endif /* WITH_UNISCRIBE */ + #include "safeguards.h" @@ -665,10 +669,10 @@ Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsi line.layout->Reflow(); } else { /* Line is new, layout it */ -#ifdef WITH_ICU_LAYOUT FontState old_state = state; const char *old_str = str; +#ifdef WITH_ICU_LAYOUT GetLayouter<ICUParagraphLayoutFactory>(line, str, state); if (line.layout == NULL) { static bool warned = false; @@ -679,11 +683,22 @@ Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsi state = old_state; str = old_str; - GetLayouter<FallbackParagraphLayoutFactory>(line, str, state); } -#else - GetLayouter<FallbackParagraphLayoutFactory>(line, str, state); #endif + +#ifdef WITH_UNISCRIBE + if (line.layout == NULL) { + GetLayouter<UniscribeParagraphLayoutFactory>(line, str, state); + if (line.layout == NULL) { + state = old_state; + str = old_str; + } + } +#endif + + if (line.layout == NULL) { + GetLayouter<FallbackParagraphLayoutFactory>(line, str, state); + } } /* Copy all lines into a local cache so we can reuse them later on more easily. */ @@ -820,6 +835,10 @@ void Layouter::ResetFontCache(FontSize size) /* We must reset the linecache since it references the just freed fonts */ ResetLineCache(); + +#if defined(WITH_UNISCRIBE) + UniscribeResetScriptCache(size); +#endif } /** |