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_osx.h Functions related to localized text support on OSX. */
13 #include "../../gfx_layout.h"
14 #include "../../string_base.h"
16 /** String iterator using CoreText as a backend. */
17 class OSXStringIterator
: public StringIterator
{
18 /** Break info for a character. */
20 bool word_stop
: 1; ///< Code point is suitable as a word break.
21 bool char_stop
: 1; ///< Code point is the start of a grapheme cluster, i.e. a "character".
24 std::vector
<CharInfo
> str_info
; ///< Break information for each code point.
25 std::vector
<size_t> utf16_to_utf8
; ///< Mapping from UTF-16 code point position to index in the UTF-8 source string.
27 size_t cur_pos
; ///< Current iteration position.
30 void SetString(const char *s
) override
;
31 size_t SetCurPosition(size_t pos
) override
;
32 size_t Next(IterType what
) override
;
33 size_t Prev(IterType what
) override
;
35 static std::unique_ptr
<StringIterator
> Create();
39 * Helper class to construct a new #CoreTextParagraphLayout.
41 class CoreTextParagraphLayoutFactory
{
43 /** Helper for GetLayouter, to get the right type. */
44 typedef UniChar CharType
;
45 /** Helper for GetLayouter, to get whether the layouter supports RTL. */
46 static const bool SUPPORTS_RTL
= true;
49 * Get the actual ParagraphLayout for the given buffer.
50 * @param buff The begin of the buffer.
51 * @param buff_end The location after the last element in the buffer.
52 * @param fontMapping THe mapping of the fonts.
53 * @return The ParagraphLayout instance.
55 static ParagraphLayouter
*GetParagraphLayout(CharType
*buff
, CharType
*buff_end
, FontMap
&fontMapping
);
58 * Append a wide character to the internal buffer.
59 * @param buff The buffer to append to.
60 * @param buffer_last The end of the buffer.
61 * @param c The character to add.
62 * @return The number of buffer spaces that were used.
64 static size_t AppendToBuffer(CharType
*buff
, const CharType
*buffer_last
, char32_t c
)
66 assert(buff
< buffer_last
);
68 /* Character is encoded using surrogates in UTF-16. */
69 if (buff
+ 1 <= buffer_last
) {
70 buff
[0] = (CharType
)(((c
- 0x010000U
) >> 10) + 0xD800);
71 buff
[1] = (CharType
)(((c
- 0x010000U
) & 0x3FF) + 0xDC00);
73 /* Not enough space in buffer. */
78 *buff
= (CharType
)(c
& 0xFFFF);
84 void MacOSResetScriptCache(FontSize size
);
85 void MacOSSetCurrentLocaleName(const char *iso_code
);
86 int MacOSStringCompare(std::string_view s1
, std::string_view s2
);
87 int MacOSStringContains(const std::string_view str
, const std::string_view value
, bool case_insensitive
);
89 void MacOSRegisterExternalFont(const char *file_path
);
91 #endif /* STRING_OSX_H */