diff options
| author | Jason Rumney | 2008-06-26 22:11:25 +0000 |
|---|---|---|
| committer | Jason Rumney | 2008-06-26 22:11:25 +0000 |
| commit | c35f9821de5ec0cf127185890191ad0154600d0d (patch) | |
| tree | 18fc6dbe64578d453a0004a8d7b7c4dc3a94e13c /src | |
| parent | ec06f5c9a0d4fc01c3af9e14add64bb09f977fb6 (diff) | |
| download | emacs-c35f9821de5ec0cf127185890191ad0154600d0d.tar.gz emacs-c35f9821de5ec0cf127185890191ad0154600d0d.zip | |
* w32font.h (FONT_HANDLE, FONT_TEXTMETRIC): New macros.
* w32term.c (x_draw_glyph_string_foreground):
(x_draw_composite_glyph_string_foreground): Sync with xterm.c.
Use FONT_HANDLE macro.
(x_draw_glyph_string): Use FONT_TEXTMETRIC macro.
* w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape):
(uniscribe_encode_char): Use FONT_HANDLE macro.
* w32font.c (Fx_select_font): Use FONT_HANDLE macro.
(w32font_text_extents): Use precast w32_font.
(w32font_close): Free cached metrics.
(w32font_open_internal): Allocate space for name on stack.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 17 | ||||
| -rw-r--r-- | src/w32font.c | 29 | ||||
| -rw-r--r-- | src/w32font.h | 4 | ||||
| -rw-r--r-- | src/w32term.c | 53 | ||||
| -rw-r--r-- | src/w32uniscribe.c | 6 |
5 files changed, 62 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index ac2aa66f321..83b6881b424 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2008-06-26 Jason Rumney <jasonr@gnu.org> | ||
| 2 | |||
| 3 | * w32font.h (FONT_HANDLE, FONT_TEXTMETRIC): New macros. | ||
| 4 | |||
| 5 | * w32term.c (x_draw_glyph_string_foreground): | ||
| 6 | (x_draw_composite_glyph_string_foreground): Sync with xterm.c. | ||
| 7 | Use FONT_HANDLE macro. | ||
| 8 | (x_draw_glyph_string): Use FONT_TEXTMETRIC macro. | ||
| 9 | |||
| 10 | * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape): | ||
| 11 | (uniscribe_encode_char): Use FONT_HANDLE macro. | ||
| 12 | |||
| 13 | * w32font.c (Fx_select_font): Use FONT_HANDLE macro. | ||
| 14 | (w32font_text_extents): Use precast w32_font. | ||
| 15 | (w32font_close): Free cached metrics. | ||
| 16 | (w32font_open_internal): Allocate space for name on stack. | ||
| 17 | |||
| 1 | 2008-06-26 Chong Yidong <cyd@stupidchicken.com> | 18 | 2008-06-26 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 19 | ||
| 3 | * xdisp.c (extend_face_to_end_of_line): Fix last change. | 20 | * xdisp.c (extend_face_to_end_of_line): Fix last change. |
diff --git a/src/w32font.c b/src/w32font.c index 9b261a9da38..bc3340c191f 100644 --- a/src/w32font.c +++ b/src/w32font.c | |||
| @@ -233,8 +233,23 @@ w32font_close (f, font) | |||
| 233 | FRAME_PTR f; | 233 | FRAME_PTR f; |
| 234 | struct font *font; | 234 | struct font *font; |
| 235 | { | 235 | { |
| 236 | int i; | ||
| 236 | struct w32font_info *w32_font = (struct w32font_info *) font; | 237 | struct w32font_info *w32_font = (struct w32font_info *) font; |
| 238 | |||
| 239 | /* Delete the GDI font object. */ | ||
| 237 | DeleteObject (w32_font->hfont); | 240 | DeleteObject (w32_font->hfont); |
| 241 | |||
| 242 | /* Free all the cached metrics. */ | ||
| 243 | if (w32_font->cached_metrics) | ||
| 244 | { | ||
| 245 | for (i = 0; i < w32_font->n_cache_blocks; i++) | ||
| 246 | { | ||
| 247 | if (w32_font->cached_metrics[i]) | ||
| 248 | xfree (w32_font->cached_metrics[i]); | ||
| 249 | } | ||
| 250 | xfree (w32_font->cached_metrics); | ||
| 251 | w32_font->cached_metrics = NULL; | ||
| 252 | } | ||
| 238 | } | 253 | } |
| 239 | 254 | ||
| 240 | /* w32 implementation of has_char for font backend. | 255 | /* w32 implementation of has_char for font backend. |
| @@ -493,8 +508,7 @@ w32font_text_extents (font, code, nglyphs, metrics) | |||
| 493 | { | 508 | { |
| 494 | metrics->width = total_width; | 509 | metrics->width = total_width; |
| 495 | metrics->lbearing = 0; | 510 | metrics->lbearing = 0; |
| 496 | metrics->rbearing = total_width | 511 | metrics->rbearing = total_width + w32_font->metrics.tmOverhang; |
| 497 | + ((struct w32font_info *) font)->metrics.tmOverhang; | ||
| 498 | } | 512 | } |
| 499 | 513 | ||
| 500 | /* Restore state and release DC. */ | 514 | /* Restore state and release DC. */ |
| @@ -831,15 +845,12 @@ w32font_open_internal (f, font_entity, pixel_size, font_object) | |||
| 831 | /* We don't know how much space we need for the full name, so start with | 845 | /* We don't know how much space we need for the full name, so start with |
| 832 | 96 bytes and go up in steps of 32. */ | 846 | 96 bytes and go up in steps of 32. */ |
| 833 | len = 96; | 847 | len = 96; |
| 834 | name = xmalloc (len); | 848 | name = alloca (len); |
| 835 | while (name && w32font_full_name (&logfont, font_entity, pixel_size, | 849 | while (name && w32font_full_name (&logfont, font_entity, pixel_size, |
| 836 | name, len) < 0) | 850 | name, len) < 0) |
| 837 | { | 851 | { |
| 838 | char *new = xrealloc (name, len += 32); | 852 | len += 32; |
| 839 | 853 | name = alloca (len); | |
| 840 | if (! new) | ||
| 841 | xfree (name); | ||
| 842 | name = new; | ||
| 843 | } | 854 | } |
| 844 | if (name) | 855 | if (name) |
| 845 | font->props[FONT_FULLNAME_INDEX] | 856 | font->props[FONT_FULLNAME_INDEX] |
| @@ -2048,7 +2059,7 @@ in the font selection dialog. */) | |||
| 2048 | /* Initialize as much of the font details as we can from the current | 2059 | /* Initialize as much of the font details as we can from the current |
| 2049 | default font. */ | 2060 | default font. */ |
| 2050 | hdc = GetDC (FRAME_W32_WINDOW (f)); | 2061 | hdc = GetDC (FRAME_W32_WINDOW (f)); |
| 2051 | oldobj = SelectObject (hdc, ((struct w32font_info *) FRAME_FONT (f))->hfont); | 2062 | oldobj = SelectObject (hdc, FONT_HANDLE (FRAME_FONT (f))); |
| 2052 | GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName); | 2063 | GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName); |
| 2053 | if (GetTextMetrics (hdc, &tm)) | 2064 | if (GetTextMetrics (hdc, &tm)) |
| 2054 | { | 2065 | { |
diff --git a/src/w32font.h b/src/w32font.h index 30b6ed34271..25cf4ece560 100644 --- a/src/w32font.h +++ b/src/w32font.h | |||
| @@ -56,6 +56,10 @@ struct w32font_info | |||
| 56 | HFONT hfont; | 56 | HFONT hfont; |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | /* Macros for getting OS specific information from a font struct. */ | ||
| 60 | #define FONT_HANDLE(f) (((struct w32font_info *)(f))->hfont) | ||
| 61 | #define FONT_TEXTMETRIC(f) (((struct w32font_info *)(f))->metrics) | ||
| 62 | |||
| 59 | #define CACHE_BLOCKSIZE 128 | 63 | #define CACHE_BLOCKSIZE 128 |
| 60 | 64 | ||
| 61 | Lisp_Object w32font_get_cache P_ ((FRAME_PTR fe)); | 65 | Lisp_Object w32font_get_cache P_ ((FRAME_PTR fe)); |
diff --git a/src/w32term.c b/src/w32term.c index 57662051302..28861eea902 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -1237,8 +1237,6 @@ x_draw_glyph_string_foreground (s) | |||
| 1237 | struct glyph_string *s; | 1237 | struct glyph_string *s; |
| 1238 | { | 1238 | { |
| 1239 | int i, x; | 1239 | int i, x; |
| 1240 | struct w32font_info * w32_font; | ||
| 1241 | HFONT old_font; | ||
| 1242 | 1240 | ||
| 1243 | /* If first glyph of S has a left box line, start drawing the text | 1241 | /* If first glyph of S has a left box line, start drawing the text |
| 1244 | of S to the right of that box line. */ | 1242 | of S to the right of that box line. */ |
| @@ -1248,21 +1246,10 @@ x_draw_glyph_string_foreground (s) | |||
| 1248 | else | 1246 | else |
| 1249 | x = s->x; | 1247 | x = s->x; |
| 1250 | 1248 | ||
| 1251 | if (s->for_overlaps || (s->background_filled_p && s->hl != DRAW_CURSOR) | ||
| 1252 | || cleartype_active) | ||
| 1253 | SetBkMode (s->hdc, TRANSPARENT); | ||
| 1254 | else | ||
| 1255 | SetBkMode (s->hdc, OPAQUE); | ||
| 1256 | |||
| 1257 | SetTextColor (s->hdc, s->gc->foreground); | 1249 | SetTextColor (s->hdc, s->gc->foreground); |
| 1258 | SetBkColor (s->hdc, s->gc->background); | 1250 | SetBkColor (s->hdc, s->gc->background); |
| 1259 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | 1251 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); |
| 1260 | 1252 | ||
| 1261 | w32_font = (struct w32font_info *) s->font; | ||
| 1262 | |||
| 1263 | if (w32_font && w32_font->hfont) | ||
| 1264 | old_font = SelectObject (s->hdc, w32_font->hfont); | ||
| 1265 | |||
| 1266 | /* Draw characters of S as rectangles if S's font could not be | 1253 | /* Draw characters of S as rectangles if S's font could not be |
| 1267 | loaded. */ | 1254 | loaded. */ |
| 1268 | if (s->font_not_found_p) | 1255 | if (s->font_not_found_p) |
| @@ -1278,24 +1265,27 @@ x_draw_glyph_string_foreground (s) | |||
| 1278 | } | 1265 | } |
| 1279 | else | 1266 | else |
| 1280 | { | 1267 | { |
| 1281 | int boff = s->font->baseline_offset; | 1268 | struct font *font = s->font; |
| 1269 | int boff = font->baseline_offset; | ||
| 1282 | int y; | 1270 | int y; |
| 1271 | HFONT old_font; | ||
| 1272 | |||
| 1273 | old_font = SelectObject (s->hdc, FONT_HANDLE (font)); | ||
| 1283 | 1274 | ||
| 1284 | if (s->font->vertical_centering) | 1275 | if (font->vertical_centering) |
| 1285 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | 1276 | boff = VCENTER_BASELINE_OFFSET (font, s->f) - boff; |
| 1286 | 1277 | ||
| 1287 | y = s->ybase - boff; | 1278 | y = s->ybase - boff; |
| 1288 | if (s->for_overlaps | 1279 | if (s->for_overlaps |
| 1289 | || (s->background_filled_p && s->hl != DRAW_CURSOR)) | 1280 | || (s->background_filled_p && s->hl != DRAW_CURSOR)) |
| 1290 | s->font->driver->draw (s, 0, s->nchars, x, y, 0); | 1281 | font->driver->draw (s, 0, s->nchars, x, y, 0); |
| 1291 | else | 1282 | else |
| 1292 | s->font->driver->draw (s, 0, s->nchars, x, y, 1); | 1283 | font->driver->draw (s, 0, s->nchars, x, y, 1); |
| 1293 | if (s->face->overstrike) | 1284 | if (s->face->overstrike) |
| 1294 | s->font->driver->draw (s, 0, s->nchars, x + 1, y, 0); | 1285 | font->driver->draw (s, 0, s->nchars, x + 1, y, 0); |
| 1295 | } | ||
| 1296 | 1286 | ||
| 1297 | if (w32_font && w32_font->hfont) | 1287 | SelectObject (s->hdc, old_font); |
| 1298 | SelectObject (s->hdc, old_font); | 1288 | } |
| 1299 | } | 1289 | } |
| 1300 | 1290 | ||
| 1301 | /* Draw the foreground of composite glyph string S. */ | 1291 | /* Draw the foreground of composite glyph string S. */ |
| @@ -1305,8 +1295,6 @@ x_draw_composite_glyph_string_foreground (s) | |||
| 1305 | struct glyph_string *s; | 1295 | struct glyph_string *s; |
| 1306 | { | 1296 | { |
| 1307 | int i, j, x; | 1297 | int i, j, x; |
| 1308 | HFONT old_font; | ||
| 1309 | struct w32font_info * w32_font; | ||
| 1310 | 1298 | ||
| 1311 | /* If first glyph of S has a left box line, start drawing the text | 1299 | /* If first glyph of S has a left box line, start drawing the text |
| 1312 | of S to the right of that box line. */ | 1300 | of S to the right of that box line. */ |
| @@ -1323,14 +1311,8 @@ x_draw_composite_glyph_string_foreground (s) | |||
| 1323 | 1311 | ||
| 1324 | SetTextColor (s->hdc, s->gc->foreground); | 1312 | SetTextColor (s->hdc, s->gc->foreground); |
| 1325 | SetBkColor (s->hdc, s->gc->background); | 1313 | SetBkColor (s->hdc, s->gc->background); |
| 1326 | SetBkMode (s->hdc, TRANSPARENT); | ||
| 1327 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); | 1314 | SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT); |
| 1328 | 1315 | ||
| 1329 | w32_font = (struct w32font_info *) s->font; | ||
| 1330 | |||
| 1331 | if (w32_font && w32_font->hfont) | ||
| 1332 | old_font = SelectObject (s->hdc, w32_font->hfont); | ||
| 1333 | |||
| 1334 | /* Draw a rectangle for the composition if the font for the very | 1316 | /* Draw a rectangle for the composition if the font for the very |
| 1335 | first character of the composition could not be loaded. */ | 1317 | first character of the composition could not be loaded. */ |
| 1336 | if (s->font_not_found_p) | 1318 | if (s->font_not_found_p) |
| @@ -1339,11 +1321,14 @@ x_draw_composite_glyph_string_foreground (s) | |||
| 1339 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, | 1321 | w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1, |
| 1340 | s->height - 1); | 1322 | s->height - 1); |
| 1341 | } | 1323 | } |
| 1342 | 1324 | else | |
| 1343 | { | 1325 | { |
| 1344 | struct font *font = s->font; | 1326 | struct font *font = s->font; |
| 1345 | int y = s->ybase; | 1327 | int y = s->ybase; |
| 1346 | int width = 0; | 1328 | int width = 0; |
| 1329 | HFONT old_font; | ||
| 1330 | |||
| 1331 | old_font = SelectObject (s->hdc, FONT_HANDLE (font)); | ||
| 1347 | 1332 | ||
| 1348 | if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING) | 1333 | if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING) |
| 1349 | { | 1334 | { |
| @@ -1393,10 +1378,8 @@ x_draw_composite_glyph_string_foreground (s) | |||
| 1393 | font->driver->draw (s, j, j + 1, xx + 1, yy, 0); | 1378 | font->driver->draw (s, j, j + 1, xx + 1, yy, 0); |
| 1394 | } | 1379 | } |
| 1395 | } | 1380 | } |
| 1381 | SelectObject (s->hdc, old_font); | ||
| 1396 | } | 1382 | } |
| 1397 | |||
| 1398 | if (w32_font && w32_font->hfont) | ||
| 1399 | SelectObject (s->hdc, old_font); | ||
| 1400 | } | 1383 | } |
| 1401 | 1384 | ||
| 1402 | 1385 | ||
| @@ -2345,7 +2328,7 @@ x_draw_glyph_string (s) | |||
| 2345 | 2328 | ||
| 2346 | /* Draw strike-through. */ | 2329 | /* Draw strike-through. */ |
| 2347 | if (s->face->strike_through_p | 2330 | if (s->face->strike_through_p |
| 2348 | && !((struct w32font_info *) s->font)->metrics.tmStruckOut) | 2331 | && !FONT_TEXTMETRIC(s->font).tmStruckOut) |
| 2349 | { | 2332 | { |
| 2350 | unsigned long h = 1; | 2333 | unsigned long h = 1; |
| 2351 | unsigned long dy = (s->height - h) / 2; | 2334 | unsigned long dy = (s->height - h) / 2; |
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c index 494abef74db..366287e8de6 100644 --- a/src/w32uniscribe.c +++ b/src/w32uniscribe.c | |||
| @@ -166,7 +166,7 @@ uniscribe_otf_capability (font) | |||
| 166 | 166 | ||
| 167 | f = XFRAME (selected_frame); | 167 | f = XFRAME (selected_frame); |
| 168 | context = get_frame_dc (f); | 168 | context = get_frame_dc (f); |
| 169 | old_font = SelectObject (context, ((struct w32font_info *) font)->hfont); | 169 | old_font = SelectObject (context, FONT_HANDLE(font)); |
| 170 | 170 | ||
| 171 | features = otf_features (context, "GSUB"); | 171 | features = otf_features (context, "GSUB"); |
| 172 | XSETCAR (capability, features); | 172 | XSETCAR (capability, features); |
| @@ -259,7 +259,7 @@ uniscribe_shape (lgstring) | |||
| 259 | 259 | ||
| 260 | f = XFRAME (selected_frame); | 260 | f = XFRAME (selected_frame); |
| 261 | context = get_frame_dc (f); | 261 | context = get_frame_dc (f); |
| 262 | old_font = SelectObject (context, uniscribe_font->w32_font.hfont); | 262 | old_font = SelectObject (context, FONT_HANDLE(font)); |
| 263 | 263 | ||
| 264 | glyphs = alloca (max_glyphs * sizeof (WORD)); | 264 | glyphs = alloca (max_glyphs * sizeof (WORD)); |
| 265 | clusters = alloca (nchars * sizeof (WORD)); | 265 | clusters = alloca (nchars * sizeof (WORD)); |
| @@ -424,7 +424,7 @@ uniscribe_encode_char (font, c) | |||
| 424 | /* Use selected frame until API is updated to pass the frame. */ | 424 | /* Use selected frame until API is updated to pass the frame. */ |
| 425 | f = XFRAME (selected_frame); | 425 | f = XFRAME (selected_frame); |
| 426 | context = get_frame_dc (f); | 426 | context = get_frame_dc (f); |
| 427 | old_font = SelectObject (context, ((struct w32font_info *) font)->hfont); | 427 | old_font = SelectObject (context, FONT_HANDLE(font)); |
| 428 | 428 | ||
| 429 | retval = GetGlyphIndicesW (context, chars, 1, indices, | 429 | retval = GetGlyphIndicesW (context, chars, 1, indices, |
| 430 | GGI_MARK_NONEXISTING_GLYPHS); | 430 | GGI_MARK_NONEXISTING_GLYPHS); |