| 1 |
/* |
| 2 |
|
| 3 |
Copyright 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 |
*/ |
| 26 |
|
| 27 |
/* |
| 28 |
* Author: Keith Packard, MIT X Consortium |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifdef HAVE_CONFIG_H |
| 32 |
#include <config.h> |
| 33 |
#endif |
| 34 |
#include "libxfontint.h" |
| 35 |
|
| 36 |
#include <X11/fonts/fntfilst.h> |
| 37 |
#include <X11/fonts/bitmap.h> |
| 38 |
|
| 39 |
int |
| 40 |
bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars, |
| 41 |
FontEncoding charEncoding, |
| 42 |
unsigned long *glyphCount, /* RETURN */ |
| 43 |
CharInfoPtr *glyphs) /* RETURN */ |
| 44 |
{ |
| 45 |
BitmapFontPtr bitmapFont; |
| 46 |
unsigned int firstCol; |
| 47 |
register unsigned int numCols; |
| 48 |
unsigned int firstRow; |
| 49 |
unsigned int numRows; |
| 50 |
CharInfoPtr *glyphsBase; |
| 51 |
register unsigned int c; |
| 52 |
register CharInfoPtr pci; |
| 53 |
unsigned int r; |
| 54 |
CharInfoPtr **encoding; |
| 55 |
CharInfoPtr pDefault; |
| 56 |
|
| 57 |
bitmapFont = (BitmapFontPtr) pFont->fontPrivate; |
| 58 |
encoding = bitmapFont->encoding; |
| 59 |
pDefault = bitmapFont->pDefault; |
| 60 |
firstCol = pFont->info.firstCol; |
| 61 |
numCols = pFont->info.lastCol - firstCol + 1; |
| 62 |
glyphsBase = glyphs; |
| 63 |
switch (charEncoding) { |
| 64 |
|
| 65 |
case Linear8Bit: |
| 66 |
case TwoD8Bit: |
| 67 |
if (pFont->info.firstRow > 0) { |
| 68 |
if (pDefault) |
| 69 |
while (count--) |
| 70 |
*glyphs++ = pDefault; |
| 71 |
break; |
| 72 |
} |
| 73 |
if (pFont->info.allExist && pDefault) { |
| 74 |
while (count--) { |
| 75 |
c = (*chars++) - firstCol; |
| 76 |
if (c < numCols) |
| 77 |
*glyphs++ = ACCESSENCODING(encoding,c); |
| 78 |
else |
| 79 |
*glyphs++ = pDefault; |
| 80 |
} |
| 81 |
} else { |
| 82 |
while (count--) { |
| 83 |
c = (*chars++) - firstCol; |
| 84 |
if (c < numCols && (pci = ACCESSENCODING(encoding,c))) |
| 85 |
*glyphs++ = pci; |
| 86 |
else if (pDefault) |
| 87 |
*glyphs++ = pDefault; |
| 88 |
} |
| 89 |
} |
| 90 |
break; |
| 91 |
case Linear16Bit: |
| 92 |
if (pFont->info.allExist && pDefault) { |
| 93 |
while (count--) { |
| 94 |
c = *chars++ << 8; |
| 95 |
c = (c | *chars++) - firstCol; |
| 96 |
if (c < numCols) |
| 97 |
*glyphs++ = ACCESSENCODING(encoding,c); |
| 98 |
else |
| 99 |
*glyphs++ = pDefault; |
| 100 |
} |
| 101 |
} else { |
| 102 |
while (count--) { |
| 103 |
c = *chars++ << 8; |
| 104 |
c = (c | *chars++) - firstCol; |
| 105 |
if (c < numCols && (pci = ACCESSENCODING(encoding,c))) |
| 106 |
*glyphs++ = pci; |
| 107 |
else if (pDefault) |
| 108 |
*glyphs++ = pDefault; |
| 109 |
} |
| 110 |
} |
| 111 |
break; |
| 112 |
|
| 113 |
case TwoD16Bit: |
| 114 |
firstRow = pFont->info.firstRow; |
| 115 |
numRows = pFont->info.lastRow - firstRow + 1; |
| 116 |
while (count--) { |
| 117 |
r = (*chars++) - firstRow; |
| 118 |
c = (*chars++) - firstCol; |
| 119 |
if (r < numRows && c < numCols && |
| 120 |
(pci = ACCESSENCODING(encoding, r * numCols + c))) |
| 121 |
*glyphs++ = pci; |
| 122 |
else if (pDefault) |
| 123 |
*glyphs++ = pDefault; |
| 124 |
} |
| 125 |
break; |
| 126 |
} |
| 127 |
*glyphCount = glyphs - glyphsBase; |
| 128 |
return Successful; |
| 129 |
} |
| 130 |
|
| 131 |
static CharInfoRec nonExistantChar; |
| 132 |
|
| 133 |
int |
| 134 |
bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars, |
| 135 |
FontEncoding charEncoding, |
| 136 |
unsigned long *glyphCount, /* RETURN */ |
| 137 |
xCharInfo **glyphs) /* RETURN */ |
| 138 |
{ |
| 139 |
int ret; |
| 140 |
xCharInfo *ink_metrics; |
| 141 |
CharInfoPtr metrics; |
| 142 |
BitmapFontPtr bitmapFont; |
| 143 |
CharInfoPtr oldDefault; |
| 144 |
int i; |
| 145 |
|
| 146 |
bitmapFont = (BitmapFontPtr) pFont->fontPrivate; |
| 147 |
oldDefault = bitmapFont->pDefault; |
| 148 |
bitmapFont->pDefault = &nonExistantChar; |
| 149 |
ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs); |
| 150 |
if (ret == Successful) { |
| 151 |
if (bitmapFont->ink_metrics) { |
| 152 |
metrics = bitmapFont->metrics; |
| 153 |
ink_metrics = bitmapFont->ink_metrics; |
| 154 |
for (i = 0; i < *glyphCount; i++) { |
| 155 |
if (glyphs[i] != (xCharInfo *) & nonExistantChar) |
| 156 |
glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
bitmapFont->pDefault = oldDefault; |
| 161 |
return ret; |
| 162 |
} |