home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff589.lza / Term / TermSrc.lha / Scale.c < prev    next >
C/C++ Source or Header  |  1991-09-28  |  5KB  |  252 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: Scale.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Some static data required by the bitmap scaling routine. */
  18.  
  19. STATIC struct RastPort        *ScaleRPort;
  20. STATIC struct BitMap        *ScaleSrcBitMap,*ScaleDstBitMap;
  21. STATIC struct BitScaleArgs    *ScaleArgs;
  22.  
  23. STATIC struct TextFont        *ScaleFontType = NULL;
  24.  
  25.     /* DeleteScale():
  26.      *
  27.      *    Frees all the data associated with font scaling.
  28.      */
  29.  
  30. VOID
  31. DeleteScale()
  32. {
  33.     if(ScaleArgs)
  34.         FreeMem(ScaleArgs,sizeof(struct BitScaleArgs));
  35.  
  36.     ScaleArgs = NULL;
  37.  
  38.     if(ScaleDstBitMap)
  39.     {
  40.         if(ScaleDstBitMap -> Planes[0])
  41.             FreeMem(ScaleDstBitMap -> Planes[0],2 * 16 * ScaleDstBitMap -> Depth);
  42.  
  43.         FreeMem(ScaleDstBitMap,sizeof(struct BitMap));
  44.     }
  45.  
  46.     ScaleDstBitMap = NULL;
  47.  
  48.     if(ScaleSrcBitMap)
  49.     {
  50.         if(ScaleSrcBitMap -> Planes[0])
  51.             FreeMem(ScaleSrcBitMap -> Planes[0],2 * 8 * ScaleSrcBitMap -> Depth);
  52.  
  53.         FreeMem(ScaleSrcBitMap,sizeof(struct BitMap));
  54.     }
  55.  
  56.     ScaleSrcBitMap = NULL;
  57.  
  58.     if(ScaleRPort)
  59.         FreeMem(ScaleRPort,sizeof(struct RastPort));
  60.  
  61.     ScaleRPort = NULL;
  62. }
  63.  
  64.     /* CreateScale():
  65.      *
  66.      *    Sets up the data required for real-time font scaling
  67.      *    (bitmaps, rastports, etc.).
  68.      */
  69.  
  70. BYTE
  71. CreateScale()
  72. {
  73.     SHORT i;
  74.  
  75.     if(ScaleRPort = (struct RastPort *)AllocMem(sizeof(struct RastPort),MEMF_PUBLIC|MEMF_CLEAR))
  76.     {
  77.         InitRastPort(ScaleRPort);
  78.  
  79.         if(ScaleSrcBitMap = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR))
  80.         {
  81.             InitBitMap(ScaleSrcBitMap,Screen -> RastPort . BitMap -> Depth,16,8);
  82.  
  83.             if(ScaleDstBitMap = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR))
  84.             {
  85.                 InitBitMap(ScaleDstBitMap,Screen -> RastPort . BitMap -> Depth,16,16);
  86.  
  87.                 ScaleRPort -> BitMap = ScaleSrcBitMap;
  88.  
  89.                 if(ScaleSrcBitMap -> Planes[0] = (PLANEPTR)AllocMem(2 * 8 * ScaleSrcBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
  90.                 {
  91.                     for(i = 1 ; i < ScaleSrcBitMap -> Depth ; i++)
  92.                         ScaleSrcBitMap -> Planes[i] = ScaleSrcBitMap -> Planes[0] + i * 2 * 8;
  93.  
  94.                     if(ScaleDstBitMap -> Planes[0] = (PLANEPTR)AllocMem(2 * 16 * ScaleDstBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
  95.                     {
  96.                         for(i = 1 ; i < ScaleDstBitMap -> Depth ; i++)
  97.                             ScaleDstBitMap -> Planes[i] = ScaleDstBitMap -> Planes[0] + i * 2 * 16;
  98.  
  99.                         SetFont(ScaleRPort,CurrentFont);
  100.  
  101.                         ScaleFontType = CurrentFont;
  102.  
  103.                         SetDrMd(ScaleRPort,JAM2);
  104.                         SetAPen(ScaleRPort,1);
  105.                         SetBPen(ScaleRPort,0);
  106.  
  107.                         if(ScaleArgs = (struct BitScaleArgs *)AllocMem(sizeof(struct BitScaleArgs),MEMF_PUBLIC|MEMF_CLEAR))
  108.                         {
  109.                             ScaleArgs -> bsa_SrcWidth    = 8;
  110.                             ScaleArgs -> bsa_SrcHeight    = 8;
  111.  
  112.                             ScaleArgs -> bsa_SrcBitMap    = ScaleSrcBitMap;
  113.                             ScaleArgs -> bsa_DestBitMap    = ScaleDstBitMap;
  114.  
  115.                             return(TRUE);
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.         }
  121.     }
  122.  
  123.     return(FALSE);
  124. }
  125.  
  126.     /* PrintScaled(UBYTE Char,UBYTE Scale):
  127.      *
  128.      *    This is the big one: since VT100 supports a number of
  129.      *    font sizes (double height, double width, 132 columns),
  130.      *    the approriate characters are scaled in real-time before
  131.      *    they are displayed.
  132.      */
  133.  
  134. VOID
  135. PrintScaled(UBYTE *Buffer,LONG Size,UBYTE Scale)
  136. {
  137.     STATIC UBYTE LocalFgPen = 1,LocalBgPen = 0;
  138.  
  139.     LONG i;
  140.     
  141.     ULONG srcY,destX,destY,sizeX;
  142.  
  143.         /* Look for the font type to scale. */
  144.  
  145.     if(CurrentFont != ScaleFontType)
  146.     {
  147.         SetFont(ScaleRPort,CurrentFont);
  148.  
  149.         ScaleFontType = CurrentFont;
  150.     }
  151.  
  152.         /* Set the approriate colours. */
  153.  
  154.     if(ScaleRPort -> FgPen != LocalFgPen)
  155.     {
  156.         SetAPen(ScaleRPort,FgPen);
  157.  
  158.         LocalFgPen = FgPen;
  159.     }
  160.  
  161.     if(ScaleRPort -> BgPen != LocalBgPen)
  162.     {
  163.         LocalBgPen = BgPen;
  164.  
  165.         SetBPen(ScaleRPort,BgPen);
  166.     }
  167.  
  168.         /* Determine the scale of the destination character. */
  169.  
  170.     ScaleArgs -> bsa_YSrcFactor = 1;
  171.  
  172.     if((Config . FontScale == SCALE_HALF) && (Scale == SCALE_ATTR_NORMAL))
  173.     {
  174.         ScaleArgs -> bsa_XSrcFactor = 2;
  175.  
  176.         destX = CursorX << 2;
  177.  
  178.         sizeX = 4;
  179.     } else
  180.     {
  181.         ScaleArgs -> bsa_XSrcFactor = 1;
  182.  
  183.         destX = CursorX << 3;
  184.  
  185.         sizeX = 8;
  186.  
  187.         if(Config . FontScale == SCALE_NORMAL)
  188.             if(Scale != SCALE_ATTR_NORMAL)
  189.             {
  190.                 sizeX = 16;
  191.                 destX <<= 1;
  192.             }
  193.     }
  194.  
  195.     srcY = 0;
  196.     destY = CursorY << 3;
  197.  
  198.     ScaleArgs -> bsa_XDestFactor = 1;
  199.     ScaleArgs -> bsa_YDestFactor = 1;
  200.  
  201.     switch(Scale)
  202.     {
  203.             /* Twice as wide as the source data. */
  204.  
  205.         case SCALE_ATTR_2X:
  206.  
  207.             if(Config . FontScale == SCALE_NORMAL)
  208.                 ScaleArgs -> bsa_XDestFactor = 2;
  209.  
  210.             ScaleArgs -> bsa_YDestFactor = 1;
  211.  
  212.             break;
  213.  
  214.             /* Twice as high as the source data. */
  215.  
  216.         case SCALE_ATTR_BOT2X:
  217.  
  218.             srcY = 8;
  219.  
  220.         case SCALE_ATTR_TOP2X:
  221.  
  222.             if(Config . FontScale == SCALE_NORMAL)
  223.                 ScaleArgs -> bsa_XDestFactor = 2;
  224.  
  225.             ScaleArgs -> bsa_YDestFactor = 2;
  226.  
  227.             break;
  228.     }
  229.  
  230.     for(i = 0; i < Size; i++)
  231.     {
  232.  
  233.             /* Print the character to be scaled into the
  234.              * invisible drawing area.
  235.              */
  236.  
  237.         Move(ScaleRPort,0,6);
  238.  
  239.         Text(ScaleRPort,Buffer++,1);
  240.  
  241.             /* Scale the font. */
  242.  
  243.         BitMapScale(ScaleArgs);
  244.  
  245.             /* Render the character. */
  246.  
  247.         BltBitMapRastPort(ScaleDstBitMap,0,srcY,RPort,destX,destY,sizeX,8,0xC0);
  248.  
  249.         destX += sizeX;
  250.     }
  251. }
  252.