OpenTTD Source 20241224-master-gee860a5c8e
string_osx.cpp File Reference

Functions related to localized text support on OSX. More...

#include "../../stdafx.h"
#include "string_osx.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../table/control_codes.h"
#include "../../fontcache.h"
#include "../../zoom_func.h"
#include "macos.h"
#include <CoreFoundation/CoreFoundation.h>

Go to the source code of this file.

Data Structures

struct  CTRunDelegateCallbacks
 
class  CoreTextParagraphLayout
 Wrapper for doing layouts with CoreText. More...
 
class  CoreTextParagraphLayout::CoreTextVisualRun
 Visual run contains data about the bit of text with the same font. More...
 
class  CoreTextParagraphLayout::CoreTextLine
 A single line worth of VisualRuns. More...
 

Typedefs

typedef const struct __CTRunDelegate * CTRunDelegateRef
 
typedef void(* CTRunDelegateDeallocateCallback) (void *refCon)
 
typedef CGFloat(* CTRunDelegateGetAscentCallback) (void *refCon)
 
typedef CGFloat(* CTRunDelegateGetDescentCallback) (void *refCon)
 
typedef CGFloat(* CTRunDelegateGetWidthCallback) (void *refCon)
 

Enumerations

enum  { kCTRunDelegateVersion1 = 1 , kCTRunDelegateCurrentVersion = kCTRunDelegateVersion1 }
 

Functions

CTRunDelegateRef CTRunDelegateCreate (const CTRunDelegateCallbacks *callbacks, void *refCon) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
 
static CGFloat SpriteFontGetWidth (void *ref_con)
 Get the width of an encoded sprite font character.
 
void MacOSResetScriptCache (FontSize size)
 Delete CoreText font reference for a specific font size.
 
void MacOSRegisterExternalFont (const char *file_path)
 Register an external font file with the CoreText system.
 
void MacOSSetCurrentLocaleName (const char *iso_code)
 Store current language locale as a CoreFoundation locale.
 
int MacOSStringCompare (std::string_view s1, std::string_view s2)
 Compares two strings using case insensitive natural sort.
 
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.
 

Variables

const CFStringRef kCTRunDelegateAttributeName AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
 
static CFAutoRelease< CFLocaleRef > _osx_locale
 Cached current locale.
 
static CFAutoRelease< CTFontRef > _font_cache [FS_END]
 CoreText cache for font information, cleared when OTTD changes fonts.
 
static CTRunDelegateCallbacks _sprite_font_callback
 

Detailed Description

Functions related to localized text support on OSX.

Definition in file string_osx.cpp.

Typedef Documentation

◆ CTRunDelegateDeallocateCallback

typedef void(* CTRunDelegateDeallocateCallback) (void *refCon)

Definition at line 27 of file string_osx.cpp.

◆ CTRunDelegateGetAscentCallback

typedef CGFloat(* CTRunDelegateGetAscentCallback) (void *refCon)

Definition at line 28 of file string_osx.cpp.

◆ CTRunDelegateGetDescentCallback

typedef CGFloat(* CTRunDelegateGetDescentCallback) (void *refCon)

Definition at line 29 of file string_osx.cpp.

◆ CTRunDelegateGetWidthCallback

typedef CGFloat(* CTRunDelegateGetWidthCallback) (void *refCon)

Definition at line 30 of file string_osx.cpp.

◆ CTRunDelegateRef

typedef const struct __CTRunDelegate* CTRunDelegateRef

Definition at line 25 of file string_osx.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 39 of file string_osx.cpp.

Function Documentation

◆ MacOSRegisterExternalFont()

void MacOSRegisterExternalFont ( const char *  file_path)

Register an external font file with the CoreText system.

Definition at line 303 of file string_osx.cpp.

References MacOSVersionIsAtLeast().

◆ MacOSResetScriptCache()

void MacOSResetScriptCache ( FontSize  size)

Delete CoreText font reference for a specific font size.

Definition at line 297 of file string_osx.cpp.

References _font_cache.

Referenced by Layouter::ResetFontCache().

◆ MacOSSetCurrentLocaleName()

void MacOSSetCurrentLocaleName ( const char *  iso_code)

Store current language locale as a CoreFoundation locale.

Definition at line 314 of file string_osx.cpp.

References _osx_locale, and MacOSVersionIsAtLeast().

Referenced by ReadLanguagePack().

◆ MacOSStringCompare()

int MacOSStringCompare ( std::string_view  s1,
std::string_view  s2 
)

Compares two strings using case insensitive natural sort.

Parameters
s1First string to compare.
s2Second string to compare.
Returns
1 if s1 < s2, 2 if s1 == s2, 3 if s1 > s2, or 0 if not supported by the OS.

Definition at line 329 of file string_osx.cpp.

References _osx_locale, and MacOSVersionIsAtLeast().

Referenced by StrNaturalCompare().

◆ 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.

Parameters
strString to search in.
valueString to search for.
case_insensitiveSearch case-insensitive.
Returns
1 if value was found, 0 if it was not found, or -1 if not supported by the OS.

Definition at line 353 of file string_osx.cpp.

References _osx_locale, and MacOSVersionIsAtLeast().

Referenced by StrNaturalContains(), and StrNaturalContainsIgnoreCase().

◆ SpriteFontGetWidth()

static CGFloat SpriteFontGetWidth ( void *  ref_con)
static

Get the width of an encoded sprite font character.


Definition at line 138 of file string_osx.cpp.

References GetGlyphWidth().

Variable Documentation

◆ _font_cache

CFAutoRelease<CTFontRef> _font_cache[FS_END]
static

CoreText cache for font information, cleared when OTTD changes fonts.

Definition at line 53 of file string_osx.cpp.

Referenced by CoreTextParagraphLayoutFactory::GetParagraphLayout(), and MacOSResetScriptCache().

◆ _osx_locale

CFAutoRelease<CFLocaleRef> _osx_locale
static

Cached current locale.

Definition at line 51 of file string_osx.cpp.

Referenced by MacOSSetCurrentLocaleName(), MacOSStringCompare(), MacOSStringContains(), and OSXStringIterator::SetString().

◆ _sprite_font_callback

CTRunDelegateCallbacks _sprite_font_callback
static
Initial value:
= {
kCTRunDelegateCurrentVersion, nullptr, nullptr, nullptr,
}
static CGFloat SpriteFontGetWidth(void *ref_con)
Get the width of an encoded sprite font character.

Definition at line 146 of file string_osx.cpp.