emacs-devel
[Top][All Lists]
Advanced

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

Re: Emacs Mac port


From: YAMAMOTO Mitsuharu
Subject: Re: Emacs Mac port
Date: Sat, 30 Apr 2016 14:57:54 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shij┼Ź) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Sat, 23 Apr 2016 08:51:45 +0900, YAMAMOTO Mitsuharu <address@hidden> 
>>>>> said:

> The ninth update of the Mac port based on Emacs 24.5 is available from
>   ftp://ftp.math.s.chiba-u.ac.jp/emacs/emacs-24.5-mac-5.16.tar.gz

This release was mainly intended for enhancement on Retina display
environments, but actually there was a nasty bug in that part when the
Mac port was compiled with ImageMagick.  I've just made another
release:

  ftp://ftp.math.s.chiba-u.ac.jp/emacs/emacs-24.5-mac-5.17.tar.gz

The only changed file is `patch-mac'.  So, if you still have a build
tree, then you can just unapply the `patch-mac' file in the previous
version and apply the new one.  Sorry for the inconvenience.

> and Git repository is also available at

>   https://bitbucket.org/mituharu/emacs-mac.git

> A bare development branch (no documentation updates yet) based on the
> pretest versions of Emacs 25.1 is also available from the "work"
> branch of the above repository.

** Fixed bugs

*** Shrunken image size on a Retina display is wrong if it is created
from the raw data using genuine ImageMagick.
Reported by Sean Farley.

** Improvements

*** When you create an image from the raw data as opposed to a file,
you can now provide 2x data for high-resolution environments via the
`:data-2x' property.  It can be specified either as a property of the
image descriptor or as a text property of the first character of the
standard resolution data (if it is given as a string).


> The patch below is a quick hack (see the "XXX" comment below) for PDF
> Tools to display 2x images on Retina display.

Also, I made the patch below for preview-latex in AUCTeX so preview
images look fine on Retina displays.  It now makes Ghostscript
generate PDF files instead of PNG ones, and let the Mac port render
them using the `image-io' image type via PDFKit.  So moving a frame
between Retina and non-Retina displays works gracefully unlike my
previous patch for PDF Tools.

                                     YAMAMOTO Mitsuharu
                                address@hidden

diff --git a/preview.el.in b/preview.el.in
index 8a58104..48f0608 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -188,7 +188,10 @@ spec to avoid unnecessary evaluation time."
          (close preview-gs-close))
     (tiff (open preview-gs-open)
          (place preview-gs-place)
-         (close preview-gs-close)))
+         (close preview-gs-close))
+    (image-io (open preview-gs-open)
+             (place preview-gs-place)
+             (close preview-gs-close)))
   "Define functions for generating images.
 These functions get called in the process of generating inline
 images of the specified type.  The open function is called
@@ -218,17 +221,23 @@ function args" :inline t sexp))
     (dvipng png "-sDEVICE=png16m")
     (jpeg jpeg "-sDEVICE=jpeg")
     (pnm pbm "-sDEVICE=pnmraw")
-    (tiff tiff "-sDEVICE=tiff12nc"))
+    (tiff tiff "-sDEVICE=tiff12nc")
+    (image-io (image-io pdf t) "-sDEVICE=pdfwrite"))
   "*Alist of image types and corresponding Ghostscript options.
 The `dvipng' and `postscript' (don't use) entries really specify
 a fallback device when images can't be processed by the requested
 method, like when PDFTeX was used."
   :group 'preview-gs
   :type '(repeat (list :tag nil (symbol :tag "preview image-type")
-                      (symbol :tag "Emacs image-type")
+                      (choice (symbol :tag "Emacs image-type")
+                              (list :tag "Extended setting"
+                                    (symbol :tag "Emacs image-type")
+                                    (symbol :tag "File name extension")
+                                    (boolean :tag "Produces vector output")))
                       (repeat :inline t :tag "Ghostscript options" string))))
 
