Possible API/ABI incompatibility with SDL2-ttf

Ryan C. Gordon icculus at icculus.org
Fri Jan 29 20:05:23 UTC 2016


> Thanks for the confirmation.  Please let us know if you go ahead with
> 2.0.14 or what's the final resolution.

Here's the proposed fix, for inclusion in a speedy 2.0.14 release 
(attached). Sam, let me know if I should push this when you get a moment.

--ryan.


-------------- next part --------------
# HG changeset patch
# User Ryan C. Gordon <icculus at icculus.org>
# Date 1454097815 18000
#      Fri Jan 29 15:03:35 2016 -0500
# Node ID 9eebcfd9a538cc0f879db2a48bbae18639b8d182
# Parent  a99da50ec45be5aeb0b93001ddab9282a381a8e0
Restored binary compatibility for TTF_GetFontKerningSize().

The (corrected) behavior of this function has been moved to a new API,
named TTF_GetFontKerningSizeGlyphs(), and the original function has been
restored to its wrong behavior and marked as deprecated.

diff --git a/SDL_ttf.c b/SDL_ttf.c
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -2196,7 +2196,15 @@
     return TTF_initialized;
 }
 
-int TTF_GetFontKerningSize(TTF_Font *font, Uint16 previous_ch, Uint16 ch)
+/* don't use this function. It's just here for binary compatibility. */
+int TTF_GetFontKerningSize(TTF_Font* font, int prev_index, int index)
+{
+    FT_Vector delta;
+    FT_Get_Kerning( font->face, prev_index, index, ft_kerning_default, &delta );
+    return (delta.x >> 6);
+}
+
+int TTF_GetFontKerningSizeGlyphs(TTF_Font *font, Uint16 previous_ch, Uint16 ch)
 {
     int error;
     int glyph_index, prev_index;
@@ -2231,3 +2239,4 @@
     }
     return (delta.x >> 6);
 }
+
diff --git a/SDL_ttf.h b/SDL_ttf.h
--- a/SDL_ttf.h
+++ b/SDL_ttf.h
@@ -24,6 +24,10 @@
     http://www.freetype.org/
 */
 
+/* Note: In many places, SDL_ttf will say "glyph" when it means "code point."
+   Unicode is hard, we learn as we go, and we apologize for adding to the
+   confusion. */
+
 #ifndef _SDL_TTF_H
 #define _SDL_TTF_H
 
@@ -247,8 +251,16 @@
 /* Check if the TTF engine is initialized */
 extern DECLSPEC int SDLCALL TTF_WasInit(void);
 
+/* Get the kerning size of two glyphs indices */
+/* DEPRECATED: this function requires FreeType font indexes, not glyphs,
+   by accident, which we don't expose through this API, so it could give
+   wildly incorrect results, especially with non-ASCII values.
+   Going forward, please use TTF_GetFontKerningSizeGlyphs() instead, which
+   does what you probably expected this function to do. */
+extern DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index) SDL_DEPRECATED;
+
 /* Get the kerning size of two glyphs */
-extern DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, Uint16 previous_ch, Uint16 ch);
+extern DECLSPEC int TTF_GetFontKerningSizeGlyphs(TTF_Font *font, Uint16 previous_ch, Uint16 ch);
 
 /* We'll use SDL for reporting errors */
 #define TTF_SetError    SDL_SetError


More information about the Pkg-sdl-maintainers mailing list