 (advice-add #'pdf-view--push-mark :after #'pdf-translate-selection)
 
 ;;Add retina support for pdf
-(defun +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args)
-  (cl-letf* ((old-create-image (symbol-function #'create-image))
-             ((symbol-function #'create-image)
-              (lambda (file-or-data &optional type data-p &rest props)
-                (apply old-create-image file-or-data type data-p
-                       :width (car (pdf-view-image-size))
-                       props))))
-    (apply orig-fn args)))
+(defadvice! +pdf--scale-up-on-retina-display-a (orig-fn &rest args)
+  "Scale up the PDF on retina displays."
+  :around #'pdf-util-frame-scale-factor
+  (cond ((not pdf-view-use-scaling) 1)
+        ((and (memq (pdf-view-image-type) '(imagemagick image-io))
+              (fboundp 'frame-monitor-attributes))
+         (funcall orig-fn))
+        ;; Add special support for retina displays on MacOS
+        ((eq (framep-on-display) 'ns) 2)
+        (1)))
 
-(defun +pdf--util-frame-scale-factor-a (orig-fn)
-  (if (and pdf-view-use-scaling
-           (memq (pdf-view-image-type) '(imagemagick image-io))
-           (fboundp 'frame-monitor-attributes))
-      (funcall orig-fn)
-    ;; Add special support for retina displays on MacOS
-    (if (eq (framep-on-display) 'ns)
-        2
-      1)))
+(defadvice! +pdf--use-scaling-on-ns-a ()
+  :before-until #'pdf-view-use-scaling-p
+  (eq (framep-on-display) 'ns))
 
-(defun +pdf--view-use-scaling-p-a ()
-  "Returns t if on ns window-system on Emacs 27+."
-  (and (eq (framep-on-display) 'ns)
-       pdf-view-use-scaling))
-
-(advice-add #'pdf-util-frame-scale-factor :around #'+pdf--util-frame-scale-factor-a)
-(advice-add #'pdf-view-use-scaling-p :before-until #'+pdf--view-use-scaling-p-a)
 (defadvice! +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args)
   :around '(pdf-annot-show-annotation
             pdf-isearch-hl-matches

                                (local-set-key (kbd "<down-mouse-1>") #'pdf-view-mouse-set-region-wapper)
                                (local-set-key (kbd "<double-mouse-1>") #'pdf-traslate-under-mouse)))

(provide 'init-pdf)

                  :width (car (pdf-view-image-size))
                  props))
    (apply orig-fn args)))

(with-eval-after-load 'pdf-annot
  (defun +pdf-cleanup-windows-h ()