-(defcustom preview-image-type 'png
+(defcustom preview-image-type
+  (if (preview-supports-image-type 'image-io) 'image-io 'png)
   "*Image type to be used in images."
   :group 'preview-gs
   :type (append '(choice)
@@ -372,6 +381,13 @@ See also `preview-gs-command'."
   :group 'preview-gs
   :type '(repeat string))
 
+(defcustom preview-gs-vector-options '("-q" "-dDELAYSAFER" "-dNOPAUSE"
+                                      "-DNOPLATFONTS" "-dPrinted")
+  "*Like `preview-gs-options', but used when gs produces vector outputs.
+See also `preview-gs-command'."
+  :group 'preview-gs
+  :type '(repeat string))
+
 (defvar preview-gs-queue nil
   "List of overlays to convert using gs.
 Buffer-local to the appropriate TeX process buffer.")
@@ -406,6 +422,14 @@ follow changes in the displayed buffer area faster."
   "Image type for gs produced images.")
 (make-variable-buffer-local 'preview-gs-image-type)
 
+(defvar preview-gs-image-extension nil
+  "Image file name extension for gs produced images.")
+(make-variable-buffer-local 'preview-gs-image-extension)
+
+(defvar preview-gs-image-vector-p nil
+  "Non-nil if gs produces vector output images.")
+(make-variable-buffer-local 'preview-gs-image-vector-p)
+
 (defvar preview-gs-sequence nil
   "Pair of sequence numbers for gs produced images.")
 (make-variable-buffer-local 'preview-gs-sequence)
@@ -696,7 +720,7 @@ Gets the usual PROCESS and STRING parameters, see
                             (format "%s/pr%d-%%d.%s"
                                     (car TeX-active-tempdir)
                                     (car preview-gs-sequence)
-                                    preview-gs-image-type))))
+                                    preview-gs-image-extension))))
           (process
            (apply #'start-process
                   "Preview-Ghostscript"
@@ -726,11 +750,20 @@ Gets the usual PROCESS and STRING parameters, see
 (defun preview-gs-open (&optional setup)
   "Start a Ghostscript conversion pass.
 SETUP may contain a parser setup function."
-  (let ((image-info (assq preview-image-type preview-gs-image-type-alist)))
-    (setq preview-gs-image-type (nth 1 image-info))
+  (let* ((image-info (assq preview-image-type preview-gs-image-type-alist))
+        (image-type-info (nth 1 image-info)))
+    (if (not (consp image-type-info))
+       (setq preview-gs-image-type image-type-info
+             preview-gs-image-extension image-type-info
+             preview-gs-image-vector-p nil)
+      (setq preview-gs-image-type (nth 0 image-type-info)
+           preview-gs-image-extension (nth 1 image-type-info)
+           preview-gs-image-vector-p (nth 2 image-type-info)))
     (setq preview-gs-sequence nil)
     (setq preview-gs-command-line (append
-                                  preview-gs-options
+                                  (if (not preview-gs-image-vector-p)
+                                      preview-gs-options
+                                    preview-gs-vector-options)
                                   (nthcdr 2 image-info))
          preview-gs-init-string
          (format "{DELAYSAFER{.setsafe}if}stopped pop\
@@ -833,7 +866,7 @@ Pure borderless black-on-white will return an empty string."
     (let ((process (preview-start-dvips preview-fast-conversion)))
       (setq TeX-sentinel-function #'preview-gs-dvips-sentinel)
       (list process (current-buffer) TeX-active-tempdir preview-ps-file
-           preview-gs-image-type))))
+           preview-gs-image-extension))))
 
 (defun preview-dvipng-process-setup ()
   "Set up dvipng process for conversion."
@@ -861,7 +894,7 @@ Pure borderless black-on-white will return an empty string."
   (let ((process (preview-start-pdf2dsc)))
     (setq TeX-sentinel-function #'preview-pdf2dsc-sentinel)
     (list process (current-buffer) TeX-active-tempdir preview-ps-file
-         preview-gs-image-type)))
+         preview-gs-image-extension)))
 
 (defun preview-dvips-abort ()
   "Abort a Dvips run."
@@ -1248,11 +1281,13 @@ given as ANSWER."
              (overlay-put ov 'filenames (cdr filenames))
              (preview-replace-active-icon
               ov
-              (preview-create-icon (car newfile)
-                                   preview-gs-image-type
-                                   (preview-ascent-from-bb
-                                    bbox)
-                                   (aref preview-colors 2))))
+              (apply #'preview-create-icon
+                     (car newfile)
+                     preview-gs-image-type
+                     (preview-ascent-from-bb bbox)
+                     (aref preview-colors 2)
+                     (and preview-gs-image-vector-p
+                          (list (preview-size-from-bb bbox))))))
            (overlay-put ov 'queued nil)))))
     (while (and (< (length preview-gs-outstanding)
                   preview-gs-outstanding-limit)
@@ -1269,7 +1304,7 @@ given as ANSWER."
                                             (format "pr%d-%d.%s"
                                                     (car preview-gs-sequence)
                                                     (cdr preview-gs-sequence)
-                                                    preview-gs-image-type)
+                                                    preview-gs-image-extension)
                                             TeX-active-tempdir))))))
                 (bbox (aset queued 0
                             (or (and preview-prefer-TeX-bb
@@ -1459,6 +1494,24 @@ numbers (can be float if available)."
        (round (* 100.0 (/ (- top 720.0) (- top bottom))))
       100)))
 
+(defun preview-size-from-bb (bb)
+  "This calculates the image pixel size from its bounding box.
+When the ghostscript device produces vector outputs, the `-r'
+option does not change the page size of the produced output, but
+specifies the resolution for pattern fills and fonts that must be
+converted to bitmaps.  This function is used for calculating the
+size in pixels from the value passed to the `-r' option and the
+given bounding box."
+  (let ((res '(72.0 . 72.0)))
+    (dolist (option preview-gs-command-line)
+      (if (string-match "\\`-r\\([0-9.]+\\)x\\([0-9.]+\\)\\'" option)
+         (setq res (cons (string-to-number (match-string 1 option))
+                         (string-to-number (match-string 2 option))))))
+    (cons (round (* (- (aref bb 2) (aref bb 0))
+                   (/ (car res) 72.0)))
+         (round (* (- (aref bb 3) (aref bb 1))
+                   (/ (cdr res) 72.0))))))
+
 (defface preview-face '((((background dark))
                         (:background "dark slate gray"))
                        (t
@@ -3556,6 +3609,7 @@ If not a regular release, the date of the last change.")
        preview-pdf2dsc-command
        preview-gs-command
        preview-gs-options
+       preview-gs-vector-options
        preview-gs-image-type-alist
        preview-fast-conversion
        preview-prefer-TeX-bb
diff --git a/prv-emacs.el b/prv-emacs.el
index 9f40736..07c4018 100644
--- a/prv-emacs.el
+++ b/prv-emacs.el
@@ -80,19 +80,20 @@ Consults `preview-transparent-color'."
                          (nth 1 preview-transparent-color)
                          'default)))))
 
-(defsubst preview-create-icon-1 (file type ascent border)
+(defsubst preview-create-icon-1 (file type ascent border &optional size)
   `(image
     :file ,file
     :type ,type
     :ascent ,ascent
     ,@(and border
-          '(:mask (heuristic t)))))
+          '(:mask (heuristic t)))
+    ,@(and size
+          `(:width ,(car size) :height ,(cdr size)))))
 
-(defun preview-create-icon (file type ascent border)
+(defun preview-create-icon (file type ascent border &optional size)
   "Create an icon from FILE, image TYPE, ASCENT and BORDER."
-  (list
-   (preview-create-icon-1 file type ascent border)
-   file type ascent border))
+  `(,(preview-create-icon-1 file type ascent border size)
+    ,file ,type ,ascent ,border ,@(and size (list size))))
 
 (put 'preview-filter-specs :type
      #'(lambda (keyword value &rest args)
@@ -590,7 +591,8 @@ The fourth value is the transparent border thickness."
                                (nth 2 image)
                                (if (< (length image) 4)
                                    (preview-get-heuristic-mask)
-                                 (nth 3 image))))))
+                                 (nth 3 image))
+                               (nth 4 image)))))
 
 (defsubst preview-supports-image-type (imagetype)
   "Check if IMAGETYPE is supported."



reply via email to

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