How to embed fonts into diagrams

Hello,

I want to embed fonts into the diagram.

I already tried the AddFontResource method, below is my test code.
Only ttf fonts were tested, which should be freely licensed.

This function is called in applications main form or earlier

---->
procedure S4PrivateFont_Add(strFontFile : String);
var
  sFontFile: string;
  sFotName: String;
  bErg: Boolean;
  iErg: Integer;
  a, b: Array[0..128] of Char;

begin

  sFontFile := ExtractFilePath(Application.ExeName) + strFontFile; //'MyFont.ttf';
  If FileExists(sFontFile) = True Then
  Begin

    sFotName := ChangeFileExt(sFontFile, '.FOT');
    StrPCopy(A, sFotName);
    StrPCopy(B, sFontFile);
    if not FileExists(sFotname) then
      bErg := CreateScalableFontResource(0, a, b, '')
    else
      bErg:=true;

    iErg := AddFontResource(PChar(sFotName));
    if iErg > 0 then
    begin
      SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

    end;
  End;

end;
<------

This seems to work fine with other controls, but the diagram doesn't react correctly, although the
font name is available.
If I use this e.g. with normal labels, they react as expected.


What could go wrong here ?

Rolf

TatDiagram doesn't respond to WM_FONTCHANGE message, especially because it's not associated with a single font. Would your code work with a TRichEdit component, for example?

Dear Wagner Landgraf,

thanks for the answer.

I need to apply some special fonts to single diagram objects, e.g. to have objects with LCD font
and objects with special designed symbols.

I don't understand why I cannot simply set the fonts after startup.
The assignment of the .Font property doesn't use the source font, although this is available
when I try to assign with other objects.

No matter of WM_FONTCHANGE, this should be possible, or not ?

Rolf

Hi Rolf, as I mentioned, the font doesn't belong to the diagram component, but to the blocks. You must assign a font to the block component, although it doesn't listen to Windows messages (it's just a component, not a control).