format.c revision 23a0898a
1/* $Xorg: format.c,v 1.4 2001/02/09 02:04:04 xorgcvs Exp $ */ 2/* 3 * Copyright 1990, 1991 Network Computing Devices; 4 * Portions Copyright 1987 by Digital Equipment Corporation 5 * 6 * Permission to use, copy, modify, distribute, and sell this software and its 7 * documentation for any purpose is hereby granted without fee, provided that 8 * the above copyright notice appear in all copies and that both that 9 * copyright notice and this permission notice appear in supporting 10 * documentation, and that the names of Network Computing Devices or Digital 11 * not be used in advertising or publicity pertaining to distribution of the 12 * software without specific, written prior permission. Network Computing 13 * Devices and Digital make no representations about the suitability of 14 * this software for any purpose. It is provided "as is" without express 15 * or implied warranty. 16 * 17 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH 18 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 19 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE 20 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 */ 25 26/* 27 28Copyright 1987, 1998 The Open Group 29 30Permission to use, copy, modify, distribute, and sell this software and its 31documentation for any purpose is hereby granted without fee, provided that 32the above copyright notice appear in all copies and that both that 33copyright notice and this permission notice appear in supporting 34documentation. 35 36The above copyright notice and this permission notice shall be included 37in all copies or substantial portions of the Software. 38 39THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 40OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 41MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 42IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 43OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 44ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 45OTHER DEALINGS IN THE SOFTWARE. 46 47Except as contained in this notice, the name of The Open Group shall 48not be used in advertising or otherwise to promote the sale, use or 49other dealings in this Software without prior written authorization 50from The Open Group. 51 52*/ 53/* $XFree86: xc/lib/font/util/format.c,v 1.4 2001/01/17 19:43:33 dawes Exp $ */ 54 55#ifdef HAVE_CONFIG_H 56#include <config.h> 57#endif 58#include <X11/fonts/FSproto.h> 59#include <X11/fonts/font.h> 60#include <X11/fonts/fontstruct.h> 61#include <X11/fonts/fontutil.h> 62 63int 64CheckFSFormat(fsBitmapFormat format, 65 fsBitmapFormatMask fmask, 66 int *bit_order, 67 int *byte_order, 68 int *scan, 69 int *glyph, 70 int *image) 71{ 72 /* convert format to what the low levels want */ 73 if (fmask & BitmapFormatMaskBit) { 74 *bit_order = format & BitmapFormatBitOrderMask; 75 *bit_order = (*bit_order == BitmapFormatBitOrderMSB) 76 ? MSBFirst : LSBFirst; 77 } 78 if (fmask & BitmapFormatMaskByte) { 79 *byte_order = format & BitmapFormatByteOrderMask; 80 *byte_order = (*byte_order == BitmapFormatByteOrderMSB) 81 ? MSBFirst : LSBFirst; 82 } 83 if (fmask & BitmapFormatMaskScanLineUnit) { 84 *scan = format & BitmapFormatScanlineUnitMask; 85 /* convert byte paddings into byte counts */ 86 switch (*scan) { 87 case BitmapFormatScanlineUnit8: 88 *scan = 1; 89 break; 90 case BitmapFormatScanlineUnit16: 91 *scan = 2; 92 break; 93 case BitmapFormatScanlineUnit32: 94 *scan = 4; 95 break; 96 default: 97 return BadFontFormat; 98 } 99 } 100 if (fmask & BitmapFormatMaskScanLinePad) { 101 *glyph = format & BitmapFormatScanlinePadMask; 102 /* convert byte paddings into byte counts */ 103 switch (*glyph) { 104 case BitmapFormatScanlinePad8: 105 *glyph = 1; 106 break; 107 case BitmapFormatScanlinePad16: 108 *glyph = 2; 109 break; 110 case BitmapFormatScanlinePad32: 111 *glyph = 4; 112 break; 113 default: 114 return BadFontFormat; 115 } 116 } 117 if (fmask & BitmapFormatMaskImageRectangle) { 118 *image = format & BitmapFormatImageRectMask; 119 120 if (*image != BitmapFormatImageRectMin && 121 *image != BitmapFormatImageRectMaxWidth && 122 *image != BitmapFormatImageRectMax) 123 return BadFontFormat; 124 } 125 return Successful; 126} 127