| 1 |
/* $XConsortium: t1funcs.c,v 1.10 92/05/12 18:07:55 gildea Exp $ */ |
| 2 |
/* Copyright International Business Machines,Corp. 1991 |
| 3 |
* All Rights Reserved |
| 4 |
* |
| 5 |
* License, subject to the license given below, to use, |
| 6 |
* copy, modify, and distribute this software * and its |
| 7 |
* documentation for any purpose and without fee is hereby |
| 8 |
* granted, provided that the above copyright notice appear |
| 9 |
* in all copies and that both that copyright notice and |
| 10 |
* this permission notice appear in supporting documentation, |
| 11 |
* and that the name of IBM not be used in advertising or |
| 12 |
* publicity pertaining to distribution of the software |
| 13 |
* without specific, written prior permission. |
| 14 |
* |
| 15 |
* IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES |
| 16 |
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT |
| 17 |
* LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF |
| 19 |
* THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND |
| 20 |
* PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT |
| 21 |
* OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF |
| 22 |
* THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES |
| 23 |
* THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN |
| 24 |
* NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 25 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING |
| 26 |
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 27 |
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 28 |
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 29 |
* SOFTWARE. |
| 30 |
* |
| 31 |
* Author: Jeffrey B. Lotspiech, IBM Almaden Research Center |
| 32 |
* Modeled on spfuncs.c by Dave Lemke, Network Computing Devices, Inc |
| 33 |
* which contains the following copyright and permission notices: |
| 34 |
* |
| 35 |
* Copyright 1990, 1991 Network Computing Devices; |
| 36 |
* Portions Copyright 1987 by Digital Equipment Corporation and the |
| 37 |
* Massachusetts Institute of Technology |
| 38 |
* |
| 39 |
* Permission to use, copy, modify, and distribute this protoype software |
| 40 |
* and its documentation to Members and Affiliates of the MIT X Consortium |
| 41 |
* any purpose and without fee is hereby granted, provided |
| 42 |
* that the above copyright notice appear in all copies and that both that |
| 43 |
* copyright notice and this permission notice appear in supporting |
| 44 |
* documentation, and that the names of Network Computing Devices, Digital or |
| 45 |
* MIT not be used in advertising or publicity pertaining to distribution of |
| 46 |
* the software without specific, written prior permission. |
| 47 |
* |
| 48 |
* NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH |
| 49 |
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 50 |
* AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE |
| 51 |
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 52 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 53 |
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 54 |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 55 |
*/ |
| 56 |
|
| 57 |
#include "types.h" |
| 58 |
#include <string.h> |
| 59 |
#include "ffilest.h" |
| 60 |
#ifdef XSERVER |
| 61 |
#include <X11/Xfuncs.h> |
| 62 |
#include "FSproto.h" |
| 63 |
#endif |
| 64 |
#include "t1intf.h" |
| 65 |
|
| 66 |
#include "objects.h" |
| 67 |
#include "spaces.h" |
| 68 |
#include "paths.h" |
| 69 |
#include "regions.h" |
| 70 |
#include "t1stdio.h" |
| 71 |
#include "util.h" |
| 72 |
#include "fontfcn.h" |
| 73 |
|
| 74 |
static int Type1GetGlyphs(struct _Font *pFont, uint32_t count, |
| 75 |
unsigned char *chars, FontEncoding charEncoding, |
| 76 |
uint32_t *glyphCount, struct _CharInfo **glyphs); |
| 77 |
static int Type1GetMetrics(struct _Font *pFont, uint32_t count, |
| 78 |
unsigned char *chars, FontEncoding charEncoding, |
| 79 |
uint32_t *glyphCount, xCharInfo **glyphs ); |
| 80 |
static void fillrun(register char *p,pel x0,pel x1,int bit); |
| 81 |
static void fill(char *dest,int h,int w,struct region *area, |
| 82 |
int byte,int bit,int wordsize); |
| 83 |
static void FontDefaultFormat(int *bit, int *byte, int *glyphs, int *scan); |
| 84 |
|
| 85 |
#define DECIPOINTSPERINCH 722.7 |
| 86 |
|
| 87 |
/*ARGSUSED*/ |
| 88 |
int Type1OpenScalable ( |
| 89 |
encoding ev, |
| 90 |
FontPtr *ppFont, |
| 91 |
int flags, |
| 92 |
FontEntryPtr entry, |
| 93 |
char *fileName, |
| 94 |
FontScalablePtr vals, |
| 95 |
fsBitmapFormat format, |
| 96 |
fsBitmapFormatMask fmask, |
| 97 |
DOUBLE efactor, |
| 98 |
DOUBLE slant) |
| 99 |
{ |
| 100 |
FontPtr pFont; |
| 101 |
int bit, |
| 102 |
byte, |
| 103 |
glyph, |
| 104 |
scan, |
| 105 |
image; |
| 106 |
int pad,wordsize; /* scan & image in bits */ |
| 107 |
int size; /* for memory size calculations */ |
| 108 |
struct XYspace *S; /* coordinate space for character */ |
| 109 |
struct region *area; |
| 110 |
DOUBLE scale; /* scale factor for font */ |
| 111 |
DOUBLE txx, tyx, txy, tyy; |
| 112 |
CharInfoRec *glyphs; |
| 113 |
register int i; |
| 114 |
int len,rc; |
| 115 |
struct type1font *type1; |
| 116 |
|
| 117 |
/* set up default values */ |
| 118 |
FontDefaultFormat(&bit, &byte, &glyph, &scan); |
| 119 |
/* get any changes made from above */ |
| 120 |
rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image); |
| 121 |
if (rc != Successful) |
| 122 |
return rc; |
| 123 |
|
| 124 |
pad = glyph * 8; |
| 125 |
wordsize = scan * 8; |
| 126 |
|
| 127 |
#define PAD(bits, pad) (((bits)+(pad)-1)&-(pad)) |
| 128 |
|
| 129 |
pFont = (FontPtr) Xalloc(sizeof(FontRec)); |
| 130 |
if (pFont == NULL) |
| 131 |
return AllocError; |
| 132 |
|
| 133 |
type1 = (struct type1font *)Xalloc(sizeof(struct type1font)); |
| 134 |
if (type1 == NULL) { |
| 135 |
Xfree(pFont); |
| 136 |
return AllocError; |
| 137 |
} |
| 138 |
(void) memset(type1, 0, sizeof(struct type1font)); |
| 139 |
|
| 140 |
scale = (DOUBLE) vals->pixel; |
| 141 |
|
| 142 |
/* Code added by E. Schenk. July 25, 1992. |
| 143 |
* The following code reads the FontMatrix for the font, |
| 144 |
* and transforms the font using it. This is necessary |
| 145 |
* for fonts that are just an oblique, or extend of |
| 146 |
* a normal font. |
| 147 |
*/ |
| 148 |
{ float fontmatrix[6]; |
| 149 |
int rc; |
| 150 |
QueryFontLib(fileName,"FontMatrix",fontmatrix,&rc); |
| 151 |
if (!rc) { |
| 152 |
S = (struct XYspace *) Transform((struct xobject *)IDENTITY, |
| 153 |
fontmatrix[0], fontmatrix[1], fontmatrix[2], fontmatrix[3]); |
| 154 |
} |
| 155 |
else { |
| 156 |
S = (struct XYspace *) Scale((struct xobject *)IDENTITY,0.001,0.001); |
| 157 |
} |
| 158 |
} |
| 159 |
/* End of additional code */ |
| 160 |
|
| 161 |
if (efactor == 1.0 && slant == 0.0) |
| 162 |
S = (struct XYspace *)Permanent(Scale((struct xobject *)S, scale, - scale)); |
| 163 |
else { |
| 164 |
txx = (DOUBLE)vals->x * efactor * vals->point / DECIPOINTSPERINCH; |
| 165 |
tyy = (DOUBLE)vals->y * vals->point / DECIPOINTSPERINCH; |
| 166 |
tyx = 0.0; |
| 167 |
txy = (DOUBLE)vals->x * slant * vals->point / DECIPOINTSPERINCH; |
| 168 |
S = (struct XYspace *) Permanent(Transform((struct xobject *)S, txx, tyx, txy, -tyy)); |
| 169 |
} |
| 170 |
|
| 171 |
glyphs = type1->glyphs; |
| 172 |
|
| 173 |
/* load font if not already loaded */ |
| 174 |
if (!fontfcnA(fileName, &rc)) |
| 175 |
return (rc); |
| 176 |
|
| 177 |
for (i=0; i < 256-FIRSTCOL; i++) { |
| 178 |
int32_t h,w; |
| 179 |
int32_t paddedW; |
| 180 |
|
| 181 |
if (ev[i] == NULL) continue; |
| 182 |
len = strlen(ev[i]); |
| 183 |
|
| 184 |
currentchar = i; |
| 185 |
|
| 186 |
rc = 0; |
| 187 |
area = fontfcnB(S, (unsigned char *)ev[i], &len, &rc); |
| 188 |
if (rc < 0) { |
| 189 |
rc = BadFontName; |
| 190 |
break; |
| 191 |
} |
| 192 |
else if (rc > 0) |
| 193 |
continue; |
| 194 |
|
| 195 |
if (area == NULL) |
| 196 |
continue; |
| 197 |
|
| 198 |
h = area->ymax - area->ymin; |
| 199 |
w = area->xmax - area->xmin; |
| 200 |
paddedW = PAD(w, pad); |
| 201 |
|
| 202 |
if (h > 0 && w > 0) { |
| 203 |
size = h * paddedW / 8; |
| 204 |
glyphs[i].bits = (char *)Xalloc(size); |
| 205 |
if (glyphs[i].bits == NULL) { |
| 206 |
rc = AllocError; |
| 207 |
break; |
| 208 |
} |
| 209 |
} |
| 210 |
else { |
| 211 |
h = w = 0; |
| 212 |
area->xmin = area->xmax = 0; |
| 213 |
area->ymin = area->ymax = 0; |
| 214 |
} |
| 215 |
|
| 216 |
glyphs[i].metrics.leftSideBearing = area->xmin; |
| 217 |
glyphs[i].metrics.characterWidth = NEARESTPEL(area->ending.x - area->origin.x); |
| 218 |
glyphs[i].metrics.rightSideBearing = w + area->xmin; |
| 219 |
glyphs[i].metrics.descent = area->ymax - NEARESTPEL(area->origin.y); |
| 220 |
glyphs[i].metrics.ascent = h - glyphs[i].metrics.descent; |
| 221 |
|
| 222 |
if (h > 0 && w > 0) { |
| 223 |
(void) memset(glyphs[i].bits, 0, size); |
| 224 |
fill(glyphs[i].bits, h, paddedW, area, byte, bit, wordsize ); |
| 225 |
} |
| 226 |
|
| 227 |
Destroy(area); |
| 228 |
} |
| 229 |
|
| 230 |
if (i != 256 - FIRSTCOL) { |
| 231 |
for (i--; i >= 0; i--) |
| 232 |
if (glyphs[i].bits != NULL) |
| 233 |
Xfree(glyphs[i].bits); |
| 234 |
Xfree(type1); |
| 235 |
Xfree(pFont); |
| 236 |
return rc; |
| 237 |
} |
| 238 |
type1->pDefault = NULL; |
| 239 |
|
| 240 |
pFont->format = format; |
| 241 |
|
| 242 |
pFont->bit = bit; |
| 243 |
pFont->byte = byte; |
| 244 |
pFont->glyph = glyph; |
| 245 |
pFont->scan = scan; |
| 246 |
|
| 247 |
pFont->info.firstCol = FIRSTCOL; |
| 248 |
pFont->info.lastCol = 255; |
| 249 |
pFont->info.firstRow = 0; |
| 250 |
pFont->info.lastRow = 0; |
| 251 |
|
| 252 |
pFont->get_metrics = Type1GetMetrics; |
| 253 |
pFont->get_glyphs = Type1GetGlyphs; |
| 254 |
pFont->unload_font = Type1CloseFont; |
| 255 |
pFont->refcnt = 0; |
| 256 |
pFont->maxPrivate = -1; |
| 257 |
pFont->devPrivates = 0; |
| 258 |
|
| 259 |
pFont->fontPrivate = (unsigned char *) type1; |
| 260 |
|
| 261 |
T1FillFontInfo(pFont, vals, fileName, entry->name.name); |
| 262 |
|
| 263 |
*ppFont = pFont; |
| 264 |
return Successful; |
| 265 |
} |
| 266 |
|
| 267 |
/* NOTE: ILH removed tests ...->characterWidth != 0 below because zero-width |
| 268 |
does not mean the character is empty, simply that it has zero escapement. */ |
| 269 |
|
| 270 |
static int |
| 271 |
Type1GetGlyphs( |
| 272 |
FontPtr pFont, |
| 273 |
uint32_t count, |
| 274 |
register unsigned char *chars, |
| 275 |
FontEncoding charEncoding, |
| 276 |
uint32_t *glyphCount, /* RETURN */ |
| 277 |
CharInfoPtr *glyphs) /* RETURN */ |
| 278 |
{ |
| 279 |
unsigned int firstRow; |
| 280 |
unsigned int numRows; |
| 281 |
CharInfoPtr *glyphsBase; |
| 282 |
register unsigned int c; |
| 283 |
unsigned int r; |
| 284 |
CharInfoPtr pDefault; |
| 285 |
register struct type1font *type1Font; |
| 286 |
register int firstCol; |
| 287 |
|
| 288 |
type1Font = (struct type1font *) pFont->fontPrivate; |
| 289 |
firstCol = pFont->info.firstCol; |
| 290 |
pDefault = type1Font->pDefault; |
| 291 |
glyphsBase = glyphs; |
| 292 |
|
| 293 |
switch (charEncoding) { |
| 294 |
|
| 295 |
case Linear8Bit: |
| 296 |
case TwoD8Bit: |
| 297 |
if (pFont->info.firstRow > 0) |
| 298 |
break; |
| 299 |
while (count--) { |
| 300 |
c = (*chars++); |
| 301 |
if (c >= firstCol) |
| 302 |
*glyphs++ = &type1Font->glyphs[c-firstCol]; |
| 303 |
else if (pDefault) |
| 304 |
*glyphs++ = pDefault; |
| 305 |
} |
| 306 |
break; |
| 307 |
case Linear16Bit: |
| 308 |
while (count--) { |
| 309 |
c = *chars++ << 8; |
| 310 |
c = (c | *chars++); |
| 311 |
if (c < 256 && c >= firstCol) |
| 312 |
*glyphs++ = &type1Font->glyphs[c-firstCol]; |
| 313 |
else if (pDefault) |
| 314 |
*glyphs++ = pDefault; |
| 315 |
} |
| 316 |
break; |
| 317 |
|
| 318 |
case TwoD16Bit: |
| 319 |
firstRow = pFont->info.firstRow; |
| 320 |
numRows = pFont->info.lastRow - firstRow + 1; |
| 321 |
while (count--) { |
| 322 |
r = (*chars++) - firstRow; |
| 323 |
c = (*chars++); |
| 324 |
if (r < numRows && c < 256 && c >= firstCol) |
| 325 |
*glyphs++ = &type1Font->glyphs[(r << 8) + c - firstCol]; |
| 326 |
else if (pDefault) |
| 327 |
*glyphs++ = pDefault; |
| 328 |
} |
| 329 |
break; |
| 330 |
} |
| 331 |
*glyphCount = glyphs - glyphsBase; |
| 332 |
return Successful; |
| 333 |
} |
| 334 |
|
| 335 |
static int |
| 336 |
Type1GetMetrics( |
| 337 |
FontPtr pFont, |
| 338 |
uint32_t count, |
| 339 |
register unsigned char *chars, |
| 340 |
FontEncoding charEncoding, |
| 341 |
uint32_t *glyphCount, /* RETURN */ |
| 342 |
xCharInfo **glyphs) /* RETURN */ |
| 343 |
{ |
| 344 |
static CharInfoRec nonExistantChar; |
| 345 |
|
| 346 |
int ret; |
| 347 |
struct type1font *type1Font; |
| 348 |
CharInfoPtr oldDefault; |
| 349 |
|
| 350 |
type1Font = (struct type1font *) pFont->fontPrivate; |
| 351 |
oldDefault = type1Font->pDefault; |
| 352 |
type1Font->pDefault = &nonExistantChar; |
| 353 |
ret = Type1GetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs); |
| 354 |
type1Font->pDefault = oldDefault; |
| 355 |
return ret; |
| 356 |
} |
| 357 |
|
| 358 |
void Type1CloseFont(FontPtr pFont) |
| 359 |
{ |
| 360 |
register int i; |
| 361 |
struct type1font *type1; |
| 362 |
|
| 363 |
type1 = (struct type1font *) pFont->fontPrivate; |
| 364 |
for (i=0; i < 256 - pFont->info.firstCol; i++) |
| 365 |
if (type1->glyphs[i].bits != NULL) |
| 366 |
Xfree(type1->glyphs[i].bits); |
| 367 |
Xfree(type1); |
| 368 |
|
| 369 |
if (pFont->info.props) |
| 370 |
Xfree(pFont->info.props); |
| 371 |
|
| 372 |
if (pFont->info.isStringProp) |
| 373 |
Xfree(pFont->info.isStringProp); |
| 374 |
|
| 375 |
Xfree(pFont); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
static void fill( |
| 380 |
register char *dest, /* destination bitmap */ |
| 381 |
int h, int w, /* dimensions of 'dest', w padded */ |
| 382 |
register struct region *area, /* region to write to 'dest' */ |
| 383 |
int Byte, int bit, /* flags; LSBFirst or MSBFirst */ |
| 384 |
int wordsize) /* number of bits per word for LSB/MSB purposes */ |
| 385 |
{ |
| 386 |
register struct edgelist *edge; /* for looping through edges */ |
| 387 |
register char *p; /* current scan line in 'dest' */ |
| 388 |
register int y; /* for looping through scans */ |
| 389 |
register int wbytes = w / 8; /* number of bytes in width */ |
| 390 |
register pel *leftP,*rightP; /* pointers to X values, left and right */ |
| 391 |
int xmin = area->xmin; /* upper left X */ |
| 392 |
int ymin = area->ymin; /* upper left Y */ |
| 393 |
|
| 394 |
for (edge = area->anchor; VALIDEDGE(edge); edge = edge->link->link) { |
| 395 |
|
| 396 |
p = dest + (edge->ymin - ymin) * wbytes; |
| 397 |
leftP = edge->xvalues; |
| 398 |
rightP = edge->link->xvalues; |
| 399 |
|
| 400 |
for (y = edge->ymin; y < edge->ymax; y++) { |
| 401 |
fillrun(p, (pel)(*leftP++ - xmin), (pel)(*rightP++ - xmin), bit); |
| 402 |
p += wbytes; |
| 403 |
} |
| 404 |
} |
| 405 |
/* |
| 406 |
Now, as an afterthought, we'll go reorganize if odd byte order requires |
| 407 |
it: |
| 408 |
*/ |
| 409 |
if (Byte == LSBFirst && wordsize != 8) { |
| 410 |
register int i; |
| 411 |
|
| 412 |
switch (wordsize) { |
| 413 |
case 16: |
| 414 |
{ |
| 415 |
register unsigned short data,*p; |
| 416 |
|
| 417 |
p = (unsigned short *) dest; |
| 418 |
|
| 419 |
for (i = h * w /16; --i >= 0;) { |
| 420 |
data = *p; |
| 421 |
*p++ = (data << 8) + (data >> 8); |
| 422 |
} |
| 423 |
break; |
| 424 |
} |
| 425 |
case 64: |
| 426 |
case 32: |
| 427 |
{ |
| 428 |
register uint32_t data,*p; |
| 429 |
|
| 430 |
p = (uint32_t *) dest; |
| 431 |
|
| 432 |
for (i = h * w / 32; --i >= 0;) { |
| 433 |
data = *p; |
| 434 |
*p++ = (data << 24) + (data >> 24) |
| 435 |
+ (0xFF00 & (data >> 8)) |
| 436 |
+ (0xFF0000 & (data << 8)); |
| 437 |
} |
| 438 |
if (wordsize == 64) { |
| 439 |
|
| 440 |
p = (uint32_t *) dest; |
| 441 |
|
| 442 |
for (i = h * w / 64; --i >= 0;) { |
| 443 |
data = *p++; |
| 444 |
p[-1] = p[0]; |
| 445 |
*p++ = data; |
| 446 |
} |
| 447 |
} |
| 448 |
break; |
| 449 |
} |
| 450 |
default: |
| 451 |
t1_abort("xiFill: unknown format"); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
} |
| 456 |
|
| 457 |
#define ALLONES 0xFF |
| 458 |
|
| 459 |
static void fillrun(register char *p, pel x0, pel x1, int bit) |
| 460 |
{ |
| 461 |
register int startmask,endmask; /* bits to set in first and last char*/ |
| 462 |
register int middle; /* number of chars between start and end + 1 */ |
| 463 |
|
| 464 |
if (x1 <= x0) |
| 465 |
return; |
| 466 |
middle = x1/8 - x0/8; |
| 467 |
p += x0/8; |
| 468 |
x0 &= 7; x1 &= 7; |
| 469 |
if (bit == LSBFirst) { |
| 470 |
startmask = ALLONES << x0; |
| 471 |
endmask = ~(ALLONES << x1); |
| 472 |
} |
| 473 |
else { |
| 474 |
startmask = ALLONES >> x0; |
| 475 |
endmask = ~(ALLONES >> x1); |
| 476 |
} |
| 477 |
if (middle == 0) |
| 478 |
*p++ |= startmask & endmask; |
| 479 |
else { |
| 480 |
*p++ |= startmask; |
| 481 |
while (--middle > 0) |
| 482 |
*p++ = ALLONES; |
| 483 |
*p |= endmask; |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
void Type1RegisterFontFileFunctions(void) |
| 489 |
{ |
| 490 |
T1InitStdProps(); |
| 491 |
} |
| 492 |
|
| 493 |
static void FontDefaultFormat(int *bit, int *byte, int *glyphs, int *scan) { ; } |