2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file string_uniscribe.h Functions related to laying out text on Win32. */
10 #ifndef STRING_UNISCRIBE_H
11 #define STRING_UNISCRIBE_H
13 #include "../../gfx_layout.h"
14 #include "../../string_base.h"
17 void UniscribeResetScriptCache(FontSize size
);
21 * Helper class to construct a new #UniscribeParagraphLayout.
23 class UniscribeParagraphLayoutFactory
{
25 /** Helper for GetLayouter, to get the right type. */
26 typedef wchar_t CharType
;
27 /** Helper for GetLayouter, to get whether the layouter supports RTL. */
28 static const bool SUPPORTS_RTL
= true;
31 * Get the actual ParagraphLayout for the given buffer.
32 * @param buff The begin of the buffer.
33 * @param buff_end The location after the last element in the buffer.
34 * @param fontMapping THe mapping of the fonts.
35 * @return The ParagraphLayout instance.
37 static ParagraphLayouter
*GetParagraphLayout(CharType
*buff
, CharType
*buff_end
, FontMap
&fontMapping
);
40 * Append a wide character to the internal buffer.
41 * @param buff The buffer to append to.
42 * @param buffer_last The end of the buffer.
43 * @param c The character to add.
44 * @return The number of buffer spaces that were used.
46 static size_t AppendToBuffer(CharType
*buff
, const CharType
*buffer_last
, char32_t c
)
48 assert(buff
< buffer_last
);
50 /* Character is encoded using surrogates in UTF-16. */
51 if (buff
+ 1 <= buffer_last
) {
52 buff
[0] = (CharType
)(((c
- 0x010000U
) >> 10) + 0xD800);
53 buff
[1] = (CharType
)(((c
- 0x010000U
) & 0x3FF) + 0xDC00);
55 /* Not enough space in buffer. */
60 *buff
= (CharType
)(c
& 0xFFFF);
66 /** String iterator using Uniscribe as a backend. */
67 class UniscribeStringIterator
: public StringIterator
{
70 bool word_stop
: 1; ///< Code point is suitable as a word break.
71 bool char_stop
: 1; ///< Code point is the start of a grapheme cluster, i.e. a "character".
74 std::vector
<CharInfo
> str_info
; ///< Break information for each code point.
75 std::vector
<size_t> utf16_to_utf8
; ///< Mapping from UTF-16 code point position to index in the UTF-8 source string.
77 size_t cur_pos
; ///< Current iteration position.
80 void SetString(const char *s
) override
;
81 size_t SetCurPosition(size_t pos
) override
;
82 size_t Next(IterType what
) override
;
83 size_t Prev(IterType what
) override
;
86 #endif /* STRING_UNISCRIBE_H */