freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] wl/sbix 21ca82be6 5/5: [sfnt] Add `sbix-not-scalable` proper


From: Werner Lemberg
Subject: [freetype2] wl/sbix 21ca82be6 5/5: [sfnt] Add `sbix-not-scalable` property.
Date: Thu, 17 Mar 2022 07:00:35 -0400 (EDT)

branch: wl/sbix
commit 21ca82be6cefddfcf0ff985250054772269bfe33
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    [sfnt] Add `sbix-not-scalable` property.
    
    This is for backwards compatibility.
    
    * src/sfnt/sfobjs.h (SFNT_DriverRec): New structure.
    (SFNT_Driver): New typedef.
    
    * src/sfnt/sfdriver.c: Include `svprop.h`.
    (sfnt_property_set, sfnt_property_get): New functions.
    (sfnt_service_properties): New service properties.
    (sfnt_service): Add `sfnt_service_properties`.
    (sfnt_module_class): Updated.
    
    * src/sfnt/sfobjs.c (sfnt_load_face): Set `has_outline` to `FALSE` if
    'sbix-not-scalable' is set.
    
    * include/freetype/ftdriver.h: Update documentation.
---
 include/freetype/ftchapters.h |   7 +--
 include/freetype/ftdriver.h   |  59 ++++++++++++++++++++++
 src/sfnt/sfdriver.c           | 115 ++++++++++++++++++++++++++++++++++++++----
 src/sfnt/sfobjs.c             |   8 +++
 src/sfnt/sfobjs.h             |  13 +++++
 5 files changed, 190 insertions(+), 12 deletions(-)

diff --git a/include/freetype/ftchapters.h b/include/freetype/ftchapters.h
index 6a9733ad7..e686e7976 100644
--- a/include/freetype/ftchapters.h
+++ b/include/freetype/ftchapters.h
@@ -80,10 +80,11 @@
    * @sections:
    *   auto_hinter
    *   cff_driver
-   *   t1_cid_driver
-   *   tt_driver
-   *   pcf_driver
    *   ot_svg_driver
+   *   pcf_driver
+   *   sfnt_driver
+   *   tt_driver
+   *   t1_cid_driver
    *   properties
    *   parameter_tags
    *   lcd_rendering
diff --git a/include/freetype/ftdriver.h b/include/freetype/ftdriver.h
index 0dc91e8b4..213d0f0bb 100644
--- a/include/freetype/ftdriver.h
+++ b/include/freetype/ftdriver.h
@@ -198,6 +198,29 @@ FT_BEGIN_HEADER
    */
 
 
+  /**************************************************************************
+   *
+   * @section:
+   *   sfnt_driver
+   *
+   * @title:
+   *   The SFNT driver
+   *
+   * @abstract:
+   *   Controlling the SFNT driver module.
+   *
+   * @description:
+   *   It is possible to control the behaviour of FreeType's SFNT driver
+   *   (which handles the basic infrastructure for OpenType fonts) with
+   *   @FT_Property_Set and @FT_Property_Get.
+   *
+   *   The SFNT driver's module name is 'sfnt'; a single property
+   *   @sbix-not-scalable is available, as documented in the @properties
+   *   section.
+   *
+   */
+
+
   /**************************************************************************
    *
    * @section:
@@ -633,6 +656,42 @@ FT_BEGIN_HEADER
    */
 
 
