Recent

Author Topic: [SOLVED] Embed a font to use without installing  (Read 39889 times)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: [SOLVED] Embed a font to use without installing
« Reply #30 on: July 11, 2017, 12:14:22 pm »
O, and one other (not so small) thing.
You have your label1 charset set to a russion charset.
But your Auricom_Regular.ttf doesn't contain such charset.
So the assigning of Font.Name to 'Auricom Regular' fails because the charset requirement can't be met.
Set it to DEFAULT_CHARSET and it will work (together with removing the gdi32.dll) !!

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. begin
  3.   Label1.Font.Charset := DEFAULT_CHARSET;
  4.   Label1.Font.Size := 12;
  5.   Label1.Font.Name := 'Auricom Regular';
  6. end;

nnm4evr

  • Newbie
  • Posts: 5
Re: [SOLVED] Embed a font to use without installing
« Reply #31 on: July 12, 2017, 06:25:35 am »
Still doesn't work on Win 7. Message "Font Installed!" showing, but Label still disappear when i push button to apply "My" Font. GDI32.DLL i remove. On Win XP all works fine. Font Auricom Regular have russian symbols, but i change charset to Default, doesn't help. Here a new small video - YouTube. And my sources without trash from my last sources (in archive only sorces and font dll w/o exe file).

(And again - Sorry for my English)



rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: [SOLVED] Embed a font to use without installing
« Reply #32 on: July 12, 2017, 09:15:32 am »
It works perfectly for me (Windows 10, Delphi 10.2) after changing some ansi stuff because of unicode.

BUT... I still see that GDI32.DLL from 2010 in your directory in that youtube video on Windows 7.
Please REMOVE IT and try again.

nnm4evr

  • Newbie
  • Posts: 5
Re: [SOLVED] Embed a font to use without installing
« Reply #33 on: July 12, 2017, 11:20:12 am »
GDI32.DLL removed, but still no effect. I use Delphi 7, but a have installed Embarcodero Delphi 2010 (from RAD Studio 2010), i'll try this code on it and answer.

No, doesn't work on 2010. This is strange. I'll try to launch app on my frends computers with Win7 and Win10 and answer.
« Last Edit: July 12, 2017, 11:35:43 am by nnm4evr »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: [SOLVED] Embed a font to use without installing
« Reply #34 on: July 12, 2017, 12:27:38 pm »
Trying on another machine might be a good idea.

Another would be to try loading the font directly from the resource without the step of saving it to disk (with AddFontMemResourceEx).

Try the following:

Code: Pascal  [Select][+][-]
  1. var hFontRes: Cardinal; // add this line
  2.  
  3. procedure TForm1.FormCreate(Sender: TObject);
  4. var
  5.   FontFileName: string;
  6.   FontCount1: Cardinal; // <--- add this one
  7. begin
  8.   DLLInstance := LoadLibrary('FNTTest.dll'); // çàãðóçêà áèáëèîòåêè Load DLL
  9.   if DLLInstance = 0 then
  10.   begin // Ïðîâåðêà çàãðóçêè Load Check
  11.     MessageDlg('Áèáëèîòåêà FNTTest.dll íå íàéäåíà èëè ïîâðåæäåíà!' + #13#10 + 'Ïîæàëóéñòà ïåðåóñòàíîâèòå ïðîãðàììó.', mtError, [mbOK], 0); // Ïèøåì ñâîå ðóãàòåëüñòî ;-) Message -> DLL Not loaded (or not found)
  12.     Application.Terminate;
  13.   end;
  14.   FontStream := TResourceStream.Create(DLLInstance, 'MyFONT', rt_RCData);
  15.  
  16.   // Now load the font directly from stream
  17.   hFontRes := AddFontMemResourceEx(FontStream.Memory, FontStream.Size, nil, @FontCount1);
  18.   if FontCount1 = 1 then ShowMessage('Font Installed from memory!') else ShowMessage('Error installing font!');
  19.  
  20.   // comment out the following lines
  21.   //FontStream.SaveToFile(ExtractFilePath(Application.ExeName) + 'Auricom_Regular.ttf');
  22.   //LoadFonts;
  23.  
  24. end;

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: [SOLVED] Embed a font to use without installing
« Reply #35 on: July 13, 2017, 05:33:55 pm »
This code work only in WinXP, i test it on old nootebok with WinXP SP3. Doesn't work on Win7 on my PC.
Did you try my short code without any dll and files savings? Just create an empty form, a label, a pair of buttons and the the code (and private field, it's easy to guess what that is). Put the font file in the program directory and try. I have Windows 7 and it works. Compiled with Delphi 7 or Lazarus.

 

TinyPortal © 2005-2018