# HG changeset patch # User Mikhail Kryshen <mikhail@kryshen.net> # Date 1334258000 -14400 # Node ID 911228da1bc8d81e155916bfcb0831cd54c6359a # Parent 24c7935a8f06872866e39982655047ae805eb9b3 Revised handling of FontRenderContexts. diff -r 24c7935a8f06 -r 911228da1bc8 src/net/kryshen/indyvon/core.clj --- a/src/net/kryshen/indyvon/core.clj Thu Apr 12 19:55:52 2012 +0400 +++ b/src/net/kryshen/indyvon/core.clj Thu Apr 12 23:13:20 2012 +0400 @@ -34,6 +34,9 @@ (def ^:dynamic ^Graphics2D *graphics*) +(def ^:dynamic ^:private ^FontRenderContext *font-context* + "FontRenderContext to use when Graphics2D is not available.") + (def ^:dynamic *width* "Width of the rendering area.") @@ -302,10 +305,7 @@ [] (if (bound? (var *graphics*)) (.getFontRenderContext *graphics*) - (let [scene *scene*] - (if-let [^Component c (:component scene)] - (.getFontRenderContext (.getFontMetrics c (.getFont c))) - (:font-context scene))))) + *font-context*)) (defn ^AffineTransform relative-transform "Returns AffineTransform: layer context -> AWT component." @@ -590,10 +590,13 @@ (defn- make-node [handle handlers] (let [clip (if *input-clip* (clip *input-clip*) - *clip*)] + *clip*) + bindings (-> (get-thread-bindings) + (dissoc (var *graphics*)) + (assoc (var *font-context*) (font-context)))] (DispatcherNode. handle handlers *event-dispatcher* clip (inverse-relative-transform) - (get-thread-bindings)))) + bindings))) (defn- add-node [tree node] (assoc-cons tree (:parent node) node)) @@ -723,7 +726,6 @@ event-dispatcher component rendering-hints - font-context next-state]) ;; Define rendering hints that affect font metrics to make sure that @@ -747,10 +749,6 @@ event-dispatcher component hints - (FontRenderContext. - nil - (get hints RenderingHints/KEY_TEXT_ANTIALIASING) - (get hints RenderingHints/KEY_FRACTIONALMETRICS)) (atom nil))))) (defn- get-and-set! @@ -789,9 +787,23 @@ (finally (remove-observers tmp-watcher) (commit (:event-dispatcher scene))))))) - + +(defn- scene-font-context [scene] + (let [hints (:rendering-hints scene) + ^Component c (:component scene) + t (if c (->> c + .getFont + (.getFontMetrics c) + .getFontRenderContext + .getTransform))] + (FontRenderContext. + t + (get hints RenderingHints/KEY_TEXT_ANTIALIASING) + (get hints RenderingHints/KEY_FRACTIONALMETRICS)))) + (defn scene-geometry [scene] - (binding [*scene* scene] + (binding [*scene* scene + *font-context* (scene-font-context scene)] (geometry (:layer scene)))) (defn set-cursor! [^Cursor cursor]