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-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 "fontforgevw.h" /* For Error */
28 #include <stdio.h>
29 #include "splinefont.h"
30 #include <utype.h>
31 #include <ustring.h>
32 #include <time.h>
33 #include <math.h>
34 
35 #include <sys/types.h> /* For stat */
36 #include <sys/stat.h>
37 #include <unistd.h>
38 
39 #ifdef __CygWin
40  #include <sys/types.h>
41  #include <sys/stat.h>
42  #include <unistd.h>
43 #endif
44 
45 static void *mygets(FILE *file,char *buffer,int size) {
46  char *end = buffer+size-1;
47  char *pt = buffer;
48  int ch;
49 
50  while ( (ch=getc(file))!=EOF && ch!='\r' && ch!='\n' && pt<end )
51  *pt++ = ch;
52  *pt = '\0';
53  if ( ch==EOF && pt==buffer )
54 return( NULL );
55  if ( ch=='\r' ) {
56  ch = getc(file);
57  if ( ch!='\n' )
58  ungetc(ch,file);
59  }
60 return( buffer );
61 }
62 
63 /* ************************************************************************** */
64 /* **************************** Reading AFM files *************************** */
65 /* ************************************************************************** */
66 static void KPInsert( SplineChar *sc1, SplineChar *sc2, int off, int isv ) {
67  KernPair *kp;
68  int32 script;
69 
70  if ( sc1!=NULL && sc2!=NULL ) {
71  for ( kp=sc1->kerns; kp!=NULL && kp->sc!=sc2; kp = kp->next );
72  if ( kp!=NULL )
73  kp->off = off;
74  else if ( off!=0 ) {
75  kp = chunkalloc(sizeof(KernPair));
76  kp->sc = sc2;
77  kp->off = off;
79  if ( script==DEFAULT_SCRIPT )
81  kp->subtable = SFSubTableFindOrMake(sc1->parent,
82  isv?CHR('v','k','r','n'):CHR('k','e','r','n'),
83  script, gpos_pair);
84  if ( isv ) {
85  kp->next = sc1->vkerns;
86  sc1->vkerns = kp;
87  } else {
88  kp->next = sc1->kerns;
89  sc1->kerns = kp;
90  }
91  }
92  }
93 }
94 
96  FILE *file = fopen(filename,"r");
97  char buffer[200], *pt, *ept, ch;
98  SplineChar *sc1, *sc2;
99  int off;
100  char name[44], second[44], lig[44], buf2[100];
101  PST *liga;
102  double scale = (sf->ascent+sf->descent)/1000.0;
103 
104  if ( file==NULL )
105 return( 0 );
106  ff_progress_change_line2(_("Reading AFM file"));
107  while ( mygets(file,buffer,sizeof(buffer))!=NULL ) {
108  if ( strncmp(buffer,"KPX",3)==0 || strncmp(buffer,"KPY",3)==0 ) {
109  int isv = strncmp(buffer,"KPY",3)==0;
110  for ( pt=buffer+3; isspace(*pt); ++pt);
111  for ( ept = pt; *ept!='\0' && !isspace(*ept); ++ept );
112  ch = *ept; *ept = '\0';
113  sc1 = SFGetChar(sf,-1,pt);
114  *ept = ch;
115  for ( pt=ept; isspace(*pt); ++pt);
116  for ( ept = pt; *ept!='\0' && !isspace(*ept); ++ept );
117  ch = *ept; *ept = '\0';
118  sc2 = SFGetChar(sf,-1,pt);
119  *ept = ch;
120  off = strtol(ept,NULL,10);
121  KPInsert(sc1,sc2,rint(off*scale),isv);
122  } else if ( buffer[0]=='C' && isspace(buffer[1])) {
123  char *pt;
124  sc2 = NULL;
125  for ( pt= strchr(buffer,';'); pt!=NULL; pt=strchr(pt+1,';') ) {
126  if ( sscanf( pt, "; N %40s", name )==1 )
127  sc2 = SFGetChar(sf,-1,name);
128  else if ( sc2!=NULL &&
129  sscanf( pt, "; L %40s %40s", second, lig)==2 ) {
130  sc1 = SFGetChar(sf,-1,lig);
131  if ( sc1!=NULL ) {
132  sprintf( buf2, "%s %s", name, second);
133  for ( liga=sc1->possub; liga!=NULL; liga=liga->next ) {
134  if ( liga->type == pst_ligature && strcmp(liga->u.lig.components,buf2)==0 )
135  break;
136  }
137  if ( liga==NULL ) {
138  liga = chunkalloc(sizeof(PST));
140  CHR('l','i','g','a'),SCScriptFromUnicode(sc2),
141  gsub_ligature);
142  liga->subtable->lookup->store_in_afm = true;
143  liga->type = pst_ligature;
144  liga->next = sc1->possub;
145  sc1->possub = liga;
146  liga->u.lig.lig = sc1;
147  liga->u.lig.components = copy( buf2 );
148  }
149  }
150  }
151  }
152  }
153  }
154  fclose(file);
155 return( 1 );
156 }
157 
158 static void CheckMMAfmFile(SplineFont *sf,char *amfm_filename,char *fontname,EncMap *map) {
159  /* the afm file should be in the same directory as the amfm file */
160  /* with the fontname as the filename */
161  char *temp, *pt;
162 
163  free(sf->fontname);
164  sf->fontname = copy(fontname);
165 
166  temp = galloc(strlen(amfm_filename)+strlen(fontname)+strlen(".afm")+1);
167  strcpy(temp, amfm_filename);
168  pt = strrchr(temp,'/');
169  if ( pt==NULL ) pt = temp;
170  else ++pt;
171  strcpy(pt,fontname);
172  pt += strlen(pt);
173  strcpy(pt,".afm");
174  if ( !LoadKerningDataFromAfm(sf,temp,map) ) {
175  strcpy(pt,".AFM");
177  }
178  free(temp);
179 }
180 
182  FILE *file=NULL;
183  char buffer[280], *pt, lastname[257];
184  int index, i;
185  MMSet *mm = sf->mm;
186 
187  if ( mm!=NULL )
188  file = fopen(filename,"r");
189  pt = strstrmatch(filename,".amfm");
190  if ( pt!=NULL ) {
191  char *afmname = copy(filename);
192  strcpy(afmname+(pt-filename),isupper(pt[1])?".AFM":".afm");
194  free(afmname);
195  }
196  if ( file==NULL )
197 return( 0 );
198 
199  ff_progress_change_line2(_("Reading AFM file"));
200  while ( fgets(buffer,sizeof(buffer),file)!=NULL ) {
201  if ( strstrmatch(buffer,"StartMaster")!=NULL )
202  break;
203  }
204  index = -1; lastname[0] = '\0';
205  while ( fgets(buffer,sizeof(buffer),file)!=NULL ) {
206  if ( strstrmatch(buffer,"EndMaster")!=NULL ) {
207  if ( lastname[0]!='\0' && index!=-1 && index<mm->instance_count )
208  CheckMMAfmFile(mm->instances[index],filename,lastname,map);
209  index = -1; lastname[0] = '\0';
210  } else if ( sscanf(buffer,"FontName %256s", lastname )== 1 ) {
211  /* Do Nothing, all done */
212  } else if ( (pt = strstr(buffer,"WeightVector"))!=NULL ) {
213  pt += strlen("WeightVector");
214  while ( *pt==' ' || *pt=='[' ) ++pt;
215  i = 0;
216  while ( *pt!=']' && *pt!='\0' ) {
217  if ( *pt=='0' )
218  ++i;
219  else if ( *pt=='1' ) {
220  index = i;
221  break;
222  }
223  ++pt;
224  }
225  }
226  }
227  fclose(file);
228 return( true );
229 }
230 
231 int CheckAfmOfPostscript(SplineFont *sf, const char *psname, EncMap *map) {
232  char *new, *pt;
233  int ret;
234  int wasuc=false;
235 
236  new = galloc(strlen(psname)+6);
237  strcpy(new,psname);
238  pt = strrchr(new,'.');
239  if ( pt==NULL ) pt = new+strlen(new);
240  else wasuc = isupper(pt[1]);
241 
242  if ( sf->mm!=NULL ) {
243  strcpy(pt,wasuc?".AMFM":".amfm");
244  if ( !LoadKerningDataFromAmfm(sf,new,map)) {
245  strcpy(pt,wasuc?".amfm":".AMFM");
247  } else
248  ret = true;
249  /* The above routine reads from the afm file if one exist */
250  } else {
251  strcpy(pt,wasuc?".AFM":".afm");
252  if ( !LoadKerningDataFromAfm(sf,new,map)) {
253  strcpy(pt,wasuc?".afm":".AFM");
255  } else
256  ret = true;
257  }
258  free(new);
259 return( ret );
260 }
261 
double __cdecl rint(double _X)
long __cdecl strtol(char const *_String, char **_EndPtr, int _Radix)
const char * fontname
Definition: afm2pl.c:186
const char * afmname
Definition: afm2pl.c:195
#define name
#define free(a)
Definition: decNumber.cpp:310
#define strrchr
Definition: detex.c:67
#define fopen
Definition: xxstdio.h:21
#define fgets
Definition: xxstdio.h:29
int strcmp()
Definition: coll.cpp:143
int sscanf()
char * strcpy()
char * temp
Definition: dvidvi.c:137
#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 scientific i
Definition: afcover.h:80
xD9 x84 xD8 xAD xD9 x80 xF0 x90 xAC x9A xE0 xA7 xA6 xE0 xA7 xAA xF0 x91 x84 xA4 xF0 x91 x84 x89 xF0 x91 x84 x9B xF0 x90 x8A xAB xF0 x90 x8B x89 xE2 xB2 x9E xE2 xB2 x9F xD0 xBE xD0 x9E xF0 x90 x90 x84 xF0 x90 x90 xAC xE1 x83 x98 xE1 x83 x94 xE1 x83 x90 xE1 xB2 xBF xE2 xB0 x95 xE2 xB1 x85 xCE xBF xCE x9F xE0 xA8 xA0 xE0 xA8 xB0 xE0 xA9 xA6 Kayah xEA xA4 x8D xEA xA4 x80 Khmer xE1 xA7 xA1 xE1 xA7 xAA xE0 xBB x90 Latin Subscript xE2 x82 x92 xE2 x82 x80 xEA x93 xB3 xF0 x96 xB9 xA1 xF0 x96 xB9 x9B xF0 x96 xB9 xAF xE1 x80 x9D xE1 x80 x84 xE1 x80 x82 no script
Definition: afscript.h:271
#define EOF
Definition: afmparse.c:59
char * strstr()
#define fclose
Definition: debug.h:100
#define getc
Definition: line.c:39
static int ret
Definition: convert.c:72
int strncmp()
#define sprintf
Definition: snprintf.c:44
long int32
Definition: tiff.h:67
dictionary off
Definition: fc-lang.py:226
char * filename[256]
Definition: pbmtopk.c:46
#define index(s, c)
Definition: plain2.h:351
double scale
Definition: pnmhistmap.c:38
static int size
Definition: ppmlabel.c:24
#define map
C API: Unicode string handling functions.
char * strstrmatch(const char *longer, const char *substr)
Definition: char.c:55
SplineChar * SFGetChar(SplineFont *sf, int unienc, const char *name)
Definition: fvfonts.c:175
#define DEFAULT_SCRIPT
Definition: splinefont.h:343
uint32 SCScriptFromUnicode(SplineChar *sc)
Definition: tottfgpos.c:202
@ pst_ligature
Definition: splinefont.h:565
@ gsub_ligature
Definition: splinefont.h:352
@ gpos_pair
Definition: splinefont.h:365
#define chunkalloc(size)
Definition: splinefont.h:1947
#define ff_progress_change_line2
Definition: uiinterface.h:145
#define isspace(ch)
Definition: utype.h:87
#define isupper(ch)
Definition: utype.h:80
struct lookup_subtable * SFSubTableFindOrMake(SplineFont *sf, uint32 tag, uint32 script, int lookup_type)
Definition: lookups.c:3428
int LoadKerningDataFromAmfm(SplineFont *sf, char *filename, EncMap *map)
static void * mygets(FILE *file, char *buffer, int size)
Definition: splinesaveafm.c:45
static void CheckMMAfmFile(SplineFont *sf, char *amfm_filename, char *fontname, EncMap *map)
static void KPInsert(SplineChar *sc1, SplineChar *sc2, int off, int isv)
Definition: splinesaveafm.c:66
int CheckAfmOfPostscript(SplineFont *sf, const char *psname, EncMap *map)
int LoadKerningDataFromAfm(SplineFont *sf, char *filename, EncMap *map)
Definition: splinesaveafm.c:95
void * galloc(long size)
Definition: utils.c:300
Definition: filedef.h:30
struct splinechar * lig
Definition: splinefont.h:595
uint8 type
Definition: splinefont.h:587
struct lookup_subtable * subtable
Definition: splinefont.h:588
union generic_pst::@1432 u
struct generic_pst * next
Definition: splinefont.h:589
Definition: mendex.h:20
Definition: ttf.h:392
Definition: afm2pl.c:139
struct otlookup * lookup
Definition: splinefont.h:429
SplineFont * normal
Definition: splinefont.h:1858
SplineFont ** instances
Definition: splinefont.h:1857
unsigned int store_in_afm
Definition: splinefont.h:466
Definition: tfmaux.c:31
struct splinefont * parent
Definition: splinefont.h:1346
KernPair * kerns
Definition: splinefont.h:1379
PST * possub
Definition: splinefont.h:1381
KernPair * vkerns
Definition: splinefont.h:1380
#define CHR(x)
Definition: sysdep.h:200
#define FILE
Definition: t1stdio.h:34
#define ungetc(c, f)
Definition: t1stdio.h:106
ch
Definition: t4ht.c:1443
*job_name strlen((char *) job_name) - 4)
second
Definition: tex4ht.c:4115
PATTERN * pt
Definition: vlna.c:74
#define buffer
Definition: xmlparse.c:611
#define end(cp)
Definition: zic.c:71