-
-
Save finalpatch/bb4bcccab0ec520ba6f96386d834f6fd to your computer and use it in GitHub Desktop.
img2x.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 files changed, 60 insertions(+), 2 deletions(-) | |
src/image.c | 1 + | |
src/nsimage.m | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- | |
modified src/image.c | |
@@ -9875,6 +9875,7 @@ non-numeric, there is no explicit limit on the size of images. */); | |
DEFSYM (QCscale, ":scale"); | |
DEFSYM (QCcolor_adjustment, ":color-adjustment"); | |
DEFSYM (QCmask, ":mask"); | |
+ DEFSYM (QCdpi_scale, "dpi_scale"); | |
/* Other symbols. */ | |
DEFSYM (Qlaplace, "laplace"); | |
modified src/nsimage.m | |
@@ -35,7 +35,46 @@ Updated by Christian Limpach (chris@nice.ch) | |
#include "frame.h" | |
#include "coding.h" | |
+Lisp_Object | |
+get_2x_image_file_name (Lisp_Object file_name) | |
+{ | |
+ Lisp_Object result; | |
+ char *p, *last_component; | |
+ ptrdiff_t prefix_len; | |
+ | |
+ p = strrchr (SSDATA (file_name), '/'); | |
+ last_component = p ? p + 1 : SSDATA (file_name); | |
+ p = strrchr (last_component, '.'); | |
+ if (p == NULL) | |
+ p = SSDATA (file_name) + SBYTES (file_name); | |
+ prefix_len = p - SSDATA (file_name); | |
+ result = make_uninit_string (SBYTES (file_name) + sizeof ("@2x") - 1); | |
+ sprintf (SSDATA (result), "%.*s@2x%.*s", | |
+ (int) prefix_len, SSDATA (file_name), | |
+ (int) (SBYTES (file_name) - prefix_len), p); | |
+ return result; | |
+} | |
+ | |
+void | |
+set_image_spec (Lisp_Object spec, Lisp_Object key, Lisp_Object value) | |
+{ | |
+ Lisp_Object tail; | |
+ | |
+ eassert (valid_image_p (spec)); | |
+ | |
+ for (tail = XCDR (spec); | |
+ CONSP (tail) && CONSP (XCDR (tail)); | |
+ tail = XCDR (XCDR (tail))) | |
+ { | |
+ if (EQ (XCAR (tail), key)) | |
+ { | |
+ XSETCAR (XCDR (tail), value); | |
+ return; | |
+ } | |
+ } | |
+ Fplist_put(XCDR(spec), key, value); | |
+} | |
/* ========================================================================== | |
@@ -76,7 +115,7 @@ Updated by Christian Limpach (chris@nice.ch) | |
{ | |
EmacsImage *eImg = nil; | |
NSSize size; | |
- Lisp_Object lisp_index, lisp_rotation; | |
+ Lisp_Object lisp_index, lisp_rotation, found, spec_file_2x, value; | |
unsigned int index; | |
double rotation; | |
@@ -92,7 +131,21 @@ Updated by Christian Limpach (chris@nice.ch) | |
if (STRINGP (spec_file)) | |
{ | |
- eImg = [EmacsImage allocInitFromFile: spec_file]; | |
+ /* Try 2x filename first */ | |
+ spec_file_2x = get_2x_image_file_name(spec_file); | |
+ eImg = [EmacsImage allocInitFromFile: spec_file_2x]; | |
+ if (eImg != nil) | |
+ { | |
+ /* fix image scale */ | |
+ set_image_spec(img->spec, QCdpi_scale, make_float(0.5)); | |
+ /* fix image name */ | |
+ [eImg setName: [NSString stringWithUTF8String: SSDATA (spec_file)]]; | |
+ } | |
+ else | |
+ { | |
+ /* failed to load 2x image */ | |
+ eImg = [EmacsImage allocInitFromFile: spec_file]; | |
+ } | |
} | |
else if (STRINGP (spec_data)) | |
{ | |
@@ -535,6 +588,10 @@ - (void)setSizeFromSpec: (Lisp_Object) spec | |
if (NUMBERP (value)) | |
scale = XFLOATINT (value) ; | |
+ value = Fplist_get (spec, QCdpi_scale); | |
+ if (NUMBERP (value)) | |
+ scale *= XFLOATINT (value) ; | |
+ | |
value = Fplist_get (spec, QCmax_width); | |
if (NUMBERP (value)) | |
max_width = XFLOATINT (value); | |
[back] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment