Files
smart-city-digital-twin-mar…/smart-app-city/frontend/node_modules/expo-font/ios/FontUtils.swift
Eric FELIXINE e30ae8ed09 feat(smart-app): implement complete mobile app MVP
- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
2026-06-01 18:00:35 -04:00

91 lines
3.0 KiB
Swift

import CoreGraphics
/**
* Queries custom native font names from the Info.plist `UIAppFonts`.
*/
internal func queryCustomNativeFonts() -> [String] {
// [0] Read from main bundle's Info.plist
guard let fontFilePaths = Bundle.main.object(forInfoDictionaryKey: "UIAppFonts") as? [String] else {
return []
}
// [1] Get font family names for each font file
let fontFamilies: [[String]] = fontFilePaths.compactMap { fontFilePath in
guard let fontUrl = Bundle.main.url(forResource: fontFilePath, withExtension: nil) as? URL else {
return []
}
guard let fontDescriptors = CTFontManagerCreateFontDescriptorsFromURL(fontUrl as CFURL) as? [CTFontDescriptor] else {
return []
}
return fontDescriptors.compactMap { descriptor in
return CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute) as? String
}
}
// [2] Retrieve font names by family names
return fontFamilies.flatMap { fontFamilyNames in
return fontFamilyNames.flatMap { fontFamilyName in
#if os(iOS) || os(tvOS)
return UIFont.fontNames(forFamilyName: fontFamilyName)
#elseif os(macOS)
return NSFontManager.shared.availableMembers(ofFontFamily: fontFamilyName)?.compactMap { $0[0] as? String } ?? []
#endif
}
}
}
/**
Loads the font from the given url and returns it as ``CGFont``.
*/
internal func loadFont(fromUrl url: CFURL, alias: String) throws -> CGFont {
guard let provider = CGDataProvider(url: url),
let cgFont = CGFont(provider) else {
throw FontCreationFailedException(alias)
}
return cgFont
}
/**
Registers the given font to make it discoverable through font descriptor matching.
*/
internal func registerFont(_ fontUrl: CFURL) throws {
var error: Unmanaged<CFError>?
if !CTFontManagerRegisterFontsForURL(fontUrl, .process, &error), let error = error?.takeRetainedValue() {
let fontError = CTFontManagerError(rawValue: CFErrorGetCode(error))
switch fontError {
case .alreadyRegistered, .duplicatedName:
// Ignore the error if:
// - this exact font instance was already registered or
// - another instance already registered with the same name (assuming it's most likely the same font anyway)
return
default:
throw FontRegistrationFailedException(error)
}
}
}
/**
Unregisters the given font, so the app will no longer be able to render it.
Returns a boolean indicating if the font is successfully unregistered after this function completes.
*/
internal func unregisterFont(url: CFURL) throws -> Bool {
var error: Unmanaged<CFError>?
if !CTFontManagerUnregisterFontsForURL(url, .process, &error), let error = error?.takeRetainedValue() {
if let ctFontManagerError = CTFontManagerError(rawValue: CFErrorGetCode(error as CFError)) {
switch ctFontManagerError {
case .systemRequired, .inUse:
return false
case .notRegistered:
return true
default:
throw UnregisteringFontFailedException(error)
}
}
}
return true
}