emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f37000a: Support (locale-info 'paper) on MS-Windows


From: Eli Zaretskii
Subject: [Emacs-diffs] master f37000a: Support (locale-info 'paper) on MS-Windows
Date: Mon, 4 Feb 2019 11:09:58 -0500 (EST)

branch: master
commit f37000aeb2b987c0fb14b6770fef69eaf274167a
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Support (locale-info 'paper) on MS-Windows
    
    * src/w32proc.c (LOCALE_IPAPERSIZE): Define if undefined.
    (nl_langinfo): Support _NL_PAPER_WIDTH and _NL_PAPER_HEIGHT
    like glibc does.
    * src/fns.c (Flocale_info): Update the doc string.
    
    * nt/inc/langinfo.h: Add _NL_PAPER_WIDTH and _NL_PAPER_HEIGHT
    to the enumeration.
    (_NL_PAPER_WIDTH, _NL_PAPER_HEIGHT): Define namesake macros.
    * nt/mingw-cfg.site (emacs_cv_langinfo__nl_paper_width): Set
    to 'yes'.
    
    * doc/lispref/nonascii.texi (Locales): Update the
    documentation of 'locale-info' for the argument of 'paper'.
    
    * etc/NEWS: Update the locale-info entry.
---
 doc/lispref/nonascii.texi |  6 +++---
 etc/NEWS                  |  8 +++++---
 nt/inc/langinfo.h         |  4 ++++
 nt/mingw-cfg.site         |  1 +
 src/fns.c                 |  5 +++--
 src/w32proc.c             | 38 ++++++++++++++++++++++++++++++++++++--
 6 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi
index 56d96cf..ae9a8ab 100644
--- a/doc/lispref/nonascii.texi
+++ b/doc/lispref/nonascii.texi
@@ -2115,9 +2115,9 @@ Return a 12-element vector of month names (locale items 
@code{MON_1}
 through @code{MON_12}).
 
 @item paper
-Return a list @code{(@var{width} @var{height})} for the default paper
-size measured in millimeters (locale items @code{PAPER_WIDTH} and
address@hidden).
+Return a list @address@hidden(@var{width} @var{height})}} of 2 integers, for
+the default paper size measured in millimeters (locale items
address@hidden and @code{_NL_PAPER_HEIGHT}).
 @end table
 
 If the system can't provide the requested information, or if
diff --git a/etc/NEWS b/etc/NEWS
index bbfc328..a9c009e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1533,12 +1533,14 @@ systems, the XRender extension to X11 is required for 
this to be
 available; the configure script will test for it and, if found, enable
 scaling.)
 
