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.
42 #include "splinefont.h"
45 #include <sys/types.h>
50 extern int autohint_before_generate
;
53 typedef void (*DumpChar
)(int ch
,void *data
);
54 struct fileencryptdata
{
63 struct psdict
*PSDictCopy(struct psdict
*dict
) {
70 ret
= gcalloc(1,sizeof(struct psdict
));
71 ret
->cnt
= dict
->cnt
; ret
->next
= dict
->next
;
72 ret
->keys
= gcalloc(ret
->cnt
,sizeof(char *));
73 ret
->values
= gcalloc(ret
->cnt
,sizeof(char *));
74 for ( i
=0; i
<dict
->next
; ++i
) {
75 ret
->keys
[i
] = copy(dict
->keys
[i
]);
76 ret
->values
[i
] = copy(dict
->values
[i
]);
82 int PSDictFindEntry(struct psdict
*dict
, char *key
) {
88 for ( i
=0; i
<dict
->next
; ++i
)
89 if ( strcmp(dict
->keys
[i
],key
)==0 )
95 char *PSDictHasEntry(struct psdict
*dict
, char *key
) {
101 for ( i
=0; i
<dict
->next
; ++i
)
102 if ( strcmp(dict
->keys
[i
],key
)==0 )
103 return( dict
->values
[i
] );
108 int PSDictRemoveEntry(struct psdict
*dict
, char *key
) {
114 for ( i
=0; i
<dict
->next
; ++i
)
115 if ( strcmp(dict
->keys
[i
],key
)==0 )
119 free( dict
->keys
[i
]);
120 free( dict
->values
[i
] );
122 while ( i
<dict
->next
) {
123 dict
->keys
[i
] = dict
->keys
[i
+1];
124 dict
->values
[i
] = dict
->values
[i
+1];
131 int PSDictChangeEntry(struct psdict
*dict
, char *key
, char *newval
) {
137 for ( i
=0; i
<dict
->next
; ++i
)
138 if ( strcmp(dict
->keys
[i
],key
)==0 )
140 if ( i
==dict
->next
) {
141 if ( dict
->next
>=dict
->cnt
) {
143 dict
->keys
= grealloc(dict
->keys
,dict
->cnt
*sizeof(char *));
144 dict
->values
= grealloc(dict
->values
,dict
->cnt
*sizeof(char *));
146 dict
->keys
[dict
->next
] = copy(key
);
147 dict
->values
[dict
->next
] = NULL
;
150 free(dict
->values
[i
]);
151 dict
->values
[i
] = copy(newval
);
156 static double FindMaxDiffOfBlues(char *pt
, double max_diff
) {
160 while ( *pt
==' ' || *pt
=='[' ) ++pt
;
162 p1
= strtod(pt
,&end
);
166 p2
= strtod(pt
,&end
);
169 if ( p2
-p1
>max_diff
) max_diff
= p2
-p1
;
175 double BlueScaleFigureForced(struct psdict
*private,real bluevalues
[], real otherblues
[]) {
180 pt
= PSDictHasEntry(private,"BlueValues");
182 max_diff
= FindMaxDiffOfBlues(pt
,max_diff
);
183 } else if ( bluevalues
!=NULL
) {
184 for ( i
=0; i
<14 && (bluevalues
[i
]!=0 || bluevalues
[i
+1])!=0; i
+=2 ) {
185 if ( bluevalues
[i
+1] - bluevalues
[i
]>=max_diff
)
186 max_diff
= bluevalues
[i
+1] - bluevalues
[i
];
189 pt
= PSDictHasEntry(private,"FamilyBlues");
191 max_diff
= FindMaxDiffOfBlues(pt
,max_diff
);
193 pt
= PSDictHasEntry(private,"OtherBlues");
195 max_diff
= FindMaxDiffOfBlues(pt
,max_diff
);
196 else if ( otherblues
!=NULL
) {
197 for ( i
=0; i
<10 && (otherblues
[i
]!=0 || otherblues
[i
+1]!=0); i
+=2 ) {
198 if ( otherblues
[i
+1] - otherblues
[i
]>=max_diff
)
199 max_diff
= otherblues
[i
+1] - otherblues
[i
];
202 pt
= PSDictHasEntry(private,"FamilyOtherBlues");
204 max_diff
= FindMaxDiffOfBlues(pt
,max_diff
);
207 if ( 1/max_diff
> .039625 )
210 return( .99/max_diff
);
213 double BlueScaleFigure(struct psdict
*private,real bluevalues
[], real otherblues
[]) {
214 if ( PSDictHasEntry(private,"BlueScale")!=NULL
)
216 return BlueScaleFigureForced(private, bluevalues
, otherblues
);