1 /* Copyright (C) 2000-2008 by George Williams */
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.
28 #include "fontforgevw.h"
34 # include <ieeefp.h> /* Solaris defines isnan in ieeefp rather than math.h */
38 int adjustwidth
= true;
39 int adjustlbearing
= true;
40 int allow_utf8_glyphnames
= false;
41 int clear_tt_instructions_when_needed
= true;
43 void SCClearRounds(SplineChar
*sc
,int layer
) {
47 for ( ss
=sc
->layers
[layer
].splines
; ss
!=NULL
; ss
=ss
->next
) {
48 for ( sp
=ss
->first
; ; ) {
49 sp
->roundx
= sp
->roundy
= false;
60 void SCClearLayer(SplineChar
*sc
,int layer
) {
63 SplinePointListsFree(sc
->layers
[layer
].splines
);
64 sc
->layers
[layer
].splines
= NULL
;
65 for ( refs
=sc
->layers
[layer
].refs
; refs
!=NULL
; refs
= next
) {
67 SCRemoveDependent(sc
,refs
,layer
);
69 sc
->layers
[layer
].refs
= NULL
;
70 ImageListsFree(sc
->layers
[layer
].images
);
71 sc
->layers
[layer
].images
= NULL
;
74 void SCClearContents(SplineChar
*sc
,int layer
) {
75 int ly_first
, ly_last
;
79 if ( sc
->parent
!=NULL
&& sc
->parent
->multilayer
) {
81 ly_last
= sc
->layer_cnt
-1;
83 ly_first
= ly_last
= layer
;
84 for ( layer
= ly_first
; layer
<=ly_last
; ++layer
)
85 SCClearLayer(sc
,layer
);
88 if ( sc
->parent
!=NULL
&&
89 (sc
->parent
->multilayer
||
90 (!sc
->parent
->layers
[layer
].background
&& SCWasEmpty(sc
,layer
)))) {
92 if ( sc
->parent
!=NULL
&& sc
->width
!=0 )
93 sc
->width
= sc
->parent
->ascent
+sc
->parent
->descent
;
94 AnchorPointsFree(sc
->anchor
);
96 StemInfosFree(sc
->hstem
); sc
->hstem
= NULL
;
97 StemInfosFree(sc
->vstem
); sc
->vstem
= NULL
;
98 DStemInfosFree(sc
->dstem
); sc
->dstem
= NULL
;
99 MinimumDistancesFree(sc
->md
); sc
->md
= NULL
;
100 free(sc
->ttf_instrs
);
101 sc
->ttf_instrs
= NULL
;
102 sc
->ttf_instrs_len
= 0;
103 SCOutOfDateBackground(sc
);
108 void SplinePointRound(SplinePoint
*sp
,real factor
) {
110 sp
->nextcp
.x
= rint(sp
->nextcp
.x
*factor
)/factor
;
111 sp
->nextcp
.y
= rint(sp
->nextcp
.y
*factor
)/factor
;
112 if ( sp
->next
!=NULL
&& sp
->next
->order2
)
113 sp
->next
->to
->prevcp
= sp
->nextcp
;
114 sp
->prevcp
.x
= rint(sp
->prevcp
.x
*factor
)/factor
;
115 sp
->prevcp
.y
= rint(sp
->prevcp
.y
*factor
)/factor
;
116 if ( sp
->prev
!=NULL
&& sp
->prev
->order2
)
117 sp
->prev
->from
->nextcp
= sp
->prevcp
;
118 if ( sp
->prev
!=NULL
&& sp
->next
!=NULL
&& sp
->next
->order2
&&
119 sp
->ttfindex
== 0xffff ) {
120 sp
->me
.x
= (sp
->nextcp
.x
+ sp
->prevcp
.x
)/2;
121 sp
->me
.y
= (sp
->nextcp
.y
+ sp
->prevcp
.y
)/2;
123 sp
->me
.x
= rint(sp
->me
.x
*factor
)/factor
;
124 sp
->me
.y
= rint(sp
->me
.y
*factor
)/factor
;
128 void SplineSetsRound2Int(SplineSet
*spl
,real factor
, int inspiro
, int onlysel
) {
131 for ( ; spl
!=NULL
; spl
=spl
->next
) {
134 for ( sp
=spl
->first
; ; ) {
135 if ( sp
->selected
|| !onlysel
)
136 SplinePointRound(sp
,factor
);
137 if ( sp
->prev
!=NULL
)
138 SplineRefigure(sp
->prev
);
139 if ( sp
->next
==NULL
)
142 if ( sp
==spl
->first
)
145 if ( spl
->first
->prev
!=NULL
)
146 SplineRefigure(spl
->first
->prev
);
151 void SCOrderAP(SplineChar
*sc
) {
152 int lc
=0, cnt
=0, out
=false, i
,j
;
153 AnchorPoint
*ap
, **array
;
154 /* Order so that first ligature index comes first */
156 for ( ap
=sc
->anchor
; ap
!=NULL
; ap
=ap
->next
) {
157 if ( ap
->lig_index
<lc
) out
= true;
158 if ( ap
->lig_index
>lc
) lc
= ap
->lig_index
;
164 array
= galloc(cnt
*sizeof(AnchorPoint
*));
165 for ( i
=0, ap
=sc
->anchor
; ap
!=NULL
; ++i
, ap
=ap
->next
)
167 for ( i
=0; i
<cnt
-1; ++i
) {
168 for ( j
=i
+1; j
<cnt
; ++j
) {
169 if ( array
[i
]->lig_index
>array
[j
]->lig_index
) {
176 sc
->anchor
= array
[0];
177 for ( i
=0; i
<cnt
-1; ++i
)
178 array
[i
]->next
= array
[i
+1];
179 array
[cnt
-1]->next
= NULL
;
184 static void SCUpdateNothing(SplineChar
*sc
) {
187 static void SCHintsChng(SplineChar
*sc
) {
188 sc
->changedsincelasthinted
= false;
189 if ( !sc
->changed
) {
191 sc
->parent
->changed
= true;
195 static void _SCChngNoUpdate(SplineChar
*sc
,int layer
,int changed
) {
198 static void SCChngNoUpdate(SplineChar
*sc
,int layer
) {
199 _SCChngNoUpdate(sc
,layer
,true);
202 static void SCB_MoreLayers(SplineChar
*sc
,Layer
*old
) {
205 static struct sc_interface noui_sc
= {
217 struct sc_interface
*sc_interface
= &noui_sc
;
219 void FF_SetSCInterface(struct sc_interface
*sci
) {
223 static void CVChngNoUpdate(CharViewBase
*cv
) {
226 static void _CVChngNoUpdate(CharViewBase
*cv
,int changed
) {
229 static void CVGlphRenameFixup(SplineFont
*sf
,char *oldname
, char *newname
) {
232 static void CV__LayerPaletteCheck(SplineFont
*sf
) {
235 static struct cv_interface noui_cv
= {
239 CV__LayerPaletteCheck
242 struct cv_interface
*cv_interface
= &noui_cv
;
244 void FF_SetCVInterface(struct cv_interface
*cvi
) {