OpenTTD
string_osx.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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  */
9 
12 #ifndef STRING_OSX_H
13 #define STRING_OSX_H
14 
15 #include "../../gfx_layout.h"
16 #include "../../string_base.h"
17 #include <vector>
18 
22  struct CharInfo {
23  bool word_stop : 1;
24  bool char_stop : 1;
25  };
26 
27  std::vector<CharInfo> str_info;
28  std::vector<size_t> utf16_to_utf8;
29 
30  size_t cur_pos;
31 
32 public:
33  virtual void SetString(const char *s);
34  virtual size_t SetCurPosition(size_t pos);
35  virtual size_t Next(IterType what);
36  virtual size_t Prev(IterType what);
37 
38  static StringIterator *Create();
39 };
40 
45 public:
47  typedef UniChar CharType;
49  static const bool SUPPORTS_RTL = true;
50 
58  static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
59 
67  static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, WChar c)
68  {
69  if (c >= 0x010000U) {
70  /* Character is encoded using surrogates in UTF-16. */
71  if (buff + 1 <= buffer_last) {
72  buff[0] = (CharType)(((c - 0x010000U) >> 10) + 0xD800);
73  buff[1] = (CharType)(((c - 0x010000U) & 0x3FF) + 0xDC00);
74  } else {
75  /* Not enough space in buffer. */
76  *buff = 0;
77  }
78  return 2;
79  } else {
80  *buff = (CharType)(c & 0xFFFF);
81  return 1;
82  }
83  }
84 };
85 
87 void MacOSSetCurrentLocaleName(const char *iso_code);
88 int MacOSStringCompare(const char *s1, const char *s2);
89 
90 #endif /* STRING_OSX_H */
bool char_stop
Code point is the start of a grapheme cluster, i.e. a "character".
Definition: string_osx.h:24
Implementation of simple mapping class.
String iterator using CoreText as a backend.
Definition: string_osx.h:20
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:28
bool word_stop
Code point is suitable as a word break.
Definition: string_osx.h:23
Break info for a character.
Definition: string_osx.h:22
virtual void SetString(const char *s)
Set a new iteration string.
Definition: string_osx.cpp:324
void MacOSSetCurrentLocaleName(const char *iso_code)
Store current language locale as a CoreFounation locale.
Definition: string_osx.cpp:280
static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, WChar c)
Append a wide character to the internal buffer.
Definition: string_osx.h:67
Interface to glue fallback and normal layouter into one.
Definition: gfx_layout.h:117
IterType
Type of the iterator.
Definition: string_base.h:19
void MacOSResetScriptCache(FontSize size)
Delete CoreText font reference for a specific font size.
Definition: string_osx.cpp:271
virtual size_t Next(IterType what)
Advance the cursor by one iteration unit.
Definition: string_osx.cpp:404
size_t cur_pos
Current iteration position.
Definition: string_osx.h:30
std::vector< CharInfo > str_info
Break information for each code point.
Definition: string_osx.h:27
FontSize
Available font sizes.
Definition: gfx_type.h:203
virtual size_t SetCurPosition(size_t pos)
Change the current string cursor.
Definition: string_osx.cpp:386
Class for iterating over different kind of parts of a string.
Definition: string_base.h:16
UniChar CharType
Helper for GetLayouter, to get the right type.
Definition: string_osx.h:47
int MacOSStringCompare(const char *s1, const char *s2)
Compares two strings using case insensitive natural sort.
Definition: string_osx.cpp:298
virtual size_t Prev(IterType what)
Move the cursor back by one iteration unit.
Definition: string_osx.cpp:418
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
Helper class to construct a new CoreTextParagraphLayout.
Definition: string_osx.h:44