Mercurial > hg > indyvon
changeset 127:911228da1bc8
Revised handling of FontRenderContexts.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Thu, 12 Apr 2012 23:13:20 +0400 |
parents | 24c7935a8f06 |
children | d37d6c5b3b08 |
files | src/net/kryshen/indyvon/core.clj |
diffstat | 1 files changed, 25 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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]