Hi,

The docs
<https://freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_render_mode>
say: "To force the use of bsdf you should render the glyph with any of the
FreeType's other rendering modes (e.g., FT_RENDER_MODE_NORMAL) and then
re-render with FT_RENDER_MODE_SDF."
So I did exactly this:
```
unsigned int codepoint = 32; // space character ' '

FT_Load_Char(font, codepoint, FT_LOAD_DEFAULT);
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); // First render

// Now face->glyph has format FT_GLYPH_FORMAT_BITMAP
// But its bitmap has: rows=0, width=0, pitch=0 (because it's a space,
white character)
// And also internal->flag FT_GLYPH_OWN_BITMAP is not set.
// And now I try to re-render it with SDF...
FT_Error error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_SDF); *//
Returns error 6!*
```

The expected behavior, in my opinion, is that there is nothing to render so
no error should be raised.
The problem is that inside function ft_bsdf_render
<https://github.com/freetype/freetype/blob/master/src/sdf/ftsdfrend.c#L464>
we first have this check
<https://github.com/freetype/freetype/blob/master/src/sdf/ftsdfrend.c#L511>:
```
    /* Do not generate SDF if the bitmap is not owned by the       */
    /* glyph: it might be that the source buffer is already freed. */
    if ( !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
    {
      FT_ERROR(( "ft_bsdf_render: can't generate SDF from"
                 " unowned source bitmap\n" ));

      error = FT_THROW( Invalid_Argument );
      goto Exit;
    }
```
And *after that* we have this check
<https://github.com/freetype/freetype/blob/master/src/sdf/ftsdfrend.c#L522>:
```
    /* nothing to render */
    if ( !bitmap->rows || !bitmap->pitch )
      return FT_Err_Ok;
```

The order of these two validations should be changed. If bitmap is empty,
then there is nothing to render => early return.
And then we may have the other validation that is supposed to raise an
error.

Changing the order of these two checks solved my problem.
What do you think?

*Best regards*
*Sebastian*

Reply via email to