(defn
->text-entity
"Returns an entity with the given text rendered to it. The second arity is for backwards\n compatibility and should not be used."
([game
{{:keys
[baked-chars
baseline
font-height
first-char
bitmap-width
bitmap-height]}
:baked-font,
:as font-entity}
text]
(when-not
(:program font-entity)
(throw
(ex-info
"Only compiled font entities can be passed to ->text-entity"
{})))
(loop
[text (seq text) total (float 0) inner-entities []]
(if-let
[ch (first text)]
(let
[{:keys [x y w h xoff yoff xadv]}
(nth
baked-chars
(- #?(:clj (int ch) :cljs (.charCodeAt ch 0)) first-char))]
(recur
(rest text)
(+ total (float xadv))
(conj
inner-entities
(->
font-entity
(t/project bitmap-width bitmap-height)
(t/crop x y w h)
(t/translate (+ xoff total) (- font-height baseline yoff))
(t/scale w h)
(update-in
[:uniforms 'u_matrix]
(fn*
[p1__44990#]
(m/multiply-matrices 3 flip-y-matrix p1__44990#)))))))
(->
(e/->image-entity game nil total font-height)
(assoc
:width
total
:height
font-height
:render-to-texture
{'u_image
(mapv
(fn*
[p1__44991#]
(assoc
p1__44991#
:viewport
{:x 0,
:y (- font-height bitmap-height),
:width bitmap-width,
:height bitmap-height}))
inner-entities)})))))
([game baked-font image-entity text]
(->text-entity
game
(assoc image-entity :baked-font baked-font)
text)))