{
void MergeFontDescriptions( const Vector<FontDescriptionRun>& fontDescriptions,
- Vector<FontId>& fontIds,
const TextAbstraction::FontDescription& defaultFontDescription,
TextAbstraction::PointSize26Dot6 defaultPointSize,
- CharacterIndex startIndex,
- Length numberOfCharacters )
+ CharacterIndex characterIndex,
+ TextAbstraction::FontDescription& fontDescription,
+ TextAbstraction::PointSize26Dot6& fontPointSize,
+ bool& isDefaultFont )
{
- // Get the handle to the font client.
- TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+ // Initialize with the default font's point size.
+ fontPointSize = defaultPointSize;
- // Pointer to the font id buffer.
- FontId* fontIdsBuffer = fontIds.Begin();
+ // Initialize with the style parameters of the default font's style.
+ fontDescription = defaultFontDescription;
- // Used to temporarily store the style per character.
- TextAbstraction::FontDescription fontDescription;
- TextAbstraction::PointSize26Dot6 fontSize;
+ // Initialize as a default font.
+ isDefaultFont = true;
+
+ Length runIndex = 0u;
Length familyIndex = 0u;
Length weightIndex = 0u;
Length slantIndex = 0u;
Length sizeIndex = 0u;
- // Traverse all the characters.
- const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
- for( CharacterIndex index = startIndex; index < lastCharacterPlusOne; ++index )
+ bool familyOverriden = false;
+ bool weightOverriden = false;
+ bool widthOverriden = false;
+ bool slantOverriden = false;
+ bool sizeOverriden = false;
+
+ // Traverse all the font descriptions.
+ const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
+ for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
+ endIt = fontDescriptions.End();
+ it != endIt;
+ ++it, ++runIndex )
{
- bool defaultFont = true;
-
- Length runIndex = 0u;
-
- bool familyOverriden = false;
- bool weightOverriden = false;
- bool widthOverriden = false;
- bool slantOverriden = false;
- bool sizeOverriden = false;
-
- // Traverse all the font descriptions.
- const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
- for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
- endIt = fontDescriptions.End();
- it != endIt;
- ++it, ++runIndex )
+ // Check whether the character's font is modified by the current font description.
+ const FontDescriptionRun& fontRun = *it;
+ if( ( characterIndex >= fontRun.characterRun.characterIndex ) &&
+ ( characterIndex < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
{
- // Check whether the character's font is modified by the current font description.
- const FontDescriptionRun& fontRun = *it;
- if( ( index >= fontRun.characterRun.characterIndex ) &&
- ( index < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
+ if( fontRun.familyDefined )
{
- if( fontRun.familyDefined )
- {
- defaultFont = false;
- familyOverriden = true;
- familyIndex = runIndex;
- }
- if( fontRun.weightDefined )
- {
- defaultFont = false;
- weightOverriden = true;
- weightIndex = runIndex;
- }
- if( fontRun.widthDefined )
- {
- defaultFont = false;
- widthOverriden = true;
- widthIndex = runIndex;
- }
- if( fontRun.slantDefined )
- {
- defaultFont = false;
- slantOverriden = true;
- slantIndex = runIndex;
- }
- if( fontRun.sizeDefined )
- {
- defaultFont = false;
- sizeOverriden = true;
- sizeIndex = runIndex;
- }
+ isDefaultFont = false;
+ familyOverriden = true;
+ familyIndex = runIndex;
}
- }
-
- // Get the font id if is not the default font.
- if( !defaultFont )
- {
- if( familyOverriden )
+ if( fontRun.weightDefined )
{
- const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + familyIndex );
- fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength ); // TODO Could use move constructor when switch to c++11.
+ isDefaultFont = false;
+ weightOverriden = true;
+ weightIndex = runIndex;
}
- else
+ if( fontRun.widthDefined )
{
- fontDescription.family = defaultFontDescription.family;
+ isDefaultFont = false;
+ widthOverriden = true;
+ widthIndex = runIndex;
}
-
- if( weightOverriden )
+ if( fontRun.slantDefined )
{
- const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + weightIndex );
- fontDescription.weight = fontRun.weight;
+ isDefaultFont = false;
+ slantOverriden = true;
+ slantIndex = runIndex;
}
- else
+ if( fontRun.sizeDefined )
{
- fontDescription.weight = defaultFontDescription.weight;
+ isDefaultFont = false;
+ sizeOverriden = true;
+ sizeIndex = runIndex;
}
+ }
+ }
- if( widthOverriden )
- {
- const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + widthIndex );
- fontDescription.width = fontRun.width;
- }
- else
- {
- fontDescription.width = defaultFontDescription.width;
- }
+ // Get the font's description if is not the default font.
+ if( !isDefaultFont )
+ {
+ if( familyOverriden )
+ {
+ const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + familyIndex );
+ fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength );
+ }
- if( slantOverriden )
- {
- const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + slantIndex );
- fontDescription.slant = fontRun.slant;
- }
- else
- {
- fontDescription.slant = defaultFontDescription.slant;
- }
+ if( weightOverriden )
+ {
+ const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + weightIndex );
+ fontDescription.weight = fontRun.weight;
+ }
- if( sizeOverriden )
- {
- const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + sizeIndex );
- fontSize = fontRun.size;
- }
- else
- {
- fontSize = defaultPointSize;
- }
+ if( widthOverriden )
+ {
+ const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + widthIndex );
+ fontDescription.width = fontRun.width;
+ }
- *( fontIdsBuffer + index - startIndex ) = fontClient.GetFontId( fontDescription, fontSize );
+ if( slantOverriden )
+ {
+ const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + slantIndex );
+ fontDescription.slant = fontRun.slant;
+ }
+
+ if( sizeOverriden )
+ {
+ const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + sizeIndex );
+ fontPointSize = fontRun.size;
}
}
}