CTFontManager.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. {
  2. * CTFontManager.h
  3. * CoreText
  4. *
  5. * Copyright (c) 2008 Apple Inc. All rights reserved.
  6. *
  7. }
  8. { Initial Pascal Translation: Jonas Maebe, <[email protected]>, October 2009 }
  9. {
  10. Modified for use with Free Pascal
  11. Version 308
  12. Please report any bugs to <[email protected]>
  13. }
  14. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  15. {$mode macpas}
  16. {$packenum 1}
  17. {$macro on}
  18. {$inline on}
  19. {$calling mwpascal}
  20. unit CTFontManager;
  21. interface
  22. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  23. {$setc GAP_INTERFACES_VERSION := $0308}
  24. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  25. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  26. {$endc}
  27. {$ifc defined CPUPOWERPC and defined CPUI386}
  28. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  29. {$endc}
  30. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  31. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  32. {$endc}
  33. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  34. {$setc __ppc__ := 1}
  35. {$elsec}
  36. {$setc __ppc__ := 0}
  37. {$endc}
  38. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  39. {$setc __ppc64__ := 1}
  40. {$elsec}
  41. {$setc __ppc64__ := 0}
  42. {$endc}
  43. {$ifc not defined __i386__ and defined CPUI386}
  44. {$setc __i386__ := 1}
  45. {$elsec}
  46. {$setc __i386__ := 0}
  47. {$endc}
  48. {$ifc not defined __x86_64__ and defined CPUX86_64}
  49. {$setc __x86_64__ := 1}
  50. {$elsec}
  51. {$setc __x86_64__ := 0}
  52. {$endc}
  53. {$ifc not defined __arm__ and defined CPUARM}
  54. {$setc __arm__ := 1}
  55. {$elsec}
  56. {$setc __arm__ := 0}
  57. {$endc}
  58. {$ifc defined cpu64}
  59. {$setc __LP64__ := 1}
  60. {$elsec}
  61. {$setc __LP64__ := 0}
  62. {$endc}
  63. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  64. {$error Conflicting definitions for __ppc__ and __i386__}
  65. {$endc}
  66. {$ifc defined __ppc__ and __ppc__}
  67. {$setc TARGET_CPU_PPC := TRUE}
  68. {$setc TARGET_CPU_PPC64 := FALSE}
  69. {$setc TARGET_CPU_X86 := FALSE}
  70. {$setc TARGET_CPU_X86_64 := FALSE}
  71. {$setc TARGET_CPU_ARM := FALSE}
  72. {$setc TARGET_OS_MAC := TRUE}
  73. {$setc TARGET_OS_IPHONE := FALSE}
  74. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  75. {$elifc defined __ppc64__ and __ppc64__}
  76. {$setc TARGET_CPU_PPC := FALSE}
  77. {$setc TARGET_CPU_PPC64 := TRUE}
  78. {$setc TARGET_CPU_X86 := FALSE}
  79. {$setc TARGET_CPU_X86_64 := FALSE}
  80. {$setc TARGET_CPU_ARM := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_IPHONE := FALSE}
  83. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  84. {$elifc defined __i386__ and __i386__}
  85. {$setc TARGET_CPU_PPC := FALSE}
  86. {$setc TARGET_CPU_PPC64 := FALSE}
  87. {$setc TARGET_CPU_X86 := TRUE}
  88. {$setc TARGET_CPU_X86_64 := FALSE}
  89. {$setc TARGET_CPU_ARM := FALSE}
  90. {$ifc defined(iphonesim)}
  91. {$setc TARGET_OS_MAC := FALSE}
  92. {$setc TARGET_OS_IPHONE := TRUE}
  93. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  94. {$elsec}
  95. {$setc TARGET_OS_MAC := TRUE}
  96. {$setc TARGET_OS_IPHONE := FALSE}
  97. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  98. {$endc}
  99. {$elifc defined __x86_64__ and __x86_64__}
  100. {$setc TARGET_CPU_PPC := FALSE}
  101. {$setc TARGET_CPU_PPC64 := FALSE}
  102. {$setc TARGET_CPU_X86 := FALSE}
  103. {$setc TARGET_CPU_X86_64 := TRUE}
  104. {$setc TARGET_CPU_ARM := FALSE}
  105. {$setc TARGET_OS_MAC := TRUE}
  106. {$setc TARGET_OS_IPHONE := FALSE}
  107. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  108. {$elifc defined __arm__ and __arm__}
  109. {$setc TARGET_CPU_PPC := FALSE}
  110. {$setc TARGET_CPU_PPC64 := FALSE}
  111. {$setc TARGET_CPU_X86 := FALSE}
  112. {$setc TARGET_CPU_X86_64 := FALSE}
  113. {$setc TARGET_CPU_ARM := TRUE}
  114. { will require compiler define when/if other Apple devices with ARM cpus ship }
  115. {$setc TARGET_OS_MAC := FALSE}
  116. {$setc TARGET_OS_IPHONE := TRUE}
  117. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  118. {$elsec}
  119. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  120. {$endc}
  121. {$ifc defined __LP64__ and __LP64__ }
  122. {$setc TARGET_CPU_64 := TRUE}
  123. {$elsec}
  124. {$setc TARGET_CPU_64 := FALSE}
  125. {$endc}
  126. {$ifc defined FPC_BIG_ENDIAN}
  127. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  128. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  129. {$elifc defined FPC_LITTLE_ENDIAN}
  130. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  131. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  132. {$elsec}
  133. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  134. {$endc}
  135. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  136. {$setc CALL_NOT_IN_CARBON := FALSE}
  137. {$setc OLDROUTINENAMES := FALSE}
  138. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  139. {$setc OPAQUE_UPP_TYPES := TRUE}
  140. {$setc OTCARBONAPPLICATION := TRUE}
  141. {$setc OTKERNEL := FALSE}
  142. {$setc PM_USE_SESSION_APIS := TRUE}
  143. {$setc TARGET_API_MAC_CARBON := TRUE}
  144. {$setc TARGET_API_MAC_OS8 := FALSE}
  145. {$setc TARGET_API_MAC_OSX := TRUE}
  146. {$setc TARGET_CARBON := TRUE}
  147. {$setc TARGET_CPU_68K := FALSE}
  148. {$setc TARGET_CPU_MIPS := FALSE}
  149. {$setc TARGET_CPU_SPARC := FALSE}
  150. {$setc TARGET_OS_UNIX := FALSE}
  151. {$setc TARGET_OS_WIN32 := FALSE}
  152. {$setc TARGET_RT_MAC_68881 := FALSE}
  153. {$setc TARGET_RT_MAC_CFM := FALSE}
  154. {$setc TARGET_RT_MAC_MACHO := TRUE}
  155. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  156. {$setc TYPE_BOOL := FALSE}
  157. {$setc TYPE_EXTENDED := FALSE}
  158. {$setc TYPE_LONGLONG := TRUE}
  159. uses MacTypes,CTFontDescriptor,CTFontManagerErrors,CFBase,CFArray,CFError;
  160. {$endc} {not MACOSALLINCLUDE}
  161. {$ifc TARGET_OS_MAC}
  162. {$ALIGN POWER}
  163. {!
  164. @header
  165. Thread Safety Information
  166. All functions in this header are thread safe unless otherwise specified.
  167. }
  168. {!
  169. @constant CTRegisterBundleFonts
  170. @discussion If this key is defined in the application bundle info dictionary with a boolean value of true, CTFontManager will register all fonts in the Fonts subdirectory of the bundle's Resources directory in the process scope.
  171. }
  172. {!
  173. @function CTFontManagerCopyAvailablePostScriptNames
  174. @abstract Returns an array of unique PostScript font names.
  175. @result This function returns a retained reference to a CFArray of CFString references, or NULL on error. The caller is responsible for releasing the array.
  176. }
  177. function CTFontManagerCopyAvailablePostScriptNames: CFArrayRef; external name '_CTFontManagerCopyAvailablePostScriptNames';
  178. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  179. {!
  180. @function CTFontManagerCopyAvailableFontFamilyNames
  181. @abstract Returns an array of visible font family names sorted for UI display.
  182. @result This function returns a retained reference to a CFArray of CFString references, or NULL on error. The caller is responsible for releasing the array.
  183. }
  184. function CTFontManagerCopyAvailableFontFamilyNames: CFArrayRef; external name '_CTFontManagerCopyAvailableFontFamilyNames';
  185. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  186. {!
  187. @function CTFontManagerCopyAvailableFontURLs
  188. @abstract Returns an array of font URLs.
  189. @result This function returns a retained reference to a CFArray of CFURL references, or NULL on error. The caller is responsible for releasing the array.
  190. }
  191. function CTFontManagerCopyAvailableFontURLs: CFArrayRef; external name '_CTFontManagerCopyAvailableFontURLs';
  192. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  193. {!
  194. @function CTFontManagerCompareFontFamilyNames
  195. @abstract A CFComparatorFunction to compare font family names and sort them according to Apple guidelines.
  196. @discussion This function compares font family names and sorts them in the Apple preferred order, accounting for foundry prefix. Family names with recognized prefixes are sorted after the un-prefixed names in prefix order.
  197. @param family1
  198. The first localized font family name, as CFStringRef.
  199. @param family2
  200. The second localized font family name, as CFStringRef.
  201. @param context
  202. Unused. Can be NULL.
  203. @result A CFComparisonResult value indicating the sort order for the two family names. kCFComparisonResultGreatherThan if family1 is greater than family2, kCFComparisonResultLessThan if family1 is less than family2, and kCFComparisonResultEqualTo if they are equal.
  204. }
  205. function CTFontManagerCompareFontFamilyNames( family1: {const} UnivPtr; family2: {const} UnivPtr; context: UnivPtr ): CFComparisonResult; external name '_CTFontManagerCompareFontFamilyNames';
  206. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  207. {!
  208. @function CTFontManagerCreateFontDescriptorsFromURL
  209. @abstract Returns an array of font descriptors representing each of the fonts in the specified URL.
  210. Note: these font descriptors are not availabe through font descriptor matching.
  211. @param fileURL
  212. A file system URL referencing a valid font file.
  213. @result This function returns a retained reference to a CFArray, or NULL on error. The caller is responsible for releasing the array.
  214. }
  215. function CTFontManagerCreateFontDescriptorsFromURL( fileURL: CFURLRef ): CFArrayRef; external name '_CTFontManagerCreateFontDescriptorsFromURL';
  216. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  217. {!
  218. @enum CTFontManagerScope
  219. @abstract Scope for font registration.
  220. @constant kCTFontManagerScopeProcess
  221. The font is available to the current process for the duration of the process unless directly unregistered.
  222. @constant kCTFontManagerScopeUser
  223. The font is available to all processes for the current user session and will be available in subsequent sessions unless unregistered.
  224. @constant kCTFontManagerScopeSession
  225. The font is available to the current user session, and will not be available in subsequent sessions.
  226. }
  227. const
  228. kCTFontManagerScopeNone = 0;
  229. kCTFontManagerScopeProcess = 1;
  230. kCTFontManagerScopeUser = 2;
  231. kCTFontManagerScopeSession = 3;
  232. type
  233. CTFontManagerScope = UInt32;
  234. {!
  235. @function CTFontManagerRegisterFontsForURL
  236. @abstract Registers fonts from the specified font URL with the font manager. Registered fonts are discoverable through font descriptor matching.
  237. @param fontURL
  238. Font URL.
  239. @param scope
  240. Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
  241. @param error
  242. Pointer to receive CFError in the case of failed registration.
  243. @result Returns true if registration of the fonts was successful.
  244. }
  245. function CTFontManagerRegisterFontsForURL( fontURL: CFURLRef; scope: CTFontManagerScope; var error: CFErrorRef ): CBool; external name '_CTFontManagerRegisterFontsForURL';
  246. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  247. {!
  248. @function CTFontManagerUnregisterFontsForURL
  249. @abstract Unregisters fonts from the specified font URL with the font manager. Unregistered fonts are no longer discoverable through font descriptor matching.
  250. @param fontURL
  251. Font URL.
  252. @param scope
  253. Scope constant defining the availability and lifetime of the registration. Should match the scope the fonts are registered in. See scope constants for more details.
  254. @param error
  255. Pointer to receive CFError in the case of failed unregistration.
  256. @result Returns true if unregistration of the fonts was successful.
  257. }
  258. function CTFontManagerUnregisterFontsForURL( fontURL: CFURLRef; scope: CTFontManagerScope; var error: CFErrorRef ): CBool; external name '_CTFontManagerUnregisterFontsForURL';
  259. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  260. {!
  261. @function CTFontManagerRegisterFontsForURLs
  262. @abstract Registers fonts from the specified font URLs with the font manager. Registered fonts are discoverable through font descriptor matching.
  263. @param fontURLs
  264. Array of font URLs.
  265. @param scope
  266. Scope constant defining the availability and lifetime of the registration. See scope constants for more details.
  267. @param errors
  268. Pointer to CFArrayRef to receive array of CFError references. Each error will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully registered. Must be released by caller. Can be NULL.
  269. @result Returns true if registration of all font URLs was successful. Otherwise false.
  270. }
  271. function CTFontManagerRegisterFontsForURLs( fontURLs: CFArrayRef; scope: CTFontManagerScope; errors: CFArrayRefPtr {can be null} ): CBool; external name '_CTFontManagerRegisterFontsForURLs';
  272. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  273. {!
  274. @function CTFontManagerUnregisterFontsForURLs
  275. @abstract Unregisters fonts from the specified font URLs with the font manager. Unregistered fonts are no longer discoverable through font descriptor matching.
  276. @param fontURLs
  277. Array of font URLs.
  278. @param scope
  279. Scope constant defining the availability and lifetime of the registration. Should match the scope the fonts are registered in. See scope constants for more details.
  280. @param errors
  281. Pointer to CFArrayRef to receive array of CFError references. Each error will contain a CFArray of font URLs corresponding to kCTFontManagerErrorFontURLsKey. These URLs represent the font files that caused the error, and were not successfully unregistered. Must be released by caller. Can be NULL.
  282. @result Returns true if unregistration of all font URLs was successful. Otherwise false.
  283. }
  284. function CTFontManagerUnregisterFontsForURLs( fontURLs: CFArrayRef; scope: CTFontManagerScope; errors: CFArrayRefPtr {can be null} ): CBool; external name '_CTFontManagerUnregisterFontsForURLs';
  285. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  286. {!
  287. @function CTFontManagerEnableFontDescriptors
  288. @abstract Enables or disables the matching font descriptors for font descriptor matching.
  289. @param descriptors
  290. Array of font descriptors.
  291. @param enable
  292. Boolean value indicating whether the fonts matching descriptors should be enabled for font descriptor matching.
  293. }
  294. procedure CTFontManagerEnableFontDescriptors( descriptors: CFArrayRef; enable: CBool ); external name '_CTFontManagerEnableFontDescriptors';
  295. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  296. {!
  297. @function CTFontManagerGetScopeForURL
  298. @abstract Returns the registration scope of the specified URL.
  299. @param fontURL
  300. Font URL.
  301. @result Returns the registration scope of the specified URL, will return kCTFontManagerScopeNone if not currently registered.
  302. }
  303. function CTFontManagerGetScopeForURL( fontURL: CFURLRef ): CTFontManagerScope; external name '_CTFontManagerGetScopeForURL';
  304. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  305. {!
  306. @function CTFontManagerIsSupportedFontFile
  307. @abstract Determines whether the referenced font data (usually by file URL) is supported on the current platform.
  308. @param fontURL
  309. A URL to font data.
  310. @result This function returns true if the URL represents a valid font that can be used on the current platform.
  311. }
  312. function CTFontManagerIsSupportedFont( fontURL: CFURLRef ): CBool; external name '_CTFontManagerIsSupportedFont';
  313. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  314. {! --------------------------------------------------------------------------
  315. @group Manager Auto-Activation
  316. }//--------------------------------------------------------------------------
  317. {!
  318. @const kCTFontManagerBundleIdentifier
  319. @abstract CTFontManage bundle identifier
  320. @discussion The CTFontManager bundle identifier to be used with get or set global auto-activation settings.
  321. }
  322. var kCTFontManagerBundleIdentifier: CFStringRef; external name '_kCTFontManagerBundleIdentifier'; (* attribute const *)
  323. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  324. {!
  325. @enum
  326. @abstract Auto-activation settings.
  327. @constant kCTFontManagerAutoActivationDefault
  328. Default auto-activation setting. When specified, the application will use the global setting.
  329. @constant kCTFontManagerAutoActivationDisabled
  330. Disables auto-activation.
  331. @constant kCTFontManagerAutoActivationEnabled
  332. Enables auto-activation.
  333. @constant kCTFontManagerAutoActivationPromptUser
  334. Requires user input for auto-activation. A dialog will be presented to the user to confirm auto
  335. activation of the font.
  336. }
  337. const
  338. kCTFontManagerAutoActivationDefault = 0;
  339. kCTFontManagerAutoActivationDisabled = 1;
  340. kCTFontManagerAutoActivationEnabled = 2;
  341. kCTFontManagerAutoActivationPromptUser = 3;
  342. type
  343. CTFontManagerAutoActivationSetting = UInt32;
  344. {!
  345. @function CTFontManagerSetAutoActivationSetting
  346. @abstract Sets the auto-activation for the specified bundle identifier.
  347. @param bundleIdentifier
  348. The bundle identifier. Used to specify a particular application bundle. If NULL,
  349. the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
  350. will set the global auto-activation settings.
  351. @param setting
  352. The new setting.
  353. @result Function will apply the setting to the appropriate preferences location.
  354. }
  355. procedure CTFontManagerSetAutoActivationSetting( bundleIdentifier: CFStringRef; setting: CTFontManagerAutoActivationSetting ); external name '_CTFontManagerSetAutoActivationSetting';
  356. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  357. {!
  358. @function CTFontManagerGetAutoActivationSetting
  359. @abstract Accessor for the auto-activation setting.
  360. @param bundleIdentifier
  361. The bundle identifier. Used to specify a particular application bundle. If NULL,
  362. the current application bundle will be used. If kCTFontManagerBundleIdentifier is specified,
  363. will set the global auto-activation settings.
  364. @result Will return the auto-activation setting for specified bundle identifier.
  365. }
  366. function CTFontManagerGetAutoActivationSetting( bundleIdentifier: CFStringRef ): CTFontManagerAutoActivationSetting; external name '_CTFontManagerGetAutoActivationSetting';
  367. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  368. {! --------------------------------------------------------------------------
  369. @group Manager Notifications
  370. }//--------------------------------------------------------------------------
  371. {!
  372. @constant kCTFontManagerRegisteredFontsChangedNotification
  373. @abstract Notification name for font registry changes.
  374. @discussion This is the string to use as the notification name when subscribing
  375. to CTFontManager notifications. This notification will be posted
  376. when fonts are added to the font registry. The client is responsible for
  377. registered with the distributed notification center to receive notifications
  378. for changes to the session or user scopes, and with a local notification
  379. for changes to the process scope.
  380. }
  381. var kCTFontManagerRegisteredFontsChangedNotification: CFStringRef; external name '_kCTFontManagerRegisteredFontsChangedNotification'; (* attribute const *)
  382. (* AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER *)
  383. {$endc} {TARGET_OS_MAC}
  384. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  385. end.
  386. {$endc} {not MACOSALLINCLUDE}