OpenTTD Source  20240917-master-g9ab0a47812
string_osx.cpp
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 #include "../../stdafx.h"
11 #include "string_osx.h"
12 #include "../../string_func.h"
13 #include "../../strings_func.h"
14 #include "../../table/control_codes.h"
15 #include "../../fontcache.h"
16 #include "../../zoom_func.h"
17 #include "macos.h"
18 
19 #include <CoreFoundation/CoreFoundation.h>
20 
21 
22 /* CTRunDelegateCreate is supported since MacOS X 10.5, but was only included in the SDKs starting with the 10.9 SDK. */
23 #ifndef HAVE_OSX_109_SDK
24 extern "C" {
25  typedef const struct __CTRunDelegate * CTRunDelegateRef;
26 
27  typedef void (*CTRunDelegateDeallocateCallback) (void *refCon);
28  typedef CGFloat (*CTRunDelegateGetAscentCallback) (void *refCon);
29  typedef CGFloat (*CTRunDelegateGetDescentCallback) (void *refCon);
30  typedef CGFloat (*CTRunDelegateGetWidthCallback) (void *refCon);
31  typedef struct {
32  CFIndex version;
33  CTRunDelegateDeallocateCallback dealloc;
34  CTRunDelegateGetAscentCallback getAscent;
35  CTRunDelegateGetDescentCallback getDescent;
36  CTRunDelegateGetWidthCallback getWidth;
38 
39  enum {
40  kCTRunDelegateVersion1 = 1,
41  kCTRunDelegateCurrentVersion = kCTRunDelegateVersion1
42  };
43 
44  extern const CFStringRef kCTRunDelegateAttributeName AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
45 
46  CTRunDelegateRef CTRunDelegateCreate(const CTRunDelegateCallbacks *callbacks, void *refCon) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
47 }
48 #endif /* HAVE_OSX_109_SDK */
49 
54 
55 
60 private:
62  ptrdiff_t length;
63  const FontMap &font_map;
64 
66 
67  CFIndex cur_offset = 0;
68 
69 public:
72  private:
73  std::vector<GlyphID> glyphs;
74  std::vector<Position> positions;
75  std::vector<int> glyph_to_char;
76 
77  int total_advance = 0;
78  Font *font;
79 
80  public:
81  CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff);
82  CoreTextVisualRun(CoreTextVisualRun &&other) = default;
83 
84  std::span<const GlyphID> GetGlyphs() const override { return this->glyphs; }
85  std::span<const Position> GetPositions() const override { return this->positions; }
86  std::span<const int> GetGlyphToCharMap() const override { return this->glyph_to_char; }
87 
88  const Font *GetFont() const override { return this->font; }
89  int GetLeading() const override { return this->font->fc->GetHeight(); }
90  int GetGlyphCount() const override { return (int)this->glyphs.size(); }
91  int GetAdvance() const { return this->total_advance; }
92  };
93 
95  class CoreTextLine : public std::vector<CoreTextVisualRun>, public ParagraphLayouter::Line {
96  public:
98  {
99  CFArrayRef runs = CTLineGetGlyphRuns(line.get());
100  for (CFIndex i = 0; i < CFArrayGetCount(runs); i++) {
101  CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, i);
102 
103  /* Extract font information for this run. */
104  CFRange chars = CTRunGetStringRange(run);
105  auto map = fontMapping.upper_bound(chars.location);
106 
107  this->emplace_back(run, map->second, buff);
108  }
109  }
110 
111  int GetLeading() const override;
112  int GetWidth() const override;
113  int CountRuns() const override { return this->size(); }
114  const VisualRun &GetVisualRun(int run) const override { return this->at(run); }
115 
116  int GetInternalCharLength(char32_t c) const override
117  {
118  /* CoreText uses UTF-16 internally which means we need to account for surrogate pairs. */
119  return c >= 0x010000U ? 2 : 1;
120  }
121  };
122 
123  CoreTextParagraphLayout(CFAutoRelease<CTTypesetterRef> typesetter, const CoreTextParagraphLayoutFactory::CharType *buffer, ptrdiff_t len, const FontMap &fontMapping) : text_buffer(buffer), length(len), font_map(fontMapping), typesetter(std::move(typesetter))
124  {
125  this->Reflow();
126  }
127 
128  void Reflow() override
129  {
130  this->cur_offset = 0;
131  }
132 
133  std::unique_ptr<const Line> NextLine(int max_width) override;
134 };
135 
136 
138 static CGFloat SpriteFontGetWidth(void *ref_con)
139 {
140  FontSize fs = (FontSize)((size_t)ref_con >> 24);
141  char32_t c = (char32_t)((size_t)ref_con & 0xFFFFFF);
142 
143  return GetGlyphWidth(fs, c);
144 }
145 
146 static CTRunDelegateCallbacks _sprite_font_callback = {
147  kCTRunDelegateCurrentVersion, nullptr, nullptr, nullptr,
149 };
150 
152 {
153  if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
154 
155  /* Can't layout an empty string. */
156  ptrdiff_t length = buff_end - buff;
157  if (length == 0) return nullptr;
158 
159  /* Can't layout our in-built sprite fonts. */
160  for (const auto &i : fontMapping) {
161  if (i.second->fc->IsBuiltInFont()) return nullptr;
162  }
163 
164  /* Make attributed string with embedded font information. */
165  CFAutoRelease<CFMutableAttributedStringRef> str(CFAttributedStringCreateMutable(kCFAllocatorDefault, 0));
166  CFAttributedStringBeginEditing(str.get());
167 
168  CFAutoRelease<CFStringRef> base(CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, buff, length, kCFAllocatorNull));
169  CFAttributedStringReplaceString(str.get(), CFRangeMake(0, 0), base.get());
170 
171  const UniChar replacment_char = 0xFFFC;
172  CFAutoRelease<CFStringRef> replacment_str(CFStringCreateWithCharacters(kCFAllocatorDefault, &replacment_char, 1));
173 
174  /* Apply font and colour ranges to our string. This is important to make sure
175  * that we get proper glyph boundaries on style changes. */
176  int last = 0;
177  for (const auto &i : fontMapping) {
178  if (i.first - last == 0) continue;
179 
180  CTFontRef font = (CTFontRef)i.second->fc->GetOSHandle();
181  if (font == nullptr) {
182  if (!_font_cache[i.second->fc->GetSize()]) {
183  /* Cache font information. */
184  CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName().c_str(), kCFStringEncodingUTF8));
185  _font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr));
186  }
187  font = _font_cache[i.second->fc->GetSize()].get();
188  }
189  CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTFontAttributeName, font);
190 
191  CGColorRef color = CGColorCreateGenericGray((uint8_t)i.second->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
192  CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTForegroundColorAttributeName, color);
193  CGColorRelease(color);
194 
195  /* Install a size callback for our special private-use sprite glyphs in case the font does not provide them. */
196  for (ssize_t c = last; c < i.first; c++) {
197  if (buff[c] >= SCC_SPRITE_START && buff[c] <= SCC_SPRITE_END && i.second->fc->MapCharToGlyph(buff[c], false) == 0) {
198  CFAutoRelease<CTRunDelegateRef> del(CTRunDelegateCreate(&_sprite_font_callback, (void *)(size_t)(buff[c] | (i.second->fc->GetSize() << 24))));
199  /* According to the offical documentation, if a run delegate is used, the char should always be 0xFFFC. */
200  CFAttributedStringReplaceString(str.get(), CFRangeMake(c, 1), replacment_str.get());
201  CFAttributedStringSetAttribute(str.get(), CFRangeMake(c, 1), kCTRunDelegateAttributeName, del.get());
202  }
203  }
204 
205  last = i.first;
206  }
207  CFAttributedStringEndEditing(str.get());
208 
209  /* Create and return typesetter for the string. */
210  CFAutoRelease<CTTypesetterRef> typesetter(CTTypesetterCreateWithAttributedString(str.get()));
211 
212  return typesetter ? new CoreTextParagraphLayout(std::move(typesetter), buff, length, fontMapping) : nullptr;
213 }
214 
215 /* virtual */ std::unique_ptr<const ParagraphLayouter::Line> CoreTextParagraphLayout::NextLine(int max_width)
216 {
217  if (this->cur_offset >= this->length) return nullptr;
218 
219  /* Get line break position, trying word breaking first and breaking somewhere if that doesn't work. */
220  CFIndex len = CTTypesetterSuggestLineBreak(this->typesetter.get(), this->cur_offset, max_width);
221  if (len <= 0) len = CTTypesetterSuggestClusterBreak(this->typesetter.get(), this->cur_offset, max_width);
222 
223  /* Create line. */
224  CFAutoRelease<CTLineRef> line(CTTypesetterCreateLine(this->typesetter.get(), CFRangeMake(this->cur_offset, len)));
225  this->cur_offset += len;
226 
227  if (!line) return nullptr;
228  return std::make_unique<CoreTextLine>(std::move(line), this->font_map, this->text_buffer);
229 }
230 
231 CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font)
232 {
233  this->glyphs.resize(CTRunGetGlyphCount(run));
234 
235  /* Query map of glyphs to source string index. */
236  CFIndex map[this->glyphs.size()];
237  CTRunGetStringIndices(run, CFRangeMake(0, 0), map);
238 
239  this->glyph_to_char.resize(this->glyphs.size());
240  for (size_t i = 0; i < this->glyph_to_char.size(); i++) this->glyph_to_char[i] = (int)map[i];
241 
242  CGPoint pts[this->glyphs.size()];
243  CTRunGetPositions(run, CFRangeMake(0, 0), pts);
244  CGSize advs[this->glyphs.size()];
245  CTRunGetAdvances(run, CFRangeMake(0, 0), advs);
246  this->positions.reserve(this->glyphs.size());
247 
248  /* Convert glyph array to our data type. At the same time, substitute
249  * the proper glyphs for our private sprite glyphs. */
250  CGGlyph gl[this->glyphs.size()];
251  CTRunGetGlyphs(run, CFRangeMake(0, 0), gl);
252  for (size_t i = 0; i < this->glyphs.size(); i++) {
253  if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END && (gl[i] == 0 || gl[i] == 3)) {
254  /* A glyph of 0 indidicates not found, while apparently 3 is what char 0xFFFC maps to. */
255  this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]);
256  this->positions.emplace_back(pts[i].x, pts[i].x + advs[i].width - 1, (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2); // Align sprite font to centre
257  } else {
258  this->glyphs[i] = gl[i];
259  this->positions.emplace_back(pts[i].x, pts[i].x + advs[i].width - 1, pts[i].y);
260  }
261  }
262  this->total_advance = (int)std::ceil(CTRunGetTypographicBounds(run, CFRangeMake(0, 0), nullptr, nullptr, nullptr));
263 }
264 
270 {
271  int leading = 0;
272  for (const auto &run : *this) {
273  leading = std::max(leading, run.GetLeading());
274  }
275 
276  return leading;
277 }
278 
284 {
285  if (this->empty()) return 0;
286 
287  int total_width = 0;
288  for (const auto &run : *this) {
289  total_width += run.GetAdvance();
290  }
291 
292  return total_width;
293 }
294 
295 
298 {
299  _font_cache[size].reset();
300 }
301 
303 void MacOSRegisterExternalFont(const char *file_path)
304 {
305  if (!MacOSVersionIsAtLeast(10, 6, 0)) return;
306 
307  CFAutoRelease<CFStringRef> path(CFStringCreateWithCString(kCFAllocatorDefault, file_path, kCFStringEncodingUTF8));
308  CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
309 
310  CTFontManagerRegisterFontsForURL(url.get(), kCTFontManagerScopeProcess, nullptr);
311 }
312 
314 void MacOSSetCurrentLocaleName(const char *iso_code)
315 {
316  if (!MacOSVersionIsAtLeast(10, 5, 0)) return;
317 
318  CFAutoRelease<CFStringRef> iso(CFStringCreateWithCString(kCFAllocatorDefault, iso_code, kCFStringEncodingUTF8));
319  _osx_locale.reset(CFLocaleCreate(kCFAllocatorDefault, iso.get()));
320 }
321 
329 int MacOSStringCompare(std::string_view s1, std::string_view s2)
330 {
331  static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
332  if (!supported) return 0;
333 
334  CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
335 
336  CFAutoRelease<CFStringRef> cf1(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s1.data(), s1.size(), kCFStringEncodingUTF8, false));
337  CFAutoRelease<CFStringRef> cf2(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s2.data(), s2.size(), kCFStringEncodingUTF8, false));
338 
339  /* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
340  if (cf1 == nullptr || cf2 == nullptr) return 0;
341 
342  return (int)CFStringCompareWithOptionsAndLocale(cf1.get(), cf2.get(), CFRangeMake(0, CFStringGetLength(cf1.get())), flags, _osx_locale.get()) + 2;
343 }
344 
353 int MacOSStringContains(const std::string_view str, const std::string_view value, bool case_insensitive)
354 {
355  static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
356  if (!supported) return -1;
357 
358  CFStringCompareFlags flags = kCFCompareLocalized | kCFCompareWidthInsensitive;
359  if (case_insensitive) flags |= kCFCompareCaseInsensitive;
360 
361  CFAutoRelease<CFStringRef> cf_str(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)str.data(), str.size(), kCFStringEncodingUTF8, false));
362  CFAutoRelease<CFStringRef> cf_value(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)value.data(), value.size(), kCFStringEncodingUTF8, false));
363 
364  /* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
365  if (cf_str == nullptr || cf_value == nullptr) return -1;
366 
367  return CFStringFindWithOptionsAndLocale(cf_str.get(), cf_value.get(), CFRangeMake(0, CFStringGetLength(cf_str.get())), flags, _osx_locale.get(), nullptr) ? 1 : 0;
368 }
369 
370 
371 /* virtual */ void OSXStringIterator::SetString(const char *s)
372 {
373  const char *string_base = s;
374 
375  this->utf16_to_utf8.clear();
376  this->str_info.clear();
377  this->cur_pos = 0;
378 
379  /* CoreText operates on UTF-16, thus we have to convert the input string.
380  * To be able to return proper offsets, we have to create a mapping at the same time. */
381  std::vector<UniChar> utf16_str;
382  while (*s != '\0') {
383  size_t idx = s - string_base;
384 
385  char32_t c = Utf8Consume(&s);
386  if (c < 0x10000) {
387  utf16_str.push_back((UniChar)c);
388  } else {
389  /* Make a surrogate pair. */
390  utf16_str.push_back((UniChar)(0xD800 + ((c - 0x10000) >> 10)));
391  utf16_str.push_back((UniChar)(0xDC00 + ((c - 0x10000) & 0x3FF)));
392  this->utf16_to_utf8.push_back(idx);
393  }
394  this->utf16_to_utf8.push_back(idx);
395  }
396  this->utf16_to_utf8.push_back(s - string_base);
397 
398  /* Query CoreText for word and cluster break information. */
399  this->str_info.resize(utf16_to_utf8.size());
400 
401  if (!utf16_str.empty()) {
402  CFAutoRelease<CFStringRef> str(CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, &utf16_str[0], utf16_str.size(), kCFAllocatorNull));
403 
404  /* Get cluster breaks. */
405  for (CFIndex i = 0; i < CFStringGetLength(str.get()); ) {
406  CFRange r = CFStringGetRangeOfComposedCharactersAtIndex(str.get(), i);
407  this->str_info[r.location].char_stop = true;
408 
409  i += r.length;
410  }
411 
412  /* Get word breaks. */
413  CFAutoRelease<CFStringTokenizerRef> tokenizer(CFStringTokenizerCreate(kCFAllocatorDefault, str.get(), CFRangeMake(0, CFStringGetLength(str.get())), kCFStringTokenizerUnitWordBoundary, _osx_locale.get()));
414 
415  CFStringTokenizerTokenType tokenType = kCFStringTokenizerTokenNone;
416  while ((tokenType = CFStringTokenizerAdvanceToNextToken(tokenizer.get())) != kCFStringTokenizerTokenNone) {
417  /* Skip tokens that are white-space or punctuation tokens. */
418  if ((tokenType & kCFStringTokenizerTokenHasNonLettersMask) != kCFStringTokenizerTokenHasNonLettersMask) {
419  CFRange r = CFStringTokenizerGetCurrentTokenRange(tokenizer.get());
420  this->str_info[r.location].word_stop = true;
421  }
422  }
423  }
424 
425  /* End-of-string is always a valid stopping point. */
426  this->str_info.back().char_stop = true;
427  this->str_info.back().word_stop = true;
428 }
429 
430 /* virtual */ size_t OSXStringIterator::SetCurPosition(size_t pos)
431 {
432  /* Convert incoming position to an UTF-16 string index. */
433  size_t utf16_pos = 0;
434  for (size_t i = 0; i < this->utf16_to_utf8.size(); i++) {
435  if (this->utf16_to_utf8[i] == pos) {
436  utf16_pos = i;
437  break;
438  }
439  }
440 
441  /* Sanitize in case we get a position inside a grapheme cluster. */
442  while (utf16_pos > 0 && !this->str_info[utf16_pos].char_stop) utf16_pos--;
443  this->cur_pos = utf16_pos;
444 
445  return this->utf16_to_utf8[this->cur_pos];
446 }
447 
448 /* virtual */ size_t OSXStringIterator::Next(IterType what)
449 {
450  assert(this->cur_pos <= this->utf16_to_utf8.size());
452 
453  if (this->cur_pos == this->utf16_to_utf8.size()) return END;
454 
455  do {
456  this->cur_pos++;
457  } while (this->cur_pos < this->utf16_to_utf8.size() && (what == ITER_WORD ? !this->str_info[this->cur_pos].word_stop : !this->str_info[this->cur_pos].char_stop));
458 
459  return this->cur_pos == this->utf16_to_utf8.size() ? END : this->utf16_to_utf8[this->cur_pos];
460 }
461 
462 /* virtual */ size_t OSXStringIterator::Prev(IterType what)
463 {
464  assert(this->cur_pos <= this->utf16_to_utf8.size());
466 
467  if (this->cur_pos == 0) return END;
468 
469  do {
470  this->cur_pos--;
471  } while (this->cur_pos > 0 && (what == ITER_WORD ? !this->str_info[this->cur_pos].word_stop : !this->str_info[this->cur_pos].char_stop));
472 
473  return this->utf16_to_utf8[this->cur_pos];
474 }
475 
476 /* static */ std::unique_ptr<StringIterator> OSXStringIterator::Create()
477 {
478  if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
479 
480  return std::make_unique<OSXStringIterator>();
481 }
FontCache::GetSize
FontSize GetSize() const
Get the FontSize of the font.
Definition: fontcache.h:42
StringIterator::IterType
IterType
Type of the iterator.
Definition: string_base.h:17
Font::fc
FontCache * fc
The font we are using.
Definition: gfx_layout.h:77
FontCache::GetHeight
int GetHeight() const
Get the height of the font.
Definition: fontcache.h:48
SpriteFontGetWidth
static CGFloat SpriteFontGetWidth(void *ref_con)
Get the width of an encoded sprite font character.
Definition: string_osx.cpp:138
OSXStringIterator::Prev
size_t Prev(IterType what) override
Move the cursor back by one iteration unit.
Definition: string_osx.cpp:462
CoreTextParagraphLayout::CoreTextLine::GetLeading
int GetLeading() const override
Get the height of the line.
Definition: string_osx.cpp:269
CFAutoRelease
std::unique_ptr< typename std::remove_pointer< T >::type, CFDeleter< typename std::remove_pointer< T >::type > > CFAutoRelease
Specialisation of std::unique_ptr for CoreFoundation objects.
Definition: macos.h:54
MacOSVersionIsAtLeast
bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
Check if we are at least running on the specified version of Mac OS.
Definition: macos.h:25
CoreTextParagraphLayoutFactory::GetParagraphLayout
static ParagraphLayouter * GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping)
Get the actual ParagraphLayout for the given buffer.
Definition: string_osx.cpp:151
CoreTextParagraphLayout
Wrapper for doing layouts with CoreText.
Definition: string_osx.cpp:59
StringIterator::ITER_CHARACTER
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
Definition: string_base.h:18
ParagraphLayouter
Interface to glue fallback and normal layouter into one.
Definition: gfx_layout.h:89
CTRunDelegateCallbacks
Definition: string_osx.cpp:31
string_osx.h
ParagraphLayouter::Line
A single line worth of VisualRuns.
Definition: gfx_layout.h:119
OSXStringIterator::SetString
void SetString(const char *s) override
Set a new iteration string.
Definition: string_osx.cpp:371
GetGlyphWidth
uint GetGlyphWidth(FontSize size, char32_t key)
Get the width of a glyph.
Definition: fontcache.h:180
MacOSStringContains
int MacOSStringContains(const std::string_view str, const std::string_view value, bool case_insensitive)
Search if a string is contained in another string using the current locale.
Definition: string_osx.cpp:353
MacOSStringCompare
int MacOSStringCompare(std::string_view s1, std::string_view s2)
Compares two strings using case insensitive natural sort.
Definition: string_osx.cpp:329
StringIterator::ITER_WORD
@ ITER_WORD
Iterate over words.
Definition: string_base.h:19
CoreTextParagraphLayout::CoreTextLine::GetWidth
int GetWidth() const override
Get the width of this line.
Definition: string_osx.cpp:283
MacOSSetCurrentLocaleName
void MacOSSetCurrentLocaleName(const char *iso_code)
Store current language locale as a CoreFoundation locale.
Definition: string_osx.cpp:314
Font
Container with information about a font.
Definition: gfx_layout.h:75
CoreTextParagraphLayout::CoreTextLine
A single line worth of VisualRuns.
Definition: string_osx.cpp:95
ParagraphLayouter::VisualRun
Visual run contains data about the bit of text with the same font.
Definition: gfx_layout.h:107
MacOSRegisterExternalFont
void MacOSRegisterExternalFont(const char *file_path)
Register an external font file with the CoreText system.
Definition: string_osx.cpp:303
FontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
_font_cache
static CFAutoRelease< CTFontRef > _font_cache[FS_END]
CoreText cache for font information, cleared when OTTD changes fonts.
Definition: string_osx.cpp:53
OSXStringIterator::SetCurPosition
size_t SetCurPosition(size_t pos) override
Change the current string cursor.
Definition: string_osx.cpp:430
CoreTextParagraphLayout::cur_offset
CFIndex cur_offset
Offset from the start of the current run from where to output.
Definition: string_osx.cpp:67
CoreTextParagraphLayoutFactory::CharType
UniChar CharType
Helper for GetLayouter, to get the right type.
Definition: string_osx.h:44
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
CoreTextParagraphLayout::CoreTextVisualRun
Visual run contains data about the bit of text with the same font.
Definition: string_osx.cpp:71
MacOSResetScriptCache
void MacOSResetScriptCache(FontSize size)
Delete CoreText font reference for a specific font size.
Definition: string_osx.cpp:297
OSXStringIterator::Next
size_t Next(IterType what) override
Advance the cursor by one iteration unit.
Definition: string_osx.cpp:448
macos.h
_osx_locale
static CFAutoRelease< CFLocaleRef > _osx_locale
Cached current locale.
Definition: string_osx.cpp:51
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:208
FontMap
std::map< int, Font * > FontMap
Mapping from index to font.
Definition: gfx_layout.h:84