bitmap.c revision 41c30155
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 break; 68 if (pFont->info.allExist && pDefault) { 69 while (count--) { 70 c = (*chars++) - firstCol; 71 if (c < numCols) 72 *glyphs++ = ACCESSENCODING(encoding,c); 73 else 74 *glyphs++ = pDefault; 75 } 76 } else { 77 while (count--) { 78 c = (*chars++) - firstCol; 79 if (c < numCols && (pci = ACCESSENCODING(encoding,c))) 80 *glyphs++ = pci; 81 else if (pDefault) 82 *glyphs++ = pDefault; 83 } 84 } 85 break; 86 case Linear16Bit: 87 if (pFont->info.allExist && pDefault) { 88 while (count--) { 89 c = *chars++ << 8; 90 c = (c | *chars++) - firstCol; 91 if (c < numCols) 92 *glyphs++ = ACCESSENCODING(encoding,c); 93 else 94 *glyphs++ = pDefault; 95 } 96 } else { 97 while (count--) { 98 c = *chars++ << 8; 99 c = (c | *chars++) - firstCol; 100 if (c < numCols && (pci = ACCESSENCODING(encoding,c))) 101 *glyphs++ = pci; 102 else if (pDefault) 103 *glyphs++ = pDefault; 104 } 105 } 106 break; 107 108 case TwoD16Bit: 109 firstRow = pFont->info.firstRow; 110 numRows = pFont->info.lastRow - firstRow + 1; 111 while (count--) { 112 r = (*chars++) - firstRow; 113 c = (*chars++) - firstCol; 114 if (r < numRows && c < numCols && 115 (pci = ACCESSENCODING(encoding, r * numCols + c))) 116 *glyphs++ = pci; 117 else if (pDefault) 118 *glyphs++ = pDefault; 119 } 120 break; 121 } 122 *glyphCount = glyphs - glyphsBase; 123 return Successful; 124} 125 126static CharInfoRec nonExistantChar; 127 128int 129bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars, 130 FontEncoding charEncoding, 131 unsigned long *glyphCount, /* RETURN */ 132 xCharInfo **glyphs) /* RETURN */ 133{ 134 int ret; 135 xCharInfo *ink_metrics; 136 CharInfoPtr metrics; 137 BitmapFontPtr bitmapFont; 138 CharInfoPtr oldDefault; 139 int i; 140 141 bitmapFont = (BitmapFontPtr) pFont->fontPrivate; 142 oldDefault = bitmapFont->pDefault; 143 bitmapFont->pDefault = &nonExistantChar; 144 ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs); 145 if (ret == Successful) { 146 if (bitmapFont->ink_metrics) { 147 metrics = bitmapFont->metrics; 148 ink_metrics = bitmapFont->ink_metrics; 149 for (i = 0; i < *glyphCount; i++) { 150 if (glyphs[i] != (xCharInfo *) & nonExistantChar) 151 glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics); 152 } 153 } 154 } 155 bitmapFont->pDefault = oldDefault; 156 return ret; 157} 158