ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtfont.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.84 by root, Tue Jan 17 05:47:42 2006 UTC vs.
Revision 1.87 by root, Wed Jan 25 21:03:04 2006 UTC

27 27
28#include <cstdlib> 28#include <cstdlib>
29#include <wchar.h> 29#include <wchar.h>
30#include <inttypes.h> 30#include <inttypes.h>
31 31
32#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width
33#define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts
34
35#define OVERLAP_OK(w,prop) (w) > ( \
36 prop->slant >= rxvt_fontprop::italic \
37 ? (prop->width * MAX_OVERLAP_ITALIC + 7) >> 3 \
38 : (prop->width * MAX_OVERLAP_ROMAN + 7) >> 3 \
39 )
33 40
34const struct rxvt_fallback_font { 41const struct rxvt_fallback_font {
35 codeset cs; 42 codeset cs;
36 const char *name; 43 const char *name;
37} fallback_fonts[] = { 44} fallback_fonts[] = {
165} 172}
166 173
167rxvt_drawable::operator XftDraw *() 174rxvt_drawable::operator XftDraw *()
168{ 175{
169 if (!xftdrawable) 176 if (!xftdrawable)
170 xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); 177 xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap);
171 178
172 return xftdrawable; 179 return xftdrawable;
173} 180}
174#endif 181#endif
175 182
176///////////////////////////////////////////////////////////////////////////// 183/////////////////////////////////////////////////////////////////////////////
177
178static void *enc_buf;
179static uint32_t enc_len;
180
181static inline void *
182get_enc_buf (uint32_t len)
183{
184 if (len > enc_len)
185 {
186 free (enc_buf);
187 enc_buf = malloc (len);
188 enc_len = len;
189 }
190
191 return enc_buf;
192}
193 184
194static const char * 185static const char *
195enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 186enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
196{ 187{
197 uint8_t *buf = (uint8_t *)get_enc_buf (len); 188 uint8_t *buf = rxvt_temp_buf<uint8_t> (len);
189 uint8_t *res = buf;
198 190
199 while (len--) 191 while (len--)
200 { 192 {
201 uint32_t c = FROM_UNICODE (cs, *text++); 193 uint32_t c = FROM_UNICODE (cs, *text++);
202 194
207 } 199 }
208 200
209 *buf++ = c; 201 *buf++ = c;
210 } 202 }
211 203
212 return (const char *)enc_buf; 204 return (const char *)res;
213} 205}
214 206
215static const XChar2b * 207static const XChar2b *
216enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) 208enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
217{ 209{
218 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 210 XChar2b *buf = rxvt_temp_buf<XChar2b> (len);
211 XChar2b *res = buf;
219 212
220 while (len--) 213 while (len--)
221 { 214 {
222 uint32_t c = FROM_UNICODE (cs, *text++); 215 uint32_t c = FROM_UNICODE (cs, *text++);
223 216
230 buf->byte1 = c >> 8; 223 buf->byte1 = c >> 8;
231 buf->byte2 = c; 224 buf->byte2 = c;
232 buf++; 225 buf++;
233 } 226 }
234 227
235 return (XChar2b *)enc_buf; 228 return res;
236} 229}
237 230
238///////////////////////////////////////////////////////////////////////////// 231/////////////////////////////////////////////////////////////////////////////
239 232
240void 233void
862 855
863 XCharStruct g; 856 XCharStruct g;
864 int dir_ret, asc_ret, des_ret; 857 int dir_ret, asc_ret, des_ret;
865 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 858 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
866 859
867 int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 860 int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
868 861
869 if (width < g.width) width = g.width; 862 if (width < g.width) width = g.width;
870 } 863 }
871 864
872 if (cs == CS_UNKNOWN) 865 if (cs == CS_UNKNOWN)
945 938
946 if (!prop || prop->width == rxvt_fontprop::unset) 939 if (!prop || prop->width == rxvt_fontprop::unset)
947 return true; 940 return true;
948 941
949 // check character against base font bounding box 942 // check character against base font bounding box
950 int w = xcs->width; 943 int w = xcs->rbearing - xcs->lbearing;
951 int wcw = wcwidth (unicode); 944 int wcw = WCWIDTH (unicode);
952 if (wcw > 0) w = (w + wcw - 1) / wcw; 945 if (wcw > 0) w = (w + wcw - 1) / wcw;
953 946
954 careful = w > prop->width; 947 careful = w > prop->width;
955 if (careful && w > prop->width * MAX_OVERLAP >> 2) 948 if (careful && OVERLAP_OK (w, prop))
956 return false; 949 return false;
957 950
958 return true; 951 return true;
959} 952}
960 953
1190 XGlyphInfo g; 1183 XGlyphInfo g;
1191 XftTextExtents16 (disp, f, &ch, 1, &g); 1184 XftTextExtents16 (disp, f, &ch, 1, &g);
1192 1185
1193 g.width -= g.x; 1186 g.width -= g.x;
1194 1187
1195 int wcw = wcwidth (ch); 1188 int wcw = WCWIDTH (ch);
1196 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 1189 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
1197 1190
1198 if (width < g.width ) width = g.width; 1191 if (width < g.width ) width = g.width;
1199 if (height < g.height ) height = g.height; 1192 if (height < g.height ) height = g.height;
1200 if (glheight < g.height - g.y) glheight = g.height - g.y; 1193 if (glheight < g.height - g.y) glheight = g.height - g.y;
1262 FcChar32 ch = unicode; 1255 FcChar32 ch = unicode;
1263 XGlyphInfo g; 1256 XGlyphInfo g;
1264 XftTextExtents32 (term->display->display, f, &ch, 1, &g); 1257 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1265 1258
1266 int w = g.width - g.x; 1259 int w = g.width - g.x;
1267 int wcw = wcwidth (unicode); 1260 int wcw = WCWIDTH (unicode);
1268 if (wcw > 0) w = (w + wcw - 1) / wcw; 1261 if (wcw > 0) w = (w + wcw - 1) / wcw;
1269 1262
1270 careful = w > prop->width; 1263 careful = w > prop->width;
1271 if (careful && w > prop->width * MAX_OVERLAP >> 2) 1264 if (careful && OVERLAP_OK (w, prop))
1272 return false; 1265 return false;
1273 1266
1274 return true; 1267 return true;
1275} 1268}
1276 1269
1280 int fg, int bg) 1273 int fg, int bg)
1281{ 1274{
1282 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1275 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1283 1276
1284 XGlyphInfo extents; 1277 XGlyphInfo extents;
1285 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); 1278 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1286 XftGlyphSpec *ep = enc; 1279 XftGlyphSpec *ep = enc;
1287 1280
1288 dTermDisplay; 1281 dTermDisplay;
1289 dTermGC; 1282 dTermGC;
1290 1283

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines