C Language Development Kit/Functions/GetFontSize

From OptiWiki

Jump to: navigation, search
Description Returns the width and the height of a character of the current font, measured in pixels.
Syntax
void getfontsize(unsigned int * height, unsigned int * width);
Arguments
unsigned int * height
The height of the characters in the current font, measured in pixels.
unsigned int * width
The width of the characters in the current font, measured in pixels.
Returns None
Remarks This function is useful when you want to know how many characters fit on a line, or how many lines fit on the display.

This information is necessary when you build a menu system that can be used for different font sizes. This function is not available on the DWT7133.

Example
#include <stdio.h>
#include "lib.h"
 
#ifndef DISP_WIDTH
#if PHL        // PHL1700-10 and PHL1700-20
   #define DISP_WIDTH  96
   #define DISP_HEIGHT 48
#elif PHL1000  // PHL1300
   #define DISP_WIDTH  96
   #define DISP_HEIGHT 64 // Change height to 48 when indicators need to be on (see cursor() function)
#elif PHL2700  // PHL2700
   #define DISP_WIDTH  128
   #define DISP_HEIGHT 64
#elif OPH      // OPH100x
   #define DISP_WIDTH  112
   #define DISP_HEIGHT 128
#else          // OPL97XX and DCL153x series
   #define DISP_WIDTH  112
   #define DISP_HEIGHT 64
#endif
#endif
 
void main( void )
{
    unsigned int height, width, font=0;
    while( 1 )
    {
        if( ((++font) %2) == 0)
            setfont( LARGE_FONT, NULL);
        else
            setfont( SMALL_FONT, NULL);
        getfontsize( height, width);
        printf("\f%d chars/line\n%dlines", WIDTH/width, HEIGHT/height);
        resetkey();
        while( !kbhit())
            idle();
    }
}


Views
Personal tools