@@ -185,14 +185,17 @@ static FT_UInt ft_glyph_warn(FT_ULong charcode)
185185 return 0 ;
186186}
187187
188- static FT_UInt ft_get_char_index_or_warn (FT_Face face, FT_ULong charcode, bool warn = true )
188+ static FT_UInt
189+ ft_get_char_index_or_warn (FT_Face face, FT_ULong charcode, bool warn = true )
189190{
190191 FT_UInt glyph_index = FT_Get_Char_Index (face, charcode);
191192 if (glyph_index) {
192193 return glyph_index;
193194 }
194- if (warn) return ft_glyph_warn (charcode);
195- else return 0 ;
195+ if (warn) {
196+ return ft_glyph_warn (charcode);
197+ }
198+ return 0 ;
196199}
197200
198201// ft_outline_decomposer should be passed to FT_Outline_Decompose. On the
@@ -396,7 +399,7 @@ void FT2Font::clear()
396399 glyph_to_font.clear ();
397400 char_to_font.clear ();
398401
399- for (unsigned int i = 0 ; i < fallbacks.size (); i++) {
402+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
400403 fallbacks[i]->clear ();
401404 }
402405}
@@ -411,7 +414,7 @@ void FT2Font::set_size(double ptsize, double dpi)
411414 FT_Matrix transform = { 65536 / hinting_factor, 0 , 0 , 65536 };
412415 FT_Set_Transform (face, &transform, 0 );
413416
414- for (unsigned int i = 0 ; i < fallbacks.size (); i++) {
417+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
415418 fallbacks[i]->set_size (ptsize, dpi);
416419 }
417420}
@@ -481,7 +484,7 @@ int FT2Font::get_kerning(FT_UInt left, FT_UInt right, FT_UInt mode, FT_Vector &d
481484void FT2Font::set_kerning_factor (int factor)
482485{
483486 kerning_factor = factor;
484- for (unsigned int i = 0 ; i < fallbacks.size (); i ++){
487+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
485488 fallbacks[i]->set_kerning_factor (factor);
486489 }
487490}
@@ -493,7 +496,7 @@ void FT2Font::set_text(
493496
494497 angle = angle / 360.0 * 2 * M_PI;
495498
496- // this computes width and height in subpixels so we have to divide by 64
499+ // this computes width and height in subpixels so we have to multiply by 64
497500 matrix.xx = (FT_Fixed)(cos (angle) * 0x10000L );
498501 matrix.xy = (FT_Fixed)(-sin (angle) * 0x10000L );
499502 matrix.yx = (FT_Fixed)(sin (angle) * 0x10000L );
@@ -507,29 +510,26 @@ void FT2Font::set_text(
507510 bbox.xMin = bbox.yMin = 32000 ;
508511 bbox.xMax = bbox.yMax = -32000 ;
509512
510- for (unsigned int n = 0 ; n < N; n++) {
511- FT_UInt glyph_index;
513+ for (size_t n = 0 ; n < N; n++) {
514+ FT_UInt glyph_index = 0 ;
512515 FT_BBox glyph_bbox;
513516 FT_Pos last_advance;
514517
515- FT_UInt final_glyph_index = 0 ;
516518 FT_Error charcode_error, glyph_error;
517519 FT2Font *ft_object_with_glyph = this ;
518- bool was_found = load_char_with_fallback (ft_object_with_glyph, final_glyph_index , glyphs,
520+ bool was_found = load_char_with_fallback (ft_object_with_glyph, glyph_index , glyphs,
519521 char_to_font, glyph_to_font, codepoints[n], flags,
520522 charcode_error, glyph_error, false );
521523 if (!was_found) {
522524 ft_glyph_warn ((FT_ULong)codepoints[n]);
523525
524- // render tofu
526+ // render missing glyph tofu
525527 // ft_object_with_glyph == this
526528 char_to_font[codepoints[n]] = ft_object_with_glyph;
527- glyph_to_font[final_glyph_index ] = ft_object_with_glyph;
528- ft_object_with_glyph->load_glyph (final_glyph_index , flags, ft_object_with_glyph, false );
529+ glyph_to_font[glyph_index ] = ft_object_with_glyph;
530+ ft_object_with_glyph->load_glyph (glyph_index , flags, ft_object_with_glyph, false );
529531 }
530532
531- glyph_index = final_glyph_index;
532-
533533 // retrieve kerning distance and move pen position
534534 if (use_kerning && previous && glyph_index) {
535535 FT_Vector delta;
@@ -587,24 +587,21 @@ void FT2Font::fill_glyphs(
587587 bbox.xMin = bbox.yMin = 32000 ;
588588 bbox.xMax = bbox.yMax = -32000 ;
589589
590- for (unsigned int n = 0 ; n < N; n++) {
591- FT_UInt glyph_index;
590+ for (size_t n = 0 ; n < N; n++) {
591+ FT_UInt glyph_index = 0 ;
592592 FT_BBox glyph_bbox;
593593 FT_Pos last_advance;
594594
595- FT_UInt final_glyph_index;
596595 FT_Error charcode_error, glyph_error;
597596 FT2Font *ft_object_with_glyph = this ;
598- bool was_found = load_char_with_fallback (ft_object_with_glyph, final_glyph_index , glyphs,
597+ bool was_found = load_char_with_fallback (ft_object_with_glyph, glyph_index , glyphs,
599598 char_to_font, glyph_to_font, codepoints[n], flags,
600599 charcode_error, glyph_error, false );
601600 if (!was_found) {
602601 if (warn) ft_glyph_warn ((FT_ULong)codepoints[n]);
603602 continue ;
604603 }
605604
606- glyph_index = final_glyph_index;
607-
608605 // retrieve kerning distance and move pen position
609606 if (use_kerning && previous && glyph_index) {
610607 FT_Vector delta;
@@ -692,12 +689,16 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
692689
693690 if (glyph_index || override ) {
694691 charcode_error = FT_Load_Glyph (face, glyph_index, flags);
692+ if (charcode_error) {
693+ return false ;
694+ }
695+
695696 FT_Glyph thisGlyph;
696697 glyph_error = FT_Get_Glyph (face->glyph , &thisGlyph);
697-
698- if (charcode_error || glyph_error) {
698+ if (glyph_error) {
699699 return false ;
700700 }
701+
701702 final_glyph_index = glyph_index;
702703
703704 // cache the result for future
@@ -711,12 +712,13 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
711712 }
712713
713714 else {
714- for (unsigned int i = 0 ; i < fallbacks.size (); ++i) {
715+ for (size_t i = 0 ; i < fallbacks.size (); ++i) {
715716 bool was_found = fallbacks[i]->load_char_with_fallback (
716717 ft_object_with_glyph, final_glyph_index, parent_glyphs, parent_char_to_font,
717718 parent_glyph_to_font, charcode, flags, charcode_error, glyph_error, override );
718- if (was_found)
719+ if (was_found) {
719720 return true ;
721+ }
720722 }
721723 return false ;
722724 }
0 commit comments