<commit_before>(in-package :mcclim-raster-image)

;;;
;;; Port
;;;

(defclass raster-image-port (render-port-mixin basic-port)
  ((width :reader raster-image-port-width)
   (height :reader raster-image-port-height)))
   
;;; Initialize and Destroy port

(defmethod initialize-instance :after ((port raster-image-port)
                                       &rest initargs
                                       &key server-path)
  (declare (ignore initargs))
  (destructuring-bind (raster-image &key
				    (num-pages 1)
				    (width 1000) (height 1000))
      server-path
    (declare (ignore raster-image num-pages))
    (setf (slot-value port 'width) width)
    (setf (slot-value port 'height) height)
    (make-graft port)))

(defun %destroy-all-mirrors (port)
  (maphash #'(lambda (key val)
	       (port-unregister-mirror port key val)
	       (destroy-mirror port key))
	   (slot-value port 'climi::sheet->mirror)))

(defmethod destroy-port :before ((port raster-image-port))
 (%destroy-all-mirrors port))
	    
;;; server path

(defun parse-raster-image-server-path (path)
  path)

;;; Port-Graft methods

(defmethod make-graft ((port raster-image-port) &key (orientation :default) (units :device))
  (let ((graft (make-instance 'raster-image-graft
			      :port port
			      :mirror nil
			      :orientation orientation
			      :units units
			      :width (raster-image-port-width port)
			      :height (raster-image-port-height port))))
    (climi::%%set-sheet-region (make-bounding-rectangle 0 0
                                                        (raster-image-port-width port)
                                                        (raster-image-port-height port))
                               graft)
    (push graft (port-grafts port))
    graft))

(defmethod graft ((port raster-image-port))
  (first (port-grafts port)))

(defmethod destroy-mirror ((port raster-image-port) sheet)
  (declare (ignore port sheet))
  nil)

;;; medium

(defmethod make-medium ((port raster-image-port) (sheet basic-sheet))
  (make-instance 'raster-image-medium :sheet sheet :port port))


(defmethod port-set-mirror-region ((port raster-image-port) mirror region)
  (declare (ignore port mirror region))
  nil)

(defmethod port-set-mirror-transformation ((port raster-image-port) mirror transformation)
  (declare (ignore port mirror transformation))
  nil)



(defgeneric make-raster-top-level-sheet (port format))

(defmethod make-raster-top-level-sheet ((port raster-image-port) format)
  (declare (ignore format))
  (let ((tlp (make-instance 'raster-image-top-level-pane
			    :enabled-p nil :port port)))
    tlp))<commit_msg>raster-image: Do not pass :PORT initarg to RASTER-IMAGE-MEDIUM<commit_after>(in-package :mcclim-raster-image)

;;;
;;; Port
;;;

(defclass raster-image-port (render-port-mixin basic-port)
  ((width :reader raster-image-port-width)
   (height :reader raster-image-port-height)))

;;; Initialize and Destroy port

(defmethod initialize-instance :after ((port raster-image-port)
                                       &rest initargs
                                       &key server-path)
  (declare (ignore initargs))
  (destructuring-bind (raster-image &key
				    (num-pages 1)
				    (width 1000) (height 1000))
      server-path
    (declare (ignore raster-image num-pages))
    (setf (slot-value port 'width) width)
    (setf (slot-value port 'height) height)
    (make-graft port)))

(defun %destroy-all-mirrors (port)
  (maphash #'(lambda (key val)
	       (port-unregister-mirror port key val)
	       (destroy-mirror port key))
	   (slot-value port 'climi::sheet->mirror)))

(defmethod destroy-port :before ((port raster-image-port))
 (%destroy-all-mirrors port))

;;; server path

(defun parse-raster-image-server-path (path)
  path)

;;; Port-Graft methods

(defmethod make-graft ((port raster-image-port) &key (orientation :default) (units :device))
  (let ((graft (make-instance 'raster-image-graft
			      :port port
			      :mirror nil
			      :orientation orientation
			      :units units
			      :width (raster-image-port-width port)
			      :height (raster-image-port-height port))))
    (climi::%%set-sheet-region (make-bounding-rectangle 0 0
                                                        (raster-image-port-width port)
                                                        (raster-image-port-height port))
                               graft)
    (push graft (port-grafts port))
    graft))

(defmethod graft ((port raster-image-port))
  (first (port-grafts port)))

(defmethod destroy-mirror ((port raster-image-port) sheet)
  (declare (ignore port sheet))
  nil)

;;; medium

(defmethod make-medium ((port raster-image-port) (sheet basic-sheet))
  (make-instance 'raster-image-medium :sheet sheet))


(defmethod port-set-mirror-region ((port raster-image-port) mirror region)
  (declare (ignore port mirror region))
  nil)

(defmethod port-set-mirror-transformation ((port raster-image-port) mirror transformation)
  (declare (ignore port mirror transformation))
  nil)



(defgeneric make-raster-top-level-sheet (port format))

(defmethod make-raster-top-level-sheet ((port raster-image-port) format)
  (declare (ignore format))
  (let ((tlp (make-instance 'raster-image-top-level-pane
			    :enabled-p nil :port port)))
    tlp))
{'fraction_non_alphanumeric': 0.1316284317412561, 'fraction_numerical': 0.004136893569010906, 'mean_word_length': 2.610997963340122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7124417', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1637, 'n_words': 410}