annotate gui/skin/font.c @ 33064:33d307c4430c

Add error check. Check whether a section is already open.
author ib
date Wed, 30 Mar 2011 10:36:52 +0000
parents f64d41dac10b
children 334e19411421
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
32851
4a0455472d13 Add missing include file.
ib
parents: 32842
diff changeset
19 #include <gtk/gtk.h>
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
20 #include <inttypes.h>
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22 #include <string.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 #include "font.h"
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
25 #include "gui/interface.h"
33046
9684ad0e1291 Move files with auxiliary functions to own directory.
ib
parents: 32917
diff changeset
26 #include "gui/util/cut.h"
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents: 33046
diff changeset
27 #include "gui/util/string.h"
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
28 #include "skin.h"
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
29
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
30 #include "libavutil/avstring.h"
26382
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
31 #include "mp_msg.h"
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
32
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
33 static bmpFont *Fonts[MAX_FONTS];
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
35 static int fntAddNewFont(char *name)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
36 {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
37 int id, i;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
39 for (id = 0; id < MAX_FONTS; id++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
40 if (!Fonts[id])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
41 break;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
43 if (id == MAX_FONTS)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
44 return -2;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
46 Fonts[id] = calloc(1, sizeof(*Fonts[id]));
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
48 if (!Fonts[id])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
49 return -1;
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
50
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
51 av_strlcpy(Fonts[id]->name, name, MAX_FONT_NAME);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
53 for (i = 0; i < ASCII_CHRS + EXTRA_CHRS; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
54 Fonts[id]->Fnt[i].x = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
55 Fonts[id]->Fnt[i].y = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
56 Fonts[id]->Fnt[i].sx = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
57 Fonts[id]->Fnt[i].sy = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
58 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
60 return id;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
63 void fntFreeFont(void)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
65 int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
66
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
67 for (i = 0; i < MAX_FONTS; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
68 if (Fonts[i]) {
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
69 bpFree(&Fonts[i]->Bitmap);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
70 gfree((void **)&Fonts[i]);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
71 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
73 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
75 int fntRead(char *path, char *fname)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
76 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
77 FILE *f;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
78 unsigned char tmp[512];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
79 unsigned char *ptmp;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
80 unsigned char command[32];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
81 unsigned char param[256];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
82 int id, n, i;
32817
a104f879bfbc Clean up variable declarations.
ib
parents: 32810
diff changeset
83
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
84 id = fntAddNewFont(fname);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
85
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
86 if (id < 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
87 return id;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
88
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
89 av_strlcpy(tmp, path, sizeof(tmp));
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
90 av_strlcat(tmp, fname, sizeof(tmp));
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
91 av_strlcat(tmp, ".fnt", sizeof(tmp));
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
92 f = fopen(tmp, "rt");
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
93
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
94 if (!f) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
95 gfree((void **)&Fonts[id]);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
96 return -3;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
97 }
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
98
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
99 while (fgets(tmp, sizeof(tmp), f)) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
100 tmp[strcspn(tmp, "\n\r")] = 0; // remove any kind of newline, if any
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
101 strswap(tmp, '\t', ' ');
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
102 trim(tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
103 ptmp = strchr(tmp, ';');
32839
2dd39155f320 Cosmetic: Make conditions more readable by having assignments outside.
ib
parents: 32838
diff changeset
104
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
105 if (ptmp && !(ptmp == tmp + 1 && tmp[0] == '"' && tmp[2] == '"'))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
106 *ptmp = 0;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
107
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
108 if (!*tmp)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
109 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
110
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
111 n = (strncmp(tmp, "\"=", 2) == 0 ? 1 : 0);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
112 cutItem(tmp, command, '=', n);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
113 cutItem(tmp, param, '=', n + 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
114
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
115 if (command[0] == '"') {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
116 if (!command[1])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
117 command[0] = '=';
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
118 else if (command[1] == '"')
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
119 command[1] = 0;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
120 else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
121 cutItem(command, command, '"', 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
122
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
123 if (command[0] & 0x80) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
124 for (i = 0; i < EXTRA_CHRS; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
125 if (!Fonts[id]->nonASCIIidx[i][0]) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
126 strncpy(Fonts[id]->nonASCIIidx[i], command, UTF8LENGTH);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
127 break;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
128 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
129 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
130
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
131 if (i == EXTRA_CHRS)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
132 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
133
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
134 i += ASCII_CHRS;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
135 } else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
136 i = command[0];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
137
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
138 cutItem(param, tmp, ',', 0);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
139 Fonts[id]->Fnt[i].x = atoi(tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
140
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
141 cutItem(param, tmp, ',', 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
142 Fonts[id]->Fnt[i].y = atoi(tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
143
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
144 cutItem(param, tmp, ',', 2);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
145 Fonts[id]->Fnt[i].sx = atoi(tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
146
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
147 cutItem(param, tmp, ',', 3);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
148 Fonts[id]->Fnt[i].sy = atoi(tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
149
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
150 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[font] char: '%s' params: %d,%d %dx%d\n", command, Fonts[id]->Fnt[i].x, Fonts[id]->Fnt[i].y, Fonts[id]->Fnt[i].sx, Fonts[id]->Fnt[i].sy);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
151 } else if (!strcmp(command, "image")) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
152 av_strlcpy(tmp, path, sizeof(tmp));
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
153 av_strlcat(tmp, param, sizeof(tmp));
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 mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[font] image file: %s\n", tmp);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
156
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
157 if (skinBPRead(tmp, &Fonts[id]->Bitmap) != 0) {
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
158 bpFree(&Fonts[id]->Bitmap);
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
159 gfree((void **)&Fonts[id]);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
160 fclose(f);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
161 return -4;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
162 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
163 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
164 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
165
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
166 fclose(f);
33053
f64d41dac10b Cosmetic: Separate return statement with newline.
ib
parents: 33048
diff changeset
167
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
168 return 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
169 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
170
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
171 int fntFindID(char *name)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
172 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
173 int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
174
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
175 for (i = 0; i < MAX_FONTS; i++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
176 if (Fonts[i])
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
177 if (!strcmp(name, Fonts[i]->name))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
178 return i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
179
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
180 return -1;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
181 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
182
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
183 // get Fnt index of character (utf8 or normal one) *str points to,
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
184 // then move pointer to next/previous character
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
185 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
186 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
187 unsigned char *p, uchar[6] = ""; // glib implements 31-bit UTF-8
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
188 int i, c = -1;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
189
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
190 if (**str & 0x80) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
191 if (utf8) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
192 p = *str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
193 *str = g_utf8_next_char(*str);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
194 strncpy(uchar, p, *str - p);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
195
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
196 if (direction < 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
197 *str = g_utf8_prev_char(p);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
198 } else {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
199 uchar[0] = **str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
200 *str += direction;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
201 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
202
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
203 for (i = 0; (i < EXTRA_CHRS) && Fonts[id]->nonASCIIidx[i][0]; i++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
204 if (strncmp(Fonts[id]->nonASCIIidx[i], uchar, UTF8LENGTH) == 0)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
205 return i + ASCII_CHRS;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
206
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
207 if (!utf8 &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
208 (Fonts[id]->nonASCIIidx[i][0] == (*uchar >> 6 | 0xc0) &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
209 Fonts[id]->nonASCIIidx[i][1] == ((*uchar & 0x3f) | 0x80) &&
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
210 Fonts[id]->nonASCIIidx[i][2] == 0))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
211 c = i + ASCII_CHRS;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
212 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
213 } else {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
214 c = **str;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
215
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
216 if (utf8 && (direction < 0))
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
217 *str = g_utf8_prev_char(*str);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
218 else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
219 *str += direction;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
220 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
221
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
222 return c;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
223 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
224
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
225 int fntTextWidth(int id, char *str)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
226 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
227 int size = 0, c;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
228 gboolean utf8;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
229 unsigned char *p;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
230
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
231 utf8 = g_utf8_validate(str, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
232 p = str;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
233
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
234 while (*p) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
235 c = fntGetCharIndex(id, &p, utf8, 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
236
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
237 if (c == -1 || Fonts[id]->Fnt[c].sx == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
238 c = ' ';
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
239
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
240 if (Fonts[id]->Fnt[c].sx != -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
241 size += Fonts[id]->Fnt[c].sx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
242 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
243
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
244 return size;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
245 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
246
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
247 static int fntTextHeight(int id, char *str)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
248 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
249 int max = 0, c, h;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
250 gboolean utf8;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
251 unsigned char *p;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
252
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
253 utf8 = g_utf8_validate(str, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
254 p = str;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
255
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
256 while (*p) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
257 c = fntGetCharIndex(id, &p, utf8, 1);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
258
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
259 if (c == -1 || Fonts[id]->Fnt[c].sx == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
260 c = ' ';
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
261
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
262 h = Fonts[id]->Fnt[c].sy;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
263
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
264 if (h > max)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
265 max = h;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
266 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
267
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
268 return max;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
269 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
270
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
271 txSample *fntRender(wItem *item, int px, char *txt)
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
272 {
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
273 unsigned char *u;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
274 unsigned int i;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
275 int c, dx, tw, th, fbw, iw, id, ofs;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
276 int x, y, fh, fw, fyc, yc;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
277 uint32_t *ibuf;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
278 uint32_t *obuf;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
279 gboolean utf8;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
280
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
281 id = item->fontid;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
282 tw = fntTextWidth(id, txt);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
283
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
284 if (!tw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
285 return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
286
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
287 iw = item->width;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
288 fbw = Fonts[id]->Bitmap.Width;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
289 th = fntTextHeight(id, txt);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
290
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
291 if (item->height != th)
32917
9949f3a123cf Add new function bpFree() to free txSamples (bitmaps).
ib
parents: 32869
diff changeset
292 bpFree(&item->Bitmap);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
293
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
294 if (!item->Bitmap.Image) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
295 item->Bitmap.Height = item->height = th;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
296 item->Bitmap.Width = item->width = iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
297 item->Bitmap.ImageSize = item->height * iw * 4;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
298
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
299 if (!item->Bitmap.ImageSize)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
300 return NULL;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
301
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
302 item->Bitmap.BPP = 32;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
303 item->Bitmap.Image = malloc(item->Bitmap.ImageSize);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
304
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
305 if (!item->Bitmap.Image)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
306 return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
307 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
308
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
309 obuf = (uint32_t *)item->Bitmap.Image;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
310 ibuf = (uint32_t *)Fonts[id]->Bitmap.Image;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
311
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
312 for (i = 0; i < item->Bitmap.ImageSize / 4; i++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
313 obuf[i] = 0x00ff00ff;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
314
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
315 if (tw <= iw) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
316 switch (item->align) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
317 default:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
318 case fntAlignLeft:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
319 dx = 0;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
320 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
321
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
322 case fntAlignCenter:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
323 dx = (iw - tw) / 2;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
324 break;
32792
31ce0bd110d5 Only replace non-existing font character by space if space itself exists.
ib
parents: 32791
diff changeset
325
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
326 case fntAlignRight:
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
327 dx = iw - tw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
328 break;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
329 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
330 } else
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
331 dx = px;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
332
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
333 ofs = dx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
334
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
335 utf8 = g_utf8_validate(txt, -1, NULL);
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
336 u = txt;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
337
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
338 while (*u) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
339 c = fntGetCharIndex(id, &u, utf8, 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
340
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
341 if (c != -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
342 fw = Fonts[id]->Fnt[c].sx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
343
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
344 if (c == -1 || fw == -1) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
345 c = ' ';
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
346 fw = Fonts[id]->Fnt[c].sx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
347 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
348
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
349 if (fw == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
350 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
351
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
352 fh = Fonts[id]->Fnt[c].sy;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
353 fyc = Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
354 yc = dx;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
355
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
356 if (dx >= 0) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
357 for (y = 0; y < fh; y++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
358 for (x = 0; x < fw; x++)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
359 if (dx + x >= 0 && dx + x < iw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
360 obuf[yc + x] = ibuf[fyc + x];
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
361
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
362 fyc += fbw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
363 yc += iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
364 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
365 }
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
366
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
367 dx += fw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
368 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
369
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
370 if (ofs > 0 && tw > item->width) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
371 dx = ofs;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
372 u = txt + strlen(txt);
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
373
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
374 while (u > (unsigned char *)txt) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
375 c = fntGetCharIndex(id, &u, utf8, -1);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
376
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
377 if (c != -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
378 fw = Fonts[id]->Fnt[c].sx;
32792
31ce0bd110d5 Only replace non-existing font character by space if space itself exists.
ib
parents: 32791
diff changeset
379
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
380 if (c == -1 || fw == -1) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
381 c = ' ';
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
382 fw = Fonts[id]->Fnt[c].sx;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
383 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
384
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
385 if (fw == -1)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
386 continue;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
387
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
388 fh = Fonts[id]->Fnt[c].sy;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
389 fyc = Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
390
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
391 dx -= fw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
392 yc = dx;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
393
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
394 if (dx >= 0) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
395 for (y = 0; y < fh; y++) {
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
396 for (x = fw - 1; x >= 0; x--)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
397 if (dx + x >= 0 && dx + x < iw)
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
398 obuf[yc + x] = ibuf[fyc + x];
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 fyc += fbw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
401 yc += iw;
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
402 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
403 }
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
404 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
405 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
406
32869
67ec52396b81 Cosmetic: Format to MPlayer coding style.
ib
parents: 32858
diff changeset
407 return &item->Bitmap;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
408 }