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