Chris-J 0 Posted November 15, 2022 Hello All, I hope this is the right place to ask this question. I am trying to make my desktop app (written in C++Builder) look slightly more modern/cloud/browser-like. Researching this, I find that one (aesthetic) way of giving more of a cloud impression, is to use use (Google) web-fonts rather than (Microsoft) desktop fonts. But when I click on "Font" in any of my VCL components (labels, etc) the fonts offered to me are all (Microsoft) desktop fonts. So my question is: how can I use a web-font such as 'Open Sans', which is free/open-source: https://fonts.adobe.com/fonts/open-sans ... in C++Builder ? Thanks in advance for any suggestions. Share this post Link to post
PeterBelow 239 Posted November 15, 2022 2 hours ago, Chris-J said: Hello All, I hope this is the right place to ask this question. I am trying to make my desktop app (written in C++Builder) look slightly more modern/cloud/browser-like. Researching this, I find that one (aesthetic) way of giving more of a cloud impression, is to use use (Google) web-fonts rather than (Microsoft) desktop fonts. But when I click on "Font" in any of my VCL components (labels, etc) the fonts offered to me are all (Microsoft) desktop fonts. So my question is: how can I use a web-font such as 'Open Sans', which is free/open-source: https://fonts.adobe.com/fonts/open-sans ... in C++Builder ? Thanks in advance for any suggestions. To be able to use a font on Windows it has to be installed (Font applet in the control panel or using the Windows font API, i. e. AddFontResourceEx). You have to do this on your user's systems as well, so have to distribute the font with your application. Share this post Link to post
Chris-J 0 Posted November 15, 2022 Thank you, Peter. Do you know if there's an explanation somewhere on the Embarcadero website of how to distribute the font with my application, as I've not done it before ? Apologies if I'm missing it / this should be obvious. Share this post Link to post
Lajos Juhász 295 Posted November 15, 2022 18 minutes ago, Chris-J said: Do you know if there's an explanation somewhere on the Embarcadero website of how to distribute the font with my application, as I've not done it before ? Apologies if I'm missing it / this should be obvious. This should be part of the installation of your application. For example Inno Setup can do it for you. Share this post Link to post
Alexander Elagin 143 Posted November 15, 2022 There is a nice example in the InnoSetup documentation: Quote FontInstall Tells Setup the file is a font that needs to be installed. The value of this parameter is the name of the font as stored in the registry or WIN.INI. This must be exactly the same name as you see when you double-click the font file in Explorer. Note that Setup will automatically append " (TrueType)" to the end of the name. If the file is not a TrueType font, you must specify the flag fontisnttruetype in the Flags parameter. It's recommended that you use the flags onlyifdoesntexist and uninsneveruninstall when installing fonts to the {autofonts} directory. If the installation is running in non administrative install mode, Windows 10 Version 1803 or later is required to successfully install a font. For compatibility with 64-bit Windows, fonts should not be installed to the {sys} directory. Use {autofonts} as the destination directory instead. Example: Source: "OZHANDIN.TTF"; DestDir: "{autofonts}"; FontInstall: "Oz Handicraft BT"; Flags: onlyifdoesntexist uninsneveruninstall Share this post Link to post
Chris-J 0 Posted November 15, 2022 Thank you, Lajos and Alexander. I'm using "Advanced Installer" but I'm sure they'll have something similar. Share this post Link to post
Lajos Juhász 295 Posted November 15, 2022 12 minutes ago, Chris-J said: I'm using "Advanced Installer" but I'm sure they'll have something similar. Google thinks this is a way to achieve it: https://www.advancedinstaller.com/forums/viewtopic.php?t=9364 Share this post Link to post
irawan 2 Posted November 16, 2022 15 hours ago, PeterBelow said: To be able to use a font on Windows it has to be installed (Font applet in the control panel or using the Windows font API, i. e. AddFontResourceEx). You have to do this on your user's systems as well, so have to distribute the font with your application. is it possible to not install this font? what i mean just put this font file together with the application and then load this font when necessary. Share this post Link to post
Sherlock 663 Posted November 16, 2022 Check out AddFontResourceEx and RemoveFontResourceEx from the Windows API. Note that while the font is installed, it may be used by any other program in your system unless you load it FR_PRIVATE. Share this post Link to post
DelphiUdIT 188 Posted November 16, 2022 I'll give you the answer in Delphi as indicated in this link Pascal load font form resource (embedded in exe). Converting it to C shouldn't be a problem. Make a text file and rename it 'resource.rc'; Put inside a line like this (you can insert how many fonts do you need): LCDN RCDATA ".\LCDN.TTF" The meaning of the data is: "Name of the resource" "Resource Type" "Font FIle Name" Insert the file "resource.rc" in you project; By doing so, you insert the font into your executable and you don't have to extract it or anything else. This is a simple code in pascal to use it: function LoadResourceFontByName( const ResourceName : string; ResType: PChar ) : Boolean; var ResStream : TResourceStream; FontsCount : DWORD; begin ResStream := TResourceStream.Create(hInstance, ResourceName, ResType); try Result := (AddFontMemResourceEx(ResStream.Memory, ResStream.Size, nil, @FontsCount) <> 0); finally ResStream.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); begin if LoadResourceFontByName('LCDN', RT_RCDATA) then //THIS 'LCDN' IS THE NAME OF THE RESOURCE Label1.Font.Name := 'LCDN'; //THIS 'LCDN' IS THE INTERNAL NAME OF THE FONT AND SHOULD BE KNOW (CAUSE THE FONT FILE MAY CONTAIN MORE TYPE LIKE BOLD, OR OTHERS) end; end. Share this post Link to post
Dimon_II 0 Posted December 13, 2022 (edited) I ran into a similar problem and analyzed it much deeper (developing a font editor to add and align colored svgs to a font). That is, I do not have my own font built into the application, but the ability to select a font file: 1. I want to load a font from a file and use it: AddFontMemResourceEx / AddFontResourceExW Both functions load a font, but they don't return its name or any handle that can be used to identify it! You either need a separate font header parser, or use an undocumented function GetFontResourceInfoW (gdi32.dll). If the font file has a bold or italic typeface, then the name is not enough - if the system has a font of the same name without a typeface or loaded font family, it will be used for display instead of the added one and a more detailed analysis of the file is required. 2. Regular font rendering does not support colored glyphs. As a result of experiments, it turned out that the DirectWrite and Direct2D methods called from Delphi do not see private fonts, and the AddFontMemResourceEx method for loading a font from memory creates only private ones. That is, for fonts with icons, this method cannot be applied. AddFontResourceExW only. 3. It turns out that I cannot modify the font in memory and re-initialize. For any display by standard means, the font must be saved to a temporary file and loaded from the file. What is very inconvenient - AddFontResourceExW blocks the file from being deleted and opened. It is quite possible to write your own render for individual glyphs, but for displaying sample phrases, taking into account kerning and hints, you get something monstrously cumbersome and does not guarantee correct operation. Edited December 13, 2022 by Dimon_II Share this post Link to post
Alexander Sviridenkov 360 Posted December 13, 2022 DirectWrite has own methods for loading custom fonts from memory. Share this post Link to post