w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

splinechar.c
Go to the documentation of this file.
1 /* -*- coding: utf-8 -*- */
2 /* Copyright (C) 2000-2012 by George Williams */
3 /*
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6 
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9 
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13 
14  * The name of the author may not be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16 
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "fontforgevw.h"
30 # include <utype.h>
31 
32 #ifdef HAVE_IEEEFP_H
33 # include <ieeefp.h> /* Solaris defines isnan in ieeefp rather than math.h */
34 #endif
35 
36 int adjustwidth = true;
37 
39  RefChar *r;
40 
41  if ( layer==ly_grid ) layer = ly_fore;
42 
43  for ( r=sc->layers[layer].refs; r!=NULL; r=r->next )
44  if ( r->use_my_metrics )
45 return( r );
46 
47 return( NULL );
48 }
49 
50 /* if they changed the width, then change the width on all bitmap chars of */
51 /* ours, and if we are a letter, then change the width on all chars linked */
52 /* to us which had the same width that we used to have (so if we change the */
53 /* width of A, we'll also change that of À and Ä and ... */
54 void SCSynchronizeWidth(SplineChar *sc,real newwidth, real oldwidth) {
55  struct splinecharlist *dlist;
57  int isprobablybase;
58 
59  sc->widthset = true;
60  if( r!=NULL ) {
61  if ( oldwidth==r->sc->width ) {
62  sc->width = r->sc->width;
63 return;
64  }
65  newwidth = r->sc->width;
66  }
67  if ( newwidth==oldwidth )
68 return;
69  sc->width = newwidth;
70  if ( !adjustwidth )
71 return;
72 
73  isprobablybase = true;
74  if ( sc->unicodeenc==-1 || sc->unicodeenc>=0x10000 ||
75  !isalpha(sc->unicodeenc) || iscombining(sc->unicodeenc))
76  isprobablybase = false;
77 
78  for ( dlist=sc->dependents; dlist!=NULL; dlist=dlist->next ) {
80  if ( metrics!=NULL && metrics->sc!=sc )
81  continue;
82  else if ( metrics==NULL && !isprobablybase )
83  continue;
84  if ( dlist->sc->width==oldwidth &&
85  (metrics!=NULL)) {
86  SCSynchronizeWidth(dlist->sc,newwidth,oldwidth);
87  if ( !dlist->sc->changed ) {
88  dlist->sc->changed = true;
89  }
90  }
91  }
92 }
93 
94 static int _SCRefNumberPoints2(SplineSet **_rss,SplineChar *sc,int pnum,int layer) {
95  SplineSet *ss, *rss = *_rss;
96  SplinePoint *sp, *rsp;
97  RefChar *r;
98  int starts_with_cp, startcnt;
99 
100  for ( ss=sc->layers[layer].splines; ss!=NULL; ss=ss->next, rss=rss->next ) {
101  if ( rss==NULL ) /* Can't happen */
102  break;
103  starts_with_cp = !ss->first->noprevcp &&
104  ((ss->first->ttfindex == pnum+1 && ss->first->prev!=NULL &&
105  ss->first->prev->from->nextcpindex==pnum ) ||
106  ((ss->first->ttfindex==0xffff || SPInterpolate( ss->first ))));
107  startcnt = pnum;
108  if ( starts_with_cp ) ++pnum;
109  for ( sp = ss->first, rsp=rss->first; ; ) {
110  if ( sp->ttfindex==0xffff || SPInterpolate( sp ))
111  rsp->ttfindex = 0xffff;
112  else
113  rsp->ttfindex = pnum++;
114  if ( sp->next==NULL )
115  break;
116  if ( sp->next!=NULL && sp->next->to == ss->first ) {
117  if ( sp->nonextcp )
118  rsp->nextcpindex = 0xffff;
119  else if ( starts_with_cp )
120  rsp->nextcpindex = startcnt;
121  else
122  rsp->nextcpindex = pnum++;
123  break;
124  }
125  if ( sp->nonextcp )
126  rsp->nextcpindex = 0xffff;
127  else
128  rsp->nextcpindex = pnum++;
129  if ( sp->next==NULL )
130  break;
131  sp = sp->next->to;
132  rsp = rsp->next->to;
133  }
134  }
135 
136  *_rss = rss;
137  for ( r = sc->layers[layer].refs; r!=NULL; r=r->next )
138  pnum = _SCRefNumberPoints2(_rss,r->sc,pnum,layer);
139 return( pnum );
140 }
141 
142 static int SCRefNumberPoints2(RefChar *ref,int pnum,int layer) {
143  SplineSet *rss;
144 
145  rss = ref->layers[0].splines;
146 return( _SCRefNumberPoints2(&rss,ref->sc,pnum,layer));
147 }
148 
150  int pnum=0;
151  SplinePoint *sp;
152  int starts_with_cp;
153 
154  for ( ; ss!=NULL; ss=ss->next ) {
155  starts_with_cp = !ss->first->noprevcp &&
156  ((ss->first->ttfindex == pnum+1 && ss->first->prev!=NULL &&
157  ss->first->prev->from->nextcpindex==pnum ) ||
158  SPInterpolate( ss->first ));
159  if ( starts_with_cp && ss->first->prev!=NULL )
160  ss->first->prev->from->nextcpindex = pnum++;
161  for ( sp=ss->first; ; ) {
162  if ( SPInterpolate(sp) )
163  sp->ttfindex = 0xffff;
164  else
165  sp->ttfindex = pnum++;
166  if ( sp->nonextcp && sp->nextcpindex!=pnum )
167  sp->nextcpindex = 0xffff;
168  else if ( !starts_with_cp || (sp->next!=NULL && sp->next->to!=ss->first) )
169  sp->nextcpindex = pnum++;
170  if ( sp->next==NULL )
171  break;
172  sp = sp->next->to;
173  if ( sp==ss->first )
174  break;
175  }
176  }
177 return( pnum );
178 }
179 
180 static int SSPsNumberPoints(SplineChar *sc, SplineSet *splines,int pnum) {
181  SplineSet *ss;
182  SplinePoint *sp;
183 
184  for ( ss = splines; ss!=NULL; ss=ss->next ) {
185  for ( sp=ss->first; ; ) {
186  sp->ttfindex = pnum++;
187  sp->nextcpindex = 0xffff;
188  if ( sc->numberpointsbackards ) {
189  if ( sp->prev==NULL )
190  break;
191  if ( !sp->noprevcp || !sp->prev->from->nonextcp )
192  pnum += 2;
193  sp = sp->prev->from;
194  } else {
195  if ( sp->next==NULL )
196  break;
197  if ( !sp->nonextcp || !sp->next->to->noprevcp )
198  pnum += 2;
199  sp = sp->next->to;
200  }
201  if ( sp==ss->first )
202  break;
203  }
204  }
205 return( pnum );
206 }
207 
209  int pnum=0;
210  SplineSet *ss;
211  SplinePoint *sp;
212  RefChar *ref;
213 
214  if ( layer<0 || layer>=sc->layer_cnt )
215  return( pnum );
216 
217  if ( sc->layers[layer].order2 ) { /* TrueType and its complexities. I ignore svg here */
218  if ( sc->layers[layer].refs!=NULL ) {
219  /* if there are references there can't be splines. So if we've got*/
220  /* splines mark all point numbers on them as meaningless */
221  for ( ss = sc->layers[layer].splines; ss!=NULL; ss=ss->next ) {
222  for ( sp=ss->first; ; ) {
223  sp->ttfindex = 0xfffe;
224  if ( !sp->nonextcp )
225  sp->nextcpindex = 0xfffe;
226  if ( sp->next==NULL )
227  break;
228  sp = sp->next->to;
229  if ( sp==ss->first )
230  break;
231  }
232  }
233  for ( ref = sc->layers[layer].refs; ref!=NULL; ref=ref->next )
234  pnum = SCRefNumberPoints2(ref,pnum,layer);
235  } else {
236  pnum = SSTtfNumberPoints(sc->layers[layer].splines);
237  }
238  } else { /* cubic (PostScript/SVG) splines */
239  int first, last;
240  if ( sc->parent->multilayer ) {
241  first = ly_fore;
242  last = sc->layer_cnt-1;
243  } else
244  first = last = layer;
245  for ( layer=first; layer<=last; ++layer ) {
246  for ( ref = sc->layers[layer].refs; ref!=NULL; ref=ref->next )
247  pnum = SSPsNumberPoints(sc,ref->layers[0].splines,pnum);
248  pnum = SSPsNumberPoints(sc,sc->layers[layer].splines,pnum);
249  }
250  }
251 return( pnum );
252 }
253 
255  int pnum=0, skipit;
256  SplineSet *ss;
257  SplinePoint *sp;
258  int starts_with_cp;
259  int start_pnum;
260 
261  if ( sc->layers[layer].splines!=NULL &&
262  sc->layers[layer].refs!=NULL )
263 return( false ); /* TrueType can't represent this, so always remove instructions. They can't be meaningful */
264 
265  for ( ss = sc->layers[layer].splines; ss!=NULL; ss=ss->next ) {
266  starts_with_cp = (ss->first->ttfindex == pnum+1 || ss->first->ttfindex==0xffff) &&
267  !ss->first->noprevcp;
268  start_pnum = pnum;
269  if ( starts_with_cp ) ++pnum;
270  for ( sp=ss->first; ; ) {
271  skipit = SPInterpolate(sp);
272  if ( sp->nonextcp || sp->noprevcp ) skipit = false;
273  if ( sp->ttfindex==0xffff && skipit )
274  /* Doesn't count */;
275  else if ( sp->ttfindex!=pnum )
276 return( false );
277  else
278  ++pnum;
279  if ( sp->nonextcp && sp->nextcpindex==0xffff )
280  /* Doesn't count */;
281  else if ( sp->nextcpindex==pnum )
282  ++pnum;
283  else if ( sp->nextcpindex==start_pnum && starts_with_cp &&
284  (sp->next!=NULL && sp->next->to==ss->first) )
285  /* Ok */;
286  else
287 return( false );
288  if ( sp->next==NULL )
289  break;
290  sp = sp->next->to;
291  if ( sp==ss->first )
292  break;
293  }
294  /* if ( starts_with_cp ) --pnum; */
295  }
296 return( true );
297 }
298 
299 void AltUniAdd(SplineChar *sc,int uni) {
300  struct altuni *altuni;
301 
302  if ( sc!=NULL && uni!=-1 && uni!=sc->unicodeenc ) {
303  for ( altuni = sc->altuni; altuni!=NULL && (altuni->unienc!=uni ||
304  altuni->vs!=-1 ||
305  altuni->fid); altuni=altuni->next );
306  if ( altuni==NULL ) {
307  altuni = chunkalloc(sizeof(struct altuni));
308  altuni->next = sc->altuni;
309  sc->altuni = altuni;
310  altuni->unienc = uni;
311  altuni->vs = -1;
312  altuni->fid = 0;
313  }
314  }
315 }
316 
318  struct altuni *altuni;
319 
320  if ( sc!=NULL && uni!=-1 && uni!=sc->unicodeenc ) {
321  altuni = chunkalloc(sizeof(struct altuni));
322  altuni->next = sc->altuni;
323  sc->altuni = altuni;
324  altuni->unienc = uni;
325  altuni->vs = -1;
326  altuni->fid = 0;
327  }
328 }
#define sc
Definition: aptex-macros.h:57
#define dlist
double real
Definition: dvips.h:66
#define NULL
Definition: ftobjs.h:61
def ref(x)
Definition: pdf-org.py:104
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
int r
Definition: ppmqvga.c:68
int SCPointsNumberedProperly(SplineChar *sc, int layer)
Definition: splinechar.c:254
static int _SCRefNumberPoints2(SplineSet **_rss, SplineChar *sc, int pnum, int layer)
Definition: splinechar.c:94
void AltUniAdd(SplineChar *sc, int uni)
Definition: splinechar.c:299
static int SCRefNumberPoints2(RefChar *ref, int pnum, int layer)
Definition: splinechar.c:142
static int SSPsNumberPoints(SplineChar *sc, SplineSet *splines, int pnum)
Definition: splinechar.c:180
int SSTtfNumberPoints(SplineSet *ss)
Definition: splinechar.c:149
int SCNumberPoints(SplineChar *sc, int layer)
Definition: splinechar.c:208
RefChar * HasUseMyMetrics(SplineChar *sc, int layer)
Definition: splinechar.c:38
void AltUniAdd_DontCheckDups(SplineChar *sc, int uni)
Definition: splinechar.c:317
int adjustwidth
Definition: splinechar.c:36
void SCSynchronizeWidth(SplineChar *sc, float newwidth, float oldwidth)
Definition: splinechar.c:54
int SPInterpolate(const SplinePoint *sp)
Definition: splineutil2.c:399
@ ly_grid
Definition: splinefont.h:1209
@ ly_fore
Definition: splinefont.h:1209
#define chunkalloc(size)
Definition: splinefont.h:1947
#define iscombining(ch)
Definition: utype.h:98
#define isalpha(ch)
Definition: utype.h:82
int32 unienc
Definition: splinefont.h:1316
struct altuni * next
Definition: splinefont.h:1316
uint32 fid
Definition: splinefont.h:1316
int32 vs
Definition: splinefont.h:1316
SplinePoint * to
Definition: splinefont.h:1038
SplinePoint * from
Definition: splinefont.h:1037
unsigned int noprevcp
Definition: splinefont.h:957
struct spline * next
Definition: splinefont.h:979
uint16 ttfindex
Definition: splinefont.h:974
struct spline * prev
Definition: splinefont.h:980
uint16 nextcpindex
Definition: splinefont.h:978
struct splinepointlist * next
Definition: splinefont.h:1073
SplinePoint * first
Definition: splinefont.h:1072
#define sp
Definition: stack.c:11