Mercurial > emacs
comparison src/w32font.c @ 90879:82b86c925f88
* w32font.c (w32font_open): Handle size, height and pixel_size better.
(w32font_draw): Use options.
(w32_enumfont_pattern_entity): Set size to 0 for scalable fonts.
Fix detection of truetype fonts.
(registry_to_w32_charset): Handle charsets other than iso8859-1
expressed as lisp symbols.
(w32_registry): Express charset as lisp symbol.
(fill_in_logfont): Reverse pixel and point height logic.
Don't set width here. Set quality to default.
* w32font.c: New file for w32 font backend.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Thu, 31 May 2007 13:20:11 +0000 |
parents | 9a1ccf2dfd96 |
children | aa7f1d212e78 |
comparison
equal
deleted
inserted
replaced
90878:efe9a1312ac6 | 90879:82b86c925f88 |
---|---|
188 Open a font specified by FONT_ENTITY on frame F. | 188 Open a font specified by FONT_ENTITY on frame F. |
189 If the font is scalable, open it with PIXEL_SIZE. */ | 189 If the font is scalable, open it with PIXEL_SIZE. */ |
190 static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity, | 190 static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity, |
191 int pixel_size) | 191 int pixel_size) |
192 { | 192 { |
193 int len; | 193 int len, size; |
194 LOGFONT logfont; | 194 LOGFONT logfont; |
195 HDC dc; | 195 HDC dc; |
196 HFONT hfont, old_font; | 196 HFONT hfont, old_font; |
197 Lisp_Object val; | 197 Lisp_Object val; |
198 /* For backwards compatibility. */ | 198 /* For backwards compatibility. */ |
205 return NULL; | 205 return NULL; |
206 | 206 |
207 bzero (&logfont, sizeof (logfont)); | 207 bzero (&logfont, sizeof (logfont)); |
208 fill_in_logfont (f, &logfont, font_entity); | 208 fill_in_logfont (f, &logfont, font_entity); |
209 | 209 |
210 size = XINT (AREF (font_entity, FONT_SIZE_INDEX)); | |
211 if (size == 0) | |
212 size = pixel_size; | |
213 | |
214 logfont.lfHeight = size; | |
210 hfont = CreateFontIndirect (&logfont); | 215 hfont = CreateFontIndirect (&logfont); |
211 | 216 |
212 if (hfont == NULL) | 217 if (hfont == NULL) |
213 { | 218 { |
214 xfree (w32_font); | 219 xfree (w32_font); |
239 bcopy (logfont.lfFaceName, font->font.name, len); | 244 bcopy (logfont.lfFaceName, font->font.name, len); |
240 font->font.name[len] = '\0'; | 245 font->font.name[len] = '\0'; |
241 font->font.full_name = font->font.name; | 246 font->font.full_name = font->font.name; |
242 font->font.charset = 0; | 247 font->font.charset = 0; |
243 font->font.codepage = 0; | 248 font->font.codepage = 0; |
244 font->font.size = logfont.lfWidth; | 249 font->font.size = w32_font->metrics.tmMaxCharWidth; |
245 font->font.height = w32_font->metrics.tmHeight; | 250 font->font.height = w32_font->metrics.tmHeight |
251 + w32_font->metrics.tmExternalLeading; | |
246 font->font.space_width = font->font.average_width | 252 font->font.space_width = font->font.average_width |
247 = w32_font->metrics.tmAveCharWidth; | 253 = w32_font->metrics.tmAveCharWidth; |
248 | 254 |
249 font->font.vertical_centering = 0; | 255 font->font.vertical_centering = 0; |
250 font->font.encoding_type = 0; | 256 font->font.encoding_type = 0; |
251 font->font.baseline_offset = 0; | 257 font->font.baseline_offset = 0; |
252 font->font.relative_compose = 0; | 258 font->font.relative_compose = 0; |
253 font->font.default_ascent = w32_font->metrics.tmAscent; | 259 font->font.default_ascent = w32_font->metrics.tmAscent; |
254 font->font.font_encoder = NULL; | 260 font->font.font_encoder = NULL; |
255 font->entity = font_entity; | 261 font->entity = font_entity; |
256 font->pixel_size = pixel_size; | 262 font->pixel_size = size; |
257 font->driver = &w32font_driver; | 263 font->driver = &w32font_driver; |
258 font->format = Qw32; | 264 font->format = Qw32; |
259 font->file_name = NULL; | 265 font->file_name = NULL; |
260 font->encoding_charset = -1; | 266 font->encoding_charset = -1; |
261 font->repertory_charset = -1; | 267 font->repertory_charset = -1; |
448 is nonzero, fill the background in advance. It is assured that | 454 is nonzero, fill the background in advance. It is assured that |
449 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ | 455 WITH_BACKGROUND is zero when (FROM > 0 || TO < S->nchars). */ |
450 static int w32font_draw (struct glyph_string *s, int from, int to, | 456 static int w32font_draw (struct glyph_string *s, int from, int to, |
451 int x, int y, int with_background) | 457 int x, int y, int with_background) |
452 { | 458 { |
459 /* TODO: Do we need to specify ETO_GLYPH_INDEX or is char2b always utf-16? */ | |
453 UINT options = 0; | 460 UINT options = 0; |
454 | 461 |
455 if (with_background) | 462 if (with_background) |
456 { | 463 { |
457 options = ETO_OPAQUE; | 464 options = ETO_OPAQUE; |
458 SetBkColor (s->hdc, s->gc->background); | 465 SetBkColor (s->hdc, s->gc->background); |
459 } | 466 } |
460 else | 467 else |
461 SetBkMode (s->hdc, TRANSPARENT); | 468 SetBkMode (s->hdc, TRANSPARENT); |
462 ExtTextOutW (s->hdc, x, y, 0, NULL, s->char2b + from, to - from + 1, NULL); | 469 |
470 ExtTextOutW (s->hdc, x, y, options, NULL, s->char2b + from, to - from, NULL); | |
463 } | 471 } |
464 | 472 |
465 /* w32 implementation of free_entity for font backend. | 473 /* w32 implementation of free_entity for font backend. |
466 Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). | 474 Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). |
467 Free FONT_EXTRA_INDEX field of FONT_ENTITY. | 475 Free FONT_EXTRA_INDEX field of FONT_ENTITY. |
596 ASET (entity, FONT_WEIGHT_INDEX, make_number (lf->lfWeight)); | 604 ASET (entity, FONT_WEIGHT_INDEX, make_number (lf->lfWeight)); |
597 ASET (entity, FONT_SLANT_INDEX, make_number (lf->lfItalic ? 200 : 100)); | 605 ASET (entity, FONT_SLANT_INDEX, make_number (lf->lfItalic ? 200 : 100)); |
598 ASET (entity, FONT_WIDTH_INDEX, | 606 ASET (entity, FONT_WIDTH_INDEX, |
599 make_number (physical_font->ntmTm.tmAveCharWidth)); | 607 make_number (physical_font->ntmTm.tmAveCharWidth)); |
600 | 608 |
601 ASET (entity, FONT_SIZE_INDEX, make_number (abs (lf->lfHeight))); | 609 if (font_type & RASTER_FONTTYPE) |
610 ASET (entity, FONT_SIZE_INDEX, make_number (physical_font->ntmTm.tmHeight)); | |
611 else | |
612 ASET (entity, FONT_SIZE_INDEX, make_number (0)); | |
602 | 613 |
603 /* Cache unicode codepoints covered by this font, as there is no other way | 614 /* Cache unicode codepoints covered by this font, as there is no other way |
604 of getting this information easily. */ | 615 of getting this information easily. */ |
605 if (font_type == TRUETYPE_FONTTYPE) | 616 if (font_type & TRUETYPE_FONTTYPE) |
606 { | 617 { |
607 DWORD *subranges = xmalloc(16); | 618 DWORD *subranges = xmalloc(16); |
608 memcpy (subranges, physical_font->ntmFontSig.fsUsb, 16); | 619 memcpy (subranges, physical_font->ntmFontSig.fsUsb, 16); |
609 ASET (entity, FONT_EXTRA_INDEX, make_save_value (subranges, 0)); | 620 ASET (entity, FONT_EXTRA_INDEX, make_save_value (subranges, 0)); |
610 } | 621 } |
645 if (EQ (charset, Qiso10646_1) || EQ (charset, Qunicode_bmp) | 656 if (EQ (charset, Qiso10646_1) || EQ (charset, Qunicode_bmp) |
646 || EQ (charset, Qunicode_sip)) | 657 || EQ (charset, Qunicode_sip)) |
647 return DEFAULT_CHARSET; /* UNICODE_CHARSET not defined in MingW32 */ | 658 return DEFAULT_CHARSET; /* UNICODE_CHARSET not defined in MingW32 */ |
648 else if (EQ (charset, Qiso8859_1)) | 659 else if (EQ (charset, Qiso8859_1)) |
649 return ANSI_CHARSET; | 660 return ANSI_CHARSET; |
661 else if (SYMBOLP (charset)) | |
662 return x_to_w32_charset (SDATA (SYMBOL_NAME (charset))); | |
650 else if (STRINGP (charset)) | 663 else if (STRINGP (charset)) |
651 return x_to_w32_charset (SDATA (charset)); | 664 return x_to_w32_charset (SDATA (charset)); |
652 else | 665 else |
653 return DEFAULT_CHARSET; | 666 return DEFAULT_CHARSET; |
654 } | 667 } |
656 static Lisp_Object w32_registry (LONG w32_charset) | 669 static Lisp_Object w32_registry (LONG w32_charset) |
657 { | 670 { |
658 if (w32_charset == ANSI_CHARSET) | 671 if (w32_charset == ANSI_CHARSET) |
659 return Qiso8859_1; | 672 return Qiso8859_1; |
660 else | 673 else |
661 return build_string (w32_to_x_charset (w32_charset, NULL)); | 674 { |
675 char * charset = w32_to_x_charset (w32_charset, NULL); | |
676 return intern_downcase (charset, strlen(charset)); | |
677 } | |
662 } | 678 } |
663 | 679 |
664 static void set_fonts_frame (Lisp_Object fontlist, Lisp_Object frame) | 680 static void set_fonts_frame (Lisp_Object fontlist, Lisp_Object frame) |
665 { | 681 { |
666 if (VECTORP (fontlist)) | 682 if (VECTORP (fontlist)) |
685 /* TODO: Allow user to override dpi settings. */ | 701 /* TODO: Allow user to override dpi settings. */ |
686 | 702 |
687 /* Height */ | 703 /* Height */ |
688 tmp = AREF (font_spec, FONT_SIZE_INDEX); | 704 tmp = AREF (font_spec, FONT_SIZE_INDEX); |
689 if (INTEGERP (tmp)) | 705 if (INTEGERP (tmp)) |
690 logfont->lfHeight = -1 * dpi / 720 * XINT (tmp); | 706 logfont->lfHeight = -1 * XINT (tmp); |
691 else if (FLOATP (tmp)) | 707 else if (FLOATP (tmp)) |
692 logfont->lfHeight = -1 * (int) XFLOAT(tmp); | 708 logfont->lfHeight = (int) (-1.0 * dpi * XFLOAT_DATA (tmp) / 72.0); |
693 | 709 |
694 /* Width */ | 710 /* Width TODO: makes fonts look distorted. |
695 tmp = AREF (font_spec, FONT_WIDTH_INDEX); | 711 tmp = AREF (font_spec, FONT_WIDTH_INDEX); |
696 if (INTEGERP (tmp)) | 712 if (INTEGERP (tmp)) |
697 logfont->lfWidth = XINT (tmp); | 713 logfont->lfWidth = XINT (tmp); |
714 */ | |
698 | 715 |
699 /* Escapement */ | 716 /* Escapement */ |
700 | 717 |
701 /* Orientation */ | 718 /* Orientation */ |
702 | 719 |
727 logfont->lfCharSet = registry_to_w32_charset (tmp); | 744 logfont->lfCharSet = registry_to_w32_charset (tmp); |
728 } | 745 } |
729 | 746 |
730 /* Out Precision */ | 747 /* Out Precision */ |
731 /* Clip Precision */ | 748 /* Clip Precision */ |
732 /* Quality */ | 749 /* Quality TODO: Allow different quality to be specified, so user |
750 can enable/disable anti-aliasing for individual fonts. */ | |
751 logfont->lfQuality = DEFAULT_QUALITY; | |
752 | |
733 /* Pitch and Family */ | 753 /* Pitch and Family */ |
734 /* Facename TODO: handle generic names */ | 754 /* Facename TODO: handle generic names */ |
735 tmp = AREF (font_spec, FONT_FAMILY_INDEX); | 755 tmp = AREF (font_spec, FONT_FAMILY_INDEX); |
736 /* Font families are interned */ | 756 /* Font families are interned */ |
737 if (SYMBOLP (tmp)) | 757 if (SYMBOLP (tmp)) |