]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/fontfile/bitsource.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / font / fontfile / bitsource.c
1 /* $XConsortium: bitsource.c,v 1.9 94/04/17 20:16:59 gildea Exp $ */
2
3 /*
4
5 Copyright (c) 1991  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27
28 */
29
30 /*
31  * Author:  Keith Packard, MIT X Consortium
32  */
33
34 #include "fntfilst.h"
35
36 BitmapSourcesRec        FontFileBitmapSources;
37
38 Bool
39 FontFileRegisterBitmapSource (fpe)
40     FontPathElementPtr  fpe;
41 {
42     FontPathElementPtr  *new;
43     int                 i;
44     int                 newsize;
45
46     for (i = 0; i < FontFileBitmapSources.count; i++)
47         if (FontFileBitmapSources.fpe[i] == fpe)
48             return TRUE;
49     if (FontFileBitmapSources.count == FontFileBitmapSources.size)
50     {
51         newsize = FontFileBitmapSources.size + 4;
52         new = (FontPathElementPtr *) xrealloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
53         if (!new)
54             return FALSE;
55         FontFileBitmapSources.size = newsize;
56         FontFileBitmapSources.fpe = new;
57     }
58     FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe;
59     return TRUE;
60 }
61
62 void
63 FontFileUnregisterBitmapSource (fpe)
64     FontPathElementPtr  fpe;
65 {
66     int     i;
67
68     for (i = 0; i < FontFileBitmapSources.count; i++)
69         if (FontFileBitmapSources.fpe[i] == fpe)
70         {
71             FontFileBitmapSources.count--;
72             if (FontFileBitmapSources.count == 0)
73             {
74                 FontFileBitmapSources.size = 0;
75                 xfree (FontFileBitmapSources.fpe);
76                 FontFileBitmapSources.fpe = 0;
77             }
78             else
79             {
80                 for (; i < FontFileBitmapSources.count; i++)
81                     FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1];
82             }
83             break;
84         }
85 }
86
87 /*
88  * Our set_path_hook: unregister all bitmap sources.
89  * This is necessary because already open fonts will keep their FPEs
90  * allocated, but they may not be on the new font path.
91  * The bitmap sources in the new path will be registered by the init_func.
92  */
93 void
94 FontFileEmptyBitmapSource()
95 {
96     if (FontFileBitmapSources.count == 0)
97         return;
98
99     FontFileBitmapSources.count = 0;
100     FontFileBitmapSources.size = 0;
101     xfree (FontFileBitmapSources.fpe);
102     FontFileBitmapSources.fpe = 0;
103 }
104
105 FontFileMatchBitmapSource (fpe, pFont, flags, entry, zeroPat, vals, format, fmask, noSpecificSize)
106     FontPathElementPtr  fpe;
107     FontPtr             *pFont;
108     int                 flags;
109     FontEntryPtr        entry;
110     FontNamePtr         zeroPat;
111     FontScalablePtr     vals;
112     fsBitmapFormat      format;
113     fsBitmapFormatMask  fmask;
114     Bool                noSpecificSize;
115 {
116     int                 source;
117     FontEntryPtr        zero;
118     FontBitmapEntryPtr  bitmap;
119     int                 ret;
120     FontDirectoryPtr    dir;
121     FontScaledPtr       scaled;
122
123     /*
124      * Look through all the registered bitmap sources for
125      * the same zero name as ours; entries along that one
126      * can be scaled as desired.
127      */
128     ret = BadFontName;
129     for (source = 0; source < FontFileBitmapSources.count; source++)
130     {
131         if (FontFileBitmapSources.fpe[source] == fpe)
132             continue;
133         dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
134         zero = FontFileFindNameInDir (&dir->scalable, zeroPat);
135         if (!zero)
136             continue;
137         scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize);
138         if (scaled)
139         {
140             if (scaled->pFont)
141             {
142                 *pFont = scaled->pFont;
143                 (*pFont)->fpe = FontFileBitmapSources.fpe[source];
144                 ret = Successful;
145             }
146             else if (scaled->bitmap)
147             {
148                 entry = scaled->bitmap;
149                 bitmap = &entry->u.bitmap;
150                 if (bitmap->pFont)
151                 {
152                     *pFont = bitmap->pFont;
153                     (*pFont)->fpe = FontFileBitmapSources.fpe[source];
154                     ret = Successful;
155                 }
156                 else
157                 {
158                     ret = FontFileOpenBitmap (
159                                 FontFileBitmapSources.fpe[source],
160                                 pFont, flags, entry, format, fmask);
161                     if (ret == Successful && *pFont)
162                         (*pFont)->fpe = FontFileBitmapSources.fpe[source];
163                 }
164             }
165             else /* "cannot" happen */
166             {
167                 ret = BadFontName;
168             }
169             break;
170         }
171     }
172     return ret;
173 }