Rev 2302 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * font.h |
||
2302 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1528 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | #ifndef _FONT |
||
9 | #define _FONT |
||
10 | |||
11 | #include <string> |
||
12 | #include <fstream> |
||
13 | #include <map> |
||
14 | |||
15 | #include "dingl.h" |
||
16 | #include "glyph.h" |
||
17 | |||
1789 | jag | 18 | #define MAKETYPE(N, T, U, V) \ |
19 | struct N { \ |
||
20 | T U;\ |
||
21 | T V;\ |
||
22 | N () { U = 0; V = 0;}\ |
||
23 | }; |
||
24 | |||
25 | MAKETYPE (charwidtht, int, max, avg) |
||
26 | MAKETYPE (charheightt, int, max, avg) |
||
27 | MAKETYPE (cellsizet, int, x, y) |
||
28 | MAKETYPE (spacingt, int, ch, word) |
||
29 | |||
1528 | jag | 30 | struct font { |
31 | |||
32 | std::string fname; |
||
33 | std::string name; |
||
34 | |||
35 | int nchars; |
||
36 | |||
1789 | jag | 37 | charwidtht charwidth; |
38 | charheightt charheight; |
||
39 | cellsizet cellsize; |
||
40 | spacingt spacing; |
||
1528 | jag | 41 | |
42 | int lift; |
||
43 | int headroom; // space above char |
||
44 | |||
45 | std::map <char, glyph> characters; // vector desc of chars |
||
46 | std::map < char, std::map<char, int> > kern; // char-char kerning |
||
47 | |||
2310 | jag | 48 | int mod; // modified? |
1528 | jag | 49 | |
50 | font (const std::string& fn); |
||
51 | ~font (); |
||
2310 | jag | 52 | |
1528 | jag | 53 | void load (const std::string& fn); |
54 | void load (std::ifstream& file); |
||
2310 | jag | 55 | |
1528 | jag | 56 | void save (); |
2310 | jag | 57 | |
1789 | jag | 58 | const std::string& filename () const { return fname;} |
1528 | jag | 59 | |
2310 | jag | 60 | |
1528 | jag | 61 | int char_width (char c); |
62 | int char_height (char c); |
||
2310 | jag | 63 | |
1789 | jag | 64 | void calc_line_height (); |
1528 | jag | 65 | |
2072 | jag | 66 | void draw_char (char c, int x, int y, int z = 0); |
1528 | jag | 67 | |
68 | const std::map<char, glyph>& get_chars (); |
||
69 | void set_chars (const std::map<char, glyph>& chars); |
||
70 | |||
71 | #ifdef __SVG_OUT__ |
||
72 | std::ofstream svg; |
||
73 | void write_char (char c, int x, int y, int z = 0); |
||
74 | #endif |
||
75 | |||
76 | #ifdef __PLOTTER_OUT__ |
||
77 | std::ofstream hpgl; |
||
78 | void plot_char (char c, int x, int y, int z = 0); |
||
79 | #endif |
||
1789 | jag | 80 | |
1528 | jag | 81 | }; |
82 | |||
83 | extern font fnt; |
||
84 | extern int line_height; |
||
85 | |||
86 | inline void draw_char (char c, int x, int y, int z = 0) { |
||
87 | fnt.draw_char (c, x, y, z); |
||
88 | } |
||
89 | |||
90 | int draw_string (const std::string& s, int x, int y, int z = 0); |
||
91 | |||
92 | #ifdef __SVG_OUT__ |
||
93 | int write_string (const std::string& s, int x, int y, int z = 0); |
||
94 | #endif |
||
95 | |||
96 | #ifdef __PLOTTER_OUT__ |
||
97 | int plot_string (const std::string& s, int x, int y, int z = 0); |
||
98 | #endif |
||
99 | |||
100 | int get_char_width (const std::string& s); |
||
1789 | jag | 101 | int get_char_height (const std::string& s); |
2006 | jag | 102 | void get_char_width_height (const std::string& s, int& w, int& h); |
1528 | jag | 103 | |
104 | #endif |