@@ -74,7 +74,7 @@ linebreak_start(int f, integer localeStrNum, uint16_t* text, integer textLength)
74
74
UErrorCode status = U_ZERO_ERROR ;
75
75
char * locale = (char * )gettexstring (localeStrNum );
76
76
77
- if (font_area [f ] == OTGR_FONT_FLAG && strcmp (locale , "G" ) == 0 ) {
77
+ if (font_area [f ] == OTGR_FONT_FLAG && streq_ptr (locale , "G" )) {
78
78
XeTeXLayoutEngine engine = (XeTeXLayoutEngine ) font_layout_engine [f ];
79
79
if (initGraphiteBreaking (engine , text , textLength ))
80
80
/* user asked for Graphite line breaking and the font supports it */
@@ -186,7 +186,7 @@ static void*
186
186
load_mapping_file (const char * s , const char * e , char byteMapping )
187
187
{
188
188
TECkit_Converter cnv = 0 ;
189
- char * buffer = ( char * ) xmalloc (e - s + 5 );
189
+ char * buffer = xmalloc (e - s + 5 );
190
190
rust_input_handle_t map ;
191
191
192
192
strncpy (buffer , s , e - s );
@@ -196,7 +196,7 @@ load_mapping_file(const char* s, const char* e, char byteMapping)
196
196
map = ttstub_input_open (buffer , kpse_miscfonts_format , 0 );
197
197
if (map ) {
198
198
size_t mappingSize = ttstub_input_get_size (map );
199
- Byte * mapping = ( Byte * ) xmalloc (mappingSize );
199
+ Byte * mapping = xmalloc (mappingSize );
200
200
201
201
if (ttstub_input_read (map , (char * ) mapping , mappingSize ) != mappingSize )
202
202
_tt_abort ("could not read mapping file \"%s\"" , buffer );
@@ -233,8 +233,7 @@ check_for_tfm_font_mapping(void)
233
233
{
234
234
char * cp = strstr ((char * )name_of_file + 1 , ":mapping=" );
235
235
if (saved_mapping_name != NULL ) {
236
- free (saved_mapping_name );
237
- saved_mapping_name = NULL ;
236
+ saved_mapping_name = mfree (saved_mapping_name );
238
237
}
239
238
if (cp != NULL ) {
240
239
* cp = 0 ;
@@ -253,8 +252,7 @@ load_tfm_font_mapping(void)
253
252
if (saved_mapping_name != NULL ) {
254
253
rval = load_mapping_file (saved_mapping_name ,
255
254
saved_mapping_name + strlen (saved_mapping_name ), 1 );
256
- free (saved_mapping_name );
257
- saved_mapping_name = NULL ;
255
+ saved_mapping_name = mfree (saved_mapping_name );
258
256
}
259
257
return rval ;
260
258
}
@@ -380,53 +378,53 @@ readCommonFeatures(const char* feat, const char* end, float* extend, float* slan
380
378
// returns 1 to go to next_option, -1 for bad_option, 0 to continue
381
379
{
382
380
const char * sep ;
383
- if ( strncmp ( feat , "mapping" , 7 ) == 0 ) {
384
- sep = feat + 7 ;
381
+ sep = strstartswith ( feat , "mapping" );
382
+ if ( sep ) {
385
383
if (* sep != '=' )
386
384
return -1 ;
387
385
loaded_font_mapping = load_mapping_file (sep + 1 , end , 0 );
388
386
return 1 ;
389
387
}
390
388
391
- if ( strncmp ( feat , "extend" , 6 ) == 0 ) {
392
- sep = feat + 6 ;
389
+ sep = strstartswith ( feat , "extend" );
390
+ if ( sep ) {
393
391
if (* sep != '=' )
394
392
return -1 ;
395
393
++ sep ;
396
394
* extend = read_double (& sep );
397
395
return 1 ;
398
396
}
399
397
400
- if ( strncmp ( feat , "slant" , 5 ) == 0 ) {
401
- sep = feat + 5 ;
398
+ sep = strstartswith ( feat , "slant" );
399
+ if ( sep ) {
402
400
if (* sep != '=' )
403
401
return -1 ;
404
402
++ sep ;
405
403
* slant = read_double (& sep );
406
404
return 1 ;
407
405
}
408
406
409
- if ( strncmp ( feat , "embolden" , 8 ) == 0 ) {
410
- sep = feat + 8 ;
407
+ sep = strstartswith ( feat , "embolden" );
408
+ if ( sep ) {
411
409
if (* sep != '=' )
412
410
return -1 ;
413
411
++ sep ;
414
412
* embolden = read_double (& sep );
415
413
return 1 ;
416
414
}
417
415
418
- if ( strncmp ( feat , "letterspace" , 11 ) == 0 ) {
419
- sep = feat + 11 ;
416
+ sep = strstartswith ( feat , "letterspace" );
417
+ if ( sep ) {
420
418
if (* sep != '=' )
421
419
return -1 ;
422
420
++ sep ;
423
421
* letterspace = read_double (& sep );
424
422
return 1 ;
425
423
}
426
424
427
- if (strncmp (feat , "color" , 5 ) == 0 ) {
425
+ sep = strstartswith (feat , "color" );
426
+ if (sep ) {
428
427
const char * s ;
429
- sep = feat + 5 ;
430
428
if (* sep != '=' )
431
429
return -1 ;
432
430
++ sep ;
@@ -533,28 +531,28 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, char* cp1
533
531
while (* cp2 && (* cp2 != ':' ) && (* cp2 != ';' ) && (* cp2 != ',' ))
534
532
++ cp2 ;
535
533
536
- if ( strncmp ( cp1 , "script" , 6 ) == 0 ) {
537
- cp3 = cp1 + 6 ;
534
+ cp3 = strstartswith ( cp1 , "script" );
535
+ if ( cp3 ) {
538
536
if (* cp3 != '=' )
539
537
goto bad_option ;
540
538
++ cp3 ;
541
539
script = hb_tag_from_string (cp3 , cp2 - cp3 );
542
540
goto next_option ;
543
541
}
544
542
545
- if ( strncmp ( cp1 , "language" , 8 ) == 0 ) {
546
- cp3 = cp1 + 8 ;
543
+ cp3 = strstartswith ( cp1 , "language" );
544
+ if ( cp3 ) {
547
545
if (* cp3 != '=' )
548
546
goto bad_option ;
549
547
++ cp3 ;
550
- language = ( char * ) xmalloc (cp2 - cp3 + 1 );
548
+ language = xmalloc (cp2 - cp3 + 1 );
551
549
language [cp2 - cp3 ] = '\0' ;
552
550
memcpy (language , cp3 , cp2 - cp3 );
553
551
goto next_option ;
554
552
}
555
553
556
- if ( strncmp ( cp1 , "shaper" , 6 ) == 0 ) {
557
- cp3 = cp1 + 6 ;
554
+ cp3 = strstartswith ( cp1 , "shaper" );
555
+ if ( cp3 ) {
558
556
if (* cp3 != '=' )
559
557
goto bad_option ;
560
558
++ cp3 ;
@@ -614,7 +612,7 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, char* cp1
614
612
goto next_option ;
615
613
}
616
614
617
- if (strncmp (cp1 , "vertical" , 8 ) == 0 ) {
615
+ if (strstartswith (cp1 , "vertical" ) ) {
618
616
cp3 = cp2 ;
619
617
if (* cp3 == ';' || * cp3 == ':' || * cp3 == ',' )
620
618
-- cp3 ;
@@ -656,7 +654,7 @@ loadOTfont(PlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, char* cp1
656
654
engine = createLayoutEngine (fontRef , font , script , language ,
657
655
features , nFeatures , shapers , rgbValue , extend , slant , embolden );
658
656
659
- if (engine == 0 ) {
657
+ if (! engine ) {
660
658
// only free these if creation failed, otherwise the engine now owns them
661
659
free (features );
662
660
free (shapers );
@@ -731,18 +729,18 @@ find_native_font(unsigned char* uname, integer scaled_size)
731
729
loaded_font_letter_space = 0 ;
732
730
733
731
splitFontName (name , & var , & feat , & end , & index );
734
- nameString = ( char * ) xmalloc (var - name + 1 );
732
+ nameString = xmalloc (var - name + 1 );
735
733
strncpy (nameString , name , var - name );
736
734
nameString [var - name ] = 0 ;
737
735
738
736
if (feat > var ) {
739
- varString = ( char * ) xmalloc (feat - var );
737
+ varString = xmalloc (feat - var );
740
738
strncpy (varString , var + 1 , feat - var - 1 );
741
739
varString [feat - var - 1 ] = 0 ;
742
740
}
743
741
744
742
if (end > feat ) {
745
- featString = ( char * ) xmalloc (end - feat );
743
+ featString = xmalloc (end - feat );
746
744
strncpy (featString , feat + 1 , end - feat - 1 );
747
745
featString [end - feat - 1 ] = 0 ;
748
746
}
@@ -767,11 +765,11 @@ find_native_font(unsigned char* uname, integer scaled_size)
767
765
/* This is duplicated in XeTeXFontMgr::findFont! */
768
766
setReqEngine (0 );
769
767
if (varString ) {
770
- if (strncmp (varString , "/AAT" , 4 ) == 0 )
768
+ if (strstartswith (varString , "/AAT" ) )
771
769
setReqEngine ('A' );
772
- else if ((strncmp (varString , "/OT" , 3 ) == 0 ) || (strncmp (varString , "/ICU" , 4 ) == 0 ))
770
+ else if ((strstartswith (varString , "/OT" ) ) || (strstartswith (varString , "/ICU" ) ))
773
771
setReqEngine ('O' );
774
- else if (strncmp (varString , "/GR" , 3 ) == 0 )
772
+ else if (strstartswith (varString , "/GR" ) )
775
773
setReqEngine ('G' );
776
774
}
777
775
@@ -789,7 +787,7 @@ find_native_font(unsigned char* uname, integer scaled_size)
789
787
} else {
790
788
fontRef = findFontByName (nameString , varString , Fix2D (scaled_size ));
791
789
792
- if (fontRef != 0 ) {
790
+ if (fontRef ) {
793
791
/* update name_of_file to the full name of the font, for error messages during font loading */
794
792
const char * fullName = getFullName (fontRef );
795
793
name_length = strlen (fullName );
@@ -1098,7 +1096,7 @@ makeXDVGlyphArrayData(void* pNode)
1098
1096
if (xdv_buffer != NULL )
1099
1097
free (xdv_buffer );
1100
1098
xdvBufSize = ((i / 1024 ) + 1 ) * 1024 ;
1101
- xdv_buffer = ( char * ) xmalloc (xdvBufSize );
1099
+ xdv_buffer = xmalloc (xdvBufSize );
1102
1100
}
1103
1101
1104
1102
glyph_info = native_glyph_info_ptr (p );
@@ -1249,7 +1247,7 @@ make_font_def(integer f)
1249
1247
if (xdv_buffer != NULL )
1250
1248
free (xdv_buffer );
1251
1249
xdvBufSize = ((fontDefLength / 1024 ) + 1 ) * 1024 ;
1252
- xdv_buffer = ( char * ) xmalloc (xdvBufSize );
1250
+ xdv_buffer = xmalloc (xdvBufSize );
1253
1251
}
1254
1252
cp = xdv_buffer ;
1255
1253
@@ -1303,7 +1301,7 @@ apply_mapping(void* pCnv, uint16_t* txtPtr, int txtLen)
1303
1301
1304
1302
/* allocate outBuffer if not big enough */
1305
1303
if (outLength < txtLen * sizeof (UniChar ) + 32 ) {
1306
- if (mapped_text != 0 )
1304
+ if (mapped_text != NULL )
1307
1305
free (mapped_text );
1308
1306
outLength = txtLen * sizeof (UniChar ) + 32 ;
1309
1307
mapped_text = xmalloc (outLength );
@@ -1597,7 +1595,7 @@ measure_native_node(void* pNode, int use_glyph_metrics)
1597
1595
glyph_info = xcalloc (totalGlyphCount , native_glyph_info_size );
1598
1596
locations = (FixedPoint * )glyph_info ;
1599
1597
glyphIDs = (uint16_t * )(locations + totalGlyphCount );
1600
- glyphAdvances = ( Fixed * ) xcalloc (totalGlyphCount , sizeof (Fixed ));
1598
+ glyphAdvances = xcalloc (totalGlyphCount , sizeof (Fixed ));
1601
1599
totalGlyphCount = 0 ;
1602
1600
1603
1601
x = y = 0.0 ;
@@ -1607,9 +1605,9 @@ measure_native_node(void* pNode, int use_glyph_metrics)
1607
1605
nGlyphs = layoutChars (engine , txtPtr , logicalStart , length , txtLen ,
1608
1606
(dir == UBIDI_RTL ));
1609
1607
1610
- glyphs = ( uint32_t * ) xcalloc (nGlyphs , sizeof (uint32_t ));
1611
- positions = ( FloatPoint * ) xcalloc (nGlyphs + 1 , sizeof (FloatPoint ));
1612
- advances = ( float * ) xcalloc (nGlyphs , sizeof (float ));
1608
+ glyphs = xcalloc (nGlyphs , sizeof (uint32_t ));
1609
+ positions = xcalloc (nGlyphs + 1 , sizeof (FloatPoint ));
1610
+ advances = xcalloc (nGlyphs , sizeof (float ));
1613
1611
1614
1612
getGlyphs (engine , glyphs );
1615
1613
getGlyphAdvances (engine , advances );
@@ -1639,9 +1637,9 @@ measure_native_node(void* pNode, int use_glyph_metrics)
1639
1637
double width = 0 ;
1640
1638
totalGlyphCount = layoutChars (engine , txtPtr , 0 , txtLen , txtLen , (dir == UBIDI_RTL ));
1641
1639
1642
- glyphs = ( uint32_t * ) xcalloc (totalGlyphCount , sizeof (uint32_t ));
1643
- positions = ( FloatPoint * ) xcalloc (totalGlyphCount + 1 , sizeof (FloatPoint ));
1644
- advances = ( float * ) xcalloc (totalGlyphCount , sizeof (float ));
1640
+ glyphs = xcalloc (totalGlyphCount , sizeof (uint32_t ));
1641
+ positions = xcalloc (totalGlyphCount + 1 , sizeof (FloatPoint ));
1642
+ advances = xcalloc (totalGlyphCount , sizeof (float ));
1645
1643
1646
1644
getGlyphs (engine , glyphs );
1647
1645
getGlyphAdvances (engine , advances );
@@ -1652,7 +1650,7 @@ measure_native_node(void* pNode, int use_glyph_metrics)
1652
1650
glyph_info = xcalloc (totalGlyphCount , native_glyph_info_size );
1653
1651
locations = (FixedPoint * )glyph_info ;
1654
1652
glyphIDs = (uint16_t * )(locations + totalGlyphCount );
1655
- glyphAdvances = ( Fixed * ) xcalloc (totalGlyphCount , sizeof (Fixed ));
1653
+ glyphAdvances = xcalloc (totalGlyphCount , sizeof (Fixed ));
1656
1654
for (i = 0 ; i < totalGlyphCount ; ++ i ) {
1657
1655
glyphIDs [i ] = glyphs [i ];
1658
1656
glyphAdvances [i ] = D2Fix (advances [i ]);
0 commit comments