freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] master 7ef2660 2/4: [sfnt] Reduce footprint if WOFF and WOFF


From: Werner Lemberg
Subject: [freetype2] master 7ef2660 2/4: [sfnt] Reduce footprint if WOFF and WOFF2 support is not needed.
Date: Mon, 8 Nov 2021 05:48:07 -0500 (EST)

branch: master
commit 7ef266045f412cf49f620f1142fc8778ce8c2f9f
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    [sfnt] Reduce footprint if WOFF and WOFF2 support is not needed.
    
    Based on a patch from metarutaiga (MR !106).  The gist of this commit is
    that it doesn't make sense to support WOFF without compression (which would
    be only possible in WOFF 1.0 anyway).
    
    * src/sfnt/sfobjs.c (sfnt_open_font): Guard WOFF code with
    `FT_CONFIG_OPTION_USE_ZLIB` block.
    Guard WOFF2 code with `FT_CONFIG_OPTION_USE_BROTLI` block.
    
    * src/sfnt/sfwoff.c, src/sfnt/sfwoff.h: Guard files with
    `FT_CONFIG_OPTION_USE_ZLIB` blocks, not parts of the code.
    
    * src/sfnt/sfwoff2.c, src/sfnt/sfwoff2.h, src/sfnt/woff2tags.c,
    src/sfnt/woff2tags.h: Guard files with `FT_CONFIG_OPTION_USE_BROTLI` blocks,
    not parts of the code.
    
    Fixes #1111.
---
 src/sfnt/sfobjs.c    | 13 +++++++++++++
 src/sfnt/sfwoff.c    | 19 ++++++++++---------
 src/sfnt/sfwoff.h    |  3 +++
 src/sfnt/sfwoff2.c   | 23 +++++++----------------
 src/sfnt/sfwoff2.h   |  2 ++
 src/sfnt/woff2tags.c | 10 ++++++++++
 src/sfnt/woff2tags.h |  4 +++-
 7 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index 656bb41..233bdb4 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -360,17 +360,27 @@
       FT_FRAME_END
     };
 
+#ifndef FT_CONFIG_OPTION_USE_BROTLI
+    FT_UNUSED( face_instance_index );
+    FT_UNUSED( woff2_num_faces );
+#endif
+
 
     face->ttc_header.tag     = 0;
     face->ttc_header.version = 0;
     face->ttc_header.count   = 0;
 
+#if defined( FTCONFIG_OPTION_USE_ZLIB )    || \
+    defined( FT_CONFIG_OPTION_USE_BROTLI )
   retry:
+#endif
+
     offset = FT_STREAM_POS();
 
     if ( FT_READ_ULONG( tag ) )
       return error;
 
+#ifdef FT_CONFIG_OPTION_USE_ZLIB
     if ( tag == TTAG_wOFF )
     {
       FT_TRACE2(( "sfnt_open_font: file is a WOFF; synthesizing SFNT\n" ));
@@ -386,7 +396,9 @@
       stream = face->root.stream;
       goto retry;
     }
+#endif
 
+#ifdef FT_CONFIG_OPTION_USE_BROTLI
     if ( tag == TTAG_wOF2 )
     {
       FT_TRACE2(( "sfnt_open_font: file is a WOFF2; synthesizing SFNT\n" ));
@@ -405,6 +417,7 @@
       stream = face->root.stream;
       goto retry;
     }
+#endif
 
     if ( tag != 0x00010000UL &&
          tag != TTAG_ttcf    &&
diff --git a/src/sfnt/sfwoff.c b/src/sfnt/sfwoff.c
index af14928..422c816 100644
--- a/src/sfnt/sfwoff.c
+++ b/src/sfnt/sfwoff.c
@@ -23,6 +23,9 @@
 #include <freetype/ftgzip.h>
 
 
+#ifdef FT_CONFIG_OPTION_USE_ZLIB
+
+
   /**************************************************************************
    *
    * The macro FT_COMPONENT is used in trace mode.  It is an implicit
@@ -360,8 +363,6 @@
       }
       else
       {
-#ifdef FT_CONFIG_OPTION_USE_ZLIB
-
         /* Uncompress with zlib. */
         FT_ULong  output_len = table->OrigLength;
 
@@ -377,13 +378,6 @@
           error = FT_THROW( Invalid_Table );
           goto Exit1;
         }
-
-#else /* !FT_CONFIG_OPTION_USE_ZLIB */
-
-        error = FT_THROW( Unimplemented_Feature );
-        goto Exit1;
-
-#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
       }
 
       FT_FRAME_EXIT();
@@ -433,5 +427,12 @@
 #undef WRITE_USHORT
 #undef WRITE_ULONG
 
+#else /* !FT_CONFIG_OPTION_USE_ZLIB */
+
+  /* ANSI C doesn't like empty source files */
+  typedef int  _sfwoff_dummy;
+
+#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
+
 
 /* END */
