home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / DISPBFON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-13  |  3.7 KB  |  141 lines

  1. /*
  2.     dispbfon.c
  3.  
  4.     % Find next bigger/smaller font
  5.  
  6.     2/4/90 by Ted.
  7.  
  8.     OWL 1.2a
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      3/28/90 jmd    ansi-fied
  15. */
  16.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19.  
  20. /* Aspect ratio multiplier */
  21. #define ASPD        10000
  22. /* Aspect ratio rounding factor */
  23. #define ASPD2        ((ASPD-1)/2)
  24. /* Aspect ratio fudged divisor */
  25. #define ASPDF        ((ASPD)/10*9)
  26.  
  27. #define BIGFONTSIZE    10000
  28. /* -------------------------------------------------------------------------- */
  29.  
  30. ofont_type disp_GetBiggerFont(ofont_type font)
  31. /*
  32.     Find the next font available on the system that's bigger than the given one.
  33.     Open and return that font.
  34. */
  35. {
  36.     fontdesc_struct freq;
  37.     ofont_type nfont;
  38.     opcoord fwidth, fheight, bwidth, bheight;
  39.  
  40.     /* Copy fontreq struct from given font so we can match it */
  41.     memmove((VOID *) &freq, (VOID *) &font->req, sizeof(fontdesc_struct));
  42.  
  43.     fwidth = ofont_GetWidth(font);
  44.     fheight = ofont_GetHeight(font);
  45.  
  46.     if (!font->real.scalable) {
  47.         /* First find the biggest font so we'll know when to stop */
  48.         freq.width  = BIGFONTSIZE;
  49.         freq.height = BIGFONTSIZE;
  50.  
  51.         if ((nfont = disp_OpenFont(&freq)) != NULL) {
  52.             bwidth = ofont_GetWidth(nfont);
  53.             bheight = ofont_GetHeight(nfont);
  54.             disp_CloseFont(nfont);
  55.         }
  56.         else return(NULL);
  57.  
  58.         /* If we are already biggest, quit */
  59.         if (bwidth == fwidth && bheight == fheight) {
  60.             return(NULL);
  61.         }
  62.     }
  63.     /* Set up font aspect ratio to pass along (if it wasn't set already) */
  64.     if (font->aspect == 0) {
  65.         font->aspect = (unsigned short) ((((long) fheight) * ASPD) / fwidth);
  66.     }
  67.     /* Now loop until we find a bigger font */
  68.     freq.width = font->req.width;
  69.     freq.height = font->req.height;
  70.     for (;;) {
  71.         /* Increment the width; scale height correspondingly given aspect ratio */
  72.         freq.width++;
  73.         freq.height = (opcoord) (
  74.             (((long) freq.width * (long) font->aspect) + ASPD2) / ASPD );
  75.  
  76.         if ((nfont = disp_OpenFont(&freq)) != NULL) {
  77.             if (ofont_GetWidth(nfont)  > fwidth ||
  78.                 ofont_GetHeight(nfont) > fheight) {
  79.                 break;
  80.             }
  81.             disp_CloseFont(nfont);
  82.         }
  83.         else return(NULL);
  84.     }
  85.     /* Set original aspect ratio in new font */
  86.     nfont->aspect = font->aspect;
  87.  
  88.     return(nfont);
  89. }
  90. /* -------------------------------------------------------------------------- */
  91.  
  92. ofont_type disp_GetSmallerFont(ofont_type font)
  93. /*
  94.     Find the next font available on the system that's smaller than the given one.
  95.     Open and return that font.
  96. */
  97. {
  98.     fontdesc_struct freq;
  99.     ofont_type nfont;
  100.     opcoord fwidth, fheight;
  101.  
  102.     /* Copy fontreq struct from given font so we can match it */
  103.     memmove((VOID *) &freq, (VOID *) &font->req, sizeof(fontdesc_struct));
  104.  
  105.     /* Loop until we find a smaller font */
  106.     fwidth = ofont_GetWidth(font);
  107.     fheight = ofont_GetHeight(font);
  108.  
  109.     /* Set up font aspect ratio to pass along (if it wasn't set already) */
  110.     if (font->aspect == 0) {
  111.         font->aspect = (unsigned short) ((((long) fheight) * ASPD) / fwidth);
  112.     }
  113.     freq.width =  ofont_GetWidth(font);
  114.     freq.height = ofont_GetHeight(font);
  115.  
  116.     for (;;) {
  117.         /* Decrement the width; scale height correspondingly given aspect ratio */
  118.         freq.width--;
  119.         freq.height = (opcoord) (
  120.             (((long) freq.width * (long) font->aspect) + ASPD2) / ASPDF );
  121.  
  122.         if (freq.width == 0 || freq.height == 0) {
  123.             return(NULL);    /* Quit if we get to 0 request size */
  124.         }
  125.         if ((nfont = disp_OpenFont(&freq)) != NULL) {
  126.             if (ofont_GetWidth(nfont)  < fwidth ||
  127.                 ofont_GetHeight(nfont) < fheight) {
  128.                 break;
  129.             }
  130.             disp_CloseFont(nfont);
  131.         }
  132.         else return(NULL);
  133.     }
  134.     /* Set original aspect ratio in new font */
  135.     nfont->aspect = font->aspect;
  136.  
  137.     return(nfont);
  138. }
  139. /* -------------------------------------------------------------------------- */
  140.  
  141.