[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
diff --git a/ChangeLog b/ChangeLog
index a17e8f0..ce05ec5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 81d2815..e1f72a9 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 c326e9b..8bc86a5 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 */