annotate font/font_peer_ft2.cc @ 12:2e6a92ed913b

Fixes savegames names
author thib
date Wed, 06 Aug 2008 12:26:57 +0000
parents 223b71206888
children 5f548e5957a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Yuki Sawada
223b71206888 Initial import
thib
parents:
diff changeset
4 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
5 *
223b71206888 Initial import
thib
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
7 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
8 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
12 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
13 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
14 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
15 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
16 *
223b71206888 Initial import
thib
parents:
diff changeset
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
27 */
223b71206888 Initial import
thib
parents:
diff changeset
28
223b71206888 Initial import
thib
parents:
diff changeset
29 #include <stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
30 #include <stdlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include <string.h>
223b71206888 Initial import
thib
parents:
diff changeset
32 #include <stdexcept>
223b71206888 Initial import
thib
parents:
diff changeset
33 #include <string>
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
36
223b71206888 Initial import
thib
parents:
diff changeset
37 #include "font.h"
223b71206888 Initial import
thib
parents:
diff changeset
38 #include "font_peer.h"
223b71206888 Initial import
thib
parents:
diff changeset
39 #include "codeconv.h"
223b71206888 Initial import
thib
parents:
diff changeset
40
223b71206888 Initial import
thib
parents:
diff changeset
41 namespace XKFont {
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 typedef struct _FontLibrary {
223b71206888 Initial import
thib
parents:
diff changeset
44 FT_Library super;
223b71206888 Initial import
thib
parents:
diff changeset
45 int ref_count;
223b71206888 Initial import
thib
parents:
diff changeset
46 char **paths;
223b71206888 Initial import
thib
parents:
diff changeset
47 int num_paths;
223b71206888 Initial import
thib
parents:
diff changeset
48 } FontLibrary;
223b71206888 Initial import
thib
parents:
diff changeset
49
223b71206888 Initial import
thib
parents:
diff changeset
50 static FontLibrary *library = NULL;
223b71206888 Initial import
thib
parents:
diff changeset
51
223b71206888 Initial import
thib
parents:
diff changeset
52 static char *default_paths[] = {
223b71206888 Initial import
thib
parents:
diff changeset
53 ".",
223b71206888 Initial import
thib
parents:
diff changeset
54 "/",
223b71206888 Initial import
thib
parents:
diff changeset
55 "/usr/X11R6/lib/X11/fonts/TrueType",
223b71206888 Initial import
thib
parents:
diff changeset
56 "/usr/local/share/fonts/TrueType",
223b71206888 Initial import
thib
parents:
diff changeset
57 "/usr//share/fonts/TrueType",
223b71206888 Initial import
thib
parents:
diff changeset
58 "/usr//share/fonts/tt",
223b71206888 Initial import
thib
parents:
diff changeset
59 NULL
223b71206888 Initial import
thib
parents:
diff changeset
60 };
223b71206888 Initial import
thib
parents:
diff changeset
61
223b71206888 Initial import
thib
parents:
diff changeset
62 static void font_library_ft2_add_path(const char *path);
223b71206888 Initial import
thib
parents:
diff changeset
63 static void font_library_ft2_remove_path(const char *path);
223b71206888 Initial import
thib
parents:
diff changeset
64 static void font_library_ft2_add_path(const char *path);
223b71206888 Initial import
thib
parents:
diff changeset
65 static char *font_library_ft2_build_path(const char *base, const char *name);
223b71206888 Initial import
thib
parents:
diff changeset
66
223b71206888 Initial import
thib
parents:
diff changeset
67 static int
223b71206888 Initial import
thib
parents:
diff changeset
68 font_library_ft2_alloc()
223b71206888 Initial import
thib
parents:
diff changeset
69 {
223b71206888 Initial import
thib
parents:
diff changeset
70 int i;
223b71206888 Initial import
thib
parents:
diff changeset
71
223b71206888 Initial import
thib
parents:
diff changeset
72 if (!library) {
223b71206888 Initial import
thib
parents:
diff changeset
73 library = (FontLibrary*) calloc(sizeof(FontLibrary), 1);
223b71206888 Initial import
thib
parents:
diff changeset
74 if (library) {
223b71206888 Initial import
thib
parents:
diff changeset
75 if (FT_Init_FreeType(&library->super))
223b71206888 Initial import
thib
parents:
diff changeset
76 goto _1;
223b71206888 Initial import
thib
parents:
diff changeset
77 fprintf(stderr, "XKFont::font_library_ft2_alloc : FreeType allocated successfully.\n");
223b71206888 Initial import
thib
parents:
diff changeset
78 for (i = 0; default_paths[i]; i++)
223b71206888 Initial import
thib
parents:
diff changeset
79 font_library_ft2_add_path(default_paths[i]);
223b71206888 Initial import
thib
parents:
diff changeset
80 }
223b71206888 Initial import
thib
parents:
diff changeset
81 }
223b71206888 Initial import
thib
parents:
diff changeset
82
223b71206888 Initial import
thib
parents:
diff changeset
83 library->ref_count++;
223b71206888 Initial import
thib
parents:
diff changeset
84 return 1;
223b71206888 Initial import
thib
parents:
diff changeset
85
223b71206888 Initial import
thib
parents:
diff changeset
86 _1:
223b71206888 Initial import
thib
parents:
diff changeset
87 free(library);
223b71206888 Initial import
thib
parents:
diff changeset
88 library = NULL;
223b71206888 Initial import
thib
parents:
diff changeset
89 fprintf(stderr, "XKFont::font_library_ft2_alloc: Couldn't allocate FreeType.\n");
223b71206888 Initial import
thib
parents:
diff changeset
90 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
91 }
223b71206888 Initial import
thib
parents:
diff changeset
92
223b71206888 Initial import
thib
parents:
diff changeset
93 static void
223b71206888 Initial import
thib
parents:
diff changeset
94 font_library_ft2_free()
223b71206888 Initial import
thib
parents:
diff changeset
95 {
223b71206888 Initial import
thib
parents:
diff changeset
96 int i;
223b71206888 Initial import
thib
parents:
diff changeset
97
223b71206888 Initial import
thib
parents:
diff changeset
98 if (!library || library->ref_count <= 0)
223b71206888 Initial import
thib
parents:
diff changeset
99 return;
223b71206888 Initial import
thib
parents:
diff changeset
100 if (--library->ref_count == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
101 FT_Done_FreeType(library->super);
223b71206888 Initial import
thib
parents:
diff changeset
102 for (i = 0; i < library->num_paths; i++)
223b71206888 Initial import
thib
parents:
diff changeset
103 free(library->paths[i]);
223b71206888 Initial import
thib
parents:
diff changeset
104 free(library->paths);
223b71206888 Initial import
thib
parents:
diff changeset
105 free(library);
223b71206888 Initial import
thib
parents:
diff changeset
106 library = NULL;
223b71206888 Initial import
thib
parents:
diff changeset
107 fprintf(stderr, "XKFont::font_library_ft2_free : FreeType done.\n");
223b71206888 Initial import
thib
parents:
diff changeset
108 }
223b71206888 Initial import
thib
parents:
diff changeset
109 }
223b71206888 Initial import
thib
parents:
diff changeset
110
223b71206888 Initial import
thib
parents:
diff changeset
111 static void
223b71206888 Initial import
thib
parents:
diff changeset
112 font_library_ft2_add_path(const char *path)
223b71206888 Initial import
thib
parents:
diff changeset
113 {
223b71206888 Initial import
thib
parents:
diff changeset
114 library->num_paths++;
223b71206888 Initial import
thib
parents:
diff changeset
115 if (!library->paths)
223b71206888 Initial import
thib
parents:
diff changeset
116 library->paths = (char**) malloc(sizeof(char *));
223b71206888 Initial import
thib
parents:
diff changeset
117 else
223b71206888 Initial import
thib
parents:
diff changeset
118 library->paths = (char**) realloc( (void*)library->paths,
223b71206888 Initial import
thib
parents:
diff changeset
119 library->num_paths * sizeof(char *));
223b71206888 Initial import
thib
parents:
diff changeset
120 library->paths[library->num_paths - 1] = strdup(path);
223b71206888 Initial import
thib
parents:
diff changeset
121 }
223b71206888 Initial import
thib
parents:
diff changeset
122
223b71206888 Initial import
thib
parents:
diff changeset
123 static void
223b71206888 Initial import
thib
parents:
diff changeset
124 font_library_ft2_remove_path(const char *path)
223b71206888 Initial import
thib
parents:
diff changeset
125 {
223b71206888 Initial import
thib
parents:
diff changeset
126 int i, j;
223b71206888 Initial import
thib
parents:
diff changeset
127
223b71206888 Initial import
thib
parents:
diff changeset
128 for (i = 0; i < library->num_paths; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
129 if (!strcmp(path, library->paths[i])) {
223b71206888 Initial import
thib
parents:
diff changeset
130 library->num_paths--;
223b71206888 Initial import
thib
parents:
diff changeset
131 for (j = i; j < library->num_paths; j++)
223b71206888 Initial import
thib
parents:
diff changeset
132 library->paths[j] = library->paths[j + 1];
223b71206888 Initial import
thib
parents:
diff changeset
133 if (library->num_paths > 0)
223b71206888 Initial import
thib
parents:
diff changeset
134 library->paths = (char**) realloc(library->paths,
223b71206888 Initial import
thib
parents:
diff changeset
135 library->num_paths * sizeof(char *));
223b71206888 Initial import
thib
parents:
diff changeset
136 else {
223b71206888 Initial import
thib
parents:
diff changeset
137 free(library->paths);
223b71206888 Initial import
thib
parents:
diff changeset
138 library->paths = NULL;
223b71206888 Initial import
thib
parents:
diff changeset
139 }
223b71206888 Initial import
thib
parents:
diff changeset
140 }
223b71206888 Initial import
thib
parents:
diff changeset
141 }
223b71206888 Initial import
thib
parents:
diff changeset
142 }
223b71206888 Initial import
thib
parents:
diff changeset
143
223b71206888 Initial import
thib
parents:
diff changeset
144 typedef struct _FontEncoding {
223b71206888 Initial import
thib
parents:
diff changeset
145 FT_UShort platform_id;
223b71206888 Initial import
thib
parents:
diff changeset
146 FT_Encoding encoding;
223b71206888 Initial import
thib
parents:
diff changeset
147 FontCodeConverter conv_func;
223b71206888 Initial import
thib
parents:
diff changeset
148 } FontEncoding;
223b71206888 Initial import
thib
parents:
diff changeset
149
223b71206888 Initial import
thib
parents:
diff changeset
150 static FontEncoding encodings[] = {
223b71206888 Initial import
thib
parents:
diff changeset
151 { 3, (FT_Encoding)ft_encoding_unicode, codeconv_euc_to_unicode },
223b71206888 Initial import
thib
parents:
diff changeset
152 { 3, (FT_Encoding)ft_encoding_sjis, codeconv_euc_to_sjis },
223b71206888 Initial import
thib
parents:
diff changeset
153 { 1, (FT_Encoding)ft_encoding_apple_roman, codeconv_euc_to_latin1 },
223b71206888 Initial import
thib
parents:
diff changeset
154 { (FT_UShort)-1, (FT_Encoding)-1, NULL }
223b71206888 Initial import
thib
parents:
diff changeset
155 };
223b71206888 Initial import
thib
parents:
diff changeset
156
223b71206888 Initial import
thib
parents:
diff changeset
157 static char *
223b71206888 Initial import
thib
parents:
diff changeset
158 font_library_ft2_build_path(const char *base, const char *name)
223b71206888 Initial import
thib
parents:
diff changeset
159 {
223b71206888 Initial import
thib
parents:
diff changeset
160 char *path;
223b71206888 Initial import
thib
parents:
diff changeset
161 const char *strs[] = { base, "/", name, NULL };
223b71206888 Initial import
thib
parents:
diff changeset
162 int i = 0;
223b71206888 Initial import
thib
parents:
diff changeset
163
223b71206888 Initial import
thib
parents:
diff changeset
164 path = (char*) calloc(sizeof(char), strlen(base) + strlen(name) + 2);
223b71206888 Initial import
thib
parents:
diff changeset
165 if (path)
223b71206888 Initial import
thib
parents:
diff changeset
166 while (strs[i])
223b71206888 Initial import
thib
parents:
diff changeset
167 strcat(path, strs[i++]);
223b71206888 Initial import
thib
parents:
diff changeset
168
223b71206888 Initial import
thib
parents:
diff changeset
169 return path;
223b71206888 Initial import
thib
parents:
diff changeset
170 }
223b71206888 Initial import
thib
parents:
diff changeset
171
223b71206888 Initial import
thib
parents:
diff changeset
172 PeerFt2::PeerFt2(const char *name, int index, int hsize, int vsize)
223b71206888 Initial import
thib
parents:
diff changeset
173 {
223b71206888 Initial import
thib
parents:
diff changeset
174 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
175
223b71206888 Initial import
thib
parents:
diff changeset
176 font_library_ft2_alloc();
223b71206888 Initial import
thib
parents:
diff changeset
177
223b71206888 Initial import
thib
parents:
diff changeset
178 for (i = 0; i < library->num_paths; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
179 char *path = font_library_ft2_build_path(library->paths[i], name);
223b71206888 Initial import
thib
parents:
diff changeset
180 if (path) {
223b71206888 Initial import
thib
parents:
diff changeset
181 if (FT_New_Face(library->super, path, index, &face))
223b71206888 Initial import
thib
parents:
diff changeset
182 face = NULL;
223b71206888 Initial import
thib
parents:
diff changeset
183 free(path);
223b71206888 Initial import
thib
parents:
diff changeset
184 }
223b71206888 Initial import
thib
parents:
diff changeset
185 if (face)
223b71206888 Initial import
thib
parents:
diff changeset
186 break;
223b71206888 Initial import
thib
parents:
diff changeset
187 }
223b71206888 Initial import
thib
parents:
diff changeset
188
223b71206888 Initial import
thib
parents:
diff changeset
189 if (!face) {
223b71206888 Initial import
thib
parents:
diff changeset
190 string err = string("XKFont::PeerFt2::PeerFt : Cannot open font(TrueType) : ")+name;
223b71206888 Initial import
thib
parents:
diff changeset
191 throw std::invalid_argument(err);
223b71206888 Initial import
thib
parents:
diff changeset
192 }
223b71206888 Initial import
thib
parents:
diff changeset
193
223b71206888 Initial import
thib
parents:
diff changeset
194 conv_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
195 for (i=0; encodings[i].conv_func != 0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
196 FT_UShort platform_id = encodings[i].platform_id;
223b71206888 Initial import
thib
parents:
diff changeset
197 FT_Encoding encoding = encodings[i].encoding;
223b71206888 Initial import
thib
parents:
diff changeset
198 for (j = 0; j < face->num_charmaps; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
199 FT_CharMap cmap = face->charmaps[j];
223b71206888 Initial import
thib
parents:
diff changeset
200 if (cmap->platform_id == platform_id && cmap->encoding == encoding) {
223b71206888 Initial import
thib
parents:
diff changeset
201 if (FT_Set_Charmap(face, cmap) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
202 conv_func = encodings[i].conv_func;
223b71206888 Initial import
thib
parents:
diff changeset
203 break;
223b71206888 Initial import
thib
parents:
diff changeset
204 }
223b71206888 Initial import
thib
parents:
diff changeset
205 }
223b71206888 Initial import
thib
parents:
diff changeset
206 }
223b71206888 Initial import
thib
parents:
diff changeset
207 if (conv_func) break;
223b71206888 Initial import
thib
parents:
diff changeset
208 }
223b71206888 Initial import
thib
parents:
diff changeset
209 if (conv_func == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
210 FT_Done_Face(face);
223b71206888 Initial import
thib
parents:
diff changeset
211 fprintf(stderr,"cannot find charmap\n");
223b71206888 Initial import
thib
parents:
diff changeset
212 string err = string("XKFont::PeerFt2::PeerFt : No supported code converter of font (TrueType) ")+name;
223b71206888 Initial import
thib
parents:
diff changeset
213 throw std::invalid_argument(err);
223b71206888 Initial import
thib
parents:
diff changeset
214 }
223b71206888 Initial import
thib
parents:
diff changeset
215 FT_Set_Pixel_Sizes(face, hsize, vsize);
223b71206888 Initial import
thib
parents:
diff changeset
216
223b71206888 Initial import
thib
parents:
diff changeset
217 }
223b71206888 Initial import
thib
parents:
diff changeset
218
223b71206888 Initial import
thib
parents:
diff changeset
219 PeerFt2::~PeerFt2() {
223b71206888 Initial import
thib
parents:
diff changeset
220 FT_Done_Face(face);
223b71206888 Initial import
thib
parents:
diff changeset
221 font_library_ft2_free();
223b71206888 Initial import
thib
parents:
diff changeset
222 }
223b71206888 Initial import
thib
parents:
diff changeset
223
223b71206888 Initial import
thib
parents:
diff changeset
224 bool
223b71206888 Initial import
thib
parents:
diff changeset
225 PeerFt2::GlyphCreate(unsigned int code, Glyph* glyph)
223b71206888 Initial import
thib
parents:
diff changeset
226 {
223b71206888 Initial import
thib
parents:
diff changeset
227 FT_GlyphSlot slot;
223b71206888 Initial import
thib
parents:
diff changeset
228 FT_UInt index;
223b71206888 Initial import
thib
parents:
diff changeset
229 int bmsize;
223b71206888 Initial import
thib
parents:
diff changeset
230
223b71206888 Initial import
thib
parents:
diff changeset
231 if (face == 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
232 code = conv_func(code);
223b71206888 Initial import
thib
parents:
diff changeset
233 if (code == 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
234 index = FT_Get_Char_Index(face, code);
223b71206888 Initial import
thib
parents:
diff changeset
235 if (index == 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
236
223b71206888 Initial import
thib
parents:
diff changeset
237 /* Don't consider error */
223b71206888 Initial import
thib
parents:
diff changeset
238 slot = face->glyph;
223b71206888 Initial import
thib
parents:
diff changeset
239 if (slot) {
223b71206888 Initial import
thib
parents:
diff changeset
240 // if (! FT_Load_Glyph(face, index, FT_LOAD_DEFAULT)) {
223b71206888 Initial import
thib
parents:
diff changeset
241 // BITMAP だと なぜか render してくれない……
223b71206888 Initial import
thib
parents:
diff changeset
242 // LOAD_DEFAULT でも、下に対応コードを付けたので一応は大丈夫
223b71206888 Initial import
thib
parents:
diff changeset
243 if (! FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP)) {
223b71206888 Initial import
thib
parents:
diff changeset
244 FT_Render_Glyph(slot, ft_render_mode_normal);
223b71206888 Initial import
thib
parents:
diff changeset
245 }
223b71206888 Initial import
thib
parents:
diff changeset
246 }
223b71206888 Initial import
thib
parents:
diff changeset
247
223b71206888 Initial import
thib
parents:
diff changeset
248 glyph->bitmap_left = slot->bitmap_left;
223b71206888 Initial import
thib
parents:
diff changeset
249 glyph->bitmap_top = slot->bitmap_top;
223b71206888 Initial import
thib
parents:
diff changeset
250 glyph->bitmap.width = slot->bitmap.width;
223b71206888 Initial import
thib
parents:
diff changeset
251 glyph->bitmap.rows = slot->bitmap.rows;
223b71206888 Initial import
thib
parents:
diff changeset
252
223b71206888 Initial import
thib
parents:
diff changeset
253 /*
223b71206888 Initial import
thib
parents:
diff changeset
254 glyph->metrics.ascender = private->face->size->metrics.ascender >> 6;
223b71206888 Initial import
thib
parents:
diff changeset
255 glyph->metrics.descender = private->face->size->metrics.descender >> 6;
223b71206888 Initial import
thib
parents:
diff changeset
256 */
223b71206888 Initial import
thib
parents:
diff changeset
257
223b71206888 Initial import
thib
parents:
diff changeset
258 glyph->advance.x = slot->advance.x >> 6;
223b71206888 Initial import
thib
parents:
diff changeset
259 glyph->advance.y = slot->advance.y >> 6;
223b71206888 Initial import
thib
parents:
diff changeset
260
223b71206888 Initial import
thib
parents:
diff changeset
261 bmsize = glyph->bitmap.width * glyph->bitmap.rows;
223b71206888 Initial import
thib
parents:
diff changeset
262 if (bmsize > 0) {
223b71206888 Initial import
thib
parents:
diff changeset
263 glyph->bitmap.buffer = new unsigned char[bmsize];
223b71206888 Initial import
thib
parents:
diff changeset
264 memcpy(glyph->bitmap.buffer, slot->bitmap.buffer, bmsize);
223b71206888 Initial import
thib
parents:
diff changeset
265 }
223b71206888 Initial import
thib
parents:
diff changeset
266 // なぜか Render したのに MONO なことがある……
223b71206888 Initial import
thib
parents:
diff changeset
267 /* for freetype < 2.1.3, use ``ft_pixel_mode_mono'' */
223b71206888 Initial import
thib
parents:
diff changeset
268 if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) {int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
269 // if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
270 char* d = (char*)slot->bitmap.buffer;
223b71206888 Initial import
thib
parents:
diff changeset
271 for (i=0; i<glyph->bitmap.rows; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
272 int flag = *d++; int len = 8;
223b71206888 Initial import
thib
parents:
diff changeset
273 unsigned char* buf = glyph->bitmap.buffer + i*slot->bitmap.width;
223b71206888 Initial import
thib
parents:
diff changeset
274 for (j=0; j<glyph->bitmap.width; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
275 if (len == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
276 flag = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
277 len = 8;
223b71206888 Initial import
thib
parents:
diff changeset
278 }
223b71206888 Initial import
thib
parents:
diff changeset
279 if (flag & 0x80) *buf++ = 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
280 else *buf++ = 0;
223b71206888 Initial import
thib
parents:
diff changeset
281 flag <<= 1;
223b71206888 Initial import
thib
parents:
diff changeset
282 len--;
223b71206888 Initial import
thib
parents:
diff changeset
283 }
223b71206888 Initial import
thib
parents:
diff changeset
284 }
223b71206888 Initial import
thib
parents:
diff changeset
285 }
223b71206888 Initial import
thib
parents:
diff changeset
286
223b71206888 Initial import
thib
parents:
diff changeset
287 return true;
223b71206888 Initial import
thib
parents:
diff changeset
288
223b71206888 Initial import
thib
parents:
diff changeset
289 }
223b71206888 Initial import
thib
parents:
diff changeset
290
223b71206888 Initial import
thib
parents:
diff changeset
291 } /* end of namespace XKFont */
223b71206888 Initial import
thib
parents:
diff changeset
292