aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2008-05-14 01:02:08 +0000
committerKenichi Handa2008-05-14 01:02:08 +0000
commit5f18d119cea1d372871ad74af985bff15a1bd4ba (patch)
tree7af8dc9761df1a66ba7d3ebf9a50f2849d5c1f6e /src
parent3af8ab1dc000a71160783f01deb8ed10db49b213 (diff)
downloademacs-5f18d119cea1d372871ad74af985bff15a1bd4ba.tar.gz
emacs-5f18d119cea1d372871ad74af985bff15a1bd4ba.zip
Throughout the file, delete all USE_FONT_BACKEND
conditionals. Don't check enable_font_backend. Delete all codes used only when USE_FONT_BACKEND is not defined. (w32font_open): Return a font-object. Make a font-object by font_make_object. Adjusted for the change of struct w32font_info. (w32font_close): Don't free struct font. Adjusted for the change of struct w32font_info. (w32font_encode_char, w32font_text_extents, w32font_draw): Adjusted for the change of struct w32font_info. (w32font_draw): Likewise. (w32font_list_internal): Return a list, not vector. (w32font_open_internal): Change the 4th arg to font-object. Adjusted for the change of struct w32font_info and font-object format. (add_font_name_to_list): Don't downcase names. (w32_enumfont_pattern_entity): Make a font-entity by font_make_entity. Adjusted for the format change of font-entity. Use FONT_SET_STYLE to set a style-related font property. If a font is scalable, set avgwidth property to 0. Set font-entity property by font_put_extra. (font_matches_spec): Adjusted for the format change of font-entity. (w32_weight_table, w32_decode_weight): New variables. (w32_encode_weight): New function. (fill_in_logfont): Adjusted for the format change of font-spec. (w32font_full_name): Use FONT_WEIGHT_SYMBOLIC to get a symbol weight value. (w32font_driver): Adjusted for the change of struct font_driver. (w32font_open_internal): Change last argument from w32font_info struct to font object. Fill in font object from font_entity. Get Outline metrics if possible. Use them to calculate underline position and thickness. Use xlfd name as name property. Don't set codepage. (w32font_open): Pass font_object to w32font_open_internal. Don't update dpyinfo->smallest_font_height and dpyinfo->smallest_char_width. (w32font_draw): Use s->font. (clear_cached_metrics): Don't clear non-existent blocks.
Diffstat (limited to 'src')
-rw-r--r--src/w32font.c377
1 files changed, 202 insertions, 175 deletions
diff --git a/src/w32font.c b/src/w32font.c
index ed53ff9c4b1..3b6e05419ff 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -18,8 +18,6 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19Boston, MA 02110-1301, USA. */ 19Boston, MA 02110-1301, USA. */
20 20
21#ifdef USE_FONT_BACKEND
22
23#include <config.h> 21#include <config.h>
24#include <windows.h> 22#include <windows.h>
25#include <math.h> 23#include <math.h>
@@ -55,7 +53,7 @@ static Lisp_Object Qserif, Qscript, Qdecorative;
55static Lisp_Object Qraster, Qoutline, Qunknown; 53static Lisp_Object Qraster, Qoutline, Qunknown;
56 54
57/* antialiasing */ 55/* antialiasing */
58extern Lisp_Object QCantialias, QCotf, QClanguage; /* defined in font.c */ 56extern Lisp_Object QCantialias, QCotf, QClang; /* defined in font.c */
59extern Lisp_Object Qnone; /* reuse from w32fns.c */ 57extern Lisp_Object Qnone; /* reuse from w32fns.c */
60static Lisp_Object Qstandard, Qsubpixel, Qnatural; 58static Lisp_Object Qstandard, Qsubpixel, Qnatural;
61 59
@@ -206,24 +204,22 @@ w32font_list_family (frame)
206/* w32 implementation of open for font backend. 204/* w32 implementation of open for font backend.
207 Open a font specified by FONT_ENTITY on frame F. 205 Open a font specified by FONT_ENTITY on frame F.
208 If the font is scalable, open it with PIXEL_SIZE. */ 206 If the font is scalable, open it with PIXEL_SIZE. */
209static struct font * 207static Lisp_Object
210w32font_open (f, font_entity, pixel_size) 208w32font_open (f, font_entity, pixel_size)
211 FRAME_PTR f; 209 FRAME_PTR f;
212 Lisp_Object font_entity; 210 Lisp_Object font_entity;
213 int pixel_size; 211 int pixel_size;
214{ 212{
215 struct w32font_info *w32_font = xmalloc (sizeof (struct w32font_info)); 213 Lisp_Object font_object;
216 214
217 if (w32_font == NULL) 215 font_object = font_make_object (VECSIZE (struct w32font_info));
218 return NULL;
219 216
220 if (!w32font_open_internal (f, font_entity, pixel_size, w32_font)) 217 if (!w32font_open_internal (f, font_entity, pixel_size, font_object))
221 { 218 {
222 xfree (w32_font); 219 return Qnil;
223 return NULL;
224 } 220 }
225 221
226 return (struct font *) w32_font; 222 return font_object;
227} 223}
228 224
229/* w32 implementation of close for font_backend. 225/* w32 implementation of close for font_backend.
@@ -233,21 +229,15 @@ w32font_close (f, font)
233 FRAME_PTR f; 229 FRAME_PTR f;
234 struct font *font; 230 struct font *font;
235{ 231{
236 if (font->font.font) 232 struct w32font_info *w32_font = (struct w32font_info *) font;
233
234 if (w32_font->compat_w32_font)
237 { 235 {
238 W32FontStruct *old_w32_font = (W32FontStruct *)font->font.font; 236 W32FontStruct *old_w32_font = w32_font->compat_w32_font;
239 DeleteObject (old_w32_font->hfont); 237 DeleteObject (old_w32_font->hfont);
240 xfree (old_w32_font); 238 xfree (old_w32_font);
241 font->font.font = 0; 239 w32_font->compat_w32_font = 0;
242 } 240 }
243
244 if (font->font.full_name && font->font.full_name != font->font.name)
245 xfree (font->font.full_name);
246
247 if (font->font.name)
248 xfree (font->font.name);
249
250 xfree (font);
251} 241}
252 242
253/* w32 implementation of has_char for font backend. 243/* w32 implementation of has_char for font backend.
@@ -320,7 +310,7 @@ w32font_encode_char (font, c)
320 f = XFRAME (selected_frame); 310 f = XFRAME (selected_frame);
321 311
322 dc = get_frame_dc (f); 312 dc = get_frame_dc (f);
323 old_font = SelectObject (dc, ((W32FontStruct *) (font->font.font))->hfont); 313 old_font = SelectObject (dc, w32_font->compat_w32_font->hfont);
324 314
325 retval = GetCharacterPlacementW (dc, in, len, 0, &result, 0); 315 retval = GetCharacterPlacementW (dc, in, len, 0, &result, 0);
326 316
@@ -419,8 +409,7 @@ w32font_text_extents (font, code, nglyphs, metrics)
419 f = XFRAME (selected_frame); 409 f = XFRAME (selected_frame);
420 410
421 dc = get_frame_dc (f); 411 dc = get_frame_dc (f);
422 old_font = SelectObject (dc, ((W32FontStruct *) 412 old_font = SelectObject (dc, FONT_COMPAT (font)->hfont);
423 (font->font.font))->hfont);
424 } 413 }
425 compute_metrics (dc, w32_font, *(code + i), char_metric); 414 compute_metrics (dc, w32_font, *(code + i), char_metric);
426 } 415 }
@@ -477,8 +466,7 @@ w32font_text_extents (font, code, nglyphs, metrics)
477 f = XFRAME (selected_frame); 466 f = XFRAME (selected_frame);
478 467
479 dc = get_frame_dc (f); 468 dc = get_frame_dc (f);
480 old_font = SelectObject (dc, ((W32FontStruct *) 469 old_font = SelectObject (dc, FONT_COMPAT (font)->hfont);
481 (font->font.font))->hfont);
482 } 470 }
483 471
484 if (GetTextExtentPoint32W (dc, wcode, nglyphs, &size)) 472 if (GetTextExtentPoint32W (dc, wcode, nglyphs, &size))
@@ -491,7 +479,7 @@ w32font_text_extents (font, code, nglyphs, metrics)
491 if (!total_width) 479 if (!total_width)
492 { 480 {
493 RECT rect; 481 RECT rect;
494 rect.top = 0; rect.bottom = font->font.height; rect.left = 0; rect.right = 1; 482 rect.top = 0; rect.bottom = font->height; rect.left = 0; rect.right = 1;
495 DrawTextW (dc, wcode, nglyphs, &rect, 483 DrawTextW (dc, wcode, nglyphs, &rect,
496 DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE); 484 DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE);
497 total_width = rect.right; 485 total_width = rect.right;
@@ -533,7 +521,7 @@ w32font_draw (s, from, to, x, y, with_background)
533{ 521{
534 UINT options; 522 UINT options;
535 HRGN orig_clip; 523 HRGN orig_clip;
536 struct w32font_info *w32font = (struct w32font_info *) s->face->font_info; 524 struct w32font_info *w32font = (struct w32font_info *) s->font;
537 525
538 options = w32font->glyph_idx; 526 options = w32font->glyph_idx;
539 527
@@ -563,7 +551,7 @@ w32font_draw (s, from, to, x, y, with_background)
563 { 551 {
564 HBRUSH brush; 552 HBRUSH brush;
565 RECT rect; 553 RECT rect;
566 struct font *font = (struct font *) s->face->font_info; 554 struct font *font = s->font;
567 555
568 brush = CreateSolidBrush (s->gc->background); 556 brush = CreateSolidBrush (s->gc->background);
569 rect.left = x; 557 rect.left = x;
@@ -719,7 +707,7 @@ w32font_list_internal (frame, font_spec, opentype_only)
719 release_frame_dc (f, dc); 707 release_frame_dc (f, dc);
720 } 708 }
721 709
722 return NILP (match_data.list) ? null_vector : Fvconcat (1, &match_data.list); 710 return NILP (match_data.list) ? Qnil : match_data.list;
723} 711}
724 712
725/* Internal implementation of w32font_match. 713/* Internal implementation of w32font_match.
@@ -756,24 +744,34 @@ w32font_match_internal (frame, font_spec, opentype_only)
756} 744}
757 745
758int 746int
759w32font_open_internal (f, font_entity, pixel_size, w32_font) 747w32font_open_internal (f, font_entity, pixel_size, font_object)
760 FRAME_PTR f; 748 FRAME_PTR f;
761 Lisp_Object font_entity; 749 Lisp_Object font_entity;
762 int pixel_size; 750 int pixel_size;
763 struct w32font_info *w32_font; 751 Lisp_Object font_object;
764{ 752{
765 int len, size; 753 int len, size, i;
766 LOGFONT logfont; 754 LOGFONT logfont;
767 HDC dc; 755 HDC dc;
768 HFONT hfont, old_font; 756 HFONT hfont, old_font;
769 Lisp_Object val, extra; 757 Lisp_Object val, extra;
770 /* For backwards compatibility. */ 758 /* For backwards compatibility. */
771 W32FontStruct *compat_w32_font; 759 W32FontStruct *compat_w32_font;
760 struct w32font_info *w32_font;
761 struct font * font;
762 OUTLINETEXTMETRIC* metrics = NULL;
763
764 w32_font = (struct w32font_info *) XFONT_OBJECT (font_object);
765 font = (struct font *) w32_font;
772 766
773 struct font * font = (struct font *) w32_font;
774 if (!font) 767 if (!font)
775 return 0; 768 return 0;
776 769
770 /* Copy from font entity. */
771 for (i = 0; i < FONT_ENTITY_MAX; i++)
772 ASET (font_object, i, AREF (font_entity, i));
773 ASET (font_object, FONT_SIZE_INDEX, make_number (pixel_size));
774
777 bzero (&logfont, sizeof (logfont)); 775 bzero (&logfont, sizeof (logfont));
778 fill_in_logfont (f, &logfont, font_entity); 776 fill_in_logfont (f, &logfont, font_entity);
779 777
@@ -791,7 +789,19 @@ w32font_open_internal (f, font_entity, pixel_size, w32_font)
791 dc = get_frame_dc (f); 789 dc = get_frame_dc (f);
792 old_font = SelectObject (dc, hfont); 790 old_font = SelectObject (dc, hfont);
793 791
794 GetTextMetrics (dc, &w32_font->metrics); 792 /* Try getting the outline metrics (only works for truetype fonts). */
793 len = GetOutlineTextMetrics (dc, 0, NULL);
794 if (len)
795 {
796 metrics = (OUTLINETEXTMETRIC *) alloca (len);
797 if (GetOutlineTextMetrics (dc, len, metrics))
798 bcopy (&metrics->otmTextMetrics, &w32_font->metrics,
799 sizeof (TEXTMETRIC));
800 else
801 metrics = NULL;
802 }
803 if (!metrics)
804 GetTextMetrics (dc, &w32_font->metrics);
795 805
796 w32_font->glyph_idx = ETO_GLYPH_INDEX; 806 w32_font->glyph_idx = ETO_GLYPH_INDEX;
797 807
@@ -803,19 +813,14 @@ w32font_open_internal (f, font_entity, pixel_size, w32_font)
803 813
804 /* W32FontStruct - we should get rid of this, and use the w32font_info 814 /* W32FontStruct - we should get rid of this, and use the w32font_info
805 struct for any W32 specific fields. font->font.font can then be hfont. */ 815 struct for any W32 specific fields. font->font.font can then be hfont. */
806 font->font.font = xmalloc (sizeof (W32FontStruct)); 816 w32_font->compat_w32_font = xmalloc (sizeof (W32FontStruct));
807 compat_w32_font = (W32FontStruct *) font->font.font; 817 compat_w32_font = w32_font->compat_w32_font;
808 bzero (compat_w32_font, sizeof (W32FontStruct)); 818 bzero (compat_w32_font, sizeof (W32FontStruct));
809 compat_w32_font->font_type = UNICODE_FONT; 819 compat_w32_font->font_type = UNICODE_FONT;
810 /* Duplicate the text metrics. */ 820 /* Duplicate the text metrics. */
811 bcopy (&w32_font->metrics, &compat_w32_font->tm, sizeof (TEXTMETRIC)); 821 bcopy (&w32_font->metrics, &compat_w32_font->tm, sizeof (TEXTMETRIC));
812 compat_w32_font->hfont = hfont; 822 compat_w32_font->hfont = hfont;
813 823
814 len = strlen (logfont.lfFaceName);
815 font->font.name = (char *) xmalloc (len + 1);
816 bcopy (logfont.lfFaceName, font->font.name, len);
817 font->font.name[len] = '\0';
818
819 { 824 {
820 char *name; 825 char *name;
821 826
@@ -833,25 +838,24 @@ w32font_open_internal (f, font_entity, pixel_size, w32_font)
833 name = new; 838 name = new;
834 } 839 }
835 if (name) 840 if (name)
836 font->font.full_name = name; 841 font->props[FONT_FULLNAME_INDEX]
842 = make_unibyte_string (name, strlen (name));
837 else 843 else
838 font->font.full_name = font->font.name; 844 font->props[FONT_FULLNAME_INDEX] =
845 make_unibyte_string (logfont.lfFaceName, len);
839 } 846 }
840 font->font.charset = 0; 847
841 font->font.codepage = 0; 848 font->max_width = w32_font->metrics.tmMaxCharWidth;
842 font->font.size = w32_font->metrics.tmMaxCharWidth; 849 font->height = w32_font->metrics.tmHeight
843 font->font.height = w32_font->metrics.tmHeight
844 + w32_font->metrics.tmExternalLeading; 850 + w32_font->metrics.tmExternalLeading;
845 font->font.space_width = font->font.average_width 851 font->space_width = font->average_width = w32_font->metrics.tmAveCharWidth;
846 = w32_font->metrics.tmAveCharWidth; 852
847 853 font->vertical_centering = 0;
848 font->font.vertical_centering = 0; 854 font->encoding_type = 0;
849 font->font.encoding_type = 0; 855 font->baseline_offset = 0;
850 font->font.baseline_offset = 0; 856 font->relative_compose = 0;
851 font->font.relative_compose = 0; 857 font->default_ascent = w32_font->metrics.tmAscent;
852 font->font.default_ascent = w32_font->metrics.tmAscent; 858 font->font_encoder = NULL;
853 font->font.font_encoder = NULL;
854 font->entity = font_entity;
855 font->pixel_size = size; 859 font->pixel_size = size;
856 font->driver = &w32font_driver; 860 font->driver = &w32font_driver;
857 /* Use format cached during list, as the information we have access to 861 /* Use format cached during list, as the information we have access to
@@ -861,55 +865,42 @@ w32font_open_internal (f, font_entity, pixel_size, w32_font)
861 { 865 {
862 val = assq_no_quit (QCformat, extra); 866 val = assq_no_quit (QCformat, extra);
863 if (CONSP (val)) 867 if (CONSP (val))
864 font->format = XCDR (val); 868 font->props[FONT_FORMAT_INDEX] = XCDR (val);
865 else 869 else
866 font->format = Qunknown; 870 font->props[FONT_FORMAT_INDEX] = Qunknown;
867 } 871 }
868 else 872 else
869 font->format = Qunknown; 873 font->props[FONT_FORMAT_INDEX] = Qunknown;
870 874
871 font->file_name = NULL; 875 font->props[FONT_FILE_INDEX] = Qnil;
872 font->encoding_charset = -1; 876 font->encoding_charset = -1;
873 font->repertory_charset = -1; 877 font->repertory_charset = -1;
874 /* TODO: do we really want the minimum width here, which could be negative? */ 878 /* TODO: do we really want the minimum width here, which could be negative? */
875 font->min_width = font->font.space_width; 879 font->min_width = font->space_width;
876 font->ascent = w32_font->metrics.tmAscent; 880 font->ascent = w32_font->metrics.tmAscent;
877 font->descent = w32_font->metrics.tmDescent; 881 font->descent = w32_font->metrics.tmDescent;
878 font->scalable = w32_font->metrics.tmPitchAndFamily & TMPF_VECTOR; 882
883 if (metrics)
884 {
885 font->underline_thickness = metrics->otmsUnderscoreSize;
886 font->underline_position = -metrics->otmsUnderscorePosition;
887 }
888 else
889 {
890 font->underline_thickness = 0;
891 font->underline_position = -1;
892 }
879 893
880 /* max_descent is used for underlining in w32term.c. Hopefully this 894 /* max_descent is used for underlining in w32term.c. Hopefully this
881 is temporary, as we'll want to get rid of the old compatibility 895 is temporary, as we'll want to get rid of the old compatibility
882 stuff later. */ 896 stuff later. */
883 compat_w32_font->max_bounds.descent = font->descent; 897 compat_w32_font->max_bounds.descent = font->descent;
884 898
885 /* Set global flag fonts_changed_p to non-zero if the font loaded 899 /* For temporary compatibility with legacy code that expects the
886 has a character with a smaller width than any other character 900 name to be usable in x-list-fonts. Eventually we expect to change
887 before, or if the font loaded has a smaller height than any other 901 x-list-fonts and other places that use fonts so that this can be
888 font loaded before. If this happens, it will make a glyph matrix 902 an fcname or similar. */
889 reallocation necessary. */ 903 font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object);
890 {
891 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
892 dpyinfo->n_fonts++;
893
894 if (dpyinfo->n_fonts == 1)
895 {
896 dpyinfo->smallest_font_height = font->font.height;
897 dpyinfo->smallest_char_width = font->min_width;
898 }
899 else
900 {
901 if (dpyinfo->smallest_font_height > font->font.height)
902 {
903 dpyinfo->smallest_font_height = font->font.height;
904 fonts_changed_p |= 1;
905 }
906 if (dpyinfo->smallest_char_width > font->min_width)
907 {
908 dpyinfo->smallest_char_width = font->min_width;
909 fonts_changed_p |= 1;
910 }
911 }
912 }
913 904
914 return 1; 905 return 1;
915} 906}
@@ -930,14 +921,17 @@ add_font_name_to_list (logical_font, physical_font, font_type, list_object)
930 if (logical_font->elfLogFont.lfFaceName[0] == '@') 921 if (logical_font->elfLogFont.lfFaceName[0] == '@')
931 return 1; 922 return 1;
932 923
933 family = intern_downcase (logical_font->elfLogFont.lfFaceName, 924 family = font_intern_prop (logical_font->elfLogFont.lfFaceName,
934 strlen (logical_font->elfLogFont.lfFaceName)); 925 strlen (logical_font->elfLogFont.lfFaceName));
935 if (! memq_no_quit (family, *list)) 926 if (! memq_no_quit (family, *list))
936 *list = Fcons (family, *list); 927 *list = Fcons (family, *list);
937 928
938 return 1; 929 return 1;
939} 930}
940 931
932static int w32_decode_weight P_ ((int));
933static int w32_encode_weight P_ ((int));
934
941/* Convert an enumerated Windows font to an Emacs font entity. */ 935/* Convert an enumerated Windows font to an Emacs font entity. */
942static Lisp_Object 936static Lisp_Object
943w32_enumfont_pattern_entity (frame, logical_font, physical_font, 937w32_enumfont_pattern_entity (frame, logical_font, physical_font,
@@ -954,16 +948,15 @@ w32_enumfont_pattern_entity (frame, logical_font, physical_font,
954 BYTE generic_type; 948 BYTE generic_type;
955 DWORD full_type = physical_font->ntmTm.ntmFlags; 949 DWORD full_type = physical_font->ntmTm.ntmFlags;
956 950
957 entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil); 951 entity = font_make_entity ();
958 952
959 ASET (entity, FONT_TYPE_INDEX, backend); 953 ASET (entity, FONT_TYPE_INDEX, backend);
960 ASET (entity, FONT_FRAME_INDEX, frame);
961 ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet, font_type)); 954 ASET (entity, FONT_REGISTRY_INDEX, w32_registry (lf->lfCharSet, font_type));
962 ASET (entity, FONT_OBJLIST_INDEX, Qnil); 955 ASET (entity, FONT_OBJLIST_INDEX, Qnil);
963 956
964 /* Foundry is difficult to get in readable form on Windows. 957 /* Foundry is difficult to get in readable form on Windows.
965 But Emacs crashes if it is not set, so set it to something more 958 But Emacs crashes if it is not set, so set it to something more
966 generic. Thes values make xflds compatible with Emacs 22. */ 959 generic. These values make xflds compatible with Emacs 22. */
967 if (lf->lfOutPrecision == OUT_STRING_PRECIS) 960 if (lf->lfOutPrecision == OUT_STRING_PRECIS)
968 tem = Qraster; 961 tem = Qraster;
969 else if (lf->lfOutPrecision == OUT_STROKE_PRECIS) 962 else if (lf->lfOutPrecision == OUT_STROKE_PRECIS)
@@ -987,14 +980,14 @@ w32_enumfont_pattern_entity (frame, logical_font, physical_font,
987 else if (generic_type == FF_SWISS) 980 else if (generic_type == FF_SWISS)
988 tem = Qsans; 981 tem = Qsans;
989 else 982 else
990 tem = null_string; 983 tem = Qnil;
991 984
992 ASET (entity, FONT_ADSTYLE_INDEX, tem); 985 ASET (entity, FONT_ADSTYLE_INDEX, tem);
993 986
994 if (physical_font->ntmTm.tmPitchAndFamily & 0x01) 987 if (physical_font->ntmTm.tmPitchAndFamily & 0x01)
995 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_PROPORTIONAL)); 988 ASET (entity, FONT_SPACING_INDEX, make_number (FONT_SPACING_PROPORTIONAL));
996 else 989 else
997 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_MONO)); 990 ASET (entity, FONT_SPACING_INDEX, make_number (FONT_SPACING_MONO));
998 991
999 if (requested_font->lfQuality != DEFAULT_QUALITY) 992 if (requested_font->lfQuality != DEFAULT_QUALITY)
1000 { 993 {
@@ -1002,13 +995,15 @@ w32_enumfont_pattern_entity (frame, logical_font, physical_font,
1002 lispy_antialias_type (requested_font->lfQuality)); 995 lispy_antialias_type (requested_font->lfQuality));
1003 } 996 }
1004 ASET (entity, FONT_FAMILY_INDEX, 997 ASET (entity, FONT_FAMILY_INDEX,
1005 intern_downcase (lf->lfFaceName, strlen (lf->lfFaceName))); 998 font_intern_prop (lf->lfFaceName, strlen (lf->lfFaceName)));
1006 999
1007 ASET (entity, FONT_WEIGHT_INDEX, make_number (lf->lfWeight)); 1000 FONT_SET_STYLE (entity, FONT_WEIGHT_INDEX,
1008 ASET (entity, FONT_SLANT_INDEX, make_number (lf->lfItalic ? 200 : 100)); 1001 make_number (w32_decode_weight (lf->lfWeight)));
1002 FONT_SET_STYLE (entity, FONT_SLANT_INDEX,
1003 make_number (lf->lfItalic ? 200 : 100));
1009 /* TODO: PANOSE struct has this info, but need to call GetOutlineTextMetrics 1004 /* TODO: PANOSE struct has this info, but need to call GetOutlineTextMetrics
1010 to get it. */ 1005 to get it. */
1011 ASET (entity, FONT_WIDTH_INDEX, make_number (100)); 1006 FONT_SET_STYLE (entity, FONT_WIDTH_INDEX, make_number (100));
1012 1007
1013 if (font_type & RASTER_FONTTYPE) 1008 if (font_type & RASTER_FONTTYPE)
1014 ASET (entity, FONT_SIZE_INDEX, make_number (physical_font->ntmTm.tmHeight)); 1009 ASET (entity, FONT_SIZE_INDEX, make_number (physical_font->ntmTm.tmHeight));
@@ -1098,14 +1093,14 @@ font_matches_spec (type, font, spec, backend, logfont)
1098 1093
1099 /* Check italic. Can't check logfonts, since it is a boolean field, 1094 /* Check italic. Can't check logfonts, since it is a boolean field,
1100 so there is no difference between "non-italic" and "don't care". */ 1095 so there is no difference between "non-italic" and "don't care". */
1101 val = AREF (spec, FONT_SLANT_INDEX); 1096 {
1102 if (INTEGERP (val)) 1097 int slant = FONT_SLANT_NUMERIC (spec);
1103 { 1098
1104 int slant = XINT (val); 1099 if (slant >= 0
1105 if ((slant > 150 && !font->ntmTm.tmItalic) 1100 && ((slant > 150 && !font->ntmTm.tmItalic)
1106 || (slant <= 150 && font->ntmTm.tmItalic)) 1101 || (slant <= 150 && font->ntmTm.tmItalic)))
1107 return 0; 1102 return 0;
1108 } 1103 }
1109 1104
1110 /* Check adstyle against generic family. */ 1105 /* Check adstyle against generic family. */
1111 val = AREF (spec, FONT_ADSTYLE_INDEX); 1106 val = AREF (spec, FONT_ADSTYLE_INDEX);
@@ -1117,6 +1112,18 @@ font_matches_spec (type, font, spec, backend, logfont)
1117 return 0; 1112 return 0;
1118 } 1113 }
1119 1114
1115 /* Check spacing */
1116 val = AREF (spec, FONT_SPACING_INDEX);
1117 if (INTEGERP (val))
1118 {
1119 int spacing = XINT (val);
1120 int proportional = (spacing < FONT_SPACING_MONO);
1121
1122 if ((proportional && !(font->ntmTm.tmPitchAndFamily & 0x01))
1123 || (!proportional && (font->ntmTm.tmPitchAndFamily & 0x01)))
1124 return 0;
1125 }
1126
1120 /* Check extra parameters. */ 1127 /* Check extra parameters. */
1121 for (extra = AREF (spec, FONT_EXTRA_INDEX); 1128 for (extra = AREF (spec, FONT_EXTRA_INDEX);
1122 CONSP (extra); extra = XCDR (extra)) 1129 CONSP (extra); extra = XCDR (extra))
@@ -1126,27 +1133,9 @@ font_matches_spec (type, font, spec, backend, logfont)
1126 if (CONSP (extra_entry)) 1133 if (CONSP (extra_entry))
1127 { 1134 {
1128 Lisp_Object key = XCAR (extra_entry); 1135 Lisp_Object key = XCAR (extra_entry);
1129 val = XCDR (extra_entry);
1130 if (EQ (key, QCspacing))
1131 {
1132 int proportional;
1133 if (INTEGERP (val))
1134 {
1135 int spacing = XINT (val);
1136 proportional = (spacing < FONT_SPACING_MONO);
1137 }
1138 else if (EQ (val, Qp))
1139 proportional = 1;
1140 else if (EQ (val, Qc) || EQ (val, Qm))
1141 proportional = 0;
1142 else
1143 return 0; /* Bad font spec. */
1144 1136
1145 if ((proportional && !(font->ntmTm.tmPitchAndFamily & 0x01)) 1137 val = XCDR (extra_entry);
1146 || (!proportional && (font->ntmTm.tmPitchAndFamily & 0x01))) 1138 if (EQ (key, QCscript) && SYMBOLP (val))
1147 return 0;
1148 }
1149 else if (EQ (key, QCscript) && SYMBOLP (val))
1150 { 1139 {
1151 /* Only truetype fonts will have information about what 1140 /* Only truetype fonts will have information about what
1152 scripts they support. This probably means the user 1141 scripts they support. This probably means the user
@@ -1234,7 +1223,7 @@ font_matches_spec (type, font, spec, backend, logfont)
1234 return 0; 1223 return 0;
1235 } 1224 }
1236 } 1225 }
1237 else if (EQ (key, QClanguage) && SYMBOLP (val)) 1226 else if (EQ (key, QClang) && SYMBOLP (val))
1238 { 1227 {
1239 /* Just handle the CJK languages here, as the language 1228 /* Just handle the CJK languages here, as the language
1240 parameter is used to select a font with appropriate 1229 parameter is used to select a font with appropriate
@@ -1401,10 +1390,55 @@ w32_registry (w32_charset, font_type)
1401 else 1390 else
1402 { 1391 {
1403 char * charset = w32_to_x_charset (w32_charset, NULL); 1392 char * charset = w32_to_x_charset (w32_charset, NULL);
1404 return intern_downcase (charset, strlen(charset)); 1393 return font_intern_prop (charset, strlen(charset));
1405 } 1394 }
1406} 1395}
1407 1396
1397static struct
1398{
1399 unsigned w32_numeric;
1400 unsigned numeric;
1401} w32_weight_table[] =
1402 { { FW_THIN, 0 },
1403 { FW_EXTRALIGHT, 40 },
1404 { FW_LIGHT, 50},
1405 { FW_NORMAL, 100},
1406 { FW_MEDIUM, 100},
1407 { FW_SEMIBOLD, 180},
1408 { FW_BOLD, 200},
1409 { FW_EXTRABOLD, 205},
1410 { FW_HEAVY, 210} };
1411
1412static int
1413w32_decode_weight (fnweight)
1414 int fnweight;
1415{
1416 if (fnweight >= FW_HEAVY) return 210;
1417 if (fnweight >= FW_EXTRABOLD) return 205;
1418 if (fnweight >= FW_BOLD) return 200;
1419 if (fnweight >= FW_SEMIBOLD) return 180;
1420 if (fnweight >= FW_NORMAL) return 100;
1421 if (fnweight >= FW_LIGHT) return 50;
1422 if (fnweight >= FW_EXTRALIGHT) return 40;
1423 if (fnweight > FW_THIN) return 20;
1424 return 0;
1425}
1426
1427static int
1428w32_encode_weight (n)
1429 int n;
1430{
1431 if (n >= 210) return FW_HEAVY;
1432 if (n >= 205) return FW_EXTRABOLD;
1433 if (n >= 200) return FW_BOLD;
1434 if (n >= 180) return FW_SEMIBOLD;
1435 if (n >= 100) return FW_NORMAL;
1436 if (n >= 50) return FW_LIGHT;
1437 if (n >= 40) return FW_EXTRALIGHT;
1438 if (n >= 20) return FW_THIN;
1439 return 0;
1440}
1441
1408/* Fill in all the available details of LOGFONT from FONT_SPEC. */ 1442/* Fill in all the available details of LOGFONT from FONT_SPEC. */
1409static void 1443static void
1410fill_in_logfont (f, logfont, font_spec) 1444fill_in_logfont (f, logfont, font_spec)
@@ -1415,19 +1449,14 @@ fill_in_logfont (f, logfont, font_spec)
1415 Lisp_Object tmp, extra; 1449 Lisp_Object tmp, extra;
1416 int dpi = FRAME_W32_DISPLAY_INFO (f)->resy; 1450 int dpi = FRAME_W32_DISPLAY_INFO (f)->resy;
1417 1451
1418 extra = AREF (font_spec, FONT_EXTRA_INDEX); 1452 tmp = AREF (font_spec, FONT_DPI_INDEX);
1419 /* Allow user to override dpi settings. */ 1453 if (INTEGERP (tmp))
1420 if (CONSP (extra))
1421 { 1454 {
1422 tmp = assq_no_quit (QCdpi, extra); 1455 dpi = XINT (tmp);
1423 if (CONSP (tmp) && INTEGERP (XCDR (tmp))) 1456 }
1424 { 1457 else if (FLOATP (tmp))
1425 dpi = XINT (XCDR (tmp)); 1458 {
1426 } 1459 dpi = (int) (XFLOAT_DATA (tmp) + 0.5);
1427 else if (CONSP (tmp) && FLOATP (XCDR (tmp)))
1428 {
1429 dpi = (int) (XFLOAT_DATA (XCDR (tmp)) + 0.5);
1430 }
1431 } 1460 }
1432 1461
1433 /* Height */ 1462 /* Height */
@@ -1444,13 +1473,13 @@ fill_in_logfont (f, logfont, font_spec)
1444 /* Weight */ 1473 /* Weight */
1445 tmp = AREF (font_spec, FONT_WEIGHT_INDEX); 1474 tmp = AREF (font_spec, FONT_WEIGHT_INDEX);
1446 if (INTEGERP (tmp)) 1475 if (INTEGERP (tmp))
1447 logfont->lfWeight = XINT (tmp); 1476 logfont->lfWeight = w32_encode_weight (FONT_WEIGHT_NUMERIC (font_spec));
1448 1477
1449 /* Italic */ 1478 /* Italic */
1450 tmp = AREF (font_spec, FONT_SLANT_INDEX); 1479 tmp = AREF (font_spec, FONT_SLANT_INDEX);
1451 if (INTEGERP (tmp)) 1480 if (INTEGERP (tmp))
1452 { 1481 {
1453 int slant = XINT (tmp); 1482 int slant = FONT_SLANT_NUMERIC (font_spec);
1454 logfont->lfItalic = slant > 150 ? 1 : 0; 1483 logfont->lfItalic = slant > 150 ? 1 : 0;
1455 } 1484 }
1456 1485
@@ -1496,41 +1525,36 @@ fill_in_logfont (f, logfont, font_spec)
1496 logfont->lfPitchAndFamily = family | DEFAULT_PITCH; 1525 logfont->lfPitchAndFamily = family | DEFAULT_PITCH;
1497 } 1526 }
1498 1527
1528
1529 /* Set pitch based on the spacing property. */
1530 tmp = AREF (font_spec, FONT_SPACING_INDEX);
1531 if (INTEGERP (tmp))
1532 {
1533 int spacing = XINT (tmp);
1534 if (spacing < FONT_SPACING_MONO)
1535 logfont->lfPitchAndFamily
1536 = logfont->lfPitchAndFamily & 0xF0 | VARIABLE_PITCH;
1537 else
1538 logfont->lfPitchAndFamily
1539 = logfont->lfPitchAndFamily & 0xF0 | FIXED_PITCH;
1540 }
1541
1499 /* Process EXTRA info. */ 1542 /* Process EXTRA info. */
1500 for ( ; CONSP (extra); extra = XCDR (extra)) 1543 for (extra = AREF (font_spec, FONT_EXTRA_INDEX);
1544 CONSP (extra); extra = XCDR (extra))
1501 { 1545 {
1502 tmp = XCAR (extra); 1546 tmp = XCAR (extra);
1503 if (CONSP (tmp)) 1547 if (CONSP (tmp))
1504 { 1548 {
1505 Lisp_Object key, val; 1549 Lisp_Object key, val;
1506 key = XCAR (tmp), val = XCDR (tmp); 1550 key = XCAR (tmp), val = XCDR (tmp);
1507 if (EQ (key, QCspacing))
1508 {
1509 /* Set pitch based on the spacing property. */
1510 if (INTEGERP (val))
1511 {
1512 int spacing = XINT (val);
1513 if (spacing < FONT_SPACING_MONO)
1514 logfont->lfPitchAndFamily
1515 = logfont->lfPitchAndFamily & 0xF0 | VARIABLE_PITCH;
1516 else
1517 logfont->lfPitchAndFamily
1518 = logfont->lfPitchAndFamily & 0xF0 | FIXED_PITCH;
1519 }
1520 else if (EQ (val, Qp))
1521 logfont->lfPitchAndFamily
1522 = logfont->lfPitchAndFamily & 0xF0 | VARIABLE_PITCH;
1523 else if (EQ (val, Qc) || EQ (val, Qm))
1524 logfont->lfPitchAndFamily
1525 = logfont->lfPitchAndFamily & 0xF0 | FIXED_PITCH;
1526 }
1527 /* Only use QCscript if charset is not provided, or is unicode 1551 /* Only use QCscript if charset is not provided, or is unicode
1528 and a single script is specified. This is rather crude, 1552 and a single script is specified. This is rather crude,
1529 and is only used to narrow down the fonts returned where 1553 and is only used to narrow down the fonts returned where
1530 there is a definite match. Some scripts, such as latin, han, 1554 there is a definite match. Some scripts, such as latin, han,
1531 cjk-misc match multiple lfCharSet values, so we can't pre-filter 1555 cjk-misc match multiple lfCharSet values, so we can't pre-filter
1532 them. */ 1556 them. */
1533 else if (EQ (key, QCscript) 1557 if (EQ (key, QCscript)
1534 && logfont->lfCharSet == DEFAULT_CHARSET 1558 && logfont->lfCharSet == DEFAULT_CHARSET
1535 && SYMBOLP (val)) 1559 && SYMBOLP (val))
1536 { 1560 {
@@ -1797,7 +1821,7 @@ w32font_full_name (font, font_obj, pixel_size, name, nbytes)
1797 1821
1798 if (font->lfWeight && font->lfWeight != FW_NORMAL) 1822 if (font->lfWeight && font->lfWeight != FW_NORMAL)
1799 { 1823 {
1800 weight = font_symbolic_weight (font_obj); 1824 weight = FONT_WEIGHT_SYMBOLIC (font_obj);
1801 len += 8 + SBYTES (SYMBOL_NAME (weight)); /* :weight=NAME */ 1825 len += 8 + SBYTES (SYMBOL_NAME (weight)); /* :weight=NAME */
1802 } 1826 }
1803 1827
@@ -1886,13 +1910,17 @@ clear_cached_metrics (w32_font)
1886{ 1910{
1887 int i; 1911 int i;
1888 for (i = 0; i < w32_font->n_cache_blocks; i++) 1912 for (i = 0; i < w32_font->n_cache_blocks; i++)
1889 bzero (w32_font->cached_metrics[i], 1913 {
1890 CACHE_BLOCKSIZE * sizeof (struct font_metrics)); 1914 if (w32_font->cached_metrics[i])
1915 bzero (w32_font->cached_metrics[i],
1916 CACHE_BLOCKSIZE * sizeof (struct font_metrics));
1917 }
1891} 1918}
1892 1919
1893struct font_driver w32font_driver = 1920struct font_driver w32font_driver =
1894 { 1921 {
1895 0, /* Qgdi */ 1922 0, /* Qgdi */
1923 0, /* case insensitive */
1896 w32font_get_cache, 1924 w32font_get_cache,
1897 w32font_list, 1925 w32font_list,
1898 w32font_match, 1926 w32font_match,
@@ -2029,7 +2057,6 @@ syms_of_w32font ()
2029 w32font_driver.type = Qgdi; 2057 w32font_driver.type = Qgdi;
2030 register_font_driver (&w32font_driver, NULL); 2058 register_font_driver (&w32font_driver, NULL);
2031} 2059}
2032#endif /* USE_FONT_BACKEND */
2033 2060
2034/* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee 2061/* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee
2035 (do not change this comment) */ 2062 (do not change this comment) */