annotate font/font_peer_ft2.cc @ 71:1fd20d231376

Fix objScale with 2D zoom; implement objWidth and objHeight.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 01 Apr 2011 23:49:12 +0200
parents 4416cfac86ae
children
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 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
44 FT_Library super;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
45 int ref_count;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
46 char **paths;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
47 int num_paths;
0
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
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 0
diff changeset
52 static const char *default_paths[] = {
0
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
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
67 static int font_library_ft2_alloc()
0
223b71206888 Initial import
thib
parents:
diff changeset
68 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
69 int i;
0
223b71206888 Initial import
thib
parents:
diff changeset
70
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
71 if (!library) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
72 library = (FontLibrary*) calloc(sizeof(FontLibrary), 1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
73 if (library) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
74 if (FT_Init_FreeType(&library->super)) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
75 free(library);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
76 library = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
77 fprintf(stderr, "XKFont::font_library_ft2_alloc: Couldn't allocate FreeType.\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
78 return 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
79 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
80 fprintf(stderr, "XKFont::font_library_ft2_alloc : FreeType allocated successfully.\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
81 for (i = 0; default_paths[i]; i++)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
82 font_library_ft2_add_path(default_paths[i]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
83 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
84 }
0
223b71206888 Initial import
thib
parents:
diff changeset
85
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
86 library->ref_count++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
87 return 1;
0
223b71206888 Initial import
thib
parents:
diff changeset
88 }
223b71206888 Initial import
thib
parents:
diff changeset
89
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
90 static void font_library_ft2_free()
0
223b71206888 Initial import
thib
parents:
diff changeset
91 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
92 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
93
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
94 if (!library || library->ref_count <= 0)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
95 return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
96 if (--library->ref_count == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
97 FT_Done_FreeType(library->super);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
98 for (i = 0; i < library->num_paths; i++)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
99 free(library->paths[i]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
100 free(library->paths);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
101 free(library);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
102 library = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
103 fprintf(stderr, "XKFont::font_library_ft2_free : FreeType done.\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
104 }
0
223b71206888 Initial import
thib
parents:
diff changeset
105 }
223b71206888 Initial import
thib
parents:
diff changeset
106
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
107 static void font_library_ft2_add_path(const char *path)
0
223b71206888 Initial import
thib
parents:
diff changeset
108 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
109 library->num_paths++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
110 if (!library->paths)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
111 library->paths = (char**) malloc(sizeof(char *));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
112 else
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
113 library->paths = (char**) realloc( (void*)library->paths, library->num_paths * sizeof(char *));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
114 library->paths[library->num_paths - 1] = strdup(path);
0
223b71206888 Initial import
thib
parents:
diff changeset
115 }
223b71206888 Initial import
thib
parents:
diff changeset
116
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
117 static void font_library_ft2_remove_path(const char *path)
0
223b71206888 Initial import
thib
parents:
diff changeset
118 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
119 int i, j;
0
223b71206888 Initial import
thib
parents:
diff changeset
120
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
121 for (i = 0; i < library->num_paths; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
122 if (!strcmp(path, library->paths[i])) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
123 library->num_paths--;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
124 for (j = i; j < library->num_paths; j++)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
125 library->paths[j] = library->paths[j + 1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
126 if (library->num_paths > 0)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
127 library->paths = (char**) realloc(library->paths, library->num_paths * sizeof(char *));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
128 else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
129 free(library->paths);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
130 library->paths = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
131 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
132 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
133 }
0
223b71206888 Initial import
thib
parents:
diff changeset
134 }
223b71206888 Initial import
thib
parents:
diff changeset
135
223b71206888 Initial import
thib
parents:
diff changeset
136 typedef struct _FontEncoding {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
137 FT_UShort platform_id;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
138 FT_Encoding encoding;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
139 FontCodeConverter conv_func;
0
223b71206888 Initial import
thib
parents:
diff changeset
140 } FontEncoding;
223b71206888 Initial import
thib
parents:
diff changeset
141
223b71206888 Initial import
thib
parents:
diff changeset
142 static FontEncoding encodings[] = {
223b71206888 Initial import
thib
parents:
diff changeset
143 { 3, (FT_Encoding)ft_encoding_unicode, codeconv_euc_to_unicode },
223b71206888 Initial import
thib
parents:
diff changeset
144 { 3, (FT_Encoding)ft_encoding_sjis, codeconv_euc_to_sjis },
223b71206888 Initial import
thib
parents:
diff changeset
145 { 1, (FT_Encoding)ft_encoding_apple_roman, codeconv_euc_to_latin1 },
223b71206888 Initial import
thib
parents:
diff changeset
146 { (FT_UShort)-1, (FT_Encoding)-1, NULL }
223b71206888 Initial import
thib
parents:
diff changeset
147 };
223b71206888 Initial import
thib
parents:
diff changeset
148
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
149 static char * font_library_ft2_build_path(const char *base, const char *name)
0
223b71206888 Initial import
thib
parents:
diff changeset
150 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
151 char *path;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
152 const char *strs[] = { base, "/", name, NULL };
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
153 int i = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
154
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
155 path = (char*) calloc(sizeof(char), strlen(base) + strlen(name) + 2);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
156 if (path)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
157 while (strs[i])
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
158 strcat(path, strs[i++]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
159
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
160 return path;
0
223b71206888 Initial import
thib
parents:
diff changeset
161 }
223b71206888 Initial import
thib
parents:
diff changeset
162
223b71206888 Initial import
thib
parents:
diff changeset
163 PeerFt2::PeerFt2(const char *name, int index, int hsize, int vsize)
223b71206888 Initial import
thib
parents:
diff changeset
164 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
165 int i,j;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
166
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
167 font_library_ft2_alloc();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
168
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
169 for (i = 0; i < library->num_paths; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
170 char *path = font_library_ft2_build_path(library->paths[i], name);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
171 if (path) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
172 if (FT_New_Face(library->super, path, index, &face))
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
173 face = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
174 free(path);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
175 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
176 if (face) break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
177 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
178
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
179 if (!face) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
180 string err = string("XKFont::PeerFt2::PeerFt : Cannot open font(TrueType) : ")+name;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
181 throw std::invalid_argument(err);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
182 }
0
223b71206888 Initial import
thib
parents:
diff changeset
183
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
184 conv_func = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
185 for (i=0; encodings[i].conv_func != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
186 FT_UShort platform_id = encodings[i].platform_id;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
187 FT_Encoding encoding = encodings[i].encoding;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
188 for (j = 0; j < face->num_charmaps; j++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
189 FT_CharMap cmap = face->charmaps[j];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
190 if (cmap->platform_id == platform_id && cmap->encoding == encoding) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
191 if (FT_Set_Charmap(face, cmap) == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
192 conv_func = encodings[i].conv_func;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
193 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
194 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
195 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
196 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
197 if (conv_func) break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
198 }
0
223b71206888 Initial import
thib
parents:
diff changeset
199
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
200 if (conv_func == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
201 FT_Done_Face(face);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
202 fprintf(stderr,"cannot find charmap\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
203 string err = string("XKFont::PeerFt2::PeerFt : No supported code converter of font (TrueType) ")+name;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
204 throw std::invalid_argument(err);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
205 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
206
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
207 FT_Set_Pixel_Sizes(face, hsize, vsize);
0
223b71206888 Initial import
thib
parents:
diff changeset
208 }
223b71206888 Initial import
thib
parents:
diff changeset
209
223b71206888 Initial import
thib
parents:
diff changeset
210 PeerFt2::~PeerFt2() {
223b71206888 Initial import
thib
parents:
diff changeset
211 FT_Done_Face(face);
223b71206888 Initial import
thib
parents:
diff changeset
212 font_library_ft2_free();
223b71206888 Initial import
thib
parents:
diff changeset
213 }
223b71206888 Initial import
thib
parents:
diff changeset
214
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
215 bool PeerFt2::GlyphCreate(unsigned int code, Glyph* glyph)
0
223b71206888 Initial import
thib
parents:
diff changeset
216 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
217 FT_GlyphSlot slot;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
218 FT_UInt index;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
219 int bmsize;
0
223b71206888 Initial import
thib
parents:
diff changeset
220
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
221 if (face == 0) return false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
222 code = conv_func(code);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
223 if (code == 0) return false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
224 index = FT_Get_Char_Index(face, code);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
225 if (index == 0) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
226
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
227 /* Don't consider error */
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
228 slot = face->glyph;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
229 if (slot) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
230 // if (! FT_Load_Glyph(face, index, FT_LOAD_DEFAULT)) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
231 // BITMAP だと なぜか render してくれない……
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
232 // LOAD_DEFAULT でも、下に対応コードを付けたので一応は大丈夫
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
233 if (! FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP))
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
234 FT_Render_Glyph(slot, ft_render_mode_normal);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
235 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
236
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
237 glyph->bitmap_left = slot->bitmap_left;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
238 glyph->bitmap_top = slot->bitmap_top;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
239 glyph->bitmap.width = slot->bitmap.width;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
240 glyph->bitmap.rows = slot->bitmap.rows;
0
223b71206888 Initial import
thib
parents:
diff changeset
241
223b71206888 Initial import
thib
parents:
diff changeset
242 /*
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
243 glyph->metrics.ascender = private->face->size->metrics.ascender >> 6;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
244 glyph->metrics.descender = private->face->size->metrics.descender >> 6;
0
223b71206888 Initial import
thib
parents:
diff changeset
245 */
223b71206888 Initial import
thib
parents:
diff changeset
246
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
247 glyph->advance.x = slot->advance.x >> 6;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
248 glyph->advance.y = slot->advance.y >> 6;
0
223b71206888 Initial import
thib
parents:
diff changeset
249
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
250 bmsize = glyph->bitmap.width * glyph->bitmap.rows;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
251 if (bmsize > 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
252 glyph->bitmap.buffer = new unsigned char[bmsize];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
253 memcpy(glyph->bitmap.buffer, slot->bitmap.buffer, bmsize);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
254 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
255 // なぜか Render したのに MONO なことがある……
0
223b71206888 Initial import
thib
parents:
diff changeset
256 /* for freetype < 2.1.3, use ``ft_pixel_mode_mono'' */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
257 if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
258 int i, j;
0
223b71206888 Initial import
thib
parents:
diff changeset
259 // if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {int i,j;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
260 char* d = (char*)slot->bitmap.buffer;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
261 for (i=0; i < glyph->bitmap.rows; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
262 int flag = *d++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
263 int len = 8;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
264 unsigned char* buf = glyph->bitmap.buffer + i*slot->bitmap.width;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
265 for (j=0; j < glyph->bitmap.width; j++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
266 if (len == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
267 flag = *d++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
268 len = 8;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
269 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
270 if (flag & 0x80) *buf++ = 0xff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
271 else *buf++ = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
272 flag <<= 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
273 len--;
0
223b71206888 Initial import
thib
parents:
diff changeset
274 }
223b71206888 Initial import
thib
parents:
diff changeset
275 }
223b71206888 Initial import
thib
parents:
diff changeset
276 }
223b71206888 Initial import
thib
parents:
diff changeset
277
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
278 return true;
0
223b71206888 Initial import
thib
parents:
diff changeset
279 }
223b71206888 Initial import
thib
parents:
diff changeset
280
223b71206888 Initial import
thib
parents:
diff changeset
281 } /* end of namespace XKFont */
223b71206888 Initial import
thib
parents:
diff changeset
282