-+++
-** (locale-info 'paper) now returns the paper size on GNUish hosts.
-
 The new function 'image-scaling-p' can be used to test whether any
 given frame supports resizing.
 
++++
+** (locale-info 'paper) now returns the paper size on systems that support it.
+This is currently supported on GNUish hosts and on modern versions of
+MS-Windows.
+
 
 * Changes in Emacs 27.1 on Non-Free Operating Systems
 
diff --git a/nt/inc/langinfo.h b/nt/inc/langinfo.h
index fc69068..6c4959e 100644
--- a/nt/inc/langinfo.h
+++ b/nt/inc/langinfo.h
@@ -27,6 +27,7 @@ enum {
   DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7,
   MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10,
   MON_11, MON_12,
+  _NL_PAPER_WIDTH, _NL_PAPER_HEIGHT,
 
   /* Number of enumerated values.  */
   _NL_NUM
@@ -55,6 +56,9 @@ enum {
 #define MON_11 MON_11
 #define MON_12 MON_12
 
+#define _NL_PAPER_WIDTH  _NL_PAPER_WIDTH
+#define _NL_PAPER_HEIGHT _NL_PAPER_HEIGHT
+
 extern char *nl_langinfo (nl_item);
 
 #endif /* _LANGINFO_H */
diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site
index d9a8240..4df2049 100644
--- a/nt/mingw-cfg.site
+++ b/nt/mingw-cfg.site
@@ -109,6 +109,7 @@ gl_cv_func_pthread_sigmask_return_works=yes
 gl_cv_func_pthread_sigmask_unblock_works="not relevant"
 # Implemented in w32proc.c
 emacs_cv_langinfo_codeset=yes
+emacs_cv_langinfo__nl_paper_width=yes
 # Declared in ms-w32.h
 ac_cv_have_decl_alarm=yes
 # Avoid including the gnulib dup2 module
diff --git a/src/fns.c b/src/fns.c
index a7279b1..95bafae 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3100,8 +3100,9 @@ ITEM should be one of the following:
 
 `months', returning a 12-element vector of month names (locale items MON_n);
 
-`paper', returning a list (WIDTH HEIGHT) for the default paper size,
-  both measured in millimeters (locale items PAPER_WIDTH, PAPER_HEIGHT).
+`paper', returning a list of 2 integers (WIDTH HEIGHT) for the default
+  paper size, both measured in millimeters (locale items _NL_PAPER_WIDTH,
+  _NL_PAPER_HEIGHT).
 
 If the system can't provide such information through a call to
 `nl_langinfo', or if ITEM isn't from the list above, return nil.
diff --git a/src/w32proc.c b/src/w32proc.c
index 05e6c46..ab0bf0f 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -3248,6 +3248,12 @@ such programs cannot be invoked by Emacs anyway.  */)
 }
 
 #ifdef HAVE_LANGINFO_CODESET
+
+/* If we are compiling for compatibility with older 32-bit Windows
+   versions, this might not be defined by the Windows headers.  */
+#ifndef LOCALE_IPAPERSIZE
+# define LOCALE_IPAPERSIZE 0x100A
+#endif
 /* Emulation of nl_langinfo.  Used in fns.c:Flocale_info.  */
 char *
 nl_langinfo (nl_item item)
@@ -3260,7 +3266,8 @@ nl_langinfo (nl_item item)
     LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3,
     LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6,
     LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8, LOCALE_SMONTHNAME9,
-    LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12
+    LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12,
+    LOCALE_IPAPERSIZE, LOCALE_IPAPERSIZE
   };
 
   static char *nl_langinfo_buf = NULL;
@@ -3269,6 +3276,8 @@ nl_langinfo (nl_item item)
   if (nl_langinfo_len <= 0)
     nl_langinfo_buf = xmalloc (nl_langinfo_len = 1);
 
+  char *retval = nl_langinfo_buf;
+
   if (item < 0 || item >= _NL_NUM)
     nl_langinfo_buf[0] = 0;
   else
@@ -3290,6 +3299,8 @@ nl_langinfo (nl_item item)
          if (nl_langinfo_len <= need_len)
            nl_langinfo_buf = xrealloc (nl_langinfo_buf,
                                        nl_langinfo_len = need_len);
+         retval = nl_langinfo_buf;
+
          if (!GetLocaleInfo (cloc, w32item[item] | LOCALE_USE_CP_ACP,
                              nl_langinfo_buf, nl_langinfo_len))
            nl_langinfo_buf[0] = 0;
@@ -3306,9 +3317,32 @@ nl_langinfo (nl_item item)
                  nl_langinfo_buf[1] = 'p';
                }
            }
+         else if (item == _NL_PAPER_WIDTH || item == _NL_PAPER_HEIGHT)
+           {
+             static const int paper_size[][2] =
+               {
+                { -1, -1 },
+                { 216, 279 },
+                { -1, -1 },
+                { -1, -1 },
+                { -1, -1 },
+                { 216, 356 },
+                { -1, -1 },
+                { -1, -1 },
+                { 297, 420 },
+                { 210, 297 }
+               };
+             int idx = atoi (nl_langinfo_buf);
+             if (0 <= idx && idx < ARRAYELTS (paper_size))
+               retval = (char *)(intptr_t) (item == _NL_PAPER_WIDTH
+                                            ? paper_size[idx][0]
+                                            : paper_size[idx][1]);
+             else
+               retval = (char *)(intptr_t) -1;
+           }
        }
     }
-  return nl_langinfo_buf;
+  return retval;
 }
 #endif /* HAVE_LANGINFO_CODESET */
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]