annotate gui/skin/font.c @ 36989:0b80003f6542

Relocate the cut functions. Put them into the string functions file.
author ib
date Thu, 27 Mar 2014 09:15:47 +0000
parents c17e58ec1e65
children fa8b6892b0bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26458
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
1 /*
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
2 * This file is part of MPlayer.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
3 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
5 * it under the terms of the GNU General Public License as published by
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
7 * (at your option) any later version.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
8 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
12 * GNU General Public License for more details.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
13 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
14 * You should have received a copy of the GNU General Public License along
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
17 */
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
18
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
19 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
20 * @file
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
21 * @brief Font file parser and font rendering
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
22 */
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
23
36013
fcc519c99311 Replace #include.
ib
parents: 35688
diff changeset
24 #include <glib.h>
33123
9566100d88a1 Replace inttypes.h by stdint.h and remove inttypes.h where unneeded.
ib
parents: 33082
diff changeset
25 #include <stdint.h>
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
26 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
27 #include <string.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
29 #include "font.h"
35530
cc6e25e348ee Cosmetic: Rearrange #includes.
ib
parents: 34578
diff changeset
30 #include "skin.h"
33739
9f6d46d325de Remove gfree() from interface.c.
ib
parents: 33731
diff changeset
31 #include "gui/util/mem.h"
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents: 33046
diff changeset
32 #include "gui/util/string.h"
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
33
36032
c667e34fb941 Cosmetic: Rearrange #includes.
ib
parents: 36013
diff changeset
34 #include "mp_msg.h"
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
35 #include "libavutil/avstring.h"
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
36
33269
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
37 #define MAX_FONTS 25
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
38
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
39 #define fntAlignLeft 0
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
40 #define fntAlignCenter 1
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
41 #define fntAlignRight 2
49ca38147d1f Remove private symbolic constants from header files.
ib
parents: 33129
diff changeset
42
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
43 static bmpFont *Fonts[MAX_FONTS];
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
44
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
45 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
46 * @brief Add a font to #Fonts.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
47 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
48 * @param name name of the font
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
49 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
50 * @return an identification >= 0 (ok), -1 (out of memory) or -2 (#MAX_FONTS exceeded)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
51 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
52 static int fntAddNewFont(char *name)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
53 {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
54 int id, i;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
56 for (id = 0; id < MAX_FONTS; id++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
57 if (!Fonts[id])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
58 break;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
60 if (id == MAX_FONTS)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
61 return -2;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
63 Fonts[id] = calloc(1, sizeof(*Fonts[id]));
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
65 if (!Fonts[id])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
66 return -1;
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
67
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
68 av_strlcpy(Fonts[id]->name, name, MAX_FONT_NAME);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
70 for (i = 0; i < ASCII_CHRS + EXTRA_CHRS; i++) {
36983
c17e58ec1e65 Cosmetic: Adjust indent.
ib
parents: 36982
diff changeset
71 Fonts[id]->Fnt[i].x = -1;
c17e58ec1e65 Cosmetic: Adjust indent.
ib
parents: 36982
diff changeset
72 Fonts[id]->Fnt[i].y = -1;
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
73 Fonts[id]->Fnt[i].w = -1;
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
74 Fonts[id]->Fnt[i].h = -1;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
75 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
77 return id;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
78 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
80 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
81 * @brief Free all memory allocated to fonts.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
82 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
83 void fntFreeFont(void)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
84 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
85 int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
86
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
87 for (i = 0; i < MAX_FONTS; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
88 if (Fonts[i]) {
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
89 bpFree(&Fonts[i]->Bitmap);
33739
9f6d46d325de Remove gfree() from interface.c.
ib
parents: 33731
diff changeset
90 nfree(Fonts[i]);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
91 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
95 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
96 * @brief Read and parse a font file.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
97 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
98 * @param path directory the font file is in
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
99 * @param fname name of the font
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
100 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
101 * @return 0 (ok), -1 or -2 (return code of #fntAddNewFont()),
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
102 * -3 (file error) or -4 (#skinImageRead() error)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
103 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
104 int fntRead(char *path, char *fname)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
105 {
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
106 FILE *file;
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
107 unsigned char buf[512];
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
108 unsigned char item[32];
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
109 unsigned char param[256];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
110 int id, n, i;
32817
a104f879bfbc Clean up variable declarations.
ib
parents: 32810
diff changeset
111
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
112 id = fntAddNewFont(fname);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
113
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
114 if (id < 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
115 return id;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
116
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
117 av_strlcpy(buf, path, sizeof(buf));
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
118 av_strlcat(buf, fname, sizeof(buf));
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
119 av_strlcat(buf, ".fnt", sizeof(buf));
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
120 file = fopen(buf, "rt");
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
121
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
122 if (!file) {
33739
9f6d46d325de Remove gfree() from interface.c.
ib
parents: 33731
diff changeset
123 nfree(Fonts[id]);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
124 return -3;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
125 }
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
126
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
127 while (fgetstr(buf, sizeof(buf), file)) {
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
128 strswap(buf, '\t', ' ');
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
129 trim(buf);
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
130 decomment(buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
131
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
132 if (!*buf)
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
133 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
134
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
135 n = (strncmp(buf, "\"=", 2) == 0 ? 1 : 0);
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
136 cutItem(buf, item, '=', n);
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
137 cutItem(buf, param, '=', n + 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
138
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
139 if (item[0] == '"') {
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
140 if (!item[1])
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
141 item[0] = '=';
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
142 else if (item[1] == '"')
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
143 item[1] = 0;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
144 else
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
145 cutItem(item, item, '"', 1);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
146
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
147 if (item[0] & 0x80) {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
148 for (i = 0; i < EXTRA_CHRS; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
149 if (!Fonts[id]->nonASCIIidx[i][0]) {
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
150 strncpy(Fonts[id]->nonASCIIidx[i], item, UTF8LENGTH);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
151 break;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
152 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
153 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
154
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
155 if (i == EXTRA_CHRS)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
156 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
157
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
158 i += ASCII_CHRS;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
159 } else
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
160 i = item[0];
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
161
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
162 cutItem(param, buf, ',', 0);
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
163 Fonts[id]->Fnt[i].x = atoi(buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
164
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
165 cutItem(param, buf, ',', 1);
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
166 Fonts[id]->Fnt[i].y = atoi(buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
167
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
168 cutItem(param, buf, ',', 2);
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
169 Fonts[id]->Fnt[i].w = atoi(buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
170
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
171 cutItem(param, buf, ',', 3);
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
172 Fonts[id]->Fnt[i].h = atoi(buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
173
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
174 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[font] char: '%s' params: %d,%d %dx%d\n", item, Fonts[id]->Fnt[i].x, Fonts[id]->Fnt[i].y, Fonts[id]->Fnt[i].w, Fonts[id]->Fnt[i].h);
33082
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
175 } else if (!strcmp(item, "image")) {
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
176 av_strlcpy(buf, path, sizeof(buf));
8b561660a6f7 Cosmetic: Use more appropriate variable names.
ib
parents: 33073
diff changeset
177 av_strlcat(buf, param, sizeof(buf));
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
178
33985
d99f341d8442 Replace all mp_dbg() calls by mp_msg().
ib
parents: 33973
diff changeset
179 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[font] image file: %s\n", buf);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
180
33969
9184bc37d4d5 Cosmetic: Rename skinBPRead() skinImageRead().
ib
parents: 33739
diff changeset
181 if (skinImageRead(buf, &Fonts[id]->Bitmap) != 0) {
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
182 bpFree(&Fonts[id]->Bitmap);
33739
9f6d46d325de Remove gfree() from interface.c.
ib
parents: 33731
diff changeset
183 nfree(Fonts[id]);
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
184 fclose(file);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
185 return -4;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
186 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
187 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
188 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
189
34578
948bec0f8df3 Cosmetic: Change some variable names.
ib
parents: 34560
diff changeset
190 fclose(file);
33053
f64d41dac10b Cosmetic: Separate return statement with newline.
ib
parents: 33048
diff changeset
191
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
192 return 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
193 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
194
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
195 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
196 * @brief Find the ID of a font by its name.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
197 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
198 * @param name name of the font
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
199 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
200 * @return an identification >= 0 (ok) or -1 (not found)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
201 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
202 int fntFindID(char *name)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
203 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
204 int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
205
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
206 for (i = 0; i < MAX_FONTS; i++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
207 if (Fonts[i])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
208 if (!strcmp(name, Fonts[i]->name))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
209 return i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
210
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
211 return -1;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
212 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
213
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
214 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
215 * @brief Get the #bmpFont::Fnt index of the character @a *str points to.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
216 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
217 * Move pointer @a *str to the character according to @a direction
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
218 * afterwards.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
219 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
220 * @param id font ID
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
221 * @param str pointer to the string
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
222 * @param uft8 flag indicating whether @a str contains UTF-8 characters
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
223 * @param direction +1 (forward) or -1 (backward)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
224 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
225 * @return index >= 0 (ok) or -1 (not found)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
226 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
227 static int fntGetCharIndex(int id, unsigned char **str, gboolean utf8, int direction)
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
228 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
229 unsigned char *p, uchar[6] = ""; // glib implements 31-bit UTF-8
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
230 int i, c = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
231
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
232 if (**str & 0x80) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
233 if (utf8) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
234 p = *str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
235 *str = g_utf8_next_char(*str);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
236 strncpy(uchar, p, *str - p);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
237
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
238 if (direction < 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
239 *str = g_utf8_prev_char(p);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
240 } else {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
241 uchar[0] = **str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
242 *str += direction;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
243 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
244
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
245 for (i = 0; (i < EXTRA_CHRS) && Fonts[id]->nonASCIIidx[i][0]; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
246 if (strncmp(Fonts[id]->nonASCIIidx[i], uchar, UTF8LENGTH) == 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
247 return i + ASCII_CHRS;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
248
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
249 if (!utf8 &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
250 (Fonts[id]->nonASCIIidx[i][0] == (*uchar >> 6 | 0xc0) &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
251 Fonts[id]->nonASCIIidx[i][1] == ((*uchar & 0x3f) | 0x80) &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
252 Fonts[id]->nonASCIIidx[i][2] == 0))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
253 c = i + ASCII_CHRS;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
254 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
255 } else {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
256 c = **str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
257
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
258 if (utf8 && (direction < 0))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
259 *str = g_utf8_prev_char(*str);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
260 else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
261 *str += direction;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
262 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
263
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
264 return c;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
265 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
266
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
267 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
268 * @brief Get the rendering width of a text.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
269 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
270 * @param id font ID
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
271 * @param str string to be examined
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
272 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
273 * @return width of the rendered string (in pixels)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
274 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
275 int fntTextWidth(int id, char *str)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
276 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
277 int size = 0, c;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
278 gboolean utf8;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
279 unsigned char *p;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
280
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
281 utf8 = g_utf8_validate(str, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
282 p = str;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
283
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
284 while (*p) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
285 c = fntGetCharIndex(id, &p, utf8, 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
286
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
287 if (c == -1 || Fonts[id]->Fnt[c].w == -1)
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
288 c = ' ';
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
289
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
290 if (Fonts[id]->Fnt[c].w != -1)
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
291 size += Fonts[id]->Fnt[c].w;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
292 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
293
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
294 return size;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
295 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
296
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
297 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
298 * @brief Get the rendering height of a text.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
299 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
300 * @param id font ID
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
301 * @param str string to be examined
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
302 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
303 * @return height of the rendered string (in pixels)
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
304 */
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
305 static int fntTextHeight(int id, char *str)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
306 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
307 int max = 0, c, h;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
308 gboolean utf8;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
309 unsigned char *p;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
310
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
311 utf8 = g_utf8_validate(str, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
312 p = str;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
313
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
314 while (*p) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
315 c = fntGetCharIndex(id, &p, utf8, 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
316
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
317 if (c == -1 || Fonts[id]->Fnt[c].w == -1)
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
318 c = ' ';
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
319
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
320 h = Fonts[id]->Fnt[c].h;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
321
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
322 if (h > max)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
323 max = h;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
324 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
325
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
326 return max;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
327 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
328
33973
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
329 /**
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
330 * @brief Render a text on an item.
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
331 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
332 * @param item item the text shall be placed on
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
333 * @param px x position for the text in case it is wider than the item width
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
334 * @param txt text to be rendered
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
335 *
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
336 * @return image containing the rendered text
082ab13a41ab Add doxygen comments to font.c.
ib
parents: 33971
diff changeset
337 */
35688
6fd886ce32b9 Cosmetic: Rename wItem guiItem.
ib
parents: 35530
diff changeset
338 guiImage *fntTextRender(guiItem *item, int px, char *txt)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
339 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
340 unsigned char *u;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
341 unsigned int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
342 int c, dx, tw, th, fbw, iw, id, ofs;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
343 int x, y, fh, fw, fyc, yc;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
344 uint32_t *ibuf;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
345 uint32_t *obuf;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
346 gboolean utf8;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
347
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
348 id = item->fontid;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
349 tw = fntTextWidth(id, txt);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
350
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
351 if (!tw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
352 return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
353
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
354 iw = item->width;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
355 fbw = Fonts[id]->Bitmap.Width;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
356 th = fntTextHeight(id, txt);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
357
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
358 if (item->height != th)
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
359 bpFree(&item->Bitmap);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
360
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
361 if (!item->Bitmap.Image) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
362 item->Bitmap.Height = item->height = th;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
363 item->Bitmap.Width = item->width = iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
364 item->Bitmap.ImageSize = item->height * iw * 4;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
365
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
366 if (!item->Bitmap.ImageSize)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
367 return NULL;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
368
33555
c5a19bbeac2b Cosmetic: Rename some GUI variables and functions.
ib
parents: 33269
diff changeset
369 item->Bitmap.Bpp = 32;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
370 item->Bitmap.Image = malloc(item->Bitmap.ImageSize);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
371
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
372 if (!item->Bitmap.Image)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
373 return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
374 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
375
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
376 obuf = (uint32_t *)item->Bitmap.Image;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
377 ibuf = (uint32_t *)Fonts[id]->Bitmap.Image;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
378
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
379 for (i = 0; i < item->Bitmap.ImageSize / 4; i++)
33731
81f71d910333 Cosmetic: Change prefix for symbolic constants from GMP to GUI.
ib
parents: 33728
diff changeset
380 obuf[i] = GUI_TRANSPARENT;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
381
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
382 if (tw <= iw) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
383 switch (item->align) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
384 default:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
385 case fntAlignLeft:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
386 dx = 0;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
387 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
388
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
389 case fntAlignCenter:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
390 dx = (iw - tw) / 2;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
391 break;
32792
31ce0bd110d5 Only replace non-existing font character by space if space itself exists.
ib
parents: 32791
diff changeset
392
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
393 case fntAlignRight:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
394 dx = iw - tw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
395 break;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
396 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
397 } else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
398 dx = px;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
399
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
400 ofs = dx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
401
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
402 utf8 = g_utf8_validate(txt, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
403 u = txt;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
404
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
405 while (*u) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
406 c = fntGetCharIndex(id, &u, utf8, 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
407
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
408 if (c != -1)
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
409 fw = Fonts[id]->Fnt[c].w;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
410
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
411 if (c == -1 || fw == -1) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
412 c = ' ';
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
413 fw = Fonts[id]->Fnt[c].w;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
414 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
415
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
416 if (fw == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
417 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
418
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
419 fh = Fonts[id]->Fnt[c].h;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
420 fyc = Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
421 yc = dx;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
422
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
423 if (dx >= 0) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
424 for (y = 0; y < fh; y++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
425 for (x = 0; x < fw; x++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
426 if (dx + x >= 0 && dx + x < iw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
427 obuf[yc + x] = ibuf[fyc + x];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
428
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
429 fyc += fbw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
430 yc += iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
431 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
432 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
433
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
434 dx += fw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
435 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
436
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
437 if (ofs > 0 && tw > item->width) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
438 dx = ofs;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
439 u = txt + strlen(txt);
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
440
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
441 while (u > (unsigned char *)txt) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
442 c = fntGetCharIndex(id, &u, utf8, -1);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
443
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
444 if (c != -1)
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
445 fw = Fonts[id]->Fnt[c].w;
32792
31ce0bd110d5 Only replace non-existing font character by space if space itself exists.
ib
parents: 32791
diff changeset
446
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
447 if (c == -1 || fw == -1) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
448 c = ' ';
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
449 fw = Fonts[id]->Fnt[c].w;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
450 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
451
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
452 if (fw == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
453 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
454
36982
896b8c73943e Cosmetic: Rename fntChar members for width and height.
ib
parents: 36032
diff changeset
455 fh = Fonts[id]->Fnt[c].h;
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
456 fyc = Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
457
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
458 dx -= fw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
459 yc = dx;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
460
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
461 if (dx >= 0) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
462 for (y = 0; y < fh; y++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
463 for (x = fw - 1; x >= 0; x--)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
464 if (dx + x >= 0 && dx + x < iw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
465 obuf[yc + x] = ibuf[fyc + x];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
466
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
467 fyc += fbw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
468 yc += iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
469 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
470 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
471 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
472 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
473
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
474 return &item->Bitmap;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
475 }