   GlyphGraphics
   (glyph-graphics [this]
     ;; Adjust canvas to fit character atlas size
-    (let [^STBTTFontinfo font-info   (make-font name-or-path)
+    (let [ms (MemoryStack/create)
+          ^STBTTFontinfo font-info   (make-font name-or-path)
           scale                      (STBTruetype/stbtt_ScaleForPixelHeight
                                        font-info
                                        size)
           [advance
            left-side-bearing]        (map (partial * scale)
-                                       (hmetrics font-info
+                                       (hmetrics ms
+                                                 font-info
                                                  (STBTruetype/stbtt_FindGlyphIndex
                                                    font-info
                                                    (int \M))))

      compact-image)
    image))

(defn- hmetrics [^STBTTFontinfo font-info glyph-index]
  (let [advance-width     (BufferUtils/createIntBuffer 1)
        left-side-bearing (BufferUtils/createIntBuffer 1)]
    (log-call "STBTruetype/stbtt_GetGlyphHMetrics" font-info (int glyph-index) advance-width left-side-bearing)
    (STBTruetype/stbtt_GetGlyphHMetrics font-info (int glyph-index) advance-width left-side-bearing)
    [(.get advance-width) (.get left-side-bearing)]))

(defn- vmetrics [^STBTTFontinfo font-info]
  (let [ascent   (BufferUtils/createIntBuffer 1)
        descent  (BufferUtils/createIntBuffer 1)
        line-gap (BufferUtils/createIntBuffer 1)]
    (log-call "STBTruetype/stbtt_GetFontVMetrics" font-info ascent descent line-gap)
    (STBTruetype/stbtt_GetFontVMetrics font-info ascent descent line-gap)
    [(.get ascent) (.get descent) (.get line-gap)]))

(defn- glyph-bitmap-box [^STBTTFontinfo font-info scale glyph-index]
  (let [ix0 (BufferUtils/createIntBuffer 1)
        iy0 (BufferUtils/createIntBuffer 1)
        ix1 (BufferUtils/createIntBuffer 1)
        iy1 (BufferUtils/createIntBuffer 1)]
    (log-call "STBTruetype/stbtt_GetGlyphBitmapBox"
      font-info
      (int glyph-index)

         :character-height char-height
         :character->col-row (character->col-row char-idxs)
         :character->transparent (zipmap characters (repeat transparent))}))))

(defrecord CompositeFont [fonts]
  GlyphGraphics
