< prev index next >

src/java.desktop/share/native/libfreetype/src/psaux/psobjs.c

Print this page

        

@@ -1,21 +1,21 @@
-/***************************************************************************/
-/*                                                                         */
-/*  psobjs.c                                                               */
-/*                                                                         */
-/*    Auxiliary functions for PostScript fonts (body).                     */
-/*                                                                         */
-/*  Copyright 1996-2018 by                                                 */
-/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
-/*                                                                         */
-/*  This file is part of the FreeType project, and may only be used,       */
-/*  modified, and distributed under the terms of the FreeType project      */
-/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
-/*  this file you indicate that you have read the license and              */
-/*  understand and accept it fully.                                        */
-/*                                                                         */
-/***************************************************************************/
+/****************************************************************************
+ *
+ * psobjs.c
+ *
+ *   Auxiliary functions for PostScript fonts (body).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT.  By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
 
 
 #include <ft2build.h>
 #include FT_INTERNAL_POSTSCRIPT_AUX_H
 #include FT_INTERNAL_DEBUG_H

@@ -27,48 +27,51 @@
 
 #include "psauxerr.h"
 #include "psauxmod.h"
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
-  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
-  /* messages during execution.                                            */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * The macro FT_COMPONENT is used in trace mode.  It is an implicit
+   * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
+   * messages during execution.
+   */
 #undef  FT_COMPONENT
-#define FT_COMPONENT  trace_psobjs
+#define FT_COMPONENT  psobjs
 
 
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
   /*****                             PS_TABLE                          *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_table_new                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Initializes a PS_Table.                                            */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    table  :: The address of the target table.                         */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    count  :: The table size = the maximum number of elements.         */
