Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: True Type Font Iconography for Mac OS X


This question is answered.


Permlink Replies: 5 - Last Post: May 23, 2016 5:53 AM Last Post By: Michael Leahy
Luke Lian

Posts: 3
Registered: 6/19/16
True Type Font Iconography for Mac OS X  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 19, 2016 7:42 PM
Now I can deploy a custom True Type Font on Android and iOS like FontAwesome, But I can't find a solution on Mac OS X.
Michael Leahy

Posts: 239
Registered: 5/9/07
Re: True Type Font Iconography for Mac OS X  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 20, 2016 6:59 AM   in response to: Luke Lian in response to: Luke Lian
Luke Lian wrote:
Now I can deploy a custom True Type Font on Android and iOS like FontAwesome, But I can't find a solution on Mac OS X.

There is a way to do this in Delphi but I cannot find it at the moment.

Whether you manually add these two lines to your <application name>.info.plist file or you figure out where to set set it in Delphi, the result will be the same. Two additional lines need to be added to this file. You'll find the file in your project folder /OSX32. Here is an example from my info.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleName</key>
        <string>Chess Openings Wizard</string>
	<key>CFBundleDisplayName</key>
        <string>Chess Openings Wizard</string>
	<key>CFBundleIdentifier</key>
        <string>com.bookup.chessopeningswizardprofessional</string>
	<key>CFBundleVersion</key>
	<string>1.0.41</string>
	<key>CFBundlePackageType</key>
        <string>APPL</string>
	<key>CFBundleSignature</key>
        <string>COWP</string>
	<key>CFBundleAllowMixedLocalizations</key>
        <string>YES</string>
	<key>CFBundleExecutable</key>
        <string>ChessOpeningsWizardBETABuild41</string>
	<key>NSHighResolutionCapable</key>
        <string>true</string>
	<key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
	<key>ATSApplicationFontsPath</key>
        <string>Fonts</string>


You can add those last two lines as a key pair anywhere in that block I think.

Now that you've told it that your fonts will be deployed to OSX in the "Fonts" folder you must actually deploy your fonts. Switch your target platform to one of the OSX selections and choose Project|Deployment

Then click the button to Add Files. It's a white icon with a tiny green plus sign.

Add your TrueType font file. It likely has .TTF for an extension.

Now double click on the Remote Path for your font entry. Change it to Contents\Resources\Fonts

That's it. Now your app can request your font by its name by setting the Font Family property of the components you use.

You may need to delete the target app in your scratch folder on OSX before Delphi will correctly deploy your app using the modified info.plist because Delphi doesn't check to see that you've manually changed the info.plist file.
Michael Leahy

Posts: 239
Registered: 5/9/07
Re: True Type Font Iconography for Mac OS X
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 20, 2016 7:08 AM   in response to: Luke Lian in response to: Luke Lian
Luke Lian wrote:
Now I can deploy a custom True Type Font on Android and iOS like FontAwesome, But I can't find a solution on Mac OS X.

And I just found the way to do it inside of Delphi.

After modifying your Project|Deployment setting to deploy your .TTF file to the Contents\Resources\Fonts folder, choose Project | Options and click Version Info.
Then right click in the Key/Value area and choose Add Key.
Set the key name to ATSApplicationFontsPath
Set the value to Fonts
Click OK
Save your project.

That should have Delphi add that key pair to your info.plist file. No need to edit it manually.
Luke Lian

Posts: 3
Registered: 6/19/16
Re: True Type Font Iconography for Mac OS X  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 22, 2016 7:44 PM   in response to: Michael Leahy in response to: Michael Leahy
Thank you very much! It's so helpful! :)

And I just found the way to do it inside of Delphi.

After modifying your Project|Deployment setting to deploy your .TTF file to the Contents\Resources\Fonts folder, choose Project | Options and click Version Info.
Then right click in the Key/Value area and choose Add Key.
Set the key name to ATSApplicationFontsPath
Set the value to Fonts
Click OK
Save your project.

That should have Delphi add that key pair to your info.plist file. No need to edit it manually.
Luke Lian

Posts: 3
Registered: 6/19/16
Re: True Type Font Iconography for Mac OS X  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2016 3:35 AM   in response to: Michael Leahy in response to: Michael Leahy
Hi,Michael!
These is no problem on Mac OS X, Android , iOS.
But on Windows, just like Windows 7 and Windows 10. I have trouble in File Permission.

