Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33c986b

Browse files
committed
cleanup
1 parent 52d02ab commit 33c986b

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

src/ft2font.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,23 @@ void FT2Font::set_text(
506506
FT_UInt previous = 0;
507507
FT2Font *previous_ft_object = NULL;
508508

509+
FT_WarnCache warn_cache;
510+
509511
for (size_t n = 0; n < N; n++) {
510512
FT_UInt glyph_index = 0;
511513
FT_BBox glyph_bbox;
512514
FT_Pos last_advance;
513515

514516
FT_Error charcode_error, glyph_error;
515517
FT2Font *ft_object_with_glyph = this;
518+
516519
bool was_found = load_char_with_fallback(ft_object_with_glyph, glyph_index, glyphs,
517520
char_to_font, glyph_to_font, codepoints[n], flags,
518-
charcode_error, glyph_error, false);
521+
charcode_error, glyph_error, &warn_cache, false);
519522
if (!was_found) {
520523
// render missing glyph tofu
521524
// come back to top-most font
525+
warn_cache.warn();
522526
ft_object_with_glyph = this;
523527
char_to_font[codepoints[n]] = ft_object_with_glyph;
524528
glyph_to_font[glyph_index] = ft_object_with_glyph;
@@ -579,9 +583,13 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
579583
FT_UInt final_glyph_index;
580584
FT_Error charcode_error, glyph_error;
581585
FT2Font *ft_object_with_glyph = this;
582-
bool was_found = load_char_with_fallback(ft_object_with_glyph, final_glyph_index, glyphs, char_to_font,
583-
glyph_to_font, charcode, flags, charcode_error, glyph_error, true);
586+
FT_WarnCache warn_cache;
587+
bool was_found = load_char_with_fallback(ft_object_with_glyph,
588+
final_glyph_index, glyphs, char_to_font,
589+
glyph_to_font, charcode, flags, charcode_error,
590+
glyph_error, warn_cache, true);
584591
if (!was_found) {
592+
warn_cache.warn();
585593
if (charcode_error) {
586594
throw_ft_error("Could not load charcode", charcode_error);
587595
}
@@ -639,9 +647,12 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph,
639647
FT_Int32 flags,
640648
FT_Error &charcode_error,
641649
FT_Error &glyph_error,
650+
std::vector<FT_WarnCache> &warn_cache,
642651
bool override = false)
643652
{
644-
FT_UInt glyph_index = ft_get_char_index_or_warn(face, charcode);
653+
FT_UInt glyph_index = ft_get_char_index_or_warn(face, charcode, warn=false);
654+
if (!glyph_index){
655+
warn_cache.push_back(charcode, face->family_name)};
645656
if (glyph_index || override) {
646657
if (charcode_error=FT_Load_Glyph(face, glyph_index, flags)) {
647658
return false;
@@ -834,3 +845,9 @@ long FT2Font::get_name_index(char *name)
834845
{
835846
return FT_Get_Name_Index(face, (FT_String *)name);
836847
}
848+
849+
void FT_WarnCache::warn(){
850+
for (int i=0; i<cache.size(); i++){
851+
ft_glyph_warn(cache[i].charcode, cache[i].family_name);
852+
}
853+
}

src/ft2font.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class FT2Image
6666

6767
extern FT_Library _ft2Library;
6868

69+
class FT_WarnCache{
70+
private:
71+
struct entry{
72+
FT_ULong charcode;
73+
FT_String family_name;
74+
};
75+
std::vector<entry> cache;
76+
public:
77+
FT_WarnCache();
78+
void warn();
79+
};
80+
81+
#endif
6982
class FT2Font
7083
{
7184

@@ -91,8 +104,8 @@ class FT2Font
91104
FT_Int32 flags,
92105
FT_Error &charcode_error,
93106
FT_Error &glyph_error,
94-
bool override,
95-
FT_WarnCache &warn_cache);
107+
FT_WarnCache &warn_cache,
108+
bool override);
96109
void load_glyph(FT_UInt glyph_index, FT_Int32 flags, FT2Font *&ft_object, bool fallback);
97110
void load_glyph(FT_UInt glyph_index, FT_Int32 flags);
98111
void get_width_height(long *width, long *height);
@@ -156,17 +169,3 @@ class FT2Font
156169
FT2Font(const FT2Font &);
157170
FT2Font &operator=(const FT2Font &);
158171
};
159-
160-
class FT_WarnCache{
161-
private:
162-
struct entry{
163-
FT_ULong charcode;
164-
FT_String family_name;
165-
};
166-
std::vector<entry> cache;
167-
public:
168-
FT_WarnCache();
169-
void warn();
170-
};
171-
172-
#endif

0 commit comments

Comments
 (0)