+  /**************************************************************************
+   *
+   * @property:
+   *   sbix-not-scalable
+   *
+   * @description:
+   *   The 'sbix' table provides data for bitmap fonts.  It can interact with
+   *   outline glyphs, making it necessary to tag the font as scalable in
+   *   this case.  Older versions of FreeType, however, didn't implement this
+   *   interaction and always tagged fonts with an 'sbix' table as
+   *   non-scalable.
+   *
+   *   If this property is set, FreeType's old behaviour gets activated, that
+   *   is, don't set @FT_FACE_FLAG_SCALABLE and don't look at outline glyphs.
+   *
+   * @note:
+   *   This property can be used with @FT_Property_Get also.
+   *
+   * @example:
+   *   ```
+   *     FT_Library  library;
+   *     FT_Bool     sbix_not_scalable = TRUE;
+   *
+   *
+   *     FT_Init_FreeType( &library );
+   *
+   *     FT_Property_Set( library, "sfnt",
+   *                               "sbix-not-scalable",
+   *                               &sbix_not_scalable );
+   *   ```
+   *
+   * @since:
+   *   2.12
+   */
+
+
   /**************************************************************************
    *
    * @enum:
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index cc121e579..0f8f84964 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -55,6 +55,7 @@
 
 #include <freetype/internal/services/svgldict.h>
 #include <freetype/internal/services/svpostnm.h>
+#include <freetype/internal/services/svprop.h>
 #include <freetype/internal/services/svsfnt.h>
 #include <freetype/internal/services/svttcmap.h>
 
@@ -74,6 +75,98 @@
 #define FT_COMPONENT  sfdriver
 
 
+  /*
+   * PROPERTY SERVICE
+   *
+   */
+  static FT_Error
+  sfnt_property_set( FT_Module    module,         /* SFNT_Driver */
+                     const char*  property_name,
+                     const void*  value,
+                     FT_Bool      value_is_string )
+  {
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+
+    FT_Error     error  = FT_Err_Ok;
+    SFNT_Driver  driver = (SFNT_Driver)module;
+
+
+    if ( !ft_strcmp( property_name, "sbix-not-scalable" ) )
+    {
+      FT_Bool*  sbix_not_scalable = (FT_Bool*)value;
+
+
+      if ( value_is_string == TRUE )
+      {
+        error = FT_THROW( Invalid_Argument );
+        goto Exit;
+      }
+
+      driver->sbix_not_scalable = *sbix_not_scalable;
+    }
+    else
+      error = FT_THROW( Missing_Property );
+
+  Exit:
+    return error;
+
+#else /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+
+    FT_UNUSED( module );
+    FT_UNUSED( property_name );
+    FT_UNUSED( value );
+    FT_UNUSED( value_is_string );
+
+    return FT_THROW( Missing_Property );
+
+#endif /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+  }
+
+
+  static FT_Error
+  sfnt_property_get( FT_Module    module,         /* SFNT_Driver */
+                     const char*  property_name,
+                     const void*  value )
+  {
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+
+    FT_Error     error  = FT_Err_Ok;
+    SFNT_Driver  driver = (SFNT_Driver)module;
+
+
+    if ( !ft_strcmp( property_name, "sbix-not-scalable" ) )
+    {
+      FT_Bool   sbix_not_scalable = driver->sbix_not_scalable;
+      FT_Bool*  val               = (FT_Bool*)value;
+
+
+      *val = sbix_not_scalable;
+    }
+    else
+      error = FT_THROW( Missing_Property );
+
+    return error;
+
+#else /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+
+    FT_UNUSED( module );
+    FT_UNUSED( property_name );
+    FT_UNUSED( value );
+
+    return FT_THROW( Missing_Property );
+
+#endif /* !TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
+  }
+
+
+  FT_DEFINE_SERVICE_PROPERTIESREC(
+    sfnt_service_properties,
+
+    (FT_Properties_SetFunc)sfnt_property_set,     /* set_property */
+    (FT_Properties_GetFunc)sfnt_property_get      /* get_property */
+  )
+
+
   /*
    * SFNT TABLE SERVICE
    *
@@ -1158,37 +1251,41 @@
    */
 
 #if defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES && defined TT_CONFIG_OPTION_BDF
-  FT_DEFINE_SERVICEDESCREC5(
+  FT_DEFINE_SERVICEDESCREC6(
     sfnt_services,
 
     FT_SERVICE_ID_SFNT_TABLE,           &sfnt_service_sfnt_table,
     FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name,
     FT_SERVICE_ID_GLYPH_DICT,           &sfnt_service_glyph_dict,
     FT_SERVICE_ID_BDF,                  &sfnt_service_bdf,
-    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info )
+    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info,
+    FT_SERVICE_ID_PROPERTIES,           &sfnt_service_properties )
 #elif defined TT_CONFIG_OPTION_POSTSCRIPT_NAMES
-  FT_DEFINE_SERVICEDESCREC4(
+  FT_DEFINE_SERVICEDESCREC5(
     sfnt_services,
 
     FT_SERVICE_ID_SFNT_TABLE,           &sfnt_service_sfnt_table,
     FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name,
     FT_SERVICE_ID_GLYPH_DICT,           &sfnt_service_glyph_dict,
-    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info )
+    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info,
+    FT_SERVICE_ID_PROPERTIES,           &sfnt_service_properties )
 #elif defined TT_CONFIG_OPTION_BDF
-  FT_DEFINE_SERVICEDESCREC4(
+  FT_DEFINE_SERVICEDESCREC5(
     sfnt_services,
 
     FT_SERVICE_ID_SFNT_TABLE,           &sfnt_service_sfnt_table,
     FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name,
     FT_SERVICE_ID_BDF,                  &sfnt_service_bdf,
-    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info )
+    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info,
+    FT_SERVICE_ID_PROPERTIES,           &sfnt_service_properties )
 #else
-  FT_DEFINE_SERVICEDESCREC3(
+  FT_DEFINE_SERVICEDESCREC4(
     sfnt_services,
 
     FT_SERVICE_ID_SFNT_TABLE,           &sfnt_service_sfnt_table,
     FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name,
-    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info )
+    FT_SERVICE_ID_TT_CMAP,              &tt_service_get_cmap_info,
+    FT_SERVICE_ID_PROPERTIES,           &sfnt_service_properties )
 #endif
 
 
@@ -1329,7 +1426,7 @@
     sfnt_module_class,
 
     0,  /* not a font driver or renderer */
-    sizeof ( FT_ModuleRec ),
+    sizeof ( SFNT_DriverRec ),
 
     "sfnt",     /* driver name                            */
     0x10000L,   /* driver version 1.0                     */
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index efef128f3..71146424f 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -851,6 +851,14 @@
     is_apple_sbit = 0;
     is_apple_sbix = !face->goto_table( face, TTAG_sbix, stream, 0 );
 
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    /* This is for backwards compatibility, also making FreeType   */
+    /* ignore outline glyph bounding boxes to adjust the positions */
+    /* of 'sbix' bitmaps.                                          */
+    if ( ((SFNT_Driver)FT_FACE_DRIVER( face ))->sbix_not_scalable )
+      has_outline = FALSE;
+#endif
+
     /* if this font doesn't contain outlines, we try to load */
     /* a `bhed' table                                        */
     if ( !has_outline && sfnt->load_bhed )
diff --git a/src/sfnt/sfobjs.h b/src/sfnt/sfobjs.h
index 1d99bfede..2e3b9389d 100644
--- a/src/sfnt/sfobjs.h
+++ b/src/sfnt/sfobjs.h
@@ -27,6 +27,19 @@
 FT_BEGIN_HEADER
 
 
+  typedef struct  SFNT_DriverRec_
+  {
+    FT_DriverRec  root;
+
+#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
+    FT_Bool  sbix_not_scalable;  /* for backward compatibility */
+#endif
+
+  } SFNT_DriverRec;
+
+  typedef struct SFNT_DriverRec_*  SFNT_Driver;
+
+
   FT_LOCAL( FT_Error )
   sfnt_init_face( FT_Stream      stream,
                   TT_Face        face,



reply via email to

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