OpenTTD Source  20240919-master-gdf0233f4c2
string_osx.h
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #ifndef STRING_OSX_H
11 #define STRING_OSX_H
12 
13 #include "../../gfx_layout.h"
14 #include "../../string_base.h"
15 
19  struct CharInfo {
20  bool word_stop : 1;
21  bool char_stop : 1;
22  };
23 
24  std::vector<CharInfo> str_info;
25  std::vector<size_t> utf16_to_utf8;
26 
27  size_t cur_pos;
28 
29 public:
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;
34 
35  static std::unique_ptr<StringIterator> Create();
36 };
37 
42 public:
44  typedef UniChar CharType;
46  static const bool SUPPORTS_RTL = true;
47 
55  static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
56 
64  static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c)
65  {
66  assert(buff < buffer_last);
67  if (c >= 0x010000U) {
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);
72  } else {
73  /* Not enough space in buffer. */
74  *buff = 0;
75  }
76  return 2;
77  } else {
78  *buff = (CharType)(c & 0xFFFF);
79  return 1;
80  }
81  }
82 };
83 
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);
88 
89 void MacOSRegisterExternalFont(const char *file_path);
90 
91 #endif /* STRING_OSX_H */
StringIterator::IterType
IterType
Type of the iterator.
Definition: string_base.h:17
CoreTextParagraphLayoutFactory::AppendToBuffer
static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c)
Append a wide character to the internal buffer.
Definition: string_osx.h:64
CoreTextParagraphLayoutFactory::SUPPORTS_RTL
static const bool SUPPORTS_RTL
Helper for GetLayouter, to get whether the layouter supports RTL.
Definition: string_osx.h:46
MacOSResetScriptCache
void MacOSResetScriptCache(FontSize size)
Delete CoreText font reference for a specific font size.
Definition: string_osx.cpp:297
OSXStringIterator::Prev
size_t Prev(IterType what) override
Move the cursor back by one iteration unit.
Definition: string_osx.cpp:462
OSXStringIterator::CharInfo::char_stop
bool char_stop
Code point is the start of a grapheme cluster, i.e. a "character".
Definition: string_osx.h:21
CoreTextParagraphLayoutFactory::GetParagraphLayout
static ParagraphLayouter * GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
Get the actual ParagraphLayout for the given buffer.
Definition: string_osx.cpp:151
OSXStringIterator
String iterator using CoreText as a backend.
Definition: string_osx.h:17
ParagraphLayouter
Interface to glue fallback and normal layouter into one.
Definition: gfx_layout.h:89
MacOSStringCompare
int MacOSStringCompare(std::string_view s1, std::string_view s2)
Compares two strings using case insensitive natural sort.
Definition: string_osx.cpp:329
OSXStringIterator::SetString
void SetString(const char *s) override
Set a new iteration string.
Definition: string_osx.cpp:371
StringIterator
Class for iterating over different kind of parts of a string.
Definition: string_base.h:14
MacOSStringContains
int MacOSStringContains(const std::string_view str, const std::string_view value, bool case_insensitive)
Search if a string is contained in another string using the current locale.
Definition: string_osx.cpp:353
OSXStringIterator::CharInfo
Break info for a character.
Definition: string_osx.h:19
MacOSSetCurrentLocaleName
void MacOSSetCurrentLocaleName(const char *iso_code)
Store current language locale as a CoreFoundation locale.
Definition: string_osx.cpp:314
OSXStringIterator::utf16_to_utf8
std::vector< size_t > utf16_to_utf8
Mapping from UTF-16 code point position to index in the UTF-8 source string.
Definition: string_osx.h:25
CoreTextParagraphLayoutFactory
Helper class to construct a new CoreTextParagraphLayout.
Definition: string_osx.h:41
OSXStringIterator::SetCurPosition
size_t SetCurPosition(size_t pos) override
Change the current string cursor.
Definition: string_osx.cpp:430
CoreTextParagraphLayoutFactory::CharType
UniChar CharType
Helper for GetLayouter, to get the right type.
Definition: string_osx.h:44
OSXStringIterator::CharInfo::word_stop
bool word_stop
Code point is suitable as a word break.
Definition: string_osx.h:20
OSXStringIterator::cur_pos
size_t cur_pos
Current iteration position.
Definition: string_osx.h:27
OSXStringIterator::Next
size_t Next(IterType what) override
Advance the cursor by one iteration unit.
Definition: string_osx.cpp:448
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:208
FontMap
std::map< int, Font * > FontMap
Mapping from index to font.
Definition: gfx_layout.h:84
MacOSRegisterExternalFont
void MacOSRegisterExternalFont(const char *file_path)
Register an external font file with the CoreText system.
Definition: string_osx.cpp:303
OSXStringIterator::str_info
std::vector< CharInfo > str_info
Break information for each code point.
Definition: string_osx.h:24