Merge pull request #49 from ISSOtm/fontconfig
Improve custom font handling on Linux
3 changed files
Diffed against the first of 2 parents.
+35−9
0cb68e9Improve custom font handling on Linux
@@ -0,0 +1,22 @@ | |||
|
1 | unit FontConfig; |
|
|
2 | |
|
|
3 | {$mode objfpc}{$H+} |
|
|
4 | |
|
|
5 | interface |
|
|
6 | |
|
|
7 | uses |
|
|
8 | Classes, SysUtils; |
|
|
9 | |
|
|
10 | type |
|
|
11 | FcBool = Integer; |
|
|
12 | |
|
|
13 | function FcConfigAppFontAddFile(Config: Pointer; _File: PChar): FcBool; cdecl; external 'libfontconfig.so'; |
|
|
14 | |
|
|
15 | function PangoCairoFontMapGetDefault: Pointer; cdecl; external 'libpangocairo-1.0.so' name 'pango_cairo_font_map_get_default'; |
|
|
16 | |
|
|
17 | procedure PangoFcFontMapConfigChanged(FcFontMap: Pointer); cdecl; external 'libpangoft2-1.0.so' name 'pango_fc_font_map_config_changed'; |
|
|
18 | |
|
|
19 | implementation |
|
|
20 | |
|
|
21 | end. |
|
|
22 | |
|
@@ -221,7 +221,7 @@ | |||
| 221 | <PackageName Value="LCL"/> |
221 | <PackageName Value="LCL"/> |
| 222 | </Item5> |
222 | </Item5> |
| 223 | </RequiredPackages> |
223 | </RequiredPackages> |
| 224 | <Units Count="26"> |
224 | <Units Count="27"> |
| 225 | <Unit0> |
225 | <Unit0> |
| 226 | <Filename Value="hUGETracker.lpr"/> |
226 | <Filename Value="hUGETracker.lpr"/> |
| 227 | <IsPartOfProject Value="True"/> |
227 | <IsPartOfProject Value="True"/> |
@@ -358,6 +358,11 @@ | |||
| 358 | <IsPartOfProject Value="True"/> |
358 | <IsPartOfProject Value="True"/> |
| 359 | <UnitName Value="DMFImport"/> |
359 | <UnitName Value="DMFImport"/> |
| 360 | </Unit25> |
360 | </Unit25> |
|
361 | <Unit26> |
|
|
362 | <Filename Value="fontconfig.pas"/> |
|
|
363 | <IsPartOfProject Value="True"/> |
|
|
364 | <UnitName Value="FontConfig"/> |
|
|
365 | </Unit26> |
|
| 361 | </Units> |
366 | </Units> |
| 362 | </ProjectOptions> |
367 | </ProjectOptions> |
| 363 | <CompilerOptions> |
368 | <CompilerOptions> |
@@ -9,6 +9,7 @@ program hUGETracker; | |||
| 9 | uses |
9 | uses |
| 10 | {$ifdef unix} |
10 | {$ifdef unix} |
| 11 | cthreads, |
11 | cthreads, |
|
12 | fontconfig, |
|
| 12 | {$endif} |
13 | {$endif} |
| 13 | {$ifdef MSWINDOWS} |
14 | {$ifdef MSWINDOWS} |
| 14 | Windows, |
15 | Windows, |
@@ -30,7 +31,7 @@ uses | |||
| 30 | |
31 | |
| 31 | {$ifdef MSWINDOWS} |
32 | {$ifdef MSWINDOWS} |
| 32 | // https://forum.lazarus.freepascal.org/index.php?topic=39124.0 |
33 | // https://forum.lazarus.freepascal.org/index.php?topic=39124.0 |
| 33 | Function AddFont (Dir : PAnsiChar; |
34 | function AddFont (Dir : PAnsiChar; |
| 34 | Flag: DWORD): LongBool; StdCall; |
35 | Flag: DWORD): LongBool; StdCall; |
| 35 | External GDI32 |
36 | External GDI32 |
| 36 | Name 'AddFontResourceExA'; |
37 | Name 'AddFontResourceExA'; |
@@ -58,14 +59,12 @@ begin | |||
| 58 | {$endif} |
59 | {$endif} |
| 59 | |
60 | |
| 60 | {$ifdef UNIX} |
61 | {$ifdef UNIX} |
| 61 | // This is the correct way to load a font on Linux according to |
62 | // This is the correct way to load a font on Linux according to... I dunno man, but this seems to work |
| 62 | // #linux on freenode. |
63 | if FcConfigAppFontAddFile(nil, PChar('PixeliteTTF.ttf')) = 0 then |
| 63 | if not DirectoryExists(GetUserDir+'.fonts') then |
64 | Writeln(StdErr, '[ERROR] Couldn''t load Pixelite!!!'); |
| 64 | CreateDir(GetUserDir+'.fonts'); |
65 | |
|
66 | PangoFcFontMapConfigChanged(PangoCairoFontMapGetDefault); |
|
| 65 | |
67 | |
| 66 | if not (CopyFile('./PixeliteTTF.ttf', GetUserDir+'.fonts/PixeliteTTF.ttf') |
|
|
| 67 | and (ExecuteProcess('/bin/bash', '-c fc-cache') = 0)) |
|
|
| 68 | then Writeln(StdErr, '[ERROR] Couldn''t copy Pixelite to ~/.fonts !!!'); |
|
|
| 69 | {$endif} |
68 | {$endif} |
| 70 | |
69 | |
| 71 | {$ifdef PRODUCTION} |
70 | {$ifdef PRODUCTION} |