1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-27 06:04:25 +01:00

Codechange: remove unneeded MacOSVersionIsAtLeast calls

This commit is contained in:
Rubidium
2026-01-22 20:43:30 +01:00
committed by rubidium42
parent 009905e39e
commit 6b3eaba308
6 changed files with 15 additions and 68 deletions

View File

@@ -123,12 +123,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
{
/* Get glyph size. */
CGGlyph glyph = (CGGlyph)key;
CGRect bounds = CGRectNull;
if (MacOSVersionIsAtLeast(10, 8, 0)) {
bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0);
} else {
bounds = CTFontGetBoundingRectsForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1);
}
CGRect bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0);
if (CGRectIsNull(bounds)) UserError("Unable to render font glyph");
uint bb_width = (uint)std::ceil(bounds.size.width) + 1; // Sometimes the glyph bounds are too tight and cut of the last pixel after rounding.
@@ -218,15 +213,10 @@ public:
std::string font = GetFontCacheFontName(fs);
if (font.empty()) return nullptr;
CFAutoRelease<CTFontDescriptorRef> font_ref;
if (MacOSVersionIsAtLeast(10, 6, 0)) {
/* Might be a font file name, try load it. */
font_ref.reset(LoadFontFromFile(font));
if (!font_ref) ShowInfo("Unable to load file '{}' for {} font, using default OS font selection instead", font, FontSizeToName(fs));
}
/* Might be a font file name, try load it. */
CFAutoRelease<CTFontDescriptorRef> font_ref(LoadFontFromFile(font));
if (!font_ref) {
ShowInfo("Unable to load file '{}' for {} font, using default OS font selection instead", font, FontSizeToName(fs));
CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, font.c_str(), kCFStringEncodingUTF8));
/* Simply creating the font using CTFontCreateWithNameAndSize will *always* return
@@ -339,8 +329,6 @@ public:
private:
static CTFontDescriptorRef LoadFontFromFile(const std::string &font_name)
{
if (!MacOSVersionIsAtLeast(10, 6, 0)) return nullptr;
/* Might be a font file name, try load it. Direct font loading is
* only supported starting on OSX 10.6. */
CFAutoRelease<CFStringRef> path;

View File

@@ -15,25 +15,6 @@ void ShowMacDialog(std::string_view title, std::string_view message, std::string
void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix);
/**
* Check if we are at least running on the specified version of Mac OS.
* @param major major version of the os. This would be 10 in the case of 10.4.11.
* @param minor minor version of the os. This would be 4 in the case of 10.4.11.
* @param bugfix bugfix version of the os. This would be 11 in the case of 10.4.11.
* @return true if the running os is at least what we asked, false otherwise.
*/
inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
{
int version_major, version_minor, version_bugfix;
GetMacOSVersion(&version_major, &version_minor, &version_bugfix);
if (version_major < major) return false;
if (version_major == major && version_minor < minor) return false;
if (version_major == major && version_minor == minor && version_bugfix < bugfix) return false;
return true;
}
bool IsMonospaceFont(CFStringRef name);
void MacOSSetThreadName(const std::string &name);

View File