Code:

{$IFDEF MSWINDOWS}
System.Win.Registry,
Winapi.Windows,
Winapi.Messages,
{$ENDIF}

function AddFont(FontName: string): Boolean;
const
REG_FONT_KEY = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\';
var
arr: array [0 .. MAX_PATH] of Char;
WinFontDir, WinFontFileName, SoureFontDir, SourceFontFilename, FotFileName: string;
Reg: TRegistry;
begin
//Create FontSource
GetWindowsDirectory(arr, MAX_PATH);
WinFontDir := arr;
WinFontDir := WinFontDir + PathDelim + 'Fonts\';
WinFontFileName := WinFontDir + IconFontname + '.ttf';

SoureFontDir := ExtractFileDir(GetModuleName(HInstance));
SourceFontFilename := SoureFontDir + PathDelim + IconFontname + '.ttf';

FotFileName := ExtractFileDir(GetModuleName(HInstance)) + PathDelim + IconFontname + '.fot';

Result := CopyFile(PWideChar(SourceFontFilename), PWideChar(WinFontFileName), False);

Result := Result and CreateScalableFontResource(0, PWideChar(FotFileName), PWideChar(IconFontname + '.ttf'), PWideChar(SoureFontDir));

Result := Result and (AddFontResource(PWideChar(WinFontFileName)) <> 0);

Reg := TRegistry.Create(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if (not Reg.KeyExists(REG_FONT_KEY)) then begin
Exit;
end;
Reg.Access := KEY_WRITE;
if not Reg.OpenKey(REG_FONT_KEY, True) then begin
Exit;
end;
Reg.WriteString(IconFontname, IconFontname + '.ttf');
Reg.CloseKey();
finally
Reg.Free;
end;

//


//SendMessage

SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;

Can you Help me?
Thank you very much!
Michael Leahy

Posts: 239
Registered: 5/9/07
Re: True Type Font Iconography for Mac OS X  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 23, 2016 5:53 AM   in response to: Luke Lian in response to: Luke Lian
Luke Lian wrote:
Hi,Michael!
These is no problem on Mac OS X, Android , iOS.
But on Windows, just like Windows 7 and Windows 10. I have trouble in File Permission.

Code:

{$IFDEF MSWINDOWS}
System.Win.Registry,
Winapi.Windows,
Winapi.Messages,
{$ENDIF}

function AddFont(FontName: string): Boolean;
const
REG_FONT_KEY = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\';
var
arr: array [0 .. MAX_PATH] of Char;
WinFontDir, WinFontFileName, SoureFontDir, SourceFontFilename, FotFileName: string;
Reg: TRegistry;
begin
//Create FontSource
GetWindowsDirectory(arr, MAX_PATH);
WinFontDir := arr;
WinFontDir := WinFontDir + PathDelim + 'Fonts\';
WinFontFileName := WinFontDir + IconFontname + '.ttf';

SoureFontDir := ExtractFileDir(GetModuleName(HInstance));
SourceFontFilename := SoureFontDir + PathDelim + IconFontname + '.ttf';

FotFileName := ExtractFileDir(GetModuleName(HInstance)) + PathDelim + IconFontname + '.fot';

Result := CopyFile(PWideChar(SourceFontFilename), PWideChar(WinFontFileName), False);

Result := Result and CreateScalableFontResource(0, PWideChar(FotFileName), PWideChar(IconFontname + '.ttf'), PWideChar(SoureFontDir));

Result := Result and (AddFontResource(PWideChar(WinFontFileName)) <> 0);

Reg := TRegistry.Create(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if (not Reg.KeyExists(REG_FONT_KEY)) then begin
Exit;
end;
Reg.Access := KEY_WRITE;
if not Reg.OpenKey(REG_FONT_KEY, True) then begin
Exit;
end;
Reg.WriteString(IconFontname, IconFontname + '.ttf');
Reg.CloseKey();
finally
Reg.Free;
end;

//


//SendMessage

SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
end;

Can you Help me?
Thank you very much!

I've never installed a font in Windows using code. I use Inno Setup which installs my custom fonts as it installs my app.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02