MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UniscribeItemizeString

Function UniscribeItemizeString

src/os/windows/string_uniscribe.cpp:248–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutFactory::CharType *buff, int32_t length)
249{
250 /* Itemize text. */
251 SCRIPT_CONTROL control{};
252 control.uDefaultLanguage = _current_language->winlangid;
253
254 SCRIPT_STATE state{};
255 state.uBidiLevel = _current_text_dir == TD_RTL ? 1 : 0;
256
257 std::vector<SCRIPT_ITEM> items(16);
258 while (true) {
259 /* We subtract one from max_items to work around a buffer overflow on some older versions of Windows. */
260 int generated = 0;
261 HRESULT hr = ScriptItemize(buff, length, (int)items.size() - 1, &control, &state, &items[0], &generated);
262
263 if (SUCCEEDED(hr)) {
264 /* Resize the item buffer. Note that Uniscribe will always add an additional end sentinel item. */
265 items.resize(generated + 1);
266 break;
267 }
268 /* Some kind of error except item buffer too small. */
269 if (hr != E_OUTOFMEMORY) return std::vector<SCRIPT_ITEM>();
270
271 items.resize(items.size() * 2);
272 }
273
274 return items;
275}
276
277/* static */ std::unique_ptr<ParagraphLayouter> UniscribeParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping)
278{

Callers 2

GetParagraphLayoutMethod · 0.85
SetStringMethod · 0.85

Calls 2

resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected