1 /**
2 ** convfont.c ---- build a converted font from an already loaded (linked) one
3 **
4 ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
5 ** [e-mail: csaba@vuse.vanderbilt.edu]
6 **
7 ** This file is part of the GRX graphics library.
8 **
9 ** The GRX graphics library is free software; you can redistribute it
10 ** and/or modify it under some conditions; see the "copying.grx" file
11 ** for details.
12 **
13 ** This library is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 **
17 **/
18
19 #include "libgrx.h"
20 #include "grfontdv.h"
21 #include "arith.h"
22
23 static const GrFont *cvfont;
24
charwdt(int chr)25 static int charwdt(int chr)
26 {
27 chr -= cvfont->h.minchar;
28 if((unsigned int)chr >= cvfont->h.numchars) return(-1);
29 return(cvfont->chrinfo[chr].width);
30 }
31
bitmap(int chr,int w,int h,char * buffer)32 static int bitmap(int chr,int w,int h,char *buffer)
33 {
34 chr -= cvfont->h.minchar;
35 if((unsigned int)chr >= cvfont->h.numchars) return(FALSE);
36 if((unsigned int)w != cvfont->chrinfo[chr].width) return(FALSE);
37 if((unsigned int)h != cvfont->h.height) return(FALSE);
38 memcpy(
39 buffer,
40 &cvfont->bitmap[cvfont->chrinfo[chr].offset],
41 ((w + 7) >> 3) * h
42 );
43 return(TRUE);
44 }
45
GrBuildConvertedFont(const GrFont * from,int cvt,int w,int h,int minch,int maxch)46 GrFont *GrBuildConvertedFont(const GrFont *from,int cvt,int w,int h,int minch,int maxch)
47 {
48 cvfont = from;
49 if(!cvfont) return(NULL);
50 return(_GrBuildFont(&from->h,cvt,w,h,minch,maxch,charwdt,bitmap,FALSE));
51 }
52
53