beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luafontloader / fontforge / fontforge / splinechar.c
blobb123de4827d2f8620c721f1cee2896e31e7d6f8c
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.
28 #include "fontforgevw.h"
29 #include <math.h>
30 #include <locale.h>
31 # include <ustring.h>
32 # include <utype.h>
33 #ifdef HAVE_IEEEFP_H
34 # include <ieeefp.h> /* Solaris defines isnan in ieeefp rather than math.h */
35 #endif
36 #include "ttf.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) {
44 SplineSet *ss;
45 SplinePoint *sp;
47 for ( ss=sc->layers[layer].splines; ss!=NULL; ss=ss->next ) {
48 for ( sp=ss->first; ; ) {
49 sp->roundx = sp->roundy = false;
50 if ( sp->next==NULL )
51 break;
52 sp = sp->next->to;
53 if ( sp==ss->first )
54 break;
60 void SCClearLayer(SplineChar *sc,int layer) {
61 RefChar *refs, *next;
63 SplinePointListsFree(sc->layers[layer].splines);
64 sc->layers[layer].splines = NULL;
65 for ( refs=sc->layers[layer].refs; refs!=NULL; refs = next ) {
66 next = 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;
77 if ( sc==NULL )
78 return;
79 if ( sc->parent!=NULL && sc->parent->multilayer ) {
80 ly_first = ly_fore;
81 ly_last = sc->layer_cnt-1;
82 } else
83 ly_first = ly_last = layer;
84 for ( layer = ly_first; layer<=ly_last; ++layer )
85 SCClearLayer(sc,layer);
86 --layer;
88 if ( sc->parent!=NULL &&
89 (sc->parent->multilayer ||
90 (!sc->parent->layers[layer].background && SCWasEmpty(sc,layer)))) {
91 sc->widthset = false;
92 if ( sc->parent!=NULL && sc->width!=0 )
93 sc->width = sc->parent->ascent+sc->parent->descent;
94 AnchorPointsFree(sc->anchor);
95 sc->anchor = NULL;
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;
122 } else {
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) {
129 SplinePoint *sp;
131 for ( ; spl!=NULL; spl=spl->next ) {
132 if ( inspiro ) {
133 } else {
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 )
140 break;
141 sp = sp->next->to;
142 if ( sp==spl->first )
143 break;
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;
159 ++cnt;
161 if ( !out )
162 return;
164 array = galloc(cnt*sizeof(AnchorPoint *));
165 for ( i=0, ap=sc->anchor; ap!=NULL; ++i, ap=ap->next )
166 array[i] = ap;
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 ) {
170 ap = array[i];
171 array[i] = array[j];
172 array[j] = ap;
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;
180 free( array );
184 static void SCUpdateNothing(SplineChar *sc) {
187 static void SCHintsChng(SplineChar *sc) {
188 sc->changedsincelasthinted = false;
189 if ( !sc->changed ) {
190 sc->changed = true;
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 = {
206 SCUpdateNothing,
207 SCUpdateNothing,
208 SCUpdateNothing,
209 SCHintsChng,
210 SCChngNoUpdate,
211 _SCChngNoUpdate,
212 SCUpdateNothing,
213 SCUpdateNothing,
214 SCB_MoreLayers
217 struct sc_interface *sc_interface = &noui_sc;
219 void FF_SetSCInterface(struct sc_interface *sci) {
220 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 = {
236 CVChngNoUpdate,
237 _CVChngNoUpdate,
238 CVGlphRenameFixup,
239 CV__LayerPaletteCheck
242 struct cv_interface *cv_interface = &noui_cv;
244 void FF_SetCVInterface(struct cv_interface *cvi) {
245 cv_interface = cvi;