- // If the cache has not a default font, get one from the font client.
- if( 0u == fontId )
- {
- // Find a default font.
- fontId = fontClient.FindDefaultFont( character, 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->mFonts.PushBack( fontId );
+ }
+ } // !isValidFont (3)
+ } // !isValidFont (2)
+ } // !isCommonScript
+ } // !isValidFont (1)