Commits

tanoku  committed 0e05b63

Changed text advance vector to dynamically allocated.

  • Participants
  • Parent commits a103e61
  • Branches pgreloaded

Comments (0)

Files changed (4)

File src/freetype/ft_metrics.c

 _PGFT_GetTextSize_INTERNAL(FreeTypeInstance *ft, PyFreeTypeFont *font, 
     const FontRenderMode *render, FontText *text)
 {
-    FT_Vector   extent, advances[PGFT_MAX_GLYPHS];
+    FT_Vector   extent;
     FT_Error    error;
     FT_Vector   size;
 
-    error = PGFT_GetTextAdvances(ft, font, render, text, advances);
+    error = PGFT_LoadTextAdvances(ft, font, render, text);
 
     if (error)
         return error;
 
-    extent = advances[text->length - 1];
+    extent = text->advances[text->length - 1];
 
     if (render->render_flags & FT_RFLAG_VERTICAL)
     {

File src/freetype/ft_render.c

     const FT_Fixed center = (1 << 15); // 0.5
 
     int         n;
-    FT_Vector   pen, advances[PGFT_MAX_GLYPHS];
+    FT_Vector   pen; 
     FT_Matrix   rotation_matrix;
     FT_Face     face;
     FT_Error    error;
+    FT_Vector   *advances = NULL;
 
     FT_Fixed    bold_str = 0;
 
     /******************************************************
      * Load advance information
      ******************************************************/
-    error = PGFT_GetTextAdvances(ft, font, render, text, advances);
+    error = PGFT_LoadTextAdvances(ft, font, render, text);
 
     if (error)
     {
         return error;
     }
 
+    advances = text->advances;
+
     /******************************************************
      * Build rotation matrix for rotated text
      ******************************************************/

File src/freetype/ft_text.c

     /* create the text struct */
     ftext = &(PGFT_INTERNALS(font)->active_text);
 
-    free(ftext->glyphs);
-    ftext->glyphs = calloc((size_t)string_length, sizeof(FontGlyph *));
+    if (string_length > ftext->length)
+    {
+        free(ftext->glyphs);
+        ftext->glyphs = malloc((size_t)string_length * sizeof(FontGlyph *));
+
+        free(ftext->advances);
+        ftext->advances = malloc((size_t)string_length * sizeof(FT_Vector));
+    }
 
     ftext->length = string_length;
     ftext->glyph_size.x = ftext->glyph_size.y = 0;
 }
 
 int
-PGFT_GetTextAdvances(FreeTypeInstance *ft, PyFreeTypeFont *font, 
-        const FontRenderMode *render, FontText *text, FT_Vector *advances)
+PGFT_LoadTextAdvances(FreeTypeInstance *ft, PyFreeTypeFont *font, 
+        const FontRenderMode *render, FontText *text)
 {
     /* Default kerning mode for all text */
     const int FT_KERNING_MODE = 1;
     FT_Vector   extent       = {0, 0};
     FT_Int      i;
     FT_Fixed    bold_str    = 0;
+    FT_Vector   *advances   = NULL;
 
     face = _PGFT_GetFaceSized(ft, font, render->pt_size);
 
     if (!face)
         return -1;
 
+    advances = text->advances;
+
     if (render->style & FT_STYLE_BOLD)
         bold_str = PGFT_GetBoldStrength(face);
 

File src/freetype/ft_wrap.h

 typedef struct __fonttext
 {
     FontGlyph **glyphs;
+    FT_Vector *advances;
     int length;
 
     FT_Vector glyph_size;       /* 26.6 */
 FontText *  PGFT_LoadFontText(FreeTypeInstance *ft, PyFreeTypeFont *font, 
                 const FontRenderMode *render, PyObject *text);
 
-int         PGFT_GetTextAdvances(FreeTypeInstance *ft, PyFreeTypeFont *font, 
-                const FontRenderMode *render, FontText *text, FT_Vector *advances);
+int         PGFT_LoadTextAdvances(FreeTypeInstance *ft, PyFreeTypeFont *font, 
+                const FontRenderMode *render, FontText *text);
 
 FT_UInt16 * PGFT_BuildUnicodeString(PyObject *);