diff --git a/src/remplater/components/builtin_components.clj b/src/remplater/components/builtin_components.clj index fc77d48..e50571a 100644 --- a/src/remplater/components/builtin_components.clj +++ b/src/remplater/components/builtin_components.clj @@ -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 @@ -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* @@ -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.) diff --git a/src/remplater/components/positioning.clj b/src/remplater/components/positioning.clj index 03f8460..fa95924 100644 --- a/src/remplater/components/positioning.clj +++ b/src/remplater/components/positioning.clj @@ -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 @@ -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)