| File: | difs/charinfo.c |
| Location: | line 510, column 3 |
| Description: | Value stored to 'dstp' is never read |
| 1 | /* |
| 2 | |
| 3 | Copyright 1990, 1991, 1998 The Open Group |
| 4 | |
| 5 | Permission to use, copy, modify, distribute, and sell this software and its |
| 6 | documentation for any purpose is hereby granted without fee, provided that |
| 7 | the above copyright notice appear in all copies and that both that |
| 8 | copyright notice and this permission notice appear in supporting |
| 9 | documentation. |
| 10 | |
| 11 | The above copyright notice and this permission notice shall be included in |
| 12 | all copies or substantial portions of the Software. |
| 13 | |
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | |
| 21 | Except as contained in this notice, the name of The Open Group shall not be |
| 22 | used in advertising or otherwise to promote the sale, use or other dealings |
| 23 | in this Software without prior written authorization from The Open Group. |
| 24 | |
| 25 | * Copyright 1990, 1991 Network Computing Devices; |
| 26 | * Portions Copyright 1987 by Digital Equipment Corporation |
| 27 | * |
| 28 | * Permission to use, copy, modify, distribute, and sell this software and |
| 29 | * its documentation for any purpose is hereby granted without fee, provided |
| 30 | * that the above copyright notice appear in all copies and that both that |
| 31 | * copyright notice and this permission notice appear in supporting |
| 32 | * documentation, and that the names of Network Computing Devices, or Digital |
| 33 | * not be used in advertising or publicity pertaining to distribution |
| 34 | * of the software without specific, written prior permission. |
| 35 | * |
| 36 | * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH |
| 37 | * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 38 | * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, |
| 39 | * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 40 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 41 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS |
| 42 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF |
| 43 | * THIS SOFTWARE. |
| 44 | */ |
| 45 | /* |
| 46 | * Defines GetExtents() and GetBitmaps(), which are |
| 47 | * called from routines in fontinfo.c. |
| 48 | * This file was once on the other side of |
| 49 | * the font library interface as util/fsfuncs.c. |
| 50 | */ |
| 51 | |
| 52 | #include "config.h" |
| 53 | |
| 54 | #include <X11/Xos.h> |
| 55 | #include "misc.h" |
| 56 | #include <X11/fonts/fontstruct.h> |
| 57 | #include <X11/fonts/fontutil.h> |
| 58 | |
| 59 | /* Don't conflict with macros/prototypes in difsutils.h */ |
| 60 | #define _HAVE_XALLOC_DECLS |
| 61 | #include <X11/fonts/fontmisc.h> |
| 62 | |
| 63 | #include "clientstr.h" |
| 64 | #define FSMD_H |
| 65 | #include <X11/fonts/FSproto.h> |
| 66 | #include "difs.h" |
| 67 | |
| 68 | #define GLWIDTHBYTESPADDED(bits,nbytes)((nbytes) == 1 ? (((bits)+7)>>3) :(nbytes) == 2 ? ((((bits )+15)>>3)&~1) :(nbytes) == 4 ? ((((bits)+31)>> 3)&~3) :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) : 0) \ |
| 69 | ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ |
| 70 | :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ |
| 71 | :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ |
| 72 | :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ |
| 73 | : 0) |
| 74 | |
| 75 | #define GLYPH_SIZE(ch, nbytes)(((nbytes)) == 1 ? ((((ch)->metrics.rightSideBearing - (ch )->metrics.leftSideBearing)+7)>>3) :((nbytes)) == 2 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing )+15)>>3)&~1) :((nbytes)) == 4 ? (((((ch)->metrics .rightSideBearing - (ch)->metrics.leftSideBearing)+31)>> 3)&~3) :((nbytes)) == 8 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing)+63)>>3)&~7) : 0 ) \ |
| 76 | GLWIDTHBYTESPADDED((ch)->metrics.rightSideBearing - \(((nbytes)) == 1 ? ((((ch)->metrics.rightSideBearing - (ch )->metrics.leftSideBearing)+7)>>3) :((nbytes)) == 2 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing )+15)>>3)&~1) :((nbytes)) == 4 ? (((((ch)->metrics .rightSideBearing - (ch)->metrics.leftSideBearing)+31)>> 3)&~3) :((nbytes)) == 8 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing)+63)>>3)&~7) : 0 ) |
| 77 | (ch)->metrics.leftSideBearing, (nbytes))(((nbytes)) == 1 ? ((((ch)->metrics.rightSideBearing - (ch )->metrics.leftSideBearing)+7)>>3) :((nbytes)) == 2 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing )+15)>>3)&~1) :((nbytes)) == 4 ? (((((ch)->metrics .rightSideBearing - (ch)->metrics.leftSideBearing)+31)>> 3)&~3) :((nbytes)) == 8 ? (((((ch)->metrics.rightSideBearing - (ch)->metrics.leftSideBearing)+63)>>3)&~7) : 0 ) |
| 78 | |
| 79 | #define n2dChars(pfi)(((pfi)->lastRow - (pfi)->firstRow + 1) * ((pfi)->lastCol - (pfi)->firstCol + 1)) (((pfi)->lastRow - (pfi)->firstRow + 1) * \ |
| 80 | ((pfi)->lastCol - (pfi)->firstCol + 1)) |
| 81 | |
| 82 | #if 0 |
| 83 | static CharInfoRec junkDefault; |
| 84 | #endif |
| 85 | |
| 86 | typedef int (*MetricsFunc)(FontPtr, unsigned long, unsigned char *, |
| 87 | FontEncoding, unsigned long *, CharInfoPtr *); |
| 88 | |
| 89 | static int |
| 90 | getCharInfos ( |
| 91 | FontPtr pfont, |
| 92 | int num_ranges, |
| 93 | fsRange *range, |
| 94 | Bool ink_metrics, |
| 95 | int *nump, /* return */ |
| 96 | CharInfoPtr **retp) /* return */ |
| 97 | { |
| 98 | CharInfoPtr *xchars, *xci; |
| 99 | int nchars; |
| 100 | FontInfoPtr pinfo = &pfont->info; |
| 101 | unsigned int r, c; |
| 102 | unsigned char ch[2]; |
| 103 | int firstCol = pinfo->firstCol; |
| 104 | int firstRow = pinfo->firstRow; |
| 105 | int lastRow = pinfo->lastRow; |
| 106 | int lastCol = pinfo->lastCol; |
| 107 | fsRange local_range, *rp; |
| 108 | int i; |
| 109 | FontEncoding encoding; |
| 110 | int err; |
| 111 | unsigned long glyphCount; |
| 112 | unsigned short defaultCh; |
| 113 | CharInfoPtr defaultPtr; |
| 114 | MetricsFunc metrics_func; |
| 115 | |
| 116 | /* |
| 117 | * compute nchars |
| 118 | */ |
| 119 | if (num_ranges == 0) { |
| 120 | if (lastRow) |
| 121 | nchars = n2dChars(pinfo)(((pinfo)->lastRow - (pinfo)->firstRow + 1) * ((pinfo)-> lastCol - (pinfo)->firstCol + 1)); |
| 122 | else |
| 123 | nchars = lastCol - firstCol + 1; |
| 124 | local_range.min_char_low = firstCol; |
| 125 | local_range.min_char_high = firstRow; |
| 126 | local_range.max_char_low = lastCol; |
| 127 | local_range.max_char_high = lastRow; |
| 128 | range = &local_range; |
| 129 | num_ranges = 1; |
| 130 | } else { |
| 131 | nchars = 0; |
| 132 | for (i = 0, rp = range; i < num_ranges; i++, rp++) { |
| 133 | if (rp->min_char_high > rp->max_char_high || |
| 134 | rp->min_char_low > rp->max_char_low) |
| 135 | return BadCharRange87; |
| 136 | nchars += (rp->max_char_high - rp->min_char_high + 1) * |
| 137 | (rp->max_char_low - rp->min_char_low + 1); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | xchars = (CharInfoPtr *) fsalloc (sizeof (CharInfoPtr) * nchars)FSalloc((unsigned long)sizeof (CharInfoPtr) * nchars); |
| 142 | if (!xchars) |
| 143 | return AllocError80; |
| 144 | bzero (xchars, sizeof (CharInfoPtr) * nchars)__builtin___memset_chk (xchars, 0, sizeof (CharInfoPtr) * nchars , __builtin_object_size (xchars, 0)); |
| 145 | |
| 146 | if (ink_metrics) |
| 147 | metrics_func = (MetricsFunc)pfont->get_metrics; |
| 148 | else |
| 149 | metrics_func = pfont->get_glyphs; |
| 150 | |
| 151 | xci = xchars; |
| 152 | encoding = Linear16Bit; |
| 153 | if (lastRow) |
| 154 | encoding = TwoD16Bit; |
| 155 | defaultCh = pinfo->defaultCh; |
| 156 | ch[0] = defaultCh >> 8; |
| 157 | ch[1] = defaultCh & 0xff; |
| 158 | /* get the default character */ |
| 159 | (*metrics_func) (pfont, 1, ch, encoding, |
| 160 | &glyphCount, &defaultPtr); |
| 161 | if (glyphCount != 1) |
| 162 | defaultPtr = NULL((void *)0); |
| 163 | |
| 164 | /* for each range, get each character individually, undoing the |
| 165 | default character substitution so we get zero metrics for |
| 166 | non-existent characters. */ |
| 167 | for (i = 0, rp = range; i < num_ranges; i++, rp++) { |
| 168 | for (r = rp->min_char_high; r <= rp->max_char_high; r++) |
| 169 | { |
| 170 | for (c = rp->min_char_low; c <= rp->max_char_low; c++) { |
| 171 | ch[0] = r; |
| 172 | ch[1] = c; |
| 173 | err = (*metrics_func) (pfont, 1, ch, encoding, |
| 174 | &glyphCount, xci); |
| 175 | if (err != Successful85) |
| 176 | { |
| 177 | fsfree (xchars)FSfree((pointer)xchars); |
| 178 | return err; |
| 179 | } |
| 180 | #if 0 |
| 181 | if (glyphCount != 1 || |
| 182 | (*xci == defaultPtr && defaultCh != ((r<<8)+c))) |
| 183 | *xci = &junkDefault; |
| 184 | #endif |
| 185 | xci++; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | *retp = xchars; |
| 190 | *nump = nchars; |
| 191 | return Successful85; |
| 192 | } |
| 193 | |
| 194 | int |
| 195 | GetExtents( |
| 196 | ClientPtr client, |
| 197 | FontPtr pfont, |
| 198 | Mask flags, |
| 199 | unsigned long num_ranges, |
| 200 | fsRange *range, |
| 201 | unsigned long *num_extents, /* return */ |
| 202 | fsXCharInfo **data) /* return */ |
| 203 | { |
| 204 | unsigned long size; |
| 205 | fsXCharInfo *ci; |
| 206 | fsXCharInfo cilocal; |
| 207 | char *pci; |
| 208 | CharInfoPtr *xchars, *xchars_cur; |
| 209 | CharInfoPtr xci; |
| 210 | int nchars; |
| 211 | int err; |
| 212 | |
| 213 | if (flags & LoadAll0x1) |
| 214 | num_ranges = 0; |
| 215 | err = getCharInfos (pfont, num_ranges, range, |
| 216 | client->major_version > 1 ? TRUE1 : FALSE0, |
| 217 | &nchars, &xchars); |
| 218 | if (err != Successful85) |
| 219 | return err; |
| 220 | |
| 221 | size = SIZEOF(fsXCharInfo)12 * nchars; |
| 222 | pci = (char *) fsalloc(size)FSalloc((unsigned long)size); |
| 223 | if (!pci) { |
| 224 | fsfree (xchars)FSfree((pointer)xchars); |
| 225 | return AllocError80; |
| 226 | } |
| 227 | |
| 228 | ci = (fsXCharInfo *) pci; |
| 229 | *num_extents = nchars; |
| 230 | |
| 231 | /* pack the data */ |
| 232 | xchars_cur = xchars; |
| 233 | while (nchars--) { |
| 234 | xci = *xchars_cur++; |
| 235 | cilocal.ascent = xci->metrics.ascent; |
| 236 | cilocal.descent = xci->metrics.descent; |
| 237 | cilocal.left = xci->metrics.leftSideBearing; |
| 238 | cilocal.right = xci->metrics.rightSideBearing; |
| 239 | cilocal.width = xci->metrics.characterWidth; |
| 240 | cilocal.attributes = xci->metrics.attributes; |
| 241 | memcpy(pci, &cilocal, SIZEOF(fsXCharInfo))__builtin___memcpy_chk (pci, &cilocal, 12, __builtin_object_size (pci, 0)); |
| 242 | pci += SIZEOF(fsXCharInfo)12; |
| 243 | } |
| 244 | |
| 245 | fsfree (xchars)FSfree((pointer)xchars); |
| 246 | |
| 247 | *data = ci; |
| 248 | |
| 249 | return Successful85; |
| 250 | } |
| 251 | |
| 252 | static int |
| 253 | packGlyphs ( |
| 254 | ClientPtr client, |
| 255 | FontPtr pfont, |
| 256 | int format, |
| 257 | Mask flags, |
| 258 | unsigned long num_ranges, |
| 259 | fsRange *range, |
| 260 | int *tsize, |
| 261 | unsigned long *num_glyphs, |
| 262 | fsOffset32 **offsets, |
| 263 | pointer *data, |
| 264 | int *freeData) |
| 265 | { |
| 266 | int i; |
| 267 | fsOffset32 *lengths, *l; |
| 268 | unsigned long size = 0; |
| 269 | pointer gdata; |
| 270 | unsigned char *gd; |
| 271 | int bitorder, byteorder, scanlinepad, scanlineunit, mappad; |
| 272 | int height = 0, dstbpr = 0, charsize = 0; |
| 273 | int dst_off = 0, src_off; |
| 274 | Bool contiguous, reformat; |
| 275 | int nchars; |
| 276 | int src_glyph_pad = pfont->glyph; |
| 277 | int src_bit_order = pfont->bit; |
| 278 | int src_byte_order = pfont->byte; |
| 279 | int err; |
| 280 | int max_ascent = 0, max_descent = 0; |
| 281 | int min_left = 0, max_right; |
| 282 | int srcbpr; |
| 283 | int lshift = 0, rshift = 0, dst_left_bytes = 0, src_left_bytes = 0; |
| 284 | unsigned char *srcp; |
| 285 | unsigned char *dstp; |
| 286 | unsigned char bits1, bits2; |
| 287 | int width; |
| 288 | int src_extra; |
| 289 | int dst_extra; |
| 290 | int r, w; |
| 291 | CharInfoPtr *bitChars, *bitCharsFree, bitc; |
| 292 | CharInfoPtr *inkChars, *inkCharsFree = NULL((void *)0), inkc; |
| 293 | FontInfoPtr pinfo = &pfont->info; |
| 294 | xCharInfo *bitm, *inkm; |
| 295 | |
| 296 | err = CheckFSFormat(format, (fsBitmapFormatMask) ~ 0, |
| 297 | &bitorder, &byteorder, &scanlineunit, &scanlinepad, &mappad); |
| 298 | |
| 299 | if (err != Successful85) |
| 300 | return err; |
| 301 | |
| 302 | if (flags & LoadAll0x1) |
| 303 | num_ranges = 0; |
| 304 | |
| 305 | err = getCharInfos (pfont, num_ranges, range, FALSE0, &nchars, &bitCharsFree); |
| 306 | |
| 307 | if (err != Successful85) |
| 308 | return err; |
| 309 | |
| 310 | /* compute dstbpr for padded out fonts */ |
| 311 | reformat = bitorder != src_bit_order || byteorder != src_byte_order; |
| 312 | |
| 313 | /* we need the ink metrics when shrink-wrapping a TE font (sigh), |
| 314 | * but only for protocol version > 1 */ |
| 315 | if (mappad != BitmapFormatImageRectMax(2L << 2) && |
| 316 | pinfo->inkMetrics && |
| 317 | client->major_version > 1) |
| 318 | { |
| 319 | err = getCharInfos (pfont, num_ranges, range, TRUE1, &nchars, &inkCharsFree); |
| 320 | if (err != Successful85) |
| 321 | { |
| 322 | fsfree (bitCharsFree)FSfree((pointer)bitCharsFree); |
| 323 | return err; |
| 324 | } |
| 325 | reformat = TRUE1; |
| 326 | } |
| 327 | |
| 328 | /* get space for glyph offsets */ |
| 329 | lengths = (fsOffset32 *) fsalloc(SIZEOF(fsOffset32) * nchars)FSalloc((unsigned long)8 * nchars); |
| 330 | if (!lengths) { |
| 331 | fsfree (bitCharsFree)FSfree((pointer)bitCharsFree); |
| 332 | fsfree (inkCharsFree)FSfree((pointer)inkCharsFree); |
| 333 | return AllocError80; |
| 334 | } |
| 335 | |
| 336 | switch (mappad) |
| 337 | { |
| 338 | case BitmapFormatImageRectMax(2L << 2): |
| 339 | max_ascent = FONT_MAX_ASCENT(pinfo)((pinfo)->fontAscent > (pinfo)->ink_maxbounds.ascent ? (pinfo)->fontAscent : (pinfo)->ink_maxbounds.ascent); |
| 340 | max_descent = FONT_MAX_DESCENT(pinfo)((pinfo)->fontDescent > (pinfo)->ink_maxbounds.descent ? (pinfo)->fontDescent : (pinfo)->ink_maxbounds.descent ); |
| 341 | height = max_ascent + max_descent; |
| 342 | /* do font ascent and font descent match bitmap bounds ? */ |
| 343 | if (height != pinfo->minbounds.ascent + pinfo->minbounds.descent) |
| 344 | reformat = TRUE1; |
| 345 | /* fall through */ |
| 346 | case BitmapFormatImageRectMaxWidth(1L << 2): |
| 347 | min_left = FONT_MIN_LEFT(pinfo)((pinfo)->ink_minbounds.leftSideBearing < 0 ? (pinfo)-> ink_minbounds.leftSideBearing : 0); |
| 348 | max_right = FONT_MAX_RIGHT(pinfo)((pinfo)->ink_maxbounds.rightSideBearing > (pinfo)-> ink_maxbounds.characterWidth ? (pinfo)->ink_maxbounds.rightSideBearing : (pinfo)->ink_maxbounds.characterWidth); |
| 349 | if (min_left != pinfo->maxbounds.leftSideBearing) |
| 350 | reformat = TRUE1; |
| 351 | if (max_right != pinfo->maxbounds.rightSideBearing) |
| 352 | reformat = TRUE1; |
| 353 | dstbpr = GLWIDTHBYTESPADDED(max_right - min_left, scanlinepad)((scanlinepad) == 1 ? (((max_right - min_left)+7)>>3) : (scanlinepad) == 2 ? ((((max_right - min_left)+15)>>3)& ~1) :(scanlinepad) == 4 ? ((((max_right - min_left)+31)>> 3)&~3) :(scanlinepad) == 8 ? ((((max_right - min_left)+63 )>>3)&~7) : 0); |
| 354 | break; |
| 355 | case BitmapFormatImageRectMin(0L << 2): |
| 356 | break; |
| 357 | } |
| 358 | if (mappad == BitmapFormatImageRectMax(2L << 2)) |
| 359 | charsize = dstbpr * height; |
| 360 | size = 0; |
| 361 | gdata = NULL((void *)0); |
| 362 | contiguous = TRUE1; |
| 363 | l = lengths; |
| 364 | inkChars = inkCharsFree; |
| 365 | bitChars = bitCharsFree; |
| 366 | for (i = 0; i < nchars; i++) |
| 367 | { |
| 368 | inkc = bitc = *bitChars++; |
| 369 | /* when ink metrics != bitmap metrics, use ink metrics */ |
| 370 | if (inkChars) |
| 371 | inkc = *inkChars++; |
| 372 | l->position = size; |
| 373 | /* |
| 374 | * Do not repad characters with no bits except for those |
| 375 | * with non-zero width. |
| 376 | */ |
| 377 | if (bitc && (bitc->bits || bitc->metrics.characterWidth)) { |
| 378 | if (!gdata) |
| 379 | gdata = (pointer) bitc->bits; |
| 380 | if ((char *) gdata + size != bitc->bits) |
| 381 | contiguous = FALSE0; |
| 382 | if (mappad == BitmapFormatImageRectMin(0L << 2)) |
| 383 | dstbpr = GLYPH_SIZE(inkc, scanlinepad)(((scanlinepad)) == 1 ? ((((inkc)->metrics.rightSideBearing - (inkc)->metrics.leftSideBearing)+7)>>3) :((scanlinepad )) == 2 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+15)>>3)&~1) :((scanlinepad )) == 4 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+31)>>3)&~3) :((scanlinepad )) == 8 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+63)>>3)&~7) : 0); |
| 384 | if (dstbpr != GLYPH_SIZE(bitc, src_glyph_pad)(((src_glyph_pad)) == 1 ? ((((bitc)->metrics.rightSideBearing - (bitc)->metrics.leftSideBearing)+7)>>3) :((src_glyph_pad )) == 2 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+15)>>3)&~1) :((src_glyph_pad )) == 4 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+31)>>3)&~3) :((src_glyph_pad )) == 8 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+63)>>3)&~7) : 0)) reformat = TRUE1; |
| 385 | if (mappad != BitmapFormatImageRectMax(2L << 2)) |
| 386 | { |
| 387 | height = inkc->metrics.ascent + inkc->metrics.descent; |
| 388 | charsize = height * dstbpr; |
| 389 | } |
| 390 | l->length = charsize; |
| 391 | size += charsize; |
| 392 | } |
| 393 | else |
| 394 | l->length = 0; |
| 395 | l++; |
| 396 | } |
| 397 | if (contiguous && !reformat) |
| 398 | { |
| 399 | *num_glyphs = nchars; |
| 400 | *freeData = FALSE0; |
| 401 | *data = gdata; |
| 402 | *tsize = size; |
| 403 | *offsets = lengths; |
| 404 | fsfree (bitCharsFree)FSfree((pointer)bitCharsFree); |
| 405 | fsfree (inkCharsFree)FSfree((pointer)inkCharsFree); |
| 406 | return Successful85; |
| 407 | } |
| 408 | if (size) |
| 409 | { |
| 410 | gdata = (pointer) fsalloc(size)FSalloc((unsigned long)size); |
| 411 | if (!gdata) { |
| 412 | fsfree (bitCharsFree)FSfree((pointer)bitCharsFree); |
| 413 | fsfree (inkCharsFree)FSfree((pointer)inkCharsFree); |
| 414 | fsfree (lengths)FSfree((pointer)lengths); |
| 415 | return AllocError80; |
| 416 | } |
| 417 | bzero ((char *) gdata, size)__builtin___memset_chk ((char *) gdata, 0, size, __builtin_object_size ((char *) gdata, 0)); |
| 418 | } |
| 419 | else |
| 420 | gdata = NULL((void *)0); |
| 421 | |
| 422 | *freeData = TRUE1; |
| 423 | l = lengths; |
| 424 | gd = gdata; |
| 425 | |
| 426 | /* finally do the work */ |
| 427 | bitChars = bitCharsFree; |
| 428 | inkChars = inkCharsFree; |
| 429 | for (i = 0; i < nchars; i++, l++) |
| 430 | { |
| 431 | inkc = bitc = *bitChars++; |
| 432 | if (inkChars) |
| 433 | inkc = *inkChars++; |
| 434 | |
| 435 | /* ignore missing chars */ |
| 436 | if (l->length == 0) |
| 437 | continue; |
| 438 | |
| 439 | bitm = &bitc->metrics; |
| 440 | inkm = &inkc->metrics; |
| 441 | |
| 442 | /* start address for the destination of bits for this char */ |
| 443 | |
| 444 | dstp = gd; |
| 445 | |
| 446 | if (mappad == BitmapFormatImageRectMax(2L << 2)) |
| 447 | height = max_ascent + max_descent; |
| 448 | else |
| 449 | height = inkm->ascent + inkm->descent; |
| 450 | |
| 451 | /* adjust destination and calculate shift offsets */ |
| 452 | switch (mappad) { |
| 453 | case BitmapFormatImageRectMax(2L << 2): |
| 454 | /* leave the first padded rows blank */ |
| 455 | if (max_ascent > inkm->ascent) |
| 456 | { |
| 457 | height -= (max_ascent - inkm->ascent); |
| 458 | dstp += dstbpr * (max_ascent - inkm->ascent); |
| 459 | } |
| 460 | if (max_descent > inkm->descent) |
| 461 | { |
| 462 | height -= (max_descent - inkm->descent); |
| 463 | } |
| 464 | /* fall thru */ |
| 465 | case BitmapFormatImageRectMaxWidth(1L << 2): |
| 466 | dst_off = inkm->leftSideBearing - min_left; |
| 467 | if (dst_off < 0) dst_off = 0; |
| 468 | break; |
| 469 | case BitmapFormatImageRectMin(0L << 2): |
| 470 | dst_off = 0; |
| 471 | dstbpr = GLYPH_SIZE(inkc, scanlinepad)(((scanlinepad)) == 1 ? ((((inkc)->metrics.rightSideBearing - (inkc)->metrics.leftSideBearing)+7)>>3) :((scanlinepad )) == 2 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+15)>>3)&~1) :((scanlinepad )) == 4 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+31)>>3)&~3) :((scanlinepad )) == 8 ? (((((inkc)->metrics.rightSideBearing - (inkc)-> metrics.leftSideBearing)+63)>>3)&~7) : 0); |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | srcbpr = GLYPH_SIZE (bitc, src_glyph_pad)(((src_glyph_pad)) == 1 ? ((((bitc)->metrics.rightSideBearing - (bitc)->metrics.leftSideBearing)+7)>>3) :((src_glyph_pad )) == 2 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+15)>>3)&~1) :((src_glyph_pad )) == 4 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+31)>>3)&~3) :((src_glyph_pad )) == 8 ? (((((bitc)->metrics.rightSideBearing - (bitc)-> metrics.leftSideBearing)+63)>>3)&~7) : 0); |
| 476 | srcp = (unsigned char *) bitc->bits; |
| 477 | |
| 478 | /* adjust source */ |
| 479 | src_off = 0; |
| 480 | if (inkm != bitm) |
| 481 | { |
| 482 | srcp += (bitm->ascent - inkm->ascent) * srcbpr; |
| 483 | src_off = inkm->leftSideBearing - bitm->leftSideBearing; |
| 484 | } |
| 485 | |
| 486 | dst_left_bytes = dst_off >> 3; |
| 487 | dst_off &= 7; |
| 488 | src_left_bytes = src_off >> 3; |
| 489 | src_off &= 7; |
| 490 | |
| 491 | /* minimum of source/dest bytes per row */ |
| 492 | width = srcbpr - src_left_bytes; |
| 493 | if (width > dstbpr - dst_left_bytes) |
| 494 | width = dstbpr - dst_left_bytes; |
| 495 | /* extra bytes in source and dest for padding */ |
| 496 | src_extra = srcbpr - width - src_left_bytes; |
| 497 | dst_extra = dstbpr - width - dst_left_bytes; |
| 498 | |
| 499 | #define MSBBitLeft(b,c)((b) << (c)) ((b) << (c)) |
| 500 | #define MSBBitRight(b,c)((b) >> (c)) ((b) >> (c)) |
| 501 | #define LSBBitLeft(b,c)((b) >> (c)) ((b) >> (c)) |
| 502 | #define LSBBitRight(b,c)((b) << (c)) ((b) << (c)) |
| 503 | |
| 504 | if (dst_off == src_off) |
| 505 | { |
| 506 | if (srcbpr == dstbpr && src_left_bytes == dst_left_bytes) |
| 507 | { |
| 508 | r = height * srcbpr; |
| 509 | memmove( dstp, srcp, r)__builtin___memmove_chk (dstp, srcp, r, __builtin_object_size (dstp, 0)); |
| 510 | dstp += r; |
Value stored to 'dstp' is never read | |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | for (r = height; r; r--) |
| 515 | { |
| 516 | dstp += dst_left_bytes; |
| 517 | srcp += src_left_bytes; |
| 518 | for (w = width; w; w--) |
| 519 | *dstp++ = *srcp++; |
| 520 | dstp += dst_extra; |
| 521 | srcp += src_extra; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | else |
| 526 | { |
| 527 | if (dst_off > src_off) |
| 528 | { |
| 529 | rshift = dst_off - src_off; |
| 530 | lshift = 8 - rshift; |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | lshift = src_off - dst_off; |
| 535 | rshift = 8 - lshift; |
| 536 | /* run the loop one fewer time if necessary */ |
| 537 | if (src_extra <= dst_extra) |
| 538 | { |
| 539 | dst_extra++; |
| 540 | width--; |
| 541 | } |
| 542 | else |
| 543 | src_extra--; |
| 544 | } |
| 545 | |
| 546 | for (r = inkm->ascent + inkm->descent; r; r--) |
| 547 | { |
| 548 | dstp += dst_left_bytes; |
| 549 | srcp += src_left_bytes; |
| 550 | bits2 = 0; |
| 551 | /* fetch first part of source when necessary */ |
| 552 | if (dst_off < src_off) |
| 553 | bits2 = *srcp++; |
| 554 | /* |
| 555 | * XXX I bet this does not work when |
| 556 | * src_bit_order != src_byte_order && scanlineunit > 1 |
| 557 | */ |
| 558 | for (w = width; w; w--) |
| 559 | { |
| 560 | bits1 = *srcp++; |
| 561 | if (src_bit_order == MSBFirst1) |
| 562 | { |
| 563 | *dstp++ = MSBBitRight(bits1, rshift)((bits1) >> (rshift)) | |
| 564 | MSBBitLeft (bits2, lshift)((bits2) << (lshift)); |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | *dstp++ = LSBBitRight(bits1, rshift)((bits1) << (rshift)) | |
| 569 | LSBBitLeft (bits2, lshift)((bits2) >> (lshift)); |
| 570 | } |
| 571 | bits2 = bits1; |
| 572 | } |
| 573 | /* get the last few bits if we have a place to store them */ |
| 574 | if (dst_extra > 0) |
| 575 | { |
| 576 | if (src_bit_order == MSBFirst1) |
| 577 | *dstp = MSBBitLeft (bits2, lshift)((bits2) << (lshift)); |
| 578 | else |
| 579 | *dstp = LSBBitLeft (bits2, lshift)((bits2) >> (lshift)); |
| 580 | } |
| 581 | dstp += dst_extra; |
| 582 | srcp += src_extra; |
| 583 | } |
| 584 | } |
| 585 | /* skip the amount we just filled in */ |
| 586 | gd += l->length; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | /* now do the bit, byte, word swapping */ |
| 591 | if (bitorder != src_bit_order) |
| 592 | BitOrderInvert(gdata, size); |
| 593 | if (byteorder != src_byte_order) |
| 594 | { |
| 595 | if (scanlineunit == 2) |
| 596 | TwoByteSwap(gdata, size); |
| 597 | else if (scanlineunit == 4) |
| 598 | FourByteSwap(gdata, size); |
| 599 | } |
| 600 | fsfree (bitCharsFree)FSfree((pointer)bitCharsFree); |
| 601 | fsfree (inkCharsFree)FSfree((pointer)inkCharsFree); |
| 602 | *num_glyphs = nchars; |
| 603 | *data = gdata; |
| 604 | *tsize = size; |
| 605 | *offsets = lengths; |
| 606 | |
| 607 | return Successful85; |
| 608 | } |
| 609 | |
| 610 | /* ARGSUSED */ |
| 611 | int |
| 612 | GetBitmaps( |
| 613 | ClientPtr client, |
| 614 | FontPtr pfont, |
| 615 | fsBitmapFormat format, |
| 616 | Mask flags, |
| 617 | unsigned long num_ranges, |
| 618 | fsRange *range, |
| 619 | int *size, |
| 620 | unsigned long *num_glyphs, |
| 621 | fsOffset32 **offsets, |
| 622 | pointer *data, |
| 623 | int *freeData) |
| 624 | { |
| 625 | int err; |
| 626 | |
| 627 | assert(pfont)((void)0); |
| 628 | |
| 629 | *size = 0; |
| 630 | *data = (pointer) 0; |
| 631 | |
| 632 | err = LoadGlyphRanges(client, pfont, TRUE1, num_ranges * 2, 0, |
| 633 | (fsChar2b *)range); |
| 634 | |
| 635 | if (err != Successful85) |
| 636 | return err; |
| 637 | |
| 638 | return packGlyphs (client, pfont, format, flags, |
| 639 | num_ranges, range, size, num_glyphs, |
| 640 | offsets, data, freeData); |
| 641 | } |