comparison src/w32font.c @ 96005:66f0213be62a

Fix crashing bug in use of bold fonts from x-select-font on W32. * w32font.c (w32_to_fc_weight): New function. (w32font_full_name, logfont_to_fcname): Use it. * font.h (font_style_symbolic_from_value): Remove. * font.c (font_style_symbolic_from_value): Remove. (font_style_symbolic): Revert to pre 2008-06-13 version.
author Jason Rumney <jasonr@gnu.org>
date Mon, 16 Jun 2008 09:11:05 +0000
parents 76261fd18708
children 0f831953ffb8
comparison
equal deleted inserted replaced
96004:376c1b70d15b 96005:66f0213be62a
1485 if (n >= 40) return FW_EXTRALIGHT; 1485 if (n >= 40) return FW_EXTRALIGHT;
1486 if (n >= 20) return FW_THIN; 1486 if (n >= 20) return FW_THIN;
1487 return 0; 1487 return 0;
1488 } 1488 }
1489 1489
1490 /* Convert a Windows font weight into one of the weights supported
1491 by fontconfig (see font.c:font_parse_fcname). */
1492 static Lisp_Object
1493 w32_to_fc_weight (n)
1494 int n;
1495 {
1496 if (n >= FW_EXTRABOLD) return intern ("black");
1497 if (n >= FW_BOLD) return intern ("bold");
1498 if (n >= FW_SEMIBOLD) return intern ("demibold");
1499 if (n >= FW_NORMAL) return intern ("medium");
1500 return intern ("light");
1501 }
1502
1490 /* Fill in all the available details of LOGFONT from FONT_SPEC. */ 1503 /* Fill in all the available details of LOGFONT from FONT_SPEC. */
1491 static void 1504 static void
1492 fill_in_logfont (f, logfont, font_spec) 1505 fill_in_logfont (f, logfont, font_spec)
1493 FRAME_PTR f; 1506 FRAME_PTR f;
1494 LOGFONT *logfont; 1507 LOGFONT *logfont;
1867 if (font->lfItalic) 1880 if (font->lfItalic)
1868 len += 7; /* :italic */ 1881 len += 7; /* :italic */
1869 1882
1870 if (font->lfWeight && font->lfWeight != FW_NORMAL) 1883 if (font->lfWeight && font->lfWeight != FW_NORMAL)
1871 { 1884 {
1872 weight = FONT_WEIGHT_SYMBOLIC (font_obj); 1885 weight = w32_to_fc_weight (font->lfWeight);
1873 len += 8 + SBYTES (SYMBOL_NAME (weight)); /* :weight=NAME */ 1886 len += 1 + SBYTES (SYMBOL_NAME (weight)); /* :WEIGHT */
1874 } 1887 }
1875 1888
1876 antialiasing = lispy_antialias_type (font->lfQuality); 1889 antialiasing = lispy_antialias_type (font->lfQuality);
1877 if (! NILP (antialiasing)) 1890 if (! NILP (antialiasing))
1878 len += 11 + SBYTES (SYMBOL_NAME (antialiasing)); /* :antialias=NAME */ 1891 len += 11 + SBYTES (SYMBOL_NAME (antialiasing)); /* :antialias=NAME */
1898 } 1911 }
1899 else 1912 else
1900 p += sprintf (p, ":pixelsize=%d", height); 1913 p += sprintf (p, ":pixelsize=%d", height);
1901 } 1914 }
1902 1915
1916 if (SYMBOLP (weight) && ! NILP (weight))
1917 p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight)));
1918
1903 if (font->lfItalic) 1919 if (font->lfItalic)
1904 p += sprintf (p, ":italic"); 1920 p += sprintf (p, ":italic");
1905
1906 if (SYMBOLP (weight) && ! NILP (weight))
1907 p += sprintf (p, ":weight=%s", SDATA (SYMBOL_NAME (weight)));
1908 1921
1909 if (SYMBOLP (antialiasing) && ! NILP (antialiasing)) 1922 if (SYMBOLP (antialiasing) && ! NILP (antialiasing))
1910 p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing))); 1923 p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing)));
1911 1924
1912 return (p - name); 1925 return (p - name);
1938 1951
1939 if (font->lfItalic) 1952 if (font->lfItalic)
1940 len += 7; /* :italic */ 1953 len += 7; /* :italic */
1941 if (font->lfWeight && font->lfWeight != FW_NORMAL) 1954 if (font->lfWeight && font->lfWeight != FW_NORMAL)
1942 { 1955 {
1943 int fc_weight = w32_decode_weight (font->lfWeight); 1956 weight = w32_to_fc_weight (font->lfWeight);
1944 weight = font_style_symbolic_from_value (FONT_WEIGHT_INDEX, 1957 len += SBYTES (SYMBOL_NAME (weight)) + 1;
1945 make_number (fc_weight), 0);
1946 len += 8; /* :weight= */
1947 if (SYMBOLP (weight))
1948 len += SBYTES (SYMBOL_NAME (weight));
1949 else
1950 {
1951 weight = make_number (fc_weight);
1952 len++;
1953 while (fc_weight /= 10)
1954 len++;
1955 }
1956 } 1958 }
1957 1959
1958 if (len > size) 1960 if (len > size)
1959 return -1; 1961 return -1;
1960 1962
1961 p += sprintf (p, "%s-%d", font->lfFaceName, pointsize / 10); 1963 p += sprintf (p, "%s-%d", font->lfFaceName, pointsize / 10);
1962 if (pointsize % 10) 1964 if (pointsize % 10)
1963 p += sprintf (p, ".%d", pointsize % 10); 1965 p += sprintf (p, ".%d", pointsize % 10);
1964 1966
1967 if (SYMBOLP (weight) && !NILP (weight))
1968 p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight)));
1969
1965 if (font->lfItalic) 1970 if (font->lfItalic)
1966 p += sprintf (p, ":italic"); 1971 p += sprintf (p, ":italic");
1967
1968 if (SYMBOLP (weight) && !NILP (weight))
1969 p += sprintf (p, "weight=%s", SDATA (SYMBOL_NAME (weight)));
1970 else if (INTEGERP (weight))
1971 p += sprintf (p, "weight=%d", XINT (weight));
1972 1972
1973 return (p - fcname); 1973 return (p - fcname);
1974 } 1974 }
1975 1975
1976 static void 1976 static void