freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] undefined_scale 3d9c3045c: [base] Undefined scale means no s


From: Werner Lemberg
Subject: [freetype2] undefined_scale 3d9c3045c: [base] Undefined scale means no scale.
Date: Wed, 19 Jan 2022 14:55:42 -0500 (EST)

branch: undefined_scale
commit 3d9c3045c03871c280ae09d053b87584ce3ea10c
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [base] Undefined scale means no scale.
    
    It might be surprising that FreeType does not have default ppem and
    the size has to be set explicitly or face undefined behavior with
    undefined variables and errors. This offers an alternative to
    missing or zero scale by simply setting FT_LOAD_NO_SCALE.
    
    This is alternative to !132 and discussed in
      https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=43708
    
    * src/base/ftobjs.c (FT_Load_Glyph): Deal with zero scale.
    * include/freetype/freetype.h: Document it.
---
 include/freetype/freetype.h | 11 ++++++++---
 src/base/ftobjs.c           |  5 +++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index d3ea3f0b9..44978f978 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -522,13 +522,13 @@ FT_BEGIN_HEADER
    *   size.
    *
    * @note:
-   *   An @FT_Face has one _active_ @FT_Size object that is used by functions
+   *   An @FT_Face has one _active_ FT_Size object that is used by functions
    *   like @FT_Load_Glyph to determine the scaling transformation that in
    *   turn is used to load and hint glyphs and metrics.
    *
    *   You can use @FT_Set_Char_Size, @FT_Set_Pixel_Sizes, @FT_Request_Size
    *   or even @FT_Select_Size to change the content (i.e., the scaling
-   *   values) of the active @FT_Size.
+   *   values) of the active FT_Size.
    *
    *   You can use @FT_New_Size to create additional size objects for a given
    *   @FT_Face, but they won't be used by other functions until you activate
@@ -2819,7 +2819,7 @@ FT_BEGIN_HEADER
    *
    *   load_flags ::
    *     A flag indicating what to load for this glyph.  The @FT_LOAD_XXX
-   *     constants can be used to control the glyph loading process (e.g.,
+   *     flags can be used to control the glyph loading process (e.g.,
    *     whether the outline should be scaled, whether to load bitmaps or
    *     not, whether to hint the outline, etc).
    *
@@ -2827,6 +2827,9 @@ FT_BEGIN_HEADER
    *   FreeType error code.  0~means success.
    *
    * @note:
+   *   For proper scaling and hinting, the active @FT_Size object owned by
+   *   the face has to be meaningfully non-trivially initialized by
+   *   calling @FT_Set_Char_Size before this function, for example.
    *   The loaded glyph may be transformed.  See @FT_Set_Transform for the
    *   details.
    *
@@ -2918,6 +2921,8 @@ FT_BEGIN_HEADER
    *
    *   FT_LOAD_NO_SCALE ::
    *     Don't scale the loaded outline glyph but keep it in font units.
+   *     This flag is also assumed if @FT_Size owned by the face was not
+   *     properly initialized.
    *
    *     This flag implies @FT_LOAD_NO_HINTING and @FT_LOAD_NO_BITMAP, and
    *     unsets @FT_LOAD_RENDER.
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 18de2f7d4..4f5e7d439 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -858,6 +858,11 @@
     library = driver->root.library;
     hinter  = library->auto_hinter;
 
+    /* undefined scale means no scale */
+    if ( face->size->metrics.x_ppem == 0 ||
+         face->size->metrics.y_ppem == 0 )
+      load_flags |= FT_LOAD_NO_SCALE;
+
     /* resolve load flags dependencies */
 
     if ( load_flags & FT_LOAD_NO_RECURSE )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]