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)  

splinesaveafm.c
Go to the documentation of this file.
1 /* Copyright (C) 2000-2012 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 "fontforgevw.h" /* For Error */
28 
29 
30 /* ************************************************************************** */
31 /* **************************** Reading OFM files *************************** */
32 /* ************************************************************************** */
33 
34 #define ExtShort(off) (((ext+2*off)[0]<<8)|(ext+2*off)[1])
35 
36 /* ************************************************************************** */
37 
39  int layer,l;
40  RefChar *ref;
41 
42  if ( sc==NULL )
43 return( false );
44  for ( layer = 0; layer<sc->layer_cnt; ++layer ) if ( !sc->layers[layer].background ) {
45  if ( sc->layers[layer].splines!=NULL)
46 return( true );
47  for ( ref = sc->layers[layer].refs; ref!=NULL; ref=ref->next )
48  for ( l=0; l<ref->layer_cnt; ++l )
49  if ( ref->layers[l].splines!=NULL )
50 return( true );
51  }
52 return( false );
53 }
54 
56 return( sc!=NULL &&
57  ( SCDrawsSomething(sc) || sc->widthset || sc->anchor!=NULL ||
58 #if HANYANG
59  sc->compositionunit ||
60 #endif
61  sc->dependents!=NULL /*||
62  sc->width!=sc->parent->ascent+sc->parent->descent*/ ) );
63 }
64 
66  LigList *l, *next;
67  struct splinecharlist *scl, *sclnext;
68  int j;
69 
70  if (sf->internal_temp)
71 return;
72 
73  for ( j=0; j<sf->glyphcnt; ++j ) if ( sf->glyphs[j]!=NULL ) {
74  for ( l = sf->glyphs[j]->ligofme; l!=NULL; l = next ) {
75  next = l->next;
76  for ( scl = l->components; scl!=NULL; scl = sclnext ) {
77  sclnext = scl->next;
78  chunkfree(scl,sizeof(struct splinecharlist));
79  }
80  if ( l->lig->temporary ) {
81  free(l->lig->u.lig.components);
82  chunkfree(l->lig,sizeof(PST));
83  }
84  free( l );
85  }
86  sf->glyphs[j]->ligofme = NULL;
87  }
88 }
89 
91  PST *lig;
92  LigList *ll;
93  int i,j,k,ch;
94  char *pt, *ligstart;
95  SplineChar *sc, *tsc;
96  struct splinecharlist *head, *last;
97  int ccnt, lcnt, lmax=20;
98  LigList **all = malloc(lmax*sizeof(LigList *));
99 
100  /* First clear out any old stuff */
101  for ( j=0; j<sf->glyphcnt; ++j ) if ( sf->glyphs[j]!=NULL )
102  sf->glyphs[j]->ligofme = NULL;
103 
104  /* Attach all the ligatures to the first character of their components */
105  /* Figure out what the components are, and if they all exist */
106  /* we're only interested in the lig if all components are worth outputting */
107  for ( i=0 ; i<sf->glyphcnt; ++i ) if ( SCWorthOutputting(sf->glyphs[i]) && sf->glyphs[i]->possub!=NULL ) {
108  for ( lig = sf->glyphs[i]->possub; lig!=NULL; lig=lig->next ) if ( lig->type==pst_ligature ) {
109  ligstart = lig->u.lig.components;
110  last = head = NULL; sc = NULL;
111  for ( pt = ligstart; *pt!='\0'; ) {
112  char *start = pt;
113  for ( ; *pt!='\0' && *pt!=' '; ++pt );
114  ch = *pt; *pt = '\0';
115  tsc = SFGetChar(sf,-1,start);
116  *pt = ch;
117  if ( tsc!=NULL ) {
118  if ( !SCWorthOutputting(tsc)) {
119  sc = NULL;
120  break;
121  }
122  if ( sc==NULL ) {
123  sc = tsc;
124  ccnt = 1;
125  } else {
126  struct splinecharlist *cur = chunkalloc(sizeof(struct splinecharlist));
127  if ( head==NULL )
128  head = cur;
129  else
130  last->next = cur;
131  last = cur;
132  cur->sc = tsc;
133  cur->next = NULL;
134  ++ccnt;
135  }
136  } else {
137  sc = NULL;
138  break;
139  }
140  while ( *pt==' ' ) ++pt;
141  }
142  if ( sc!=NULL ) {
143  ll = malloc(sizeof(LigList));
144  ll->lig = lig;
145  ll->next = sc->ligofme;
146  ll->first = sc;
147  ll->components = head;
148  ll->ccnt = ccnt;
149  sc->ligofme = ll;
150  } else {
151  while ( head!=NULL ) {
152  last = head->next;
153  chunkfree(head,sizeof(*head));
154  head = last;
155  }
156  }
157  }
158  }
159  for ( i=0 ; i<sf->glyphcnt; ++i ) if ( (sc=sf->glyphs[i])!=NULL && sc->ligofme!=NULL ) {
160  for ( ll=sc->ligofme, lcnt=0; ll!=NULL; ll=ll->next, ++lcnt );
161  /* Finally, order the list so that the longest ligatures are first */
162  if ( lcnt>1 ) {
163  if ( lcnt>=lmax )
164  all = realloc(all,(lmax=lcnt+30)*sizeof(LigList *));
165  for ( ll=sc->ligofme, k=0; ll!=NULL; ll=ll->next, ++k )
166  all[k] = ll;
167  for ( k=0; k<lcnt-1; ++k ) for ( j=k+1; j<lcnt; ++j )
168  if ( all[k]->ccnt<all[j]->ccnt ) {
169  ll = all[k];
170  all[k] = all[j];
171  all[j] = ll;
172  }
173  sc->ligofme = all[0];
174  for ( k=0; k<lcnt-1; ++k )
175  all[k]->next = all[k+1];
176  all[k]->next = NULL;
177  }
178  }
179  free( all );
180 }
181 
182 void SFKernCleanup(SplineFont *sf,int isv) {
183  int i;
184  KernPair *kp, *p, *n;
185  OTLookup *otl, *otlp, *otln;
186 
187  if (sf->internal_temp)
188 return;
189 
190  if ( (!isv && sf->kerns==NULL) || (isv && sf->vkerns==NULL) ) /* can't have gotten messed up */
191 return;
192  for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL ) {
193  for ( kp = isv ? sf->glyphs[i]->vkerns : sf->glyphs[i]->kerns, p=NULL; kp!=NULL; kp = n ) {
194  n = kp->next;
195  if ( kp->kcid!=0 ) {
196  if ( p!=NULL )
197  p->next = n;
198  else if ( isv )
199  sf->glyphs[i]->vkerns = n;
200  else
201  sf->glyphs[i]->kerns = n;
202  chunkfree(kp,sizeof(*kp));
203  } else
204  p = kp;
205  }
206  }
207  for ( otl=sf->gpos_lookups, otlp = NULL; otl!=NULL; otl = otln ) {
208  otln = otl->next;
209  if ( otl->temporary_kern ) {
210  if ( otlp!=NULL )
211  otlp->next = otln;
212  else
213  sf->gpos_lookups = otln;
214  OTLookupFree(otl);
215  } else
216  otlp = otl;
217  }
218 }
219 
220 static void KCSfree(SplineChar ***scs,int cnt) {
221  int i;
222  for ( i=1; i<cnt; ++i )
223  free( scs[i]);
224  free(scs);
225 }
226 
227 static SplineChar ***KernClassToSC(SplineFont *sf, char **classnames, int cnt) {
228  SplineChar ***scs, *sc;
229  int i,j;
230  char *pt, *end, ch;
231 
232  scs = malloc(cnt*sizeof(SplineChar **));
233  for ( i=1; i<cnt; ++i ) {
234  for ( pt=classnames[i]-1, j=0; pt!=NULL; pt=strchr(pt+1,' ') )
235  ++j;
236  scs[i] = malloc((j+1)*sizeof(SplineChar *));
237  for ( pt=classnames[i], j=0; *pt!='\0'; pt=end+1 ) {
238  end = strchr(pt,' ');
239  if ( end==NULL )
240  end = pt+strlen(pt);
241  ch = *end;
242  *end = '\0';
243  sc = SFGetChar(sf,-1,pt);
244  if ( sc!=NULL )
245  scs[i][j++] = sc;
246  if ( ch=='\0' )
247  break;
248  *end = ch;
249  }
250  scs[i][j] = NULL;
251  }
252 return( scs );
253 }
254 
256  int16 offset, struct lookup_subtable *sub,uint16 kcid,int isv) {
257  KernPair *kp;
258 
259  for ( kp=first->kerns; kp!=NULL; kp=kp->next )
260  if ( kp->sc == second )
261  break;
262  if ( kp==NULL ) {
263  kp = chunkalloc(sizeof(KernPair));
264  kp->sc = second;
265  kp->off = offset;
266  kp->subtable = sub;
267  kp->kcid = kcid;
268  if ( isv ) {
269  kp->next = first->vkerns;
270  first->vkerns = kp;
271  } else {
272  kp->next = first->kerns;
273  first->kerns = kp;
274  }
275  }
276 }
277 
279  KernClass *kc, *head= isv ? sf->vkerns : sf->kerns;
280  KernPair *kp;
281  SplineChar ***first, ***last;
282  int i, j, k, l;
283  OTLookup *otl;
284 
285  /* Make sure the temporary field is cleaned up. Otherwise we may lose kerning data */
286  for ( i=0; i<sf->glyphcnt; ++i ) if ( sf->glyphs[i]!=NULL ) {
287  for ( kp = isv ? sf->glyphs[i]->vkerns : sf->glyphs[i]->kerns; kp!=NULL; kp = kp->next ) {
288  kp->kcid = false;
289  }
290  }
291  for ( kc = head, i=0; kc!=NULL; kc = kc->next )
292  kc->kcid = ++i;
293  for ( kc = head; kc!=NULL; kc = kc->next ) {
294 
295  otl = chunkalloc(sizeof(OTLookup));
296  otl->next = sf->gpos_lookups;
297  sf->gpos_lookups = otl;
298  otl->lookup_type = gpos_pair;
301  otl->lookup_name = copy(_("<Temporary kerning>"));
302  otl->temporary_kern = otl->store_in_afm = true;
303  otl->subtables = chunkalloc(sizeof(struct lookup_subtable));
304  otl->subtables->lookup = otl;
305  otl->subtables->per_glyph_pst_or_kern = true;
306  otl->subtables->subtable_name = copy(_("<Temporary kerning>"));
307 
310  for ( i=1; i<kc->first_cnt; ++i ) for ( j=1; j<kc->second_cnt; ++j ) {
311  if ( kc->offsets[i*kc->second_cnt+j]!=0 ) {
312  for ( k=0; first[i][k]!=NULL; ++k )
313  for ( l=0; last[j][l]!=NULL; ++l )
314  AddTempKP(first[i][k],last[j][l],
315  kc->offsets[i*kc->second_cnt+j],
316  otl->subtables,kc->kcid,isv);
317  }
318  }
319  KCSfree(first,kc->first_cnt);
320  KCSfree(last,kc->second_cnt);
321  }
322 }
#define sc
Definition: aptex-macros.h:57
#define head
Definition: aptex-macros.h:513
#define next(a)
Definition: aptex-macros.h:924
static point_t cur
Definition: backend_eps.c:108
#define n
Definition: t4ht.c:1290
#define free(a)
Definition: decNumber.cpp:310
#define _(String)
Definition: ftxerr18.c:64
static void copy(GlyphCachePtr *root)
Definition: gcache.c:378
#define strchr
Definition: gsftopk.c:59
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
for(n=0;n< outline->n_points;n++)
Definition: ftbbox.c:494
#define malloc
Definition: alloca.c:91
unsigned short uint16
Definition: tiff.h:62
short int16
Definition: tiff.h:61
#define realloc
Definition: glob.c:206
std::is_same< integer_sequence< bool, true, Bs... >, integer_sequence< bool, Bs..., true > > all
Definition: variant.hpp:799
def ref(x)
Definition: pdf-org.py:104
int k
Definition: otp-parser.c:70
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 endif[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 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF sub
static int cnt
Definition: pkout.c:166
static int32_t last
Definition: ppagelist.c:29
static int32_t first
Definition: ppagelist.c:29
static int offset
Definition: ppmtogif.c:642
SplineChar * SFGetChar(SplineFont *sf, int unienc, const char *name)
Definition: fvfonts.c:175
FeatureScriptLangList * FeatureListCopy(FeatureScriptLangList *fl)
Definition: lookups.c:667
@ pst_ligature
Definition: splinefont.h:565
@ gpos_pair
Definition: splinefont.h:365
void OTLookupFree(OTLookup *lookup)
Definition: splineutil.c:2884
#define chunkalloc(size)
Definition: splinefont.h:1947
#define chunkfree(item, size)
Definition: splinefont.h:1948
void SFLigatureCleanup(SplineFont *sf)
Definition: splinesaveafm.c:65
void SFKernClassTempDecompose(SplineFont *sf, int isv)
int SCWorthOutputting(SplineChar *sc)
Definition: splinesaveafm.c:55
int SCDrawsSomething(SplineChar *sc)
Definition: splinesaveafm.c:38
static SplineChar *** KernClassToSC(SplineFont *sf, char **classnames, int cnt)
void SFKernCleanup(SplineFont *sf, int isv)
static void KCSfree(SplineChar ***scs, int cnt)
static void AddTempKP(SplineChar *first, SplineChar *second, int16 offset, struct lookup_subtable *sub, uint16 kcid, int isv)
void SFLigaturePrepare(SplineFont *sf)
Definition: splinesaveafm.c:90
Definition: ttf.h:354
int first_cnt
Definition: splinefont.h:546
int second_cnt
Definition: splinefont.h:546
char ** firsts
Definition: splinefont.h:547
int16 * offsets
Definition: splinefont.h:556
char ** seconds
Definition: splinefont.h:548
struct kernclass * next
Definition: splinefont.h:559
struct lookup_subtable * subtable
Definition: splinefont.h:554
uint16 kcid
Definition: splinefont.h:555
Definition: ttf.h:392
Definition: afm2pl.c:139
struct lig * next
Definition: afm2pl.c:140
PST * lig
Definition: splinefont.h:601
struct splinechar * first
Definition: splinefont.h:602
int ccnt
Definition: splinefont.h:605
struct liglist * next
Definition: splinefont.h:604
struct splinecharlist * components
Definition: splinefont.h:603
struct otlookup * lookup
Definition: splinefont.h:429
unsigned int per_glyph_pst_or_kern
Definition: splinefont.h:409
struct otlookup * lookup
Definition: splinefont.h:407
struct otlookup * next
Definition: splinefont.h:458
struct lookup_subtable * subtables
Definition: splinefont.h:463
unsigned int temporary_kern
Definition: splinefont.h:469
unsigned int store_in_afm
Definition: splinefont.h:466
char * lookup_name
Definition: splinefont.h:461
FeatureScriptLangList * features
Definition: splinefont.h:462
uint32 lookup_flags
Definition: splinefont.h:460
enum otlookup_type lookup_type
Definition: splinefont.h:459
Definition: tfmaux.c:31
struct splinecharlist * next
Definition: splinefont.h:1314
ch
Definition: t4ht.c:1443
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
second
Definition: tex4ht.c:4115
struct _lig lig
Definition: ttf2tfm.h:48
@ start
Definition: preamble.c:52
PATTERN * pt
Definition: vlna.c:74
#define end(cp)
Definition: zic.c:71