aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2007-05-31 13:20:11 +0000
committerJason Rumney2007-05-31 13:20:11 +0000
commit040fe91812d6555f06ee67763912fc7d107c1f47 (patch)
tree2b548183838063c381dedcf2718ab8949ecfd60d /src
parent7785759564c5b4e4b04ab0944edd89e21c85b9ba (diff)
downloademacs-040fe91812d6555f06ee67763912fc7d107c1f47.tar.gz
emacs-040fe91812d6555f06ee67763912fc7d107c1f47.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/w32font.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/w32font.c b/src/w32font.c
index 321898dd8d6..0f5f930988c 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -190,7 +190,7 @@ static Lisp_Object w32font_list_family (Lisp_Object frame)
190static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity, 190static 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;
@@ -207,6 +207,11 @@ static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity,
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)
@@ -241,8 +246,9 @@ static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity,
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
@@ -253,7 +259,7 @@ static struct font* w32font_open (FRAME_PTR f, Lisp_Object font_entity,
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;
@@ -450,6 +456,7 @@ static int w32font_text_extents (struct font *font,
450static int w32font_draw (struct glyph_string *s, int from, int to, 456static 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)
@@ -459,7 +466,8 @@ static int w32font_draw (struct glyph_string *s, int from, int to,
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.
@@ -598,11 +606,14 @@ Lisp_Object w32_enumfont_pattern_entity (ENUMLOGFONTEX *logical_font,
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);
@@ -647,6 +658,8 @@ static LONG registry_to_w32_charset (Lisp_Object charset)
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
@@ -658,7 +671,10 @@ static Lisp_Object w32_registry (LONG w32_charset)
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
664static void set_fonts_frame (Lisp_Object fontlist, Lisp_Object frame) 680static void set_fonts_frame (Lisp_Object fontlist, Lisp_Object frame)
@@ -687,14 +703,15 @@ static void fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spe
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
@@ -729,7 +746,10 @@ static void fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spe
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);