/* %kw # %v %n %d %t # */ /* Version # 1 POINTSZ.C 26-Oct-94 18:09:10 # */ /* *************************************************** */ /* METAGRAPHICS SOFTWARE CORPORATION (c) 1994 */ /* */ /* Illustrates how to specify TextSize in points */ /* relative to each bitmaps dpi settings */ /* */ /* *************************************************** */ #include #include #include #include "metawndo.h" /* master MetaWINDOW include file */ /* special stack size declaration if using Turbo or Borland C++ */ #ifdef TurboC extern unsigned _stklen = 14336U; /* stack size 14K */ #endif int LoadFont( char * fontName ); void PointSize( int x, int y ); void main( int argc, char *argv[] ) { int i, dpi; rect sR; // temp working rect grafPort *thePort; // pointer to the screen port(/bitmap) grafPort *offscrPort; // pointer to the offscreen port(/bitmap) // init MetaWINDOW i = InitGraphics( VGA640x480 ); if ( i != 0 ) { printf("Initgraphics failed %d", i ); exit(1); } // load a stroked font if( LoadFont("ROMANSIM.FNT") == 0 ) printf("Can't load ROMANSIM.FNT\n"); // set text size in points PointSize( 20, 20 ); TextFace( cProportional ); GetPort( &thePort ); // get pointer to the screen port // make a 3 x 3 inch bitmap at 300 dots (pixels) per inch // note: very large (like 8x11 inches) bitmaps have to be // created via InitBitmap() with a cache buffer set > 32K dpi = 300; offscrPort = CreateBitmap( cDISK, dpi * 3, dpi * 3 ); if ( offscrPort == NULL ) { printf("ERROR: Unable to allocate offscreen bitmap\n"); exit(1); // abort if CreateBitmap() fails } // tell offscreen bitmap how many dots per inch it represents offscrPort->portMap->pixResX = dpi; offscrPort->portMap->pixResY = dpi; printf("\nNow drawing to offscreen disk bitmap..."); // erase the bitmap BackColor( LtGray ); EraseRect( &offscrPort->portRect ); // make this port use the same font as the screen port SetFont( thePort->txFont ); TextFace( cProportional ); // set text size in points PointSize( 20, 20 ); PenColor( Black ); MoveTo( 20,100 ); DrawString("This is the text drawn on the memory bitmap"); printf("\nReady to copy offscreen bitmap to the screen"); printf("\nPress Return to continue\n"); getch(); // wait for a keypress SetPort( thePort ); // switch back to the screen SetDisplay( GrafPg0 ); // switch display to graphics mode PaintRect( &sR ); // fill screen with a different color // copy the memory bitmap to the screen bitmap CopyBlit( offscrPort, thePort, &offscrPort->portRect, &thePort->portRect ); // draw some text directly on the screen bitmap MoveTo( 20,160 ); DrawString("This is the text drawn on the screen bitmap"); getch(); // wait for a keypress // free the offscreen bitmap DestroyBitmap( offscrPort ); // free font free( thePort->txFont ); SetDisplay( TextPg0 ); // Switch to text mode i = QueryError(); // Show any MetaWINDOW detected errors printf("QueryError=%d/%d",i >> 7,i & 127); StopGraphics(); exit(i); } // allocate a buffer for, load and set as active, a font file int LoadFont( char * fontName ) { dirRec fontDir; fontRcd *theFont; // get the file size of this font if( FileQuery( fontName, &fontDir, 1 ) != 1 ) { // can't find the file return 0; } // allocate a buffer for it theFont = (fontRcd *)malloc( (size_t) fontDir.fileSize ); if( theFont == NULL ) { // out of memory return 0; } FileLoad(fontName,theFont, (Word) fontDir.fileSize ); SetFont( theFont ); return 1; } // set size of text expressed in points ( 1/72 of an inch) void PointSize( int pntX, int pntY ) { grafPort *thePort; // get pointer to the current port GetPort( &thePort ); // convert points to dots (pixels) // points * 1/72 = inches * dpi = dots pntX *= thePort->portMap->pixResX; pntX /= 72; pntY *= thePort->portMap->pixResY; pntY /= 72; TextSize( pntX, pntY ); }