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>
30 void MergeFontDescriptions(const Vector<FontDescriptionRun>& fontDescriptions,
31 const TextAbstraction::FontDescription& defaultFontDescription,
32 TextAbstraction::PointSize26Dot6 defaultPointSize,
33 CharacterIndex characterIndex,
34 TextAbstraction::FontDescription& fontDescription,
35 TextAbstraction::PointSize26Dot6& fontPointSize,
38 // Initialize with the default font's point size.
39 fontPointSize = defaultPointSize;
41 // Initialize with the style parameters of the default font's style.
42 fontDescription = defaultFontDescription;
44 // Initialize as a default font.
49 Length familyIndex = 0u;
50 Length weightIndex = 0u;
51 Length widthIndex = 0u;
52 Length slantIndex = 0u;
53 Length sizeIndex = 0u;
55 bool familyOverriden = false;
56 bool weightOverriden = false;
57 bool widthOverriden = false;
58 bool slantOverriden = false;
59 bool sizeOverriden = false;
61 // Traverse all the font descriptions.
62 const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
63 for(Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
64 endIt = fontDescriptions.End();
68 // Check whether the character's font is modified by the current font description.
69 const FontDescriptionRun& fontRun = *it;
70 if((characterIndex >= fontRun.characterRun.characterIndex) &&
71 (characterIndex < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters))
73 if(fontRun.familyDefined)
75 isDefaultFont = false;
76 familyOverriden = true;
77 familyIndex = runIndex;
79 if(fontRun.weightDefined)
81 isDefaultFont = false;
82 weightOverriden = true;
83 weightIndex = runIndex;
85 if(fontRun.widthDefined)
87 isDefaultFont = false;
88 widthOverriden = true;
89 widthIndex = runIndex;
91 if(fontRun.slantDefined)
93 isDefaultFont = false;
94 slantOverriden = true;
95 slantIndex = runIndex;
97 if(fontRun.sizeDefined)
99 isDefaultFont = false;
100 sizeOverriden = true;
101 sizeIndex = runIndex;
106 // Get the font's description if is not the default font.
111 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + familyIndex);
112 fontDescription.family = std::string(fontRun.familyName, fontRun.familyLength);
117 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + weightIndex);
118 fontDescription.weight = fontRun.weight;
123 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + widthIndex);
124 fontDescription.width = fontRun.width;
129 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + slantIndex);
130 fontDescription.slant = fontRun.slant;
135 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + sizeIndex);
136 fontPointSize = fontRun.size;
141 Script GetScript(Length index,
142 Vector<ScriptRun>::ConstIterator& scriptRunIt,
143 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt)
145 Script script = TextAbstraction::UNKNOWN;
147 while(scriptRunIt != scriptRunEndIt)
149 const ScriptRun& scriptRun = *scriptRunIt;
151 if(index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
155 else if(index >= scriptRun.characterRun.characterIndex)
157 script = scriptRun.script;
159 if(index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
161 // All the characters of the current run have been traversed. Get the next one for the next iteration.
174 } // namespace Toolkit