mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	REVIEWED: LoadFontData(), load image only if glyph has been found in font
				
					
				
			This commit is contained in:
		| @@ -604,7 +604,6 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz | |||||||
|  |  | ||||||
|             // Fill fontChars in case not provided externally |             // Fill fontChars in case not provided externally | ||||||
|             // NOTE: By default we fill glyphCount consecutively, starting at 32 (Space) |             // NOTE: By default we fill glyphCount consecutively, starting at 32 (Space) | ||||||
|  |  | ||||||
|             if (codepoints == NULL) |             if (codepoints == NULL) | ||||||
|             { |             { | ||||||
|                 codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int)); |                 codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int)); | ||||||
| @@ -612,7 +611,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz | |||||||
|                 genFontChars = true; |                 genFontChars = true; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             chars = (GlyphInfo *)RL_MALLOC(codepointCount*sizeof(GlyphInfo)); |             chars = (GlyphInfo *)RL_CALLOC(codepointCount, sizeof(GlyphInfo)); | ||||||
|  |  | ||||||
|             // NOTE: Using simple packaging, one char after another |             // NOTE: Using simple packaging, one char after another | ||||||
|             for (int i = 0; i < codepointCount; i++) |             for (int i = 0; i < codepointCount; i++) | ||||||
| @@ -630,6 +629,8 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz | |||||||
|                 else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); |                 else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); | ||||||
|                 else chars[i].image.data = NULL; |                 else chars[i].image.data = NULL; | ||||||
|  |  | ||||||
|  |                 if (chars[i].image.data != NULL)    // Glyph data has been found in the font | ||||||
|  |                 { | ||||||
|                     stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL); |                     stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL); | ||||||
|                     chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor); |                     chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor); | ||||||
|  |  | ||||||
| @@ -640,6 +641,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz | |||||||
|                     chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; |                     chars[i].image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; | ||||||
|  |  | ||||||
|                     chars[i].offsetY += (int)((float)ascent*scaleFactor); |                     chars[i].offsetY += (int)((float)ascent*scaleFactor); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 // NOTE: We create an empty image for space character, it could be further required for atlas packing |                 // NOTE: We create an empty image for space character, it could be further required for atlas packing | ||||||
|                 if (ch == 32) |                 if (ch == 32) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ray
					Ray