mac 字体遍历demo

文章目录

    • 逻辑字体类
    • 头文件
    • 实现文件
    • 使用文件主程序
    • CMakeLists文件
    • 脚本文件

逻辑字体类

#ifndef LOGICAL_FONT_H
#define LOGICAL_FONT_H#include <string>
#include <memory>
#include <CoreText/CoreText.h>
#include <CoreFoundation/CoreFoundation.h>class LogicalFont {
public:LogicalFont() = default;~LogicalFont() {if (character_set_) {CFRelease(character_set_);}}// Getters and setters for font namesconst std::string& en_family_name() const { return family_name_; }const std::string& en_face_name() const { return style_name_; }const std::string& en_postscript_name() const { return postscript_name_; }const std::string& localized_family_name() const { return localized_family_name_; }const std::string& localized_style_name() const { return localized_style_name_; }const std::string& localized_postscript_name() const { return localized_postscript_name_; }const std::string& full_name() const { return full_name_; }const std::string& font_path() const { return font_path_; }void set_family_name(const std::string& name) { family_name_ = name; }void set_style_name(const std::string& name) { style_name_ = name; }void set_postscript_name(const std::string& name) { postscript_name_ = name; }void set_localized_family_name(const std::string& name) { localized_family_name_ = name; }void set_localized_style_name(const std::string& name) { localized_style_name_ = name; }void set_localized_postscript_name(const std::string& name) { localized_postscript_name_ = name; }void set_full_name(const std::string& name) { full_name_ = name; }void set_font_path(const std::string& path) { font_path_ = path; }// Getters and setters for font metricsint32_t ascent() const { return ascent_; }int32_t descent() const { return descent_; }int32_t line_gap() const { return line_gap_; }int32_t cap_height() const { return cap_height_; }int32_t x_height() const { return x_height_; }int32_t underline_position() const { return underline_position_; }int32_t underline_thickness() const { return underline_thickness_; }int32_t strikethrough_position() const { return strikethrough_position_; }int32_t strikethrough_thickness() const { return strikethrough_thickness_; }int32_t slant_angle() const { return slant_angle_; }float weight() const { return weight_; }float width() const { return width_; }void set_ascent(int32_t value) { ascent_ = value; }void set_descent(int32_t value) { descent_ = value; }void set_line_gap(int32_t value) { line_gap_ = value; }void set_cap_height(int32_t value) { cap_height_ = value; }void set_x_height(int32_t value) { x_height_ = value; }void set_underline_position(int32_t value) { underline_position_ = value; }void set_underline_thickness(int32_t value) { underline_thickness_ = value; }void set_strikethrough_position(int32_t value) { strikethrough_position_ = value; }void set_strikethrough_thickness(int32_t value) { strikethrough_thickness_ = value; }void set_slant_angle(int32_t value) { slant_angle_ = value; }void set_weight(float value) { weight_ = value; }void set_width(float value) { width_ = value; }// Getters and setters for font style attributesbool bold() const { return bold_; }bool italic() const { return italic_; }void set_bold(bool value) { bold_ = value; }void set_italic(bool value) { italic_ = value; }// Character set handlingCFCharacterSetRef character_set() const { return character_set_; }void set_character_set(CFCharacterSetRef charset) {if (character_set_) {CFRelease(character_set_);}// 添加显式类型转换character_set_ = (CFCharacterSetRef)CFRetain(charset);}// CTFontRef handlingCTFontRef logical_font() const { return logical_font_; }void set_logical_font(CTFontRef font) { logical_font_ = font; }private:// Font namesstd::string family_name_;               // English family namestd::string style_name_;                // English style/face namestd::string postscript_name_;           // English PostScript namestd::string localized_family_name_;     // Localized family namestd::string localized_style_name_;      // Localized style namestd::string localized_postscript_name_; // Localized PostScript namestd::string full_name_;                 // Full font name (family + style)std::string font_path_;                 // Path to font file// Font metricsint32_t ascent_ = 0;int32_t descent_ = 0;int32_t line_gap_ = 0;int32_t cap_height_ = 0;int32_t x_height_ = 0;int32_t underline_position_ = 0;int32_t underline_thickness_ = 0;int32_t strikethrough_position_ = 0;int32_t strikethrough_thickness_ = 0;int32_t slant_angle_ = 0;float weight_ = 0.0f;float width_ = 0.0f;// Font style attributesbool bold_ = false;bool italic_ = false;// Character setCFCharacterSetRef character_set_ = nullptr;// CoreText font reference (weak reference, not owned)CTFontRef logical_font_ = nullptr;
};#endif // LOGICAL_FONT_H

头文件


