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