diff --git a/src/sfnt/sfwoff.h b/src/sfnt/sfwoff.h
index e2f2273..3fbdac0 100644
--- a/src/sfnt/sfwoff.h
+++ b/src/sfnt/sfwoff.h
@@ -26,12 +26,15 @@
 
 FT_BEGIN_HEADER
 
+#ifdef FT_CONFIG_OPTION_USE_ZLIB
 
   FT_LOCAL( FT_Error )
   woff_open_font( FT_Stream  stream,
                   TT_Face    face );
 
 
+#endif
+
 FT_END_HEADER
 
 #endif /* SFWOFF_H_ */
diff --git a/src/sfnt/sfwoff2.c b/src/sfnt/sfwoff2.c
index 7041b75..5ee8dea 100644
--- a/src/sfnt/sfwoff2.c
+++ b/src/sfnt/sfwoff2.c
@@ -26,8 +26,6 @@
 
 #include <brotli/decode.h>
 
-#endif
-
 
   /**************************************************************************
    *
@@ -316,8 +314,6 @@
                     const FT_Byte*  src,
                     FT_ULong        src_size )
   {
-#ifdef FT_CONFIG_OPTION_USE_BROTLI
-
     /* this cast is only of importance on 32bit systems; */
     /* we don't validate it                              */
     FT_Offset            uncompressed_size = (FT_Offset)dst_size;
@@ -338,18 +334,6 @@
 
     FT_TRACE2(( "woff2_decompress: Brotli stream decompressed.\n" ));
     return FT_Err_Ok;
-
-#else /* !FT_CONFIG_OPTION_USE_BROTLI */
-
-    FT_UNUSED( dst );
-    FT_UNUSED( dst_size );
-    FT_UNUSED( src );
-    FT_UNUSED( src_size );
-
-    FT_ERROR(( "woff2_decompress: Brotli support not available.\n" ));
-    return FT_THROW( Unimplemented_Feature );
-
-#endif /* !FT_CONFIG_OPTION_USE_BROTLI */
   }
 
 
@@ -2356,5 +2340,12 @@
 #undef BBOX_STREAM
 #undef INSTRUCTION_STREAM
 
+#else /* !FT_CONFIG_OPTION_USE_BROTLI */
+
+  /* ANSI C doesn't like empty source files */
+  typedef int  _sfwoff2_dummy;
+
+#endif /* !FT_CONFIG_OPTION_USE_BROTLI */
+
 
 /* END */
diff --git a/src/sfnt/sfwoff2.h b/src/sfnt/sfwoff2.h
index 27f3da7..fa78b02 100644
--- a/src/sfnt/sfwoff2.h
+++ b/src/sfnt/sfwoff2.h
@@ -26,6 +26,7 @@
 
 FT_BEGIN_HEADER
 
+#ifdef FT_CONFIG_OPTION_USE_BROTLI
 
   /* Leave the first byte open to store `flag_byte'. */
 #define WOFF2_FLAGS_TRANSFORM   1 << 8
@@ -66,6 +67,7 @@ FT_BEGIN_HEADER
                    FT_Int*    face_index,
                    FT_Long*   num_faces );
 
+#endif /* FT_CONFIG_OPTION_USE_BROTLI */
 
 FT_END_HEADER
 
diff --git a/src/sfnt/woff2tags.c b/src/sfnt/woff2tags.c
index a299822..fe8f5cf 100644
--- a/src/sfnt/woff2tags.c
+++ b/src/sfnt/woff2tags.c
@@ -17,6 +17,9 @@
 
 
 #include <freetype/tttags.h>
+
+#ifdef FT_CONFIG_OPTION_USE_BROTLI
+
 #include "woff2tags.h"
 
   /*
@@ -105,5 +108,12 @@
     return known_tags[index];
   }
 
+#else /* !FT_CONFIG_OPTION_USE_BROTLI */
+
+  /* ANSI C doesn't like empty source files */
+  typedef int  _woff2tags_dummy;
+
+#endif /* !FT_CONFIG_OPTION_USE_BROTLI */
+
 
 /* END */
diff --git a/src/sfnt/woff2tags.h b/src/sfnt/woff2tags.h
index 12db9cc..4ef0a65 100644
--- a/src/sfnt/woff2tags.h
+++ b/src/sfnt/woff2tags.h
@@ -2,7 +2,7 @@
  *
  * woff2tags.h
  *
- *   WOFFF2 Font table tags (specification).
+ *   WOFF2 Font table tags (specification).
  *
  * Copyright (C) 2019-2021 by
  * Nikhil Ramakrishnan, David Turner, Robert Wilhelm, and Werner Lemberg.
@@ -26,10 +26,12 @@
 
 FT_BEGIN_HEADER
 
+#ifdef FT_CONFIG_OPTION_USE_BROTLI
 
   FT_LOCAL( FT_Tag )
   woff2_known_tags( FT_Byte  index );
 
+#endif
 
 FT_END_HEADER
 



reply via email to

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