svn commit: r345483 - head/lib/libvgl
Bruce Evans
bde at FreeBSD.org
Sun Mar 24 19:41:47 UTC 2019
Author: bde
Date: Sun Mar 24 19:41:45 2019
New Revision: 345483
URL: https://svnweb.freebsd.org/changeset/base/345483
Log:
Add support for arbitrary font widths. Only multiples of 8 were supported.
Since the font format is undocumented, it is unclear how non-multiples
of 8 should be padded to bytes in the font file. Use the same
representation as bdf text format (big- endian, with padding in the
lower bits).
Modified:
head/lib/libvgl/text.c
Modified: head/lib/libvgl/text.c
==============================================================================
--- head/lib/libvgl/text.c Sun Mar 24 19:29:30 2019 (r345482)
+++ head/lib/libvgl/text.c Sun Mar 24 19:41:45 2019 (r345483)
@@ -66,7 +66,7 @@ FILE *fd;
VGLTextFont->BitmapArray =
(byte*)malloc(256*((VGLTextFont->Width + 7)/8)*VGLTextFont->Height);
fread(VGLTextFont->BitmapArray, 1,
- (256*VGLTextFont->Width* VGLTextFont->Height), fd);
+ (256*((VGLTextFont->Width + 7)/8)*VGLTextFont->Height), fd);
fclose(fd);
}
return 0;
@@ -76,44 +76,48 @@ void
VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch,
byte fgcol, byte bgcol, int fill, int dir)
{
- int lin, bit;
+ int b, Bpc, Bpl, lin, bit, topbit;
+ Bpl = (VGLTextFont->Width + 7) / 8;
+ Bpc = Bpl * VGLTextFont->Height;
+ topbit = VGLTextFont->Width - 1;
for(lin = 0; lin < VGLTextFont->Height; lin++) {
for(bit = 0; bit < VGLTextFont->Width; bit++) {
- if (VGLTextFont->BitmapArray[((ch*VGLTextFont->Height)+lin)]&(1<<bit))
+ b = bit + (-VGLTextFont->Width & 7);
+ if (VGLTextFont->BitmapArray[(ch*Bpc)+(lin*Bpl)+(b/8)]&(1<<(b%8)))
switch (dir) {
case 0:
- VGLSetXY(Object, (x+7-bit), (y+lin), fgcol);
+ VGLSetXY(Object, (x+topbit-bit), (y+lin), fgcol);
break;
case 1:
- VGLSetXY(Object, (x+lin), (y-7+bit), fgcol);
+ VGLSetXY(Object, (x+lin), (y-topbit+bit), fgcol);
break;
case 2:
- VGLSetXY(Object, (x-7+bit), (y-lin), fgcol);
+ VGLSetXY(Object, (x-topbit+bit), (y-lin), fgcol);
break;
case 3:
- VGLSetXY(Object, (x-lin), (y+7-bit), fgcol);
+ VGLSetXY(Object, (x-lin), (y+topbit-bit), fgcol);
break;
case 4:
- VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), fgcol);
+ VGLSetXY(Object, (x+lin+topbit-bit), (y+lin+bit), fgcol);
break;
}
else if (fill)
switch (dir) {
case 0:
- VGLSetXY(Object, (x+7-bit), (y+lin), bgcol);
+ VGLSetXY(Object, (x+topbit-bit), (y+lin), bgcol);
break;
case 1:
- VGLSetXY(Object, (x+lin), (y-7+bit), bgcol);
+ VGLSetXY(Object, (x+lin), (y-topbit+bit), bgcol);
break;
case 2:
- VGLSetXY(Object, (x-7+bit), (y-lin), bgcol);
+ VGLSetXY(Object, (x-topbit+bit), (y-lin), bgcol);
break;
case 3:
- VGLSetXY(Object, (x-lin), (y+7-bit), bgcol);
+ VGLSetXY(Object, (x-lin), (y+topbit-bit), bgcol);
break;
case 4:
- VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), bgcol);
+ VGLSetXY(Object, (x+lin+topbit-bit), (y+lin+bit), bgcol);
break;
}
}
More information about the svn-src-all
mailing list