DEADSOFTWARE

gl: more animation checks
[d2df-sdl.git] / src / game / renders / opengl / r_fonts.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_fonts;
18 interface
20 type
21 TFontInfo = record
22 w, h: Integer;
23 kern: Integer;
24 ch: array [AnsiChar] of record
25 w: Byte;
26 end;
27 end;
29 TFont = class abstract
30 end;
32 function r_Font_LoadInfoFromFile (const filename: AnsiString; var f: TFontInfo): Boolean;
34 implementation
36 uses
37 Math, SysUtils,
38 WADREADER, CONFIG, utils,
39 e_log
40 ;
42 function r_Font_LoadInfoFromMemory (data: Pointer; size: LongInt; var f: TFontInfo): Boolean;
43 var cfg: TConfig; c: AnsiChar;
44 begin
45 result := false;
46 if data <> nil then
47 begin
48 cfg := TConfig.CreateMem(data, size);
49 if cfg <> nil then
50 begin
51 f.w := MIN(MAX(cfg.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
52 f.h := MIN(MAX(cfg.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
53 f.kern := MIN(MAX(cfg.ReadInt('FontMap', 'Kerning', 0), -128), 127);
54 for c := #0 to #255 do
55 begin
56 f.ch[c].w := MIN(MAX(cfg.ReadInt(IntToStr(ORD(c)), 'Width', 0), 0), 255);
57 end;
58 result := (f.w > 0) and (f.h > 0);
59 cfg.Free;
60 end;
61 end;
62 end;
64 function r_Font_LoadInfoFromFile (const filename: AnsiString; var f: TFontInfo): Boolean;
65 var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer;
66 begin
67 result := false;
68 wadName := g_ExtractWadName(filename);
69 wad := TWADFile.Create();
70 if wad.ReadFile(wadName) then
71 begin
72 resName := g_ExtractFilePathName(filename);
73 if wad.GetResource(resName, data, size, false) then
74 begin
75 result := r_Font_LoadInfoFromMemory(data, size, f);
76 FreeMem(data);
77 end;
78 wad.Free;
79 end;
80 end;
82 end.