2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/multi-language-helper-functions.h>
22 #include <dali/devel-api/text-abstraction/font-client.h>
33 void MergeFontDescriptions( const Vector<FontDescriptionRun>& fontDescriptions,
34 Vector<FontId>& fontIds,
35 Vector<bool>& isDefaultFont,
36 const TextAbstraction::FontDescription& defaultFontDescription,
37 TextAbstraction::PointSize26Dot6 defaultPointSize,
38 CharacterIndex startIndex,
39 Length numberOfCharacters )
41 // Get the handle to the font client.
42 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
44 // Pointer to the font id buffer.
45 FontId* fontIdsBuffer = fontIds.Begin();
47 // Pointer to the 'is default' font buffer.
48 bool* isDefaultFontBuffer = isDefaultFont.Begin();
50 // Used to temporarily store the style per character.
51 TextAbstraction::FontDescription fontDescription;
52 TextAbstraction::PointSize26Dot6 fontSize;
54 Length familyIndex = 0u;
55 Length weightIndex = 0u;
56 Length widthIndex = 0u;
57 Length slantIndex = 0u;
58 Length sizeIndex = 0u;
60 // Traverse all the characters.
61 const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
62 for( CharacterIndex index = startIndex; index < lastCharacterPlusOne; ++index )
64 bool& defaultFont = *(isDefaultFontBuffer + index - startIndex );
68 bool familyOverriden = false;
69 bool weightOverriden = false;
70 bool widthOverriden = false;
71 bool slantOverriden = false;
72 bool sizeOverriden = false;
74 // Traverse all the font descriptions.
75 const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
76 for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
77 endIt = fontDescriptions.End();
81 // Check whether the character's font is modified by the current font description.
82 const FontDescriptionRun& fontRun = *it;
83 if( ( index >= fontRun.characterRun.characterIndex ) &&
84 ( index < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
86 if( fontRun.familyDefined )
89 familyOverriden = true;
90 familyIndex = runIndex;
92 if( fontRun.weightDefined )
95 weightOverriden = true;
96 weightIndex = runIndex;
98 if( fontRun.widthDefined )
101 widthOverriden = true;
102 widthIndex = runIndex;
104 if( fontRun.slantDefined )
107 slantOverriden = true;
108 slantIndex = runIndex;
110 if( fontRun.sizeDefined )
113 sizeOverriden = true;
114 sizeIndex = runIndex;
119 // Get the font id if is not the default font.
122 if( familyOverriden )
124 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + familyIndex );
125 fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength ); // TODO Could use move constructor when switch to c++11.
129 fontDescription.family = defaultFontDescription.family;
132 if( weightOverriden )
134 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + weightIndex );
135 fontDescription.weight = fontRun.weight;
139 fontDescription.weight = defaultFontDescription.weight;
144 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + widthIndex );
145 fontDescription.width = fontRun.width;
149 fontDescription.width = defaultFontDescription.width;
154 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + slantIndex );
155 fontDescription.slant = fontRun.slant;
159 fontDescription.slant = defaultFontDescription.slant;
164 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + sizeIndex );
165 fontSize = fontRun.size;
169 fontSize = defaultPointSize;
172 *( fontIdsBuffer + index - startIndex ) = fontClient.GetFontId( fontDescription, fontSize );
177 Script GetScript( Length index,
178 Vector<ScriptRun>::ConstIterator& scriptRunIt,
179 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt )
181 Script script = TextAbstraction::UNKNOWN;
183 while( scriptRunIt != scriptRunEndIt )
185 const ScriptRun& scriptRun = *scriptRunIt;
187 if( index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
191 else if( index >= scriptRun.characterRun.characterIndex )
193 script = scriptRun.script;
195 if( index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
197 // All the characters of the current run have been traversed. Get the next one for the next iteration.
210 } // namespace Toolkit