-  /*                                                                       */
-  /*    memory :: The memory object to use for all subsequent              */
-  /*              reallocations.                                           */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_table_new
+   *
+   * @Description:
+   *   Initializes a PS_Table.
+   *
+   * @InOut:
+   *   table ::
+   *     The address of the target table.
+   *
+   * @Input:
+   *   count ::
+   *     The table size = the maximum number of elements.
+   *
+   *   memory ::
+   *     The memory object to use for all subsequent
+   *     reallocations.
+   *
+   * @Return:
+   *   FreeType error code.  0 means success.
+   */
   FT_LOCAL_DEF( FT_Error )
   ps_table_new( PS_Table   table,
                 FT_Int     count,
                 FT_Memory  memory )
   {

@@ -142,32 +145,36 @@
 
     return FT_Err_Ok;
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_table_add                                                       */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Adds an object to a PS_Table, possibly growing its memory block.   */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    table  :: The target table.                                        */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    idx    :: The index of the object in the table.                    */
-  /*                                                                       */
-  /*    object :: The address of the object to copy in memory.             */
-  /*                                                                       */
-  /*    length :: The length in bytes of the source object.                */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.  An error is returned if a  */
-  /*    reallocation fails.                                                */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_table_add
+   *
+   * @Description:
+   *   Adds an object to a PS_Table, possibly growing its memory block.
+   *
+   * @InOut:
+   *   table ::
+   *     The target table.
+   *
+   * @Input:
+   *   idx ::
+   *     The index of the object in the table.
+   *
+   *   object ::
+   *     The address of the object to copy in memory.
+   *
+   *   length ::
+   *     The length in bytes of the source object.
+   *
+   * @Return:
+   *   FreeType error code.  0 means success.  An error is returned if a
+   *   reallocation fails.
+   */
   FT_LOCAL_DEF( FT_Error )
   ps_table_add( PS_Table  table,
                 FT_Int    idx,
                 void*     object,
                 FT_UInt   length )

@@ -214,26 +221,27 @@
     table->cursor += length;
     return FT_Err_Ok;
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_table_done                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Finalizes a PS_TableRec (i.e., reallocate it to its current        */
-  /*    cursor).                                                           */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    table :: The target table.                                         */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    This function does NOT release the heap's memory block.  It is up  */
-  /*    to the caller to clean it, or reference it in its own structures.  */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_table_done
+   *
+   * @Description:
+   *   Finalizes a PS_TableRec (i.e., reallocate it to its current
+   *   cursor).
+   *
+   * @InOut:
+   *   table ::
+   *     The target table.
+   *
+   * @Note:
+   *   This function does NOT release the heap's memory block.  It is up
+   *   to the caller to clean it, or reference it in its own structures.
+   */
   FT_LOCAL_DEF( void )
   ps_table_done( PS_Table  table )
   {
     FT_Memory  memory = table->memory;
     FT_Error   error;

@@ -496,16 +504,16 @@
 
     return error;
   }
 
 
-  /***********************************************************************/
-  /*                                                                     */
-  /* All exported parsing routines handle leading whitespace and stop at */
-  /* the first character which isn't part of the just handled token.     */
-  /*                                                                     */
-  /***********************************************************************/
+  /************************************************************************
+   *
+   * All exported parsing routines handle leading whitespace and stop at
+   * the first character which isn't part of the just handled token.
+   *
+   */
 
 
   FT_LOCAL_DEF( void )
   ps_parser_skip_PS_token( PS_Parser  parser )
   {

@@ -1098,22 +1106,26 @@
 
       switch ( type )
       {
       case T1_FIELD_TYPE_BOOL:
         val = ps_tobool( &cur, limit );
+        FT_TRACE4(( " %s", val ? "true" : "false" ));
         goto Store_Integer;
 
       case T1_FIELD_TYPE_FIXED:
         val = PS_Conv_ToFixed( &cur, limit, 0 );
+        FT_TRACE4(( " %f", (double)val / 65536 ));
         goto Store_Integer;
 
       case T1_FIELD_TYPE_FIXED_1000:
         val = PS_Conv_ToFixed( &cur, limit, 3 );
+        FT_TRACE4(( " %f", (double)val / 65536 / 1000 ));
         goto Store_Integer;
 
       case T1_FIELD_TYPE_INTEGER:
         val = PS_Conv_ToInt( &cur, limit );
+        FT_TRACE4(( " %ld", val ));
         /* fall through */
 
       Store_Integer:
         switch ( field->size )
         {

@@ -1186,10 +1198,17 @@
             goto Exit;
 
           FT_MEM_COPY( string, cur, len );
           string[len] = 0;
 
+#ifdef FT_DEBUG_LEVEL_TRACE
+          if ( token.type == T1_TOKEN_TYPE_STRING )
+            FT_TRACE4(( " (%s)", string ));
+          else
+            FT_TRACE4(( " /%s", string ));
+#endif
+
           *(FT_String**)q = string;
         }
         break;
 
       case T1_FIELD_TYPE_BBOX:

@@ -1211,10 +1230,16 @@
 
           bbox->xMin = FT_RoundFix( temp[0] );
           bbox->yMin = FT_RoundFix( temp[1] );
           bbox->xMax = FT_RoundFix( temp[2] );
           bbox->yMax = FT_RoundFix( temp[3] );
+
+          FT_TRACE4(( " [%d %d %d %d]",
+                      bbox->xMin / 65536,
+                      bbox->yMin / 65536,
+                      bbox->xMax / 65536,
+                      bbox->yMax / 65536 ));
         }
         break;
 
       case T1_FIELD_TYPE_MM_BBOX:
         {

@@ -1249,20 +1274,28 @@
             }
 
             skip_spaces( &cur, limit );
           }
 
+          FT_TRACE4(( " [" ));
           for ( i = 0; i < max_objects; i++ )
           {
             FT_BBox*  bbox = (FT_BBox*)objects[i];
 
 
             bbox->xMin = FT_RoundFix( temp[i                  ] );
             bbox->yMin = FT_RoundFix( temp[i +     max_objects] );
             bbox->xMax = FT_RoundFix( temp[i + 2 * max_objects] );
             bbox->yMax = FT_RoundFix( temp[i + 3 * max_objects] );
+
+            FT_TRACE4(( " [%d %d %d %d]",
+                        bbox->xMin / 65536,
+                        bbox->yMin / 65536,
+                        bbox->xMax / 65536,
+                        bbox->yMax / 65536 ));
           }
+          FT_TRACE4(( "]" ));
 
           FT_FREE( temp );
         }
         break;
 

@@ -1331,10 +1364,12 @@
     /* we further assume that `count_offset' can't be zero */
     if ( field->type != T1_FIELD_TYPE_BBOX && field->count_offset != 0 )
       *(FT_Byte*)( (FT_Byte*)objects[0] + field->count_offset ) =
         (FT_Byte)num_elements;
 
+    FT_TRACE4(( " [" ));
+
     /* we now load each element, adjusting the field.offset on each one */
     token = elements;
     for ( ; num_elements > 0; num_elements--, token++ )
     {
       parser->cursor = token->start;

@@ -1349,10 +1384,12 @@
         break;
 
       fieldrec.offset += fieldrec.size;
     }
 
+    FT_TRACE4(( "]" ));
+
 #if 0  /* obsolete -- keep for reference */
     if ( pflags )
       *pflags |= 1L << field->flag_bit;
 #else
     FT_UNUSED( pflags );

@@ -1408,24 +1445,24 @@
     *pnum_bytes = PS_Conv_ASCIIHexDecode( &cur,
                                           parser->limit,
                                           bytes,
                                           max_bytes );
 
+    parser->cursor = cur;
+
     if ( delimiters )
     {
       if ( cur < parser->limit && *cur != '>' )
       {
         FT_ERROR(( "ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
         error = FT_THROW( Invalid_File_Format );
         goto Exit;
       }
 
-      cur++;
+      parser->cursor++;
     }
 
-    parser->cursor = cur;
-
   Exit:
     return error;
   }
 
 

@@ -1507,30 +1544,35 @@
   /*****                            T1 BUILDER                         *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    t1_builder_init                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Initializes a given glyph builder.                                 */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    builder :: A pointer to the glyph builder to initialize.           */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face    :: The current face object.                                */
-  /*                                                                       */
-  /*    size    :: The current size object.                                */
-  /*                                                                       */
-  /*    glyph   :: The current glyph object.                               */
-  /*                                                                       */
-  /*    hinting :: Whether hinting should be applied.                      */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   t1_builder_init
+   *
+   * @Description:
+   *   Initializes a given glyph builder.
+   *
+   * @InOut:
+   *   builder ::
+   *     A pointer to the glyph builder to initialize.
+   *
+   * @Input:
+   *   face ::
+   *     The current face object.
+   *
+   *   size ::
+   *     The current size object.
+   *
+   *   glyph ::
+   *     The current glyph object.
+   *
+   *   hinting ::
+   *     Whether hinting should be applied.
+   */
   FT_LOCAL_DEF( void )
   t1_builder_init( T1_Builder    builder,
                    FT_Face       face,
                    FT_Size       size,
                    FT_GlyphSlot  glyph,

@@ -1570,23 +1612,24 @@
 
     builder->funcs = t1_builder_funcs;
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    t1_builder_done                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Finalizes a given glyph builder.  Its contents can still be used   */
-  /*    after the call, but the function saves important information       */
-  /*    within the corresponding glyph slot.                               */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    builder :: A pointer to the glyph builder to finalize.             */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   t1_builder_done
+   *
+   * @Description:
+   *   Finalizes a given glyph builder.  Its contents can still be used
+   *   after the call, but the function saves important information
+   *   within the corresponding glyph slot.
+   *
+   * @Input:
+   *   builder ::
+   *     A pointer to the glyph builder to finalize.
+   */
   FT_LOCAL_DEF( void )
   t1_builder_done( T1_Builder  builder )
   {
     FT_GlyphSlot  glyph = builder->glyph;
 

@@ -1767,30 +1810,35 @@
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    cff_builder_init                                                   */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Initializes a given glyph builder.                                 */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    builder :: A pointer to the glyph builder to initialize.           */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face    :: The current face object.                                */
-  /*                                                                       */
-  /*    size    :: The current size object.                                */
-  /*                                                                       */
-  /*    glyph   :: The current glyph object.                               */
-  /*                                                                       */
-  /*    hinting :: Whether hinting is active.                              */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   cff_builder_init
+   *
+   * @Description:
+   *   Initializes a given glyph builder.
+   *
+   * @InOut:
+   *   builder ::
+   *     A pointer to the glyph builder to initialize.
+   *
+   * @Input:
+   *   face ::
+   *     The current face object.
+   *
+   *   size ::
+   *     The current size object.
+   *
+   *   glyph ::
+   *     The current glyph object.
+   *
+   *   hinting ::
+   *     Whether hinting is active.
+   */
   FT_LOCAL_DEF( void )
   cff_builder_init( CFF_Builder*   builder,
                     TT_Face        face,
                     CFF_Size       size,
                     CFF_GlyphSlot  glyph,

@@ -1839,23 +1887,24 @@
 
     builder->funcs = cff_builder_funcs;
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    cff_builder_done                                                   */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Finalizes a given glyph builder.  Its contents can still be used   */
-  /*    after the call, but the function saves important information       */
-  /*    within the corresponding glyph slot.                               */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    builder :: A pointer to the glyph builder to finalize.             */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   cff_builder_done
+   *
+   * @Description:
+   *   Finalizes a given glyph builder.  Its contents can still be used
+   *   after the call, but the function saves important information
+   *   within the corresponding glyph slot.
+   *
+   * @Input:
+   *   builder ::
+   *     A pointer to the glyph builder to finalize.
+   */
   FT_LOCAL_DEF( void )
   cff_builder_done( CFF_Builder*  builder )
   {
     CFF_GlyphSlot  glyph = builder->glyph;
 

@@ -1991,10 +2040,18 @@
       return;
 
     first = outline->n_contours <= 1
             ? 0 : outline->contours[outline->n_contours - 2] + 1;
 
+    /* in malformed fonts it can happen that a contour was started */
+    /* but no points were added                                    */
+    if ( outline->n_contours && first == outline->n_points )
+    {
+      outline->n_contours--;
+      return;
+    }
+
     /* We must not include the last point in the path if it */
     /* is located on the first point.                       */
     if ( outline->n_points > 1 )
     {
       FT_Vector*  p1      = outline->points + first;

@@ -2031,30 +2088,35 @@
   /*****                            PS BUILDER                         *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_builder_init                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Initializes a given glyph builder.                                 */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    builder :: A pointer to the glyph builder to initialize.           */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face    :: The current face object.                                */
-  /*                                                                       */
-  /*    size    :: The current size object.                                */
-  /*                                                                       */
-  /*    glyph   :: The current glyph object.                               */
-  /*                                                                       */
-  /*    hinting :: Whether hinting should be applied.                      */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_builder_init
+   *
+   * @Description:
+   *   Initializes a given glyph builder.
+   *
+   * @InOut:
+   *   builder ::
+   *     A pointer to the glyph builder to initialize.
+   *
+   * @Input:
+   *   face ::
+   *     The current face object.
+   *
+   *   size ::
+   *     The current size object.
+   *
+   *   glyph ::
+   *     The current glyph object.
+   *
+   *   hinting ::
+   *     Whether hinting should be applied.
+   */
   FT_LOCAL_DEF( void )
   ps_builder_init( PS_Builder*  ps_builder,
                    void*        builder,
                    FT_Bool      is_t1 )
   {

@@ -2114,23 +2176,24 @@
     ps_builder->is_t1 = is_t1;
     ps_builder->funcs = ps_builder_funcs;
   }
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_builder_done                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Finalizes a given glyph builder.  Its contents can still be used   */
-  /*    after the call, but the function saves important information       */
-  /*    within the corresponding glyph slot.                               */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    builder :: A pointer to the glyph builder to finalize.             */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_builder_done
+   *
+   * @Description:
+   *   Finalizes a given glyph builder.  Its contents can still be used
+   *   after the call, but the function saves important information
+   *   within the corresponding glyph slot.
+   *
+   * @Input:
+   *   builder ::
+   *     A pointer to the glyph builder to finalize.
+   */
   FT_LOCAL_DEF( void )
   ps_builder_done( PS_Builder*  builder )
   {
     CFF_GlyphSlot  glyph = builder->glyph;
 

@@ -2334,27 +2397,30 @@
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    ps_decoder_init                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Creates a wrapper decoder for use in the combined                  */
-  /*    Type 1 / CFF interpreter.                                          */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    ps_decoder :: A pointer to the decoder to initialize.              */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    decoder    :: A pointer to the original decoder.                   */
-  /*                                                                       */
-  /*    is_t1      :: Flag indicating Type 1 or CFF                        */
-  /*                                                                       */
+  /**************************************************************************
+   *
+   * @Function:
+   *   ps_decoder_init
+   *
+   * @Description:
+   *   Creates a wrapper decoder for use in the combined
+   *   Type 1 / CFF interpreter.
+   *
+   * @InOut:
+   *   ps_decoder ::
+   *     A pointer to the decoder to initialize.
+   *
+   * @Input:
+   *   decoder ::
+   *     A pointer to the original decoder.
+   *
+   *   is_t1 ::
+   *     Flag indicating Type 1 or CFF
+   */
   FT_LOCAL_DEF( void )
   ps_decoder_init( PS_Decoder*  ps_decoder,
                    void*        decoder,
                    FT_Bool      is_t1 )
   {
< prev index next >