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:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
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.
12
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.
15
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.
26 */
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>
36
37 static FontViewBase *fv_list=NULL;
38
39 extern int onlycopydisplayed;
40 float joinsnap=0;
41
42
43 /* FV Interface */
44
_FontViewBaseCreate(SplineFont * sf)45 static FontViewBase *_FontViewBaseCreate(SplineFont *sf) {
46 FontViewBase *fv = gcalloc(1,sizeof(FontViewBase));
47 int i;
48
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;
56 }
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;
68 }
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;
77 }
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);
83 }
84 fv->selected = gcalloc(fv->map->enccount,sizeof(char));
85
86 #ifndef _NO_PYTHON
87 PyFF_InitFontHook(fv);
88 #endif
89 return( fv );
90 }
91
FontViewBase_Create(SplineFont * sf,int hide)92 static FontViewBase *FontViewBase_Create(SplineFont *sf,int hide) {
93 FontViewBase *fv = _FontViewBaseCreate(sf);
94 (void)hide;
95 return( fv );
96 }
97
FontViewBase_Append(FontViewBase * 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;
102
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;
107 }
108 return( fv );
109 }
110
FontViewBase_Free(FontViewBase * fv)111 static void FontViewBase_Free(FontViewBase *fv) {
112 int i;
113 FontViewBase *prev;
114
115 if ( fv->nextsame==NULL && fv->sf->fv==fv ) {
116 EncMapFree(fv->map);
117 SplineFontFree(fv->cidmaster?fv->cidmaster:fv->sf);
118 } else {
119 EncMapFree(fv->map);
120 if ( fv->sf->fv==fv ) {
121 if ( fv->cidmaster==NULL )
122 fv->sf->fv = fv->nextsame;
123 else {
124 fv->cidmaster->fv = fv->nextsame;
125 for ( i=0; i<fv->cidmaster->subfontcnt; ++i )
126 fv->cidmaster->subfonts[i]->fv = fv->nextsame;
127 }
128 } else {
129 for ( prev = fv->sf->fv; prev->nextsame!=fv; prev=prev->nextsame );
130 prev->nextsame = fv->nextsame;
131 }
132 }
133 #ifndef _NO_FFSCRIPT
134 DictionaryFree(fv->fontvars);
135 free(fv->fontvars);
136 #endif
137 free(fv->selected);
138 #ifndef _NO_PYTHON
139 PyFF_FreeFV(fv);
140 #endif
141 free(fv);
142 }
143
FontViewBaseWinInfo(FontViewBase * fv,int * cc,int * rc)144 static int FontViewBaseWinInfo(FontViewBase *fv, int *cc, int *rc) {
145 (void)fv;
146 *cc = 16; *rc = 4;
147 return( -1 );
148 }
149
FontViewBaseSetTitle(FontViewBase * foo)150 static void FontViewBaseSetTitle(FontViewBase *foo) { (void)foo; }
FontViewBaseSetTitles(SplineFont * foo)151 static void FontViewBaseSetTitles(SplineFont *foo) { (void)foo; }
FontViewBaseRefreshAll(SplineFont * foo)152 static void FontViewBaseRefreshAll(SplineFont *foo) { (void)foo; }
FontViewBaseReformatOne(FontViewBase * foo)153 static void FontViewBaseReformatOne(FontViewBase *foo) { (void)foo; }
FontViewBaseReformatAll(SplineFont * foo)154 static void FontViewBaseReformatAll(SplineFont *foo) { (void)foo; }
FontViewBaseLayerChanged(FontViewBase * foo)155 static void FontViewBaseLayerChanged(FontViewBase *foo) {(void)foo; }
FV_ToggleCharChanged(SplineChar * foo)156 static void FV_ToggleCharChanged(SplineChar *foo) {(void)foo; }
FVAny(void)157 static FontViewBase *FVAny(void) { return fv_list; }
FontIsActive(SplineFont * sf)158 static int FontIsActive(SplineFont *sf) {
159 FontViewBase *fv;
160
161 for ( fv=fv_list; fv!=NULL; fv=fv->next )
162 if ( fv->sf == sf )
163 return( true );
164
165 return( false );
166 }
167
FontOfFilename(const char * filename)168 static SplineFont *FontOfFilename(const char *filename) {
169 char buffer[1025];
170 FontViewBase *fv;
171
172 GFileGetAbsoluteName((char *) filename,buffer,sizeof(buffer));
173 for ( fv=fv_list; fv!=NULL ; fv=fv->next ) {
174 if ( fv->sf->filename!=NULL && strcmp(fv->sf->filename,buffer)==0 )
175 return( fv->sf );
176 else if ( fv->sf->origname!=NULL && strcmp(fv->sf->origname,buffer)==0 )
177 return( fv->sf );
178 }
179 return( NULL );
180 }
181
FVExtraEncSlots(FontViewBase * fv,int encmax)182 static void FVExtraEncSlots(FontViewBase *fv, int encmax) {
183 (void)fv;
184 (void)encmax;
185 }
186
FontViewBase_Close(FontViewBase * fv)187 static void FontViewBase_Close(FontViewBase *fv) {
188 if ( fv_list==fv )
189 fv_list = fv->next;
190 else {
191 FontViewBase *n;
192 for ( n=fv_list; n->next!=fv; n=n->next );
193 n->next = fv->next;
194 }
195 FontViewFree(fv);
196 }
197
FVB_ChangeDisplayBitmap(FontViewBase * fv,BDFFont * bdf)198 static void FVB_ChangeDisplayBitmap(FontViewBase *fv, BDFFont *bdf) {
199 fv->active_bitmap = bdf;
200 }
201
FVB_ShowFilled(FontViewBase * fv)202 static void FVB_ShowFilled(FontViewBase *fv) {
203 fv->active_bitmap = NULL;
204 }
205
FVB_ReattachCVs(SplineFont * old,SplineFont * new)206 static void FVB_ReattachCVs(SplineFont *old, SplineFont *new) {
207 (void)old;
208 (void)new;
209 }
210
FVB_DeselectAll(FontViewBase * fv)211 static void FVB_DeselectAll(FontViewBase *fv) {
212 memset(fv->selected,0,fv->map->encmax);
213 }
214
FVB_DisplayChar(FontViewBase * fv,int gid)215 static void FVB_DisplayChar(FontViewBase *fv,int gid) {
216 (void)fv;
217 (void)gid;
218 }
219
SFB_CloseAllInstrs(SplineFont * sf)220 static int SFB_CloseAllInstrs(SplineFont *sf) {
221 (void)sf;
222 return( true );
223 }
224
225 struct fv_interface noui_fv = {
226 FontViewBase_Create,
227 _FontViewBaseCreate,
228 FontViewBase_Close,
229 FontViewBase_Free,
230 FontViewBaseSetTitle,
231 FontViewBaseSetTitles,
232 FontViewBaseRefreshAll,
233 FontViewBaseReformatOne,
234 FontViewBaseReformatAll,
235 FontViewBaseLayerChanged,
236 FV_ToggleCharChanged,
237 FontViewBaseWinInfo,
238 FontIsActive,
239 FVAny,
240 FontViewBase_Append,
241 FontOfFilename,
242 FVExtraEncSlots,
243 FVExtraEncSlots,
244 FVB_ChangeDisplayBitmap,
245 FVB_ShowFilled,
246 FVB_ReattachCVs,
247 FVB_DeselectAll,
248 FVB_DisplayChar,
249 FVB_DisplayChar,
250 FVB_DisplayChar,
251 SFB_CloseAllInstrs
252 };
253
254 struct fv_interface *fv_interface = &noui_fv;
255
256
257 /******************************************************************************/
NoGlyphs(struct metricsview * mv)258 static int NoGlyphs(struct metricsview *mv) {
259 (void)mv;
260 return( 0 );
261 }
262
Nothing(struct metricsview * mv,int i)263 static SplineChar *Nothing(struct metricsview *mv, int i) {
264 (void)mv;
265 (void)i;
266 return( NULL );
267 }
268
NoReKern(struct splinefont * sf)269 static void NoReKern(struct splinefont *sf) {
270 (void)sf;
271 }
272
NoCloseAll(struct splinefont * sf)273 static void NoCloseAll(struct splinefont *sf) {
274 (void)sf;
275 }
276
277 struct mv_interface noui_mv = {
278 NoGlyphs,
279 Nothing,
280 NoReKern,
281 NoCloseAll
282 };
283
284 struct mv_interface *mv_interface = &noui_mv;
285