Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-07

Fonts

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kjow

Hi all,

I'm developing a multiplatform app and I need to have the same look on all OS. Is it possible to include a my personal font in the Lazarus compiled binary to have the same graphic/size/etc on all OS?

Thank you,
Kjow

Reply by email

Mark Morgan Lloyd
to Kjow
Kjow wrote 5 lines
Hi all, I'm developing a multiplatform app and I need to have the same look on all OS. Is it possible to include a my personal font in the Lazarus compiled binary to have the same graphic/size/etc on all OS?

Since nobody else has commented: I've done this with Delphi in Windows, embedding a (bitmap) font as a resource. Quite frankly I didn't find it entirely satisfactory since if for some reason the OS though that the binary was locked it couldn't access the resource and fell back to a "close equivalent".

I'm not sure that the same can be done in a portable fashion because of the X/unix case where the binary and the fonts are potentially stored on different hosts. It /might/ be possible to handle that particular case by making the app look like an X font server, but that would clearly fail if there was already one set up.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Felipe Monteiro de Carvalho
to Kjow: I'm developing a multiplatform app and I need to have the same look on all OS. Is it…
Kjow wrote
I'm developing a multiplatform app and I need to have the same look on all OS. Is it possible to include a my personal font in the Lazarus compiled binary to have the same graphic/size/etc on all OS?

Putting the font in the executable and reading afterwards should be the easy part. You can either use a .RC file or a .LRS file and there are APIs to retrive this. Not sure where this is documented. Lazarus uses this, so it should work very well.

Now the problem would be that I don't know if we currently support loading a not-installed font from a file in TFont. You would need to check that. If we don't, then we need a new function TFont.LoadTTFFontFromStream / LoadTTFFontFromFile, and it will need a per-widgetset implementation to connect this font stream with the widgetset.

The other solution would be placing your font file in the adequate place where system fonts should be. Your installer should do it. For unix systems you can implement "make install" to do that too, besides the traditional deb / rpm packages.

Felipe Monteiro de Carvalho

Reply by email

Duncan Parsons
to Mark Morgan Lloyd: Since nobody else has commented: I've done this with Delphi in Windows, embedding a…

From: Mark Morgan Lloyd [mailto:]
Sent: 21 July 2010 08:52

Kjow wrote: > Hi all, > > I'm developing a multiplatform app and I need to have the same look

on

> all OS. Is it possible to include a my personal font in the Lazarus > compiled binary to have the same graphic/size/etc on all OS? Since nobody else has commented: I've done this with Delphi in Windows,

embedding a (bitmap)

font as a resource. Quite frankly I didn't find it entirely

satisfactory since if for some

reason the OS though that the binary was locked it couldn't access the

resource and fell back >to a "close equivalent".

I'm not sure that the same can be done in a portable fashion because of

the X/unix case where >the binary and the fonts are potentially stored on different hosts. It /might/ be possible to >handle that particular case by making the app look like an X font server, but that would

Show quoted text 7 lines
clearly fail if there was already one set up. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or

colleagues]

The way I've done it in the past with Delphi, is to have a TrueType font in the resources and something along these lines

=-=-=-=-=-=
const
  cFont:array[0..0,0..2] of string=
             (('tmp\','SciCalc','scicalc2_small.ttf'));
function LoadFont(FontIdx:Integer; Load:boolean):boolean;
var fnt,FontRes : string;
    Res : TResourceStream;
begin
  result:=false; //assume it all went wrong...
  fnt:=SettingsRootDir+cFont[FontIdx,0]+cFont[FontIdx,2];
  if Load then
    begin
      if not(FileExists(fnt)) then
        begin
          try
            Res :=TResourceStream.Create(Hinstance,
                                           cFont[FontIdx,1],
                                           RT_RCDATA);
            Res.SaveToFile(fnt);
            Res.Free;
          except
          end;
        end;
      if FileExists(fnt) then
        begin
          FontRes:=fnt+#0;
          result:=(AddFontResource(@FontRes[1])0);
          if result then PostMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
        end;
    end
   else
    begin
      FontRes:=fnt+#0;
      result:=RemoveFontResource(@FontRes[1]);
      if result then PostMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
	//Could Delete file is wanted :shrug: depends on how app was
installed
    end;
end;

=-=-=-=-=-=

Now, this is very Windows centric, but the idea is there. Windows cannot load a font from memory - it /has/ to be a file, hence the persisting part. Something XPlatform along these lines would be super, but alas I'm not the man to do it. However this code posted here is up for grabs as a working windows implementation for whoever wants to use it.

DSP

Reply by email

waldo kitty
to Kjow: I'm developing a multiplatform app and I need to have the same look on all OS. Is it…
Kjow wrote 5 lines
Hi all, I'm developing a multiplatform app and I need to have the same look on all OS. Is it possible to include a my personal font in the Lazarus compiled binary to have the same graphic/size/etc on all OS?

i was going to reply to this and got lost in other stuff... what widget set are you using? i'm thinking of the fpGUI widget set and its specific design to look the same across all platforms...

is the font really that important that folk can't read or understand it between platforms?

Reply by email

Kjow
to waldo kitty

2010/7/21 waldo kitty :

Show quoted text 6 lines
i was going to reply to this and got lost in other stuff... what widget set are you using? i'm thinking of the fpGUI widget set and its specific design to look the same across all platforms... is the font really that important that folk can't read or understand it between platforms?

Hi,

I use gtk2 for i386-linux and arm-linux, win32/64... for windows :) between gtk2 and windows there are a lot of differences, but at moment I found that setting these params:

charset: DEFAULT_CHARSET
name: charter [bitstream]

the differences are not so bad -> very similar.

But there isn't a big choise in fonts...

In the next future I'll try qt for i386-linux and arm-linux, but not for windows.

Reply by email