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 const TextAbstraction::FontDescription& defaultFontDescription,
36 TextAbstraction::PointSize26Dot6 defaultPointSize,
37 CharacterIndex startIndex,
38 Length numberOfCharacters )
40 // Get the handle to the font client.
41 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
43 // Pointer to the font id buffer.
44 FontId* fontIdsBuffer = fontIds.Begin();
46 // Used to temporarily store the style per character.
47 TextAbstraction::FontDescription fontDescription;
48 TextAbstraction::PointSize26Dot6 fontSize;
50 Length familyIndex = 0u;
51 Length weightIndex = 0u;
52 Length widthIndex = 0u;
53 Length slantIndex = 0u;
54 Length sizeIndex = 0u;
56 // Traverse all the characters.
57 const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
58 for( CharacterIndex index = startIndex; index < lastCharacterPlusOne; ++index )
60 bool defaultFont = true;
64 bool familyOverriden = false;
65 bool weightOverriden = false;
66 bool widthOverriden = false;
67 bool slantOverriden = false;
68 bool sizeOverriden = false;
70 // Traverse all the font descriptions.
71 const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
72 for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
73 endIt = fontDescriptions.End();
77 // Check whether the character's font is modified by the current font description.
78 const FontDescriptionRun& fontRun = *it;
79 if( ( index >= fontRun.characterRun.characterIndex ) &&
80 ( index < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
82 if( fontRun.familyDefined )
85 familyOverriden = true;
86 familyIndex = runIndex;
88 if( fontRun.weightDefined )
91 weightOverriden = true;
92 weightIndex = runIndex;
94 if( fontRun.widthDefined )
97 widthOverriden = true;
98 widthIndex = runIndex;
100 if( fontRun.slantDefined )
103 slantOverriden = true;
104 slantIndex = runIndex;
106 if( fontRun.sizeDefined )
109 sizeOverriden = true;
110 sizeIndex = runIndex;
115 // Get the font id if is not the default font.
118 if( familyOverriden )
120 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + familyIndex );
121 fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength ); // TODO Could use move constructor when switch to c++11.
125 fontDescription.family = defaultFontDescription.family;
128 if( weightOverriden )
130 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + weightIndex );
131 fontDescription.weight = fontRun.weight;
135 fontDescription.weight = defaultFontDescription.weight;
140 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + widthIndex );
141 fontDescription.width = fontRun.width;
145 fontDescription.width = defaultFontDescription.width;
150 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + slantIndex );
151 fontDescription.slant = fontRun.slant;
155 fontDescription.slant = defaultFontDescription.slant;
160 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + sizeIndex );
161 fontSize = fontRun.size;
165 fontSize = defaultPointSize;
168 *( fontIdsBuffer + index - startIndex ) = fontClient.GetFontId( fontDescription, fontSize );
173 Script GetScript( Length index,
174 Vector<ScriptRun>::ConstIterator& scriptRunIt,
175 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt )
177 Script script = TextAbstraction::UNKNOWN;
179 while( scriptRunIt != scriptRunEndIt )
181 const ScriptRun& scriptRun = *scriptRunIt;
183 if( index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
187 else if( index >= scriptRun.characterRun.characterIndex )
189 script = scriptRun.script;
191 if( index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
193 // All the characters of the current run have been traversed. Get the next one for the next iteration.
206 } // namespace Toolkit