From 505aadbaa880fefea42569037b16581e2c05424b Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Wed, 2 Oct 2019 14:30:09 +0200 Subject: [PATCH] Add font setting --- README.md | 1 + resources/config.edn | 1 + src/invoices/core.clj | 5 +++-- src/invoices/pdf.clj | 7 ++++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a51b859..b719a7b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ following keys: * :seller - the seller's (i.e. the entity to be paid) information. This is required * :buyer - the buyer's (i.e. the entity that will pay) information. This is required * :items - a list of items to be paid for + * :font-path - (optional) *the path to a font file, e.g. "/usr/share/fonts/truetype/freefont/FreeSans.ttf" * :credentials - JIRA and Tempo access credentials. These are needed if the price depends on tracked time See `resources/config.edn` for an example configuration. diff --git a/resources/config.edn b/resources/config.edn index 6d28372..4933f07 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -10,6 +10,7 @@ :items [{:vat 8 :netto 123.21 :title "Buty kowbojskie"} {:vat 21 :hourly 43.12 :title "Usługa szewska"} {:vat 23 :base 4300.00 :per-day 4 :title "Praca za ladą"}] + :font-path "/usr/share/fonts/truetype/freefont/FreeSans.ttf" :credentials {:tempo-token "5zq7zF9LADefEGAs12eDDas3FDttiM" :jira-token "qypaAsdFwASasEddDDddASdC" :jira-user "mr.blobby@boots.rs"}}] diff --git a/src/invoices/core.clj b/src/invoices/core.clj index 9ee23aa..d54c06f 100644 --- a/src/invoices/core.clj +++ b/src/invoices/core.clj @@ -25,11 +25,12 @@ (not (contains? item :netto)) (assoc item :netto 0) :else item)) -(defn for-month [when {seller :seller buyer :buyer items :items creds :credentials} & [number]] +(defn for-month [when {seller :seller buyer :buyer items :items creds :credentials font-path :font-path} & [number]] (pdf/render seller buyer (map (partial set-price when creds) items) (pdf/last-working-day when) - (invoice-number when number))) + (invoice-number when number) + font-path)) (defn get-invoices [nips config] (if (seq nips) diff --git a/src/invoices/pdf.clj b/src/invoices/pdf.clj index 8c941e4..429bdd6 100644 --- a/src/invoices/pdf.clj +++ b/src/invoices/pdf.clj @@ -1,6 +1,7 @@ (ns invoices.pdf (:require [clj-pdf.core :refer [pdf]] - [clojure.string :as str])) + [clojure.string :as str]) + (:import [java.awt Font])) (defn round [val] @@ -32,7 +33,7 @@ (str/replace #"[ -/]" "_")))) -(defn render [seller buyer items when number] +(defn render [seller buyer items when number & [font-path]] (let [title (get-title (:team seller) (:name seller) number)] (println " -" title) (pdf @@ -42,7 +43,7 @@ :bottom-margin 10 :left-margin 10 :top-margin 20 - :font {:encoding :unicode :ttf-name "/usr/share/fonts/gsfonts/NimbusSans-Regular.otf"} + :font (clojure.core/when font-path{:encoding :unicode :ttf-name font-path}) :size "a4" :footer "page"}