aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1996-01-21 00:24:03 +0000
committerGeoff Voelker1996-01-21 00:24:03 +0000
commit7fb46567ca81c0e50e691e1968ba1258ef3ec7f6 (patch)
tree98acb29fdf96d6e67d4122e0f8a0804a8ec51bda /src
parent819053bff0829425e8c7fc7add1a6ebfb329df99 (diff)
downloademacs-7fb46567ca81c0e50e691e1968ba1258ef3ec7f6.tar.gz
emacs-7fb46567ca81c0e50e691e1968ba1258ef3ec7f6.zip
(Vwin32_enable_italics, Vwin32_enable_palette):
New variables. (syms_of_win32fns): Set up new lisp variables. (x_set_frame_parameters, x_real_positions, win32_load_font, win32_abort): Conform to coding style. (Fwin32_define_rgb_color, Fwin32_load_color_file, Fwin32_map_color, Fwin32_unmap_color, Fwin32_regenerate_palette): New functions. (syms_of_win32fns): Set up new lisp subroutines. (defined_color): Use palettes. (map_mode): Function removed. (win32_init_class): Don't CS_OWNDC. (win32_wnd_proc): Use segregated critical sections appropriately. Handle WM_PALETTECHANGED. Record WINDOWPLACEMENT structure length. (x_to_win32_weight, win32_to_x_weight): Handle "heavy", "extrabold", "light", "extralight", and "thin" fonts. (x_to_win32_charset, win32_to_x_charset): New functions. (win32_to_x_font): Use win32_to_x_charset. (x_to_win32_font): Use x_to_win32_charset. Support Windows font names. (Fx_list_fonts, Fx_display_color_cells, Fx_display_mm_height. Fx_display_mm_width): Use GetDC directly. (Fx_open_connection): Support external color mapping files.
Diffstat (limited to 'src')
-rw-r--r--src/w32fns.c737
1 files changed, 526 insertions, 211 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index 11aaf43dd01..4e1092c6924 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -45,6 +45,13 @@ extern struct scroll_bar *x_window_to_scroll_bar ();
45/* The colormap for converting color names to RGB values */ 45/* The colormap for converting color names to RGB values */
46Lisp_Object Vwin32_color_map; 46Lisp_Object Vwin32_color_map;
47 47
48/* Switch to control whether we inhibit requests for italicised fonts (which
49 are synthesized, look ugly, and are trashed by cursor movement under NT). */
50Lisp_Object Vwin32_enable_italics;
51
52/* Enable palette management. */
53Lisp_Object Vwin32_enable_palette;
54
48/* The name we're using in resource queries. */ 55/* The name we're using in resource queries. */
49Lisp_Object Vx_resource_name; 56Lisp_Object Vx_resource_name;
50 57
@@ -611,7 +618,7 @@ x_set_frame_parameters (f, alist)
611 if (NATNUMP (param_index) 618 if (NATNUMP (param_index)
612 && (XFASTINT (param_index) 619 && (XFASTINT (param_index)
613 < sizeof (x_frame_parms)/sizeof (x_frame_parms[0]))) 620 < sizeof (x_frame_parms)/sizeof (x_frame_parms[0])))
614 (*x_frame_parms[XINT (param_index)].setter)(f, val, old_value); 621 (*x_frame_parms[XINT (param_index)].setter) (f, val, old_value);
615 } 622 }
616 } 623 }
617 624
@@ -755,18 +762,16 @@ x_real_positions (f, xptr, yptr)
755 int *xptr, *yptr; 762 int *xptr, *yptr;
756{ 763{
757 POINT pt; 764 POINT pt;
758 765 RECT rect;
759 {
760 RECT rect;
761 766
762 GetClientRect(FRAME_WIN32_WINDOW(f), &rect); 767 GetClientRect (FRAME_WIN32_WINDOW (f), &rect);
763 AdjustWindowRect(&rect, f->output_data.win32->dwStyle, FRAME_EXTERNAL_MENU_BAR(f)); 768 AdjustWindowRect (&rect, f->output_data.win32->dwStyle,
769 FRAME_EXTERNAL_MENU_BAR (f));
764 770
765 pt.x = rect.left; 771 pt.x = rect.left;
766 pt.y = rect.top; 772 pt.y = rect.top;
767 }
768 773
769 ClientToScreen (FRAME_WIN32_WINDOW(f), &pt); 774 ClientToScreen (FRAME_WIN32_WINDOW (f), &pt);
770 775
771 *xptr = pt.x; 776 *xptr = pt.x;
772 *yptr = pt.y; 777 *yptr = pt.y;
@@ -816,25 +821,91 @@ x_report_frame_params (f, alistptr)
816} 821}
817 822
818 823
819#if 0 824DEFUN ("win32-define-rgb-color", Fwin32_define_rgb_color, Swin32_define_rgb_color, 4, 4, 0,
820DEFUN ("win32-rgb", Fwin32_rgb, Swin32_rgb, 3, 3, 0, 825 "Convert RGB numbers to a windows color reference and associate with\n\
821 "Convert RGB numbers to a windows color reference.") 826NAME (a string). This adds or updates a named color to win32-color-map,\n\
822 (red, green, blue) 827making it available for use. The original entry's RGB ref is returned,\n\
823 Lisp_Object red, green, blue; 828or nil if the entry is new.")
829 (red, green, blue, name)
830 Lisp_Object red, green, blue, name;
824{ 831{
825 Lisp_Object rgb; 832 Lisp_Object rgb;
833 Lisp_Object oldrgb = Qnil;
834 Lisp_Object entry;
826 835
827 CHECK_NUMBER (red, 0); 836 CHECK_NUMBER (red, 0);
828 CHECK_NUMBER (green, 0); 837 CHECK_NUMBER (green, 0);
829 CHECK_NUMBER (blue, 0); 838 CHECK_NUMBER (blue, 0);
839 CHECK_STRING (name, 0);
830 840
831 XSET (rgb, Lisp_Int, RGB(XUINT(red), XUINT(green), XUINT(blue))); 841 XSET (rgb, Lisp_Int, RGB (XUINT (red), XUINT (green), XUINT (blue)));
842
843 BLOCK_INPUT;
844
845 /* replace existing entry in win32-color-map or add new entry. */
846 entry = Fassoc (name, Vwin32_color_map);
847 if (NILP (entry))
848 {
849 entry = Fcons (name, rgb);
850 Vwin32_color_map = Fcons (entry, Vwin32_color_map);
851 }
852 else
853 {
854 oldrgb = Fcdr (entry);
855 Fsetcdr (entry, rgb);
856 }
857
858 UNBLOCK_INPUT;
832 859
833 return (rgb); 860 return (oldrgb);
834} 861}
835 862
863DEFUN ("win32-load-color-file", Fwin32_load_color_file, Swin32_load_color_file, 1, 1, 0,
864 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
865Assign this value to win32-color-map to replace the existing color map.\n\
866The file should define one named RGB color per line like so:\
867 R G B name\n\
868where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
869 (filename)
870 Lisp_Object filename;
871{
872 FILE *fp;
873 Lisp_Object cmap = Qnil;
874 Lisp_Object abspath;
875
876 CHECK_STRING (filename, 0);
877 abspath = Fexpand_file_name (filename, Qnil);
878
879 fp = fopen (XSTRING (filename)->data, "rt");
880 if (fp)
881 {
882 char buf[512];
883 int red, green, blue;
884 int num;
885
886 BLOCK_INPUT;
887
888 while (fgets (buf, sizeof (buf), fp) != NULL)
889 {
890 if (sscanf (buf, "%u %u %u %n]", &red, &green, &blue, &num) == 3)
891 {
892 char *name = buf + num;
893 num = strlen (name) - 1;
894 if (name[num] == '\n')
895 name[num] = 0;
896 cmap = Fcons (Fcons (build_string (name),
897 make_number (RGB (red, green, blue))),
898 cmap);
899 }
900 }
901 fclose (fp);
902
903 UNBLOCK_INPUT;
904 }
905
906 return cmap;
907}
836 908
837#else
838/* The default colors for the win32 color map */ 909/* The default colors for the win32 color map */
839typedef struct colormap_t 910typedef struct colormap_t
840{ 911{
@@ -1108,7 +1179,6 @@ DEFUN ("win32-default-color-map", Fwin32_default_color_map, Swin32_default_color
1108 1179
1109 return (cmap); 1180 return (cmap);
1110} 1181}
1111#endif
1112 1182
1113Lisp_Object 1183Lisp_Object
1114win32_to_x_color (rgb) 1184win32_to_x_color (rgb)
@@ -1161,6 +1231,121 @@ x_to_win32_color (colorname)
1161 return ret; 1231 return ret;
1162} 1232}
1163 1233
1234
1235void
1236win32_regenerate_palette (FRAME_PTR f)
1237{
1238 struct win32_palette_entry * pList;
1239 LOGPALETTE * p_palette;
1240 HPALETTE h_new_palette;
1241 int i;
1242
1243 /* don't bother trying to create palette if not supported */
1244 if (! FRAME_WIN32_DISPLAY_INFO (f)->has_palette)
1245 return;
1246
1247 p_palette = (LOGPALETTE *)
1248 xmalloc (sizeof (LOGPALETTE) +
1249 FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use * sizeof (PALETTEENTRY));
1250 p_palette->palVersion = 0x300;
1251 p_palette->palNumEntries = FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use;
1252
1253 pList = FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1254 for (i = 0; i < FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use;
1255 i++, pList = pList->next)
1256 p_palette->palPalEntry[i] = pList->entry;
1257
1258 h_new_palette = CreatePalette ((LPLOGPALETTE) p_palette);
1259
1260 enter_crit (CRIT_GDI);
1261
1262 if (FRAME_WIN32_DISPLAY_INFO (f)->h_palette)
1263 DeleteObject (FRAME_WIN32_DISPLAY_INFO (f)->h_palette);
1264 FRAME_WIN32_DISPLAY_INFO (f)->h_palette = h_new_palette;
1265
1266 /* Realize display palette and garbage all frames. */
1267 ReleaseFrameDC (f, GetFrameDC (f));
1268
1269 leave_crit (CRIT_GDI);
1270
1271 xfree (p_palette);
1272}
1273
1274#define WIN32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1275#define SET_WIN32_COLOR(pe, color) \
1276 do { \
1277 pe.peRed = GetRValue (color); \
1278 pe.peGreen = GetGValue (color); \
1279 pe.peBlue = GetBValue (color); \
1280 pe.peFlags = 0; \
1281 } while (0)
1282
1283#if 0
1284/* Keep these around in case we ever want to track color usage. */
1285void
1286win32_map_color (FRAME_PTR f, COLORREF color)
1287{
1288 struct win32_palette_entry * pList = FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1289
1290 if (NILP (Vwin32_enable_palette))
1291 return;
1292
1293 /* check if color is already mapped */
1294 while (pList)
1295 {
1296 if (WIN32_COLOR (pList->entry) == color)
1297 {
1298 ++pList->refcount;
1299 return;
1300 }
1301 pList = pList->next;
1302 }
1303
1304 /* not already mapped, so add to list and recreate Windows palette */
1305 pList = (struct win32_palette_entry *) xmalloc (sizeof (struct win32_palette_entry));
1306 SET_WIN32_COLOR (pList->entry, color);
1307 pList->refcount = 1;
1308 pList->next = FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1309 FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use = pList;
1310 FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use++;
1311
1312 /* set flag that palette must be regenerated */
1313 FRAME_WIN32_DISPLAY_INFO (f)->regen_palette = TRUE;
1314}
1315
1316void
1317win32_unmap_color (FRAME_PTR f, COLORREF color)
1318{
1319 struct win32_palette_entry * pList = FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1320 struct win32_palette_entry **ppPrev = &FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1321
1322 if (NILP (Vwin32_enable_palette))
1323 return;
1324
1325 /* check if color is already mapped */
1326 while (pList)
1327 {
1328 if (WIN32_COLOR (pList->entry) == color)
1329 {
1330 if (--pList->refcount == 0)
1331 {
1332 *ppPrev = pList->next;
1333 xfree (pList);
1334 FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use--;
1335 break;
1336 }
1337 else
1338 return;
1339 }
1340 ppPrev = &pList->next;
1341 pList = pList->next;
1342 }
1343
1344 /* set flag that palette must be regenerated */
1345 FRAME_WIN32_DISPLAY_INFO (f)->regen_palette = TRUE;
1346}
1347#endif
1348
1164/* Decide if color named COLOR is valid for the display associated with 1349/* Decide if color named COLOR is valid for the display associated with
1165 the selected frame; if so, return the rgb values in COLOR_DEF. 1350 the selected frame; if so, return the rgb values in COLOR_DEF.
1166 If ALLOC is nonzero, allocate a new colormap cell. */ 1351 If ALLOC is nonzero, allocate a new colormap cell. */
@@ -1173,18 +1358,49 @@ defined_color (f, color, color_def, alloc)
1173 int alloc; 1358 int alloc;
1174{ 1359{
1175 register Lisp_Object tem; 1360 register Lisp_Object tem;
1176 1361
1177 tem = x_to_win32_color (color); 1362 tem = x_to_win32_color (color);
1178 1363
1179 if (!NILP (tem)) 1364 if (!NILP (tem))
1180 { 1365 {
1181 *color_def = XUINT (tem); 1366 if (!NILP (Vwin32_enable_palette))
1367 {
1368 struct win32_palette_entry * pEntry =
1369 FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1370 struct win32_palette_entry ** ppLast =
1371 &FRAME_WIN32_DISPLAY_INFO (f)->p_colors_in_use;
1372
1373 /* check if color is already mapped */
1374 while (pEntry)
1375 {
1376 if (WIN32_COLOR (pEntry->entry) == XUINT(tem))
1377 break;
1378 ppLast = &pEntry->next;
1379 pEntry = pEntry->next;
1380 }
1381
1382 if (pEntry == NULL && alloc)
1383 {
1384 /* not already mapped, so add to list */
1385 pEntry = (struct win32_palette_entry *)
1386 xmalloc (sizeof (struct win32_palette_entry));
1387 SET_WIN32_COLOR (pEntry->entry, XUINT(tem));
1388 pEntry->next = NULL;
1389 *ppLast = pEntry;
1390 FRAME_WIN32_DISPLAY_INFO (f)->n_colors_in_use++;
1391
1392 /* set flag that palette must be regenerated */
1393 FRAME_WIN32_DISPLAY_INFO (f)->regen_palette = TRUE;
1394 }
1395 }
1396 /* whether or not frame can display arbitrary RGB colors, force
1397 COLORREF value to snap to nearest color in system palette by
1398 simulating the PALETTE_RGB macro. */
1399 *color_def = XUINT (tem) | 0x2000000;
1182 return 1; 1400 return 1;
1183 }
1184 else
1185 {
1186 return 0;
1187 } 1401 }
1402 else
1403 return 0;
1188} 1404}
1189 1405
1190/* Given a string ARG naming a color, compute a pixel value from it 1406/* Given a string ARG naming a color, compute a pixel value from it
@@ -2323,7 +2539,7 @@ win32_init_class (hinst)
2323{ 2539{
2324 WNDCLASS wc; 2540 WNDCLASS wc;
2325 2541
2326 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 2542 wc.style = CS_HREDRAW | CS_VREDRAW;
2327 wc.lpfnWndProc = (WNDPROC) win32_wnd_proc; 2543 wc.lpfnWndProc = (WNDPROC) win32_wnd_proc;
2328 wc.cbClsExtra = 0; 2544 wc.cbClsExtra = 0;
2329 wc.cbWndExtra = WND_EXTRA_BYTES; 2545 wc.cbWndExtra = WND_EXTRA_BYTES;
@@ -2427,26 +2643,6 @@ win_msg_worker (dw)
2427 return (0); 2643 return (0);
2428} 2644}
2429 2645
2430HDC
2431map_mode (hdc)
2432 HDC hdc;
2433{
2434 if (hdc)
2435 {
2436#if 0
2437 /* Make mapping mode be in 1/20 of point */
2438
2439 SetMapMode (hdc, MM_ANISOTROPIC);
2440 SetWindowExtEx (hdc, 1440, 1440, NULL);
2441 SetViewportExtEx (hdc,
2442 GetDeviceCaps (hdc, LOGPIXELSX),
2443 GetDeviceCaps (hdc, LOGPIXELSY),
2444 NULL);
2445#endif
2446 }
2447 return (hdc);
2448}
2449
2450/* Convert between the modifier bits Win32 uses and the modifier bits 2646/* Convert between the modifier bits Win32 uses and the modifier bits
2451 Emacs uses. */ 2647 Emacs uses. */
2452unsigned int 2648unsigned int
@@ -2493,50 +2689,33 @@ win32_wnd_proc (hwnd, msg, wParam, lParam)
2493 switch (msg) 2689 switch (msg)
2494 { 2690 {
2495 case WM_ERASEBKGND: 2691 case WM_ERASEBKGND:
2692 enter_crit (CRIT_GDI);
2693 GetUpdateRect (hwnd, &wmsg.rect, FALSE);
2694 leave_crit (CRIT_GDI);
2695 my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
2696 return 1;
2697 case WM_PALETTECHANGED:
2698 /* ignore our own changes */
2699 if ((HWND)wParam != hwnd)
2496 { 2700 {
2497 HBRUSH hb; 2701 /* simply notify main thread it may need to update frames */
2498 HANDLE oldobj; 2702 my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
2499 RECT rect;
2500
2501 GetClientRect (hwnd, &rect);
2502
2503 hb = CreateSolidBrush (GetWindowLong (hwnd, WND_BACKGROUND_INDEX));
2504
2505 oldobj = SelectObject ((HDC)wParam, hb);
2506
2507 FillRect((HDC)wParam, &rect, hb);
2508
2509 SelectObject((HDC)wParam, oldobj);
2510
2511 DeleteObject (hb);
2512
2513 return (0);
2514 } 2703 }
2704 return 0;
2515 case WM_PAINT: 2705 case WM_PAINT:
2516 { 2706 {
2517 PAINTSTRUCT paintStruct; 2707 PAINTSTRUCT paintStruct;
2518 2708
2709 enter_crit (CRIT_GDI);
2519 BeginPaint (hwnd, &paintStruct); 2710 BeginPaint (hwnd, &paintStruct);
2520 wmsg.rect = paintStruct.rcPaint; 2711 wmsg.rect = paintStruct.rcPaint;
2521 EndPaint (hwnd, &paintStruct); 2712 EndPaint (hwnd, &paintStruct);
2522 2713 leave_crit (CRIT_GDI);
2714
2523 my_post_msg (&wmsg, hwnd, msg, wParam, lParam); 2715 my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
2524 2716
2525 return (0); 2717 return (0);
2526 } 2718 }
2527
2528 case WM_CREATE:
2529 {
2530 HDC hdc = my_get_dc (hwnd);
2531
2532 /* Make mapping mode be in 1/20 of point */
2533
2534 map_mode (hdc);
2535
2536 ReleaseDC (hwnd, hdc);
2537 }
2538
2539 return (0);
2540 case WM_KEYDOWN: 2719 case WM_KEYDOWN:
2541 case WM_SYSKEYDOWN: 2720 case WM_SYSKEYDOWN:
2542#if 0 2721#if 0
@@ -2561,7 +2740,7 @@ win32_wnd_proc (hwnd, msg, wParam, lParam)
2561 || wParam == VK_SHIFT 2740 || wParam == VK_SHIFT
2562 || wParam == VK_CONTROL 2741 || wParam == VK_CONTROL
2563 || wParam == VK_CAPITAL) 2742 || wParam == VK_CAPITAL)
2564 break; 2743 goto dflt;
2565 2744
2566 /* Anything we do not have a name for needs to be translated or 2745 /* Anything we do not have a name for needs to be translated or
2567 returned as ascii keystroke. */ 2746 returned as ascii keystroke. */
@@ -2624,7 +2803,8 @@ win32_wnd_proc (hwnd, msg, wParam, lParam)
2624 { 2803 {
2625 WINDOWPLACEMENT wp; 2804 WINDOWPLACEMENT wp;
2626 LPWINDOWPOS lppos = (WINDOWPOS *) lParam; 2805 LPWINDOWPOS lppos = (WINDOWPOS *) lParam;
2627 2806
2807 wp.length = sizeof (wp);
2628 GetWindowPlacement (hwnd, &wp); 2808 GetWindowPlacement (hwnd, &wp);
2629 2809
2630 if (wp.showCmd != SW_SHOWMINIMIZED && ! (lppos->flags & SWP_NOSIZE)) 2810 if (wp.showCmd != SW_SHOWMINIMIZED && ! (lppos->flags & SWP_NOSIZE))
@@ -2638,12 +2818,12 @@ win32_wnd_proc (hwnd, msg, wParam, lParam)
2638 2818
2639 GetWindowRect (hwnd, &wr); 2819 GetWindowRect (hwnd, &wr);
2640 2820
2641 enter_crit (); 2821 enter_crit (CRIT_MSG);
2642 2822
2643 dwXUnits = GetWindowLong (hwnd, WND_X_UNITS_INDEX); 2823 dwXUnits = GetWindowLong (hwnd, WND_X_UNITS_INDEX);
2644 dwYUnits = GetWindowLong (hwnd, WND_Y_UNITS_INDEX); 2824 dwYUnits = GetWindowLong (hwnd, WND_Y_UNITS_INDEX);
2645 2825
2646 leave_crit (); 2826 leave_crit (CRIT_MSG);
2647 2827
2648 memset (&rect, 0, sizeof (rect)); 2828 memset (&rect, 0, sizeof (rect));
2649 AdjustWindowRect (&rect, GetWindowLong (hwnd, GWL_STYLE), 2829 AdjustWindowRect (&rect, GetWindowLong (hwnd, GWL_STYLE),
@@ -2929,7 +3109,7 @@ This function is an internal primitive--use `make-frame' instead.")
2929 font = x_new_font (f, "-*-system-medium-r-normal-*-*-200-*-*-c-120-*-*"); 3109 font = x_new_font (f, "-*-system-medium-r-normal-*-*-200-*-*-c-120-*-*");
2930#endif 3110#endif
2931 if (! STRINGP (font)) 3111 if (! STRINGP (font))
2932 font = x_new_font (f, "-*-terminal-medium-r-normal-*-*-180-*-*-c-120-*-*"); 3112 font = x_new_font (f, "-*-Fixedsys-*-r-*-*-12-90-*-*-c-*-*-*");
2933 UNBLOCK_INPUT; 3113 UNBLOCK_INPUT;
2934 if (! STRINGP (font)) 3114 if (! STRINGP (font))
2935 font = build_string ("-*-system"); 3115 font = build_string ("-*-system");
@@ -3117,54 +3297,50 @@ DEFUN ("unfocus-frame", Funfocus_frame, Sunfocus_frame, 0, 0, 0,
3117 return Qnil; 3297 return Qnil;
3118} 3298}
3119 3299
3120XFontStruct 3300XFontStruct *
3121*win32_load_font (dpyinfo,name) 3301win32_load_font (dpyinfo,name)
3122struct win32_display_info *dpyinfo; 3302 struct win32_display_info *dpyinfo;
3123char * name; 3303 char *name;
3124{ 3304{
3125 XFontStruct * font = NULL; 3305 XFontStruct * font = NULL;
3126 BOOL ok; 3306 BOOL ok;
3127 3307 LOGFONT lf;
3128 { 3308
3129 LOGFONT lf; 3309 if (!name || !x_to_win32_font (name, &lf))
3130 3310 return (NULL);
3131 if (!name || !x_to_win32_font(name, &lf)) 3311
3132 return (NULL); 3312 font = (XFontStruct *) xmalloc (sizeof (XFontStruct));
3133 3313 if (!font) return (NULL);
3134 font = (XFontStruct *) xmalloc (sizeof (XFontStruct)); 3314
3135 3315 BLOCK_INPUT;
3136 if (!font) return (NULL); 3316
3137 3317 font->hfont = CreateFontIndirect (&lf);
3138 BLOCK_INPUT; 3318
3139 3319 if (font->hfont == NULL)
3140 font->hfont = CreateFontIndirect(&lf); 3320 {
3321 ok = FALSE;
3322 }
3323 else
3324 {
3325 HDC hdc;
3326 HANDLE oldobj;
3327
3328 hdc = GetDC (dpyinfo->root_window);
3329
3330 oldobj = SelectObject (hdc, font->hfont);
3331
3332 ok = GetTextMetrics (hdc, &font->tm);
3333
3334 SelectObject (hdc, oldobj);
3335
3336 ReleaseDC (dpyinfo->root_window, hdc);
3141 } 3337 }
3142
3143 if (font->hfont == NULL)
3144 {
3145 ok = FALSE;
3146 }
3147 else
3148 {
3149 HDC hdc;
3150 HANDLE oldobj;
3151 3338
3152 hdc = my_get_dc (dpyinfo->root_window);
3153
3154 oldobj = SelectObject (hdc, font->hfont);
3155
3156 ok = GetTextMetrics (hdc, &font->tm);
3157
3158 SelectObject (hdc, oldobj);
3159
3160 ReleaseDC (dpyinfo->root_window, hdc);
3161 }
3162
3163 UNBLOCK_INPUT; 3339 UNBLOCK_INPUT;
3164 3340
3165 if (ok) return (font); 3341 if (ok) return (font);
3166 3342
3167 win32_unload_font(dpyinfo, font); 3343 win32_unload_font (dpyinfo, font);
3168 return (NULL); 3344 return (NULL);
3169} 3345}
3170 3346
@@ -3175,7 +3351,7 @@ win32_unload_font (dpyinfo, font)
3175{ 3351{
3176 if (font) 3352 if (font)
3177 { 3353 {
3178 if (font->hfont) DeleteObject(font->hfont); 3354 if (font->hfont) DeleteObject (font->hfont);
3179 xfree (font); 3355 xfree (font);
3180 } 3356 }
3181} 3357}
@@ -3260,7 +3436,11 @@ x_to_win32_weight (lpw)
3260{ 3436{
3261 if (!lpw) return (FW_DONTCARE); 3437 if (!lpw) return (FW_DONTCARE);
3262 3438
3263 if (stricmp (lpw, "bold") == 0) 3439 if (stricmp (lpw, "heavy") == 0)
3440 return (FW_HEAVY);
3441 else if (stricmp (lpw, "extrabold") == 0)
3442 return (FW_EXTRABOLD);
3443 else if (stricmp (lpw, "bold") == 0)
3264 return (FW_BOLD); 3444 return (FW_BOLD);
3265 else if (stricmp (lpw, "demibold") == 0) 3445 else if (stricmp (lpw, "demibold") == 0)
3266 return (FW_SEMIBOLD); 3446 return (FW_SEMIBOLD);
@@ -3268,22 +3448,81 @@ x_to_win32_weight (lpw)
3268 return (FW_MEDIUM); 3448 return (FW_MEDIUM);
3269 else if (stricmp (lpw, "normal") == 0) 3449 else if (stricmp (lpw, "normal") == 0)
3270 return (FW_NORMAL); 3450 return (FW_NORMAL);
3451 else if (stricmp (lpw, "light") == 0)
3452 return (FW_LIGHT);
3453 else if (stricmp (lpw, "extralight") == 0)
3454 return (FW_EXTRALIGHT);
3455 else if (stricmp (lpw, "thin") == 0)
3456 return (FW_THIN);
3271 else 3457 else
3272 return (FW_DONTCARE); 3458 return (FW_DONTCARE);
3273} 3459}
3274 3460
3461
3275char * 3462char *
3276win32_to_x_weight (fnweight) 3463win32_to_x_weight (fnweight)
3277 int fnweight; 3464 int fnweight;
3278{ 3465{
3279 if (fnweight >= FW_BOLD) 3466 if (fnweight >= FW_HEAVY)
3280 return ("bold"); 3467 return "heavy";
3281 else if (fnweight >= FW_SEMIBOLD) 3468 else if (fnweight >= FW_EXTRABOLD)
3282 return ("demibold"); 3469 return "extrabold";
3283 else if (fnweight >= FW_MEDIUM) 3470 else if (fnweight >= FW_BOLD)
3284 return ("medium"); 3471 return "bold";
3285 else 3472 else if (fnweight >= FW_SEMIBOLD)
3286 return ("normal"); 3473 return "semibold";
3474 else if (fnweight >= FW_MEDIUM)
3475 return "medium";
3476 else if (fnweight >= FW_NORMAL)
3477 return "normal";
3478 else if (fnweight >= FW_LIGHT)
3479 return "light";
3480 else if (fnweight >= FW_EXTRALIGHT)
3481 return "extralight";
3482 else if (fnweight >= FW_THIN)
3483 return "thin";
3484 else
3485 return "*";
3486}
3487
3488LONG
3489x_to_win32_charset (lpcs)
3490 char * lpcs;
3491{
3492 if (!lpcs) return (0);
3493
3494 if (stricmp (lpcs, "ansi") == 0)
3495 return (ANSI_CHARSET);
3496 else if (stricmp (lpcs, "iso8859-1") == 0)
3497 return (ANSI_CHARSET);
3498 else if (stricmp (lpcs, "iso8859") == 0)
3499 return (ANSI_CHARSET);
3500 else if (stricmp (lpcs, "oem") == 0)
3501 return (OEM_CHARSET);
3502#ifdef UNICODE_CHARSET
3503 else if (stricmp (lpcs, "unicode") == 0)
3504 return (UNICODE_CHARSET);
3505 else if (stricmp (lpcs, "iso10646") == 0)
3506 return (UNICODE_CHARSET);
3507#endif
3508 else
3509 return (0);
3510}
3511
3512char *
3513win32_to_x_charset (fncharset)
3514 int fncharset;
3515{
3516 switch (fncharset)
3517 {
3518 case ANSI_CHARSET: return "ansi";
3519 case OEM_CHARSET: return "oem";
3520 case SYMBOL_CHARSET: return "symbol";
3521#ifdef UNICODE_CHARSET
3522 case UNICODE_CHARSET: return "unicode";
3523#endif
3524 }
3525 return "*";
3287} 3526}
3288 3527
3289BOOL 3528BOOL
@@ -3294,29 +3533,25 @@ win32_to_x_font (lplogfont, lpxstr, len)
3294{ 3533{
3295 if (!lpxstr) return (FALSE); 3534 if (!lpxstr) return (FALSE);
3296 3535
3297 if (lplogfont) 3536 if (lplogfont)
3298 { 3537 {
3299 int height = (lplogfont->lfHeight * 1440)
3300 / one_win32_display_info.height_in;
3301 int width = (lplogfont->lfWidth * 1440)
3302 / one_win32_display_info.width_in;
3303
3304 height = abs (height);
3305 _snprintf (lpxstr, len - 1, 3538 _snprintf (lpxstr, len - 1,
3306 "-*-%s-%s-%c-%s-%s-*-%d-*-*-%c-%d-*-*-", 3539 "-*-%s-%s-%c-*-*-%d-%d-*-*-%c-%d-*-%s-",
3307 lplogfont->lfFaceName, 3540 lplogfont->lfFaceName,
3308 win32_to_x_weight (lplogfont->lfWeight), 3541 win32_to_x_weight (lplogfont->lfWeight),
3309 lplogfont->lfItalic ? 'i' : 'r', 3542 lplogfont->lfItalic ? 'i' : 'r',
3310 "*", "*", 3543 abs (lplogfont->lfHeight),
3311 height, 3544 (abs (lplogfont->lfHeight) * 720) / one_win32_display_info.height_in,
3312 ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) ? 'p' : 'c', 3545 ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) ? 'p' : 'c',
3313 width); 3546 lplogfont->lfWidth * 10,
3314 } 3547 win32_to_x_charset (lplogfont->lfCharSet)
3315 else 3548 );
3549 }
3550 else
3316 { 3551 {
3317 strncpy (lpxstr, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-", len - 1); 3552 strncpy (lpxstr, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-", len - 1);
3318 } 3553 }
3319 3554
3320 lpxstr[len - 1] = 0; /* just to be sure */ 3555 lpxstr[len - 1] = 0; /* just to be sure */
3321 return (TRUE); 3556 return (TRUE);
3322} 3557}
@@ -3330,56 +3565,119 @@ x_to_win32_font (lpxstr, lplogfont)
3330 3565
3331 memset (lplogfont, 0, sizeof (*lplogfont)); 3566 memset (lplogfont, 0, sizeof (*lplogfont));
3332 3567
3333 lplogfont->lfCharSet = OEM_CHARSET;
3334 lplogfont->lfOutPrecision = OUT_DEFAULT_PRECIS; 3568 lplogfont->lfOutPrecision = OUT_DEFAULT_PRECIS;
3335 lplogfont->lfClipPrecision = CLIP_DEFAULT_PRECIS; 3569 lplogfont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
3336 lplogfont->lfQuality = DEFAULT_QUALITY; 3570 lplogfont->lfQuality = DEFAULT_QUALITY;
3337 3571
3338 if (lpxstr && *lpxstr == '-') lpxstr++; 3572 if (!lpxstr)
3573 return FALSE;
3574
3575 /* Provide a simple escape mechanism for specifying Windows font names
3576 * directly -- if font spec does not beginning with '-', assume this
3577 * format:
3578 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
3579 */
3339 3580
3340 { 3581 if (*lpxstr == '-')
3341 int fields; 3582 {
3342 char name[50], weight[20], slant, pitch, height[10], width[10]; 3583 int fields;
3343 3584 char name[50], weight[20], slant, pitch, pixels[10], height[10], width[10], remainder[20];
3344 fields = (lpxstr 3585 char * encoding;
3345 ? sscanf (lpxstr, 3586
3346 "%*[^-]-%[^-]-%[^-]-%c-%*[^-]-%*[^-]-%*[^-]-%[^-]-%*[^-]-%*[^-]-%c-%[^-]", 3587 fields = sscanf (lpxstr,
3347 name, weight, &slant, height, &pitch, width) 3588 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%*[^-]-%c-%9[^-]-%19s",
3348 : 0); 3589 name, weight, &slant, pixels, height, &pitch, width, remainder);
3349 3590
3350 if (fields == EOF) return (FALSE); 3591 if (fields == EOF) return (FALSE);
3351 3592
3352 if (fields > 0 && name[0] != '*') 3593 if (fields > 0 && name[0] != '*')
3353 { 3594 {
3354 strncpy (lplogfont->lfFaceName, name, LF_FACESIZE); 3595 strncpy (lplogfont->lfFaceName,name, LF_FACESIZE);
3355 } 3596 lplogfont->lfFaceName[LF_FACESIZE-1] = 0;
3356 else 3597 }
3357 { 3598 else
3358 lplogfont->lfFaceName[0] = 0; 3599 lplogfont->lfFaceName[0] = 0;
3600
3601 fields--;
3602
3603 lplogfont->lfWeight = x_to_win32_weight((fields > 0 ? weight : ""));
3604
3605 fields--;
3606
3607 if (!NILP (Vwin32_enable_italics))
3608 lplogfont->lfItalic = (fields > 0 && slant == 'i');
3609
3610 fields--;
3611
3612 if (fields > 0 && pixels[0] != '*')
3613 lplogfont->lfHeight = atoi (pixels);
3614
3615 fields--;
3616
3617 if (fields > 0 && lplogfont->lfHeight == 0 && height[0] != '*')
3618 lplogfont->lfHeight = (atoi (height)
3619 * one_win32_display_info.height_in) / 720;
3620
3621 fields--;
3622
3623 lplogfont->lfPitchAndFamily =
3624 (fields > 0 && pitch == 'p') ? VARIABLE_PITCH : FIXED_PITCH;
3625
3626 fields--;
3627
3628 if (fields > 0 && width[0] != '*')
3629 lplogfont->lfWidth = atoi (width) / 10;
3630
3631 fields--;
3632
3633 /* Not all font specs include the registry field, so we allow for an
3634 optional registry field before the encoding when parsing
3635 remainder. Also we strip the trailing '-' if present. */
3636 {
3637 int len = strlen (remainder);
3638 if (len > 0 && remainder[len-1] == '-')
3639 remainder[len-1] = 0;
3359 } 3640 }
3360 3641 encoding = remainder;
3361 fields--; 3642 if (strncmp (encoding, "*-", 2) == 0)
3362 3643 encoding += 2;
3363 lplogfont->lfWeight = x_to_win32_weight((fields > 0 ? weight : "")); 3644 lplogfont->lfCharSet = x_to_win32_charset (fields > 0 ? encoding : "");
3364 3645 }
3365 fields--; 3646 else
3366 3647 {
3367 lplogfont->lfItalic = (fields > 0 && slant == 'i'); 3648 int fields;
3368 3649 char name[100], height[10], width[10], weight[20];
3369 fields--; 3650
3370 3651 fields = sscanf (lpxstr,
3371 if (fields > 0 && height[0] != '*') 3652 "%99[^:]:%9[^:]:%9[^:]:%19s",
3372 lplogfont->lfHeight = (atoi (height) * one_win32_display_info.height_in) / 1440; 3653 name, height, width, weight);
3373 3654
3374 fields--; 3655 if (fields == EOF) return (FALSE);
3375 3656
3376 lplogfont->lfPitchAndFamily = (fields > 0 && pitch == 'p') ? VARIABLE_PITCH : FIXED_PITCH; 3657 if (fields > 0)
3377 3658 {
3378 fields--; 3659 strncpy (lplogfont->lfFaceName,name, LF_FACESIZE);
3379 3660 lplogfont->lfFaceName[LF_FACESIZE-1] = 0;
3380 if (fields > 0 && width[0] != '*') 3661 }
3381 lplogfont->lfWidth = (atoi (width) * one_win32_display_info.width_in) / 1440; 3662 else
3382 } 3663 {
3664 lplogfont->lfFaceName[0] = 0;
3665 }
3666
3667 fields--;
3668
3669 if (fields > 0)
3670 lplogfont->lfHeight = atoi (height);
3671
3672 fields--;
3673
3674 if (fields > 0)
3675 lplogfont->lfWidth = atoi (width);
3676
3677 fields--;
3678
3679 lplogfont->lfWeight = x_to_win32_weight ((fields > 0 ? weight : ""));
3680 }
3383 3681
3384 return (TRUE); 3682 return (TRUE);
3385} 3683}
@@ -3573,7 +3871,7 @@ even if they match PATTERN and FACE.")
3573 ef.numFonts = 0; 3871 ef.numFonts = 0;
3574 3872
3575 { 3873 {
3576 ef.hdc = my_get_dc (FRAME_WIN32_WINDOW (f)); 3874 ef.hdc = GetDC (FRAME_WIN32_WINDOW (f));
3577 3875
3578 EnumFontFamilies (ef.hdc, NULL, (FONTENUMPROC) enum_font_cb1, (LPARAM)&ef); 3876 EnumFontFamilies (ef.hdc, NULL, (FONTENUMPROC) enum_font_cb1, (LPARAM)&ef);
3579 3877
@@ -3759,9 +4057,11 @@ If omitted or nil, that stands for the selected frame's display.")
3759 HDC hdc; 4057 HDC hdc;
3760 int cap; 4058 int cap;
3761 4059
3762 hdc = my_get_dc (dpyinfo->root_window); 4060 hdc = GetDC (dpyinfo->root_window);
3763 4061 if (dpyinfo->has_palette)
3764 cap = GetDeviceCaps (hdc,NUMCOLORS); 4062 cap = GetDeviceCaps (hdc, SIZEPALETTE);
4063 else
4064 cap = GetDeviceCaps (hdc, NUMCOLORS);
3765 4065
3766 ReleaseDC (dpyinfo->root_window, hdc); 4066 ReleaseDC (dpyinfo->root_window, hdc);
3767 4067
@@ -3840,10 +4140,8 @@ If omitted or nil, that stands for the selected frame's display.")
3840 HDC hdc; 4140 HDC hdc;
3841 int cap; 4141 int cap;
3842 4142
3843 hdc = my_get_dc (dpyinfo->root_window); 4143 hdc = GetDC (dpyinfo->root_window);
3844
3845 cap = GetDeviceCaps (hdc, VERTSIZE); 4144 cap = GetDeviceCaps (hdc, VERTSIZE);
3846
3847 ReleaseDC (dpyinfo->root_window, hdc); 4145 ReleaseDC (dpyinfo->root_window, hdc);
3848 4146
3849 return make_number (cap); 4147 return make_number (cap);
@@ -3862,10 +4160,8 @@ If omitted or nil, that stands for the selected frame's display.")
3862 HDC hdc; 4160 HDC hdc;
3863 int cap; 4161 int cap;
3864 4162
3865 hdc = my_get_dc (dpyinfo->root_window); 4163 hdc = GetDC (dpyinfo->root_window);
3866
3867 cap = GetDeviceCaps (hdc, HORZSIZE); 4164 cap = GetDeviceCaps (hdc, HORZSIZE);
3868
3869 ReleaseDC (dpyinfo->root_window, hdc); 4165 ReleaseDC (dpyinfo->root_window, hdc);
3870 4166
3871 return make_number (cap); 4167 return make_number (cap);
@@ -4014,12 +4310,22 @@ terminate Emacs if we can't open the connection.")
4014 unsigned int n_planes; 4310 unsigned int n_planes;
4015 unsigned char *xrm_option; 4311 unsigned char *xrm_option;
4016 struct win32_display_info *dpyinfo; 4312 struct win32_display_info *dpyinfo;
4313 Lisp_Object color_file = Qnil;
4017 4314
4018 CHECK_STRING (display, 0); 4315 CHECK_STRING (display, 0);
4019 if (! NILP (xrm_string)) 4316 if (! NILP (xrm_string))
4020 CHECK_STRING (xrm_string, 1); 4317 CHECK_STRING (xrm_string, 1);
4021 4318
4022 Vwin32_color_map = Fwin32_default_color_map (); 4319 /* Allow color mapping to be defined externally; first look in user's
4320 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
4321 color_file = build_string ("~/rgb.txt");
4322 if (NILP (color_file) || NILP (Ffile_readable_p (color_file)))
4323 color_file = concat2 (Vdoc_directory, build_string ("rgb.txt"));
4324
4325 Vwin32_color_map = Fwin32_load_color_file (color_file);
4326
4327 if (NILP (Vwin32_color_map))
4328 Vwin32_color_map = Fwin32_default_color_map ();
4023 4329
4024 if (! NILP (xrm_string)) 4330 if (! NILP (xrm_string))
4025 xrm_option = (unsigned char *) XSTRING (xrm_string)->data; 4331 xrm_option = (unsigned char *) XSTRING (xrm_string)->data;
@@ -4039,8 +4345,7 @@ terminate Emacs if we can't open the connection.")
4039 if (dpyinfo == 0) 4345 if (dpyinfo == 0)
4040 { 4346 {
4041 if (!NILP (must_succeed)) 4347 if (!NILP (must_succeed))
4042 fatal ("Cannot connect to server %s.\n", 4348 fatal ("Cannot connect to server %s.\n", XSTRING (display)->data);
4043 XSTRING (display)->data);
4044 else 4349 else
4045 error ("Cannot connect to server %s", XSTRING (display)->data); 4350 error ("Cannot connect to server %s", XSTRING (display)->data);
4046 } 4351 }
@@ -4131,7 +4436,7 @@ DEFUN ("win32-select-font", Fwin32_select_font, Swin32_select_font, 0, 1, 0,
4131 cf.lpLogFont = &lf; 4436 cf.lpLogFont = &lf;
4132 4437
4133 if (!ChooseFont (&cf) || !win32_to_x_font (&lf, buf, 100)) 4438 if (!ChooseFont (&cf) || !win32_to_x_font (&lf, buf, 100))
4134 return Qnil; 4439 return Qnil;
4135 4440
4136 return build_string (buf); 4441 return build_string (buf);
4137} 4442}
@@ -4219,6 +4524,14 @@ syms_of_win32fns ()
4219 "A array of color name mappings for windows."); 4524 "A array of color name mappings for windows.");
4220 Vwin32_color_map = Qnil; 4525 Vwin32_color_map = Qnil;
4221 4526
4527 DEFVAR_LISP ("win32-enable-italics", &Vwin32_enable_italics,
4528 "Non-nil enables selection of artificially italicized fonts.");
4529 Vwin32_enable_italics = Qnil;
4530
4531 DEFVAR_LISP ("win32-enable-palette", &Vwin32_enable_palette,
4532 "Non-nil enables Windows palette management to map colors exactly.");
4533 Vwin32_enable_palette = Qt;
4534
4222 init_x_parm_symbols (); 4535 init_x_parm_symbols ();
4223 4536
4224 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path, 4537 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path,
@@ -4294,6 +4607,8 @@ unless you set it to something else.");
4294 /* Win32 specific functions */ 4607 /* Win32 specific functions */
4295 4608
4296 defsubr (&Swin32_select_font); 4609 defsubr (&Swin32_select_font);
4610 defsubr (&Swin32_define_rgb_color);
4611 defsubr (&Swin32_load_color_file);
4297} 4612}
4298 4613
4299#undef abort 4614#undef abort
@@ -4301,9 +4616,9 @@ unless you set it to something else.");
4301void 4616void
4302win32_abort() 4617win32_abort()
4303{ 4618{
4304 MessageBox (NULL, 4619 MessageBox (NULL,
4305 "A fatal error has occurred - aborting!", 4620 "A fatal error has occurred - aborting!",
4306 "Emacs Abort Dialog", 4621 "Emacs Abort Dialog",
4307 MB_OK|MB_ICONEXCLAMATION); 4622 MB_OK | MB_ICONEXCLAMATION);
4308 abort(); 4623 abort();
4309} 4624}