Skip to content

Commit

Permalink
refactor: add attrs->sizes and attrs->pdrect functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Seryiza committed Nov 11, 2024
1 parent 7a415d5 commit 74d602c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
10 changes: 3 additions & 7 deletions src/remplater/components/builtin_components.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
line-width 1.0}
:as attrs}
& children]
(let [;; TODO: add fig-opts->pdrect fn
width (abs (- x2 x1))
height (abs (- y2 y1))
(let [[width height] (fo/attrs->sizes attrs)
fill-color (cond
(fn? fill-color) (fill-color attrs)
(some? fill-color) fill-color
Expand Down Expand Up @@ -159,7 +157,7 @@

;; TODO: add link-type to change PDPageFitWidthDestination
(defmethod r/render :page-link
[_ {:keys [target-page x1 y1 x2 y2]} & children]
[_ {:as attrs :keys [target-page x1 y1 x2 y2]} & children]
(let [target-page (cond
(string? target-page)
(->> r/*all-pages*
Expand All @@ -173,9 +171,7 @@
target-page)
annotations (.getAnnotations r/*page*)
annotation-link (PDAnnotationLink.)
width (abs (- x2 x1))
height (abs (- y2 y1))
rect (PDRectangle. x1 y1 width height)
rect (fo/attrs->pdrect attrs)
go-to-action (PDActionGoTo.)
destination (PDPageFitWidthDestination.)
border-style (doto (PDBorderStyleDictionary.)
Expand Down
21 changes: 15 additions & 6 deletions src/remplater/components/positioning.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
(ns remplater.components.positioning)
(ns remplater.components.positioning
(:import
[org.apache.pdfbox.pdmodel.common PDRectangle]))

(defn attrs->sizes [{:keys [x1 y1 x2 y2]}]
(let [width (abs (- x2 x1))
height (abs (- y2 y1))]
[width height]))

(defn attrs->pdrect [{:as attrs :keys [x1 y1]}]
(let [[width height] (attrs->sizes attrs)]
(PDRectangle. x1 y1 width height)))

(defn split-one [attrs coordinate split-size]
(comment
Expand Down Expand Up @@ -113,15 +124,13 @@
:left (rect->border-line attrs :left)
:right (rect->border-line attrs :right)})

(defn rect->center [{:keys [x1 y1 x2 y2]}]
(let [width (abs (- x2 x1))
height (abs (- y2 y1))]
(defn rect->center [{:as attrs :keys [x1 y1 x2 y2]}]
(let [[width height] (attrs->sizes attrs)]
{:x (+ x1 (/ width 2))
:y (+ y1 (/ height 2))}))

(defn pattern-grid [{:as attrs :keys [pattern x1 y1 x2 y2]}]
(let [width (abs (- x2 x1))
height (abs (- y2 y1))
(let [[width height] (attrs->sizes attrs)
pattern-width (:width pattern)
pattern-height (:height pattern)
used-patterns-x (quot width pattern-width)
Expand Down

0 comments on commit 74d602c

Please sign in to comment.