home *** CD-ROM | disk | FTP | other *** search
- /*
- dispbfon.c
-
- % Find next bigger/smaller font
-
- 2/4/90 by Ted.
-
- OWL 1.2a
- Copyright (c) 1988, 1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/28/90 jmd ansi-fied
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
-
- /* Aspect ratio multiplier */
- #define ASPD 10000
- /* Aspect ratio rounding factor */
- #define ASPD2 ((ASPD-1)/2)
- /* Aspect ratio fudged divisor */
- #define ASPDF ((ASPD)/10*9)
-
- #define BIGFONTSIZE 10000
- /* -------------------------------------------------------------------------- */
-
- ofont_type disp_GetBiggerFont(ofont_type font)
- /*
- Find the next font available on the system that's bigger than the given one.
- Open and return that font.
- */
- {
- fontdesc_struct freq;
- ofont_type nfont;
- opcoord fwidth, fheight, bwidth, bheight;
-
- /* Copy fontreq struct from given font so we can match it */
- memmove((VOID *) &freq, (VOID *) &font->req, sizeof(fontdesc_struct));
-
- fwidth = ofont_GetWidth(font);
- fheight = ofont_GetHeight(font);
-
- if (!font->real.scalable) {
- /* First find the biggest font so we'll know when to stop */
- freq.width = BIGFONTSIZE;
- freq.height = BIGFONTSIZE;
-
- if ((nfont = disp_OpenFont(&freq)) != NULL) {
- bwidth = ofont_GetWidth(nfont);
- bheight = ofont_GetHeight(nfont);
- disp_CloseFont(nfont);
- }
- else return(NULL);
-
- /* If we are already biggest, quit */
- if (bwidth == fwidth && bheight == fheight) {
- return(NULL);
- }
- }
- /* Set up font aspect ratio to pass along (if it wasn't set already) */
- if (font->aspect == 0) {
- font->aspect = (unsigned short) ((((long) fheight) * ASPD) / fwidth);
- }
- /* Now loop until we find a bigger font */
- freq.width = font->req.width;
- freq.height = font->req.height;
- for (;;) {
- /* Increment the width; scale height correspondingly given aspect ratio */
- freq.width++;
- freq.height = (opcoord) (
- (((long) freq.width * (long) font->aspect) + ASPD2) / ASPD );
-
- if ((nfont = disp_OpenFont(&freq)) != NULL) {
- if (ofont_GetWidth(nfont) > fwidth ||
- ofont_GetHeight(nfont) > fheight) {
- break;
- }
- disp_CloseFont(nfont);
- }
- else return(NULL);
- }
- /* Set original aspect ratio in new font */
- nfont->aspect = font->aspect;
-
- return(nfont);
- }
- /* -------------------------------------------------------------------------- */
-
- ofont_type disp_GetSmallerFont(ofont_type font)
- /*
- Find the next font available on the system that's smaller than the given one.
- Open and return that font.
- */
- {
- fontdesc_struct freq;
- ofont_type nfont;
- opcoord fwidth, fheight;
-
- /* Copy fontreq struct from given font so we can match it */
- memmove((VOID *) &freq, (VOID *) &font->req, sizeof(fontdesc_struct));
-
- /* Loop until we find a smaller font */
- fwidth = ofont_GetWidth(font);
- fheight = ofont_GetHeight(font);
-
- /* Set up font aspect ratio to pass along (if it wasn't set already) */
- if (font->aspect == 0) {
- font->aspect = (unsigned short) ((((long) fheight) * ASPD) / fwidth);
- }
- freq.width = ofont_GetWidth(font);
- freq.height = ofont_GetHeight(font);
-
- for (;;) {
- /* Decrement the width; scale height correspondingly given aspect ratio */
- freq.width--;
- freq.height = (opcoord) (
- (((long) freq.width * (long) font->aspect) + ASPD2) / ASPDF );
-
- if (freq.width == 0 || freq.height == 0) {
- return(NULL); /* Quit if we get to 0 request size */
- }
- if ((nfont = disp_OpenFont(&freq)) != NULL) {
- if (ofont_GetWidth(nfont) < fwidth ||
- ofont_GetHeight(nfont) < fheight) {
- break;
- }
- disp_CloseFont(nfont);
- }
- else return(NULL);
- }
- /* Set original aspect ratio in new font */
- nfont->aspect = font->aspect;
-
- return(nfont);
- }
- /* -------------------------------------------------------------------------- */
-