#pragma once
#include <memory>
#include <CoreText/CoreText.h>
#include <type_traits>
#include <CoreText/CoreText.h>
#include <CoreGraphics/CoreGraphics.h>
#include <iostream>#include<memory>
#include <CoreText/CoreText.h>#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include<unordered_set>
#include "LogicalFont.hpp"namespace FontUtils {// CFString转std::stringstd::string CFStringToStdString(CFStringRef cfStr);// Unicode范围结构体struct UnicodeRange {uint32_t start;  // 范围起始码点uint32_t end;    // 范围结束码点};// CFURL转文件路径std::string CFURLToPath(CFURLRef url);// 字符串规范化(去空格/符号+转小写)std::string NormalizeString(std::string input);} // namespace FontUtilsclass FontManagerMac
{
public:FontManagerMac() {};~FontManagerMac() {};void EnumerateSystemFonts();private:// 处理所有字体家族void ProcessFontFamilies(CFArrayRef fontFamilies);// 处理单个字体家族void ProcessSingleFontFamily(CFStringRef familyName);// 处理字体描述符数组void ProcessFontDescriptors(CFArrayRef fontDescriptors, CFStringRef familyName);// 处理单个字体void ProcessSingleFont(CTFontDescriptorRef fontDescriptor, CFStringRef familyName, CFIndex index);void StoreFontInfo(const std::shared_ptr<LogicalFont>& log_font);bool GetFontInfo(std::shared_ptr<LogicalFont>& font, CTFontRef ctFont);bool GetExtendedFontMetrics(std::shared_ptr<LogicalFont> &font, CTFontRef ctf_font);std::vector<FontUtils::UnicodeRange> GetSupportedUnicodeRanges(CTFontRef font);public: //为了便于演示这些数据,直接设置为公开的// 字体对象映射容器std::unordered_map<std::string, std::shared_ptr<LogicalFont>> postscript_to_font_;std::unordered_map<std::string, std::shared_ptr<LogicalFont>> local_postscript_to_font_;std::unordered_map<std::string, std::shared_ptr<LogicalFont>> full_to_font_;// 名称集合容器std::unordered_set<std::string> family_set_;std::unordered_set<std::string> postscript_set_;std::unordered_set<std::string> local_family_set_;std::unordered_set<std::string> local_postscript_set_;// 名称映射容器std::unordered_map<std::string, std::string> postscript_to_family_;std::unordered_map<std::string, std::string> en_to_local_family_;std::unordered_map<std::string, std::string> local_to_en_ps_;std::map<std::string, std::vector<FontUtils::UnicodeRange>> font_unicode_ranges_map_ ; // 打印所有字体容器数据void PrintAllFontData() const {std::cout << "\n========== Font Container Data ==========\n";PrintFontMaps();PrintNameSets();PrintNameMappings();// PrintUnicodeRanges();std::cout << "========================================\n";}
private:// 打印字体对象映射void PrintFontMaps() const {std::cout << "\n[Font Object Mappings]\n";PrintMap("PostScript to Font", postscript_to_font_);PrintMap("Localized PostScript to Font", local_postscript_to_font_);PrintMap("Full Name to Font", full_to_font_);}// 打印名称集合void PrintNameSets() const {std::cout << "\n[Name Sets]\n";PrintSet("Family Names", family_set_);PrintSet("PostScript Names", postscript_set_);PrintSet("Localized Family Names", local_family_set_);PrintSet("Localized PostScript Names", local_postscript_set_);}// 打印名称映射void PrintNameMappings() const {std::cout << "\n[Name Mappings]\n";PrintStringMap("PostScript to Family", postscript_to_family_);PrintStringMap("English to Local Family", en_to_local_family_);PrintStringMap("Local to English PostScript", local_to_en_ps_);}// 打印Unicode范围void PrintUnicodeRanges() const {std::cout << "\n[Unicode Ranges by Font]\n";for (const auto& [fontName, ranges] : font_unicode_ranges_map_) {std::cout << "  " << fontName << ":\n";for (const auto& range : ranges) {std::cout << "    U+" << std::hex << std::uppercase << std::setw(4) << std::setfill('0') << range.start << "-U+" << std::setw(4) << range.end << std::dec << "\n";}}}// 辅助函数:打印unordered_map<string, shared_ptr>template<typename T>void PrintMap(const std::string& title, const std::unordered_map<std::string, std::shared_ptr<T>>& map) const {std::cout << "  " << title << " (" << map.size() << " items):\n";for (const auto& [key, value] : map) {std::cout << "    " << std::setw(40) << std::left << key << " -> " << (value ? value->en_postscript_name() : "nullptr") << "\n";}}// 辅助函数:打印unordered_set<string>void PrintSet(const std::string& title, const std::unordered_set<std::string>& set) const {std::cout << "  " << title << " (" << set.size() << " items):\n    ";size_t count = 0;for (const auto& item : set) {std::cout << item;if (++count % 5 == 0 && count != set.size()) std::cout << "\n    ";else if (count != set.size()) std::cout << ", ";}std::cout << "\n";}// 辅助函数:打印unordered_map<string, string>void PrintStringMap(const std::string& title, const std::unordered_map<std::string, std::string>& map) const {std::cout << "  " << title << " (" << map.size() << " items):\n";for (const auto& [key, value] : map) {std::cout << "    " << std::setw(40) << std::left << key << " -> " << value << "\n";}}
};

