diff options
| author | Jason Rumney | 2007-12-08 02:23:57 +0000 |
|---|---|---|
| committer | Jason Rumney | 2007-12-08 02:23:57 +0000 |
| commit | f0121ad2e8f4ce95ee6bc1d08005460c08c7896f (patch) | |
| tree | 87bc8c9f014c13e8fa5f3ed70eec7b54eca0d30b /src | |
| parent | 473d924511a64b2c67537d2507c8b739cf37384f (diff) | |
| download | emacs-f0121ad2e8f4ce95ee6bc1d08005460c08c7896f.tar.gz emacs-f0121ad2e8f4ce95ee6bc1d08005460c08c7896f.zip | |
(w32font_open_internal): New function.
(w32font_open): Use it. Revert to static.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32font.c | 164 |
1 files changed, 90 insertions, 74 deletions
diff --git a/src/w32font.c b/src/w32font.c index 62c8f95d8bc..3a8ad108a51 100644 --- a/src/w32font.c +++ b/src/w32font.c | |||
| @@ -192,94 +192,24 @@ w32font_list_family (frame) | |||
| 192 | /* w32 implementation of open for font backend. | 192 | /* w32 implementation of open for font backend. |
| 193 | Open a font specified by FONT_ENTITY on frame F. | 193 | Open a font specified by FONT_ENTITY on frame F. |
| 194 | If the font is scalable, open it with PIXEL_SIZE. */ | 194 | If the font is scalable, open it with PIXEL_SIZE. */ |
| 195 | struct font * | 195 | static struct font * |
| 196 | w32font_open (f, font_entity, pixel_size) | 196 | w32font_open (f, font_entity, pixel_size) |
| 197 | FRAME_PTR f; | 197 | FRAME_PTR f; |
| 198 | Lisp_Object font_entity; | 198 | Lisp_Object font_entity; |
| 199 | int pixel_size; | 199 | int pixel_size; |
| 200 | { | 200 | { |
| 201 | int len, size; | ||
| 202 | LOGFONT logfont; | ||
| 203 | HDC dc; | ||
| 204 | HFONT hfont, old_font; | ||
| 205 | Lisp_Object val, extra; | ||
| 206 | /* For backwards compatibility. */ | ||
| 207 | W32FontStruct *compat_w32_font; | ||
| 208 | |||
| 209 | struct w32font_info *w32_font = xmalloc (sizeof (struct w32font_info)); | 201 | struct w32font_info *w32_font = xmalloc (sizeof (struct w32font_info)); |
| 210 | 202 | ||
| 211 | struct font * font = (struct font *) w32_font; | 203 | if (w32_font == NULL) |
| 212 | if (!font) | ||
| 213 | return NULL; | 204 | return NULL; |
| 214 | 205 | ||
| 215 | bzero (&logfont, sizeof (logfont)); | 206 | if (!w32font_open_internal (f, font_entity, pixel_size, w32_font)) |
| 216 | fill_in_logfont (f, &logfont, font_entity); | ||
| 217 | |||
| 218 | size = XINT (AREF (font_entity, FONT_SIZE_INDEX)); | ||
| 219 | if (!size) | ||
| 220 | size = pixel_size; | ||
| 221 | |||
| 222 | logfont.lfHeight = -size; | ||
| 223 | hfont = CreateFontIndirect (&logfont); | ||
| 224 | |||
| 225 | if (hfont == NULL) | ||
| 226 | { | 207 | { |
| 227 | xfree (w32_font); | 208 | xfree (w32_font); |
| 228 | return NULL; | 209 | return NULL; |
| 229 | } | 210 | } |
| 230 | 211 | ||
| 231 | w32_font->owning_frame = f; | 212 | return (struct font *) w32_font; |
| 232 | |||
| 233 | /* Get the metrics for this font. */ | ||
| 234 | dc = get_frame_dc (f); | ||
| 235 | old_font = SelectObject (dc, hfont); | ||
| 236 | |||
| 237 | GetTextMetrics (dc, &w32_font->metrics); | ||
| 238 | |||
| 239 | SelectObject (dc, old_font); | ||
| 240 | release_frame_dc (f, dc); | ||
| 241 | /* W32FontStruct - we should get rid of this, and use the w32font_info | ||
| 242 | struct for any W32 specific fields. font->font.font can then be hfont. */ | ||
| 243 | font->font.font = xmalloc (sizeof (W32FontStruct)); | ||
| 244 | compat_w32_font = (W32FontStruct *) font->font.font; | ||
| 245 | bzero (compat_w32_font, sizeof (W32FontStruct)); | ||
| 246 | compat_w32_font->font_type = UNICODE_FONT; | ||
| 247 | /* Duplicate the text metrics. */ | ||
| 248 | bcopy (&w32_font->metrics, &compat_w32_font->tm, sizeof (TEXTMETRIC)); | ||
| 249 | compat_w32_font->hfont = hfont; | ||
| 250 | |||
| 251 | len = strlen (logfont.lfFaceName); | ||
| 252 | font->font.name = (char *) xmalloc (len + 1); | ||
| 253 | bcopy (logfont.lfFaceName, font->font.name, len); | ||
| 254 | font->font.name[len] = '\0'; | ||
| 255 | font->font.full_name = font->font.name; | ||
| 256 | font->font.charset = 0; | ||
| 257 | font->font.codepage = 0; | ||
| 258 | font->font.size = w32_font->metrics.tmMaxCharWidth; | ||
| 259 | font->font.height = w32_font->metrics.tmHeight | ||
| 260 | + w32_font->metrics.tmExternalLeading; | ||
| 261 | font->font.space_width = font->font.average_width | ||
| 262 | = w32_font->metrics.tmAveCharWidth; | ||
| 263 | |||
| 264 | font->font.vertical_centering = 0; | ||
| 265 | font->font.encoding_type = 0; | ||
| 266 | font->font.baseline_offset = 0; | ||
| 267 | font->font.relative_compose = 0; | ||
| 268 | font->font.default_ascent = w32_font->metrics.tmAscent; | ||
| 269 | font->font.font_encoder = NULL; | ||
| 270 | font->entity = font_entity; | ||
| 271 | font->pixel_size = size; | ||
| 272 | font->driver = &w32font_driver; | ||
| 273 | font->format = Qgdi; | ||
| 274 | font->file_name = NULL; | ||
| 275 | font->encoding_charset = -1; | ||
| 276 | font->repertory_charset = -1; | ||
| 277 | font->min_width = 0; | ||
| 278 | font->ascent = w32_font->metrics.tmAscent; | ||
| 279 | font->descent = w32_font->metrics.tmDescent; | ||
| 280 | font->scalable = w32_font->metrics.tmPitchAndFamily & TMPF_VECTOR; | ||
| 281 | |||
| 282 | return font; | ||
| 283 | } | 213 | } |
| 284 | 214 | ||
| 285 | /* w32 implementation of close for font_backend. | 215 | /* w32 implementation of close for font_backend. |
| @@ -685,6 +615,92 @@ w32font_match_internal (frame, font_spec, opentype_only) | |||
| 685 | return NILP (match_data.list) ? Qnil : XCAR (match_data.list); | 615 | return NILP (match_data.list) ? Qnil : XCAR (match_data.list); |
| 686 | } | 616 | } |
| 687 | 617 | ||
| 618 | int | ||
| 619 | w32font_open_internal (f, font_entity, pixel_size, w32_font) | ||
| 620 | FRAME_PTR f; | ||
| 621 | Lisp_Object font_entity; | ||
| 622 | int pixel_size; | ||
| 623 | struct w32font_info *w32_font; | ||
| 624 | { | ||
| 625 | int len, size; | ||
| 626 | LOGFONT logfont; | ||
| 627 | HDC dc; | ||
| 628 | HFONT hfont, old_font; | ||
| 629 | Lisp_Object val, extra; | ||
| 630 | /* For backwards compatibility. */ | ||
| 631 | W32FontStruct *compat_w32_font; | ||
| 632 | |||
| 633 | struct font * font = (struct font *) w32_font; | ||
| 634 | if (!font) | ||
| 635 | return 0; | ||
| 636 | |||
| 637 | bzero (&logfont, sizeof (logfont)); | ||
| 638 | fill_in_logfont (f, &logfont, font_entity); | ||
| 639 | |||
| 640 | size = XINT (AREF (font_entity, FONT_SIZE_INDEX)); | ||
| 641 | if (!size) | ||
| 642 | size = pixel_size; | ||
| 643 | |||
| 644 | logfont.lfHeight = -size; | ||
| 645 | hfont = CreateFontIndirect (&logfont); | ||
| 646 | |||
| 647 | if (hfont == NULL) | ||
| 648 | return 0; | ||
| 649 | |||
| 650 | w32_font->owning_frame = f; | ||
| 651 | |||
| 652 | /* Get the metrics for this font. */ | ||
| 653 | dc = get_frame_dc (f); | ||
| 654 | old_font = SelectObject (dc, hfont); | ||
| 655 | |||
| 656 | GetTextMetrics (dc, &w32_font->metrics); | ||
| 657 | |||
| 658 | SelectObject (dc, old_font); | ||
| 659 | release_frame_dc (f, dc); | ||
| 660 | /* W32FontStruct - we should get rid of this, and use the w32font_info | ||
| 661 | struct for any W32 specific fields. font->font.font can then be hfont. */ | ||
| 662 | font->font.font = xmalloc (sizeof (W32FontStruct)); | ||
| 663 | compat_w32_font = (W32FontStruct *) font->font.font; | ||
| 664 | bzero (compat_w32_font, sizeof (W32FontStruct)); | ||
| 665 | compat_w32_font->font_type = UNICODE_FONT; | ||
| 666 | /* Duplicate the text metrics. */ | ||
| 667 | bcopy (&w32_font->metrics, &compat_w32_font->tm, sizeof (TEXTMETRIC)); | ||
| 668 | compat_w32_font->hfont = hfont; | ||
| 669 | |||
| 670 | len = strlen (logfont.lfFaceName); | ||
| 671 | font->font.name = (char *) xmalloc (len + 1); | ||
| 672 | bcopy (logfont.lfFaceName, font->font.name, len); | ||
| 673 | font->font.name[len] = '\0'; | ||
| 674 | font->font.full_name = font->font.name; | ||
| 675 | font->font.charset = 0; | ||
| 676 | font->font.codepage = 0; | ||
| 677 | font->font.size = w32_font->metrics.tmMaxCharWidth; | ||
| 678 | font->font.height = w32_font->metrics.tmHeight | ||
| 679 | + w32_font->metrics.tmExternalLeading; | ||
| 680 | font->font.space_width = font->font.average_width | ||
| 681 | = w32_font->metrics.tmAveCharWidth; | ||
| 682 | |||
| 683 | font->font.vertical_centering = 0; | ||
| 684 | font->font.encoding_type = 0; | ||
| 685 | font->font.baseline_offset = 0; | ||
| 686 | font->font.relative_compose = 0; | ||
| 687 | font->font.default_ascent = w32_font->metrics.tmAscent; | ||
| 688 | font->font.font_encoder = NULL; | ||
| 689 | font->entity = font_entity; | ||
| 690 | font->pixel_size = size; | ||
| 691 | font->driver = &w32font_driver; | ||
| 692 | font->format = Qgdi; | ||
| 693 | font->file_name = NULL; | ||
| 694 | font->encoding_charset = -1; | ||
| 695 | font->repertory_charset = -1; | ||
| 696 | font->min_width = 0; | ||
| 697 | font->ascent = w32_font->metrics.tmAscent; | ||
| 698 | font->descent = w32_font->metrics.tmDescent; | ||
| 699 | font->scalable = w32_font->metrics.tmPitchAndFamily & TMPF_VECTOR; | ||
| 700 | |||
| 701 | return 1; | ||
| 702 | } | ||
| 703 | |||
| 688 | /* Callback function for EnumFontFamiliesEx. | 704 | /* Callback function for EnumFontFamiliesEx. |
| 689 | * Adds the name of a font to a Lisp list (passed in as the lParam arg). */ | 705 | * Adds the name of a font to a Lisp list (passed in as the lParam arg). */ |
| 690 | static int CALLBACK | 706 | static int CALLBACK |