diff options
author | Alexei Podtelezhnikov <apodtele@gmail.com> | 2018-06-17 22:33:29 -0400 |
---|---|---|
committer | Alexei Podtelezhnikov <apodtele@gmail.com> | 2018-06-17 22:33:29 -0400 |
commit | b1a3c59f8df2b6f1a0c1ddf10fbfc67138c32cc5 (patch) | |
tree | 400fb6861718bcde489ec30b12f8a0334f5b5295 | |
parent | e13599a0369cf68279b991dbab3e845d7a300399 (diff) | |
download | freetype2-b1a3c59f8df2b6f1a0c1ddf10fbfc67138c32cc5.tar.gz |
[base] Introduce `FT_New_Glyph'.
This function facilitates access to full capabilities of FreeType
rendering engine for custom glyphs. This can be quite useful for
consistent rendering of mathematical and chemical formulas, e.g.
https://bugs.chromium.org/p/chromium/issues/detail?id=757078
* include/freetype/ftglyph.h, src/base/ftglyph.c (FT_New_Glyph): New
function.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | include/freetype/ftglyph.h | 29 | ||||
-rw-r--r-- | src/base/ftglyph.c | 55 |
3 files changed, 74 insertions, 23 deletions
@@ -1,3 +1,16 @@ +2018-06-17 Alexei Podtelezhnikov <apodtele@gmail.com> + + [base] Introduce `FT_New_Glyph'. + + This function facilitates access to full capabilities of FreeType + rendering engine for custom glyphs. This can be quite useful for + consistent rendering of mathematical and chemical formulas, e.g. + + https://bugs.chromium.org/p/chromium/issues/detail?id=757078 + + * include/freetype/ftglyph.h, src/base/ftglyph.c (FT_New_Glyph): New + function. + 2018-06-17 Armin Hasitzka <prince.cherusker@gmail.com> [bdf] Fix underflow of an unsigned value. diff --git a/include/freetype/ftglyph.h b/include/freetype/ftglyph.h index 81d281595..e1f72a972 100644 --- a/include/freetype/ftglyph.h +++ b/include/freetype/ftglyph.h @@ -226,6 +226,35 @@ FT_BEGIN_HEADER /************************************************************************** * * @function: + * FT_New_Glyph + * + * @description: + * A function used to create a new empty glyph image. Note that + * the created @FT_Glyph object must be released with @FT_Done_Glyph. + * + * @input: + * library :: A handle to the FreeType library object. + * + * format :: The format of the glyph's image. + * + * @output: + * aglyph :: A handle to the glyph object. + * + * @return: + * FreeType error code. 0~means success. + * + * @since + * 2.10 + */ + FT_EXPORT( FT_Error ) + FT_New_Glyph( FT_Library library, + FT_Glyph_Format format, + FT_Glyph *aglyph ); + + + /************************************************************************** + * + * @function: * FT_Get_Glyph * * @description: diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index c326e9b9b..8bc86a542 100644 --- a/src/base/ftglyph.c +++ b/src/base/ftglyph.c @@ -358,37 +358,28 @@ /* documentation is in ftglyph.h */ - FT_EXPORT_DEF( FT_Error ) - FT_Get_Glyph( FT_GlyphSlot slot, - FT_Glyph *aglyph ) + FT_EXPORT( FT_Error ) + FT_New_Glyph( FT_Library library, + FT_Glyph_Format format, + FT_Glyph *aglyph ) { - FT_Library library; - FT_Error error; - FT_Glyph glyph; - const FT_Glyph_Class* clazz = NULL; - - if ( !slot ) - return FT_THROW( Invalid_Slot_Handle ); - - library = slot->library; - - if ( !aglyph ) + if ( !library || !aglyph ) return FT_THROW( Invalid_Argument ); /* if it is a bitmap, that's easy :-) */ - if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) + if ( format == FT_GLYPH_FORMAT_BITMAP ) clazz = &ft_bitmap_glyph_class; /* if it is an outline */ - else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) + else if ( format == FT_GLYPH_FORMAT_OUTLINE ) clazz = &ft_outline_glyph_class; else { /* try to find a renderer that supports the glyph image format */ - FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); + FT_Renderer render = FT_Lookup_Renderer( library, format, 0 ); if ( render ) @@ -396,13 +387,31 @@ } if ( !clazz ) - { - error = FT_THROW( Invalid_Glyph_Format ); - goto Exit; - } + return FT_THROW( Invalid_Glyph_Format ); + + /* create FT_Glyph object */ + return ft_new_glyph( library, clazz, aglyph ); + } + + + /* documentation is in ftglyph.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Get_Glyph( FT_GlyphSlot slot, + FT_Glyph *aglyph ) + { + FT_Error error; + FT_Glyph glyph; + + + if ( !slot ) + return FT_THROW( Invalid_Slot_Handle ); + + if ( !aglyph ) + return FT_THROW( Invalid_Argument ); /* create FT_Glyph object */ - error = ft_new_glyph( library, clazz, &glyph ); + error = FT_New_Glyph( slot->library, slot->format, &glyph ); if ( error ) goto Exit; @@ -426,7 +435,7 @@ glyph->advance.y = slot->advance.y * 1024; /* now import the image from the glyph slot */ - error = clazz->glyph_init( glyph, slot ); + error = glyph->clazz->glyph_init( glyph, slot ); Exit2: /* if an error occurred, destroy the glyph */ |