OpenTTD
string_uniscribe.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_UNISCRIBE_H
11 #define STRING_UNISCRIBE_H
12 
13 #if defined(WITH_UNISCRIBE)
14 
15 #include "../../gfx_layout.h"
16 #include "../../string_base.h"
17 #include <vector>
18 
19 
20 void UniscribeResetScriptCache(FontSize size);
21 
22 
26 class UniscribeParagraphLayoutFactory {
27 public:
29  typedef wchar_t CharType;
31  static const bool SUPPORTS_RTL = true;
32 
40  static ParagraphLayouter *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
41 
49  static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, WChar c)
50  {
51  if (c >= 0x010000U) {
52  /* Character is encoded using surrogates in UTF-16. */
53  if (buff + 1 <= buffer_last) {
54  buff[0] = (CharType)(((c - 0x010000U) >> 10) + 0xD800);
55  buff[1] = (CharType)(((c - 0x010000U) & 0x3FF) + 0xDC00);
56  } else {
57  /* Not enough space in buffer. */
58  *buff = 0;
59  }
60  return 2;
61  } else {
62  *buff = (CharType)(c & 0xFFFF);
63  return 1;
64  }
65  }
66 };
67 
69 class UniscribeStringIterator : public StringIterator {
71  struct CharInfo {
72  bool word_stop : 1;
73  bool char_stop : 1;
74  };
75 
76  std::vector<CharInfo> str_info;
77  std::vector<size_t> utf16_to_utf8;
78 
79  size_t cur_pos;
80 
81 public:
82  void SetString(const char *s) override;
83  size_t SetCurPosition(size_t pos) override;
84  size_t Next(IterType what) override;
85  size_t Prev(IterType what) override;
86 };
87 
88 #endif /* defined(WITH_UNISCRIBE) */
89 
90 #endif /* STRING_UNISCRIBE_H */
Implementation of simple mapping class.
Interface to glue fallback and normal layouter into one.
Definition: gfx_layout.h:115
FontSize
Available font sizes.
Definition: gfx_type.h:201
Class for iterating over different kind of parts of a string.
Definition: string_base.h:14
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35