Repository: celiagg/celiagg (language: python)

Issue:
Make the font cache a separate object
This is a rather sizable refactor which aims to fix the [Windows] text rendering bugs introduced in #65.

Instead of creating `thread_local` globals in `Font` for management of glyph caching, I've separated out the font cache into a new `FontCache` object which exists independently of the `Canvas*` and `Font` objects. A font cache can be shared between any number of canvas instances, as long as one takes care not to use the cache simultaneously from multiple threads.

One big downside of this change is that it **breaks** the existing `Font` API by moving the `Font.string_width` method to `FontCache.width`. Therefore I intend to bump the package's major version number to 2, as an extra warning to downstream users. `Canvas*` classes also need to be passed a `FontCache` instance at construction time, but existing code can continue to work _without modification_ due to some Python wrappers in the package's `__init__` module.

~It _should_ fix #62, but some tests are needed.~

Fixes #62


Discussion / hints:

Fix patch:
diff --git a/celiagg/__init__.py b/celiagg/__init__.py
index e2356d0..894694a 100644
--- a/celiagg/__init__.py
+++ b/celiagg/__init__.py
@@ -26,7 +26,7 @@
 
 from . import _celiagg
 from ._celiagg import (
-    AggError, BSpline, BlendMode, DrawingMode, Font, FontCache, FontCacheType,
+    AggError, BSpline, BlendMode, DrawingMode, Font, FontCache,
     GradientSpread, GradientUnits, GraphicsState, Image, InnerJoin,
     LineCap, LineJoin, LinearGradientPaint, Path, PatternPaint, PatternStyle,
     PixelFormat, RadialGradientPaint, Rect, ShapeAtPoints, SolidPaint,
@@ -41,11 +41,10 @@
     'HAS_TEXT',
 
     'AggError', 'BlendMode', 'BSpline', 'DrawingMode', 'Font', 'FontCache',
-    'FontCacheType', 'GradientSpread', 'GradientUnits', 'GraphicsState',
-    'Image', 'InnerJoin', 'LinearGradientPaint', 'LineCap', 'LineJoin',
-    'RadialGradientPaint', 'Path', 'PatternPaint', 'PatternStyle',
-    'PixelFormat', 'Rect', 'ShapeAtPoints', 'SolidPaint', 'TextDrawingMode',
-    'Transform',
+    'GradientSpread', 'GradientUnits', 'GraphicsState', 'Image', 'InnerJoin',
+    'LinearGradientPaint', 'LineCap', 'LineJoin', 'RadialGradientPaint',
+    'Path', 'PatternPaint', 'PatternStyle', 'PixelFormat', 'Rect',
+    'ShapeAtPoints', 'SolidPaint', 'TextDrawingMode', 'Transform',
 
     'CanvasG8', 'CanvasGA16', 'CanvasRGB24', 'CanvasRGBA32', 'CanvasBGRA32',
     'CanvasRGBA128',
diff --git a/celiagg/_enums.pxd b/celiagg/_enums.pxd
index f090314..b8cae4b 100644
--- a/celiagg/_enums.pxd
+++ b/celiagg/_enums.pxd
@@ -22,10 +22,10 @@
 #
 # Authors: John Wiggins
 
-cdef extern from "font.h" namespace "Font":
-    cdef enum FontCacheType:
-        RasterFontCache
-        VectorFontCache
+cdef extern from "font_cache.h" namespace "FontCache":
+    cdef enum GlyphType:
+        RasterGlyph
+        VectorGlyph
 
 
 cdef extern from "image.h":
@@ -82,6 +82,7 @@ cdef extern from "graphics_state.h" namespace "GraphicsState":
         TextDrawFill
         TextDrawStroke
         TextDrawClip
+        TextDrawRaster
         TextDrawFillStroke
         TextDrawFillClip
         TextDrawStrokeClip
diff --git a/celiagg/_font.pxd b/celiagg/_font.pxd
index 69db919..f531920 100644
--- a/celiagg/_font.pxd
+++ b/celiagg/_font.pxd
@@ -23,15 +23,12 @@
 # Authors: John Wiggins
 
 from libcpp cimport bool
-cimport _enums
 
 
 cdef extern from "font.h":
     cdef cppclass Font:
-        Font(char* fileName, double height, _enums.FontCacheType ch,
-             unsigned face_index)
+        Font(char* fileName, double height, unsigned face_index)
 
-        _enums.FontCacheType cache_type() const
         unsigned face_index() const
         const char* filepath() const
         bool flip() const
diff --git a/celiagg/_font_cache.pxd b/celiagg/_font_cache.pxd
index f6dc31c..7f58bb4 100644
--- a/celiagg/_font_cache.pxd
+++ b/celiagg/_font_cache.pxd
@@ -22,6 +22,7 @@
 #
 # Authors: John Wiggins
 
+cimport _enums
 cimport _font
 cimport _transform
 
@@ -30,5 +31,7 @@ cdef extern from "font_cache.h":
     cdef cppclass FontCache:
         FontCache()
 
+        # NOTE: The GlyphType argument for activate() is ignored here
+        # All text measurement happens with raster glyphs, for speed reasons.
         void activate(_font.Font& font, _transform.trans_affine& transform);
         double measure_width(char* str)
diff --git a/celiagg/enums.pxi b/celiagg/enums.pxi
index 3790d0d..647acd6 100644
--- a/celiagg/enums.pxi
+++ b/celiagg/enums.pxi
@@ -73,6 +73,7 @@ cpdef enum TextDrawingMode:
     TextDrawFill = _enums.TextDrawFill
     TextDrawStroke = _enums.TextDrawStroke
     TextDrawClip = _enums.TextDrawClip
+    TextDrawRaster = _enums.TextDrawRaster
     TextDrawFillStroke = _enums.TextDrawFillStroke
     TextDrawFillClip = _enums.TextDrawFillClip
     TextDrawStrokeClip = _enums.TextDrawStrokeClip
diff --git a/celiagg/font.cpp b/celiagg/font.cpp
index bbf328c..5f58339 100644
--- a/celiagg/font.cpp
+++ b/celiagg/font.cpp
@@ -24,21 +24,14 @@
 
 #include "font.h"
 
-Font::Font(char const* fontName, double const height, FontCacheType const ch, unsigned const face_index)
+Font::Font(char const* fontName, double const height, unsigned const face_index)
 : m_height(height)
 , m_font_name(fontName)
-, m_cache_type(ch)
 , m_face_index(face_index)
 , m_flip(false)
 , m_hinting(true)
 {}
 
-Font::FontCacheType
-Font::cache_type() const
-{
-    return m_cache_type;
-}
-
 unsigned
 Font::face_index() const
 {
diff --git a/celiagg/font.h b/celiagg/font.h
index c634fc8..dac41cc 100644
--- a/celiagg/font.h
+++ b/celiagg/font.h
@@ -31,17 +31,9 @@ class Font
 {
 public:
 
-    enum FontCacheType
-    {
-        RasterFontCache,
-        VectorFontCache
-    };
-
                         Font(char const* fileName, double const height,
-                             FontCacheType const ch = RasterFontCache,
                              unsigned const face_index = 0);
 
-    FontCacheType       cache_type() const;
     unsigned            face_index() const;
     const char*         filepath() const;
 
@@ -58,7 +50,6 @@ class Font
 
         double          m_height;
         std::string     m_font_name;
-        FontCacheType   m_cache_type;
         unsigned        m_face_index;
         bool            m_flip;
         bool            m_hinting;
diff --git a/celiagg/font.pxi b/celiagg/font.pxi
index bcf466e..ff07c10 100644
--- a/celiagg/font.pxi
+++ b/celiagg/font.pxi
@@ -23,38 +23,27 @@
 # Authors: John Wiggins
 
 
-cpdef enum FontCacheType:
-    RasterFontCache = _enums.RasterFontCache
-    VectorFontCache = _enums.VectorFontCache 
-
-
 cdef class Font:
-    """Font(path, size, cache_type, face_index=0)
+    """Font(path, size, face_index=0)
 
     :param path: A Unicode string containing the path of a ``Font`` file
     :param size: The size of the font
-    :param cache_type: A ``FontCacheType``
     :param face_index: For .ttc fonts, the index of the desired font within
                         the collection.
     """
     cdef _font.Font* _this
 
-    def __cinit__(self, fontName, double size, FontCacheType ch,
-                    unsigned face_index=0):
+    def __cinit__(self, fontName, double size, unsigned face_index=0):
         fontName = _get_utf8_text(fontName,
                                   "Font path must be a unicode string")
-        self._this = new _font.Font(fontName, size, ch, face_index)
+        self._this = new _font.Font(fontName, size, face_index)
 
     def __dealloc__(self):
         del self._this
 
     def copy(self):
         return Font(self._this.filepath(), self._this.height(),
-                    self._this.cache_type(), self._this.face_index())
-
-    property cache_type:
-        def __get__(self):
-            return FontCacheType(self._this.cache_type())
+                    self._this.face_index())
 
     property face_index:
         def __get__(self):
diff --git a/celiagg/font_cache.cpp b/celiagg/font_cache.cpp
index e5b0b58..852368d 100644
--- a/celiagg/font_cache.cpp
+++ b/celiagg/font_cache.cpp
@@ -32,7 +32,7 @@
 
 FontCache::FontCache() {}
 FontCache::~FontCache() {}
-void FontCache::activate(const Font&, const agg::trans_affine& transform) {}
+void FontCache::activate(const Font&, const agg::trans_affine& transform, GlyphType const type) {}
 double FontCache::measure_width(char const* str) { return 0.0; }
 
 
@@ -57,12 +57,12 @@ FontCache::~FontCache()
 }
 
 void
-FontCache::activate(const Font& font, const agg::trans_affine& transform)
+FontCache::activate(const Font& font, const agg::trans_affine& transform, GlyphType const type)
 {
 #ifdef _USE_FREETYPE
     m_font_engine.load_font(font.filepath(),
                             font.face_index(),
-                            (font.cache_type() == Font::VectorFontCache) ?
+                            (type == FontCache::VectorGlyph) ?
                                 agg::glyph_ren_outline :
                                 agg::glyph_ren_agg_gray8);
     // Manipulate the aspects of the font which was just loaded.
@@ -78,7 +78,7 @@ FontCache::activate(const Font& font, const agg::trans_affine& transform)
     m_font_engine.hinting(font.hinting());
     m_font_engine.transform(transform);
     m_font_engine.create_font(font.filepath(),
-                             (font.cache_type() == Font::VectorFontCache) ?
+                             (type == FontCache::VectorGlyph) ?
                                 agg::glyph_ren_outline :
                                 agg::glyph_ren_agg_gray8,
                               font.height(),
diff --git a/celiagg/font_cache.h b/celiagg/font_cache.h
index c5b9868..4445a3c 100644
--- a/celiagg/font_cache.h
+++ b/celiagg/font_cache.h
@@ -45,6 +45,12 @@ class FontCache
 {
 public:
 
+    enum GlyphType
+    {
+        RasterGlyph,
+        VectorGlyph
+    };
+
 #ifdef _ENABLE_TEXT_RENDERING
 #ifdef _USE_FREETYPE
     typedef agg::font_engine_freetype_int32       FontEngine;
@@ -57,7 +63,9 @@ class FontCache
                         FontCache();
                         ~FontCache();
 
-    void                activate(const Font& font, const agg::trans_affine& transform);
+    void                activate(const Font& font,
+                                 const agg::trans_affine& transform,
+                                 GlyphType const type = RasterGlyph);
     double              measure_width(char const* str);
 
 #ifdef _ENABLE_TEXT_RENDERING
diff --git a/celiagg/font_cache.pxi b/celiagg/font_cache.pxi
index e478f95..86716c2 100644
--- a/celiagg/font_cache.pxi
+++ b/celiagg/font_cache.pxi
@@ -22,6 +22,7 @@
 #
 # Authors: John Wiggins
 
+
 cdef class FontCache:
     """FontCache()
 
diff --git a/celiagg/glyph_iter.cpp b/celiagg/glyph_iter.cpp
index 0552249..34b2aeb 100644
--- a/celiagg/glyph_iter.cpp
+++ b/celiagg/glyph_iter.cpp
@@ -24,11 +24,10 @@
 
 #include "glyph_iter.h"
 
-GlyphIterator::GlyphIterator(char const* utf8Text, FontCache& cache, const bool drawing,
-                             const double x_off, const double y_off)
+GlyphIterator::GlyphIterator(char const* utf8Text, FontCache& cache, const bool drawing)
 : m_font_cache(cache)
-, m_offset_x(x_off)
-, m_offset_y(y_off)
+, m_offset_x(0.0)
+, m_offset_y(0.0)
 , m_text(utf8Text)
 , m_index(0)
 , m_is_drawing(drawing)
diff --git a/celiagg/glyph_iter.h b/celiagg/glyph_iter.h
index 38fb9f4..e16e39b 100644
--- a/celiagg/glyph_iter.h
+++ b/celiagg/glyph_iter.h
@@ -41,10 +41,9 @@ class GlyphIterator
 
 public:
                         GlyphIterator(char const* utf8Text, FontCache& cache,
-                                      const bool drawing = false,
-                                      const double x_off = 0.0,
-                                      const double y_off = 0.0);
+                                      const bool drawing = false);
 
+    void                offset(double x, double y) { m_offset_x = x; m_offset_y = y; }
     StepAction          step();
     double              x_offset() const { return m_offset_x; }
     double              y_offset() const { return m_offset_y; }
diff --git a/celiagg/graphics_state.h b/celiagg/graphics_state.h
index 009a3be..894487c 100644
--- a/celiagg/graphics_state.h
+++ b/celiagg/graphics_state.h
@@ -73,11 +73,12 @@ class GraphicsState
 
     enum TextDrawingMode
     {
-        // Bit 0: fill, Bit 1: stroke, Bit 2: clip
+        // Bit 0: fill, Bit 1: stroke, Bit 2: clip, Bit 3: raster
         TextDrawInvisible = 0x0000,
         TextDrawFill = 0x0001,
         TextDrawStroke = 0x0002,
         TextDrawClip = 0x0004,
+        TextDrawRaster = 0x0008,  // Same as TextDrawFill, but fast and high quality
         TextDrawFillStroke = TextDrawFill | TextDrawStroke,
         TextDrawFillClip = TextDrawFill | TextDrawClip,
         TextDrawStrokeClip = TextDrawStroke | TextDrawClip,
@@ -117,7 +118,7 @@ class GraphicsState
         m_clip_box(0.0, 0.0, -1.0, -1.0),  // Invalid by default!
         m_stencil(NULL),
         m_drawing_mode(DrawFillStroke),
-        m_text_drawing_mode(TextDrawFill),
+        m_text_drawing_mode(TextDrawRaster),
         m_blend_mode(BlendAlpha),
         m_image_blend_mode(BlendDst),
         m_master_alpha(1.0),
diff --git a/celiagg/ndarray_canvas.h b/celiagg/ndarray_canvas.h
index f23bba4..ee7e883 100644
--- a/celiagg/ndarray_canvas.h
+++ b/celiagg/ndarray_canvas.h
@@ -163,13 +163,15 @@ class ndarray_canvas : public ndarray_canvas_base
                              base_renderer_t& renderer);
     template<typename base_renderer_t>
     void _draw_text_raster(GlyphIterator& iterator,
-                           agg::trans_affine& transform,
-                           Paint& linePaint, Paint& fillPaint,
+                           Font& font,
+                           const agg::trans_affine& transform,
+                           Paint& fillPaint,
                            const GraphicsState& gs,
                            base_renderer_t& renderer);
     template<typename base_renderer_t>
     void _draw_text_vector(GlyphIterator& iterator,
-                           agg::trans_affine& transform,
+                           Font& font,
+                           const agg::trans_affine& transform,
                            Paint& linePaint, Paint& fillPaint,
                            const GraphicsState& gs,
                            base_renderer_t& renderer);
diff --git a/celiagg/ndarray_canvas.hxx b/celiagg/ndarray_canvas.hxx
index 9182697..4b0f5dc 100644
--- a/celiagg/ndarray_canvas.hxx
+++ b/celiagg/ndarray_canvas.hxx
@@ -270,38 +270,22 @@ void ndarray_canvas<pixfmt_t>::_draw_text_internal(const char* text, Font& font,
     const agg::trans_affine& transform, Paint& linePaint, Paint& fillPaint,
     const GraphicsState& gs, base_renderer_t& renderer)
 {
-    agg::trans_affine mtx = transform;
-    double transform_array[6];
-    double start_x, start_y;
-    const bool font_flip = font.flip();
-
     // Flip the font?
+    const bool font_flip = font.flip();
     font.flip(!m_bottom_up);
 
-    // Pull the translation values out of the matrix as our starting offset and
-    // then replace them with zeros for use in the font engine.
-    mtx.store_to(transform_array);
-    start_x = transform_array[4];
-    start_y = transform_array[5];
-    transform_array[4] = 0.0;
-    transform_array[5] = 0.0;
-    mtx.load_from(transform_array);
-
-    // Make sure the font is activated
-    m_font_cache.activate(font, mtx);
-
-    GlyphIterator iterator(text, m_font_cache, true, start_x, start_y);
-    if (font.cache_type() == Font::RasterFontCache)
+    GlyphIterator iterator(text, m_font_cache, true);
+    if (gs.text_drawing_mode() == GraphicsState::TextDrawRaster)
     {
-        _draw_text_raster(iterator, mtx, linePaint, fillPaint, gs, renderer);
+        // Raster text only uses the fill paint!
+        _draw_text_raster(iterator, font, transform, fillPaint, gs, renderer);
     }
     else
     {
-        agg::trans_affine identity;
-        // XXX: TextDrawingMode only applies to Vector fonts!
+        // Pick the correct drawing mode for the glyph paths
         GraphicsState copy_state(gs);
         copy_state.drawing_mode(_convert_text_mode(gs.text_drawing_mode()));
-        _draw_text_vector(iterator, identity, linePaint, fillPaint, copy_state, renderer);
+        _draw_text_vector(iterator, font, transform, linePaint, fillPaint, copy_state, renderer);
     }
 
     // Restore the font's flip state to whatever it was
@@ -311,25 +295,41 @@ void ndarray_canvas<pixfmt_t>::_draw_text_internal(const char* text, Font& font,
 template<typename pixfmt_t>
 template<typename base_renderer_t>
 void ndarray_canvas<pixfmt_t>::_draw_text_raster(GlyphIterator& iterator,
-    agg::trans_affine& transform, Paint& linePaint, Paint& fillPaint,
+    Font& font, const agg::trans_affine& transform, Paint& fillPaint,
     const GraphicsState& gs, base_renderer_t& renderer)
 {
 #ifdef _ENABLE_TEXT_RENDERING
     typedef FontCache::FontCacheManager::gray8_adaptor_type font_rasterizer_t;
     typedef FontCache::FontCacheManager::gray8_scanline_type scanline_t;
 
-    font_rasterizer_t& ras = m_font_cache.manager().gray8_adaptor();
-    scanline_t& scanline = m_font_cache.manager().gray8_scanline();
-
     const bool eof = (gs.drawing_mode() & GraphicsState::DrawEofFill) == GraphicsState::DrawEofFill;
     m_rasterizer.filling_rule(eof ? agg::fill_even_odd : agg::fill_non_zero);
 
+    // Strip the translation out of the transformation when activating the font
+    // so that the cached glyphs aren't associated with a specific translation,
+    // only the current rotation & shear.
+    double transform_array[6];
+    transform.store_to(transform_array);
+    transform_array[4] = 0.0; transform_array[5] = 0.0;
+    m_font_cache.activate(font, agg::trans_affine(transform_array), FontCache::RasterGlyph);
+
+    // Determine the starting glyph position from the transform and initialize
+    // the iterator.
+    double start_x = 0.0, start_y = 0.0;
+    transform.transform(&start_x, &start_y);
+    iterator.offset(start_x, start_y);
+
+    // Rendery bits from the font cache
+    font_rasterizer_t& ras = m_font_cache.manager().gray8_adaptor();
+    scanline_t& scanline = m_font_cache.manager().gray8_scanline();
+
+    // Draw the glyphs one at a time
     GlyphIterator::StepAction action = GlyphIterator::k_StepActionInvalid;
     while (action != GlyphIterator::k_StepActionEnd)
     {
         if (action == GlyphIterator::k_StepActionDraw)
         {
-            linePaint.render<pixfmt_t, font_rasterizer_t, scanline_t, base_renderer_t>(ras, scanline, renderer, transform);
+            fillPaint.render<pixfmt_t, font_rasterizer_t, scanline_t, base_renderer_t>(ras, scanline, renderer, transform);
         }
         action = iterator.step();
     }
@@ -339,25 +339,26 @@ void ndarray_canvas<pixfmt_t>::_draw_text_raster(GlyphIterator& iterator,
 template<typename pixfmt_t>
 template<typename base_renderer_t>
 void ndarray_canvas<pixfmt_t>::_draw_text_vector(GlyphIterator& iterator,
-    agg::trans_affine& transform, Paint& linePaint, Paint& fillPaint,
+    Font& font, const agg::trans_affine& transform, Paint& linePaint, Paint& fillPaint,
     const GraphicsState& gs, base_renderer_t& renderer)
 {
 #ifdef _ENABLE_TEXT_RENDERING
-    typedef agg::conv_transform<FontCache::FontCacheManager::path_adaptor_type> trans_font_t;
+    PathSource shape;
+
+    // Activate the font with an identity transform. The passed in transform
+    // will be applied later when drawing the generated path.
+    m_font_cache.activate(font, agg::trans_affine(), FontCache::VectorGlyph);
 
     GlyphIterator::StepAction action = GlyphIterator::k_StepActionInvalid;
     while (action != GlyphIterator::k_StepActionEnd)
     {
         if (action == GlyphIterator::k_StepActionDraw)
         {
-            trans_font_t tr(m_font_cache.manager().path_adaptor(), transform);
-            PathSource shape;
-            shape.concat_path(tr, 0);
-
-            _draw_shape_internal(shape, transform, linePaint, fillPaint, gs, renderer);
+            shape.concat_path(m_font_cache.manager().path_adaptor(), 0);
         }
         action = iterator.step();
     }
+    _draw_shape_internal(shape, transform, linePaint, fillPaint, gs, renderer);
 #endif
 }
 
@@ -372,6 +373,7 @@ GraphicsState::DrawingMode ndarray_canvas<pixfmt_t>::_convert_text_mode(const Gr
         case GraphicsState::TextDrawClip:
         case GraphicsState::TextDrawFill:
         case GraphicsState::TextDrawFillClip:
+        case GraphicsState::TextDrawRaster:
             return GraphicsState::DrawFill;
         case GraphicsState::TextDrawStroke:
         case GraphicsState::TextDrawStrokeClip:


Test patch:
diff --git a/celiagg/tests/test_canvas.py b/celiagg/tests/test_canvas.py
index f58d547..6a23b30 100644
--- a/celiagg/tests/test_canvas.py
+++ b/celiagg/tests/test_canvas.py
@@ -50,9 +50,7 @@ def test_bad_method_args(self):
 
         if agg.HAS_TEXT:
             text = 'Hello!'
-            font = agg.Font(
-                'Times New Roman', 12.0, agg.FontCacheType.RasterFontCache
-            )
+            font = agg.Font('Times New Roman', 12.0)
             with self.assertRaises(TypeError):
                 canvas.draw_text(text, None, transform, gs)
             with self.assertRaises(TypeError):
diff --git a/celiagg/tests/test_text.py b/celiagg/tests/test_text.py
index e67efba..3f1b337 100644
--- a/celiagg/tests/test_text.py
+++ b/celiagg/tests/test_text.py
@@ -20,18 +20,9 @@ def test_font_byte_string(self):
         transform = agg.Transform()
 
         text_unicode = 'Hello!'
-        font_unicode = agg.Font(
-            FONT_FILE,
-            12.0,
-            agg.FontCacheType.RasterFontCache,
-            face_index=1,
-        )
+        font_unicode = agg.Font(FONT_FILE, 12.0, face_index=1)
         text_byte = b'Hello!'
-        font_byte = agg.Font(
-            FONT_FILE.encode('utf8'),
-            12.0,
-            agg.FontCacheType.RasterFontCache,
-        )
+        font_byte = agg.Font(FONT_FILE.encode('utf8'), 12.0)
 
         canvas.draw_text(text_unicode, font_unicode, transform, gs)
         canvas.draw_text(text_byte, font_unicode, transform, gs)
@@ -45,7 +36,7 @@ def test_text_rendering(self):
         )
         canvas.clear(1.0, 1.0, 1.0)
 
-        font = agg.Font(FONT_FILE, 24.0, agg.FontCacheType.RasterFontCache)
+        font = agg.Font(FONT_FILE, 24.0)
         gs = agg.GraphicsState()
         paint = agg.SolidPaint(1.0, 0.0, 0.0, 1.0)
         transform = agg.Transform()
@@ -65,7 +56,7 @@ def test_text_measurement(self):
         canvas = agg.CanvasRGB24(
             np.zeros((100, 100, 3), dtype=np.uint8), font_cache=font_cache,
         )
-        font = agg.Font(FONT_FILE, 12.0, agg.FontCacheType.RasterFontCache)
+        font = agg.Font(FONT_FILE, 12.0)
         gs = agg.GraphicsState()
         paint = agg.SolidPaint(1.0, 0.0, 0.0, 1.0)
         text = 'Some appropriate string'