@@ -193,9 +193,7 @@ bool IsMonospaceFont(CFStringRef name)
*/
void MacOSSetThreadName(const std::string &name)
{
if (MacOSVersionIsAtLeast(10, 6, 0)) {
pthread_setname_np(name.c_str());
}
pthread_setname_np(name.c_str());
NSThread *cur = [ NSThread currentThread ];
if (cur != nil && [ cur respondsToSelector:@selector(setName:) ]) {

View File

@@ -124,8 +124,6 @@ static const CTRunDelegateCallbacks _sprite_font_callback = {
/* static */ std::unique_ptr<ParagraphLayouter> CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping)
{
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
/* Can't layout an empty string. */
ptrdiff_t length = buff_end - buff;
if (length == 0) return nullptr;
@@ -276,8 +274,6 @@ void MacOSResetScriptCache(FontSize size)
/** Register an external font file with the CoreText system. */
void MacOSRegisterExternalFont(std::string_view file_path)
{
if (!MacOSVersionIsAtLeast(10, 6, 0)) return;
CFAutoRelease<CFStringRef> path(CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(file_path.data()), file_path.size(), kCFStringEncodingUTF8, false));
CFAutoRelease<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false));
@@ -287,8 +283,6 @@ void MacOSRegisterExternalFont(std::string_view file_path)
/** Store current language locale as a CoreFoundation locale. */
void MacOSSetCurrentLocaleName(std::string_view iso_code)
{
if (!MacOSVersionIsAtLeast(10, 5, 0)) return;
CFAutoRelease<CFStringRef> iso(CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(iso_code.data()), iso_code.size(), kCFStringEncodingUTF8, false));
_osx_locale.reset(CFLocaleCreate(kCFAllocatorDefault, iso.get()));
}
@@ -302,9 +296,6 @@ void MacOSSetCurrentLocaleName(std::string_view iso_code)
*/
int MacOSStringCompare(std::string_view s1, std::string_view s2)
{
static const bool supported = MacOSVersionIsAtLeast(10, 5, 0);
if (!supported) return 0;
CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
CFAutoRelease<CFStringRef> cf1(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s1.data(), s1.size(), kCFStringEncodingUTF8, false));
@@ -326,9 +317,6 @@ int MacOSStringCompare(std::string_view s1, std::string_view s2)
*/
int MacOSStringContains(std::string_view str, std::string_view value, bool case_insensitive)
{
static const bool supported = MacOSVersionIsAtLeast(10, 5, 0);
if (!supported) return -1;
CFStringCompareFlags flags = kCFCompareLocalized | kCFCompareWidthInsensitive;
if (case_insensitive) flags |= kCFCompareCaseInsensitive;
@@ -447,7 +435,5 @@ int MacOSStringContains(std::string_view str, std::string_view value, bool case_
/* static */ std::unique_ptr<StringIterator> OSXStringIterator::Create()
{
if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr;
return std::make_unique<OSXStringIterator>();
}

View File

@@ -103,8 +103,6 @@ void VideoDriver_Cocoa::Stop()
*/
std::optional<std::string_view> VideoDriver_Cocoa::Initialize()
{
if (!MacOSVersionIsAtLeast(10, 7, 0)) return "The Cocoa video driver requires Mac OS X 10.7 or later.";
if (_cocoa_video_started) return "Already started";
_cocoa_video_started = true;
@@ -237,18 +235,16 @@ std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates()
{
std::vector<int> rates{};
if (MacOSVersionIsAtLeast(10, 6, 0)) {
std::array<CGDirectDisplayID, 16> displays;
std::array<CGDirectDisplayID, 16> displays;
uint32_t count = 0;
CGGetActiveDisplayList(displays.size(), displays.data(), &count);
uint32_t count = 0;
CGGetActiveDisplayList(displays.size(), displays.data(), &count);
for (uint32_t i = 0; i < count; i++) {
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
int rate = (int)CGDisplayModeGetRefreshRate(mode);
if (rate > 0) rates.push_back(rate);
CGDisplayModeRelease(mode);
}
for (uint32_t i = 0; i < count; i++) {
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
int rate = static_cast<int>(CGDisplayModeGetRefreshRate(mode));
if (rate > 0) rates.push_back(rate);
CGDisplayModeRelease(mode);
}
return rates;

View File

@@ -310,10 +310,8 @@ static void setupWindowMenu()
[ menuItem setSubmenu:windowMenu ];
[ [ NSApp mainMenu ] addItem:menuItem ];
if (MacOSVersionIsAtLeast(10, 7, 0)) {
/* The OS will change the name of this menu item automatically */
[ windowMenu addItemWithTitle:@"Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"^f" ];
}
/* The OS will change the name of this menu item automatically */
[ windowMenu addItemWithTitle:@"Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"^f" ];
/* Tell the application object that this is now the window menu */
[ NSApp setWindowsMenu:windowMenu ];