< prev index next >

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

Print this page


   1 /****************************************************************************
   2  *
   3  * t1decode.c
   4  *
   5  *   PostScript Type 1 decoding routines (body).
   6  *
   7  * Copyright (C) 2000-2019 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   9  *
  10  * This file is part of the FreeType project, and may only be used,
  11  * modified, and distributed under the terms of the FreeType project
  12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13  * this file you indicate that you have read the license and
  14  * understand and accept it fully.
  15  *
  16  */
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_CALC_H
  21 #include FT_INTERNAL_DEBUG_H
  22 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
  23 #include FT_INTERNAL_HASH_H
  24 #include FT_OUTLINE_H
  25 
  26 #include "t1decode.h"
  27 #include "psobjs.h"


 350       /* subglyph 1 = accent character */
 351       subg->index = achar_index;
 352       subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
 353       subg->arg1  = (FT_Int)FIXED_TO_INT( adx - asb );
 354       subg->arg2  = (FT_Int)FIXED_TO_INT( ady );
 355 
 356       /* set up remaining glyph fields */
 357       glyph->num_subglyphs = 2;
 358       glyph->subglyphs     = loader->base.subglyphs;
 359       glyph->format        = FT_GLYPH_FORMAT_COMPOSITE;
 360 
 361       loader->current.num_subglyphs = 2;
 362       goto Exit;
 363     }
 364 
 365     /* First load `bchar' in builder */
 366     /* now load the unscaled outline */
 367 
 368     FT_GlyphLoader_Prepare( decoder->builder.loader );  /* prepare loader */
 369 






 370     /* the seac operator must not be nested */
 371     decoder->seac = TRUE;
 372     error = t1_decoder_parse_glyph( decoder, (FT_UInt)bchar_index );
 373     decoder->seac = FALSE;
 374     if ( error )
 375       goto Exit;
 376 
 377     /* save the left bearing and width of the base character */
 378     /* as they will be erased by the next load.              */
 379 


 380     left_bearing = decoder->builder.left_bearing;
 381     advance      = decoder->builder.advance;

 382 
 383     decoder->builder.left_bearing.x = 0;
 384     decoder->builder.left_bearing.y = 0;
 385 
 386     decoder->builder.pos_x = adx - asb;
 387     decoder->builder.pos_y = ady;
 388 
 389     /* Now load `achar' on top of */
 390     /* the base outline           */
 391 
 392     /* the seac operator must not be nested */
 393     decoder->seac = TRUE;
 394     error = t1_decoder_parse_glyph( decoder, (FT_UInt)achar_index );
 395     decoder->seac = FALSE;
 396     if ( error )
 397       goto Exit;
 398 
 399     /* restore the left side bearing and   */
 400     /* advance width of the base character */
 401 
 402     decoder->builder.left_bearing = left_bearing;
 403     decoder->builder.advance      = advance;
 404 
 405     decoder->builder.pos_x = 0;
 406     decoder->builder.pos_y = 0;
 407 
 408   Exit:
 409     return error;
 410   }
 411 
 412 
 413   /**************************************************************************
 414    *
 415    * @Function:
 416    *   t1_decoder_parse_charstrings
 417    *
 418    * @Description:
 419    *   Parses a given Type 1 charstrings program.
 420    *


 633                      " unexpected EOF in integer\n" ));
 634           goto Syntax_Error;
 635         }
 636 
 637         value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
 638                             ( (FT_UInt32)ip[1] << 16 ) |
 639                             ( (FT_UInt32)ip[2] << 8  ) |
 640                               (FT_UInt32)ip[3]         );
 641         ip += 4;
 642 
 643         /* According to the specification, values > 32000 or < -32000 must */
 644         /* be followed by a `div' operator to make the result be in the    */
 645         /* range [-32000;32000].  We expect that the second argument of    */
 646         /* `div' is not a large number.  Additionally, we don't handle     */
 647         /* stuff like `<large1> <large2> <num> div <num> div' or           */
 648         /* <large1> <large2> <num> div div'.  This is probably not allowed */
 649         /* anyway.                                                         */
 650         if ( value > 32000 || value < -32000 )
 651         {
 652           if ( large_int )
 653           {
 654             FT_ERROR(( "t1_decoder_parse_charstrings:"
 655                        " no `div' after large integer\n" ));
 656           }
 657           else
 658             large_int = TRUE;
 659         }
 660         else
 661         {
 662           if ( !large_int )
 663             value = (FT_Int32)( (FT_UInt32)value << 16 );
 664         }
 665 
 666         break;
 667 
 668       default:
 669         if ( ip[-1] >= 32 )
 670         {
 671           if ( ip[-1] < 247 )
 672             value = (FT_Int32)ip[-1] - 139;
 673           else
 674           {
 675             if ( ++ip > limit )
 676             {


1673    *     The current Type 1 decoder.
1674    *
1675    *   charstring_base ::
1676    *     The base address of the charstring stream.
1677    *
1678    *   charstring_len ::
1679    *     The length in bytes of the charstring stream.
1680    *
1681    * @Return:
1682    *   FreeType error code.  0 means success.
1683    */
1684   FT_LOCAL_DEF( FT_Error )
1685   t1_decoder_parse_metrics( T1_Decoder  decoder,
1686                             FT_Byte*    charstring_base,
1687                             FT_UInt     charstring_len )
1688   {
1689     T1_Decoder_Zone  zone;
1690     FT_Byte*         ip;
1691     FT_Byte*         limit;
1692     T1_Builder       builder = &decoder->builder;

1693 
1694 #ifdef FT_DEBUG_LEVEL_TRACE
1695     FT_Bool          bol = TRUE;
1696 #endif
1697 
1698 
1699     /* First of all, initialize the decoder */
1700     decoder->top  = decoder->stack;
1701     decoder->zone = decoder->zones;
1702     zone          = decoder->zones;
1703 
1704     builder->parse_state = T1_Parse_Start;
1705 
1706     zone->base           = charstring_base;
1707     limit = zone->limit  = charstring_base + charstring_len;
1708     ip    = zone->cursor = zone->base;
1709 


1710     /* now, execute loop */
1711     while ( ip < limit )
1712     {
1713       FT_Long*     top   = decoder->top;
1714       T1_Operator  op    = op_none;
1715       FT_Int32     value = 0;
1716 
1717 
1718 #ifdef FT_DEBUG_LEVEL_TRACE
1719       if ( bol )
1720       {
1721         FT_TRACE5(( " (%d)", decoder->top - decoder->stack ));
1722         bol = FALSE;
1723       }
1724 #endif
1725 
1726       /**********************************************************************
1727        *
1728        * Decode operator or operand
1729        *


1750       case 31:
1751         goto No_Width;
1752 
1753       case 13:
1754         op = op_hsbw;
1755         break;
1756 
1757       case 12:
1758         if ( ip >= limit )
1759         {
1760           FT_ERROR(( "t1_decoder_parse_metrics:"
1761                      " invalid escape (12+EOF)\n" ));
1762           goto Syntax_Error;
1763         }
1764 
1765         switch ( *ip++ )
1766         {
1767         case 7:
1768           op = op_sbw;
1769           break;



1770 
1771         default:
1772           goto No_Width;
1773         }
1774         break;
1775 
1776       case 255:    /* four bytes integer */
1777         if ( ip + 4 > limit )
1778         {
1779           FT_ERROR(( "t1_decoder_parse_metrics:"
1780                      " unexpected EOF in integer\n" ));
1781           goto Syntax_Error;
1782         }
1783 
1784         value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
1785                             ( (FT_UInt32)ip[1] << 16 ) |
1786                             ( (FT_UInt32)ip[2] << 8  ) |
1787                               (FT_UInt32)ip[3]         );
1788         ip += 4;
1789 
1790         /* According to the specification, values > 32000 or < -32000 must */
1791         /* be followed by a `div' operator to make the result be in the    */
1792         /* range [-32000;32000].  We expect that the second argument of    */
1793         /* `div' is not a large number.  Additionally, we don't handle     */
1794         /* stuff like `<large1> <large2> <num> div <num> div' or           */
1795         /* <large1> <large2> <num> div div'.  This is probably not allowed */
1796         /* anyway.                                                         */
1797         if ( value > 32000 || value < -32000 )
1798         {


1799           FT_ERROR(( "t1_decoder_parse_metrics:"
1800                      " large integer found for width\n" ));
1801           goto Syntax_Error;
1802         }
1803         else



1804         {

1805           value = (FT_Int32)( (FT_UInt32)value << 16 );
1806         }
1807 
1808         break;
1809 
1810       default:
1811         if ( ip[-1] >= 32 )
1812         {
1813           if ( ip[-1] < 247 )
1814             value = (FT_Int32)ip[-1] - 139;
1815           else
1816           {
1817             if ( ++ip > limit )
1818             {
1819               FT_ERROR(( "t1_decoder_parse_metrics:"
1820                          " unexpected EOF in integer\n" ));
1821               goto Syntax_Error;
1822             }
1823 
1824             if ( ip[-2] < 251 )
1825               value =    ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108;
1826             else
1827               value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 );
1828           }
1829 

1830           value = (FT_Int32)( (FT_UInt32)value << 16 );
1831         }
1832         else
1833         {
1834           FT_ERROR(( "t1_decoder_parse_metrics:"
1835                      " invalid byte (%d)\n", ip[-1] ));
1836           goto Syntax_Error;
1837         }
1838       }
1839 







1840       /**********************************************************************
1841        *
1842        * Push value on stack, or process operator
1843        *
1844        */
1845       if ( op == op_none )
1846       {
1847         if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
1848         {
1849           FT_ERROR(( "t1_decoder_parse_metrics: stack overflow\n" ));
1850           goto Syntax_Error;
1851         }
1852 
1853 #ifdef FT_DEBUG_LEVEL_TRACE



1854           FT_TRACE4(( " %d", value / 65536 ));
1855 #endif
1856 
1857         *top++       = value;
1858         decoder->top = top;
1859       }
1860       else  /* general operator */
1861       {
1862         FT_Int  num_args = t1_args_count[op];
1863 
1864 
1865         FT_ASSERT( num_args >= 0 );
1866 
1867         if ( top - decoder->stack < num_args )
1868           goto Stack_Underflow;
1869 
1870 #ifdef FT_DEBUG_LEVEL_TRACE
1871 


1872         if ( top - decoder->stack != num_args )
1873           FT_TRACE0(( "t1_decoder_parse_metrics:"
1874                       " too much operands on the stack"
1875                       " (seen %d, expected %d)\n",
1876                       top - decoder->stack, num_args ));

1877 
1878 #endif /* FT_DEBUG_LEVEL_TRACE */
1879 
1880         top -= num_args;
1881 
1882         switch ( op )
1883         {
1884         case op_hsbw:
1885           FT_TRACE4(( " hsbw" ));
1886 
1887           builder->parse_state = T1_Parse_Have_Width;
1888 
1889           builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1890                                               top[0] );
1891 
1892           builder->advance.x = top[1];
1893           builder->advance.y = 0;
1894 
1895           /* we only want to compute the glyph's metrics */
1896           /* (lsb + advance width), not load the rest of */


1900 
1901         case op_sbw:
1902           FT_TRACE4(( " sbw" ));
1903 
1904           builder->parse_state = T1_Parse_Have_Width;
1905 
1906           builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1907                                               top[0] );
1908           builder->left_bearing.y = ADD_LONG( builder->left_bearing.y,
1909                                               top[1] );
1910 
1911           builder->advance.x = top[2];
1912           builder->advance.y = top[3];
1913 
1914           /* we only want to compute the glyph's metrics */
1915           /* (lsb + advance width), not load the rest of */
1916           /* it; so exit immediately                     */
1917           FT_TRACE4(( "\n" ));
1918           return FT_Err_Ok;
1919 












1920         default:
1921           FT_ERROR(( "t1_decoder_parse_metrics:"
1922                      " unhandled opcode %d\n", op ));
1923           goto Syntax_Error;
1924         }


1925 
1926       } /* general operator processing */
1927 
1928     } /* while ip < limit */
1929 
1930     FT_TRACE4(( "..end..\n\n" ));
1931 
1932   No_Width:
1933     FT_ERROR(( "t1_decoder_parse_metrics:"
1934                " no width, found op %d instead\n",
1935                ip[-1] ));
1936   Syntax_Error:
1937     return FT_THROW( Syntax_Error );
1938 
1939   Stack_Underflow:
1940     return FT_THROW( Stack_Underflow );
1941   }
1942 
1943 #endif /* !T1_CONFIG_OPTION_OLD_ENGINE */
1944 


   1 /****************************************************************************
   2  *
   3  * t1decode.c
   4  *
   5  *   PostScript Type 1 decoding routines (body).
   6  *
   7  * Copyright (C) 2000-2020 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   9  *
  10  * This file is part of the FreeType project, and may only be used,
  11  * modified, and distributed under the terms of the FreeType project
  12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13  * this file you indicate that you have read the license and
  14  * understand and accept it fully.
  15  *
  16  */
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_CALC_H
  21 #include FT_INTERNAL_DEBUG_H
  22 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
  23 #include FT_INTERNAL_HASH_H
  24 #include FT_OUTLINE_H
  25 
  26 #include "t1decode.h"
  27 #include "psobjs.h"


 350       /* subglyph 1 = accent character */
 351       subg->index = achar_index;
 352       subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
 353       subg->arg1  = (FT_Int)FIXED_TO_INT( adx - asb );
 354       subg->arg2  = (FT_Int)FIXED_TO_INT( ady );
 355 
 356       /* set up remaining glyph fields */
 357       glyph->num_subglyphs = 2;
 358       glyph->subglyphs     = loader->base.subglyphs;
 359       glyph->format        = FT_GLYPH_FORMAT_COMPOSITE;
 360 
 361       loader->current.num_subglyphs = 2;
 362       goto Exit;
 363     }
 364 
 365     /* First load `bchar' in builder */
 366     /* now load the unscaled outline */
 367 
 368     FT_GlyphLoader_Prepare( decoder->builder.loader );  /* prepare loader */
 369 
 370     /* save the left bearing and width of the SEAC   */
 371     /* glyph as they will be erased by the next load */
 372 
 373     left_bearing = decoder->builder.left_bearing;
 374     advance      = decoder->builder.advance;
 375 
 376     /* the seac operator must not be nested */
 377     decoder->seac = TRUE;
 378     error = t1_decoder_parse_glyph( decoder, (FT_UInt)bchar_index );
 379     decoder->seac = FALSE;
 380     if ( error )
 381       goto Exit;
 382 
 383     /* If the SEAC glyph doesn't have a (H)SBW of its */
 384     /* own use the values from the base glyph.        */
 385 
 386     if ( decoder->builder.parse_state != T1_Parse_Have_Width )
 387     {
 388       left_bearing = decoder->builder.left_bearing;
 389       advance      = decoder->builder.advance;
 390     }
 391 
 392     decoder->builder.left_bearing.x = 0;
 393     decoder->builder.left_bearing.y = 0;
 394 
 395     decoder->builder.pos_x = adx - asb;
 396     decoder->builder.pos_y = ady;
 397 
 398     /* Now load `achar' on top of */
 399     /* the base outline           */
 400 
 401     /* the seac operator must not be nested */
 402     decoder->seac = TRUE;
 403     error = t1_decoder_parse_glyph( decoder, (FT_UInt)achar_index );
 404     decoder->seac = FALSE;
 405     if ( error )
 406       goto Exit;
 407 
 408     /* restore the left side bearing and advance width   */
 409     /* of the SEAC glyph or base character (saved above) */
 410 
 411     decoder->builder.left_bearing = left_bearing;
 412     decoder->builder.advance      = advance;
 413 
 414     decoder->builder.pos_x = 0;
 415     decoder->builder.pos_y = 0;
 416 
 417   Exit:
 418     return error;
 419   }
 420 
 421 
 422   /**************************************************************************
 423    *
 424    * @Function:
 425    *   t1_decoder_parse_charstrings
 426    *
 427    * @Description:
 428    *   Parses a given Type 1 charstrings program.
 429    *


 642                      " unexpected EOF in integer\n" ));
 643           goto Syntax_Error;
 644         }
 645 
 646         value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
 647                             ( (FT_UInt32)ip[1] << 16 ) |
 648                             ( (FT_UInt32)ip[2] << 8  ) |
 649                               (FT_UInt32)ip[3]         );
 650         ip += 4;
 651 
 652         /* According to the specification, values > 32000 or < -32000 must */
 653         /* be followed by a `div' operator to make the result be in the    */
 654         /* range [-32000;32000].  We expect that the second argument of    */
 655         /* `div' is not a large number.  Additionally, we don't handle     */
 656         /* stuff like `<large1> <large2> <num> div <num> div' or           */
 657         /* <large1> <large2> <num> div div'.  This is probably not allowed */
 658         /* anyway.                                                         */
 659         if ( value > 32000 || value < -32000 )
 660         {
 661           if ( large_int )

 662             FT_ERROR(( "t1_decoder_parse_charstrings:"
 663                        " no `div' after large integer\n" ));

 664           else
 665             large_int = TRUE;
 666         }
 667         else
 668         {
 669           if ( !large_int )
 670             value = (FT_Int32)( (FT_UInt32)value << 16 );
 671         }
 672 
 673         break;
 674 
 675       default:
 676         if ( ip[-1] >= 32 )
 677         {
 678           if ( ip[-1] < 247 )
 679             value = (FT_Int32)ip[-1] - 139;
 680           else
 681           {
 682             if ( ++ip > limit )
 683             {


1680    *     The current Type 1 decoder.
1681    *
1682    *   charstring_base ::
1683    *     The base address of the charstring stream.
1684    *
1685    *   charstring_len ::
1686    *     The length in bytes of the charstring stream.
1687    *
1688    * @Return:
1689    *   FreeType error code.  0 means success.
1690    */
1691   FT_LOCAL_DEF( FT_Error )
1692   t1_decoder_parse_metrics( T1_Decoder  decoder,
1693                             FT_Byte*    charstring_base,
1694                             FT_UInt     charstring_len )
1695   {
1696     T1_Decoder_Zone  zone;
1697     FT_Byte*         ip;
1698     FT_Byte*         limit;
1699     T1_Builder       builder = &decoder->builder;
1700     FT_Bool          large_int;
1701 
1702 #ifdef FT_DEBUG_LEVEL_TRACE
1703     FT_Bool          bol = TRUE;
1704 #endif
1705 
1706 
1707     /* First of all, initialize the decoder */
1708     decoder->top  = decoder->stack;
1709     decoder->zone = decoder->zones;
1710     zone          = decoder->zones;
1711 
1712     builder->parse_state = T1_Parse_Start;
1713 
1714     zone->base           = charstring_base;
1715     limit = zone->limit  = charstring_base + charstring_len;
1716     ip    = zone->cursor = zone->base;
1717 
1718     large_int = FALSE;
1719 
1720     /* now, execute loop */
1721     while ( ip < limit )
1722     {
1723       FT_Long*     top   = decoder->top;
1724       T1_Operator  op    = op_none;
1725       FT_Int32     value = 0;
1726 
1727 
1728 #ifdef FT_DEBUG_LEVEL_TRACE
1729       if ( bol )
1730       {
1731         FT_TRACE5(( " (%d)", decoder->top - decoder->stack ));
1732         bol = FALSE;
1733       }
1734 #endif
1735 
1736       /**********************************************************************
1737        *
1738        * Decode operator or operand
1739        *


1760       case 31:
1761         goto No_Width;
1762 
1763       case 13:
1764         op = op_hsbw;
1765         break;
1766 
1767       case 12:
1768         if ( ip >= limit )
1769         {
1770           FT_ERROR(( "t1_decoder_parse_metrics:"
1771                      " invalid escape (12+EOF)\n" ));
1772           goto Syntax_Error;
1773         }
1774 
1775         switch ( *ip++ )
1776         {
1777         case 7:
1778           op = op_sbw;
1779           break;
1780         case 12:
1781           op = op_div;
1782           break;
1783 
1784         default:
1785           goto No_Width;
1786         }
1787         break;
1788 
1789       case 255:    /* four bytes integer */
1790         if ( ip + 4 > limit )
1791         {
1792           FT_ERROR(( "t1_decoder_parse_metrics:"
1793                      " unexpected EOF in integer\n" ));
1794           goto Syntax_Error;
1795         }
1796 
1797         value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
1798                             ( (FT_UInt32)ip[1] << 16 ) |
1799                             ( (FT_UInt32)ip[2] << 8  ) |
1800                               (FT_UInt32)ip[3]         );
1801         ip += 4;
1802 
1803         /* According to the specification, values > 32000 or < -32000 must */
1804         /* be followed by a `div' operator to make the result be in the    */
1805         /* range [-32000;32000].  We expect that the second argument of    */
1806         /* `div' is not a large number.  Additionally, we don't handle     */
1807         /* stuff like `<large1> <large2> <num> div <num> div' or           */
1808         /* <large1> <large2> <num> div div'.  This is probably not allowed */
1809         /* anyway.                                                         */
1810         if ( value > 32000 || value < -32000 )
1811         {
1812           if ( large_int )
1813           {
1814             FT_ERROR(( "t1_decoder_parse_metrics:"
1815                        " no `div' after large integer\n" ));
1816             goto Syntax_Error;
1817           }
1818           else
1819             large_int = TRUE;
1820         }
1821         else
1822         {
1823           if ( !large_int )
1824             value = (FT_Int32)( (FT_UInt32)value << 16 );
1825         }
1826 
1827         break;
1828 
1829       default:
1830         if ( ip[-1] >= 32 )
1831         {
1832           if ( ip[-1] < 247 )
1833             value = (FT_Int32)ip[-1] - 139;
1834           else
1835           {
1836             if ( ++ip > limit )
1837             {
1838               FT_ERROR(( "t1_decoder_parse_metrics:"
1839                          " unexpected EOF in integer\n" ));
1840               goto Syntax_Error;
1841             }
1842 
1843             if ( ip[-2] < 251 )
1844               value =    ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108;
1845             else
1846               value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 );
1847           }
1848 
1849           if ( !large_int )
1850             value = (FT_Int32)( (FT_UInt32)value << 16 );
1851         }
1852         else
1853         {
1854           FT_ERROR(( "t1_decoder_parse_metrics:"
1855                      " invalid byte (%d)\n", ip[-1] ));
1856           goto Syntax_Error;
1857         }
1858       }
1859 
1860       if ( large_int && !( op == op_none || op == op_div ) )
1861       {
1862         FT_ERROR(( "t1_decoder_parse_metrics:"
1863                    " no `div' after large integer\n" ));
1864         goto Syntax_Error;
1865       }
1866 
1867       /**********************************************************************
1868        *
1869        * Push value on stack, or process operator
1870        *
1871        */
1872       if ( op == op_none )
1873       {
1874         if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
1875         {
1876           FT_ERROR(( "t1_decoder_parse_metrics: stack overflow\n" ));
1877           goto Syntax_Error;
1878         }
1879 
1880 #ifdef FT_DEBUG_LEVEL_TRACE
1881         if ( large_int )
1882           FT_TRACE4(( " %d", value ));
1883         else
1884           FT_TRACE4(( " %d", value / 65536 ));
1885 #endif
1886 
1887         *top++       = value;
1888         decoder->top = top;
1889       }
1890       else  /* general operator */
1891       {
1892         FT_Int  num_args = t1_args_count[op];
1893 
1894 
1895         FT_ASSERT( num_args >= 0 );
1896 
1897         if ( top - decoder->stack < num_args )
1898           goto Stack_Underflow;
1899 
1900 #ifdef FT_DEBUG_LEVEL_TRACE
1901 
1902         if ( op != op_div )
1903         {
1904           if ( top - decoder->stack != num_args )
1905             FT_TRACE0(( "t1_decoder_parse_metrics:"
1906                         " too much operands on the stack"
1907                         " (seen %d, expected %d)\n",
1908                         top - decoder->stack, num_args ));
1909         }
1910 
1911 #endif /* FT_DEBUG_LEVEL_TRACE */
1912 
1913         top -= num_args;
1914 
1915         switch ( op )
1916         {
1917         case op_hsbw:
1918           FT_TRACE4(( " hsbw" ));
1919 
1920           builder->parse_state = T1_Parse_Have_Width;
1921 
1922           builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1923                                               top[0] );
1924 
1925           builder->advance.x = top[1];
1926           builder->advance.y = 0;
1927 
1928           /* we only want to compute the glyph's metrics */
1929           /* (lsb + advance width), not load the rest of */


1933 
1934         case op_sbw:
1935           FT_TRACE4(( " sbw" ));
1936 
1937           builder->parse_state = T1_Parse_Have_Width;
1938 
1939           builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1940                                               top[0] );
1941           builder->left_bearing.y = ADD_LONG( builder->left_bearing.y,
1942                                               top[1] );
1943 
1944           builder->advance.x = top[2];
1945           builder->advance.y = top[3];
1946 
1947           /* we only want to compute the glyph's metrics */
1948           /* (lsb + advance width), not load the rest of */
1949           /* it; so exit immediately                     */
1950           FT_TRACE4(( "\n" ));
1951           return FT_Err_Ok;
1952 
1953         case op_div:
1954           FT_TRACE4(( " div" ));
1955 
1956           /* if `large_int' is set, we divide unscaled numbers; */
1957           /* otherwise, we divide numbers in 16.16 format --    */
1958           /* in both cases, it is the same operation            */
1959           *top = FT_DivFix( top[0], top[1] );
1960           top++;
1961 
1962           large_int = FALSE;
1963           break;
1964 
1965         default:
1966           FT_ERROR(( "t1_decoder_parse_metrics:"
1967                      " unhandled opcode %d\n", op ));
1968           goto Syntax_Error;
1969         }
1970 
1971         decoder->top = top;
1972 
1973       } /* general operator processing */
1974 
1975     } /* while ip < limit */
1976 
1977     FT_TRACE4(( "..end..\n\n" ));
1978 
1979   No_Width:
1980     FT_ERROR(( "t1_decoder_parse_metrics:"
1981                " no width, found op %d instead\n",
1982                ip[-1] ));
1983   Syntax_Error:
1984     return FT_THROW( Syntax_Error );
1985 
1986   Stack_Underflow:
1987     return FT_THROW( Stack_Underflow );
1988   }
1989 
1990 #endif /* !T1_CONFIG_OPTION_OLD_ENGINE */
1991 


< prev index next >