Browse files

Added font-families function to get a list of all the valid font fami…

…ly names on the system.
  • Loading branch information...
daveray committed Dec 8, 2011
1 parent 01a30f2 commit a76da24c50eb83cd4eff11db9ba17544badb931d
Showing with 22 additions and 3 deletions.
  1. +19 −3 src/seesaw/font.clj
  2. +3 −0 test/seesaw/test/font.clj
@@ -13,7 +13,21 @@
:author "Dave Ray"}
(:use [seesaw.util :only [constant-map resource resource-key?]])
- (:import [java.awt Font]))
+ (:import [java.awt Font GraphicsEnvironment]))
+(defn font-families
+ "Returns a seq of strings naming the font families on the system. These
+ are the names that are valid in :name option (seesaw.font/font) as well
+ as in font descriptor strings like \"Arial-BOLD-20\"
+ See:
+ (seesaw.core/font)
+ "
+ ([] (font-families nil))
+ ([locale]
+ (-> (GraphicsEnvironment/getLocalGraphicsEnvironment)
+ (.getAvailableFontFamilyNames locale)
+ seq)))
(def ^{:private true} style-table (constant-map Font :bold :plain :italic))
(defn- get-style-mask [v]
@@ -34,7 +48,8 @@
Options are:
:name The name of the font. Besides string values, also possible are
- any of :monospaced, :serif, :sans-serif.
+ any of :monospaced, :serif, :sans-serif. See (seesaw.font/font-families)
+ to get a system-specific list of all valid values.
:style The style. One of :bold, :plain, :italic, or a set of those values
to combine them. Default: :plain.
:size The size of the font. Default: 12.
@@ -51,14 +66,15 @@
(font :style #{:bold :italic} :name :monospaced)
+ (seesaw.font/font-families)
[& args]
(if (= 1 (count args))
(let [v (first args)]
(if (resource-key? v)
(Font/decode (resource v))
- (Font/decode (str v))))
+ (Font/decode (name v))))
(let [{:keys [style size from] :as opts} args
font-name (:name opts)
font-style (get-style-mask (or style :plain))
@@ -35,6 +35,9 @@
(it "can create a font with a specific size"
(let [f (font :size 40)]
(expect (= 40 (.getSize f)))))
+ (it "can create a font from a family keyword"
+ (let [f (font :monospaced)]
+ (expect (= "Monospaced" (.getFamily f)))))
(it "can create a monospace font"
(let [f (font :name :monospaced)]
(expect (= Font/MONOSPACED (.getName f)))))

0 comments on commit a76da24

Please sign in to comment.