comparison src/w32font.c @ 95894:76261fd18708

* w32fns.c (Fw32_select_font): Removed old font API function. * w32font.c (logfont_to_fcname): New function. (Fx_select_font): New font dialog function compatible with GTK/fontconfig version. * font.c (font_style_symbolic_from_value): New function. (font_style_symbolic): Use it. * font.h (font_style_symbolic_from_value): Declare new function.
author Jason Rumney <jasonr@gnu.org>
date Fri, 13 Jun 2008 14:29:47 +0000
parents cb4bf2ae5ac2
children 66f0213be62a
comparison
equal deleted inserted replaced
95893:680b6bde042b 95894:76261fd18708
18 18
19 #include <config.h> 19 #include <config.h>
20 #include <windows.h> 20 #include <windows.h>
21 #include <math.h> 21 #include <math.h>
22 #include <ctype.h> 22 #include <ctype.h>
23 #include <commdlg.h>
23 24
24 #include "lisp.h" 25 #include "lisp.h"
25 #include "w32term.h" 26 #include "w32term.h"
26 #include "frame.h" 27 #include "frame.h"
27 #include "dispextern.h" 28 #include "dispextern.h"
1859 /* Represent size of scalable fonts by point size. But use pixelsize for 1860 /* Represent size of scalable fonts by point size. But use pixelsize for
1860 raster fonts to indicate that they are exactly that size. */ 1861 raster fonts to indicate that they are exactly that size. */
1861 if (outline) 1862 if (outline)
1862 len += 11; /* -SIZE */ 1863 len += 11; /* -SIZE */
1863 else 1864 else
1864 len = strlen (font->lfFaceName) + 21; 1865 len += 21;
1865 1866
1866 if (font->lfItalic) 1867 if (font->lfItalic)
1867 len += 7; /* :italic */ 1868 len += 7; /* :italic */
1868 1869
1869 if (font->lfWeight && font->lfWeight != FW_NORMAL) 1870 if (font->lfWeight && font->lfWeight != FW_NORMAL)
1909 p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing))); 1910 p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing)));
1910 1911
1911 return (p - name); 1912 return (p - name);
1912 } 1913 }
1913 1914
1915 /* Convert a logfont and point size into a fontconfig style font name.
1916 POINTSIZE is in tenths of points.
1917 If SIZE indicates the size of buffer FCNAME, into which the font name
1918 is written. If the buffer is not large enough to contain the name,
1919 the function returns -1, otherwise it returns the number of bytes
1920 written to FCNAME. */
1921 static int logfont_to_fcname(font, pointsize, fcname, size)
1922 LOGFONT* font;
1923 int pointsize;
1924 char *fcname;
1925 int size;
1926 {
1927 int len, height;
1928 char *p = fcname;
1929 Lisp_Object weight = Qnil;
1930
1931 len = strlen (font->lfFaceName) + 2;
1932 height = pointsize / 10;
1933 while (height /= 10)
1934 len++;
1935
1936 if (pointsize % 10)
1937 len += 2;
1938
1939 if (font->lfItalic)
1940 len += 7; /* :italic */
1941 if (font->lfWeight && font->lfWeight != FW_NORMAL)
1942 {
1943 int fc_weight = w32_decode_weight (font->lfWeight);
1944 weight = font_style_symbolic_from_value (FONT_WEIGHT_INDEX,
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 }
1957
1958 if (len > size)
1959 return -1;
1960
1961 p += sprintf (p, "%s-%d", font->lfFaceName, pointsize / 10);
1962 if (pointsize % 10)
1963 p += sprintf (p, ".%d", pointsize % 10);
1964
1965 if (font->lfItalic)
1966 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
1973 return (p - fcname);
1974 }
1914 1975
1915 static void 1976 static void
1916 compute_metrics (dc, w32_font, code, metrics) 1977 compute_metrics (dc, w32_font, code, metrics)
1917 HDC dc; 1978 HDC dc;
1918 struct w32font_info *w32_font; 1979 struct w32font_info *w32_font;
1959 { 2020 {
1960 if (w32_font->cached_metrics[i]) 2021 if (w32_font->cached_metrics[i])
1961 bzero (w32_font->cached_metrics[i], 2022 bzero (w32_font->cached_metrics[i],
1962 CACHE_BLOCKSIZE * sizeof (struct font_metrics)); 2023 CACHE_BLOCKSIZE * sizeof (struct font_metrics));
1963 } 2024 }
2025 }
2026
2027 DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
2028 doc: /* Read a font name using a W32 font selection dialog.
2029 Return fontconfig style font string corresponding to the selection.
2030
2031 If FRAME is omitted or nil, it defaults to the selected frame.
2032 If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
2033 in the font selection dialog. */)
2034 (frame, include_proportional)
2035 Lisp_Object frame, include_proportional;
2036 {
2037 FRAME_PTR f = check_x_frame (frame);
2038 CHOOSEFONT cf;
2039 LOGFONT lf;
2040 TEXTMETRIC tm;
2041 HDC hdc;
2042 HANDLE oldobj;
2043 char buf[100];
2044
2045 bzero (&cf, sizeof (cf));
2046 bzero (&lf, sizeof (lf));
2047
2048 cf.lStructSize = sizeof (cf);
2049 cf.hwndOwner = FRAME_W32_WINDOW (f);
2050 cf.Flags = CF_FORCEFONTEXIST | CF_SCREENFONTS | CF_NOVERTFONTS;
2051
2052 /* Unless include_proportional is non-nil, limit the selection to
2053 monospaced fonts. */
2054 if (NILP (include_proportional))
2055 cf.Flags |= CF_FIXEDPITCHONLY;
2056
2057 cf.lpLogFont = &lf;
2058
2059 /* Initialize as much of the font details as we can from the current
2060 default font. */
2061 hdc = GetDC (FRAME_W32_WINDOW (f));
2062 oldobj = SelectObject (hdc, FONT_COMPAT (FRAME_FONT (f))->hfont);
2063 GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName);
2064 if (GetTextMetrics (hdc, &tm))
2065 {
2066 lf.lfHeight = tm.tmInternalLeading - tm.tmHeight;
2067 lf.lfWeight = tm.tmWeight;
2068 lf.lfItalic = tm.tmItalic;
2069 lf.lfUnderline = tm.tmUnderlined;
2070 lf.lfStrikeOut = tm.tmStruckOut;
2071 lf.lfCharSet = tm.tmCharSet;
2072 cf.Flags |= CF_INITTOLOGFONTSTRUCT;
2073 }
2074 SelectObject (hdc, oldobj);
2075 ReleaseDC (FRAME_W32_WINDOW (f), hdc);
2076
2077 if (!ChooseFont (&cf)
2078 || logfont_to_fcname (&lf, cf.iPointSize, buf, 100) < 0)
2079 return Qnil;
2080
2081 return build_string (buf);
1964 } 2082 }
1965 2083
1966 struct font_driver w32font_driver = 2084 struct font_driver w32font_driver =
1967 { 2085 {
1968 0, /* Qgdi */ 2086 0, /* Qgdi */
2098 DEFSYM (Qtagbanwa, "tagbanwa"); 2216 DEFSYM (Qtagbanwa, "tagbanwa");
2099 DEFSYM (Qtai_le, "tai_le"); 2217 DEFSYM (Qtai_le, "tai_le");
2100 DEFSYM (Qtifinagh, "tifinagh"); 2218 DEFSYM (Qtifinagh, "tifinagh");
2101 DEFSYM (Qugaritic, "ugaritic"); 2219 DEFSYM (Qugaritic, "ugaritic");
2102 2220
2221 defsubr (&Sx_select_font);
2222
2103 w32font_driver.type = Qgdi; 2223 w32font_driver.type = Qgdi;
2104 register_font_driver (&w32font_driver, NULL); 2224 register_font_driver (&w32font_driver, NULL);
2105 } 2225 }
2106 2226
2107 /* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee 2227 /* arch-tag: 65b8a3cd-46aa-4c0d-a1f3-99e75b9c07ee