]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/bitmap/bitmaputil.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / lib / font / bitmap / bitmaputil.c
1 /* $XConsortium: bitmaputil.c,v 1.6 94/04/17 20:17:12 gildea Exp $ */
2
3 /*
4
5 Copyright (c) 1990, 1994  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 #include "fntfilst.h"
34 #include "bitmap.h"
35
36 #ifndef MAXSHORT
37 #define MAXSHORT    32767
38 #endif
39
40 #ifndef MINSHORT
41 #define MINSHORT    -32768
42 #endif
43
44 static xCharInfo initMinMetrics = {
45 MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, 0xFFFF};
46 static xCharInfo initMaxMetrics = {
47 MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
48
49 #define MINMAX(field,ci) \
50         if (minbounds->field > (ci)->field) \
51              minbounds->field = (ci)->field; \
52         if (maxbounds->field < (ci)->field) \
53              maxbounds->field = (ci)->field;
54
55 #define COMPUTE_MINMAX(ci) \
56     if ((ci)->ascent != -(ci)->descent || \
57         (ci)->leftSideBearing != (ci)->rightSideBearing || \
58         (ci)->characterWidth) \
59     { \
60         MINMAX(ascent, (ci)); \
61         MINMAX(descent, (ci)); \
62         MINMAX(leftSideBearing, (ci)); \
63         MINMAX(rightSideBearing, (ci)); \
64         MINMAX(characterWidth, (ci)); \
65     }
66
67 void
68 bitmapComputeFontBounds(pFont)
69     FontPtr     pFont;
70 {
71     BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
72     int         nchars;
73     int         r,
74                 c;
75     CharInfoPtr ci,
76                *pci;
77     int         maxOverlap;
78     int         overlap;
79     xCharInfo  *minbounds,
80                *maxbounds;
81     int         i;
82     int         numneg = 0, numpos = 0;
83
84     if (bitmapFont->bitmapExtra) {
85         minbounds = &bitmapFont->bitmapExtra->info.minbounds;
86         maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
87     } else {
88         minbounds = &pFont->info.minbounds;
89         maxbounds = &pFont->info.maxbounds;
90     }
91     *minbounds = initMinMetrics;
92     *maxbounds = initMaxMetrics;
93     maxOverlap = MINSHORT;
94     nchars = bitmapFont->num_chars;
95     for (i = 0, ci = bitmapFont->metrics; i < nchars; i++, ci++) {
96         COMPUTE_MINMAX(&ci->metrics);
97         if (ci->metrics.characterWidth < 0)
98             numneg++;
99         else
100             numpos++;
101         minbounds->attributes &= ci->metrics.attributes;
102         maxbounds->attributes |= ci->metrics.attributes;
103         overlap = ci->metrics.rightSideBearing - ci->metrics.characterWidth;
104         if (maxOverlap < overlap)
105             maxOverlap = overlap;
106     }
107     if (bitmapFont->bitmapExtra) {
108         if (numneg > numpos)
109             bitmapFont->bitmapExtra->info.drawDirection = RightToLeft;
110         else
111             bitmapFont->bitmapExtra->info.drawDirection = LeftToRight;
112         bitmapFont->bitmapExtra->info.maxOverlap = maxOverlap;
113         minbounds = &pFont->info.minbounds;
114         maxbounds = &pFont->info.maxbounds;
115         *minbounds = initMinMetrics;
116         *maxbounds = initMaxMetrics;
117         pci = bitmapFont->encoding;
118         maxOverlap = MINSHORT;
119         for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
120             for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
121                 ci = *pci++;
122                 if (ci) {
123                     COMPUTE_MINMAX(&ci->metrics);
124                     if (ci->metrics.characterWidth < 0)
125                         numneg++;
126                     else
127                         numpos++;
128                     minbounds->attributes &= ci->metrics.attributes;
129                     maxbounds->attributes |= ci->metrics.attributes;
130                     overlap = ci->metrics.rightSideBearing -
131                         ci->metrics.characterWidth;
132                     if (maxOverlap < overlap)
133                         maxOverlap = overlap;
134                 }
135             }
136         }
137     }
138     if (numneg > numpos)
139         pFont->info.drawDirection = RightToLeft;
140     else
141         pFont->info.drawDirection = LeftToRight;
142     pFont->info.maxOverlap = maxOverlap;
143 }
144
145 void
146 bitmapComputeFontInkBounds(pFont)
147     FontPtr     pFont;
148 {
149     BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
150     int         nchars;
151     int         r,
152                 c;
153     CharInfoPtr *pci,
154                 cit;
155     xCharInfo  *ci;
156     int         offset;
157     xCharInfo  *minbounds,
158                *maxbounds;
159     int         i;
160
161     if (!bitmapFont->ink_metrics) {
162         if (bitmapFont->bitmapExtra) {
163             bitmapFont->bitmapExtra->info.ink_minbounds = bitmapFont->bitmapExtra->info.minbounds;
164             bitmapFont->bitmapExtra->info.ink_maxbounds = bitmapFont->bitmapExtra->info.maxbounds;
165         }
166         pFont->info.ink_minbounds = pFont->info.minbounds;
167         pFont->info.ink_maxbounds = pFont->info.maxbounds;
168     } else {
169         if (bitmapFont->bitmapExtra) {
170             minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
171             maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
172         } else {
173             minbounds = &pFont->info.ink_minbounds;
174             maxbounds = &pFont->info.ink_maxbounds;
175         }
176         *minbounds = initMinMetrics;
177         *maxbounds = initMaxMetrics;
178         nchars = bitmapFont->num_chars;
179         for (i = 0, ci = bitmapFont->ink_metrics; i < nchars; i++, ci++) {
180             COMPUTE_MINMAX(ci);
181             minbounds->attributes &= ci->attributes;
182             maxbounds->attributes |= ci->attributes;
183         }
184         if (bitmapFont->bitmapExtra) {
185             minbounds = &pFont->info.ink_minbounds;
186             maxbounds = &pFont->info.ink_maxbounds;
187             *minbounds = initMinMetrics;
188             *maxbounds = initMaxMetrics;
189             pci = bitmapFont->encoding;
190             for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
191                 for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
192                     cit = *pci++;
193                     if (cit) {
194                         offset = cit - bitmapFont->metrics;
195                         ci = &bitmapFont->ink_metrics[offset];
196                         COMPUTE_MINMAX(ci);
197                         minbounds->attributes &= ci->attributes;
198                         maxbounds->attributes |= ci->attributes;
199                     }
200                 }
201             }
202         }
203     }
204 }
205
206 Bool
207 bitmapAddInkMetrics(pFont)
208     FontPtr     pFont;
209 {
210     BitmapFontPtr  bitmapFont;
211     int         i;
212
213     bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
214     bitmapFont->ink_metrics = (xCharInfo *) xalloc(bitmapFont->num_chars * sizeof(xCharInfo));
215     if (!bitmapFont->ink_metrics)
216         return FALSE;
217     for (i = 0; i < bitmapFont->num_chars; i++)
218         FontCharInkMetrics(pFont, &bitmapFont->metrics[i], &bitmapFont->ink_metrics[i]);
219     pFont->info.inkMetrics = TRUE;
220     return TRUE;
221 }
222
223 /* ARGSUSED */
224 int
225 bitmapComputeWeight(pFont)
226     FontPtr     pFont;
227 {
228     return 10;
229 }