emacs-devel
[Top][All Lists]
Advanced

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

Re: display word wrapping


From: Juanma Barranquero
Subject: Re: display word wrapping
Date: Wed, 02 Jun 2004 17:04:45 +0200

On 31 May 2004 22:18:39 +0200
address@hidden (Kim F. Storm) wrote:

> Both term/w32-win.el and .emacs are read before loading the
> splash screen.  In addition, IIRC, PBM support is built-in
> even on w32.  So it should work.

There's a first cut of implementing that.  The patch seems bigger than
it is, because I've had to extract functionality from init_image and
move it to a new function.

With this patch term/w32-win.el sets the new variable
`w32-image-libraries-alist'.

There's a new `init-image-libraries' which can be called to load all
image libraries. This is called from `init_image' on non-Windows environments,
and does not depend on the alist (so nothing changes). On Windows it
uses the variable, and can be called... where? This is my biggest doubt. If
I call `init-image-libraries' from my .emacs, for example, the splash
screen is shown correctly. But there's no way the user must be
responsible for calling it. So, where should it be called so it is done
automatically on Windows, but *after* loading .emacs?

Another question: currently, I'm not checking whether the func is called
several times. Should it check it and refuse, or allow it (and, in this
case, get sure that image-types is checked before adding image-type
symbols to it)?

I've used the same machinery to load zlib, because libpng12 and libtiff3
need it, and it also can appear under several names (at least zlib1.dll
and zlib.dll are common).

                                                                Juanma



--- image.c.orig        2004-06-02 10:50:59.000000000 +0200
+++ image.c     2004-06-02 16:45:23.000000000 +0200
@@ -63,4 +63,6 @@
 #include "w32term.h"
 
+Lisp_Object Vw32_image_libraries_alist;
+
 /* W32_TODO : Color tables on W32.  */
 #undef COLOR_TABLE_SUPPORT
@@ -1789,4 +1791,31 @@
   }
 
+/* Load a DLL implementing an image type.
+   The `w32-image-libraries-alist' variable associates a symbol,
+   identifying  an image type, to a list of possible filenames.
+   The function returns NULL if no library could be loaded for
+   the given image type, else the handle of the DLL.  */
+static HMODULE
+w32_dynaload (Lisp_Object library_id)
+{
+  HMODULE library = NULL;
+  Lisp_Object dll_list;
+
+  dll_list = Fassq (library_id, Vw32_image_libraries_alist);
+
+  if (CONSP (dll_list))
+    for (dll_list = XCDR (dll_list); !NILP (dll_list); dll_list = XCDR 
(dll_list))
+      {
+        Lisp_Object lib = XCAR (dll_list);
+
+        if (!STRINGP (lib))
+          error ("Library name is not a string");
+        else if (library = LoadLibrary (SDATA (lib)))
+          break;
+      }
+
+  return library;
+}
+
 #endif /* HAVE_NTGUI */
 
@@ -3495,5 +3522,5 @@
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libXpm.dll")))
+  if (!(library = w32_dynaload (Qxpm)))
     return 0;
 
@@ -5490,4 +5517,9 @@
 Lisp_Object Qpng;
 
+#ifndef NEED_ZLIB
+Lisp_Object Qzlib;
+#define NEED_ZLIB
+#endif
+
 /* Indices of image specification fields in png_format, below.  */
 
@@ -5593,15 +5625,10 @@
   HMODULE library;
 
-  /* Ensure zlib is loaded.  Try debug version first.  */
-  if (!LoadLibrary ("zlibd.dll")
-      && !LoadLibrary ("zlib.dll"))
+  /* Ensure zlib is loaded.  */
+  if (!w32_dynaload (Qzlib))
     return 0;
 
   /* Try loading libpng under probable names.  */
-  if (!(library = LoadLibrary ("libpng13d.dll"))
-      && !(library = LoadLibrary ("libpng13.dll"))
-      && !(library = LoadLibrary ("libpng12d.dll"))
-      && !(library = LoadLibrary ("libpng12.dll"))
-      && !(library = LoadLibrary ("libpng.dll")))
+  if (!(library = w32_dynaload (Qpng)))
     return 0;
 
@@ -6251,7 +6278,5 @@
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libjpeg.dll"))
-      && !(library = LoadLibrary ("jpeg-62.dll"))
-      && !(library = LoadLibrary ("jpeg.dll")))
+  if (!(library = w32_dynaload (Qjpeg)))
     return 0;
 
@@ -6605,4 +6630,9 @@
 Lisp_Object Qtiff;
 
+#ifndef NEED_ZLIB
+Lisp_Object Qzlib;
+#define NEED_ZLIB
+#endif
+
 /* Indices of image specification fields in tiff_format, below.  */
 
@@ -6688,5 +6718,9 @@
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libtiff.dll")))
+  /* Ensure zlib is loaded.  */
+  if (!w32_dynaload (Qzlib))
+    return 0;
+
+  if (!(library = w32_dynaload (Qtiff)))
     return 0;
 
@@ -7108,5 +7142,5 @@
   HMODULE library;
 
-  if (!(library = LoadLibrary ("libungif.dll")))
+  if (!(library = w32_dynaload (Qgif)))
     return 0;
 
@@ -7881,4 +7915,58 @@
  ***********************************************************************/
 
