@@ -154,6 +154,90 @@ describe("CFFParser", function () {
154154 expect ( properties . ascentScaled ) . toEqual ( true ) ;
155155 } ) ;
156156
157+ it ( "repairs a FontBBox with unsigned-encoded negative coordinates" , function ( ) {
158+ // [-456, -305, 2158, 989] encoded as unsigned 16-bit values; produced
159+ // by some Ghostscript-generated CFF fonts.
160+ cff . topDict . setByName ( "FontBBox" , [ 65080 , 65231 , 2158 , 989 ] ) ;
161+ const fontDataRepaired = new CFFCompiler ( cff ) . compile ( ) ;
162+
163+ const properties = {
164+ bbox : [ - 456 , - 305 , 2158 , 989 ] ,
165+ } ;
166+ const reparsedCff = new CFFParser (
167+ new Stream ( fontDataRepaired ) ,
168+ properties ,
169+ SEAC_ANALYSIS_ENABLED
170+ ) . parse ( ) ;
171+
172+ expect ( reparsedCff . topDict . getByName ( "FontBBox" ) ) . toEqual ( [
173+ - 456 , - 305 , 2158 , 989 ,
174+ ] ) ;
175+ expect ( properties . ascent ) . toEqual ( 989 ) ;
176+ expect ( properties . descent ) . toEqual ( - 305 ) ;
177+ expect ( properties . ascentScaled ) . toEqual ( true ) ;
178+ } ) ;
179+
180+ it ( "doesn't replace a repairable FontBBox with an empty descriptor bbox" , function ( ) {
181+ cff . topDict . setByName ( "FontBBox" , [ 65080 , 65231 , 2158 , 989 ] ) ;
182+ const fontDataRepaired = new CFFCompiler ( cff ) . compile ( ) ;
183+
184+ const properties = {
185+ bbox : [ 0 , 0 , 0 , 0 ] ,
186+ } ;
187+ const reparsedCff = new CFFParser (
188+ new Stream ( fontDataRepaired ) ,
189+ properties ,
190+ SEAC_ANALYSIS_ENABLED
191+ ) . parse ( ) ;
192+
193+ expect ( reparsedCff . topDict . getByName ( "FontBBox" ) ) . toEqual ( [
194+ - 456 , - 305 , 2158 , 989 ,
195+ ] ) ;
196+ expect ( properties . ascent ) . toEqual ( 989 ) ;
197+ expect ( properties . descent ) . toEqual ( - 305 ) ;
198+ expect ( properties . ascentScaled ) . toEqual ( true ) ;
199+ } ) ;
200+
201+ it ( "repairs unsigned-encoded negative FontBBox without descriptor data" , function ( ) {
202+ cff . topDict . setByName ( "FontBBox" , [ 65080 , 65231 , 2158 , 989 ] ) ;
203+ const fontDataRepaired = new CFFCompiler ( cff ) . compile ( ) ;
204+
205+ const properties = { } ;
206+ const reparsedCff = new CFFParser (
207+ new Stream ( fontDataRepaired ) ,
208+ properties ,
209+ SEAC_ANALYSIS_ENABLED
210+ ) . parse ( ) ;
211+
212+ expect ( reparsedCff . topDict . getByName ( "FontBBox" ) ) . toEqual ( [
213+ - 456 , - 305 , 2158 , 989 ,
214+ ] ) ;
215+ expect ( properties . ascent ) . toEqual ( 989 ) ;
216+ expect ( properties . descent ) . toEqual ( - 305 ) ;
217+ expect ( properties . ascentScaled ) . toEqual ( true ) ;
218+ } ) ;
219+
220+ it ( "preserves large positive upper FontBBox coordinates" , function ( ) {
221+ cff . topDict . setByName ( "FontBBox" , [ 0 , - 305 , 40000 , 989 ] ) ;
222+ const fontDataRepaired = new CFFCompiler ( cff ) . compile ( ) ;
223+
224+ const properties = {
225+ bbox : [ 0 , - 305 , 40000 , 989 ] ,
226+ } ;
227+ const reparsedCff = new CFFParser (
228+ new Stream ( fontDataRepaired ) ,
229+ properties ,
230+ SEAC_ANALYSIS_ENABLED
231+ ) . parse ( ) ;
232+
233+ expect ( reparsedCff . topDict . getByName ( "FontBBox" ) ) . toEqual ( [
234+ 0 , - 305 , 40000 , 989 ,
235+ ] ) ;
236+ expect ( properties . ascent ) . toEqual ( 989 ) ;
237+ expect ( properties . descent ) . toEqual ( - 305 ) ;
238+ expect ( properties . ascentScaled ) . toEqual ( true ) ;
239+ } ) ;
240+
157241 it ( "repairs likely Ghostscript-zeroed FDArray private defaults" , function ( ) {
158242 cff . isCIDFont = true ;
159243 cff . topDict . setByName ( "ROS" , [ 0 , 0 , 0 ] ) ;
0 commit comments