实现文件


#include "mac_font_traversal.h"
using std::shared_ptr;namespace FontUtils {std::string CFStringToStdString(CFStringRef cfStr) {if (!cfStr) return "";CFIndex length = CFStringGetLength(cfStr);CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;std::unique_ptr<char[]> buffer(new char[maxSize]);if (CFStringGetCString(cfStr, buffer.get(), maxSize, kCFStringEncodingUTF8)) {return std::string(buffer.get());}return "";}std::string CFURLToPath(CFURLRef url) {if (!url) {return {}; // 返回空字符串如果 URL 是空的}char path[PATH_MAX];if (!CFURLGetFileSystemRepresentation(url, true, (UInt8*)path, PATH_MAX)) {return {}; // 返回空字符串如果转换失败}return std::string(path); // 转换成功,返回路径字符串}std::string NormalizeString(std::string input) {std::string result;result.reserve(input.size());for (const unsigned char ch : input) {if (ch != ' ' && ch != '-' && ch != '_' && ch != ',' && !std::isspace(ch)) {result += std::tolower(ch);}}return result;}}// 函数:获取字体支持的Unicode范围
// 参数:字体引用(CTFontRef)
// 返回值:该字体支持的Unicode范围集合(vector<UnicodeRange>)
std::vector<FontUtils::UnicodeRange> FontManagerMac::GetSupportedUnicodeRanges(CTFontRef font) {std::vector<FontUtils::UnicodeRange> tempRanges; // 临时存储范围集合if (!font) {  // 检查字体引用是否有效return tempRanges; // 无效则返回空集合}// 1. 获取字体支持的字符集CFCharacterSetRef charset = CTFontCopyCharacterSet(font); // 复制字体字符集// 创建字符集的位图表示CFDataRef bitmapData = CFCharacterSetCreateBitmapRepresentation(kCFAllocatorDefault, charset);const UInt8 *bitmap = CFDataGetBytePtr(bitmapData); // 获取位图数据指针CFIndex length = CFDataGetLength(bitmapData);      // 获取位图数据长度bool inRange = false;   // 标记是否处于连续范围内uint32_t start = 0;     // 当前范围的起始码点uint32_t maxChar = 0;   // 当前范围的结束码点// 2. 遍历位图,检测并合并连续范围for (uint32_t byteIndex = 0; byteIndex < length; byteIndex++) {UInt8 byte = bitmap[byteIndex]; // 获取当前字节if (byte == 0) {  // 如果字节为0,表示没有支持的字符if (inRange) { // 如果之前处于范围内,则结束当前范围tempRanges.push_back({start, (byteIndex << 3) - 1});inRange = false;}continue; // 跳过后续处理}// 检查字节中的每一位(共8位)for (uint32_t bit = 0; bit < 8; bit++) {uint32_t currentChar = (byteIndex << 3) + bit; // 计算当前字符码点bool isSupported = (byte & (1 << bit)) != 0;   // 检查当前位是否被支持if (isSupported) {  // 如果字符被支持if (!inRange) { // 如果不在范围内,则开始新范围start = currentChar;inRange = true;}maxChar = currentChar; // 更新范围结束码点} else if (inRange) { // 如果字符不被支持但之前处于范围内tempRanges.push_back({start, currentChar - 1}); // 结束当前范围inRange = false;}}}// 处理最后一个范围(如果遍历结束时仍处于范围内)if (inRange) {tempRanges.push_back({start, maxChar});}// 3. 压缩范围(合并相邻或重叠的范围)if (!tempRanges.empty()) {size_t compressedCount = 0; // 压缩后的范围计数// 遍历所有范围for (size_t i = 1; i < tempRanges.size(); i++) {// 如果当前范围与前一个范围相邻或重叠if (tempRanges[i].start <= tempRanges[compressedCount].end + 1) {// 合并范围(取最大的结束码点)if (tempRanges[i].end > tempRanges[compressedCount].end) {tempRanges[compressedCount].end = tempRanges[i].end;}} else {// 不重叠则保留当前范围compressedCount++;tempRanges[compressedCount] = tempRanges[i];}}// 调整向量大小为压缩后的数量tempRanges.resize(compressedCount + 1);}// 释放资源CFRelease(bitmapData);CFRelease(charset);return tempRanges; // 返回最终的范围集合
}
void FontManagerMac::StoreFontInfo(const std::shared_ptr<LogicalFont>& font) {// 规范化名称const auto norm_face_name = FontUtils::NormalizeString(font->en_face_name());const auto norm_family_name = FontUtils::NormalizeString(font->en_family_name());const auto norm_ps_name = FontUtils::NormalizeString(font->en_postscript_name());const auto norm_local_ps_name = FontUtils::NormalizeString(font->localized_postscript_name());const auto norm_local_family_name = FontUtils::NormalizeString(font->localized_family_name());const auto norm_full_name = FontUtils::NormalizeString(font->full_name());// 字体对象映射postscript_to_font_.emplace(norm_ps_name, font);local_postscript_to_font_.emplace(norm_local_ps_name, font);full_to_font_.emplace(norm_full_name, font);// 名称集合family_set_.insert(norm_family_name);postscript_set_.insert(norm_ps_name);// 家族与Postscript名映射//family_to_postscript_[norm_family_name].insert(norm_ps_name);postscript_to_family_.emplace(norm_ps_name, norm_family_name);// 本地化名称集合local_family_set_.insert(font->localized_family_name());local_postscript_set_.insert(font->localized_postscript_name());// 本地化与标准名称映射en_to_local_family_.emplace(norm_family_name, norm_local_family_name);local_to_en_ps_.emplace(norm_local_ps_name, norm_ps_name);//处理对应的unicode 支持范围font_unicode_ranges_map_.try_emplace(norm_family_name,GetSupportedUnicodeRanges(font->logical_font()));}// 枚举系统字体void FontManagerMac::EnumerateSystemFonts() {// 获取系统所有可用字体家族名称数组CFArrayRef fontFamilies = CTFontManagerCopyAvailableFontFamilyNames();// 检查是否成功获取字体家族列表if (!fontFamilies) {std::cerr << "Error: Unable to get system font family list" << std::endl;return;}// 处理所有字体家族ProcessFontFamilies(fontFamilies);// 释放字体家族数组内存CFRelease(fontFamilies);}// 处理所有字体家族void FontManagerMac::ProcessFontFamilies(CFArrayRef fontFamilies) {// 获取字体家族数量CFIndex familyCount = CFArrayGetCount(fontFamilies);// 遍历每个字体家族for (CFIndex i = 0; i < familyCount; ++i) {// 获取当前索引的字体家族名称CFStringRef familyName = (CFStringRef)CFArrayGetValueAtIndex(fontFamilies, i);// 检查是否成功获取家族名称if (!familyName) {std::cerr << "Warning: Failed to get font family name at index " << i << std::endl;continue;}// 处理单个字体家族ProcessSingleFontFamily(familyName);}}// 处理单个字体家族void FontManagerMac::ProcessSingleFontFamily(CFStringRef familyName) {// 创建字体描述符(指定家族名称和默认大小0)CTFontDescriptorRef familyDescriptor = CTFontDescriptorCreateWithNameAndSize(familyName, 0);// 检查是否成功创建描述符if (!familyDescriptor) {std::cerr << "Warning: Failed to create descriptor for family "<< FontUtils::CFStringToStdString(familyName) << std::endl;return;}// 获取匹配该家族的所有字体描述符CFArrayRef fontDescriptors = CTFontDescriptorCreateMatchingFontDescriptors(familyDescriptor, NULL);// 释放家族描述符内存CFRelease(familyDescriptor);// 检查是否获取到字体描述符if (!fontDescriptors) {std::cerr << "Warning: No fonts found for family "<< FontUtils::CFStringToStdString(familyName) << std::endl;return;}// 处理该家族下的所有字体描述符ProcessFontDescriptors(fontDescriptors, familyName);// 释放字体描述符数组内存CFRelease(fontDescriptors);}// 处理字体描述符数组void FontManagerMac::ProcessFontDescriptors(CFArrayRef fontDescriptors, CFStringRef familyName) {// 获取字体描述符数量CFIndex fontCount = CFArrayGetCount(fontDescriptors);// 遍历每个字体描述符for (CFIndex j = 0; j < fontCount; ++j) {// 获取当前索引的字体描述符CTFontDescriptorRef fontDescriptor = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fontDescriptors, j);// 处理单个字体ProcessSingleFont(fontDescriptor, familyName, j);}}// 处理单个字体void FontManagerMac::ProcessSingleFont(CTFontDescriptorRef fontDescriptor, CFStringRef familyName, CFIndex index) {// 根据描述符创建字体对象CTFontRef font = CTFontCreateWithFontDescriptor(fontDescriptor, 0.0, NULL);// 检查是否成功创建字体if (!font) {std::cerr << "Warning: Failed to create font for descriptor " << index<< " in family " << FontUtils::CFStringToStdString(familyName) << std::endl;return;}// 创建逻辑字体对象auto log_font = std::make_shared<LogicalFont>();// 设置字体属性并存储有效字体if (GetFontInfo(log_font, font)) {StoreFontInfo(log_font);}// 释放字体对象内存CFRelease(font);}bool FontManagerMac::GetExtendedFontMetrics(std::shared_ptr<LogicalFont>& font, CTFontRef ctf_font) {if (!ctf_font || !font) return false;// 获取基本度量信息font->set_ascent(static_cast<int32_t>(CTFontGetAscent(ctf_font)));font->set_descent(static_cast<int32_t>(CTFontGetDescent(ctf_font)));font->set_line_gap(static_cast<int32_t>(CTFontGetLeading(ctf_font)));font->set_cap_height(static_cast<int32_t>(CTFontGetCapHeight(ctf_font)));font->set_x_height(static_cast<int32_t>(CTFontGetXHeight(ctf_font)));// 下划线信息font->set_underline_position(static_cast<int32_t>(CTFontGetUnderlinePosition(ctf_font)));font->set_underline_thickness(static_cast<int32_t>(CTFontGetUnderlineThickness(ctf_font)));// 删除线信息(估算)font->set_strikethrough_position(static_cast<int32_t>(font->strikethrough_position() * 0.5f));font->set_strikethrough_thickness(font->underline_thickness());// 斜体角度if (&CTFontGetSlantAngle != NULL) {font->set_slant_angle(static_cast<int32_t>(CTFontGetSlantAngle(ctf_font)));}// 字重CGFloat fontWeight = 0.0;CFDictionaryRef fontTraits = CTFontCopyTraits(ctf_font);if (fontTraits) {CFNumberRef weightTrait = (CFNumberRef)CFDictionaryGetValue(fontTraits, kCTFontWeightTrait);if (weightTrait) {CFNumberGetValue(weightTrait, kCFNumberCGFloatType, &fontWeight);fontWeight = (fontWeight - 0.4) / 0.6; // 标准化}CFRelease(fontTraits);}font->set_weight(fontWeight);// 字体宽度CGGlyph glyph;UniChar testChar = 'x';if (CTFontGetGlyphsForCharacters(ctf_font, &testChar, &glyph, 1)) {CGSize advance;CTFontGetAdvancesForGlyphs(ctf_font, kCTFontOrientationHorizontal, &glyph, &advance, 1);font->set_width(advance.width);}return true;
}
// 获取字体信息并填充到LogicalFont对象中
bool FontManagerMac::GetFontInfo(std::shared_ptr<LogicalFont>& font, CTFontRef ctf_font) {if (!font || !ctf_font) return false;CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(ctf_font);if (!descriptor) return false;// 一次性获取所有基础属性CFStringRef family = nullptr;CFStringRef styleName = nullptr;// 获取 family 和 styleName
if ((family = static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute)))) {font->set_family_name(FontUtils::CFStringToStdString(family));}if ((styleName = static_cast<CFStringRef>(CTFontDescriptorCopyAttribute(descriptor, kCTFontStyleNameAttribute)))) {font->set_style_name(FontUtils::CFStringToStdString(styleName));}// 设置全名(需要family和styleName)if (family && styleName) {font->set_full_name(FontUtils::CFStringToStdString(family) + " " +FontUtils::CFStringToStdString(styleName));}// 获取本地化名称if (CFStringRef localizedFamily = CTFontCopyLocalizedName(ctf_font, kCTFontFamilyNameKey, nullptr)) {font->set_localized_family_name(FontUtils::CFStringToStdString(localizedFamily));CFRelease(localizedFamily);}if (styleName) { // 本地化样式名需要styleNameif (CFStringRef localizedStyle = CTFontCopyLocalizedName(ctf_font, kCTFontStyleNameKey, nullptr)) {font->set_localized_style_name(FontUtils::CFStringToStdString(localizedStyle));CFRelease(localizedStyle);}}// 获取PostScript相关名称(独立操作)if (CFStringRef psName = CTFontCopyPostScriptName(ctf_font)) {font->set_postscript_name(FontUtils::CFStringToStdString(psName));CFRelease(psName);if (CFStringRef localizedPsName = CTFontCopyLocalizedName(ctf_font, kCTFontPostScriptNameKey, nullptr)) {font->set_localized_postscript_name(FontUtils::CFStringToStdString(localizedPsName));CFRelease(localizedPsName);}}// 获取字符集if (CFCharacterSetRef fontChars = CTFontCopyCharacterSet(ctf_font)) {font->set_character_set(fontChars);CFRelease(fontChars);}// 获取字体路径if (CFURLRef fontURL = static_cast<CFURLRef>(CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute))) {font->set_font_path(FontUtils::CFURLToPath(fontURL));CFRelease(fontURL);}// 释放基础属性if (family) CFRelease(family);if (styleName) CFRelease(styleName);// 获取扩展属性GetExtendedFontMetrics(font, ctf_font);font->set_logical_font(ctf_font);CFRelease(descriptor);return true;
}

使用文件主程序

#include "mac_font_traversal.h"int main()
{FontManagerMac  font_manager;font_manager.EnumerateSystemFonts();font_manager.PrintAllFontData();
}

CMakeLists文件

cmake_minimum_required(VERSION 3.15)
project(FontManagerMac)# 设置C++标准
set(CMAKE_CXX_STANDARD 17)# 查找macOS系统框架
find_library(COREFOUNDATION CoreFoundation REQUIRED)
find_library(CORETEXT CoreText REQUIRED)# 添加库目标
add_executable(FontManagerMac${CMAKE_CURRENT_SOURCE_DIR}/LogicalFont.hpp${CMAKE_CURRENT_SOURCE_DIR}/mac_font_traversal.h${CMAKE_CURRENT_SOURCE_DIR}/mac_font_traversal.cpp${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)# 链接系统框架
target_link_libraries(FontManagerMac PRIVATE${COREFOUNDATION}${CORETEXT}
)
# 找到并链接 CoreGraphics 和 ImageIO 框架
if(APPLE)find_library(COREGRAPHICS_FRAMEWORK CoreGraphics)find_library(IMAGEIO_FRAMEWORK ImageIO)target_link_libraries(FontManagerMac  PRIVATE ${COREGRAPHICS_FRAMEWORK} ${IMAGEIO_FRAMEWORK})
endif()# 包含当前目录
target_include_directories(FontManagerMac PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})# 针对Xcode额外设置
if(CMAKE_GENERATOR STREQUAL "Xcode")set_target_properties(FontManagerMac PROPERTIESXCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES"XCODE_ATTRIBUTE_GCC_INPUT_FILETYPE "sourcecode.cpp.utf-8")
endif()

脚本文件

#!/bin/bash# Set root directory
root_dir=$(pwd)# Function to perform the build
build() {local arch="$1"local build_type="$2"# Define directoriesbuild_dir=${root_dir}/build/mainmodule_build/MACOSX/${arch}install_dir=${root_dir}/installecho "Build dir: ${build_dir}"# Remove existing build dir to ensure a clean buildif [ -e $build_dir ]; thenrm -rf $build_dirfi# CMake command with common parameterscmake \-DBUILD_SHARED_LIBS:BOOL=TRUE \-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \-DCMAKE_BUILD_TYPE:STRING=${build_type} \-DCMAKE_INSTALL_PREFIX=${install_dir} \-DCMAKE_OSX_ARCHITECTURES=${arch} \-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 \-DSYSTEM:STRING=Darwin \-DAFS_TARGET_PLATFORM=mac \-DAFS_BUILD_MODE:STRING=build \-G "Xcode" \-S ${root_dir} \-B ${build_dir}# Build and installcmake --build ${build_dir} \--config ${build_type} \-j 14 \--
}# Call build function for Debug configurations only
build x86_64 Debug
# build arm64 Debug# # 定义输出路径
# output_path="${root_dir}/install/bin"
# debug_libs_dir="${output_path}/Debug"# # 确保Debug目录存在
# mkdir -p "${debug_libs_dir}"# # 检查要合并的库文件是否存在
# x86_lib="${output_path}/x86_64/Debug/PDFCore.dylib"
# arm_lib="${output_path}/arm64/Debug/PDFCore.dylib"# if [[ ! -f "${x86_lib}" || ! -f "${arm_lib}" ]]; then
#     echo "错误:找不到要合并的库文件"
#     echo "x86_64 库路径: ${x86_lib} - $(test -f "${x86_lib}" && echo "存在" || echo "不存在")"
#     echo "arm64 库路径: ${arm_lib} - $(test -f "${arm_lib}" && echo "存在" || echo "不存在")"
#     exit 1
# fi# # 合并Debug版本库
# echo "正在合并Debug库..."
# lipo -create \
#   "${x86_lib}" \
#   "${arm_lib}" \
#   -output "${debug_libs_dir}/PDFCore.dylib"# # 验证合并后的库
# if [[ -f "${debug_libs_dir}/PDFCore.dylib" ]]; then
#     echo "验证合并后的库架构:"
#     lipo -info "${debug_libs_dir}/PDFCore.dylib"
#     echo "库合并成功完成。"
# else
#     echo "错误:合并后的库文件未生成"
#     exit 1
# fi

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/94132.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/94132.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2025牛客多校第六场 D.漂亮矩阵 K.最大gcd C.栈 L.最小括号串 个人题解

L.最小括号串 #数组操作 #贪心 题目 思路 感谢Leratiomyces大佬赛时的提示&#xff0c;否则估计还一直签不了到&#xff08;&#xff09; 首先&#xff0c;贪心地构造出最优情况&#xff1a;数组左半部分全是(&#xff0c;右半部分全是)&#xff0c;随后通过判断给定的区间…

Ubuntu搭建PX4无人机仿真环境(5) —— 仿真环境搭建(以Ubuntu 22.04,ROS2 Humble 为例)

目录前言1. 准备下载源码方式一&#xff1a;方式二&#xff1a;安装依赖安装 Gazebo2. 安装 Micro XRCE-DDS Agent3. 编译4. 通信5. offboard 测试参考前言 本教程基于 ROS2 &#xff0c;在搭建之前&#xff0c;需要把 ROS2、QGC 等基础环境安装配置完成。但是这块的资料相比较…

自动驾驶中的传感器技术11——Camera(2)

1、自驾Camera关键技术点汇总 ADAS Camera 关键技术点摘选&#xff08;IEEE-P2020工作组&#xff09;如下&#xff1a; Ref &#xff1a; 5. IEEE 相关标准 - 图像质量与色彩技术知识库 https://www.image-engineering.de/content/library/white_paper/P2020_white_paper.pd…

福彩双色球第2025088期篮球号码分析

蔡楚门福彩双色球第2025088期篮球号码分析&#xff0c;上期开出篮球号码数字08&#xff0c;数字形式是合数偶数2路球数字&#xff0c;小号区域&#xff0c;0字头数字。本期篮球号码分析&#xff0c;4尾数0414遗漏9期上次遗漏11期&#xff0c;2尾数0212遗漏4期上次遗漏27期&…

【兆易创新】单片机GD32F103C8T6系列入门资料

GD32F103xx 系列器件是一款基于ARM Cortex-M3 RISC内核的32位通用微控制器&#xff0c;在处理能力、降低功耗和外设方面具有超优的性价比。Cortex-M3是下一代处理器核心&#xff0c;它与嵌套矢量中断控制器(NVIC)&#xff0c; SysTick计时器和高级调试支持紧密耦合。 GD32F103…

高效轻量的C++ HTTP服务:cpp-httplib使用指南

文章目录httplib介绍与安装使用案例httplib介绍与安装 C HTTP 库&#xff08;cpp-httplib&#xff09;是一个轻量级的 C HTTP 客户端/服务器库&#xff0c;它提供了简单的 API 来创建 HTTP 服务器和客户端&#xff0c;支持同步和异步操作。以下是一些关于cpp-httplib 的主要特…

24 SAP CPI 调用SAP HTTP接口

SAP CPI 访问SAP接口一般用RFC或者HTTP,个人在项目中两种方法都用过,最后还是倾向于HTTP的方式,此方式易于维护,统一管理,接口搭建比较方便。 读者朋友可网上自行搜索"SAP 发布HTTP接口",SAP CPI调用SAP发布的HTTP接口。 配置CPI接口前,需要将CPI的证书导入…

C/C++常用字符串函数

一、字符串函数介绍&#xff1a; 字符串作为程序中常用的数据类型&#xff0c;学会对字符串进行处理是作为一名C/C程序员的基本功&#xff0c;我们要学会使用相关函数&#xff0c;并且对重点函数要会自己手动实现&#xff08;下文对重点函数有实现代码以及相关示例&#xff09…

YOLO的Python实现以及 OpenCV

YOLO的Python实现以及 OpenCV Darknet 实现 YOLO 从头开始开发 YOLO模型不容易&#xff0c;所以我们要使用预训练模型在项目里进行目 标检测。你可以在 https://pjreddie.com里到所有可用的预训练模型。这是 Joseph C. Redmon的主页&#xff0c;他是 Darknet的维护者。 注意 …

译|Netflix 数据平台运营中基于机器学习自动修复系统

来自上传文件中的文章《Evolving from Rule-based Classifier: Machine Learning Powered Auto Remediation in Netflix Data Platform》 本文介绍了Netflix如何将基于规则的错误分类器与机器学习服务集成&#xff0c;实现Spark作业失败的自动修复。技术亮点包括结合规则和ML智…

PAES算法求解 ZDT1 双目标优化问题

前言 提醒&#xff1a; 文章内容为方便作者自己后日复习与查阅而进行的书写与发布&#xff0c;其中引用内容都会使用链接表明出处&#xff08;如有侵权问题&#xff0c;请及时联系&#xff09;。 其中内容多为一次书写&#xff0c;缺少检查与订正&#xff0c;如有问题或其他拓展…

逻辑回归的应用

一参数逻辑回归参数及多分类策略等完整解析LogisticRegression 初始参数声明LogisticRegression(penaltyl2, dualFalse, tol0.0001, C1.0, fit_interceptTrue, intercept_scaling1, class_weightNone, random_stateNone, solverliblinear, max_iter100, multi_classovr, verbos…

C语言(长期更新)第7讲:VS实用调试技巧

C语言&#xff08;长期更新&#xff09; 第7讲 VS实用调试技巧 跟着潼心走&#xff0c;轻松拿捏C语言&#xff0c;困惑通通走&#xff0c;一去不回头~欢迎开始今天的学习内容&#xff0c;你的支持就是博主最大的动力。 目录 C语言&#xff08;长期更新&#xff09; 第7讲 …

CONTRASTIVE-KAN:一种用于稀缺标记数据的网络安全半监督入侵检测框架

研究背景与挑战​ ​工业环境需求​: 第四次工业革命中,物联网(IoT)和工业物联网(IIoT)的普及使网络安全成为关键挑战。 入侵检测系统需实时性高,尤其对关键基础设施(如燃气管道)的快速攻击检测至关重要。 ​核心问题​: ​标签数据稀缺​:工业系统多数时间处于正常…

综合:单臂路由+三层交换技术+telnet配置+DHCP

技术考核1 实验拓扑&#xff1a;实验需求 1.按照图示配置IP地址设备名 2.在SW1和SW2之间配置链路聚合增加链路带宽&#xff0c;提高可靠性 3.PC5和PC6属于VLAN10&#xff0c; PC7和PC8属于VLAN20 4.SW1和SW2属于二层交换机&#xff0c;SW3为三层交换机&#xff08;VLAN100用于对…

工业火焰识别漏报率↓78%!陌讯多模态融合算法实战解析

原创声明&#xff1a;本文技术方案解析基于陌讯技术白皮书2025版 标签&#xff1a;#陌讯视觉算法 #火焰识别优化 #工业安全监控 #边缘计算优化一、行业痛点&#xff1a;工业火灾监控的漏检危机据《2025工业安全白皮书》统计&#xff0c;化工场景传统火焰识别系统漏报率高达35%&…

C++引用:高效安全的别名机制详解

目录 一、引用的概念 二、引用的特性 1、定义时必须初始化 2、一个变量可以有多个引用 3、引用一旦绑定实体就不能更改 三、const引用&#xff08;常引用&#xff09; 1、const引用的基本特性 2、临时对象与const引用 3、临时对象的特性 4、const 引用作为函数形参 …

大语言模型API付费?

下面是目前主流 大语言模型 API 的付费情况总览&#xff1a; &#x1f9e0; 一、主要大语言模型 API&#xff1a;是否付费对比 提供方模型是否免费限制 / 说明OpenAIGPT-3.5 / GPT-4 / GPT-4o❌ 付费为主有免费额度&#xff08;如 ChatGPT 免费版&#xff09;&#xff0c;API …

巧用Wisdom SSH:容器化运维与传统运维的抉择

巧用Wisdom SSH&#xff1a;容器化运维与传统运维的抉择 在当下的技术领域&#xff0c;容器化运维与传统运维是运维人员面临的两大主要方向&#xff0c;对于从业者来说&#xff0c;如何抉择至关重要&#xff0c;而Wisdom SSH在其中能发挥显著作用。 传统运维&#xff1a;基石…

API征服者:Python抓取星链卫星实时轨迹

API征服者&#xff1a;Python抓取星链卫星实时轨迹从基础调用到工业级卫星追踪系统实战指南一、太空数据时代&#xff1a;星链卫星的全球覆盖​​星链卫星网络规模​​&#xff1a;已发射卫星数量&#xff1a;4,000目标卫星总数&#xff1a;42,000轨道高度&#xff1a;340km - …