+#ifdef HAVE_NTGUI
+/* Image types that rely on external libraries are loaded dynamically
+   if the library is available.  */
+#define IF_LIB_AVAILABLE(init_lib_fn)  if (init_lib_fn())
+#else
+#define IF_LIB_AVAILABLE(init_func)    /* Load unconditionally */
+#endif /* HAVE_NTGUI */
+
+DEFUN ("init-image-libraries", Finit_image_libraries, Sinit_image_libraries, 
0, 0, 0,
+       doc: /* Initialize image libraries.
+Image types pbm and xbm are prebuilt; other types are loaded here.
+On Windows, what gets loaded depends on the value of the variable
+`w32-image-libraries-alist'.  */)
+     ()
+{
+
+#if defined (HAVE_XPM) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_xpm_functions)
+    define_image_type (&xpm_type);
+#endif
+
+#if defined (HAVE_JPEG) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_jpeg_functions)
+    define_image_type (&jpeg_type);
+#endif
+
+#if defined (HAVE_TIFF) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_tiff_functions)
+    define_image_type (&tiff_type);
+#endif
+
+#if defined (HAVE_GIF) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_gif_functions)
+    define_image_type (&gif_type);
+#endif
+
+#if defined (HAVE_PNG) || defined (MAC_OS)
+  IF_LIB_AVAILABLE(init_png_functions)
+    define_image_type (&png_type);
+#endif
+
+#ifdef HAVE_GHOSTSCRIPT
+  define_image_type (&gs_type);
+#endif
+
+#ifdef MAC_OS
+  /* Animated gifs use QuickTime Movie Toolbox.  So initialize it here. */
+  EnterMovies ();
+#ifdef MAC_OSX
+  init_image_func_pointer ();
+#endif
+#endif
+}
+
 void
 syms_of_image ()
@@ -7958,4 +8046,10 @@
 #endif
 
+#if defined (NEED_ZLIB)
+  Qzlib = intern ("zlib");
+  staticpro (&Qzlib);
+#endif
+
+  defsubr (&Sinit_image_libraries);
   defsubr (&Sclear_image_cache);
   defsubr (&Simage_size);
@@ -7983,14 +8077,17 @@
 meaning don't clear the cache.  */);
   Vimage_cache_eviction_delay = make_number (30 * 60);
-}
-
 
 #ifdef HAVE_NTGUI
-/* Image types that rely on external libraries are loaded dynamically
-   if the library is available.  */
-#define IF_LIB_AVAILABLE(init_lib_fn)  if (init_lib_fn())
-#else
-#define IF_LIB_AVAILABLE(init_func)    /* Load unconditionally */
-#endif /* HAVE_NTGUI */
+  DEFVAR_LISP ("w32-image-libraries-alist", &Vw32_image_libraries_alist,
+   doc: /* Alist of image-types vs external libraries needed to display them.
+Each element is a list (IMAGE-TYPE LIBRARY...), where the car is a symbol
+representing a supported image type, and the rest are strings giving
+alternate filenames for the corresponding external libraries to load.
+They are tried in the order they appear on the list; if none of them can
+be loaded, the running session of Emacs won't display the image type.
+No entries are needed for pbm and xbm images; they're always supported.  */);
+  Vw32_image_libraries_alist = Qnil;
+#endif
+}
 
 void
@@ -8003,39 +8100,8 @@
   define_image_type (&pbm_type);
 
-#if defined (HAVE_XPM) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_xpm_functions)
-    define_image_type (&xpm_type);
-#endif
-
-#if defined (HAVE_JPEG) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_jpeg_functions)
-    define_image_type (&jpeg_type);
-#endif
-
-#if defined (HAVE_TIFF) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_tiff_functions)
-    define_image_type (&tiff_type);
-#endif
-
-#if defined (HAVE_GIF) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_gif_functions)
-    define_image_type (&gif_type);
-#endif
-
-#if defined (HAVE_PNG) || defined (MAC_OS)
-  IF_LIB_AVAILABLE(init_png_functions)
-    define_image_type (&png_type);
-#endif
-
-#ifdef HAVE_GHOSTSCRIPT
-  define_image_type (&gs_type);
-#endif
-
-#ifdef MAC_OS
-  /* Animated gifs use QuickTime Movie Toolbox.  So initialize it here. */
-  EnterMovies ();
-#ifdef MAC_OSX
-  init_image_func_pointer ();
-#endif
+#ifndef HAVE_NTGUI
+  /* For now, delayed loading of image libraries is only needed
+     or useful on Windows.  */
+  Finit_image_libraries ();
 #endif
 }
--- term/w32-win.el.orig        2004-06-02 16:34:20.000000000 +0200
+++ term/w32-win.el     2004-06-02 16:48:08.000000000 +0200
@@ -1262,4 +1262,16 @@
            (error "Font not found")))))
 
+;;; Set default known names for image libraries
+(setq w32-image-libraries-alist
+      '((xpm "libXpm-nox4.dll" "libxpm.dll")
+        (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" 
"libpng.dll")
+        (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
+        (tiff "libtiff3.dll" "libtiff.dll")
+        (gif "libungif.dll")
+        ;; A trick: some libraries need to preload zlib, which can appear 
under several
+        ;; names, so we reuse the machinery
+        (zlib "zlib1.dll" "zlibd.dll" "zlib.dll")))
+(put 'w32-image-libraries-alist 'risky-local-variable t)
+
 ;;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
 ;;; w32-win.el ends here





reply via email to

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