Permalink
Browse files

Text bounds calculation for java 2d

  • Loading branch information...
1 parent 344b149 commit 0d545eaab7fe4b58f7c7935b8296b894534d34bf @stathissideris committed Nov 14, 2012
Showing with 18 additions and 0 deletions.
  1. +10 −0 src/dali/backend/java_2d.clj
  2. +8 −0 src/dali/test.clj
@@ -194,6 +194,16 @@
size (.getSize *DEFAULT-FONT*)}}]
(Font. family java.awt.Font/PLAIN size))
+(defn text-bounds
+ [backend {content :content {position :position} :geometry :as text}]
+ (let [font (font->java-font (get-in text [:style :font]))
+ rect (.getStringBounds
+ font content
+ (.getFontRenderContext (.graphics backend)))
+ upper-left [(.getX rect) (.getY rect)]]
+ (rectangle (translate position upper-left)
+ [(.getWidth rect) (.getHeight rect)])))
+
(defmacro isolate-style
"Isolates the side-effects of the body to the backend, and executes
the body in an implicit do."
View
@@ -30,6 +30,14 @@
java.awt.RenderingHints/KEY_ANTIALIASING
java.awt.RenderingHints/VALUE_ANTIALIAS_ON)
+ #_(println
+ (.getStringBounds
+ dali.backend.java-2d/*DEFAULT-FONT*
+ "Stathis"
+ (.getFontRenderContext (.graphics backend))))
+
+ #_(println (text-bounds backend (text [100 100] "Stathis")))
+
(doto backend
(set-paint (color 0 0 0))
(fill (rectangle [0 0] [(.getWidth @img) (.getHeight @img)]))

0 comments on commit 0d545ea

Please sign in to comment.