bitmap.c revision 0145ab54
1/* 2 3Copyright 1991, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in 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 35#include <X11/fonts/fntfilst.h> 36#include <X11/fonts/bitmap.h> 37 38int 39bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars, 40 FontEncoding charEncoding, 41 unsigned long *glyphCount, /* RETURN */ 42 CharInfoPtr *glyphs) /* RETURN */ 43{ 44 BitmapFontPtr bitmapFont; 45 unsigned int firstCol; 46 register unsigned int numCols; 47 unsigned int firstRow; 48 unsigned int numRows; 49 CharInfoPtr *glyphsBase; 50 register unsigned int c; 51 register CharInfoPtr pci; 52 unsigned int r; 53 CharInfoPtr **encoding; 54 CharInfoPtr pDefault; 55 56 bitmapFont = (BitmapFontPtr) pFont->fontPrivate; 57 encoding = bitmapFont->encoding; 58 pDefault = bitmapFont->pDefault; 59 firstCol = pFont->info.firstCol; 60 numCols = pFont->info.lastCol - firstCol + 1; 61 glyphsBase = glyphs; 62 switch (charEncoding) { 63 64 case Linear8Bit: 65 case TwoD8Bit: 66 if (pFont->info.firstRow > 0) { 67 if (pDefault) 68 while (count--) 69 *glyphs++ = pDefault; 70 break; 71 } 72 if (pFont->info.allExist && pDefault) { 73 while (count--) { 74 c = (*chars++) - firstCol; 75 if (c < numCols) 76 *glyphs++ = ACCESSENCODING(encoding,c); 77 else 78 *glyphs++ = pDefault; 79 } 80 } else { 81 while (count--) { 82 c = (*chars++) - firstCol; 83 if (c < numCols && (pci = ACCESSENCODING(encoding,c))) 84 *glyphs++ = pci; 85 else if (pDefault) 86 *glyphs++ = pDefault; 87 } 88 } 89 break; 90 case Linear16Bit: 91 if (pFont->info.allExist && pDefault) { 92 while (count--) { 93 c = *chars++ << 8; 94 c = (c | *chars++) - firstCol; 95 if (c < numCols) 96 *glyphs++ = ACCESSENCODING(encoding,c); 97 else 98 *glyphs++ = pDefault; 99 } 100 } else { 101 while (count--) { 102 c = *chars++ << 8; 103 c = (c | *chars++) - firstCol; 104 if (c < numCols && (pci = ACCESSENCODING(encoding,c))) 105 *glyphs++ = pci; 106 else if (pDefault) 107 *glyphs++ = pDefault; 108 } 109 } 110 break; 111 112 case TwoD16Bit: 113 firstRow = pFont->info.firstRow; 114 numRows = pFont->info.lastRow - firstRow + 1; 115 while (count--) { 116 r = (*chars++) - firstRow; 117 c = (*chars++) - firstCol; 118 if (r < numRows && c < numCols && 119 (pci = ACCESSENCODING(encoding, r * numCols + c))) 120 *glyphs++ = pci; 121 else if (pDefault) 122 *glyphs++ = pDefault; 123 } 124 break; 125 } 126 *glyphCount = glyphs - glyphsBase; 127 return Successful; 128} 129 130static CharInfoRec nonExistantChar; 131 132int 133bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars, 134 FontEncoding charEncoding, 135 unsigned long *glyphCount, /* RETURN */ 136 xCharInfo **glyphs) /* RETURN */ 137{ 138 int ret; 139 xCharInfo *ink_metrics; 140 CharInfoPtr metrics; 141 BitmapFontPtr bitmapFont; 142 CharInfoPtr oldDefault; 143 int i; 144 145 bitmapFont = (BitmapFontPtr) pFont->fontPrivate; 146 oldDefault = bitmapFont->pDefault; 147 bitmapFont->pDefault = &nonExistantChar; 148 ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs); 149 if (ret == Successful) { 150 if (bitmapFont->ink_metrics) { 151 metrics = bitmapFont->metrics; 152 ink_metrics = bitmapFont->ink_metrics; 153 for (i = 0; i < *glyphCount; i++) { 154 if (glyphs[i] != (xCharInfo *) & nonExistantChar) 155 glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics); 156 } 157 } 158 } 159 bitmapFont->pDefault = oldDefault; 160 return ret; 161} 162