bitmap.c revision e24f450b
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 "fntfilst.h" 36#include "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 CharInfoPtr **encoding; 53 CharInfoPtr pDefault; 54 55 bitmapFont = (BitmapFontPtr) pFont->fontPrivate; 56 encoding = bitmapFont->encoding; 57 pDefault = bitmapFont->pDefault; 58 firstCol = pFont->info.firstCol; 59 numCols = pFont->info.lastCol - firstCol + 1; 60 glyphsBase = glyphs; 61 switch (charEncoding) { 62 63 case Linear8Bit: 64 case TwoD8Bit: 65 if (pFont->info.firstRow > 0) { 66 if (pDefault) 67 while (count--) 68 *glyphs++ = pDefault; 69 break; 70 } 71 if (pFont->info.allExist && pDefault) { 72 while (count--) { 73 c = (*chars++) - firstCol; 74 if (c < numCols) 75 *glyphs++ = ACCESSENCODING(encoding, c); 76 else 77 *glyphs++ = pDefault; 78 } 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 } 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 unsigned int r; 118 119 r = (*chars++) - firstRow; 120 c = (*chars++) - firstCol; 121 if (r < numRows && c < numCols && 122 (pci = ACCESSENCODING(encoding, r * numCols + c))) 123 *glyphs++ = pci; 124 else if (pDefault) 125 *glyphs++ = pDefault; 126 } 127 break; 128 } 129 *glyphCount = glyphs - glyphsBase; 130 return Successful; 131} 132 133static CharInfoRec nonExistantChar; 134 135int 136bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars, 137 FontEncoding charEncoding, 138 unsigned long *glyphCount, /* RETURN */ 139 xCharInfo ** glyphs) /* RETURN */ 140{ 141 int ret; 142 BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate; 143 CharInfoPtr oldDefault = bitmapFont->pDefault; 144 145 bitmapFont->pDefault = &nonExistantChar; 146 ret = 147 bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, 148 (CharInfoPtr *) glyphs); 149 if (ret == Successful) { 150 if (bitmapFont->ink_metrics) { 151 CharInfoPtr metrics = bitmapFont->metrics; 152 xCharInfo *ink_metrics = bitmapFont->ink_metrics; 153 154 for (unsigned long i = 0; i < *glyphCount; i++) { 155 if (glyphs[i] != (xCharInfo *) & nonExistantChar) 156 glyphs[i] = 157 ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics); 158 } 159 } 160 } 161 bitmapFont->pDefault = oldDefault; 162 return ret; 163} 164