aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2008-06-13 14:29:47 +0000
committerJason Rumney2008-06-13 14:29:47 +0000
commit6fe9826d7586a4e6dedb0c567553f70c92161da3 (patch)
tree35f618c1ff63908d519c51e85e0e03730df839fc /src
parentc652498926fd5444559bc9065067b17c85a55c4a (diff)
downloademacs-6fe9826d7586a4e6dedb0c567553f70c92161da3.tar.gz
emacs-6fe9826d7586a4e6dedb0c567553f70c92161da3.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/font.c17
-rw-r--r--src/font.h6
-rw-r--r--src/w32fns.c57
-rw-r--r--src/w32font.c122
5 files changed, 152 insertions, 64 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 88aa859b8e0..5d47aa03a3b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12008-06-13 Jason Rumney <jasonr@gnu.org>
2
3 * w32fns.c (Fw32_select_font): Removed old font API function.
4
5 * w32font.c (logfont_to_fcname): New function.
6 (Fx_select_font): New font dialog function compatible with
7 GTK/fontconfig version.
8
9 * font.c (font_style_symbolic_from_value): New function.
10 (font_style_symbolic): Use it.
11
12 * font.h (font_style_symbolic_from_value): Declare new function.
13
12008-06-13 Juanma Barranquero <lekktu@gmail.com> 142008-06-13 Juanma Barranquero <lekktu@gmail.com>
2 15
3 * font.c (syms_of_font) <font-weight-table, font-slant-table>: 16 * font.c (syms_of_font) <font-weight-table, font-slant-table>:
@@ -39,7 +52,6 @@
39 (font_update_lface): Don't parse "foundry-family" form here. 52 (font_update_lface): Don't parse "foundry-family" form here.
40 Handle FONT_FOUNDRY_INDEX. 53 Handle FONT_FOUNDRY_INDEX.
41 (font_find_for_lface): Likewise. Handle alternate families here. 54 (font_find_for_lface): Likewise. Handle alternate families here.
42 If registry is nil, try iso8859-1 and ascii-0.
43 (font_open_for_lface): Pay attention to size in ENTITY. 55 (font_open_for_lface): Pay attention to size in ENTITY.
44 (font_open_by_name): Simplify by calling font_load_for_lface. 56 (font_open_by_name): Simplify by calling font_load_for_lface.
45 (free_font_driver_list): Delete it. 57 (free_font_driver_list): Delete it.
diff --git a/src/font.c b/src/font.c
index 2c60d0349ca..ead3a6a59a8 100644
--- a/src/font.c
+++ b/src/font.c
@@ -355,12 +355,11 @@ font_style_to_value (prop, val, noerror)
355} 355}
356 356
357Lisp_Object 357Lisp_Object
358font_style_symbolic (font, prop, for_face) 358font_style_symbolic_from_value (prop, val, for_face)
359 Lisp_Object font;
360 enum font_property_index prop; 359 enum font_property_index prop;
360 Lisp_Object val;
361 int for_face; 361 int for_face;
362{ 362{
363 Lisp_Object val = AREF (font, prop);
364 Lisp_Object table, elt; 363 Lisp_Object table, elt;
365 int i; 364 int i;
366 365
@@ -371,7 +370,17 @@ font_style_symbolic (font, prop, for_face)
371 font_assert (((i >> 4) & 0xF) < ASIZE (table)); 370 font_assert (((i >> 4) & 0xF) < ASIZE (table));
372 elt = AREF (table, ((i >> 4) & 0xF)); 371 elt = AREF (table, ((i >> 4) & 0xF));
373 font_assert ((i & 0xF) + 1 < ASIZE (elt)); 372 font_assert ((i & 0xF) + 1 < ASIZE (elt));
374 return (for_face ? AREF (elt, 1) : AREF (elt, (i & 0xF) + 1)); 373 return (for_face ? AREF (elt, 1) : AREF (elt, (i & 0xF) + 1));
374}
375
376Lisp_Object
377font_style_symbolic (font, prop, for_face)
378 Lisp_Object font;
379 enum font_property_index prop;
380 int for_face;
381{
382 Lisp_Object val = AREF (font, prop);
383 return font_style_symbolic_from_value (prop, val, for_face);
375} 384}
376 385
377extern Lisp_Object Vface_alternative_font_family_alist; 386extern Lisp_Object Vface_alternative_font_family_alist;
diff --git a/src/font.h b/src/font.h
index 131e2332dd0..598c48b1aab 100644
--- a/src/font.h
+++ b/src/font.h
@@ -776,7 +776,11 @@ extern int font_style_to_value P_ ((enum font_property_index prop,
776extern Lisp_Object font_style_symbolic P_ ((Lisp_Object font, 776extern Lisp_Object font_style_symbolic P_ ((Lisp_Object font,
777 enum font_property_index prop, 777 enum font_property_index prop,
778 int for_face)); 778 int for_face));
779 779extern Lisp_Object font_style_symbolic_from_value
780 P_ ((enum font_property_index prop,
781 Lisp_Object val,
782 int for_face));
783
780extern int font_match_p P_ ((Lisp_Object spec, Lisp_Object entity)); 784extern int font_match_p P_ ((Lisp_Object spec, Lisp_Object entity));
781extern Lisp_Object font_list_entities P_ ((Lisp_Object frame, 785extern Lisp_Object font_list_entities P_ ((Lisp_Object frame,
782 Lisp_Object spec)); 786 Lisp_Object spec));
diff --git a/src/w32fns.c b/src/w32fns.c
index e83acf0711d..c31ee5be04d 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -8195,62 +8195,6 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */)
8195 w32 specialized functions 8195 w32 specialized functions
8196 ***********************************************************************/ 8196 ***********************************************************************/
8197 8197
8198DEFUN ("w32-select-font", Fw32_select_font, Sw32_select_font, 0, 2, 0,
8199 doc: /* Select a font for the named FRAME using the W32 font dialog.
8200Return an X-style font string corresponding to the selection.
8201
8202If FRAME is omitted or nil, it defaults to the selected frame.
8203If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
8204in the font selection dialog. */)
8205 (frame, include_proportional)
8206 Lisp_Object frame, include_proportional;
8207{
8208 FRAME_PTR f = check_x_frame (frame);
8209 CHOOSEFONT cf;
8210 LOGFONT lf;
8211 TEXTMETRIC tm;
8212 HDC hdc;
8213 HANDLE oldobj;
8214 char buf[100];
8215
8216 bzero (&cf, sizeof (cf));
8217 bzero (&lf, sizeof (lf));
8218
8219 cf.lStructSize = sizeof (cf);
8220 cf.hwndOwner = FRAME_W32_WINDOW (f);
8221 cf.Flags = CF_FORCEFONTEXIST | CF_SCREENFONTS | CF_NOVERTFONTS;
8222
8223 /* Unless include_proportional is non-nil, limit the selection to
8224 monospaced fonts. */
8225 if (NILP (include_proportional))
8226 cf.Flags |= CF_FIXEDPITCHONLY;
8227
8228 cf.lpLogFont = &lf;
8229
8230 /* Initialize as much of the font details as we can from the current
8231 default font. */
8232 hdc = GetDC (FRAME_W32_WINDOW (f));
8233 oldobj = SelectObject (hdc, FONT_COMPAT (FRAME_FONT (f))->hfont);
8234 GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName);
8235 if (GetTextMetrics (hdc, &tm))
8236 {
8237 lf.lfHeight = tm.tmInternalLeading - tm.tmHeight;
8238 lf.lfWeight = tm.tmWeight;
8239 lf.lfItalic = tm.tmItalic;
8240 lf.lfUnderline = tm.tmUnderlined;
8241 lf.lfStrikeOut = tm.tmStruckOut;
8242 lf.lfCharSet = tm.tmCharSet;
8243 cf.Flags |= CF_INITTOLOGFONTSTRUCT;
8244 }
8245 SelectObject (hdc, oldobj);
8246 ReleaseDC (FRAME_W32_WINDOW (f), hdc);
8247
8248 if (!ChooseFont (&cf) || !w32_to_x_font (&lf, buf, 100, NULL))
8249 return Qnil;
8250
8251 return build_string (buf);
8252}
8253
8254DEFUN ("w32-send-sys-command", Fw32_send_sys_command, 8198DEFUN ("w32-send-sys-command", Fw32_send_sys_command,
8255 Sw32_send_sys_command, 1, 2, 0, 8199 Sw32_send_sys_command, 1, 2, 0,
8256 doc: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND. 8200 doc: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
@@ -9308,7 +9252,6 @@ versions of Windows) characters. */);
9308 9252
9309 /* W32 specific functions */ 9253 /* W32 specific functions */
9310 9254
9311 defsubr (&Sw32_select_font);
9312 defsubr (&Sw32_define_rgb_color); 9255 defsubr (&Sw32_define_rgb_color);
9313 defsubr (&Sw32_default_color_map); 9256 defsubr (&Sw32_default_color_map);
9314 defsubr (&Sw32_load_color_file); 9257 defsubr (&Sw32_load_color_file);
diff --git a/src/w32font.c b/src/w32font.c
index dc0612f7e67..862bdabec96 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
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"
@@ -1861,7 +1862,7 @@ w32font_full_name (font, font_obj, pixel_size, name, nbytes)
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 */
@@ -1911,6 +1912,66 @@ w32font_full_name (font, font_obj, pixel_size, name, nbytes)
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. */
1921static 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
1915static void 1976static void
1916compute_metrics (dc, w32_font, code, metrics) 1977compute_metrics (dc, w32_font, code, metrics)
@@ -1963,6 +2024,63 @@ clear_cached_metrics (w32_font)
1963 } 2024 }
1964} 2025}
1965 2026
2027DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
2028 doc: /* Read a font name using a W32 font selection dialog.
2029Return fontconfig style font string corresponding to the selection.
2030
2031If FRAME is omitted or nil, it defaults to the selected frame.
2032If INCLUDE-PROPORTIONAL is non-nil, include proportional fonts
2033in 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);
2082}
2083
1966struct font_driver w32font_driver = 2084struct font_driver w32font_driver =
1967 { 2085 {
1968 0, /* Qgdi */ 2086 0, /* Qgdi */
@@ -2100,6 +2218,8 @@ syms_of_w32font ()
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}