@@ -199,14 +199,17 @@ static FT_UInt ft_glyph_warn(FT_ULong charcode)
199199 return 0 ;
200200}
201201
202- static FT_UInt ft_get_char_index_or_warn (FT_Face face, FT_ULong charcode, bool warn = true )
202+ static FT_UInt
203+ ft_get_char_index_or_warn (FT_Face face, FT_ULong charcode, bool warn = true )
203204{
204205 FT_UInt glyph_index = FT_Get_Char_Index (face, charcode);
205206 if (glyph_index) {
206207 return glyph_index;
207208 }
208- if (warn) return ft_glyph_warn (charcode);
209- else return 0 ;
209+ if (warn) {
210+ return ft_glyph_warn (charcode);
211+ }
212+ return 0 ;
210213}
211214
212215// ft_outline_decomposer should be passed to FT_Outline_Decompose. On the
@@ -403,7 +406,7 @@ void FT2Font::clear()
403406 glyph_to_font.clear ();
404407 char_to_font.clear ();
405408
406- for (unsigned int i = 0 ; i < fallbacks.size (); i++) {
409+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
407410 fallbacks[i]->clear ();
408411 }
409412}
@@ -418,7 +421,7 @@ void FT2Font::set_size(double ptsize, double dpi)
418421 FT_Matrix transform = { 65536 / hinting_factor, 0 , 0 , 65536 };
419422 FT_Set_Transform (face, &transform, 0 );
420423
421- for (unsigned int i = 0 ; i < fallbacks.size (); i++) {
424+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
422425 fallbacks[i]->set_size (ptsize, dpi);
423426 }
424427}
@@ -488,7 +491,7 @@ int FT2Font::get_kerning(FT_UInt left, FT_UInt right, FT_UInt mode, FT_Vector &d
488491void FT2Font::set_kerning_factor (int factor)
489492{
490493 kerning_factor = factor;
491- for (unsigned int i = 0 ; i < fallbacks.size (); i ++){
494+ for (size_t i = 0 ; i < fallbacks.size (); i++) {
492495 fallbacks[i]->set_kerning_factor (factor);
493496 }
494497}
@@ -500,7 +503,7 @@ void FT2Font::set_text(
500503
501504 angle = angle / 360.0 * 2 * M_PI;
502505
503- // this computes width and height in subpixels so we have to divide by 64
506+ // this computes width and height in subpixels so we have to multiply by 64
504507 matrix.xx = (FT_Fixed)(cos (angle) * 0x10000L );
505508 matrix.xy = (FT_Fixed)(-sin (angle) * 0x10000L );
506509 matrix.yx = (FT_Fixed)(sin (angle) * 0x10000L );
@@ -514,29 +517,26 @@ void FT2Font::set_text(
514517 bbox.xMin = bbox.yMin = 32000 ;
515518 bbox.xMax = bbox.yMax = -32000 ;
516519
517- for (unsigned int n = 0 ; n < N; n++) {
518- FT_UInt glyph_index;
520+ for (size_t n = 0 ; n < N; n++) {
521+ FT_UInt glyph_index = 0 ;
519522 FT_BBox glyph_bbox;
520523 FT_Pos last_advance;
521524
522- FT_UInt final_glyph_index = 0 ;
523525 FT_Error charcode_error, glyph_error;
524526 FT2Font *ft_object_with_glyph = this ;
525- bool was_found = load_char_with_fallback (ft_object_with_glyph, final_glyph_index , glyphs,
527+ bool was_found = load_char_with_fallback (ft_object_with_glyph, glyph_index , glyphs,
526528 char_to_font, glyph_to_font, codepoints[n], flags,
527529 charcode_error, glyph_error, false );
528530 if (!was_found) {
529531 ft_glyph_warn ((FT_ULong)codepoints[n]);
530532
531- // render tofu
533+ // render missing glyph tofu
532534 // ft_object_with_glyph == this
533535 char_to_font[codepoints[n]] = ft_object_with_glyph;
534- glyph_to_font[final_glyph_index ] = ft_object_with_glyph;
535- ft_object_with_glyph->load_glyph (final_glyph_index , flags, ft_object_with_glyph, false );
536+ glyph_to_font[glyph_index ] = ft_object_with_glyph;
537+ ft_object_with_glyph->load_glyph (glyph_index , flags, ft_object_with_glyph, false );
536538 }
537539
538- glyph_index = final_glyph_index;
539-
540540 // retrieve kerning distance and move pen position
541541 if (use_kerning && previous && glyph_index) {
542542 FT_Vector delta;
@@ -594,24 +594,21 @@ void FT2Font::fill_glyphs(
594594 bbox.xMin = bbox.yMin = 32000 ;
595595 bbox.xMax = bbox.yMax = -32000 ;
596596
597- for (unsigned int n = 0 ; n < N; n++) {
598- FT_UInt glyph_index;
597+ for (size_t n = 0 ; n < N; n++) {
598+ FT_UInt glyph_index = 0 ;
599599 FT_BBox glyph_bbox;
600600 FT_Pos last_advance;
601601
602- FT_UInt final_glyph_index;
603602 FT_Error charcode_error, glyph_error;
604603 FT2Font *ft_object_with_glyph = this ;
605- bool was_found = load_char_with_fallback (ft_object_with_glyph, final_glyph_index , glyphs,
604+ bool was_found = load_char_with_fallback (ft_object_with_glyph, glyph_index , glyphs,
606605 char_to_font, glyph_to_font, codepoints[n], flags,
607606 charcode_error, glyph_error, false );
608607 if (!was_found) {
609608 if (warn) ft_glyph_warn ((FT_ULong)codepoints[n]);
610609 continue ;
611610 }
612611
613- glyph_index = final_glyph_index;
614-
615612 // retrieve kerning distance and move pen position
616613 if (use_kerning && previous && glyph_index) {
617614 FT_Vector delta;
@@ -699,12 +696,16 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
699696
700697 if (glyph_index || override ) {
701698 charcode_error = FT_Load_Glyph (face, glyph_index, flags);
699+ if (charcode_error) {
700+ return false ;
701+ }
702+
702703 FT_Glyph thisGlyph;
703704 glyph_error = FT_Get_Glyph (face->glyph , &thisGlyph);
704-
705- if (charcode_error || glyph_error) {
705+ if (glyph_error) {
706706 return false ;
707707 }
708+
708709 final_glyph_index = glyph_index;
709710
710711 // cache the result for future
@@ -718,12 +719,13 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
718719 }
719720
720721 else {
721- for (unsigned int i = 0 ; i < fallbacks.size (); ++i) {
722+ for (size_t i = 0 ; i < fallbacks.size (); ++i) {
722723 bool was_found = fallbacks[i]->load_char_with_fallback (
723724 ft_object_with_glyph, final_glyph_index, parent_glyphs, parent_char_to_font,
724725 parent_glyph_to_font, charcode, flags, charcode_error, glyph_error, override );
725- if (was_found)
726+ if (was_found) {
726727 return true ;
728+ }
727729 }
728730 return false ;
729731 }
0 commit comments