OpenTTD Source: src/os/windows/string_uniscribe.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef STRING_UNISCRIBE_H
11#define STRING_UNISCRIBE_H
12
13#include "../../gfx_layout.h"
14#include "../../string_base.h"
15
16
17void UniscribeResetScriptCache(FontSize size);
18
19
23 class UniscribeParagraphLayoutFactory {
24public:
26 typedef wchar_t CharType;
28 static const bool SUPPORTS_RTL = true;
29
37 static std::unique_ptr<ParagraphLayouter> GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping);
38
46 static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c)
47 {
48 assert(buff < buffer_last);
49 if (c >= 0x010000U) {
50 /* Character is encoded using surrogates in UTF-16. */
51 if (buff + 1 <= buffer_last) {
52 buff[0] = (CharType)(((c - 0x010000U) >> 10) + 0xD800);
53 buff[1] = (CharType)(((c - 0x010000U) & 0x3FF) + 0xDC00);
54 } else {
55 /* Not enough space in buffer. */
56 *buff = 0;
57 }
58 return 2;
59 } else {
60 *buff = (CharType)(c & 0xFFFF);
61 return 1;
62 }
63 }
64};
65
67 class UniscribeStringIterator : public StringIterator {
69 struct CharInfo {
70 bool word_stop : 1;
71 bool char_stop : 1;
72 };
73
74 std::vector<CharInfo> str_info;
75 std::vector<size_t> utf16_to_utf8;
76
77 size_t cur_pos;
78
79public:
80 void SetString(std::string_view s) override;
81 size_t SetCurPosition(size_t pos) override;
82 size_t Next(IterType what) override;
83 size_t Prev(IterType what) override;
84};
85
86#endif /* STRING_UNISCRIBE_H */
StringIterator
Class for iterating over different kind of parts of a string.
Definition string_base.h:14
StringIterator::IterType
IterType
Type of the iterator.
Definition string_base.h:17
UniscribeParagraphLayoutFactory
Helper class to construct a new UniscribeParagraphLayout.
Definition string_uniscribe.h:23
UniscribeParagraphLayoutFactory::SUPPORTS_RTL
static const bool SUPPORTS_RTL
Helper for GetLayouter, to get whether the layouter supports RTL.
Definition string_uniscribe.h:28
UniscribeParagraphLayoutFactory::AppendToBuffer
static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c)
Append a wide character to the internal buffer.
Definition string_uniscribe.h:46
UniscribeParagraphLayoutFactory::GetParagraphLayout
static std::unique_ptr< ParagraphLayouter > GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping)
Get the actual ParagraphLayout for the given buffer.
Definition string_uniscribe.cpp:277
UniscribeParagraphLayoutFactory::CharType
wchar_t CharType
Helper for GetLayouter, to get the right type.
Definition string_uniscribe.h:26
UniscribeStringIterator
String iterator using Uniscribe as a backend.
Definition string_uniscribe.h:67
UniscribeStringIterator::Prev
size_t Prev(IterType what) override
Move the cursor back by one iteration unit.
Definition string_uniscribe.cpp:601
UniscribeStringIterator::str_info
std::vector< CharInfo > str_info
Break information for each code point.
Definition string_uniscribe.h:74
UniscribeStringIterator::SetString
void SetString(std::string_view s) override
Set a new iteration string.
Definition string_uniscribe.cpp:517
UniscribeStringIterator::cur_pos
size_t cur_pos
Current iteration position.
Definition string_uniscribe.h:77
UniscribeStringIterator::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_uniscribe.h:75
UniscribeStringIterator::Next
size_t Next(IterType what) override
Advance the cursor by one iteration unit.
Definition string_uniscribe.cpp:587
UniscribeStringIterator::SetCurPosition
size_t SetCurPosition(size_t pos) override
Change the current string cursor.
Definition string_uniscribe.cpp:569
FontMap
std::vector< std::pair< int, Font * > > FontMap
Mapping from index to font.
Definition gfx_layout.h:106
FontSize
FontSize
Available font sizes.
Definition gfx_type.h:248
UniscribeStringIterator::CharInfo
Definition string_uniscribe.h:69
UniscribeStringIterator::CharInfo::char_stop
bool char_stop
Code point is the start of a grapheme cluster, i.e. a "character".
Definition string_uniscribe.h:71
UniscribeStringIterator::CharInfo::word_stop
bool word_stop
Code point is suitable as a word break.
Definition string_uniscribe.h:70