home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / ft-beta.zip / freetype / test / fdebug.c < prev    next >
C/C++ Source or Header  |  1997-10-06  |  10KB  |  323 lines

  1. /****************************************************************************}
  2. {*                                                                          *}
  3. {*  The FreeType project - a Free and Portable Quality TrueType Renderer.   *}
  4. {*                                                                          *}
  5. {*  Copyright 1996  D. Turner, R.Wilhelm, W. Lemberg                        *}
  6. {*                                                                          *}
  7. {*  fdebug : A very simple TrueType bytecode debugger.                      *}
  8. {*                                                                          *}
  9. {*  NOTE : You must compile the interpreter with the DEBUG macro            *}
  10. {*         defined in order to link this program !!                         *}
  11. {*                                                                          *}
  12. {*  Keys :                                                                  *}
  13. {*                                                                          *}
  14. {*  x :   fine counter_clockwise rotation                                   *}
  15. {*  c :   fine clockwise rotation                                           *}
  16. {*                                                                          *}
  17. {*  v :   fast counter_clockwise rotation                                   *}
  18. {*  b :   fast clockwise rotation                                           *}
  19. {*                                                                          *}
  20. {*  + :   fast scale up                                                     *}
  21. {*  - :   fast scale down                                                   *}
  22. {*  u :   fine scale down                                                   *}
  23. {*  j :   fine scale up                                                     *}
  24. {*                                                                          *}
  25. {*  l :   go to next glyph                                                  *}
  26. {*  k :   go to previous glyph                                              *}
  27. {*                                                                          *}
  28. {*  o :   go to tenth next glyph                                            *}
  29. {*  i :   go to tenth previous glyph                                        *}
  30. {*                                                                          *}
  31. {*  0 :   go to hundredth next glyph                                        *}
  32. {*  9 :   go to hundredth previous glyph                                    *}
  33. {*                                                                          *}
  34. {*  ESC :   exit                                                            *}
  35. {*                                                                          *}
  36. {*                                                                          *}
  37. {*  NOTE : This is just a test program that is used to show off and         *}
  38. {*         debug the current engine; which is still in alpha. In no         *}
  39. {*         way does it shows the final high-level interface that            *}
  40. {*         client applications will use. Wait for at least a beta for       *}
  41. {*         this.                                                            *}
  42. {*                                                                          *}
  43. {****************************************************************************/
  44.  
  45. #ifdef HAVE_CONIO_H
  46. #include <conio.h>
  47. #endif
  48.  
  49. #ifdef ARM
  50. #include "std.h"
  51. #include "graflink.h"
  52. #endif
  53.  
  54. #include "tttypes.h"
  55. #include "tterror.h"
  56. #include "ttcalc.h"
  57. #include "tttables.h"
  58. #include "ttmemory.h"
  59. #include "ttraster.h"
  60. #include "ttindex.h"
  61. #include "ttins.h"
  62. #include "ttfile.h"
  63. #include "ttexec.h"
  64. #include "tttables.h"
  65.  
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <string.h>
  69. #include <math.h>    /* libc ANSI */
  70.  
  71.  
  72. #ifdef ARM
  73. #include "armsup.c" /* pull in our routines */
  74. #endif
  75.  
  76. #define  Pi          3.1415926535
  77.  
  78. #define  MAXPTSIZE   500           /* dtp */
  79. #define  Center_X   (Bit.width/2)  /* dtp */
  80. #define  Center_Y   (Bit.rows/2)   /* dtp */
  81.  
  82. #define  Profile_Buff_Size  64000      /* Size of the render pool   */
  83.                                        /* Minimum is around 4 Kb    */
  84.                                        /* experiment to see how its */
  85.                                        /* size impacts on raster    */
  86.  
  87.                                        /* performance..             */
  88. #define  Font_Buff_Size  256000        /* this buffer holds all     */
  89.                                        /* font specific data.       */
  90.  
  91. #define  Border 10
  92.  
  93.   TT_Stream         stream;
  94.   PResident_Record  resident;
  95.   PInstance_Record  instance;
  96.  
  97.   PExecution_Context  exec;
  98.  
  99.   PStorage        Font_Buffer;
  100.  
  101.   int   num_glyphs;
  102.   int   num_pts;
  103.   int   num_ctr;
  104.  
  105.   int   glyfArray;
  106.  
  107.   PShort  epts_ctr;
  108.  
  109.   /* DTP important font metrics */
  110.   Long   cur_LeftSB,
  111.          cur_Ascent,
  112.          cur_Descent,
  113.          cur_AdvanceWidth; 
  114.            
  115.   Int    ptsize;
  116.  
  117.   float  ymin,
  118.          ymax,
  119.          xmax,
  120.          xmin,
  121.          xsize;    /* DTP testing precision */
  122.  
  123.   float  resR;
  124.  
  125.   TGlyphRecord  gRec;
  126.  
  127.   TRasterBlock  Bit;
  128.  
  129.   Int           Rotation;
  130.   Int           Fail;
  131.   Int           Num;
  132.   unsigned char autorun;
  133.  
  134.   char          GrayLines[1024];
  135.   int           gray_render;
  136.  
  137.   TT_PCMapTable OurcmapIndex;
  138.  
  139.   FILE* FOut;
  140.  
  141.   TT_PCoordinates   Save_orgx, Save_orgy, Save_curx, Save_cury, Save_touch;
  142.  
  143.  
  144.   void Dump_CVT( PShort cvt, Int num )
  145.   {
  146.     Int  i;
  147.  
  148.     for ( i = 0; i < num; i++ )
  149.     {
  150.       fprintf( FOut, "%04hx:", cvt[i] );
  151.     }
  152.     fprintf( FOut, "\n" );
  153.   }
  154.  
  155.  
  156.   Bool  LoadTrueTypeChar( Int idx )
  157.   {
  158.     TGlyph      *pG;
  159.     Short       numP, numC;
  160.  
  161.     Int i;
  162.  
  163.     /* Reset_Context( instance->exec );  */
  164.     
  165.     if ( !Load_TrueType_Glyph( instance, idx, TRUE ) )
  166.       return FAILURE;
  167.   
  168.     pG   = instance->glyph;
  169.     numP = instance->pts.n;
  170.     numC = instance->glyph->numberOfContours;
  171.   
  172.     if (numP <= 0 || numC <= 0)
  173.       return FAILURE;
  174.   
  175.     DebugTrace(( "num contours = %d\n", numC ));
  176.  
  177.     for ( i = 0; i < numC; i++ )
  178.     DebugTrace(( "%d ", instance->endContours[i] ));
  179.  
  180.     DebugTrace(( "\n" ));
  181.  
  182.     DebugTrace(( "Original values\n" ));
  183.     for ( i = 0; i < instance->pts.n; i++ )
  184.     {
  185.       DebugTrace(( "%02hx  ", i ));
  186.       DebugTrace(( "%08lx,%08lx\n", 
  187.                    instance->pts.cur_x[i],
  188.                    instance->pts.cur_y[i] ));
  189.     }
  190.     DebugTrace(( "\n" ));
  191.  
  192.     TT_Transform_Glyph( instance );
  193.      /* This call scales the glyph */
  194.  
  195.     DebugTrace(( "Scaled values\n" ));
  196.     for ( i = 0; i < instance->pts.n; i++ )
  197.     {
  198.       DebugTrace(( "%02hx  ", i ));
  199.       DebugTrace(( "%08lx,%08lx\n", 
  200.                    instance->pts.cur_x[i],
  201.                    instance->pts.cur_y[i] ));
  202.     }
  203.     DebugTrace(( "\n" ));
  204.  
  205.     DebugTrace(( "Scale1 = %04lx\n", exec->scale1 ));
  206.     DebugTrace(( "Scale2 = %04lx\n\n", exec->scale2 ));
  207.  
  208.     /* The following operations should be later included into the */
  209.     /* Run_Context function. However, we're still under debuggig  */
  210.     /* and it is important to do these things ourselves           */
  211.  
  212.      if ( !Load_Glyph_Instructions( instance, 0 ) )
  213.        Panic( "ERROR: could not load instructions\n" );
  214.  
  215.      if ( !DebugIns( exec ) )
  216.      {
  217.        DebugTrace(( "error = %d\n", exec->error ));
  218.        return FAILURE;
  219.      }
  220.  
  221.     return SUCCESS;
  222.   }
  223.  
  224.  
  225.   void main( int argc, char** argv ) 
  226.   {
  227.   
  228.    int     i;
  229.    char    filename[128+4];
  230.    char*   execname;
  231.   
  232.    Font_Buffer = (PStorage)malloc( Font_Buff_Size );
  233.     if ( !Font_Buffer )
  234.     {
  235.       Message( "Error: Could not even allocate font pool!\n" );
  236.       exit( 1 );
  237.     }
  238.  
  239.     Init_FontPool( Font_Buffer, Font_Buff_Size );
  240.  
  241.     num_pts = 0;
  242.     num_ctr = 0;
  243.  
  244.     execname = argv[0];
  245.  
  246.     if ( argc != 4 )
  247.     {
  248.       Message( "Test: simple TrueType interpreter tester - part of the FreeType project\n" );
  249.       Message( "-----------------------------------------------------------------------\n\n");
  250.       Message( "Usage: %s glyphnum ppem fontname[.ttf]\n\n", execname );
  251.       exit( 1 );
  252.     }
  253.  
  254.     if ( sscanf( argv[1], "%d", &Num ) == EOF )
  255.       Num = 0;
  256.  
  257.     if ( sscanf( argv[2], "%d", &ptsize ) == EOF )
  258.       ptsize = 64;
  259.  
  260.     i = strlen( argv[3] );
  261.     while ( i > 0 && argv[3][i] != '\\' )
  262.     {
  263.       if ( argv[3][i] == '.' )
  264.         i = 0;
  265.       i--;
  266.     }
  267.  
  268.     filename[128] = 0;
  269.  
  270.     strncpy( filename, argv[3], 128 );
  271.     if ( i >= 0 )
  272.       strncpy( filename + strlen(filename), ".ttf", 4 );
  273.  
  274.     if ( !TT_Open_File( filename , &stream) )
  275.     {
  276.       Message( "Error, could not find/open %s\n\n", filename );
  277.       exit( 1 );
  278.     }
  279.  
  280.     if ( !TT_Load_Resident_Table( stream, &resident ) ) 
  281.     {
  282.       Message( "ERROR: Could not load data from %s\n", filename );
  283.       exit( 1 );
  284.     }
  285. /*
  286.     FOut = fopen( "h:\\work\\freetype\\p2.txt", "wt" );
  287.  
  288.     fprintf( FOut, "Original CVT\n" );
  289.     Dump_CVT( resident->cvt, resident->cvtSize );
  290. */
  291.     num_glyphs = resident->numGlyphs;
  292.         
  293.     if ( !TT_Load_Instance_Data( resident, &instance ) ) 
  294.     {
  295.       Message( "ERROR: Could not open instance from %s\n", filename );
  296.       exit( 1 );
  297.     }
  298.  
  299.     if ( !Create_Context( instance ) )
  300.       Panic( "ERROR: could not create execution context\n" );
  301.  
  302.     exec = (PExecution_Context)instance->exec;
  303.  
  304.     if ( !Reset_Context( instance, ptsize, 96 ) )
  305.       Panic( "ERROR: could not reset execution context\n" );
  306. /*
  307.     fprintf( FOut, "Scaled CVT\n" );
  308.     Dump_CVT( instance->cvt, instance->cvtSize );
  309. */
  310.     LoadTrueTypeChar(Num);
  311.  
  312. /*
  313.     fprintf( FOut, "Hinted CVT\n" );
  314.     Dump_CVT( instance->cvt, instance->cvtSize );
  315.  
  316.     fclose( FOut );
  317. */
  318.     TT_Close_File(stream);
  319.   }
  320.  
  321.  
  322. /* End */
  323.