Browse code

lavfi/drawtext: get bitmap from glyph in a separate step

This change makes it possible to transform the glyph or get its border before
turning it into a bitmap.

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Ramiro Polla authored on 2014/01/10 22:03:12
Showing 2 changed files
... ...
@@ -3594,7 +3594,7 @@ a combination of the following values:
3594 3594
 @item no_autohint
3595 3595
 @end table
3596 3596
 
3597
-Default value is "render".
3597
+Default value is "default".
3598 3598
 
3599 3599
 For more information consult the documentation for the FT_LOAD_*
3600 3600
 libfreetype flags.
... ...
@@ -206,7 +206,7 @@ static const AVOption drawtext_options[]= {
206 206
     {"start_number", "start frame number for n/frame_num variable", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS},
207 207
 
208 208
     /* FT_LOAD_* flags */
209
-    { "ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, { .i64 = FT_LOAD_DEFAULT | FT_LOAD_RENDER}, 0, INT_MAX, FLAGS, "ft_load_flags" },
209
+    { "ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, { .i64 = FT_LOAD_DEFAULT }, 0, INT_MAX, FLAGS, "ft_load_flags" },
210 210
         { "default",                     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_DEFAULT },                     .flags = FLAGS, .unit = "ft_load_flags" },
211 211
         { "no_scale",                    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_NO_SCALE },                    .flags = FLAGS, .unit = "ft_load_flags" },
212 212
         { "no_hinting",                  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FT_LOAD_NO_HINTING },                  .flags = FLAGS, .unit = "ft_load_flags" },
... ...
@@ -264,6 +264,7 @@ static int glyph_cmp(void *key, const void *b)
264 264
 static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code)
265 265
 {
266 266
     DrawTextContext *s = ctx->priv;
267
+    FT_BitmapGlyph bitmapglyph;
267 268
     Glyph *glyph;
268 269
     struct AVTreeNode *node = NULL;
269 270
     int ret;
... ...
@@ -284,10 +285,15 @@ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code)
284 284
         ret = AVERROR(EINVAL);
285 285
         goto error;
286 286
     }
287
+    if (FT_Glyph_To_Bitmap(glyph->glyph, FT_RENDER_MODE_NORMAL, 0, 1)) {
288
+        ret = AVERROR_EXTERNAL;
289
+        goto error;
290
+    }
291
+    bitmapglyph = (FT_BitmapGlyph) *glyph->glyph;
287 292
 
288
-    glyph->bitmap      = s->face->glyph->bitmap;
289
-    glyph->bitmap_left = s->face->glyph->bitmap_left;
290
-    glyph->bitmap_top  = s->face->glyph->bitmap_top;
293
+    glyph->bitmap      = bitmapglyph->bitmap;
294
+    glyph->bitmap_left = bitmapglyph->left;
295
+    glyph->bitmap_top  = bitmapglyph->top;
291 296
     glyph->advance     = s->face->glyph->advance.x >> 6;
292 297
 
293 298
     /* measure text height to calculate text_height (or the maximum text height) */