comparison src/w32font.c @ 91260:75f89f349f70

(w32font_text_extents): Dereference selected_frame. (w32_enumfont_pattern_entity): Map generic family to adstyle using most common hyphenless variation. (logfonts_match): Check generic family. (font_matches_spec): Don't check generic family here. (fill_in_logfont): Set generic family based on adstyle. + changes to sans-serif constants to avoid hyphen (for xfld compatibility)
author Jason Rumney <jasonr@gnu.org>
date Thu, 20 Dec 2007 00:10:57 +0000
parents 51863d34f0f1
children 9112e263c11f
comparison
equal deleted inserted replaced
91259:51863d34f0f1 91260:75f89f349f70
43 #endif 43 #endif
44 44
45 extern struct font_driver w32font_driver; 45 extern struct font_driver w32font_driver;
46 46
47 Lisp_Object Qgdi; 47 Lisp_Object Qgdi;
48 extern Lisp_Object QCfamily; /* reuse from xfaces.c */ 48 static Lisp_Object Qmonospace, Qsansserif, Qmono, Qsans, Qsans_serif;
49 static Lisp_Object Qmonospace, Qsans_serif, Qserif, Qmono, Qsans, Qsans__serif; 49 static Lisp_Object Qserif, Qscript, Qdecorative;
50 static Lisp_Object Qscript, Qdecorative, Qraster, Qoutline, Qunknown; 50 static Lisp_Object Qraster, Qoutline, Qunknown;
51 51
52 /* antialiasing */ 52 /* antialiasing */
53 extern Lisp_Object QCantialias; /* defined in font.c */ 53 extern Lisp_Object QCantialias; /* defined in font.c */
54 extern Lisp_Object Qnone; /* reuse from w32fns.c */ 54 extern Lisp_Object Qnone; /* reuse from w32fns.c */
55 static Lisp_Object Qstandard, Qsubpixel, Qnatural; 55 static Lisp_Object Qstandard, Qsubpixel, Qnatural;
296 #if 0 296 #if 0
297 /* Frames can come and go, and their fonts outlive them. This is 297 /* Frames can come and go, and their fonts outlive them. This is
298 particularly troublesome with tooltip frames, and causes crashes. */ 298 particularly troublesome with tooltip frames, and causes crashes. */
299 f = ((struct w32font_info *)font)->owning_frame; 299 f = ((struct w32font_info *)font)->owning_frame;
300 #else 300 #else
301 f = selected_frame; 301 f = XFRAME (selected_frame);
302 #endif 302 #endif
303 303
304 dc = get_frame_dc (f); 304 dc = get_frame_dc (f);
305 old_font = SelectObject (dc, ((W32FontStruct *)(font->font.font))->hfont); 305 old_font = SelectObject (dc, ((W32FontStruct *)(font->font.font))->hfont);
306 306
769 useful to users looking for a close match. */ 769 useful to users looking for a close match. */
770 generic_type = physical_font->ntmTm.tmPitchAndFamily & 0xF0; 770 generic_type = physical_font->ntmTm.tmPitchAndFamily & 0xF0;
771 if (generic_type == FF_DECORATIVE) 771 if (generic_type == FF_DECORATIVE)
772 tem = Qdecorative; 772 tem = Qdecorative;
773 else if (generic_type == FF_MODERN) 773 else if (generic_type == FF_MODERN)
774 tem = Qmonospace; 774 tem = Qmono;
775 else if (generic_type == FF_ROMAN) 775 else if (generic_type == FF_ROMAN)
776 tem = Qserif; 776 tem = Qserif;
777 else if (generic_type == FF_SCRIPT) 777 else if (generic_type == FF_SCRIPT)
778 tem = Qscript; 778 tem = Qscript;
779 else if (generic_type == FF_SWISS) 779 else if (generic_type == FF_SWISS)
780 tem = Qsans_serif; 780 tem = Qsans;
781 else 781 else
782 tem = Qnil; 782 tem = null_string;
783 783
784 if (! NILP (tem)) 784 ASET (entity, FONT_ADSTYLE_INDEX, tem);
785 font_put_extra (entity, QCfamily, tem);
786 785
787 if (physical_font->ntmTm.tmPitchAndFamily & 0x01) 786 if (physical_font->ntmTm.tmPitchAndFamily & 0x01)
788 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_PROPORTIONAL)); 787 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_PROPORTIONAL));
789 else 788 else
790 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_MONO)); 789 font_put_extra (entity, QCspacing, make_number (FONT_SPACING_MONO));
825 w32_generic_family (Lisp_Object name) 824 w32_generic_family (Lisp_Object name)
826 { 825 {
827 /* Generic families. */ 826 /* Generic families. */
828 if (EQ (name, Qmonospace) || EQ (name, Qmono)) 827 if (EQ (name, Qmonospace) || EQ (name, Qmono))
829 return FF_MODERN; 828 return FF_MODERN;
830 else if (EQ (name, Qsans_serif) || EQ (name, Qsans__serif) 829 else if (EQ (name, Qsans) || EQ (name, Qsans_serif) || EQ (name, Qsansserif))
831 || EQ (name, Qsans))
832 return FF_SWISS; 830 return FF_SWISS;
833 else if (EQ (name, Qserif)) 831 else if (EQ (name, Qserif))
834 return FF_ROMAN; 832 return FF_ROMAN;
835 else if (EQ (name, Qdecorative)) 833 else if (EQ (name, Qdecorative))
836 return FF_DECORATIVE; 834 return FF_DECORATIVE;
853 if (pattern->lfWeight 851 if (pattern->lfWeight
854 && ((font->lfWeight < (pattern->lfWeight - 150)) 852 && ((font->lfWeight < (pattern->lfWeight - 150))
855 || font->lfWeight > (pattern->lfWeight + 150))) 853 || font->lfWeight > (pattern->lfWeight + 150)))
856 return 0; 854 return 0;
857 855
856 if (pattern->lfPitchAndFamily & 0xF0 != FF_DONTCARE
857 && pattern->lfPitchAndFamily & 0xF0 != font->lfPitchAndFamily & 0xF0)
858 return 0;
859
858 /* Charset and face should be OK. Italic has to be checked 860 /* Charset and face should be OK. Italic has to be checked
859 against the original spec, in case we don't have any preference. */ 861 against the original spec, in case we don't have any preference. */
860 return 1; 862 return 1;
861 } 863 }
862 864
887 extra_entry = XCAR (extra); 889 extra_entry = XCAR (extra);
888 if (CONSP (extra_entry)) 890 if (CONSP (extra_entry))
889 { 891 {
890 Lisp_Object key = XCAR (extra_entry); 892 Lisp_Object key = XCAR (extra_entry);
891 val = XCDR (extra_entry); 893 val = XCDR (extra_entry);
892 if (EQ (key, QCfamily)) 894 if (EQ (key, QCspacing))
893 {
894 /* Generic family. Most useful when there is no font name
895 specified. eg, if a script does not exist in the default
896 font, we could look for a font with the same generic family
897 that does support the script. Full PANOSE support would
898 be better, but we need to open the font to get that. */
899 BYTE w32_family = w32_generic_family (val);
900
901 /* Reject if FF_DONTCARE is returned, as it means the
902 font spec is bad. */
903 if (w32_family == FF_DONTCARE
904 || w32_family != (font->ntmTm.tmPitchAndFamily & 0xF0))
905 return 0;
906 }
907 else if (EQ (key, QCspacing))
908 { 895 {
909 int proportional; 896 int proportional;
910 if (INTEGERP (val)) 897 if (INTEGERP (val))
911 { 898 {
912 int spacing = XINT (val); 899 int spacing = XINT (val);
1174 strncpy (logfont->lfFaceName, SDATA (SYMBOL_NAME (tmp)), LF_FACESIZE); 1161 strncpy (logfont->lfFaceName, SDATA (SYMBOL_NAME (tmp)), LF_FACESIZE);
1175 else if (STRINGP (tmp)) 1162 else if (STRINGP (tmp))
1176 strncpy (logfont->lfFaceName, SDATA (tmp), LF_FACESIZE); 1163 strncpy (logfont->lfFaceName, SDATA (tmp), LF_FACESIZE);
1177 } 1164 }
1178 1165
1166 tmp = AREF (font_spec, FONT_ADSTYLE_INDEX);
1167 if (!NILP (tmp))
1168 {
1169 /* Override generic family. */
1170 BYTE family = w32_generic_family (tmp);
1171 if (family != FF_DONTCARE)
1172 logfont->lfPitchAndFamily = family | DEFAULT_PITCH;
1173 }
1174
1179 /* Process EXTRA info. */ 1175 /* Process EXTRA info. */
1180 for ( ; CONSP (extra); extra = XCDR (extra)) 1176 for ( ; CONSP (extra); extra = XCDR (extra))
1181 { 1177 {
1182 tmp = XCAR (extra); 1178 tmp = XCAR (extra);
1183 if (CONSP (tmp)) 1179 if (CONSP (tmp))
1184 { 1180 {
1185 Lisp_Object key, val; 1181 Lisp_Object key, val;
1186 key = XCAR (tmp), val = XCDR (tmp); 1182 key = XCAR (tmp), val = XCDR (tmp);
1187 if (EQ (key, QCfamily)) 1183 if (EQ (key, QCspacing))
1188 {
1189 /* Override generic family. */
1190 BYTE family = w32_generic_family (val);
1191 if (family != FF_DONTCARE)
1192 logfont->lfPitchAndFamily
1193 = logfont->lfPitchAndFamily & 0x0F | family;
1194 }
1195 else if (EQ (key, QCspacing))
1196 { 1184 {
1197 /* Set pitch based on the spacing property. */ 1185 /* Set pitch based on the spacing property. */
1198 if (INTEGERP (val)) 1186 if (INTEGERP (val))
1199 { 1187 {
1200 int spacing = XINT (val); 1188 int spacing = XINT (val);
1452 DEFSYM (Qgdi, "gdi"); 1440 DEFSYM (Qgdi, "gdi");
1453 1441
1454 /* Generic font families. */ 1442 /* Generic font families. */
1455 DEFSYM (Qmonospace, "monospace"); 1443 DEFSYM (Qmonospace, "monospace");
1456 DEFSYM (Qserif, "serif"); 1444 DEFSYM (Qserif, "serif");
1457 DEFSYM (Qsans_serif, "sans-serif"); 1445 DEFSYM (Qsansserif, "sansserif");
1458 DEFSYM (Qscript, "script"); 1446 DEFSYM (Qscript, "script");
1459 DEFSYM (Qdecorative, "decorative"); 1447 DEFSYM (Qdecorative, "decorative");
1460 /* Aliases. */ 1448 /* Aliases. */
1461 DEFSYM (Qsans__serif, "sans_serif"); 1449 DEFSYM (Qsans_serif, "sans_serif");
1462 DEFSYM (Qsans, "sans"); 1450 DEFSYM (Qsans, "sans");
1463 DEFSYM (Qmono, "mono"); 1451 DEFSYM (Qmono, "mono");
1464 1452
1465 /* Fake foundries. */ 1453 /* Fake foundries. */
1466 DEFSYM (Qraster, "raster"); 1454 DEFSYM (Qraster, "raster");