@@ -1258,7 +1258,7 @@ FontCharsClass::Get_Char_Data (WCHAR ch)
12581258 const FontCharsClassCharDataStruct *retval = nullptr ;
12591259
12601260#ifdef __APPLE__
1261- if ( ch >= 0xFFFD || (ch >= 256 && AlternateUnicodeFont == nullptr && this == AlternateUnicodeFont) )
1261+ if ( ch >= 0xFFFD )
12621262 {
12631263 ch = L' ?' ;
12641264 }
@@ -1397,6 +1397,19 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
13971397 xOrigin = 1 ;
13981398 }
13991399
1400+ if (GDIBitmapBits == nullptr || MemDC == nullptr ) {
1401+ FontCharsClassCharDataStruct *char_data = W3DNEW FontCharsClassCharDataStruct;
1402+ char_data->Value = ch;
1403+ char_data->Width = 0 ;
1404+ char_data->Buffer = nullptr ;
1405+ if ( ch < 256 ) {
1406+ ASCIICharArray[ch] = char_data;
1407+ } else {
1408+ UnicodeCharArray[ch - FirstUnicodeChar] = char_data;
1409+ }
1410+ return char_data;
1411+ }
1412+
14001413 CGContextRef context = (CGContextRef)MemDC;
14011414 CTFontRef ctFont = (CTFontRef)GDIFont;
14021415
@@ -1447,7 +1460,10 @@ FontCharsClass::Store_GDI_Char (WCHAR ch)
14471460 int index = (row * stride);
14481461
14491462 for (int col = 0 ; col < char_size.cx ; col ++) {
1450- uint8 pixel_value = GDIBitmapBits[index];
1463+ uint8 pixel_value = 0 ;
1464+ if (GDIBitmapBits != nullptr && row < height && col < width && index < stride * height) {
1465+ pixel_value = GDIBitmapBits[index];
1466+ }
14511467 index += 1 ;
14521468
14531469 uint32 pixel_color = (pixel_value != 0 ) ? 0x00FFFFFF : 0 ;
@@ -1566,7 +1582,7 @@ FontCharsClass::Update_Current_Buffer (int char_width)
15661582 // Would we extend past this buffer?
15671583 //
15681584#ifdef __APPLE__
1569- int pixels_needed = char_width * CharHeight * 2 ;
1585+ int pixels_needed = ( char_width + PixelOverlap) * CharHeight * 2 ;
15701586#else
15711587 int pixels_needed = char_width * CharHeight;
15721588#endif
@@ -1637,13 +1653,27 @@ FontCharsClass::Create_GDI_Font (const char *font_name)
16371653 CGContextRef context = CGBitmapContextCreate (NULL , width, height, 8 , width, colorSpace, kCGImageAlphaNone );
16381654 CGColorSpaceRelease (colorSpace);
16391655
1656+ if (!context) {
1657+ CFRelease (ctFont);
1658+ GDIFont = nullptr ;
1659+ return false ;
1660+ }
1661+
16401662 CGContextSetShouldSmoothFonts (context, false );
16411663 CGContextSetAllowsFontSmoothing (context, false );
16421664
16431665 MemDC = (HDC )context;
16441666 GDIBitmapBits = (uint8*)CGBitmapContextGetData (context);
16451667 GDIBitmapStride = CGBitmapContextGetBytesPerRow (context);
16461668
1669+ if (!GDIBitmapBits) {
1670+ CGContextRelease (context);
1671+ MemDC = nullptr ;
1672+ CFRelease (ctFont);
1673+ GDIFont = nullptr ;
1674+ return false ;
1675+ }
1676+
16471677 // Generals font uses compressed width on Windows
16481678 CGAffineTransform matrix = CGAffineTransformIdentity;
16491679 if (doingGenerals) {
0 commit comments