Browse Source

Add support for multi-line texts

Show the "description" field in the Black Wolf character sheets.
It's meant to be a multi-line text. For now, there's no UI to
input the description: it has to be added directly in the database.
master
parent
commit
b76e183754
2 changed files with 35 additions and 0 deletions
  1. +34
    -0
      src/clj/character_suite/pdf.clj
  2. +1
    -0
      src/cljx/character_suite/character/blackwolf.cljx

+ 34
- 0
src/clj/character_suite/pdf.clj View File

@@ -9,6 +9,7 @@
[character-suite.character.coc :as coc]
[character-suite.character.soy :as soy]
[character-suite.character.blackwolf :as blackwolf]
[clojure.string :as str]
[clojure.java.io :as io]))

(defn- draw-circle [content-stream center-x center-y radius]
@@ -61,6 +62,39 @@
(.drawString content-stream text)
(.endText content-stream)))

(defn- split-paragraph [text font font-size max-length]
(reduce (fn [acc word]
(let [last-line (or (last acc) "")
updated-last-line (str last-line " " word)]
(if (= word "")
(conj acc "")
(if (> (string-width updated-last-line font font-size)
max-length)
(conj acc word)
(if (= last-line "")
(conj acc word)
(conj (vec (butlast acc))
(str last-line " " word)))))))
[]
(str/split text #"\s")))

(defmethod write-mark :text-block [content-stream mark doc]
(let [font (PDTrueTypeFont/loadTTF doc "resources/RiseStarHandLight.ttf")
[_ raw-text x y font-size max-width] mark
max-width (or max-width 500)
lines (split-paragraph (str raw-text) font font-size max-width)]
(loop [line lines
line-y y]
(when-not (empty? line)
(.beginText content-stream)
(.moveTextPositionByAmount content-stream x line-y)
(.setFont content-stream font font-size)
(.drawString content-stream (first line))
(.endText content-stream))

(if-not (empty? line)
(recur (rest line) (- line-y font-size))))))

(defmethod write-mark :circle [content-stream mark doc]
(let [[_ x y radius] mark]
(draw-circle content-stream x y radius)))


+ 1
- 0
src/cljx/character_suite/character/blackwolf.cljx View File

@@ -258,6 +258,7 @@
[:text (:class props) 325 760 14 :left 93]
[:text (:cult props) 449 760 14 :left 100]
[:text (:place-origin props) 344 741 14 :left 196]
[:text-block (:description props) 263 710 10 285]
[:text (get-in props [:complications :complication1]) 52 562 14 :left 135]
[:text (get-in props [:complications :complication2]) 52 541 14 :left 135]
[:text (get-in props [:complications :complication3]) 52 520 14 :left 135]


Loading…
Cancel
Save