@@ -958,7 +958,7 @@ void TextServerAdvanced::_generateMTSDF_threaded(void *p_td, uint32_t p_y) {
958958 }
959959}
960960
961- _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf (FontAdvanced *p_font_data, FontForSizeAdvanced *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *outline , const Vector2 &advance ) const {
961+ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf (FontAdvanced *p_font_data, FontForSizeAdvanced *p_data, int p_pixel_range, int p_rect_margin, FT_Outline *p_outline , const Vector2 &p_advance ) const {
962962 msdfgen::Shape shape;
963963
964964 shape.contours .clear ();
@@ -974,13 +974,13 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf(
974974 ft_functions.shift = 0 ;
975975 ft_functions.delta = 0 ;
976976
977- int error = FT_Outline_Decompose (outline , &ft_functions, &context);
977+ int error = FT_Outline_Decompose (p_outline , &ft_functions, &context);
978978 ERR_FAIL_COND_V_MSG (error, FontGlyph (), " FreeType: Outline decomposition error: '" + String (FT_Error_String (error)) + " '." );
979979 if (!shape.contours .empty () && shape.contours .back ().edges .empty ()) {
980980 shape.contours .pop_back ();
981981 }
982982
983- if (FT_Outline_Get_Orientation (outline ) == 1 ) {
983+ if (FT_Outline_Get_Orientation (p_outline ) == 1 ) {
984984 for (int i = 0 ; i < (int )shape.contours .size (); ++i) {
985985 shape.contours [i].reverse ();
986986 }
@@ -993,12 +993,19 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf(
993993
994994 FontGlyph chr;
995995 chr.found = true ;
996- chr.advance = advance ;
996+ chr.advance = p_advance ;
997997
998998 if (shape.validate () && shape.contours .size () > 0 ) {
999999 int w = (bounds.r - bounds.l );
10001000 int h = (bounds.t - bounds.b );
10011001
1002+ if (w == 0 || h == 0 ) {
1003+ chr.texture_idx = -1 ;
1004+ chr.uv_rect = Rect2 ();
1005+ chr.rect = Rect2 ();
1006+ return chr;
1007+ }
1008+
10021009 int mw = w + p_rect_margin * 4 ;
10031010 int mh = h + p_rect_margin * 4 ;
10041011
@@ -1056,12 +1063,24 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf(
10561063#endif
10571064
10581065#ifdef MODULE_FREETYPE_ENABLED
1059- _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitmap (FontForSizeAdvanced *p_data, int p_rect_margin, FT_Bitmap bitmap, int yofs, int xofs, const Vector2 &advance, bool p_bgra) const {
1060- int w = bitmap.width ;
1061- int h = bitmap.rows ;
1066+ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitmap (FontForSizeAdvanced *p_data, int p_rect_margin, FT_Bitmap p_bitmap, int p_yofs, int p_xofs, const Vector2 &p_advance, bool p_bgra) const {
1067+ FontGlyph chr;
1068+ chr.advance = p_advance * p_data->scale / p_data->oversampling ;
1069+ chr.found = true ;
1070+
1071+ int w = p_bitmap.width ;
1072+ int h = p_bitmap.rows ;
1073+
1074+ if (w == 0 || h == 0 ) {
1075+ chr.texture_idx = -1 ;
1076+ chr.uv_rect = Rect2 ();
1077+ chr.rect = Rect2 ();
1078+ return chr;
1079+ }
1080+
10621081 int color_size = 2 ;
10631082
1064- switch (bitmap .pixel_mode ) {
1083+ switch (p_bitmap .pixel_mode ) {
10651084 case FT_PIXEL_MODE_MONO:
10661085 case FT_PIXEL_MODE_GRAY: {
10671086 color_size = 2 ;
@@ -1100,54 +1119,54 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitma
11001119 for (int j = 0 ; j < w; j++) {
11011120 int ofs = ((i + tex_pos.y + p_rect_margin * 2 ) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2 ) * color_size;
11021121 ERR_FAIL_COND_V (ofs >= tex.image ->data_size (), FontGlyph ());
1103- switch (bitmap .pixel_mode ) {
1122+ switch (p_bitmap .pixel_mode ) {
11041123 case FT_PIXEL_MODE_MONO: {
1105- int byte = i * bitmap .pitch + (j >> 3 );
1124+ int byte = i * p_bitmap .pitch + (j >> 3 );
11061125 int bit = 1 << (7 - (j % 8 ));
11071126 wr[ofs + 0 ] = 255 ; // grayscale as 1
1108- wr[ofs + 1 ] = (bitmap .buffer [byte] & bit) ? 255 : 0 ;
1127+ wr[ofs + 1 ] = (p_bitmap .buffer [byte] & bit) ? 255 : 0 ;
11091128 } break ;
11101129 case FT_PIXEL_MODE_GRAY:
11111130 wr[ofs + 0 ] = 255 ; // grayscale as 1
1112- wr[ofs + 1 ] = bitmap .buffer [i * bitmap .pitch + j];
1131+ wr[ofs + 1 ] = p_bitmap .buffer [i * p_bitmap .pitch + j];
11131132 break ;
11141133 case FT_PIXEL_MODE_BGRA: {
1115- int ofs_color = i * bitmap .pitch + (j << 2 );
1116- wr[ofs + 2 ] = bitmap .buffer [ofs_color + 0 ];
1117- wr[ofs + 1 ] = bitmap .buffer [ofs_color + 1 ];
1118- wr[ofs + 0 ] = bitmap .buffer [ofs_color + 2 ];
1119- wr[ofs + 3 ] = bitmap .buffer [ofs_color + 3 ];
1134+ int ofs_color = i * p_bitmap .pitch + (j << 2 );
1135+ wr[ofs + 2 ] = p_bitmap .buffer [ofs_color + 0 ];
1136+ wr[ofs + 1 ] = p_bitmap .buffer [ofs_color + 1 ];
1137+ wr[ofs + 0 ] = p_bitmap .buffer [ofs_color + 2 ];
1138+ wr[ofs + 3 ] = p_bitmap .buffer [ofs_color + 3 ];
11201139 } break ;
11211140 case FT_PIXEL_MODE_LCD: {
1122- int ofs_color = i * bitmap .pitch + (j * 3 );
1141+ int ofs_color = i * p_bitmap .pitch + (j * 3 );
11231142 if (p_bgra) {
1124- wr[ofs + 0 ] = bitmap .buffer [ofs_color + 2 ];
1125- wr[ofs + 1 ] = bitmap .buffer [ofs_color + 1 ];
1126- wr[ofs + 2 ] = bitmap .buffer [ofs_color + 0 ];
1143+ wr[ofs + 0 ] = p_bitmap .buffer [ofs_color + 2 ];
1144+ wr[ofs + 1 ] = p_bitmap .buffer [ofs_color + 1 ];
1145+ wr[ofs + 2 ] = p_bitmap .buffer [ofs_color + 0 ];
11271146 wr[ofs + 3 ] = 255 ;
11281147 } else {
1129- wr[ofs + 0 ] = bitmap .buffer [ofs_color + 0 ];
1130- wr[ofs + 1 ] = bitmap .buffer [ofs_color + 1 ];
1131- wr[ofs + 2 ] = bitmap .buffer [ofs_color + 2 ];
1148+ wr[ofs + 0 ] = p_bitmap .buffer [ofs_color + 0 ];
1149+ wr[ofs + 1 ] = p_bitmap .buffer [ofs_color + 1 ];
1150+ wr[ofs + 2 ] = p_bitmap .buffer [ofs_color + 2 ];
11321151 wr[ofs + 3 ] = 255 ;
11331152 }
11341153 } break ;
11351154 case FT_PIXEL_MODE_LCD_V: {
1136- int ofs_color = i * bitmap .pitch * 3 + j;
1155+ int ofs_color = i * p_bitmap .pitch * 3 + j;
11371156 if (p_bgra) {
1138- wr[ofs + 0 ] = bitmap .buffer [ofs_color + bitmap .pitch * 2 ];
1139- wr[ofs + 1 ] = bitmap .buffer [ofs_color + bitmap .pitch ];
1140- wr[ofs + 2 ] = bitmap .buffer [ofs_color + 0 ];
1157+ wr[ofs + 0 ] = p_bitmap .buffer [ofs_color + p_bitmap .pitch * 2 ];
1158+ wr[ofs + 1 ] = p_bitmap .buffer [ofs_color + p_bitmap .pitch ];
1159+ wr[ofs + 2 ] = p_bitmap .buffer [ofs_color + 0 ];
11411160 wr[ofs + 3 ] = 255 ;
11421161 } else {
1143- wr[ofs + 0 ] = bitmap .buffer [ofs_color + 0 ];
1144- wr[ofs + 1 ] = bitmap .buffer [ofs_color + bitmap .pitch ];
1145- wr[ofs + 2 ] = bitmap .buffer [ofs_color + bitmap .pitch * 2 ];
1162+ wr[ofs + 0 ] = p_bitmap .buffer [ofs_color + 0 ];
1163+ wr[ofs + 1 ] = p_bitmap .buffer [ofs_color + p_bitmap .pitch ];
1164+ wr[ofs + 2 ] = p_bitmap .buffer [ofs_color + p_bitmap .pitch * 2 ];
11461165 wr[ofs + 3 ] = 255 ;
11471166 }
11481167 } break ;
11491168 default :
1150- ERR_FAIL_V_MSG (FontGlyph (), " Font uses unsupported pixel format: " + String::num_int64 (bitmap .pixel_mode ) + " ." );
1169+ ERR_FAIL_V_MSG (FontGlyph (), " Font uses unsupported pixel format: " + String::num_int64 (p_bitmap .pixel_mode ) + " ." );
11511170 break ;
11521171 }
11531172 }
@@ -1156,13 +1175,10 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitma
11561175
11571176 tex.dirty = true ;
11581177
1159- FontGlyph chr;
1160- chr.advance = advance * p_data->scale / p_data->oversampling ;
11611178 chr.texture_idx = tex_pos.index ;
1162- chr.found = true ;
11631179
11641180 chr.uv_rect = Rect2 (tex_pos.x + p_rect_margin, tex_pos.y + p_rect_margin, w + p_rect_margin * 2 , h + p_rect_margin * 2 );
1165- chr.rect .position = Vector2 (xofs - p_rect_margin, -yofs - p_rect_margin) * p_data->scale / p_data->oversampling ;
1181+ chr.rect .position = Vector2 (p_xofs - p_rect_margin, -p_yofs - p_rect_margin) * p_data->scale / p_data->oversampling ;
11661182 chr.rect .size = chr.uv_rect .size * p_data->scale / p_data->oversampling ;
11671183 return chr;
11681184}
@@ -3619,9 +3635,6 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
36193635
36203636 const FontGlyph &gl = fd->cache [size]->glyph_map [index];
36213637 if (gl.found ) {
3622- if (gl.uv_rect .size .x <= 2 || gl.uv_rect .size .y <= 2 ) {
3623- return ; // Nothing to draw.
3624- }
36253638 ERR_FAIL_COND (gl.texture_idx < -1 || gl.texture_idx >= fd->cache [size]->textures .size ());
36263639
36273640 if (gl.texture_idx != -1 ) {
@@ -3730,9 +3743,6 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
37303743
37313744 const FontGlyph &gl = fd->cache [size]->glyph_map [index];
37323745 if (gl.found ) {
3733- if (gl.uv_rect .size .x <= 2 || gl.uv_rect .size .y <= 2 ) {
3734- return ; // Nothing to draw.
3735- }
37363746 ERR_FAIL_COND (gl.texture_idx < -1 || gl.texture_idx >= fd->cache [size]->textures .size ());
37373747
37383748 if (gl.texture_idx != -1 ) {
0 commit comments