From a865901405cfcec9c65c023356c655d2ae1c8236 Mon Sep 17 00:00:00 2001 From: "Oleg.Korshul" Date: Fri, 25 Jul 2025 11:21:08 +0300 Subject: [PATCH] Fix bug 57586 --- DesktopEditor/fontengine/ApplicationFonts.cpp | 10 +++ DesktopEditor/fontengine/ApplicationFonts.h | 5 ++ .../fontengine/ApplicationFonts_mac.mm | 64 +++++++++++++++++++ DesktopEditor/graphics/pro/fontengine.pri | 6 ++ 4 files changed, 85 insertions(+) create mode 100644 DesktopEditor/fontengine/ApplicationFonts_mac.mm diff --git a/DesktopEditor/fontengine/ApplicationFonts.cpp b/DesktopEditor/fontengine/ApplicationFonts.cpp index 018a2c1100..ed1a01fb1b 100644 --- a/DesktopEditor/fontengine/ApplicationFonts.cpp +++ b/DesktopEditor/fontengine/ApplicationFonts.cpp @@ -1853,6 +1853,16 @@ std::vector CApplicationFonts::GetSetupFontFiles(const bool& bIsUs #if defined(_MAC) && !defined(_IOS) std::vector _array = NSDirectory::GetFiles(L"/Library/Fonts", true); NSDirectory::GetFiles2(L"/System/Library/Fonts", _array, true); + + std::set installedList = GetInstalledFontsMac(); + for (const auto& sysPath : installedList) { + if (0 == sysPath.find(L"/System/Library/Fonts/")) + continue; + if (0 == sysPath.find(L"/Library/Fonts/")) + continue; + _array.push_back(sysPath); + } + return _array; #endif diff --git a/DesktopEditor/fontengine/ApplicationFonts.h b/DesktopEditor/fontengine/ApplicationFonts.h index 2b2658451f..a2fe97849c 100644 --- a/DesktopEditor/fontengine/ApplicationFonts.h +++ b/DesktopEditor/fontengine/ApplicationFonts.h @@ -38,6 +38,7 @@ #include #include #include "FontManager.h" +#include namespace NSFonts { @@ -354,6 +355,10 @@ public: void InitFromReg(); #endif +#if defined(_MAC) && !defined(_IOS) + std::set GetInstalledFontsMac(); +#endif + NSFonts::IFontManager* GenerateFontManager(); std::wstring GetFontBySymbol(int symbol); diff --git a/DesktopEditor/fontengine/ApplicationFonts_mac.mm b/DesktopEditor/fontengine/ApplicationFonts_mac.mm new file mode 100644 index 0000000000..a0b1349d44 --- /dev/null +++ b/DesktopEditor/fontengine/ApplicationFonts_mac.mm @@ -0,0 +1,64 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#include "ApplicationFonts.h" +#include "../common/File.h" +#import +#import + +std::set CApplicationFonts::GetInstalledFontsMac() +{ + std::set paths; + + CFArrayRef fontURLs = CTFontManagerCopyAvailableFontURLs(); + if (!fontURLs) + return paths; + + NSStringEncoding encode = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingUTF32LE); + + CFIndex count = CFArrayGetCount(fontURLs); + for (CFIndex i = 0; i < count; ++i) + { + CFURLRef url = (CFURLRef)CFArrayGetValueAtIndex(fontURLs, i); + if (!url) + continue; + + NSString* nsPath = [(__bridge NSURL *)url path]; + if (!nsPath) + continue; + + NSData* pSData = [nsPath dataUsingEncoding: encode]; + paths.emplace(std::wstring((wchar_t*)[pSData bytes], [pSData length] / sizeof (wchar_t))); + } + + CFRelease(fontURLs); + return paths; +} diff --git a/DesktopEditor/graphics/pro/fontengine.pri b/DesktopEditor/graphics/pro/fontengine.pri index c562a1ba87..9b9ce1de87 100644 --- a/DesktopEditor/graphics/pro/fontengine.pri +++ b/DesktopEditor/graphics/pro/fontengine.pri @@ -18,6 +18,12 @@ SOURCES += \ $$FONT_ENGINE_PATH/FontPath.cpp \ $$FONT_ENGINE_PATH/GlyphString.cpp +core_mac { + OBJECTIVE_SOURCES += $$FONT_ENGINE_PATH/ApplicationFonts_mac.mm + LIBS += -framework Foundation + LIBS += -framework CoreText +} + # Application fonts worker HEADERS += $$FONT_ENGINE_PATH/ApplicationFontsWorker.h SOURCES += $$FONT_ENGINE_PATH/ApplicationFontsWorker.cpp