@@ -142,7 +142,7 @@ static Font defaultFont = { 0 };
142
142
static Font LoadBMFont (const char * fileName ); // Load a BMFont file (AngelCode font file)
143
143
#endif
144
144
#if defined(SUPPORT_FILEFORMAT_BDF )
145
- static GlyphInfo * LoadBDFFontData (const unsigned char * fileData , int dataSize , int * codepoints , int codepointCount , int * outFontSize );
145
+ static GlyphInfo * LoadFontDataBDF (const unsigned char * fileData , int dataSize , int * codepoints , int codepointCount , int * outFontSize );
146
146
#endif
147
147
static int textLineSpacing = 15 ; // Text vertical line spacing in pixels
148
148
@@ -547,7 +547,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
547
547
#if defined(SUPPORT_FILEFORMAT_BDF )
548
548
if (TextIsEqual (fileExtLower , ".bdf" ))
549
549
{
550
- font .glyphs = LoadBDFFontData (fileData , dataSize , codepoints , font .glyphCount , & font .baseSize );
550
+ font .glyphs = LoadFontDataBDF (fileData , dataSize , codepoints , font .glyphCount , & font .baseSize );
551
551
}
552
552
else
553
553
#endif
@@ -1457,25 +1457,33 @@ int TextToInteger(const char *text)
1457
1457
return value * sign ;
1458
1458
}
1459
1459
1460
+ // Get float value from text
1461
+ // NOTE: This function replaces atof() [stdlib.h]
1462
+ // WARNING: Only '.' character is understood as decimal point
1460
1463
float TextToFloat (const char * text )
1461
1464
{
1462
1465
float value = 0.0f ;
1463
1466
float sign = 1.0f ;
1464
1467
1465
1468
if ((text [0 ] == '+' ) || (text [0 ] == '-' ))
1466
1469
{
1467
- if (text [0 ] == '-' ) sign = -1 ;
1470
+ if (text [0 ] == '-' ) sign = -1.0f ;
1468
1471
text ++ ;
1469
1472
}
1470
- int i = 0 ;
1471
- for (; ((text [i ] >= '0' ) && (text [i ] <= '9' )); ++ i ) value = value * 10.0f + (float )(text [i ] - '0' );
1472
- if ( text [ i ++ ] != '.' ) return value * sign ;
1473
- float divisor = 10.0f ;
1474
- for (; (( text [ i ] >= '0' ) && ( text [ i ] <= '9' )); ++ i )
1473
+
1474
+ for (int i = 0 ; ((text [i ] >= '0' ) && (text [i ] <= '9' )); i ++ ) value = value * 10.0f + (float )(text [i ] - '0' );
1475
+
1476
+ if ( text [ i ++ ] != '.' ) value *= sign ;
1477
+ else
1475
1478
{
1476
- value += ((float )(text [i ] - '0' ))/divisor ;
1477
- divisor = divisor * 10.0f ;
1479
+ float divisor = 10.0f ;
1480
+ for (int i = 0 ; ((text [i ] >= '0' ) && (text [i ] <= '9' )); i ++ )
1481
+ {
1482
+ value += ((float )(text [i ] - '0' ))/divisor ;
1483
+ divisor = divisor * 10.0f ;
1484
+ }
1478
1485
}
1486
+
1479
1487
return value ;
1480
1488
}
1481
1489
@@ -2275,41 +2283,41 @@ static char HexToInt(char hex) {
2275
2283
2276
2284
// Load font data for further use
2277
2285
// NOTE: Requires BDF font memory data
2278
- static GlyphInfo * LoadBDFFontData (const unsigned char * fileData , int dataSize , int * codepoints , int codepointCount , int * outFontSize )
2286
+ static GlyphInfo * LoadFontDataBDF (const unsigned char * fileData , int dataSize , int * codepoints , int codepointCount , int * outFontSize )
2279
2287
{
2280
2288
#define MAX_BUFFER_SIZE 256
2289
+
2281
2290
char buffer [MAX_BUFFER_SIZE ] = { 0 };
2282
2291
2283
2292
GlyphInfo * glyphs = NULL ;
2284
-
2285
2293
bool genFontChars = false;
2286
2294
2287
- int totalReadBytes = 0 ; // Data bytes read (total)
2288
- int readBytes = 0 ; // Data bytes read (line)
2289
- int readVars = 0 ; // Variables filled by sscanf()
2295
+ int totalReadBytes = 0 ; // Data bytes read (total)
2296
+ int readBytes = 0 ; // Data bytes read (line)
2297
+ int readVars = 0 ; // Variables filled by sscanf()
2290
2298
2291
2299
const char * fileText = (const char * )fileData ;
2292
2300
const char * fileTextPtr = fileText ;
2293
2301
2294
- bool fontMalformed = false; // Is the font malformed
2295
- bool fontStarted = false; // Has font started (STARTFONT)
2296
- int fontBBw = 0 ; // Font base character bounding box width
2297
- int fontBBh = 0 ; // Font base character bounding box height
2298
- int fontBBxoff0 = 0 ; // Font base character bounding box X0 offset
2299
- int fontBByoff0 = 0 ; // Font base character bounding box Y0 offset
2300
- int fontAscent = 0 ; // Font ascent
2301
-
2302
- bool charStarted = false; // Has character started (STARTCHAR)
2303
- bool charBitmapStarted = false; // Has bitmap data started (BITMAP)
2304
- int charBitmapNextRow = 0 ; // Y position for the next row of bitmap data
2305
- int charEncoding = -1 ; // The unicode value of the character (-1 if not set)
2306
- int charBBw = 0 ; // Character bounding box width
2307
- int charBBh = 0 ; // Character bounding box height
2308
- int charBBxoff0 = 0 ; // Character bounding box X0 offset
2309
- int charBByoff0 = 0 ; // Character bounding box Y0 offset
2310
- int charDWidthX = 0 ; // Character advance X
2311
- int charDWidthY = 0 ; // Character advance Y (unused)
2312
- GlyphInfo * charGlyphInfo = NULL ; // Pointer to output glyph info (NULL if not set)
2302
+ bool fontMalformed = false; // Is the font malformed
2303
+ bool fontStarted = false; // Has font started (STARTFONT)
2304
+ int fontBBw = 0 ; // Font base character bounding box width
2305
+ int fontBBh = 0 ; // Font base character bounding box height
2306
+ int fontBBxoff0 = 0 ; // Font base character bounding box X0 offset
2307
+ int fontBByoff0 = 0 ; // Font base character bounding box Y0 offset
2308
+ int fontAscent = 0 ; // Font ascent
2309
+
2310
+ bool charStarted = false; // Has character started (STARTCHAR)
2311
+ bool charBitmapStarted = false; // Has bitmap data started (BITMAP)
2312
+ int charBitmapNextRow = 0 ; // Y position for the next row of bitmap data
2313
+ int charEncoding = -1 ; // The unicode value of the character (-1 if not set)
2314
+ int charBBw = 0 ; // Character bounding box width
2315
+ int charBBh = 0 ; // Character bounding box height
2316
+ int charBBxoff0 = 0 ; // Character bounding box X0 offset
2317
+ int charBByoff0 = 0 ; // Character bounding box Y0 offset
2318
+ int charDWidthX = 0 ; // Character advance X
2319
+ int charDWidthY = 0 ; // Character advance Y (unused)
2320
+ GlyphInfo * charGlyphInfo = NULL ; // Pointer to output glyph info (NULL if not set)
2313
2321
2314
2322
if (fileData == NULL ) return glyphs ;
2315
2323
@@ -2333,12 +2341,12 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
2333
2341
totalReadBytes += (readBytes + 1 );
2334
2342
fileTextPtr += (readBytes + 1 );
2335
2343
2336
- // COMMENT
2344
+ // Line: COMMENT
2337
2345
if (strstr (buffer , "COMMENT" ) != NULL ) continue ; // Ignore line
2338
2346
2339
2347
if (charStarted )
2340
2348
{
2341
- // ENDCHAR
2349
+ // Line: ENDCHAR
2342
2350
if (strstr (buffer , "ENDCHAR" ) != NULL )
2343
2351
{
2344
2352
charStarted = false;
@@ -2347,59 +2355,56 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
2347
2355
2348
2356
if (charBitmapStarted )
2349
2357
{
2350
- if (charGlyphInfo != NULL ) {
2358
+ if (charGlyphInfo != NULL )
2359
+ {
2351
2360
int pixelY = charBitmapNextRow ++ ;
2352
- if (pixelY >= charGlyphInfo -> image .height )
2353
- {
2354
- break ;
2355
- }
2361
+
2362
+ if (pixelY >= charGlyphInfo -> image .height ) break ;
2363
+
2356
2364
for (int x = 0 ; x < readBytes ; x ++ )
2357
2365
{
2358
2366
char byte = HexToInt (buffer [x ]);
2367
+
2359
2368
for (int bitX = 0 ; bitX < 4 ; bitX ++ )
2360
2369
{
2361
2370
int pixelX = ((x * 4 ) + bitX );
2362
- if (pixelX >= charGlyphInfo -> image .width )
2363
- {
2364
- break ;
2365
- }
2366
-
2367
- if ((byte & (8 >> bitX )) > 0 )
2368
- {
2369
- ((unsigned char * )charGlyphInfo -> image .data )[(pixelY * charGlyphInfo -> image .width ) + pixelX ] = 255 ;
2370
- }
2371
+
2372
+ if (pixelX >= charGlyphInfo -> image .width ) break ;
2373
+
2374
+ if ((byte & (8 >> bitX )) > 0 ) ((unsigned char * )charGlyphInfo -> image .data )[(pixelY * charGlyphInfo -> image .width ) + pixelX ] = 255 ;
2371
2375
}
2372
2376
}
2373
2377
}
2374
2378
continue ;
2375
2379
}
2376
2380
2377
- // ENCODING
2381
+ // Line: ENCODING
2378
2382
if (strstr (buffer , "ENCODING" ) != NULL )
2379
2383
{
2380
2384
readVars = sscanf (buffer , "ENCODING %i" , & charEncoding );
2381
2385
continue ;
2382
2386
}
2383
2387
2384
- // BBX
2388
+ // Line: BBX
2385
2389
if (strstr (buffer , "BBX" ) != NULL )
2386
2390
{
2387
2391
readVars = sscanf (buffer , "BBX %i %i %i %i" , & charBBw , & charBBh , & charBBxoff0 , & charBByoff0 );
2388
2392
continue ;
2389
2393
}
2390
2394
2391
- // DWIDTH
2395
+ // Line: DWIDTH
2392
2396
if (strstr (buffer , "DWIDTH" ) != NULL )
2393
2397
{
2394
2398
readVars = sscanf (buffer , "DWIDTH %i %i" , & charDWidthX , & charDWidthY );
2395
2399
continue ;
2396
2400
}
2397
2401
2398
- // BITMAP
2402
+ // Line: BITMAP
2399
2403
if (strstr (buffer , "BITMAP" ) != NULL )
2400
2404
{
2401
2405
// Search for glyph index in codepoints
2402
2406
charGlyphInfo = NULL ;
2407
+
2403
2408
for (int codepointIndex = 0 ; codepointIndex < codepointCount ; codepointIndex ++ )
2404
2409
{
2405
2410
if (codepoints [codepointIndex ] == charEncoding )
@@ -2432,30 +2437,24 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
2432
2437
}
2433
2438
else if (fontStarted )
2434
2439
{
2435
- // ENDFONT
2440
+ // Line: ENDFONT
2436
2441
if (strstr (buffer , "ENDFONT" ) != NULL )
2437
2442
{
2438
2443
fontStarted = false;
2439
2444
break ;
2440
2445
}
2441
2446
2442
- // SIZE
2447
+ // Line: SIZE
2443
2448
if (strstr (buffer , "SIZE" ) != NULL )
2444
2449
{
2445
- if (outFontSize != NULL )
2446
- {
2447
- readVars = sscanf (buffer , "SIZE %i" , outFontSize );
2448
- }
2450
+ if (outFontSize != NULL ) readVars = sscanf (buffer , "SIZE %i" , outFontSize );
2449
2451
continue ;
2450
2452
}
2451
2453
2452
2454
// PIXEL_SIZE
2453
2455
if (strstr (buffer , "PIXEL_SIZE" ) != NULL )
2454
2456
{
2455
- if (outFontSize != NULL )
2456
- {
2457
- readVars = sscanf (buffer , "PIXEL_SIZE %i" , outFontSize );
2458
- }
2457
+ if (outFontSize != NULL ) readVars = sscanf (buffer , "PIXEL_SIZE %i" , outFontSize );
2459
2458
continue ;
2460
2459
}
2461
2460
@@ -2520,7 +2519,6 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
2520
2519
2521
2520
return glyphs ;
2522
2521
}
2523
-
2524
2522
#endif
2525
2523
2526
2524
#endif // SUPPORT_MODULE_RTEXT
0 commit comments