Local fonts in bundles lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- duncanparsons · 2011-08-17 08:52 Hello I have some custom fonts that I want to be available just for the app I'm running, rather than generally installed. The Win32 code is simple to achieve this, and (on the face of it) the same is true of the mac, however I can't get it working and I'm interested to know if this is a problem with me not seeing something, or an FPC/LCL problem. The advertised way to achieve this is to add a key 'ATSApplicationFontsPath' to Info.PList with a string value of either the font, or the folder wherein the customs font(s) lie, relative to the Resources folder in the bundle. So if I have a couple of fonts in Contents/Resources/Fonts/, then Fonts/ is the key. I've followed this to the letter, ensured all capitalisation is right in both Info.PList and my Canvas.Font.Name - but no dice. Anyone else had experience of this? I've traced the code thru from a TextOut, and it goes into what appears to be win32 based code using a TLogFont structure in fonts.inc. However, the debugger keeps freezing so I haven't found if it goes to the low level mac interface correctly.. All comments gratefully received :-) Duncan ---------------------------------------------------------------------- felipemdc · 2011-08-22 06:45 For each widgetset, fonts are created by LCLIntf.CreateFontIndirect In the case of Carbon it is: lcl/interfaces/carbon/carbonwinapi.pas locate CreateFontIndirect here If you follow the code flow from there, you end up in lcl/interfaces/carbon/carbonproc.pas in this routine: function FindCarbonFontID(const FontName: String): ATSUFontID; var   fn  : String; begin   Result := 0;   //DebugLn('FindCarbonFontID ' + FontName);   if SameText(FontName, 'default')     then fn:=CarbonDefaultFont     else fn:=FontName;   if (fn <> '') then   begin     OSError(ATSUFindFontFromName(@fn[1], Length(fn),         lclFontName, lclFontPlatform, lclFontScript,         lclFontLanguage, Result),       'FindCarbonFontID', 'ATSUFindFontFromName');   end; end; This font name is passed unmodified from what you wrong, AFAIK. So now you just need to find out what ATSUFindFontFromName does, and how to make it read a font from the bundle. The nasty thing is Apple considers Carbon obsolete, so I google for this function and I could not find any online docs for it =O  It seams that they deleted the online docs for ATSUI =( But I did find a PDF: http://www.google.com/url?sa=t&source=web&cd=5&ved=0CEMQFjAE&url=http% 3A%2F%2Fdeveloper.apple.com%2Flegacy%2Fmac%2Flibrary%2Fdocumentation%2 FCarbon%2Freference%2FATSUI_Reference%2Fatsui_reference.pdf&ei=V_pRTpv PJ4fi4QT2rI26Bw&usg=AFQjCNF3ejSMFUt6whn77hLZVcszV_hkEw In this PDF (I'll copy here before they delete it too) it says: ATSUFindFontFromName Obtains an ATSUI font ID for the first entry in a name table that matches the specified name string, name code, platform, script, and/or language. (Deprecated in Mac OS X v10.6.) OSStatus ATSUFindFontFromName ( const void *iName, ByteCount iNameLength, FontNameCode iFontNameCode, FontPlatformCode iFontNamePlatform, FontScriptCode iFontNameScript, FontLanguageCode iFontNameLanguage, ATSUFontID *oFontID ); Parameters iName A string that specifies the font name whose ATSUI font ID you want to obtain. The string that you pass must be appropriate for the value you pass in the iFontNameCode parameter. For example, if the iFontNameCode parameter is kFontPostscriptName, then you would supply a string that specifies the PostScript name of the font. iNameLength A ByteCount value specifying the length of the font name string provided in the iName parameter. Deprecated in Mac OS X v10.6 Legacy Document   |   2008-11-26   |   © 2003, 2008 Apple Inc. All Rights Reserved. APPENDIX A Deprecated ATSUI Functions iFontNameCode The FontNameCode value of the font name for which to obtain an ATSUI font ID. The FontNameCode is a UInt32 data type, and it is defined in the SFNTTypes.h header file. You can supply any of the following constants, kFontCopyrightName, kFontFamilyName, kFontStyleName, kFontUniqueName, kFontFullName, kFontVersionName, kFontPostscriptName, kFontTrademarkName, kFontManufacturerName, kFontDesignerName, kFontDescriptionName, kFontVendorURLName, kFontDesignerURLName, kFontLicenseDescriptionName,or kFontLicenseInfoURLName. iFontNamePlatform A FontPlatformCode value specifying the encoding of the font name, for example, kFontUnicodePlatform (for UTF-16), kFontMacintoshPlatform, kFontReservedPlatform, kFontMicrosoftPlatform, or kFontCustomPlatform. If you pass the kFontNoPlatformCode constant, ATSUFindFontFromName produces the first font in the name table matching the other specified parameters. See the SFNTTypes.h header file for a definition of the FontPlatformCode type and a list of possible values. iFontNameScript A FontScriptCode value specifying the script code of the font name, for example, kFontRomanScript. Pass kFontNoScriptCode if you supplied the kFontUnicodePlatform constant for the iFontNamePlatform parameter. If you pass the kFontNoScriptCode constant, ATSUFindFontFromName produces the first font in the name table matching the other specified parameters. See the SFNTTypes.h header file for a definition of the FontScriptCode type and a list of possible values. iFontNameLanguage A FontLanguageCode value specifying the language of the font name, for example, kFontNorwegianLanguage. Pass kFontNoLanguageCode if you supplied the kFontUnicodePlatform constant for the iFontNamePlatform parameter. If you pass the kFontNoLanguageCode constant, ATSUFindFontFromName produces the first font in the name table matching the other specified parameters. See the SFNTTypes.h header file for a definition of the FontLanguageCode type and a list of possible values. oFontID On return, points to the unique identifier for the specified font that matches the specified name string, name code, platform, script, and/or language. Note that because Apple Type Services assigns ATSUFontID values systemwide at runtime, font IDs can change across system restarts. Return Value A result code. If no installed font matches the specified parameters, ATSUFindFontFromName produces the constant kATSUInvalidFontID and returns the result code kATSUInvalidFontErr. See “ATSUI Result Codes” (page 100). Discussion The ATSUFindFontFromName function obtains an ATSUI font ID for the first font that matches the specified name string, name code, platform, script, and/or language. Because ATSUI cannot guarantee the uniqueness of names among installed fonts, ATSUFindFontFromName does not necessarily find the only font ID that matches these parameters. As a result, you may want to create a more sophisticated name-matching algorithm or guarantee the uniqueness of names among installed fonts. To find a name string and index value for the first font in a name table that matches an ATSUI font ID and the specified font parameters, call the function ATSUFindFontName (page 150). Availability Available in Mac OS X v10.0 and later. Deprecated in Mac OS X v10.6. ---------------------------------------------------------------------- felipemdc · 2011-08-22 06:50 Ok, the documentation of that routine was not very helpful =D So next you should simply google for something like: mac bundle font I did this and one of the items is: http://stackoverflow.com/questions/2444717/embed-font-in-a-mac-bundle Which has some hints about some stuff to put in the bundle information files. You could try something like that. Change the information files in your bundle and add the key mentioned in this link and see if it works. Also google, and post an answer here if you manage to do it =) Or even better, document this in the wiki.