OpenTTD Source  20240919-master-gdf0233f4c2
string_osx.cpp File Reference
#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. More...
 
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. More...
 
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. More...
 

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.

Function Documentation

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

◆ 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

◆ _sprite_font_callback

CTRunDelegateCallbacks _sprite_font_callback
static
Initial value:
= {
kCTRunDelegateCurrentVersion, nullptr, nullptr, nullptr,
}

Definition at line 146 of file string_osx.cpp.

SpriteFontGetWidth
static CGFloat SpriteFontGetWidth(void *ref_con)
Get the width of an encoded sprite font character.
Definition: string_osx.cpp:138