home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol04 / 01b / macsl / mpmfig9.txt < prev    next >
Text File  |  1988-10-27  |  4KB  |  145 lines

  1. /*-----------------------------------------------------------------*/
  2. /* MpmGPI.c                                                        */
  3. /* GPI functions                                                   */
  4. /*-----------------------------------------------------------------*/
  5.  
  6. #include "MacPM.h"
  7.  
  8. /*-----------------------------------------------------------------*/
  9. /* Draw a character string at the current position                 */
  10. /*-----------------------------------------------------------------*/
  11.  
  12. LONG APIENTRY GpiCharString( hps, lLen, pch )
  13.     HPS         hps;
  14.     LONG        lLen;
  15.     PCH         pch;
  16. {
  17.     if( ! MpmValidatePS(hps) )
  18.       return GPI_ERROR;
  19.  
  20.     thePort = PGRAFOFHPS(hps);
  21.  
  22.     DrawText( pch, 0, (SHORT)lLen );
  23.  
  24.     return GPI_OK;
  25. }
  26.  
  27. /*-----------------------------------------------------------------*/
  28. /* Draw a character string at the specified position               */
  29. /*-----------------------------------------------------------------*/
  30.  
  31. LONG APIENTRY GpiCharStringAt( hps, pptl, lLen, pch )
  32.     HPS         hps;
  33.     PPOINTL     pptl;
  34.     LONG        lLen;
  35.     PCH         pch;
  36. {
  37.     if( ! GpiMove( hps, pptl ) )
  38.       return GPI_ERROR;
  39.  
  40.     return GpiCharString( hps, lLen, pch );
  41. }
  42.  
  43. /*-----------------------------------------------------------------*/
  44. /* Erase a PS on the screen.                                       */
  45. /*-----------------------------------------------------------------*/
  46.  
  47. BOOL APIENTRY GpiErase( hps )
  48.     HPS         hps;
  49. {
  50.     if( ! MpmValidatePS(hps) )
  51.       return FALSE;
  52.  
  53.     thePort = PGRAFOFHPS(hps);
  54.  
  55.     EraseRgn( thePort->visRgn );
  56.  
  57.     return TRUE;
  58. }
  59.  
  60. /*-----------------------------------------------------------------*/
  61. /* Set the drawing position to *pptl.                              */
  62. /*-----------------------------------------------------------------*/
  63.  
  64. BOOL APIENTRY GpiMove( hps, pptl )
  65.     HPS         hps;
  66.     PPOINTL     pptl;
  67. {
  68.     PMYWND      pwnd;
  69.  
  70.     if( ! MpmValidatePS(hps) )
  71.       return FALSE;
  72.  
  73.     thePort = PGRAFOFHPS(hps);
  74.     pwnd = PMYWNDOF(HWNDOFHPS(hps));
  75.  
  76.     MoveTo( (SHORT)pptl->x, (SHORT)( pwnd->cy - pptl->y ) );
  77.  
  78.     return TRUE;
  79. }
  80.  
  81. /*-----------------------------------------------------------------*/
  82. /* Pick up the current font metrics and return it in *pfm.         */
  83. /* This is kind of hokey and only initializes some of the fields   */
  84. /* properly!                                                       */
  85. /*-----------------------------------------------------------------*/
  86.  
  87. BOOL APIENTRY GpiQueryFontMetrics( hps, lLen, pfm )
  88.     HPS         hps;
  89.     LONG        lLen;
  90.     PFONTMETRICS pfm;
  91. {
  92.     GrafPtr     pgraf;
  93.     FMInput     fmi;
  94.     FMOutPtr    pfmo;
  95.  
  96.     if( ! MpmValidatePS(hps) )
  97.       return FALSE;
  98.  
  99.     pgraf = PGRAFOFHPS( hps );
  100.  
  101.     fmi.family    = pgraf->txFont;
  102.     fmi.size      = pgraf->txSize;
  103.     fmi.face      = pgraf->txFace;
  104.     fmi.needBits  = FALSE;
  105.     fmi.device    = 0;
  106.     fmi.numer.h   = 1;
  107.     fmi.numer.v   = 1;
  108.     fmi.denom.h   = 1;
  109.     fmi.denom.v   = 1;
  110.  
  111.     pfmo = FMSwapFont( &fmi );
  112.     ASSERT( pfmo,
  113.             "GpiQueryFontMetrics: FMSwapFont failed?" );
  114.  
  115.     memzero( pfm );
  116.  
  117.     pfm->lAveCharWidth      =  /* wrong, but make it same as max */
  118.     pfm->lMaxCharInc        = pfmo->widMax;
  119.     pfm->lMaxBaselineExt    = pfmo->ascent + pfmo->descent
  120.                               + pfmo->leading;
  121.     pfm->lMaxDescender      = pfmo->descent;
  122.  
  123.     /* more later... */
  124.  
  125.     return TRUE;
  126. }
  127.  
  128. /*-----------------------------------------------------------------*/
  129. /* Make sure hps is a valid PS handle.                             */
  130. /*-----------------------------------------------------------------*/
  131.  
  132. LOCAL BOOL MpmValidatePS( hps )
  133.     HPS         hps;
  134. {
  135.     if( hps != _hps1 )
  136.     {
  137.       ERROR( "Invalid PS handle!" );
  138.       return FALSE;
  139.     }
  140.  
  141.     return TRUE;
  142. }
  143.  
  144. /*-----------------------------------------------------------------*/
  145.