beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luafontloader / fontforge / fontforge / fontviewbase.c
blobaa0ed46aeb8dc556529b2e483bb14ce8aef7ca1c
1 /* Copyright (C) 2000-2008 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "pfaedit.h"
28 #include "baseviews.h"
29 #include "psfont.h"
30 #include <ustring.h>
31 #include <utype.h>
32 #include <chardata.h>
33 #include <math.h>
34 #include <unistd.h>
35 #include <gfile.h>
37 static FontViewBase *fv_list=NULL;
39 extern int onlycopydisplayed;
40 float joinsnap=0;
43 /* FV Interface */
45 static FontViewBase *_FontViewBaseCreate(SplineFont *sf) {
46 FontViewBase *fv = gcalloc(1,sizeof(FontViewBase));
47 int i;
49 fv->nextsame = sf->fv;
50 fv->active_layer = ly_fore;
51 sf->fv = fv;
52 if ( sf->mm!=NULL ) {
53 sf->mm->normal->fv = fv;
54 for ( i = 0; i<sf->mm->instance_count; ++i )
55 sf->mm->instances[i]->fv = fv;
57 if ( sf->subfontcnt==0 ) {
58 fv->sf = sf;
59 if ( fv->nextsame!=NULL ) {
60 fv->map = EncMapCopy(fv->nextsame->map);
61 fv->normal = fv->nextsame->normal==NULL ? NULL : EncMapCopy(fv->nextsame->normal);
62 } else if ( sf->compacted ) {
63 fv->normal = sf->map;
64 fv->map = CompactEncMap(EncMapCopy(sf->map),sf);
65 } else {
66 fv->map = sf->map;
67 fv->normal = NULL;
69 } else {
70 fv->cidmaster = sf;
71 for ( i=0; i<sf->subfontcnt; ++i )
72 sf->subfonts[i]->fv = fv;
73 for ( i=0; i<sf->subfontcnt; ++i ) /* Search for a subfont that contains more than ".notdef" (most significant in .gai fonts) */
74 if ( sf->subfonts[i]->glyphcnt>1 ) {
75 fv->sf = sf->subfonts[i];
76 break;
78 if ( fv->sf==NULL )
79 fv->sf = sf->subfonts[0];
80 sf = fv->sf;
81 if ( fv->nextsame==NULL ) EncMapFree(sf->map);
82 fv->map = EncMap1to1(sf->glyphcnt);
84 fv->selected = gcalloc(fv->map->enccount,sizeof(char));
86 #ifndef _NO_PYTHON
87 PyFF_InitFontHook(fv);
88 #endif
89 return( fv );
92 static FontViewBase *FontViewBase_Create(SplineFont *sf,int hide) {
93 FontViewBase *fv = _FontViewBaseCreate(sf);
94 (void)hide;
95 return( fv );
98 static FontViewBase *FontViewBase_Append(FontViewBase *fv) {
99 /* Normally fontviews get added to the fv list when their windows are */
100 /* created. but we don't create any windows here, so... */
101 FontViewBase *test;
103 if ( fv_list==NULL ) fv_list = fv;
104 else {
105 for ( test = fv_list; test->next!=NULL; test=test->next );
106 test->next = fv;
108 return( fv );
111 static void FontViewBase_Free(FontViewBase *fv) {
112 int i;
113 FontViewBase *prev;
115 if (fv->cidmaster)
116 EncMapFree(fv->cidmaster->map);
118 if ( fv->nextsame==NULL && fv->sf->fv==fv ) {
119 EncMapFree(fv->map);
120 SplineFontFree(fv->cidmaster?fv->cidmaster:fv->sf);
121 } else {
122 EncMapFree(fv->map);
123 if ( fv->sf->fv==fv ) {
124 if ( fv->cidmaster==NULL )
125 fv->sf->fv = fv->nextsame;
126 else {
127 fv->cidmaster->fv = fv->nextsame;
128 for ( i=0; i<fv->cidmaster->subfontcnt; ++i )
129 fv->cidmaster->subfonts[i]->fv = fv->nextsame;
131 } else {
132 for ( prev = fv->sf->fv; prev->nextsame!=fv; prev=prev->nextsame );
133 prev->nextsame = fv->nextsame;
136 #ifndef _NO_FFSCRIPT
137 DictionaryFree(fv->fontvars);
138 free(fv->fontvars);
139 #endif
140 free(fv->selected);
141 #ifndef _NO_PYTHON
142 PyFF_FreeFV(fv);
143 #endif
144 free(fv);
147 static int FontViewBaseWinInfo(FontViewBase *fv, int *cc, int *rc) {
148 (void)fv;
149 *cc = 16; *rc = 4;
150 return( -1 );
153 static void FontViewBaseSetTitle(FontViewBase *foo) { (void)foo; }
154 static void FontViewBaseSetTitles(SplineFont *foo) { (void)foo; }
155 static void FontViewBaseRefreshAll(SplineFont *foo) { (void)foo; }
156 static void FontViewBaseReformatOne(FontViewBase *foo) { (void)foo; }
157 static void FontViewBaseReformatAll(SplineFont *foo) { (void)foo; }
158 static void FontViewBaseLayerChanged(FontViewBase *foo) {(void)foo; }
159 static void FV_ToggleCharChanged(SplineChar *foo) {(void)foo; }
160 static FontViewBase *FVAny(void) { return fv_list; }
161 static int FontIsActive(SplineFont *sf) {
162 FontViewBase *fv;
164 for ( fv=fv_list; fv!=NULL; fv=fv->next )
165 if ( fv->sf == sf )
166 return( true );
168 return( false );
171 static SplineFont *FontOfFilename(const char *filename) {
172 char buffer[1025];
173 FontViewBase *fv;
175 GFileGetAbsoluteName((char *) filename,buffer,sizeof(buffer));
176 for ( fv=fv_list; fv!=NULL ; fv=fv->next ) {
177 if ( fv->sf->filename!=NULL && strcmp(fv->sf->filename,buffer)==0 )
178 return( fv->sf );
179 else if ( fv->sf->origname!=NULL && strcmp(fv->sf->origname,buffer)==0 )
180 return( fv->sf );
182 return( NULL );
185 static void FVExtraEncSlots(FontViewBase *fv, int encmax) {
186 (void)fv;
187 (void)encmax;
190 static void FontViewBase_Close(FontViewBase *fv) {
191 if ( fv_list==fv )
192 fv_list = fv->next;
193 else {
194 FontViewBase *n;
195 for ( n=fv_list; n->next!=fv; n=n->next );
196 n->next = fv->next;
198 FontViewFree(fv);
201 static void FVB_ChangeDisplayBitmap(FontViewBase *fv, BDFFont *bdf) {
202 fv->active_bitmap = bdf;
205 static void FVB_ShowFilled(FontViewBase *fv) {
206 fv->active_bitmap = NULL;
209 static void FVB_ReattachCVs(SplineFont *old, SplineFont *new) {
210 (void)old;
211 (void)new;
214 static void FVB_DeselectAll(FontViewBase *fv) {
215 memset(fv->selected,0,fv->map->encmax);
218 static void FVB_DisplayChar(FontViewBase *fv,int gid) {
219 (void)fv;
220 (void)gid;
223 static int SFB_CloseAllInstrs(SplineFont *sf) {
224 (void)sf;
225 return( true );
228 struct fv_interface noui_fv = {
229 FontViewBase_Create,
230 _FontViewBaseCreate,
231 FontViewBase_Close,
232 FontViewBase_Free,
233 FontViewBaseSetTitle,
234 FontViewBaseSetTitles,
235 FontViewBaseRefreshAll,
236 FontViewBaseReformatOne,
237 FontViewBaseReformatAll,
238 FontViewBaseLayerChanged,
239 FV_ToggleCharChanged,
240 FontViewBaseWinInfo,
241 FontIsActive,
242 FVAny,
243 FontViewBase_Append,
244 FontOfFilename,
245 FVExtraEncSlots,
246 FVExtraEncSlots,
247 FVB_ChangeDisplayBitmap,
248 FVB_ShowFilled,
249 FVB_ReattachCVs,
250 FVB_DeselectAll,
251 FVB_DisplayChar,
252 FVB_DisplayChar,
253 FVB_DisplayChar,
254 SFB_CloseAllInstrs
257 struct fv_interface *fv_interface = &noui_fv;
260 /******************************************************************************/
261 static int NoGlyphs(struct metricsview *mv) {
262 (void)mv;
263 return( 0 );
266 static SplineChar *Nothing(struct metricsview *mv, int i) {
267 (void)mv;
268 (void)i;
269 return( NULL );
272 static void NoReKern(struct splinefont *sf) {
273 (void)sf;
276 static void NoCloseAll(struct splinefont *sf) {
277 (void)sf;
280 struct mv_interface noui_mv = {
281 NoGlyphs,
282 Nothing,
283 NoReKern,
284 NoCloseAll
287 struct mv_interface *mv_interface = &noui_mv;