summaryrefslogtreecommitdiff
path: root/src/bitmap
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:50 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:50 +0000
commit4349bf0fa125e2a1c32b0b49c974ff5fa588cdbe (patch)
tree2e4b857f2103cfbcdfcfd53b47334166e139a273 /src/bitmap
parent3795e9702b3b3a6fe0594d09cdd110adeb5e42f9 (diff)
Diffstat (limited to 'src/bitmap')
-rw-r--r--src/bitmap/bdfread.c147
-rw-r--r--src/bitmap/bdfutils.c74
-rw-r--r--src/bitmap/bitmap.c40
-rw-r--r--src/bitmap/bitmapfunc.c93
-rw-r--r--src/bitmap/bitmaputil.c37
-rw-r--r--src/bitmap/bitscale.c435
-rw-r--r--src/bitmap/fontink.c17
-rw-r--r--src/bitmap/pcfread.c348
-rw-r--r--src/bitmap/pcfwrite.c79
-rw-r--r--src/bitmap/snfread.c115
-rw-r--r--src/bitmap/snfstr.h8
11 files changed, 720 insertions, 673 deletions
diff --git a/src/bitmap/bdfread.c b/src/bitmap/bdfread.c
index d365d6f..67e4252 100644
--- a/src/bitmap/bdfread.c
+++ b/src/bitmap/bdfread.c
@@ -50,9 +50,13 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bdfread.c,v 1.12 2002/09/10 16:14:34 tsi Exp $ */
+#ifndef FONTMODULE
#include <ctype.h>
+#endif
#include "fntfilst.h"
+#include "fontutil.h"
/* use bitmap structure */
#include "bitmap.h"
#include "bdfint.h"
@@ -61,22 +65,14 @@ from The Open Group.
#define MAXENCODING 0xFFFF
#define BDFLINELEN 1024
-extern int bitmapGetGlyphs(), bitmapGetMetrics();
-extern int bitmapGetBitmaps(), bitmapGetExtents();
-static Bool bdfPadToTerminal();
+static Bool bdfPadToTerminal(FontPtr pFont);
extern int bdfFileLineNum;
/***====================================================================***/
static Bool
-bdfReadBitmap(pCI, file, bit, byte, glyph, scan, sizes)
- CharInfoPtr pCI;
- FontFilePtr file;
- int bit,
- byte,
- glyph,
- scan;
- int sizes[GLYPHPADOPTIONS];
+bdfReadBitmap(CharInfoPtr pCI, FontFilePtr file, int bit, int byte,
+ int glyph, int scan, CARD32 *sizes)
{
int widthBits,
widthBytes,
@@ -90,7 +86,7 @@ bdfReadBitmap(pCI, file, bit, byte, glyph, scan, sizes)
unsigned char *pInBits,
*picture,
*line = NULL;
- char lineBuf[BDFLINELEN];
+ unsigned char lineBuf[BDFLINELEN];
widthBits = GLYPHWIDTHPIXELS(pCI);
height = GLYPHHEIGHTPIXELS(pCI);
@@ -99,9 +95,9 @@ bdfReadBitmap(pCI, file, bit, byte, glyph, scan, sizes)
if (widthBytes * height > 0) {
picture = (unsigned char *) xalloc(widthBytes * height);
if (!picture) {
- bdfError("Couldn't allocate picture (%d*%d)\n", widthBytes, height);
+ bdfError("Couldn't allocate picture (%d*%d)\n", widthBytes, height);
goto BAILOUT;
- }
+ }
} else
picture = NULL;
pCI->bits = (char *) picture;
@@ -198,13 +194,11 @@ BAILOUT:
/***====================================================================***/
static Bool
-bdfSkipBitmap(file, height)
- FontFilePtr file;
- int height;
+bdfSkipBitmap(FontFilePtr file, int height)
{
unsigned char *line;
int i = 0;
- char lineBuf[BDFLINELEN];
+ unsigned char lineBuf[BDFLINELEN];
do {
line = bdfGetLine(file, lineBuf, BDFLINELEN);
@@ -221,16 +215,21 @@ bdfSkipBitmap(file, height)
/***====================================================================***/
static void
-bdfFreeFontBits(pFont)
- FontPtr pFont;
+bdfFreeFontBits(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
BitmapExtraPtr bitmapExtra;
- int i;
+ int i, nencoding;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;
xfree(bitmapFont->ink_metrics);
+ if(bitmapFont->encoding) {
+ nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+ (pFont->info.lastRow - pFont->info.firstRow + 1);
+ for(i=0; i<NUM_SEGMENTS(nencoding); i++)
+ xfree(bitmapFont->encoding[i]);
+ }
xfree(bitmapFont->encoding);
for (i = 0; i < bitmapFont->num_chars; i++)
xfree(bitmapFont->metrics[i].bits);
@@ -247,14 +246,8 @@ bdfFreeFontBits(pFont)
static Bool
-bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
- FontFilePtr file;
- FontPtr pFont;
- bdfFileState *pState;
- int bit,
- byte,
- glyph,
- scan;
+bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
+ int bit, int byte, int glyph, int scan)
{
unsigned char *line;
register CharInfoPtr ci;
@@ -268,7 +261,7 @@ bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
BitmapFontPtr bitmapFont;
BitmapExtraPtr bitmapExtra;
CARD32 *bitmapsSizes;
- char lineBuf[BDFLINELEN];
+ unsigned char lineBuf[BDFLINELEN];
int nencoding;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
@@ -352,7 +345,7 @@ bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
bdfError("bad 'ENCODING' in BDF file\n");
goto BAILOUT;
}
- if (enc < -1 || t == 2 && enc2 < -1) {
+ if (enc < -1 || (t == 2 && enc2 < -1)) {
bdfError("bad ENCODING value");
goto BAILOUT;
}
@@ -435,7 +428,7 @@ bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
(*p == ' ') || (*p == '\t');
p++)
/* empty for loop */ ;
- ci->metrics.attributes = bdfHexByte(p) << 8 + bdfHexByte(p + 2);
+ ci->metrics.attributes = (bdfHexByte(p) << 8) + bdfHexByte(p + 2);
line = bdfGetLine(file, lineBuf, BDFLINELEN);
} else
ci->metrics.attributes = 0;
@@ -489,11 +482,13 @@ bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
nencoding = (pFont->info.lastRow - pFont->info.firstRow + 1) *
(pFont->info.lastCol - pFont->info.firstCol + 1);
- bitmapFont->encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+ bitmapFont->encoding =
+ (CharInfoPtr **) xcalloc(NUM_SEGMENTS(nencoding),
+ sizeof(CharInfoPtr*));
if (!bitmapFont->encoding) {
bdfError("Couldn't allocate ppCI (%d,%d)\n",
- nencoding,
- sizeof(CharInfoPtr));
+ NUM_SEGMENTS(nencoding),
+ sizeof(CharInfoPtr*));
goto BAILOUT;
}
pFont->info.allExist = TRUE;
@@ -503,19 +498,26 @@ bdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)
char_row++) {
if (bdfEncoding[char_row] == (CharInfoPtr *) NULL) {
pFont->info.allExist = FALSE;
- for (char_col = pFont->info.firstCol;
- char_col <= pFont->info.lastCol;
- char_col++) {
- bitmapFont->encoding[i++] = NullCharInfo;
- }
+ i += pFont->info.lastCol - pFont->info.firstCol + 1;
} else {
for (char_col = pFont->info.firstCol;
char_col <= pFont->info.lastCol;
char_col++) {
if (!bdfEncoding[char_row][char_col])
pFont->info.allExist = FALSE;
- bitmapFont->encoding[i++] = bdfEncoding[char_row][char_col];
- }
+ else {
+ if (!bitmapFont->encoding[SEGMENT_MAJOR(i)]) {
+ bitmapFont->encoding[SEGMENT_MAJOR(i)]=
+ (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE,
+ sizeof(CharInfoPtr));
+ if (!bitmapFont->encoding[SEGMENT_MAJOR(i)])
+ goto BAILOUT;
+ }
+ ACCESSENCODINGL(bitmapFont->encoding,i) =
+ bdfEncoding[char_row][char_col];
+ }
+ i++;
+ }
}
}
for (i = 0; i < 256; i++)
@@ -533,13 +535,11 @@ BAILOUT:
/***====================================================================***/
static Bool
-bdfReadHeader(file, pState)
- FontFilePtr file;
- bdfFileState *pState;
+bdfReadHeader(FontFilePtr file, bdfFileState *pState)
{
unsigned char *line;
char namebuf[BDFLINELEN];
- char lineBuf[BDFLINELEN];
+ unsigned char lineBuf[BDFLINELEN];
line = bdfGetLine(file, lineBuf, BDFLINELEN);
if (!line || sscanf((char *) line, "STARTFONT %s", namebuf) != 1 ||
@@ -578,10 +578,7 @@ bdfReadHeader(file, pState)
/***====================================================================***/
static Bool
-bdfReadProperties(file, pFont, pState)
- FontFilePtr file;
- FontPtr pFont;
- bdfFileState *pState;
+bdfReadProperties(FontFilePtr file, FontPtr pFont, bdfFileState *pState)
{
int nProps, props_left,
nextProp;
@@ -591,7 +588,7 @@ bdfReadProperties(file, pFont, pState)
secondbuf[BDFLINELEN],
thirdbuf[BDFLINELEN];
unsigned char *line;
- char lineBuf[BDFLINELEN];
+ unsigned char lineBuf[BDFLINELEN];
BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
line = bdfGetLine(file, lineBuf, BDFLINELEN);
@@ -605,6 +602,7 @@ bdfReadProperties(file, pFont, pState)
}
pFont->info.isStringProp = NULL;
pFont->info.props = NULL;
+ pFont->info.nprops = 0;
stringProps = (char *) xalloc((nProps + BDF_GENPROPS) * sizeof(char));
pFont->info.isStringProp = stringProps;
@@ -647,7 +645,7 @@ bdfReadProperties(file, pFont, pState)
if (secondbuf[0] == '"') {
stringProps[nextProp] = TRUE;
props[nextProp].value =
- bdfGetPropertyValue(line + strlen(namebuf) + 1);
+ bdfGetPropertyValue((char *)line + strlen(namebuf) + 1);
if (!props[nextProp].value)
goto BAILOUT;
break;
@@ -668,7 +666,7 @@ bdfReadProperties(file, pFont, pState)
if (secondbuf[0] == '"') {
stringProps[nextProp] = TRUE;
props[nextProp].value =
- bdfGetPropertyValue(line + strlen(namebuf) + 1);
+ bdfGetPropertyValue((char *)line + strlen(namebuf) + 1);
if (!props[nextProp].value)
goto BAILOUT;
break;
@@ -776,22 +774,15 @@ BAILOUT:
/***====================================================================***/
static void
-bdfUnloadFont(pFont)
- FontPtr pFont;
+bdfUnloadFont(FontPtr pFont)
{
bdfFreeFontBits (pFont);
- xfree (pFont->devPrivates);
- xfree(pFont);
+ DestroyFontRec(pFont);
}
int
-bdfReadFont(pFont, file, bit, byte, glyph, scan)
- FontPtr pFont;
- FontFilePtr file;
- int bit,
- byte,
- glyph,
- scan;
+bdfReadFont(FontPtr pFont, FontFilePtr file,
+ int bit, int byte, int glyph, int scan)
{
bdfFileState state;
xCharInfo *min,
@@ -808,7 +799,7 @@ bdfReadFont(pFont, file, bit, byte, glyph, scan)
bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));
if (!bitmapFont) {
- bdfError("Couldn't allocate bitmapFontRec (%d)\n", sizeof(BitmapFontRec));
+ bdfError("Couldn't allocate bitmapFontRec (%d)\n", sizeof(BitmapFontRec));
goto BAILOUT;
}
bzero((char *)bitmapFont, sizeof(BitmapFontRec));
@@ -822,7 +813,7 @@ bdfReadFont(pFont, file, bit, byte, glyph, scan)
bitmapFont->bitmapExtra = (BitmapExtraPtr) xalloc(sizeof(BitmapExtraRec));
if (!bitmapFont->bitmapExtra) {
- bdfError("Couldn't allocate bitmapExtra (%d)\n", sizeof(BitmapExtraRec));
+ bdfError("Couldn't allocate bitmapExtra (%d)\n", sizeof(BitmapExtraRec));
goto BAILOUT;
}
bzero((char *)bitmapFont->bitmapExtra, sizeof(BitmapExtraRec));
@@ -846,7 +837,8 @@ bdfReadFont(pFont, file, bit, byte, glyph, scan)
cols = pFont->info.lastCol - pFont->info.firstCol + 1;
r = r - pFont->info.firstRow;
c = c - pFont->info.firstCol;
- bitmapFont->pDefault = bitmapFont->encoding[r * cols + c];
+ bitmapFont->pDefault = ACCESSENCODING(bitmapFont->encoding,
+ r * cols + c);
}
}
pFont->bit = bit;
@@ -864,11 +856,11 @@ bdfReadFont(pFont, file, bit, byte, glyph, scan)
if (bitmapFont->bitmapExtra)
FontComputeInfoAccelerators(&bitmapFont->bitmapExtra->info);
if (pFont->info.constantMetrics) {
- if (!bitmapAddInkMetrics(pFont)) {
- bdfError("Failed to add bitmap ink metrics\n");
- goto BAILOUT;
- }
- }
+ if (!bitmapAddInkMetrics(pFont)) {
+ bdfError("Failed to add bitmap ink metrics\n");
+ goto BAILOUT;
+ }
+ }
if (bitmapFont->bitmapExtra)
bitmapFont->bitmapExtra->info.inkMetrics = pFont->info.inkMetrics;
@@ -902,9 +894,7 @@ BAILOUT:
}
int
-bdfReadFontInfo(pFontInfo, file)
- FontInfoPtr pFontInfo;
- FontFilePtr file;
+bdfReadFontInfo(FontInfoPtr pFontInfo, FontFilePtr file)
{
FontRec font;
int ret;
@@ -923,8 +913,7 @@ bdfReadFontInfo(pFontInfo, file)
}
static Bool
-bdfPadToTerminal(pFont)
- FontPtr pFont;
+bdfPadToTerminal(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
BitmapExtraPtr bitmapExtra;
@@ -947,9 +936,9 @@ bdfPadToTerminal(pFont)
for (i = 0; i < bitmapFont->num_chars; i++) {
new.bits = (char *) xalloc(new_size);
if (!new.bits) {
- bdfError("Couldn't allocate bits (%d)\n", new_size);
+ bdfError("Couldn't allocate bits (%d)\n", new_size);
return FALSE;
- }
+ }
FontCharReshape(pFont, &bitmapFont->metrics[i], &new);
new.metrics.attributes = bitmapFont->metrics[i].metrics.attributes;
xfree(bitmapFont->metrics[i].bits);
diff --git a/src/bitmap/bdfutils.c b/src/bitmap/bdfutils.c
index d7e5b4c..94a9ff6 100644
--- a/src/bitmap/bdfutils.c
+++ b/src/bitmap/bdfutils.c
@@ -49,43 +49,30 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bdfutils.c,v 1.10 2001/12/14 19:56:45 dawes Exp $ */
+#ifndef FONTMODULE
#include <ctype.h>
-
#include <stdio.h>
+#include <stdarg.h>
+#endif
+
#include "fntfilst.h"
#include "fontstruct.h"
/* use bitmap structure */
#include "bitmap.h"
#include "bdfint.h"
-#if NeedVarargsPrototypes
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
int bdfFileLineNum;
/***====================================================================***/
-/* VARARGS1 */
void
-#if NeedVarargsPrototypes
bdfError(char* message, ...)
-#else
-bdfError (message, va_alist)
- char* message;
- va_dcl
-#endif
{
va_list args;
-#if NeedVarargsPrototypes
va_start (args, message);
-#else
- va_start (args);
-#endif
-
fprintf(stderr, "BDF Error on line %d: ", bdfFileLineNum);
vfprintf(stderr, message, args);
va_end (args);
@@ -93,19 +80,15 @@ bdfError (message, va_alist)
/***====================================================================***/
-/* VARARGS1 */
void
-bdfWarning(message, a0, a1, a2, a3, a4, a5)
- char *message;
- pointer a0,
- a1,
- a2,
- a3,
- a4,
- a5;
+bdfWarning(char *message, ...)
{
+ va_list args;
+
+ va_start (args, message);
fprintf(stderr, "BDF Warning on line %d: ", bdfFileLineNum);
- fprintf(stderr, message, a0, a1, a2, a3, a4, a5);
+ vfprintf(stderr, message, args);
+ va_end (args);
}
/*
@@ -114,10 +97,7 @@ bdfWarning(message, a0, a1, a2, a3, a4, a5)
*/
unsigned char *
-bdfGetLine(file, buf, len)
- FontFilePtr file;
- unsigned char *buf;
- int len;
+bdfGetLine(FontFilePtr file, unsigned char *buf, int len)
{
int c;
unsigned char *b;
@@ -147,19 +127,17 @@ bdfGetLine(file, buf, len)
/***====================================================================***/
Atom
-bdfForceMakeAtom(str, size)
- register char *str;
- register int *size;
+bdfForceMakeAtom(char *str, int *size)
{
register int len = strlen(str);
- extern Atom MakeAtom();
+ extern Atom MakeAtom(); /* Added this line to be consistent with X.org code */
Atom the_atom;
if (size != NULL)
*size += len + 1;
the_atom = MakeAtom(str, len, TRUE);
if (the_atom == None)
- bdfError("Atom allocation failed\n");
+ bdfError("Atom allocation failed\n");
return the_atom;
}
@@ -170,8 +148,7 @@ bdfForceMakeAtom(str, size)
*/
Atom
-bdfGetPropertyValue(s)
- char *s;
+bdfGetPropertyValue(char *s)
{
register char *p,
*pp;
@@ -198,8 +175,8 @@ bdfGetPropertyValue(s)
s++;
pp = p = (char *) xalloc((unsigned) strlen(s) + 1);
if (pp == NULL) {
- bdfError("Couldn't allocate property value string (%d)\n", strlen(s) + 1);
- return None;
+ bdfError("Couldn't allocate property value string (%d)\n", strlen(s) + 1);
+ return None;
}
while (*s) {
if (*s == '"') {
@@ -225,8 +202,7 @@ bdfGetPropertyValue(s)
* return TRUE if string is a valid integer
*/
int
-bdfIsInteger(str)
- char *str;
+bdfIsInteger(char *str)
{
char c;
@@ -234,7 +210,7 @@ bdfIsInteger(str)
if (!(isdigit(c) || c == '-' || c == '+'))
return (FALSE);
- while (c = *str++)
+ while ((c = *str++))
if (!isdigit(c))
return (FALSE);
@@ -248,8 +224,7 @@ bdfIsInteger(str)
*/
unsigned char
-bdfHexByte(s)
- char *s;
+bdfHexByte(unsigned char *s)
{
unsigned char b = 0;
register char c;
@@ -302,11 +277,8 @@ static char *SpecialAtoms[] = {
};
Bool
-bdfSpecialProperty(pFont, prop, isString, bdfState)
- FontPtr pFont;
- FontPropPtr prop;
- char isString;
- bdfFileState *bdfState;
+bdfSpecialProperty(FontPtr pFont, FontPropPtr prop,
+ char isString, bdfFileState *bdfState)
{
char **special;
char *name;
diff --git a/src/bitmap/bitmap.c b/src/bitmap/bitmap.c
index 39fd5dc..6fa7bfa 100644
--- a/src/bitmap/bitmap.c
+++ b/src/bitmap/bitmap.c
@@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bitmap.c,v 1.7 2001/12/14 19:56:45 dawes Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
@@ -33,19 +34,11 @@ in this Software without prior written authorization from The Open Group.
#include "fntfilst.h"
#include "bitmap.h"
-int bitmapGetGlyphs(), bitmapGetMetrics();
-int bitmapGetBitmaps(), bitmapGetExtents();
-void bitmapComputeFontBounds ();
-void bitmapComputeFontInkBounds ();
-
int
-bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
- FontPtr pFont;
- unsigned long count;
- register unsigned char *chars;
- FontEncoding charEncoding;
- unsigned long *glyphCount; /* RETURN */
- CharInfoPtr *glyphs; /* RETURN */
+bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars,
+ FontEncoding charEncoding,
+ unsigned long *glyphCount, /* RETURN */
+ CharInfoPtr *glyphs) /* RETURN */
{
BitmapFontPtr bitmapFont;
unsigned int firstCol;
@@ -56,7 +49,7 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
register unsigned int c;
register CharInfoPtr pci;
unsigned int r;
- CharInfoPtr *encoding;
+ CharInfoPtr **encoding;
CharInfoPtr pDefault;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
@@ -75,14 +68,14 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
while (count--) {
c = (*chars++) - firstCol;
if (c < numCols)
- *glyphs++ = encoding[c];
+ *glyphs++ = ACCESSENCODING(encoding,c);
else
*glyphs++ = pDefault;
}
} else {
while (count--) {
c = (*chars++) - firstCol;
- if (c < numCols && (pci = encoding[c]))
+ if (c < numCols && (pci = ACCESSENCODING(encoding,c)))
*glyphs++ = pci;
else if (pDefault)
*glyphs++ = pDefault;
@@ -95,7 +88,7 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
c = *chars++ << 8;
c = (c | *chars++) - firstCol;
if (c < numCols)
- *glyphs++ = encoding[c];
+ *glyphs++ = ACCESSENCODING(encoding,c);
else
*glyphs++ = pDefault;
}
@@ -103,7 +96,7 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
while (count--) {
c = *chars++ << 8;
c = (c | *chars++) - firstCol;
- if (c < numCols && (pci = encoding[c]))
+ if (c < numCols && (pci = ACCESSENCODING(encoding,c)))
*glyphs++ = pci;
else if (pDefault)
*glyphs++ = pDefault;
@@ -118,7 +111,7 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
r = (*chars++) - firstRow;
c = (*chars++) - firstCol;
if (r < numRows && c < numCols &&
- (pci = encoding[r * numCols + c]))
+ (pci = ACCESSENCODING(encoding, r * numCols + c)))
*glyphs++ = pci;
else if (pDefault)
*glyphs++ = pDefault;
@@ -132,13 +125,10 @@ bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
static CharInfoRec nonExistantChar;
int
-bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
- FontPtr pFont;
- unsigned long count;
- register unsigned char *chars;
- FontEncoding charEncoding;
- unsigned long *glyphCount; /* RETURN */
- xCharInfo **glyphs; /* RETURN */
+bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars,
+ FontEncoding charEncoding,
+ unsigned long *glyphCount, /* RETURN */
+ xCharInfo **glyphs) /* RETURN */
{
int ret;
xCharInfo *ink_metrics;
diff --git a/src/bitmap/bitmapfunc.c b/src/bitmap/bitmapfunc.c
index c52c7e8..da06e7d 100644
--- a/src/bitmap/bitmapfunc.c
+++ b/src/bitmap/bitmapfunc.c
@@ -26,54 +26,65 @@ in this Software without prior written authorization from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bitmapfunc.c,v 3.18 2002/09/24 20:48:52 tsi Exp $ */
+
/*
* Author: Keith Packard, MIT X Consortium
*/
#include "fntfilst.h"
#include "bitmap.h"
+#include "fontutil.h"
+#include "bdfint.h"
+#include "pcf.h"
+#include "snfstr.h"
typedef struct _BitmapFileFunctions {
- int (*ReadFont) ( /* pFont, file, bit, byte, glyph, scan */ );
- int (*ReadInfo) ( /* pFontInfo, file */ );
+ int (*ReadFont) (FontPtr /* pFont */, FontFilePtr /* file */,
+ int /* bit */, int /* byte */,
+ int /* glyph */, int /* scan */);
+ int (*ReadInfo) ( FontInfoPtr /* pFontInfo */,
+ FontFilePtr /* file */ );
} BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
-extern int pcfReadFont(), pcfReadFontInfo();
-extern int snfReadFont(), snfReadFontInfo();
-extern int bdfReadFont(), bdfReadFontInfo();
-extern int pmfReadFont();
-int BitmapOpenBitmap ();
-extern int BitmapOpenScalable ();
-int BitmapGetInfoBitmap ();
-extern int BitmapGetInfoScalable ();
-int BitmapGetRenderIndex ();
/*
- * these two arrays must be in the same order
+ * the readers[] and renderers[] arrays must be in the same order,
+ * and also in the same order as scale[] and find_scale[] in bitscale.c
+ *
*/
static BitmapFileFunctionsRec readers[] = {
+#ifdef PCFFORMAT
{ pcfReadFont, pcfReadFontInfo} ,
{ pcfReadFont, pcfReadFontInfo} ,
#ifdef X_GZIP_FONT_COMPRESSION
{ pcfReadFont, pcfReadFontInfo} ,
#endif
- { snfReadFont, snfReadFontInfo} ,
- { snfReadFont, snfReadFontInfo} ,
+#endif
+#ifdef SNFFORMAT
+ { snfReadFont, snfReadFontInfo},
+ { snfReadFont, snfReadFontInfo},
#ifdef X_GZIP_FONT_COMPRESSION
{ snfReadFont, snfReadFontInfo} ,
#endif
+#endif
+#ifdef BDFFORMAT
{ bdfReadFont, bdfReadFontInfo} ,
{ bdfReadFont, bdfReadFontInfo} ,
#ifdef X_GZIP_FONT_COMPRESSION
{ bdfReadFont, bdfReadFontInfo} ,
#endif
+#endif
+#ifdef PCFFORMAT
{ pmfReadFont, pcfReadFontInfo} ,
+#endif
};
#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
static FontRendererRec renderers[] = {
+#ifdef PCFFORMAT
{ ".pcf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
@@ -81,10 +92,13 @@ static FontRendererRec renderers[] = {
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#ifdef X_GZIP_FONT_COMPRESSION
- { ".pcf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable,
+ { ".pcf.gz", 7,
+ BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
+#endif
+#ifdef SNFFORMAT
{ ".snf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
@@ -96,6 +110,8 @@ static FontRendererRec renderers[] = {
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
+#endif
+#ifdef BDFFORMAT
{ ".bdf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
@@ -107,21 +123,19 @@ static FontRendererRec renderers[] = {
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
+#endif
+#ifdef PCFFORMAT
{ ".pmf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES }
+#endif
};
-int BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask,
- non_cachable_font)
- FontPathElementPtr fpe;
- FontPtr *ppFont;
- int flags;
- FontEntryPtr entry;
- char *fileName;
- fsBitmapFormat format;
- fsBitmapFormatMask fmask;
- FontPtr non_cachable_font; /* We don't do licensing */
+int
+BitmapOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags,
+ FontEntryPtr entry, char *fileName,
+ fsBitmapFormat format, fsBitmapFormatMask fmask,
+ FontPtr non_cachable_font) /* We don't do licensing */
{
FontFilePtr file;
FontPtr pFont;
@@ -137,13 +151,12 @@ int BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask,
file = FontFileOpen (fileName);
if (!file)
return BadFontName;
- pFont = (FontPtr) xalloc(sizeof(FontRec));
- if (!pFont) {
- fprintf(stderr, "Error: Couldn't allocate pFont (%d)\n", sizeof(FontRec));
+ if (!(pFont = CreateFontRec())) {
+ fprintf(stderr, "Error: Couldn't allocate pFont (%ld)\n",
+ (unsigned long)sizeof(FontRec));
FontFileClose (file);
return AllocError;
}
- bzero((char *)pFont, sizeof(FontRec));
/* set up default values */
FontDefaultFormat(&bit, &byte, &glyph, &scan);
/* get any changes made from above */
@@ -151,24 +164,21 @@ int BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask,
/* Fill in font record. Data format filled in by reader. */
pFont->refcnt = 0;
- pFont->maxPrivate = -1;
- pFont->devPrivates = (pointer *) 0;
ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
FontFileClose (file);
- if (ret != Successful)
+ if (ret != Successful) {
xfree(pFont);
- else
+ } else {
*ppFont = pFont;
+ }
return ret;
}
-int BitmapGetInfoBitmap (fpe, pFontInfo, entry, fileName)
- FontPathElementPtr fpe;
- FontInfoPtr pFontInfo;
- FontEntryPtr entry;
- char *fileName;
+int
+BitmapGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
+ FontEntryPtr entry, char *fileName)
{
FontFilePtr file;
int i;
@@ -189,7 +199,8 @@ int BitmapGetInfoBitmap (fpe, pFontInfo, entry, fileName)
#define numRenderers (sizeof renderers / sizeof renderers[0])
-void BitmapRegisterFontFileFunctions ()
+void
+BitmapRegisterFontFileFunctions (void)
{
int i;
@@ -202,8 +213,8 @@ void BitmapRegisterFontFileFunctions ()
* the font info reader, and the bitmap scaling routine. All users
* of this routine must be kept in step with the renderer array.
*/
-int BitmapGetRenderIndex(renderer)
- FontRendererPtr renderer;
+int
+BitmapGetRenderIndex(FontRendererPtr renderer)
{
return renderer - renderers;
}
diff --git a/src/bitmap/bitmaputil.c b/src/bitmap/bitmaputil.c
index 337ae13..d061fcd 100644
--- a/src/bitmap/bitmaputil.c
+++ b/src/bitmap/bitmaputil.c
@@ -27,9 +27,11 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bitmaputil.c,v 1.11 2003/02/19 01:22:34 dawes Exp $ */
#include "fntfilst.h"
#include "bitmap.h"
+#include "bdfint.h"
#ifndef MAXSHORT
#define MAXSHORT 32767
@@ -51,8 +53,8 @@ MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
maxbounds->field = (ci)->field;
#define COMPUTE_MINMAX(ci) \
- if ((ci)->ascent != -(ci)->descent || \
- (ci)->leftSideBearing != (ci)->rightSideBearing || \
+ if ((ci)->ascent || (ci)->descent || \
+ (ci)->leftSideBearing || (ci)->rightSideBearing || \
(ci)->characterWidth) \
{ \
MINMAX(ascent, (ci)); \
@@ -63,15 +65,13 @@ MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
}
void
-bitmapComputeFontBounds(pFont)
- FontPtr pFont;
+bitmapComputeFontBounds(FontPtr pFont)
{
BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
int nchars;
int r,
c;
- CharInfoPtr ci,
- *pci;
+ CharInfoPtr ci;
int maxOverlap;
int overlap;
xCharInfo *minbounds,
@@ -112,11 +112,11 @@ bitmapComputeFontBounds(pFont)
maxbounds = &pFont->info.maxbounds;
*minbounds = initMinMetrics;
*maxbounds = initMaxMetrics;
- pci = bitmapFont->encoding;
+ i = 0;
maxOverlap = MINSHORT;
for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
- ci = *pci++;
+ ci = ACCESSENCODING(bitmapFont->encoding, i);
if (ci) {
COMPUTE_MINMAX(&ci->metrics);
if (ci->metrics.characterWidth < 0)
@@ -130,6 +130,7 @@ bitmapComputeFontBounds(pFont)
if (maxOverlap < overlap)
maxOverlap = overlap;
}
+ i++;
}
}
}
@@ -141,15 +142,13 @@ bitmapComputeFontBounds(pFont)
}
void
-bitmapComputeFontInkBounds(pFont)
- FontPtr pFont;
+bitmapComputeFontInkBounds(FontPtr pFont)
{
BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
int nchars;
int r,
c;
- CharInfoPtr *pci,
- cit;
+ CharInfoPtr cit;
xCharInfo *ci;
int offset;
xCharInfo *minbounds,
@@ -184,10 +183,10 @@ bitmapComputeFontInkBounds(pFont)
maxbounds = &pFont->info.ink_maxbounds;
*minbounds = initMinMetrics;
*maxbounds = initMaxMetrics;
- pci = bitmapFont->encoding;
+ i=0;
for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
- cit = *pci++;
+ cit = ACCESSENCODING(bitmapFont->encoding, i);
if (cit) {
offset = cit - bitmapFont->metrics;
ci = &bitmapFont->ink_metrics[offset];
@@ -195,6 +194,7 @@ bitmapComputeFontInkBounds(pFont)
minbounds->attributes &= ci->attributes;
maxbounds->attributes |= ci->attributes;
}
+ i++;
}
}
}
@@ -202,8 +202,7 @@ bitmapComputeFontInkBounds(pFont)
}
Bool
-bitmapAddInkMetrics(pFont)
- FontPtr pFont;
+bitmapAddInkMetrics(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
int i;
@@ -211,7 +210,8 @@ bitmapAddInkMetrics(pFont)
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
bitmapFont->ink_metrics = (xCharInfo *) xalloc(bitmapFont->num_chars * sizeof(xCharInfo));
if (!bitmapFont->ink_metrics) {
- fprintf(stderr, "Error: Couldn't allocate ink_metrics (%d*%d)\n", bitmapFont->num_chars, sizeof(xCharInfo));
+ fprintf(stderr, "Error: Couldn't allocate ink_metrics (%d*%ld)\n",
+ bitmapFont->num_chars, (unsigned long)sizeof(xCharInfo));
return FALSE;
}
for (i = 0; i < bitmapFont->num_chars; i++)
@@ -222,8 +222,7 @@ bitmapAddInkMetrics(pFont)
/* ARGSUSED */
int
-bitmapComputeWeight(pFont)
- FontPtr pFont;
+bitmapComputeWeight(FontPtr pFont)
{
return 10;
}
diff --git a/src/bitmap/bitscale.c b/src/bitmap/bitscale.c
index 5f8ef80..287bd5c 100644
--- a/src/bitmap/bitscale.c
+++ b/src/bitmap/bitscale.c
@@ -1,5 +1,4 @@
/* $Xorg: bitscale.c,v 1.5 2001/02/09 02:04:02 xorgcvs Exp $ */
-
/*
Copyright 1991, 1994, 1998 The Open Group
@@ -27,6 +26,7 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/bitscale.c,v 3.29 2003/01/12 03:55:46 tsi Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
@@ -34,6 +34,8 @@ from The Open Group.
#include "fntfilst.h"
#include "bitmap.h"
+#include "fontutil.h"
+#ifndef FONTMODULE
#ifdef _XOPEN_SOURCE
#include <math.h>
#else
@@ -41,14 +43,25 @@ from The Open Group.
#include <math.h>
#undef _XOPEN_SOURCE
#endif
+#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b)) ? a : b)
#endif
-extern Atom MakeAtom();
+/* Should get this from elsewhere */
+extern unsigned long serverGeneration;
-void bitmapUnloadScalable();
+static void bitmapUnloadScalable (FontPtr pFont);
+static void ScaleBitmap ( FontPtr pFont, CharInfoPtr opci,
+ CharInfoPtr pci, double *inv_xform,
+ double widthMult, double heightMult );
+static FontPtr BitmapScaleBitmaps(FontPtr pf, FontPtr opf,
+ double widthMult, double heightMult,
+ FontScalablePtr vals);
+static FontPtr PrinterScaleBitmaps(FontPtr pf, FontPtr opf,
+ double widthMult, double heightMult,
+ FontScalablePtr vals);
enum scaleType {
atom, truncate_atom, pixel_size, point_size, resolution_x,
@@ -63,38 +76,84 @@ typedef struct _fontProp {
enum scaleType type;
} fontProp;
-static FontPtr BitmapScaleBitmaps();
-static FontPtr PrinterScaleBitmaps();
+typedef FontPtr (*ScaleFunc) ( FontPtr /* pf */,
+ FontPtr /* opf */,
+ double /* widthMult */,
+ double /* heightMult */,
+ FontScalablePtr /* vals */);
-typedef FontPtr (*ScaleFunc) ();
/* These next two arrays must be kept in step with the renderer array */
ScaleFunc scale[] =
{
+#ifdef PCFFORMAT
+ BitmapScaleBitmaps,
+ BitmapScaleBitmaps,
+#ifdef X_GZIP_FONT_COMPRESSION
BitmapScaleBitmaps,
+#endif
+#endif
+#ifdef SNFFORMAT
BitmapScaleBitmaps,
BitmapScaleBitmaps,
+#ifdef X_GZIP_FONT_COMPRESSION
+ BitmapScaleBitmaps,
+#endif
+#endif
+#ifdef BDFFORMAT
BitmapScaleBitmaps,
BitmapScaleBitmaps,
+#ifdef X_GZIP_FONT_COMPRESSION
BitmapScaleBitmaps,
+#endif
+#endif
+#ifdef PCFFORMAT
PrinterScaleBitmaps,
+#endif
};
-
-static FontEntryPtr FindBestToScale();
-static FontEntryPtr FindPmfToScale();
-
-typedef FontEntryPtr (*FindToScale) ();
+
+static FontEntryPtr FindBestToScale ( FontPathElementPtr fpe,
+ FontEntryPtr entry,
+ FontScalablePtr vals,
+ FontScalablePtr best,
+ double *dxp, double *dyp,
+ double *sdxp, double *sdyp,
+ FontPathElementPtr *fpep );
+static FontEntryPtr FindPmfToScale ( FontPathElementPtr fpe,
+ FontEntryPtr entry,
+ FontScalablePtr vals,
+ FontScalablePtr best,
+ double *dxp, double *dyp,
+ double *sdxp, double *sdyp,
+ FontPathElementPtr *fpep );
+
+typedef FontEntryPtr (*FindToScale) (FontPathElementPtr fpe,
+ FontEntryPtr entry,
+ FontScalablePtr vals,
+ FontScalablePtr best,
+ double *dxp, double *dyp,
+ double *sdxp, double *sdyp,
+ FontPathElementPtr *fpep);
FindToScale find_scale[] =
{
FindBestToScale,
FindBestToScale,
+#ifdef X_GZIP_FONT_COMPRESSION
+ FindBestToScale,
+#endif
+ FindBestToScale,
+ FindBestToScale,
+#ifdef X_GZIP_FONT_COMPRESSION
FindBestToScale,
+#endif
FindBestToScale,
FindBestToScale,
+#ifdef X_GZIP_FONT_COMPRESSION
FindBestToScale,
+#endif
FindPmfToScale,
};
-static unsigned long fontGeneration = 0; /* initialization flag */
+static unsigned long bitscaleGeneration = 0; /* initialization flag */
static fontProp fontNamePropTable[] = {
{ "FOUNDRY", 0, atom },
@@ -194,7 +253,7 @@ static fontProp rawFontPropTable[] = {
};
static void
-initFontPropTable()
+initFontPropTable(void)
{
int i;
fontProp *t;
@@ -212,39 +271,34 @@ initFontPropTable()
t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
}
+#if 0
static FontEntryPtr
-GetScalableEntry (fpe, name)
- FontPathElementPtr fpe;
- FontNamePtr name;
+GetScalableEntry (FontPathElementPtr fpe, FontNamePtr name)
{
FontDirectoryPtr dir;
dir = (FontDirectoryPtr) fpe->private;
return FontFileFindNameInDir (&dir->scalable, name);
}
+#endif
static double
-get_matrix_horizontal_component(matrix)
- double *matrix;
+get_matrix_horizontal_component(double *matrix)
{
return hypot(matrix[0], matrix[1]);
}
static double
-get_matrix_vertical_component(matrix)
- double *matrix;
+get_matrix_vertical_component(double *matrix)
{
return hypot(matrix[2], matrix[3]);
}
static Bool
-ComputeScaleFactors(from, to, dx, dy, sdx, sdy, rescale_x)
- FontScalablePtr from,
- to;
- double *dx, *sdx,
- *dy, *sdy,
- *rescale_x;
+ComputeScaleFactors(FontScalablePtr from, FontScalablePtr to,
+ double *dx, double *dy, double *sdx, double *sdy,
+ double *rescale_x)
{
double srcpixelset, destpixelset, srcpixel, destpixel;
@@ -315,40 +369,37 @@ if (m >= 1.0) { \
else if (m == 2.0) \
score += (4 * s); \
else \
- score += (3 * s) / m; \
+ score += (int)(((double)(3 * s)) / m); \
} else { \
- score += (2 * s) * m; \
+ score += (int)(((double)(2 * s)) * m); \
}
/* don't need to favor enlargement when looking for bitmap that can
be used unscalable */
#define SCORE2(m,s) \
if (m >= 1.0) \
- score += (8 * s) / m; \
+ score += (int)(((double)(8 * s)) / m); \
else \
- score += (8 * s) * m;
+ score += (int)(((double)(8 * s)) * m);
static FontEntryPtr
-FindBestToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
- FontPathElementPtr fpe;
- FontEntryPtr entry;
- FontScalablePtr vals,
- best;
- double *dxp, *sdxp,
- *dyp, *sdyp;
- FontPathElementPtr *fpep;
+FindBestToScale(FontPathElementPtr fpe, FontEntryPtr entry,
+ FontScalablePtr vals, FontScalablePtr best,
+ double *dxp, double *dyp,
+ double *sdxp, double *sdyp,
+ FontPathElementPtr *fpep)
{
FontScalableRec temp;
int source, i;
int best_score, best_unscaled_score,
score;
- double dx, sdx, dx_amount,
- dy, sdy, dy_amount,
- best_dx, best_sdx, best_dx_amount,
- best_dy, best_sdy, best_dy_amount,
- best_unscaled_sdx, best_unscaled_sdy,
- rescale_x, best_rescale_x,
- best_unscaled_rescale_x;
+ double dx = 0.0, sdx = 0.0, dx_amount = 0.0,
+ dy = 0.0, sdy = 0.0, dy_amount = 0.0,
+ best_dx = 0.0, best_sdx = 0.0, best_dx_amount = 0.0,
+ best_dy = 0.0, best_sdy = 0.0, best_dy_amount = 0.0,
+ best_unscaled_sdx = 0.0, best_unscaled_sdy = 0.0,
+ rescale_x = 0.0, best_rescale_x = 0.0,
+ best_unscaled_rescale_x = 0.0;
FontEntryPtr zero;
FontNameRec zeroName;
char zeroChars[MAXFONTNAMELEN];
@@ -356,14 +407,15 @@ FindBestToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
FontScaledPtr scaled;
FontScalableExtraPtr extra;
FontScaledPtr best_scaled, best_unscaled;
- FontPathElementPtr best_fpe, best_unscaled_fpe;
+ FontPathElementPtr best_fpe = NULL, best_unscaled_fpe = NULL;
FontEntryPtr bitmap = NULL;
FontEntryPtr result;
int aliascount = 20;
- FontPathElementPtr bitmap_fpe;
+ FontPathElementPtr bitmap_fpe = NULL;
FontNameRec xlfdName;
/* find the best match */
+ rescale_x = 1.0;
best_scaled = 0;
best_score = 0;
best_unscaled = 0;
@@ -542,14 +594,11 @@ FindBestToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
}
static FontEntryPtr
-FindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
- FontPathElementPtr fpe;
- FontEntryPtr entry;
- FontScalablePtr vals,
- best;
- double *dxp, *sdxp,
- *dyp, *sdyp;
- FontPathElementPtr *fpep;
+FindPmfToScale(FontPathElementPtr fpe, FontEntryPtr entry,
+ FontScalablePtr vals, FontScalablePtr best,
+ double *dxp, double *dyp,
+ double *sdxp, double *sdyp,
+ FontPathElementPtr *fpep)
{
FontEntryPtr result = NULL;
FontScaledPtr scaled;
@@ -576,7 +625,7 @@ FindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
the matrix appropriately */
vals->pixel_matrix[0] *= rescale_x;
vals->pixel_matrix[1] *= rescale_x;
- #ifdef NOTDEF
+#ifdef NOTDEF
/* This would force the pointsize and pixelsize fields in the
FONT property to display as matrices to more accurately
report the font being supplied. It might also break existing
@@ -584,9 +633,9 @@ FindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
vals->values_supplied =
vals->values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK) |
PIXELSIZE_ARRAY;
- #else /* NOTDEF */
+#else /* NOTDEF */
vals->values_supplied = vals->values_supplied & ~POINTSIZE_MASK;
- #endif /* NOTDEF */
+#endif /* NOTDEF */
/* Recompute and reround the FontScalablePtr values after
rescaling for the new width. */
FontFileCompleteXLFD(vals, vals);
@@ -597,27 +646,21 @@ FindPmfToScale(fpe, entry, vals, best, dxp, dyp, sdxp, sdyp, fpep)
}
static long
-doround(x)
-double x;
+doround(double x)
{
return (x >= 0) ? (long)(x + .5) : (long)(x - .5);
}
static int
-computeProps(pf, wasStringProp, npf, isStringProp, nprops, xfactor, yfactor,
- sXfactor, sYfactor)
- FontPropPtr pf;
- char *wasStringProp;
- FontPropPtr npf;
- char *isStringProp;
- unsigned int nprops;
- double xfactor, sXfactor,
- yfactor, sYfactor;
+computeProps(FontPropPtr pf, char *wasStringProp,
+ FontPropPtr npf, char *isStringProp,
+ unsigned int nprops, double xfactor, double yfactor,
+ double sXfactor, double sYfactor)
{
int n;
int count;
fontProp *t;
- double rawfactor;
+ double rawfactor = 0.0;
for (count = 0; nprops > 0; nprops--, pf++, wasStringProp++) {
n = sizeof(fontPropTable) / sizeof(fontProp);
@@ -641,6 +684,8 @@ computeProps(pf, wasStringProp, npf, isStringProp, nprops, xfactor, yfactor,
count++;
*isStringProp++ = *wasStringProp;
break;
+ default:
+ break;
}
if (t->type != unscaled)
{
@@ -660,44 +705,43 @@ computeProps(pf, wasStringProp, npf, isStringProp, nprops, xfactor, yfactor,
static int
-ComputeScaledProperties(sourceFontInfo, name, vals, dx, dy, sdx, sdy,
- sWidth, pProps, pIsStringProp)
- FontInfoPtr sourceFontInfo; /* the font to be scaled */
- char *name; /* name of resulting font */
- FontScalablePtr vals;
- double dx, sdx,
- dy, sdy; /* scale factors in x and y directions */
- long sWidth; /* 1000-pixel average width */
- FontPropPtr *pProps; /* returns properties; preallocated */
- char **pIsStringProp; /* return booleans; preallocated */
+ComputeScaledProperties(FontInfoPtr sourceFontInfo, /* the font to be scaled */
+ char *name, /* name of resulting font */
+ FontScalablePtr vals,
+ double dx, double dy, /* scale factors in x and y */
+ double sdx, double sdy, /* directions */
+ long sWidth, /* 1000-pixel average width */
+ FontPropPtr *pProps, /* returns properties;
+ preallocated */
+ char **pIsStringProp) /* return booleans;
+ preallocated */
{
int n;
- char *ptr1,
- *ptr2;
+ char *ptr1 = NULL, *ptr2 = NULL;
char *ptr3;
FontPropPtr fp;
fontProp *fpt;
- extern int serverGeneration;
char *isStringProp;
int nProps;
- if (fontGeneration != serverGeneration) {
+ if (bitscaleGeneration != serverGeneration) {
initFontPropTable();
- fontGeneration = serverGeneration;
+ bitscaleGeneration = serverGeneration;
}
nProps = NPROPS + 1 + sizeof(fontPropTable) / sizeof(fontProp) +
sizeof(rawFontPropTable) / sizeof(fontProp);
fp = (FontPropPtr) xalloc(sizeof(FontPropRec) * nProps);
*pProps = fp;
if (!fp) {
- fprintf(stderr, "Error: Couldn't allocate font properties (%d*%d)\n", sizeof(FontPropRec), nProps);
+ fprintf(stderr, "Error: Couldn't allocate font properties (%ld*%d)\n",
+ (unsigned long)sizeof(FontPropRec), nProps);
return 1;
}
isStringProp = (char *) xalloc (nProps);
*pIsStringProp = isStringProp;
if (!isStringProp)
{
- fprintf(stderr, "Error: Couldn't allocate isStringProp (%d)\n", nProps);
+ fprintf(stderr, "Error: Couldn't allocate isStringProp (%d)\n", nProps);
xfree (fp);
return 1;
}
@@ -761,6 +805,8 @@ ComputeScaledProperties(sourceFontInfo, name, vals, dx, dy, sdx, sdy,
case raw_average_width:
fp->value = sWidth;
break;
+ default:
+ break;
}
fp->name = fpt->atom;
}
@@ -771,13 +817,11 @@ ComputeScaledProperties(sourceFontInfo, name, vals, dx, dy, sdx, sdy,
return n;
}
-static void ScaleBitmap();
static int
-compute_xform_matrix(vals, dx, dy, xform, inv_xform, xmult, ymult)
- FontScalablePtr vals;
- double dx, dy, *inv_xform, *xmult, *ymult;
- register double *xform;
+compute_xform_matrix(FontScalablePtr vals, double dx, double dy,
+ double *xform, double *inv_xform,
+ double *xmult, double *ymult)
{
double det;
double pixel = get_matrix_vertical_component(vals->pixel_matrix);
@@ -835,19 +879,17 @@ compute_xform_matrix(vals, dx, dy, xform, inv_xform, xmult, ymult)
* returns a pointer to the new scaled font, or NULL (due to AllocError).
*/
static FontPtr
-ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
- newWidthMult, newHeightMult, sWidth)
- FontPtr opf; /* originating font */
- double widthMult; /* glyphs width scale factor */
- double heightMult; /* glyphs height scale factor */
- double sWidthMult; /* scalable glyphs width scale factor */
- double sHeightMult; /* scalable glyphs height scale factor */
- FontScalablePtr vals;
- double *newWidthMult; /* return: X component of glyphs width
- scale factor */
- double *newHeightMult; /* return: Y component of glyphs height
- scale factor */
- long *sWidth; /* return: average 1000-pixel width */
+ScaleFont(FontPtr opf, /* originating font */
+ double widthMult, /* glyphs width scale factor */
+ double heightMult, /* glyphs height scale factor */
+ double sWidthMult, /* scalable glyphs width scale factor */
+ double sHeightMult, /* scalable glyphs height scale factor */
+ FontScalablePtr vals,
+ double *newWidthMult, /* return: X component of glyphs width
+ scale factor */
+ double *newHeightMult, /* return: Y component of glyphs height
+ scale factor */
+ long *sWidth) /* return: average 1000-pixel width */
{
FontPtr pf;
FontInfoPtr pfi,
@@ -856,7 +898,7 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
obitmapFont;
CharInfoPtr pci,
opci;
- int nchars; /* how many characters in the font */
+ int nchars = 0; /* how many characters in the font */
int i;
int glyph;
int firstCol, lastCol, firstRow, lastRow;
@@ -870,11 +912,6 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
(i)%(lastCol - firstCol + 1) + \
firstCol - opf->info.firstCol)
- extern int bitmapGetBitmaps();
- extern int bitmapGetExtents();
- extern int bitmapGetGlyphs();
- extern int bitmapGetMetrics();
-
*sWidth = 0;
opfi = &opf->info;
@@ -882,14 +919,12 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
obitmapFont = (BitmapFontPtr) opf->fontPrivate;
bitmapFont = 0;
- pf = (FontPtr) xalloc(sizeof(FontRec));
- if (!pf) {
- fprintf(stderr, "Error: Couldn't allocate FontRec (%d)\n", sizeof(FontRec));
+ if (!(pf = CreateFontRec())) {
+ fprintf(stderr, "Error: Couldn't allocate FontRec (%ld)\n",
+ (unsigned long)sizeof(FontRec));
goto bail;
}
pf->refcnt = 0;
- pf->maxPrivate = -1;
- pf->devPrivates = (pointer *) 0;
pf->bit = opf->bit;
pf->byte = opf->byte;
pf->glyph = opf->glyph;
@@ -953,7 +988,8 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));
if (!bitmapFont) {
- fprintf(stderr, "Error: Couldn't allocate bitmapFont (%d)\n", sizeof(BitmapFontRec));
+ fprintf(stderr, "Error: Couldn't allocate bitmapFont (%ld)\n",
+ (unsigned long)sizeof(BitmapFontRec));
goto bail;
}
nchars = (lastRow - firstRow + 1) * (lastCol - firstCol + 1);
@@ -973,12 +1009,16 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
bitmapFont->pDefault = 0;
bitmapFont->metrics = (CharInfoPtr) xalloc(nchars * sizeof(CharInfoRec));
if (!bitmapFont->metrics) {
- fprintf(stderr, "Error: Couldn't allocate metrics (%d*%d)\n", nchars, sizeof(CharInfoRec));
+ fprintf(stderr, "Error: Couldn't allocate metrics (%d*%ld)\n",
+ nchars, (unsigned long)sizeof(CharInfoRec));
goto bail;
}
- bitmapFont->encoding = (CharInfoPtr *) xalloc(nchars * sizeof(CharInfoPtr));
+ bitmapFont->encoding =
+ (CharInfoPtr **) xcalloc(NUM_SEGMENTS(nchars),
+ sizeof(CharInfoPtr*));
if (!bitmapFont->encoding) {
- fprintf(stderr, "Error: Couldn't allocate encoding (%d*%d)\n", nchars, sizeof(CharInfoPtr));
+ fprintf(stderr, "Error: Couldn't allocate encoding (%d*%ld)\n",
+ nchars, (unsigned long)sizeof(CharInfoPtr));
goto bail;
}
@@ -1020,7 +1060,8 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
pci = bitmapFont->metrics;
for (i = 0; i < nchars; i++)
{
- if ((opci = obitmapFont->encoding[inkindex2 = OLDINDEX(i)]))
+ inkindex2 = OLDINDEX(i);
+ if ((opci = ACCESSENCODING(obitmapFont->encoding,OLDINDEX(i))))
{
double newlsb, newrsb, newdesc, newasc, point[2];
@@ -1039,7 +1080,6 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
break;
if (j == vals->nranges)
{
- bitmapFont->encoding[i] = 0;
continue;
}
}
@@ -1050,11 +1090,17 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
opci->metrics.descent == 0 &&
opci->metrics.characterWidth == 0)
{
- bitmapFont->encoding[i] = 0;
continue;
}
- bitmapFont->encoding[i] = pci;
+ if(!bitmapFont->encoding[SEGMENT_MAJOR(i)]) {
+ bitmapFont->encoding[SEGMENT_MAJOR(i)]=
+ (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE,
+ sizeof(CharInfoPtr));
+ if(!bitmapFont->encoding[SEGMENT_MAJOR(i)])
+ goto bail;
+ }
+ ACCESSENCODINGL(bitmapFont->encoding, i) = pci;
/* Compute new extents for this glyph */
TRANSFORM_POINT(xform,
@@ -1107,8 +1153,6 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
pci++;
}
- else
- bitmapFont->encoding[i] = 0;
}
@@ -1120,10 +1164,9 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
pci = bitmapFont->metrics;
for (i = 0; i < nchars; i++)
{
- if ((pci = bitmapFont->encoding[i]) &&
- (opci = obitmapFont->encoding[OLDINDEX(i)]))
+ if ((pci = ACCESSENCODING(bitmapFont->encoding,i)) &&
+ (opci = ACCESSENCODING(obitmapFont->encoding,OLDINDEX(i))))
{
- pci = bitmapFont->encoding[i];
totalchars++;
*sWidth += abs((int)(INT16)pci->metrics.attributes);
#define MINMAX(field) \
@@ -1185,7 +1228,8 @@ ScaleFont(opf, widthMult, heightMult, sWidthMult, sHeightMult, vals,
cols = pfi->lastCol - pfi->firstCol + 1;
r = r - pfi->firstRow;
c = c - pfi->firstCol;
- bitmapFont->pDefault = bitmapFont->encoding[r * cols + c];
+ bitmapFont->pDefault =
+ ACCESSENCODING(bitmapFont->encoding, r * cols + c);
}
}
@@ -1199,19 +1243,17 @@ bail:
xfree(bitmapFont->metrics);
xfree(bitmapFont->ink_metrics);
xfree(bitmapFont->bitmaps);
+ if(bitmapFont->encoding)
+ for(i=0; i<NUM_SEGMENTS(nchars); i++)
+ xfree(bitmapFont->encoding[i]);
xfree(bitmapFont->encoding);
}
return NULL;
}
static void
-ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
- FontPtr pFont;
- CharInfoPtr opci;
- CharInfoPtr pci;
- double *inv_xform;
- double widthMult;
- double heightMult;
+ScaleBitmap(FontPtr pFont, CharInfoPtr opci, CharInfoPtr pci,
+ double *inv_xform, double widthMult, double heightMult)
{
register char *bitmap, /* The bits */
*newBitmap;
@@ -1229,8 +1271,9 @@ ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
yValue;
double point[2];
unsigned char *char_grayscale = 0;
- INT32 *diffusion_workspace, *thisrow, *nextrow, pixmult;
- int box_x, box_y;
+ INT32 *diffusion_workspace = NULL, *thisrow = NULL,
+ *nextrow = NULL, pixmult = 0;
+ int box_x = 0, box_y = 0;
static unsigned char masklsb[] =
{ 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
@@ -1292,7 +1335,9 @@ ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
(INT32 *)xalloc((newWidth + 2) * 2 * sizeof(int));
if (!diffusion_workspace)
{
- fprintf(stderr, "Warning: Couldn't allocate diffusion workspace (%d)\n", (newWidth + 2) * 2 * sizeof(int));
+ fprintf(stderr, "Warning: Couldn't allocate diffusion"
+ " workspace (%ld)\n",
+ (newWidth + 2) * 2 * (unsigned long)sizeof(int));
xfree(char_grayscale);
char_grayscale = (unsigned char *)0;
}
@@ -1301,8 +1346,8 @@ ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
(newWidth + 3) * sizeof(int));
thisrow = diffusion_workspace + 1;
nextrow = diffusion_workspace + newWidth + 3;
- } else {
- fprintf(stderr, "Warning: Couldn't allocate character grayscale (%d)\n", (width + 1) * (height + 1));
+ } else {
+ fprintf(stderr, "Warning: Couldn't allocate character grayscale (%d)\n", (width + 1) * (height + 1));
}
}
}
@@ -1554,15 +1599,14 @@ ScaleBitmap(pFont, opci, pci, inv_xform, widthMult, heightMult)
}
static FontPtr
-BitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)
- FontPtr pf; /* scaled font */
- FontPtr opf; /* originating font */
- double widthMult; /* glyphs width scale factor */
- double heightMult; /* glyphs height scale factor */
- FontScalablePtr vals;
+BitmapScaleBitmaps(FontPtr pf, /* scaled font */
+ FontPtr opf, /* originating font */
+ double widthMult, /* glyphs width scale factor */
+ double heightMult, /* glyphs height scale factor */
+ FontScalablePtr vals)
{
register int i;
- int nchars;
+ int nchars = 0;
char *glyphBytes;
BitmapFontPtr bitmapFont,
obitmapFont;
@@ -1593,7 +1637,7 @@ BitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)
glyph = pf->glyph;
for (i = 0; i < nchars; i++)
{
- if ((pci = bitmapFont->encoding[i]))
+ if ((pci = ACCESSENCODING(bitmapFont->encoding, i)))
bytestoalloc += BYTES_FOR_GLYPH(pci, glyph);
}
@@ -1603,7 +1647,7 @@ BitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)
bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);
if (!bitmapFont->bitmaps) {
- fprintf(stderr, "Error: Couldn't allocate bitmaps (%d)\n", bytestoalloc);
+ fprintf(stderr, "Error: Couldn't allocate bitmaps (%d)\n", bytestoalloc);
goto bail;
}
bzero(bitmapFont->bitmaps, bytestoalloc);
@@ -1611,8 +1655,8 @@ BitmapScaleBitmaps(pf, opf, widthMult, heightMult, vals)
glyphBytes = bitmapFont->bitmaps;
for (i = 0; i < nchars; i++)
{
- if ((pci = bitmapFont->encoding[i]) &&
- (opci = obitmapFont->encoding[OLDINDEX(i)]))
+ if ((pci = ACCESSENCODING(bitmapFont->encoding, i)) &&
+ (opci = ACCESSENCODING(obitmapFont->encoding, OLDINDEX(i))))
{
pci->bits = glyphBytes;
ScaleBitmap (pf, opci, pci, inv_xform,
@@ -1629,21 +1673,23 @@ bail:
xfree(bitmapFont->metrics);
xfree(bitmapFont->ink_metrics);
xfree(bitmapFont->bitmaps);
+ if(bitmapFont->encoding)
+ for(i=0; i<NUM_SEGMENTS(nchars); i++)
+ xfree(bitmapFont->encoding[i]);
xfree(bitmapFont->encoding);
}
return NULL;
}
static FontPtr
-PrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)
- FontPtr pf; /* scaled font */
- FontPtr opf; /* originating font */
- double widthMult; /* glyphs width scale factor */
- double heightMult; /* glyphs height scale factor */
- FontScalablePtr vals;
+PrinterScaleBitmaps(FontPtr pf, /* scaled font */
+ FontPtr opf, /* originating font */
+ double widthMult, /* glyphs width scale factor */
+ double heightMult, /* glyphs height scale factor */
+ FontScalablePtr vals)
{
register int i;
- int nchars;
+ int nchars = 0;
char *glyphBytes;
BitmapFontPtr bitmapFont,
obitmapFont;
@@ -1674,7 +1720,7 @@ PrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)
glyph = pf->glyph;
for (i = 0; i < nchars; i++)
{
- if ((pci = bitmapFont->encoding[i]))
+ if ((pci = ACCESSENCODING(bitmapFont->encoding, i)))
bytestoalloc = MAX(bytestoalloc,BYTES_FOR_GLYPH(pci, glyph));
}
@@ -1684,7 +1730,7 @@ PrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)
bitmapFont->bitmaps = (char *) xalloc(bytestoalloc);
if (!bitmapFont->bitmaps) {
- fprintf(stderr, "Error: Couldn't allocate bitmaps (%d)\n", bytestoalloc);
+ fprintf(stderr, "Error: Couldn't allocate bitmaps (%d)\n", bytestoalloc);
goto bail;
}
bzero(bitmapFont->bitmaps, bytestoalloc);
@@ -1692,8 +1738,8 @@ PrinterScaleBitmaps(pf, opf, widthMult, heightMult, vals)
glyphBytes = bitmapFont->bitmaps;
for (i = 0; i < nchars; i++)
{
- if ((pci = bitmapFont->encoding[i]) &&
- (opci = obitmapFont->encoding[OLDINDEX(i)]))
+ if ((pci = ACCESSENCODING(bitmapFont->encoding, i)) &&
+ (opci = ACCESSENCODING(obitmapFont->encoding, OLDINDEX(i))))
{
pci->bits = glyphBytes;
}
@@ -1707,6 +1753,9 @@ bail:
xfree(bitmapFont->metrics);
xfree(bitmapFont->ink_metrics);
xfree(bitmapFont->bitmaps);
+ if(bitmapFont->encoding)
+ for(i=0; i<NUM_SEGMENTS(nchars); i++)
+ xfree(bitmapFont->encoding[i]);
xfree(bitmapFont->encoding);
}
return NULL;
@@ -1717,13 +1766,8 @@ bail:
* exported interfaces
*/
-FontFileLoadName(dirs, ndirs, name, pfont, format, fmask)
- FontFileDirPtr *dirs;
- int ndirs;
- char *name;
- FontPtr *pfont;
- fsBitmapFormat format;
- fsBitmapFormatMask fmask;
+FontFileLoadName(FontFileDirPtr *dirs, int ndirs, char *name, FontPtr *pfont,
+ fsBitmapFormat format, fsBitmapFormatMask fmask)
{
FontFileNamePtr fname;
char full_name[1024];
@@ -1758,17 +1802,15 @@ FontFileLoadName(dirs, ndirs, name, pfont, format, fmask)
/* ARGSUSED */
int
-BitmapOpenScalable (fpe, pFont, flags, entry, fileName, vals, format, fmask,
- non_cachable_font)
- FontPathElementPtr fpe;
- FontPtr *pFont;
- int flags;
- FontEntryPtr entry;
- char *fileName; /* unused */
- FontScalablePtr vals;
- fsBitmapFormat format;
- fsBitmapFormatMask fmask;
- FontPtr non_cachable_font; /* We don't do licensing */
+BitmapOpenScalable (FontPathElementPtr fpe,
+ FontPtr *pFont,
+ int flags,
+ FontEntryPtr entry,
+ char *fileName, /* unused */
+ FontScalablePtr vals,
+ fsBitmapFormat format,
+ fsBitmapFormatMask fmask,
+ FontPtr non_cachable_font) /* We don't do licensing */
{
FontScalableRec best;
FontPtr font = NullFont;
@@ -1861,13 +1903,12 @@ BitmapOpenScalable (fpe, pFont, flags, entry, fileName, vals, format, fmask,
}
int
-BitmapGetInfoScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
- FontPathElementPtr fpe;
- FontInfoPtr pFontInfo;
- FontEntryPtr entry;
- FontNamePtr fontName;
- char *fileName;
- FontScalablePtr vals;
+BitmapGetInfoScalable (FontPathElementPtr fpe,
+ FontInfoPtr pFontInfo,
+ FontEntryPtr entry,
+ FontNamePtr fontName,
+ char *fileName,
+ FontScalablePtr vals)
{
FontPtr pfont;
int flags = 0;
@@ -1881,6 +1922,7 @@ BitmapGetInfoScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
return ret;
*pFontInfo = pfont->info;
+ pfont->info.nprops = 0;
pfont->info.props = NULL;
pfont->info.isStringProp = NULL;
@@ -1888,22 +1930,27 @@ BitmapGetInfoScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
return Successful;
}
-void
-bitmapUnloadScalable (pFont)
- FontPtr pFont;
+static void
+bitmapUnloadScalable (FontPtr pFont)
{
BitmapFontPtr bitmapFont;
FontInfoPtr pfi;
+ int i, nencoding;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
pfi = &pFont->info;
xfree (pfi->props);
xfree (pfi->isStringProp);
+ if(bitmapFont->encoding) {
+ nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+ (pFont->info.lastRow - pFont->info.firstRow + 1);
+ for(i=0; i<NUM_SEGMENTS(nencoding); i++)
+ xfree(bitmapFont->encoding[i]);
+ }
xfree (bitmapFont->encoding);
xfree (bitmapFont->bitmaps);
xfree (bitmapFont->ink_metrics);
xfree (bitmapFont->metrics);
xfree (pFont->fontPrivate);
- xfree (pFont->devPrivates);
- xfree (pFont);
+ DestroyFontRec (pFont);
}
diff --git a/src/bitmap/fontink.c b/src/bitmap/fontink.c
index fc9bc9a..45226c5 100644
--- a/src/bitmap/fontink.c
+++ b/src/bitmap/fontink.c
@@ -27,12 +27,15 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/fontink.c,v 1.7 2001/12/14 19:56:46 dawes Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
*/
#include "fntfilst.h"
+#include "bitmap.h"
+#include "bdfint.h"
static unsigned char ink_mask_msb[8] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
@@ -43,23 +46,20 @@ static unsigned char ink_mask_lsb[8] = {
};
void
-FontCharInkMetrics(pFont, pCI, pInk)
- FontPtr pFont;
- CharInfoPtr pCI;
- xCharInfo *pInk;
+FontCharInkMetrics(FontPtr pFont, CharInfoPtr pCI, xCharInfo *pInk)
{
int leftBearing,
ascent,
descent;
register int vpos,
hpos,
- bpos;
+ bpos = 0;
int bitmapByteWidth,
bitmapByteWidthPadded;
int bitmapBitWidth;
int span;
register unsigned char *p;
- unsigned char *ink_mask;
+ unsigned char *ink_mask = 0;
register int bmax;
register unsigned char charbits;
@@ -157,10 +157,7 @@ found_right:
#define Max(a,b) ((a)>(b)?(a):(b))
void
-FontCharReshape(pFont, pSrc, pDst)
- FontPtr pFont;
- CharInfoPtr pSrc,
- pDst;
+FontCharReshape(FontPtr pFont, CharInfoPtr pSrc, CharInfoPtr pDst)
{
int x,
y;
diff --git a/src/bitmap/pcfread.c b/src/bitmap/pcfread.c
index 7125b1a..1e07b09 100644
--- a/src/bitmap/pcfread.c
+++ b/src/bitmap/pcfread.c
@@ -1,5 +1,4 @@
/* $Xorg: pcfread.c,v 1.5 2001/02/09 02:04:02 xorgcvs Exp $ */
-
/*
Copyright 1990, 1998 The Open Group
@@ -27,6 +26,7 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/pcfread.c,v 1.20 2003/01/12 03:55:46 tsi Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
@@ -35,6 +35,7 @@ from The Open Group.
#include "fntfilst.h"
#include "bitmap.h"
#include "pcf.h"
+
#ifndef MAX
#define MAX(a,b) (((a)>(b)) ? a : b)
#endif
@@ -57,24 +58,28 @@ pcfError (message, va_alist)
va_list args;
#if NeedVarargsPrototypes
- va_start (args, message);
+ va_start(args, message);
#else
- va_start (args);
+ va_start(args);
#endif
fprintf(stderr, "PCF Error: ");
vfprintf(stderr, message, args);
- va_end (args);
+ va_end(args);
}
-
+
/* Read PCF font files */
-void pcfUnloadFont();
+static void pcfUnloadFont ( FontPtr pFont );
static int position;
+
+#define IS_EOF(file) ((file)->eof == BUFFILEEOF)
+
+#define FONT_FILE_GETC_ERR(f) (tmp = FontFileGetc(f), BAIL_ON_EOF)
+
static int
-pcfGetLSB32(file)
- FontFilePtr file;
+pcfGetLSB32(FontFilePtr file)
{
int c;
@@ -87,9 +92,7 @@ pcfGetLSB32(file)
}
static int
-pcfGetINT32(file, format)
- FontFilePtr file;
- CARD32 format;
+pcfGetINT32(FontFilePtr file, CARD32 format)
{
int c;
@@ -109,9 +112,7 @@ pcfGetINT32(file, format)
}
static int
-pcfGetINT16(file, format)
- FontFilePtr file;
- CARD32 format;
+pcfGetINT16(FontFilePtr file, CARD32 format)
{
int c;
@@ -129,9 +130,7 @@ pcfGetINT16(file, format)
#define pcfGetINT8(file, format) (position++, FontFileGetc(file))
static PCFTablePtr
-pcfReadTOC(file, countp)
- FontFilePtr file;
- int *countp;
+pcfReadTOC(FontFilePtr file, int *countp)
{
CARD32 version;
PCFTablePtr tables;
@@ -143,9 +142,10 @@ pcfReadTOC(file, countp)
if (version != PCF_FILE_VERSION)
return (PCFTablePtr) NULL;
count = pcfGetLSB32(file);
+ if (IS_EOF(file)) return (PCFTablePtr) NULL;
tables = (PCFTablePtr) xalloc(count * sizeof(PCFTableRec));
if (!tables) {
- pcfError("pcfReadTOC(): Couldn't allocate tables (%d*%d)\n", count, sizeof(PCFTableRec));
+ pcfError("pcfReadTOC(): Couldn't allocate tables (%d*%d)\n", count, sizeof(PCFTableRec));
return (PCFTablePtr) NULL;
}
for (i = 0; i < count; i++) {
@@ -153,9 +153,15 @@ pcfReadTOC(file, countp)
tables[i].format = pcfGetLSB32(file);
tables[i].size = pcfGetLSB32(file);
tables[i].offset = pcfGetLSB32(file);
+ if (IS_EOF(file)) goto Bail;
}
+
*countp = count;
return tables;
+
+ Bail:
+ xfree(tables);
+ return (PCFTablePtr) NULL;
}
/*
@@ -165,11 +171,8 @@ pcfReadTOC(file, countp)
* metrics
*/
-static void
-pcfGetMetric(file, format, metric)
- FontFilePtr file;
- CARD32 format;
- xCharInfo *metric;
+static Bool
+pcfGetMetric(FontFilePtr file, CARD32 format, xCharInfo *metric)
{
metric->leftSideBearing = pcfGetINT16(file, format);
metric->rightSideBearing = pcfGetINT16(file, format);
@@ -177,13 +180,13 @@ pcfGetMetric(file, format, metric)
metric->ascent = pcfGetINT16(file, format);
metric->descent = pcfGetINT16(file, format);
metric->attributes = pcfGetINT16(file, format);
+ if (IS_EOF(file)) return FALSE;
+
+ return TRUE;
}
-static void
-pcfGetCompressedMetric(file, format, metric)
- FontFilePtr file;
- CARD32 format;
- xCharInfo *metric;
+static Bool
+pcfGetCompressedMetric(FontFilePtr file, CARD32 format, xCharInfo *metric)
{
metric->leftSideBearing = pcfGetINT8(file, format) - 0x80;
metric->rightSideBearing = pcfGetINT8(file, format) - 0x80;
@@ -191,6 +194,9 @@ pcfGetCompressedMetric(file, format, metric)
metric->ascent = pcfGetINT8(file, format) - 0x80;
metric->descent = pcfGetINT8(file, format) - 0x80;
metric->attributes = 0;
+ if (IS_EOF(file)) return FALSE;
+
+ return TRUE;
}
/*
@@ -198,13 +204,8 @@ pcfGetCompressedMetric(file, format, metric)
* in the font file
*/
static Bool
-pcfSeekToType(file, tables, ntables, type, formatp, sizep)
- FontFilePtr file;
- PCFTablePtr tables;
- int ntables;
- CARD32 type;
- CARD32 *formatp;
- CARD32 *sizep;
+pcfSeekToType(FontFilePtr file, PCFTablePtr tables, int ntables,
+ CARD32 type, CARD32 *formatp, CARD32 *sizep)
{
int i;
@@ -223,10 +224,7 @@ pcfSeekToType(file, tables, ntables, type, formatp, sizep)
}
static Bool
-pcfHasType (tables, ntables, type)
- PCFTablePtr tables;
- int ntables;
- CARD32 type;
+pcfHasType (PCFTablePtr tables, int ntables, CARD32 type)
{
int i;
@@ -244,18 +242,15 @@ pcfHasType (tables, ntables, type)
*/
static Bool
-pcfGetProperties(pFontInfo, file, tables, ntables)
- FontInfoPtr pFontInfo;
- FontFilePtr file;
- PCFTablePtr tables;
- int ntables;
+pcfGetProperties(FontInfoPtr pFontInfo, FontFilePtr file,
+ PCFTablePtr tables, int ntables)
{
FontPropPtr props = 0;
int nprops;
char *isStringProp = 0;
CARD32 format;
int i;
- int size;
+ CARD32 size;
int string_size;
char *strings;
@@ -267,20 +262,22 @@ pcfGetProperties(pFontInfo, file, tables, ntables)
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
goto Bail;
nprops = pcfGetINT32(file, format);
+ if (IS_EOF(file)) goto Bail;
props = (FontPropPtr) xalloc(nprops * sizeof(FontPropRec));
if (!props) {
- pcfError("pcfGetProperties(): Couldn't allocate props (%d*%d)\n", nprops, sizeof(FontPropRec));
+ pcfError("pcfGetProperties(): Couldn't allocate props (%d*%d)\n", nprops, sizeof(FontPropRec));
goto Bail;
}
isStringProp = (char *) xalloc(nprops * sizeof(char));
if (!isStringProp) {
- pcfError("pcfGetProperties(): Couldn't allocate isStringProp (%d*%d)\n", nprops, sizeof(char));
+ pcfError("pcfGetProperties(): Couldn't allocate isStringProp (%d*%d)\n", nprops, sizeof(char));
goto Bail;
}
for (i = 0; i < nprops; i++) {
props[i].name = pcfGetINT32(file, format);
isStringProp[i] = pcfGetINT8(file, format);
props[i].value = pcfGetINT32(file, format);
+ if (IS_EOF(file)) goto Bail;
}
/* pad the property array */
/*
@@ -290,16 +287,19 @@ pcfGetProperties(pFontInfo, file, tables, ntables)
if (nprops & 3)
{
i = 4 - (nprops & 3);
- FontFileSkip(file, i);
+ (void)FontFileSkip(file, i);
position += i;
}
+ if (IS_EOF(file)) goto Bail;
string_size = pcfGetINT32(file, format);
+ if (IS_EOF(file)) goto Bail;
strings = (char *) xalloc(string_size);
if (!strings) {
- pcfError("pcfGetProperties(): Couldn't allocate strings (%d)\n", string_size);
+ pcfError("pcfGetProperties(): Couldn't allocate strings (%d)\n", string_size);
goto Bail;
}
FontFileRead(file, strings, string_size);
+ if (IS_EOF(file)) goto Bail;
position += string_size;
for (i = 0; i < nprops; i++) {
props[i].name = MakeAtom(strings + props[i].name,
@@ -329,17 +329,14 @@ Bail:
*/
static Bool
-pcfGetAccel(pFontInfo, file, tables, ntables, type)
- FontInfoPtr pFontInfo;
- FontFilePtr file;
- PCFTablePtr tables;
- int ntables;
- CARD32 type;
+pcfGetAccel(FontInfoPtr pFontInfo, FontFilePtr file,
+ PCFTablePtr tables, int ntables, CARD32 type)
{
CARD32 format;
- int size;
+ CARD32 size;
- if (!pcfSeekToType(file, tables, ntables, type, &format, &size))
+ if (!pcfSeekToType(file, tables, ntables, type, &format, &size) ||
+ IS_EOF(file))
goto Bail;
format = pcfGetLSB32(file);
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
@@ -360,11 +357,16 @@ pcfGetAccel(pFontInfo, file, tables, ntables, type)
pFontInfo->fontAscent = pcfGetINT32(file, format);
pFontInfo->fontDescent = pcfGetINT32(file, format);
pFontInfo->maxOverlap = pcfGetINT32(file, format);
- pcfGetMetric(file, format, &pFontInfo->minbounds);
- pcfGetMetric(file, format, &pFontInfo->maxbounds);
+ if (IS_EOF(file)) goto Bail;
+ if (!pcfGetMetric(file, format, &pFontInfo->minbounds))
+ goto Bail;
+ if (!pcfGetMetric(file, format, &pFontInfo->maxbounds))
+ goto Bail;
if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {
- pcfGetMetric(file, format, &pFontInfo->ink_minbounds);
- pcfGetMetric(file, format, &pFontInfo->ink_maxbounds);
+ if (!pcfGetMetric(file, format, &pFontInfo->ink_minbounds))
+ goto Bail;
+ if (!pcfGetMetric(file, format, &pFontInfo->ink_maxbounds))
+ goto Bail;
} else {
pFontInfo->ink_minbounds = pFontInfo->minbounds;
pFontInfo->ink_maxbounds = pFontInfo->maxbounds;
@@ -375,13 +377,8 @@ Bail:
}
int
-pcfReadFont(pFont, file, bit, byte, glyph, scan)
- FontPtr pFont;
- FontFilePtr file;
- int bit,
- byte,
- glyph,
- scan;
+pcfReadFont(FontPtr pFont, FontFilePtr file,
+ int bit, int byte, int glyph, int scan)
{
CARD32 format;
CARD32 size;
@@ -396,13 +393,14 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
CharInfoPtr metrics = 0;
xCharInfo *ink_metrics = 0;
char *bitmaps = 0;
- CharInfoPtr *encoding = 0;
- int nencoding;
+ CharInfoPtr **encoding = 0;
+ int nencoding = 0;
int encodingOffset;
CARD32 bitmapSizes[GLYPHPADOPTIONS];
CARD32 *offsets = 0;
Bool hasBDFAccelerators;
+ pFont->info.nprops = 0;
pFont->info.props = 0;
if (!(tables = pcfReadTOC(file, &ntables)))
goto Bail;
@@ -433,17 +431,21 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
nmetrics = pcfGetINT32(file, format);
else
nmetrics = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
if (!metrics) {
- pcfError("pcfReadFont(): Couldn't allocate metrics (%d*%d)\n", nmetrics, sizeof(CharInfoRec));
+ pcfError("pcfReadFont(): Couldn't allocate metrics (%d*%d)\n", nmetrics, sizeof(CharInfoRec));
goto Bail;
}
for (i = 0; i < nmetrics; i++)
- if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
- pcfGetMetric(file, format, &(metrics + i)->metrics);
- else
- pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
-
+ if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) {
+ if (!pcfGetMetric(file, format, &(metrics + i)->metrics))
+ goto Bail;
+ } else {
+ if (!pcfGetCompressedMetric(file, format, &(metrics + i)->metrics))
+ goto Bail;
+ }
+
/* bitmaps */
if (!pcfSeekToType(file, tables, ntables, PCF_BITMAPS, &format, &size))
@@ -453,41 +455,46 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
goto Bail;
nbitmaps = pcfGetINT32(file, format);
- if (nbitmaps != nmetrics)
+ if (nbitmaps != nmetrics || IS_EOF(file))
goto Bail;
offsets = (CARD32 *) xalloc(nbitmaps * sizeof(CARD32));
if (!offsets) {
- pcfError("pcfReadFont(): Couldn't allocate offsets (%d*%d)\n", nbitmaps, sizeof(CARD32));
+ pcfError("pcfReadFont(): Couldn't allocate offsets (%d*%d)\n", nbitmaps, sizeof(CARD32));
goto Bail;
}
-
- for (i = 0; i < nbitmaps; i++)
+ for (i = 0; i < nbitmaps; i++) {
offsets[i] = pcfGetINT32(file, format);
+ if (IS_EOF(file)) goto Bail;
+ }
- for (i = 0; i < GLYPHPADOPTIONS; i++)
+ for (i = 0; i < GLYPHPADOPTIONS; i++) {
bitmapSizes[i] = pcfGetINT32(file, format);
+ if (IS_EOF(file)) goto Bail;
+ }
+
sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX(format)];
/* guard against completely empty font */
- bitmaps = (char *) xalloc(sizebitmaps ? sizebitmaps : 1);
+ bitmaps = xalloc(sizebitmaps ? sizebitmaps : 1);
if (!bitmaps) {
- pcfError("pcfReadFont(): Couldn't allocate bitmaps (%d)\n", sizebitmaps ? sizebitmaps : 1);
+ pcfError("pcfReadFont(): Couldn't allocate bitmaps (%d)\n", sizebitmaps ? sizebitmaps : 1);
goto Bail;
}
FontFileRead(file, bitmaps, sizebitmaps);
+ if (IS_EOF(file)) goto Bail;
position += sizebitmaps;
if (PCF_BIT_ORDER(format) != bit)
- BitOrderInvert(bitmaps, sizebitmaps);
+ BitOrderInvert((unsigned char *)bitmaps, sizebitmaps);
if ((PCF_BYTE_ORDER(format) == PCF_BIT_ORDER(format)) != (bit == byte)) {
switch (bit == byte ? PCF_SCAN_UNIT(format) : scan) {
case 1:
break;
case 2:
- TwoByteSwap(bitmaps, sizebitmaps);
+ TwoByteSwap((unsigned char *)bitmaps, sizebitmaps);
break;
case 4:
- FourByteSwap(bitmaps, sizebitmaps);
+ FourByteSwap((unsigned char *)bitmaps, sizebitmaps);
break;
}
}
@@ -501,7 +508,7 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
sizepadbitmaps = bitmapSizes[PCF_SIZE_TO_INDEX(glyph)];
padbitmaps = (char *) xalloc(sizepadbitmaps);
if (!padbitmaps) {
- pcfError("pcfReadFont(): Couldn't allocate padbitmaps (%d)\n", sizepadbitmaps);
+ pcfError("pcfReadFont(): Couldn't allocate padbitmaps (%d)\n", sizepadbitmaps);
goto Bail;
}
new = 0;
@@ -536,18 +543,22 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
nink_metrics = pcfGetINT32(file, format);
else
nink_metrics = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
if (nink_metrics != nmetrics)
goto Bail;
ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
- if (!ink_metrics) {
- pcfError("pcfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n", nink_metrics, sizeof(xCharInfo));
+ if (!ink_metrics) {
+ pcfError("pcfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n", nink_metrics, sizeof(xCharInfo));
goto Bail;
- }
+ }
for (i = 0; i < nink_metrics; i++)
- if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
- pcfGetMetric(file, format, ink_metrics + i);
- else
- pcfGetCompressedMetric(file, format, ink_metrics + i);
+ if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) {
+ if (!pcfGetMetric(file, format, ink_metrics + i))
+ goto Bail;
+ } else {
+ if (!pcfGetCompressedMetric(file, format, ink_metrics + i))
+ goto Bail;
+ }
}
/* encoding */
@@ -563,24 +574,34 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
pFont->info.firstRow = pcfGetINT16(file, format);
pFont->info.lastRow = pcfGetINT16(file, format);
pFont->info.defaultCh = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
(pFont->info.lastRow - pFont->info.firstRow + 1);
- encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+ encoding = (CharInfoPtr **) xcalloc(NUM_SEGMENTS(nencoding),
+ sizeof(CharInfoPtr*));
if (!encoding) {
- pcfError("pcfReadFont(): Couldn't allocate encoding (%d*%d)\n", nencoding, sizeof(CharInfoPtr));
+ pcfError("pcfReadFont(): Couldn't allocate encoding (%d*%d)\n", nencoding, sizeof(CharInfoPtr));
goto Bail;
}
-
+
pFont->info.allExist = TRUE;
for (i = 0; i < nencoding; i++) {
encodingOffset = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
if (encodingOffset == 0xFFFF) {
pFont->info.allExist = FALSE;
- encoding[i] = 0;
- } else
- encoding[i] = metrics + encodingOffset;
+ } else {
+ if(!encoding[SEGMENT_MAJOR(i)]) {
+ encoding[SEGMENT_MAJOR(i)]=
+ (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE,
+ sizeof(CharInfoPtr));
+ if(!encoding[SEGMENT_MAJOR(i)])
+ goto Bail;
+ }
+ ACCESSENCODINGL(encoding, i) = metrics + encodingOffset;
+ }
}
/* BDF style accelerators (i.e. bounds based on encoded glyphs) */
@@ -591,7 +612,7 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
if (!bitmapFont) {
- pcfError("pcfReadFont(): Couldn't allocate bitmapFont (%d)\n", sizeof *bitmapFont);
+ pcfError("pcfReadFont(): Couldn't allocate bitmapFont (%d)\n", sizeof *bitmapFont);
goto Bail;
}
@@ -615,7 +636,7 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
cols = pFont->info.lastCol - pFont->info.firstCol + 1;
r = r - pFont->info.firstRow;
c = c - pFont->info.firstCol;
- bitmapFont->pDefault = encoding[r * cols + c];
+ bitmapFont->pDefault = ACCESSENCODING(encoding, r * cols + c);
}
}
bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
@@ -632,21 +653,25 @@ pcfReadFont(pFont, file, bit, byte, glyph, scan)
return Successful;
Bail:
xfree(ink_metrics);
+ if(encoding) {
+ for(i=0; i<NUM_SEGMENTS(nencoding); i++)
+ xfree(encoding[i]);
+ }
xfree(encoding);
xfree(bitmaps);
- xfree(offsets);
xfree(metrics);
xfree(pFont->info.props);
+ pFont->info.nprops = 0;
pFont->info.props = 0;
+ xfree (pFont->info.isStringProp);
xfree(bitmapFont);
xfree(tables);
+ xfree(offsets);
return AllocError;
}
int
-pcfReadFontInfo(pFontInfo, file)
- FontInfoPtr pFontInfo;
- FontFilePtr file;
+pcfReadFontInfo(FontInfoPtr pFontInfo, FontFilePtr file)
{
PCFTablePtr tables;
int ntables;
@@ -657,6 +682,7 @@ pcfReadFontInfo(pFontInfo, file)
pFontInfo->isStringProp = NULL;
pFontInfo->props = NULL;
+ pFontInfo->nprops = 0;
if (!(tables = pcfReadTOC(file, &ntables)))
goto Bail;
@@ -686,6 +712,7 @@ pcfReadFontInfo(pFontInfo, file)
pFontInfo->firstRow = pcfGetINT16(file, format);
pFontInfo->lastRow = pcfGetINT16(file, format);
pFontInfo->defaultCh = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
nencoding = (pFontInfo->lastCol - pFontInfo->firstCol + 1) *
(pFontInfo->lastRow - pFontInfo->firstRow + 1);
@@ -694,7 +721,9 @@ pcfReadFontInfo(pFontInfo, file)
while (nencoding--) {
if (pcfGetINT16(file, format) == 0xFFFF)
pFontInfo->allExist = FALSE;
+ if (IS_EOF(file)) goto Bail;
}
+ if (IS_EOF(file)) goto Bail;
/* BDF style accelerators (i.e. bounds based on encoded glyphs) */
@@ -705,38 +734,39 @@ pcfReadFontInfo(pFontInfo, file)
xfree(tables);
return Successful;
Bail:
+ pFontInfo->nprops = 0;
xfree (pFontInfo->props);
xfree (pFontInfo->isStringProp);
xfree(tables);
return AllocError;
}
-void
-pcfUnloadFont(pFont)
- FontPtr pFont;
+static void
+pcfUnloadFont(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
+ int i,nencoding;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
xfree(bitmapFont->ink_metrics);
+ if(bitmapFont->encoding) {
+ nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+ (pFont->info.lastRow - pFont->info.firstRow + 1);
+ for(i=0; i<NUM_SEGMENTS(nencoding); i++)
+ xfree(bitmapFont->encoding[i]);
+ }
xfree(bitmapFont->encoding);
xfree(bitmapFont->bitmaps);
xfree(bitmapFont->metrics);
xfree(pFont->info.isStringProp);
xfree(pFont->info.props);
xfree(bitmapFont);
- xfree(pFont->devPrivates);
- xfree(pFont);
+ DestroyFontRec(pFont);
}
int
-pmfReadFont(pFont, file, bit, byte, glyph, scan)
- FontPtr pFont;
- FontFilePtr file;
- int bit,
- byte,
- glyph,
- scan;
+pmfReadFont(FontPtr pFont, FontFilePtr file,
+ int bit, int byte, int glyph, int scan)
{
CARD32 format;
CARD32 size;
@@ -750,13 +780,15 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
CharInfoPtr metrics = 0;
xCharInfo *ink_metrics = 0;
char *bitmaps = 0;
- CharInfoPtr *encoding = 0;
- int nencoding;
+ CharInfoPtr **encoding = 0;
+ int nencoding = 0;
int encodingOffset;
Bool hasBDFAccelerators;
CharInfoPtr pci;
+ pFont->info.nprops = 0;
pFont->info.props = 0;
+
if (!(tables = pcfReadTOC(file, &ntables)))
goto Bail;
@@ -786,17 +818,21 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
nmetrics = pcfGetINT32(file, format);
else
nmetrics = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
if (!metrics) {
- pcfError("pmfReadFont(): Couldn't allocate metrics (%d*%d)\n", nmetrics, sizeof(CharInfoRec));
+ pcfError("pmfReadFont(): Couldn't allocate metrics (%d*%d)\n", nmetrics, sizeof(CharInfoRec));
goto Bail;
}
for (i = 0; i < nmetrics; i++)
- if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
- pcfGetMetric(file, format, &(metrics + i)->metrics);
- else
- pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
-
+ if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) {
+ if (!pcfGetMetric(file, format, &(metrics + i)->metrics))
+ goto Bail;
+ } else {
+ if (!pcfGetCompressedMetric(file, format, &(metrics + i)->metrics))
+ goto Bail;
+ }
+
/* Set the bitmaps to all point to the same zero filled array
* that is the size of the largest bitmap.
*/
@@ -809,11 +845,15 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
pci++;
}
+#ifdef FONTMODULE
+ sizebitmaps = 1024; /* Default - we xalloc the size anyway */
+#else
sizebitmaps = BUFSIZ;
+#endif
/* guard against completely empty font */
bitmaps = (char *) xalloc(sizebitmaps);
if (!bitmaps) {
- pcfError("pmfReadFont(): Couldn't allocate bitmaps (%d)\n", sizebitmaps);
+ pcfError("pmfReadFont(): Couldn't allocate bitmaps (%d)\n", sizebitmaps);
goto Bail;
}
@@ -836,16 +876,20 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
nink_metrics = pcfGetINT16(file, format);
if (nink_metrics != nmetrics)
goto Bail;
+ if (IS_EOF(file)) goto Bail;
ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
- if (!ink_metrics) {
- pcfError("pmfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n", nink_metrics, sizeof(xCharInfo));
+ if (!ink_metrics) {
+ pcfError("pmfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n", nink_metrics, sizeof(xCharInfo));
goto Bail;
- }
+ }
for (i = 0; i < nink_metrics; i++)
- if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
- pcfGetMetric(file, format, ink_metrics + i);
- else
- pcfGetCompressedMetric(file, format, ink_metrics + i);
+ if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) {
+ if (!pcfGetMetric(file, format, ink_metrics + i))
+ goto Bail;
+ } else {
+ if (!pcfGetCompressedMetric(file, format, ink_metrics + i))
+ goto Bail;
+ }
}
/* encoding */
@@ -861,25 +905,36 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
pFont->info.firstRow = pcfGetINT16(file, format);
pFont->info.lastRow = pcfGetINT16(file, format);
pFont->info.defaultCh = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
(pFont->info.lastRow - pFont->info.firstRow + 1);
- encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
+ encoding = (CharInfoPtr **) xcalloc(NUM_SEGMENTS(nencoding),
+ sizeof(CharInfoPtr*));
if (!encoding) {
- pcfError("pmfReadFont(): Couldn't allocate encoding (%d*%d)\n", nencoding, sizeof(CharInfoPtr));
+ pcfError("pmfReadFont(): Couldn't allocate encoding (%d*%d)\n", nencoding, sizeof(CharInfoPtr));
goto Bail;
}
-
pFont->info.allExist = TRUE;
for (i = 0; i < nencoding; i++) {
encodingOffset = pcfGetINT16(file, format);
+ if (IS_EOF(file)) goto Bail;
if (encodingOffset == 0xFFFF) {
pFont->info.allExist = FALSE;
encoding[i] = 0;
- } else
- encoding[i] = metrics + encodingOffset;
+ } else {
+ if(!encoding[SEGMENT_MAJOR(i)]) {
+ encoding[SEGMENT_MAJOR(i)]=
+ (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE,
+ sizeof(CharInfoPtr));
+ if(!encoding[SEGMENT_MAJOR(i)])
+ goto Bail;
+ }
+ ACCESSENCODINGL(encoding, i) = metrics + encodingOffset;
+ }
}
+ if (IS_EOF(file)) goto Bail;
/* BDF style accelerators (i.e. bounds based on encoded glyphs) */
@@ -889,10 +944,10 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
if (!bitmapFont) {
- pcfError("pmfReadFont(): Couldn't allocate bitmapFont (%d)\n", sizeof *bitmapFont);
+ pcfError("pmfReadFont(): Couldn't allocate bitmapFont (%d)\n", sizeof *bitmapFont);
goto Bail;
}
-
+
bitmapFont->version_num = PCF_FILE_VERSION;
bitmapFont->num_chars = nmetrics;
bitmapFont->num_tables = ntables;
@@ -913,7 +968,7 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
cols = pFont->info.lastCol - pFont->info.firstCol + 1;
r = r - pFont->info.firstRow;
c = c - pFont->info.firstCol;
- bitmapFont->pDefault = encoding[r * cols + c];
+ bitmapFont->pDefault = ACCESSENCODING(encoding, r * cols + c);
}
}
bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
@@ -930,11 +985,18 @@ pmfReadFont(pFont, file, bit, byte, glyph, scan)
return Successful;
Bail:
xfree(ink_metrics);
+ if(encoding) {
+ for(i=0; i<NUM_SEGMENTS(nencoding); i++)
+ xfree(encoding[i]);
+ }
xfree(encoding);
+ xfree(bitmaps);
xfree(metrics);
xfree(pFont->info.props);
- xfree(bitmapFont);
+ pFont->info.nprops = 0;
pFont->info.props = 0;
+ xfree (pFont->info.isStringProp);
+ xfree(bitmapFont);
xfree(tables);
return AllocError;
}
diff --git a/src/bitmap/pcfwrite.c b/src/bitmap/pcfwrite.c
index 39f79bc..74b099e 100644
--- a/src/bitmap/pcfwrite.c
+++ b/src/bitmap/pcfwrite.c
@@ -1,5 +1,4 @@
/* $Xorg: pcfwrite.c,v 1.5 2001/02/09 02:04:02 xorgcvs Exp $ */
-
/*
Copyright 1990, 1994, 1998 The Open Group
@@ -27,6 +26,7 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/pcfwrite.c,v 1.10 2003/01/12 03:55:46 tsi Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
@@ -39,27 +39,23 @@ from The Open Group.
extern void pcfError(
#if NeedVarargsPrototypes
- char* message, ...
+ char* message, ...
#endif
-);
+ );
/* Write PCF font files */
-static int current_position;
+static CARD32 current_position;
static int
-pcfWrite(file, b, c)
- FontFilePtr file;
- char *b;
- int c;
+pcfWrite(FontFilePtr file, char *b, int c)
{
current_position += c;
return FontFileWrite(file, b, c);
}
static int
-pcfPutLSB32(file, c)
- FontFilePtr file;
+pcfPutLSB32(FontFilePtr file, int c)
{
current_position += 4;
(void) FontFilePutc(c, file);
@@ -69,9 +65,7 @@ pcfPutLSB32(file, c)
}
static int
-pcfPutINT32(file, format, c)
- FontFilePtr file;
- CARD32 format;
+pcfPutINT32(FontFilePtr file, CARD32 format, int c)
{
current_position += 4;
if (PCF_BYTE_ORDER(format) == MSBFirst) {
@@ -88,9 +82,7 @@ pcfPutINT32(file, format, c)
}
static int
-pcfPutINT16(file, format, c)
- FontFilePtr file;
- CARD32 format;
+pcfPutINT16(FontFilePtr file, CARD32 format, int c)
{
current_position += 2;
if (PCF_BYTE_ORDER(format) == MSBFirst) {
@@ -104,19 +96,14 @@ pcfPutINT16(file, format, c)
/*ARGSUSED*/
static int
-pcfPutINT8(file, format, c)
- FontFilePtr file;
- CARD32 format;
+pcfPutINT8(FontFilePtr file, CARD32 format, int c)
{
current_position += 1;
return FontFilePutc(c, file);
}
static void
-pcfWriteTOC(file, table, count)
- FontFilePtr file;
- PCFTablePtr table;
- int count;
+pcfWriteTOC(FontFilePtr file, PCFTablePtr table, int count)
{
CARD32 version;
int i;
@@ -134,10 +121,7 @@ pcfWriteTOC(file, table, count)
}
static void
-pcfPutCompressedMetric(file, format, metric)
- FontFilePtr file;
- CARD32 format;
- xCharInfo *metric;
+pcfPutCompressedMetric(FontFilePtr file, CARD32 format, xCharInfo *metric)
{
pcfPutINT8(file, format, metric->leftSideBearing + 0x80);
pcfPutINT8(file, format, metric->rightSideBearing + 0x80);
@@ -147,10 +131,7 @@ pcfPutCompressedMetric(file, format, metric)
}
static void
-pcfPutMetric(file, format, metric)
- FontFilePtr file;
- CARD32 format;
- xCharInfo *metric;
+pcfPutMetric(FontFilePtr file, CARD32 format, xCharInfo *metric)
{
pcfPutINT16(file, format, metric->leftSideBearing);
pcfPutINT16(file, format, metric->rightSideBearing);
@@ -161,10 +142,7 @@ pcfPutMetric(file, format, metric)
}
static void
-pcfPutBitmap(file, format, pCI)
- FontFilePtr file;
- CARD32 format;
- CharInfoPtr pCI;
+pcfPutBitmap(FontFilePtr file, CARD32 format, CharInfoPtr pCI)
{
int count;
unsigned char *bits;
@@ -177,10 +155,7 @@ pcfPutBitmap(file, format, pCI)
}
static void
-pcfPutAccel(file, format, pFontInfo)
- FontFilePtr file;
- CARD32 format;
- FontInfoPtr pFontInfo;
+pcfPutAccel(FontFilePtr file, CARD32 format, FontInfoPtr pFontInfo)
{
pcfPutINT8(file, format, pFontInfo->noOverlap);
pcfPutINT8(file, format, pFontInfo->constantMetrics);
@@ -220,16 +195,13 @@ pcfPutAccel(file, format, pFontInfo)
#define CanCompressMetrics(min,max) (CanCompressMetric(min) && CanCompressMetric(max))
static char *
-pcfNameForAtom(a)
- Atom a;
+pcfNameForAtom(Atom a)
{
return NameForAtom(a);
}
int
-pcfWriteFont(pFont, file)
- FontPtr pFont;
- FontFilePtr file;
+pcfWriteFont(FontPtr pFont, FontFilePtr file)
{
PCFTableRec tables[32],
*table;
@@ -247,13 +219,13 @@ pcfWriteFont(pFont, file)
xCharInfo *ink_minbounds,
*ink_maxbounds;
BitmapFontPtr bitmapFont;
- int nencodings;
+ int nencodings = 0;
int header_size;
FontPropPtr offsetProps;
- int prop_pad;
+ int prop_pad = 0;
char *atom_name;
int glyph;
- int offset;
+ CARD32 offset;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
if (bitmapFont->bitmapExtra) {
@@ -269,7 +241,7 @@ pcfWriteFont(pFont, file)
}
offsetProps = (FontPropPtr) xalloc(pFont->info.nprops * sizeof(FontPropRec));
if (!offsetProps) {
- pcfError("pcfWriteFont(): Couldn't allocate offsetProps (%d*%d)", pFont->info.nprops, sizeof(FontPropRec));
+ pcfError("pcfWriteFont(): Couldn't allocate offsetProps (%d*%d)", pFont->info.nprops, sizeof(FontPropRec));
return AllocError;
}
prop_string_size = 0;
@@ -388,7 +360,8 @@ pcfWriteFont(pFont, file)
cur_table++, table++) {
if (current_position > table->offset) {
printf("can't go backwards... %d > %d\n",
- current_position, table->offset);
+ (int)current_position, (int)table->offset);
+ xfree(offsetProps);
return BadFontName;
}
while (current_position < table->offset)
@@ -461,8 +434,10 @@ pcfWriteFont(pFont, file)
pcfPutINT16(file, format, pFont->info.lastRow);
pcfPutINT16(file, format, pFont->info.defaultCh);
for (i = 0; i < nencodings; i++) {
- if (bitmapFont->encoding[i])
- pcfPutINT16(file, format, bitmapFont->encoding[i] - bitmapFont->metrics);
+ if (ACCESSENCODING(bitmapFont->encoding,i))
+ pcfPutINT16(file, format,
+ ACCESSENCODING(bitmapFont->encoding, i) -
+ bitmapFont->metrics);
else
pcfPutINT16(file, format, 0xFFFF);
}
@@ -490,5 +465,7 @@ pcfWriteFont(pFont, file)
break;
}
}
+
+ xfree(offsetProps);
return Successful;
}
diff --git a/src/bitmap/snfread.c b/src/bitmap/snfread.c
index 04982bc..375fa5a 100644
--- a/src/bitmap/snfread.c
+++ b/src/bitmap/snfread.c
@@ -49,8 +49,12 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/snfread.c,v 1.11 2003/01/12 03:55:46 tsi Exp $ */
+#ifndef FONTMODULE
#include <ctype.h>
+#endif
+
#include "fntfilst.h"
#include "bitmap.h"
#include "snfstr.h"
@@ -73,23 +77,20 @@ snfError (message, va_alist)
va_list args;
#if NeedVarargsPrototypes
- va_start (args, message);
+ va_start(args, message);
#else
- va_start (args);
+ va_start(args);
#endif
fprintf(stderr, "SNF Error: ");
vfprintf(stderr, message, args);
- va_end (args);
+ va_end(args);
}
-
-static void snfUnloadFont();
+
+static void snfUnloadFont(FontPtr pFont);
static int
-snfReadCharInfo(file, charInfo, base)
- FontFilePtr file;
- CharInfoPtr charInfo;
- char *base;
+snfReadCharInfo(FontFilePtr file, CharInfoPtr charInfo, char *base)
{
snfCharInfoRec snfCharInfo;
@@ -109,9 +110,7 @@ snfReadCharInfo(file, charInfo, base)
}
static int
-snfReadxCharInfo(file, charInfo)
- FontFilePtr file;
- xCharInfo *charInfo;
+snfReadxCharInfo(FontFilePtr file, xCharInfo *charInfo)
{
snfCharInfoRec snfCharInfo;
@@ -124,9 +123,7 @@ snfReadxCharInfo(file, charInfo)
}
static void
-snfCopyInfo(snfInfo, pFontInfo)
- snfFontInfoPtr snfInfo;
- FontInfoPtr pFontInfo;
+snfCopyInfo(snfFontInfoPtr snfInfo, FontInfoPtr pFontInfo)
{
pFontInfo->firstCol = snfInfo->firstCol;
pFontInfo->lastCol = snfInfo->lastCol;
@@ -152,10 +149,7 @@ snfCopyInfo(snfInfo, pFontInfo)
}
static int
-snfReadProps(snfInfo, pFontInfo, file)
- snfFontInfoPtr snfInfo;
- FontInfoPtr pFontInfo;
- FontFilePtr file;
+snfReadProps(snfFontInfoPtr snfInfo, FontInfoPtr pFontInfo, FontFilePtr file)
{
char *strings;
FontPropPtr pfp;
@@ -168,7 +162,7 @@ snfReadProps(snfInfo, pFontInfo, file)
BYTESOFSTRINGINFO(snfInfo);
propspace = (char *) xalloc(bytestoalloc);
if (!propspace) {
- snfError("snfReadProps(): Couldn't allocate propspace (%d)\n", bytestoalloc);
+ snfError("snfReadProps(): Couldn't allocate propspace (%d)\n", bytestoalloc);
return AllocError;
}
@@ -195,10 +189,8 @@ snfReadProps(snfInfo, pFontInfo, file)
return Successful;
}
-int
-snfReadHeader(snfInfo, file)
- snfFontInfoPtr snfInfo;
- FontFilePtr file;
+static int
+snfReadHeader(snfFontInfoPtr snfInfo, FontFilePtr file)
{
if (FontFileRead(file, (char *) snfInfo, sizeof *snfInfo) != sizeof *snfInfo)
return BadFontName;
@@ -213,8 +205,7 @@ static int snf_set;
static int snf_bit, snf_byte, snf_glyph, snf_scan;
void
-SnfSetFormat (bit, byte, glyph, scan)
- int bit, byte, glyph, scan;
+SnfSetFormat (int bit, int byte, int glyph, int scan)
{
snf_bit = bit;
snf_byte = byte;
@@ -223,9 +214,8 @@ SnfSetFormat (bit, byte, glyph, scan)
snf_set = 1;
}
-void
-SnfGetFormat (bit, byte, glyph, scan)
- int *bit, *byte, *glyph, *scan;
+static void
+SnfGetFormat (int *bit, int *byte, int *glyph, int *scan)
{
if (!snf_set)
FontDefaultFormat (&snf_bit, &snf_byte, &snf_glyph, &snf_scan);
@@ -236,17 +226,12 @@ SnfGetFormat (bit, byte, glyph, scan)
}
int
-snfReadFont(pFont, file, bit, byte, glyph, scan)
- FontPtr pFont;
- FontFilePtr file;
- int bit,
- byte,
- glyph,
- scan;
+snfReadFont(FontPtr pFont, FontFilePtr file,
+ int bit, int byte, int glyph, int scan)
{
snfFontInfoRec fi;
unsigned bytestoalloc;
- int i;
+ int i, j;
char *fontspace;
BitmapFontPtr bitmapFont;
int num_chars;
@@ -283,7 +268,8 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
metrics_off = bytestoalloc;
bytestoalloc += num_chars * sizeof(CharInfoRec); /* metrics */
encoding_off = bytestoalloc;
- bytestoalloc += num_chars * sizeof(CharInfoPtr); /* encoding */
+ bytestoalloc += NUM_SEGMENTS(num_chars) * sizeof(CharInfoPtr**);
+ /* encoding */
props_off = bytestoalloc;
bytestoalloc += fi.nProps * sizeof(FontPropRec); /* props */
isStringProp_off = bytestoalloc;
@@ -295,14 +281,13 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
fontspace = (char *) xalloc(bytestoalloc);
if (!fontspace) {
- snfError("snfReadFont(): Couldn't allocate fontspace (%d)\n", bytestoalloc);
+ snfError("snfReadFont(): Couldn't allocate fontspace (%d)\n", bytestoalloc);
return AllocError;
}
-
bitmaps = (char *) xalloc (bitmapsSize);
if (!bitmaps)
{
- snfError("snfReadFont(): Couldn't allocate bitmaps (%d)\n", bitmapsSize);
+ snfError("snfReadFont(): Couldn't allocate bitmaps (%d)\n", bitmapsSize);
xfree (fontspace);
return AllocError;
}
@@ -313,7 +298,7 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
bitmapFont = (BitmapFontPtr) fontspace;
bitmapFont->num_chars = num_chars;
bitmapFont->metrics = (CharInfoPtr) (fontspace + metrics_off);
- bitmapFont->encoding = (CharInfoPtr *) (fontspace + encoding_off);
+ bitmapFont->encoding = (CharInfoPtr **) (fontspace + encoding_off);
bitmapFont->bitmaps = bitmaps;
bitmapFont->pDefault = NULL;
bitmapFont->bitmapExtra = NULL;
@@ -329,16 +314,30 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
*/
ret = Successful;
+ memset(bitmapFont->encoding, 0,
+ NUM_SEGMENTS(num_chars)*sizeof(CharInfoPtr*));
for (i = 0; ret == Successful && i < num_chars; i++) {
ret = snfReadCharInfo(file, &bitmapFont->metrics[i], bitmaps);
- if (bitmapFont->metrics[i].bits)
- bitmapFont->encoding[i] = &bitmapFont->metrics[i];
- else
- bitmapFont->encoding[i] = 0;
+ if (bitmapFont->metrics[i].bits) {
+ if (!bitmapFont->encoding[SEGMENT_MAJOR(i)]) {
+ bitmapFont->encoding[SEGMENT_MAJOR(i)]=
+ (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE,
+ sizeof(CharInfoPtr));
+ if (!bitmapFont->encoding[SEGMENT_MAJOR(i)]) {
+ ret = AllocError;
+ break;
+ }
+ }
+ ACCESSENCODINGL(bitmapFont->encoding,i) = &bitmapFont->metrics[i];
+ }
}
if (ret != Successful) {
xfree(bitmaps);
+ if(bitmapFont->encoding) {
+ for(j=0; j<SEGMENT_MAJOR(i); j++)
+ xfree(bitmapFont->encoding[i]);
+ }
xfree(fontspace);
return ret;
}
@@ -346,23 +345,23 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
* read the glyphs
*/
- if (FontFileRead(file, (char *) bitmaps, bitmapsSize) != bitmapsSize) {
+ if (FontFileRead(file, bitmaps, bitmapsSize) != bitmapsSize) {
xfree(bitmaps);
xfree(fontspace);
return BadFontName;
}
if (def_bit != bit)
- BitOrderInvert(bitmaps, bitmapsSize);
+ BitOrderInvert((unsigned char *)bitmaps, bitmapsSize);
if ((def_byte == def_bit) != (bit == byte)) {
switch (bit == byte ? def_scan : scan) {
case 1:
break;
case 2:
- TwoByteSwap(bitmaps, bitmapsSize);
+ TwoByteSwap((unsigned char *)bitmaps, bitmapsSize);
break;
case 4:
- FourByteSwap(bitmaps, bitmapsSize);
+ FourByteSwap((unsigned char *)bitmaps, bitmapsSize);
break;
}
}
@@ -457,9 +456,7 @@ snfReadFont(pFont, file, bit, byte, glyph, scan)
}
int
-snfReadFontInfo(pFontInfo, file)
- FontInfoPtr pFontInfo;
- FontFilePtr file;
+snfReadFontInfo(FontInfoPtr pFontInfo, FontFilePtr file)
{
int ret;
snfFontInfoRec fi;
@@ -473,19 +470,19 @@ snfReadFontInfo(pFontInfo, file)
pFontInfo->props = (FontPropPtr) xalloc(fi.nProps * sizeof(FontPropRec));
if (!pFontInfo->props) {
- snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n", fi.nProps, sizeof(FontPropRec));
+ snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n", fi.nProps, sizeof(FontPropRec));
return AllocError;
}
pFontInfo->isStringProp = (char *) xalloc(fi.nProps * sizeof(char));
if (!pFontInfo->isStringProp) {
- snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n", fi.nProps, sizeof(char));
+ snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n", fi.nProps, sizeof(char));
xfree(pFontInfo->props);
return AllocError;
}
num_chars = n2dChars(&fi);
bytestoskip = num_chars * sizeof(snfCharInfoRec); /* charinfos */
bytestoskip += BYTESOFGLYPHINFO(&fi);
- FontFileSkip(file, bytestoskip);
+ (void)FontFileSkip(file, bytestoskip);
ret = snfReadProps(&fi, pFontInfo, file);
if (ret != Successful) {
@@ -515,15 +512,13 @@ snfReadFontInfo(pFontInfo, file)
}
static void
-snfUnloadFont(pFont)
- FontPtr pFont;
+snfUnloadFont(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
xfree (bitmapFont->bitmaps);
xfree (bitmapFont);
- xfree (pFont->devPrivates);
- xfree (pFont);
+ DestroyFontRec (pFont);
}
diff --git a/src/bitmap/snfstr.h b/src/bitmap/snfstr.h
index 1ca91fb..09ecf8a 100644
--- a/src/bitmap/snfstr.h
+++ b/src/bitmap/snfstr.h
@@ -49,10 +49,13 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/lib/font/bitmap/snfstr.h,v 1.5 2001/12/14 19:56:47 dawes Exp $ */
#ifndef SNFSTR_H
#define SNFSTR_H 1
+#include "fntfilio.h"
+
/*-
* This file describes the Server Natural Font format.
* SNF fonts are both CPU-dependent and frame buffer bit order dependent.
@@ -173,4 +176,9 @@ typedef struct _snfFontInfo {
unsigned int version2; /* version stamp double-check */
} snfFontInfoRec;
+extern void SnfSetFormat ( int bit, int byte, int glyph, int scan );
+extern int snfReadFont ( FontPtr pFont, FontFilePtr file,
+ int bit, int byte, int glyph, int scan );
+extern int snfReadFontInfo ( FontInfoPtr pFontInfo, FontFilePtr file );
+
#endif /* SNFSTR_H */