- // If the system does not support a suitable font, fallback to Latin
- if( 0u == fontId )
- {
- fontId = *( defaultFontPerScriptCacheBuffer + TextAbstraction::LATIN );
- }
- if( 0u == fontId )
- {
- fontId = fontClient.FindDefaultFont( UTF32_A, pointSize );
- }
+ if( isValidCachedDefaultFont )
+ {
+ // Use the cached default font for the script if there is one.
+ fontId = cachedDefaultFontId;
+ }
+ else
+ {
+ // There is no valid cached default font for the script.
+
+ DefaultFonts* defaultFontsPerScript = NULL;
+
+ // Emojis are present in many monochrome fonts; prefer color by default.
+ const bool preferColor = ( TextAbstraction::EMOJI == script );
+
+ // Find a fallback-font.
+ fontId = fontClient.FindFallbackFont( character,
+ currentFontDescription,
+ currentFontPointSize,
+ preferColor );
+
+ if( 0u == fontId )
+ {
+ // If the system does not support a suitable font, fallback to Latin
+ defaultFontsPerScript = *( defaultFontPerScriptCacheBuffer + TextAbstraction::LATIN );
+ if( NULL != defaultFontsPerScript )
+ {
+ fontId = defaultFontsPerScript->FindFont( fontClient,
+ currentFontDescription,
+ currentFontPointSize );
+ }
+ }
+
+ if( 0u == fontId )
+ {
+ fontId = fontClient.FindDefaultFont( UTF32_A, currentFontPointSize );
+ }
+
+ // Cache the font.
+ if( NULL == defaultFontsPerScript )
+ {
+ defaultFontsPerScript = *( defaultFontPerScriptCacheBuffer + script );
+
+ if( NULL == defaultFontsPerScript )
+ {
+ defaultFontsPerScript = new DefaultFonts();
+ *( defaultFontPerScriptCacheBuffer + script ) = defaultFontsPerScript;
+ }
+ }
+ defaultFontsPerScript->Cache( currentFontDescription, fontId );
+ }
+ } // !isValidFont (3)
+ } // !isValidFont (2)
+ } // !isCommonScript
+ } // !isValidFont (1)