Delete all Trailing spaces in code.
[reactos.git] / reactos / dll / 3rdparty / freetype / src / cid / cidparse.c
index bb87afc..8ab7fa7 100644 (file)
-/***************************************************************************/
-/*                                                                         */
-/*  cidparse.c                                                             */
-/*                                                                         */
-/*    CID-keyed Type1 parser (body).                                       */
-/*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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_DEBUG_H
-#include FT_INTERNAL_CALC_H
-#include FT_INTERNAL_OBJECTS_H
-#include FT_INTERNAL_STREAM_H
-
-#include "cidparse.h"
-
-#include "ciderrs.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.                                            */
-  /*                                                                       */
-#undef  FT_COMPONENT
-#define FT_COMPONENT  trace_cidparse
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    INPUT STREAM PARSER                        *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_LOCAL_DEF( FT_Error )
-  cid_parser_new( CID_Parser*    parser,
-                  FT_Stream      stream,
-                  FT_Memory      memory,
-                  PSAux_Service  psaux )
-  {
-    FT_Error  error;
-    FT_ULong  base_offset, offset, ps_len;
-    FT_Byte   *cur, *limit;
-    FT_Byte   *arg1, *arg2;
-
-
-    FT_MEM_ZERO( parser, sizeof ( *parser ) );
-    psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
-
-    parser->stream = stream;
-
-    base_offset = FT_STREAM_POS();
-
-    /* first of all, check the font format in the header */
-    if ( FT_FRAME_ENTER( 31 ) )
-      goto Exit;
-
-    if ( ft_strncmp( (char *)stream->cursor,
-                     "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )
-    {
-      FT_TRACE2(( "[not a valid CID-keyed font]\n" ));
-      error = CID_Err_Unknown_File_Format;
-    }
-
-    FT_FRAME_EXIT();
-    if ( error )
-      goto Exit;
-
-  Again:
-    /* now, read the rest of the file until we find */
-    /* `StartData' or `/sfnts'                      */
-    {
-      FT_Byte   buffer[256 + 10];
-      FT_Int    read_len = 256 + 10;
-      FT_Byte*  p        = buffer;
-
-
-      for ( offset = (FT_ULong)FT_STREAM_POS(); ; offset += 256 )
-      {
-        FT_Int  stream_len;
-
-
-        stream_len = stream->size - FT_STREAM_POS();
-        if ( stream_len == 0 )
-        {
-          FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" ));
-          error = CID_Err_Unknown_File_Format;
-          goto Exit;
-        }
-
-        read_len = FT_MIN( read_len, stream_len );
-        if ( FT_STREAM_READ( p, read_len ) )
-          goto Exit;
-
-        if ( read_len < 256 )
-          p[read_len]  = '\0';
-
-        limit = p + read_len - 10;
-
-        for ( p = buffer; p < limit; p++ )
-        {
-          if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 )
-          {
-            /* save offset of binary data after `StartData' */
-            offset += p - buffer + 10;
-            goto Found;
-          }
-          else if ( p[1] == 's' && ft_strncmp( (char*)p, "/sfnts", 6 ) == 0 )
-          {
-            offset += p - buffer + 7;
-            goto Found;
-          }
-        }
-
-        FT_MEM_MOVE( buffer, p, 10 );
-        read_len = 256;
-        p = buffer + 10;
-      }
-    }
-
-  Found:
-    /* We have found the start of the binary data or the `/sfnts' token. */
-    /* Now rewind and extract the frame corresponding to this PostScript */
-    /* section.                                                          */
-
-    ps_len = offset - base_offset;
-    if ( FT_STREAM_SEEK( base_offset )                  ||
-         FT_FRAME_EXTRACT( ps_len, parser->postscript ) )
-      goto Exit;
-
-    parser->data_offset    = offset;
-    parser->postscript_len = ps_len;
-    parser->root.base      = parser->postscript;
-    parser->root.cursor    = parser->postscript;
-    parser->root.limit     = parser->root.cursor + ps_len;
-    parser->num_dict       = -1;
-
-    /* Finally, we check whether `StartData' or `/sfnts' was real --  */
-    /* it could be in a comment or string.  We also get the arguments */
-    /* of `StartData' to find out whether the data is represented in  */
-    /* binary or hex format.                                          */
-
-    arg1 = parser->root.cursor;
-    cid_parser_skip_PS_token( parser );
-    cid_parser_skip_spaces  ( parser );
-    arg2 = parser->root.cursor;
-    cid_parser_skip_PS_token( parser );
-    cid_parser_skip_spaces  ( parser );
-
-    limit = parser->root.limit;
-    cur   = parser->root.cursor;
-
-    while ( cur < limit )
-    {
-      if ( parser->root.error )
-      {
-        error = parser->root.error;
-        goto Exit;
-      }
-
-      if ( cur[0] == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 )
-      {
-        if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
-          parser->binary_length = ft_atol( (const char *)arg2 );
-
-        limit = parser->root.limit;
-        cur   = parser->root.cursor;
-        goto Exit;
-      }
-      else if ( cur[1] == 's' && ft_strncmp( (char*)cur, "/sfnts", 6 ) == 0 )
-      {
-        FT_TRACE2(( "cid_parser_new: cannot handle Type 11 fonts\n" ));
-        error = CID_Err_Unknown_File_Format;
-        goto Exit;
-      }
-
-      cid_parser_skip_PS_token( parser );
-      cid_parser_skip_spaces  ( parser );
-      arg1 = arg2;
-      arg2 = cur;
-      cur  = parser->root.cursor;
-    }
-
-    /* we haven't found the correct `StartData'; go back and continue */
-    /* searching                                                      */
-    FT_FRAME_RELEASE( parser->postscript );
-    if ( !FT_STREAM_SEEK( offset ) )
-      goto Again;
-
-  Exit:
-    return error;
-  }
-
-
-  FT_LOCAL_DEF( void )
-  cid_parser_done( CID_Parser*  parser )
-  {
-    /* always free the private dictionary */
-    if ( parser->postscript )
-    {
-      FT_Stream  stream = parser->stream;
-
-
-      FT_FRAME_RELEASE( parser->postscript );
-    }
-    parser->root.funcs.done( &parser->root );
-  }
-
-
-/* END */
+/***************************************************************************/\r
+/*                                                                         */\r
+/*  cidparse.c                                                             */\r
+/*                                                                         */\r
+/*    CID-keyed Type1 parser (body).                                       */\r
+/*                                                                         */\r
+/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by             */\r
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */\r
+/*                                                                         */\r
+/*  This file is part of the FreeType project, and may only be used,       */\r
+/*  modified, and distributed under the terms of the FreeType project      */\r
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */\r
+/*  this file you indicate that you have read the license and              */\r
+/*  understand and accept it fully.                                        */\r
+/*                                                                         */\r
+/***************************************************************************/\r
+\r
+\r
+#include <ft2build.h>\r
+#include FT_INTERNAL_DEBUG_H\r
+#include FT_INTERNAL_CALC_H\r
+#include FT_INTERNAL_OBJECTS_H\r
+#include FT_INTERNAL_STREAM_H\r
+\r
+#include "cidparse.h"\r
+\r
+#include "ciderrs.h"\r
+\r
+\r
+  /*************************************************************************/\r
+  /*                                                                       */\r
+  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */\r
+  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */\r
+  /* messages during execution.                                            */\r
+  /*                                                                       */\r
+#undef  FT_COMPONENT\r
+#define FT_COMPONENT  trace_cidparse\r
+\r
+\r
+  /*************************************************************************/\r
+  /*************************************************************************/\r
+  /*************************************************************************/\r
+  /*****                                                               *****/\r
+  /*****                    INPUT STREAM PARSER                        *****/\r
+  /*****                                                               *****/\r
+  /*************************************************************************/\r
+  /*************************************************************************/\r
+  /*************************************************************************/\r
+\r
+\r
+  FT_LOCAL_DEF( FT_Error )\r
+  cid_parser_new( CID_Parser*    parser,\r
+                  FT_Stream      stream,\r
+                  FT_Memory      memory,\r
+                  PSAux_Service  psaux )\r
+  {\r
+    FT_Error  error;\r
+    FT_ULong  base_offset, offset, ps_len;\r
+    FT_Byte   *cur, *limit;\r
+    FT_Byte   *arg1, *arg2;\r
+\r
+\r
+    FT_MEM_ZERO( parser, sizeof ( *parser ) );\r
+    psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );\r
+\r
+    parser->stream = stream;\r
+\r
+    base_offset = FT_STREAM_POS();\r
+\r
+    /* first of all, check the font format in the header */\r
+    if ( FT_FRAME_ENTER( 31 ) )\r
+      goto Exit;\r
+\r
+    if ( ft_strncmp( (char *)stream->cursor,\r
+                     "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )\r
+    {\r
+      FT_TRACE2(( "[not a valid CID-keyed font]\n" ));\r
+      error = CID_Err_Unknown_File_Format;\r
+    }\r
+\r
+    FT_FRAME_EXIT();\r
+    if ( error )\r
+      goto Exit;\r
+\r
+  Again:\r
+    /* now, read the rest of the file until we find */\r
+    /* `StartData' or `/sfnts'                      */\r
+    {\r
+      FT_Byte   buffer[256 + 10];\r
+      FT_Int    read_len = 256 + 10;\r
+      FT_Byte*  p        = buffer;\r
+\r
+\r
+      for ( offset = (FT_ULong)FT_STREAM_POS(); ; offset += 256 )\r
+      {\r
+        FT_Int  stream_len;\r
+\r
+\r
+        stream_len = stream->size - FT_STREAM_POS();\r
+        if ( stream_len == 0 )\r
+        {\r
+          FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" ));\r
+          error = CID_Err_Unknown_File_Format;\r
+          goto Exit;\r
+        }\r
+\r
+        read_len = FT_MIN( read_len, stream_len );\r
+        if ( FT_STREAM_READ( p, read_len ) )\r
+          goto Exit;\r
+\r
+        if ( read_len < 256 )\r
+          p[read_len]  = '\0';\r
+\r
+        limit = p + read_len - 10;\r
+\r
+        for ( p = buffer; p < limit; p++ )\r
+        {\r
+          if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 )\r
+          {\r
+            /* save offset of binary data after `StartData' */\r
+            offset += p - buffer + 10;\r
+            goto Found;\r
+          }\r
+          else if ( p[1] == 's' && ft_strncmp( (char*)p, "/sfnts", 6 ) == 0 )\r
+          {\r
+            offset += p - buffer + 7;\r
+            goto Found;\r
+          }\r
+        }\r
+\r
+        FT_MEM_MOVE( buffer, p, 10 );\r
+        read_len = 256;\r
+        p = buffer + 10;\r
+      }\r
+    }\r
+\r
+  Found:\r
+    /* We have found the start of the binary data or the `/sfnts' token. */\r
+    /* Now rewind and extract the frame corresponding to this PostScript */\r
+    /* section.                                                          */\r
+\r
+    ps_len = offset - base_offset;\r
+    if ( FT_STREAM_SEEK( base_offset )                  ||\r
+         FT_FRAME_EXTRACT( ps_len, parser->postscript ) )\r
+      goto Exit;\r
+\r
+    parser->data_offset    = offset;\r
+    parser->postscript_len = ps_len;\r
+    parser->root.base      = parser->postscript;\r
+    parser->root.cursor    = parser->postscript;\r
+    parser->root.limit     = parser->root.cursor + ps_len;\r
+    parser->num_dict       = -1;\r
+\r
+    /* Finally, we check whether `StartData' or `/sfnts' was real --  */\r
+    /* it could be in a comment or string.  We also get the arguments */\r
+    /* of `StartData' to find out whether the data is represented in  */\r
+    /* binary or hex format.                                          */\r
+\r
+    arg1 = parser->root.cursor;\r
+    cid_parser_skip_PS_token( parser );\r
+    cid_parser_skip_spaces  ( parser );\r
+    arg2 = parser->root.cursor;\r
+    cid_parser_skip_PS_token( parser );\r
+    cid_parser_skip_spaces  ( parser );\r
+\r
+    limit = parser->root.limit;\r
+    cur   = parser->root.cursor;\r
+\r
+    while ( cur < limit )\r
+    {\r
+      if ( parser->root.error )\r
+      {\r
+        error = parser->root.error;\r
+        goto Exit;\r
+      }\r
+\r
+      if ( cur[0] == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 )\r
+      {\r
+        if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )\r
+          parser->binary_length = ft_atol( (const char *)arg2 );\r
+\r
+        limit = parser->root.limit;\r
+        cur   = parser->root.cursor;\r
+        goto Exit;\r
+      }\r
+      else if ( cur[1] == 's' && ft_strncmp( (char*)cur, "/sfnts", 6 ) == 0 )\r
+      {\r
+        FT_TRACE2(( "cid_parser_new: cannot handle Type 11 fonts\n" ));\r
+        error = CID_Err_Unknown_File_Format;\r
+        goto Exit;\r
+      }\r
+\r
+      cid_parser_skip_PS_token( parser );\r
+      cid_parser_skip_spaces  ( parser );\r
+      arg1 = arg2;\r
+      arg2 = cur;\r
+      cur  = parser->root.cursor;\r
+    }\r
+\r
+    /* we haven't found the correct `StartData'; go back and continue */\r
+    /* searching                                                      */\r
+    FT_FRAME_RELEASE( parser->postscript );\r
+    if ( !FT_STREAM_SEEK( offset ) )\r
+      goto Again;\r
+\r
+  Exit:\r
+    return error;\r
+  }\r
+\r
+\r
+  FT_LOCAL_DEF( void )\r
+  cid_parser_done( CID_Parser*  parser )\r
+  {\r
+    /* always free the private dictionary */\r
+    if ( parser->postscript )\r
+    {\r
+      FT_Stream  stream = parser->stream;\r
+\r
+\r
+      FT_FRAME_RELEASE( parser->postscript );\r
+    }\r
+    parser->root.funcs.done( &parser->root );\r
+  }\r
+\r
+\r
+/* END */\r