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,
34 CharacterIndex characterIndex,
35 TextAbstraction::FontDescription& fontDescription,
36 TextAbstraction::PointSize26Dot6& fontPointSize,
39 // Initialize with the default font's point size.
40 fontPointSize = defaultPointSize;
42 // Initialize with the style parameters of the default font's style.
43 fontDescription = defaultFontDescription;
45 // Initialize as a default font.
50 Length familyIndex = 0u;
51 Length weightIndex = 0u;
52 Length widthIndex = 0u;
53 Length slantIndex = 0u;
54 Length sizeIndex = 0u;
56 bool familyOverriden = false;
57 bool weightOverriden = false;
58 bool widthOverriden = false;
59 bool slantOverriden = false;
60 bool sizeOverriden = false;
62 // Traverse all the font descriptions.
63 const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
64 for(Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
65 endIt = fontDescriptions.End();
69 // Check whether the character's font is modified by the current font description.
70 const FontDescriptionRun& fontRun = *it;
71 if((characterIndex >= fontRun.characterRun.characterIndex) &&
72 (characterIndex < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters))
74 if(fontRun.familyDefined)
76 isDefaultFont = false;
77 familyOverriden = true;
78 familyIndex = runIndex;
80 if(fontRun.weightDefined)
82 isDefaultFont = false;
83 weightOverriden = true;
84 weightIndex = runIndex;
86 if(fontRun.widthDefined)
88 isDefaultFont = false;
89 widthOverriden = true;
90 widthIndex = runIndex;
92 if(fontRun.slantDefined)
94 isDefaultFont = false;
95 slantOverriden = true;
96 slantIndex = runIndex;
98 if(fontRun.sizeDefined)
100 isDefaultFont = false;
101 sizeOverriden = true;
102 sizeIndex = runIndex;
107 // Get the font's description if is not the default font.
112 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + familyIndex);
113 fontDescription.family = std::string(fontRun.familyName, fontRun.familyLength);
118 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + weightIndex);
119 fontDescription.weight = fontRun.weight;
124 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + widthIndex);
125 fontDescription.width = fontRun.width;
130 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + slantIndex);
131 fontDescription.slant = fontRun.slant;
136 const FontDescriptionRun& fontRun = *(fontDescriptionsBuffer + sizeIndex);
137 fontPointSize = static_cast<PointSize26Dot6>(fontRun.size * fontSizeScale);
142 Script GetScript(Length index,
143 Vector<ScriptRun>::ConstIterator& scriptRunIt,
144 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt)
146 Script script = TextAbstraction::UNKNOWN;
148 while(scriptRunIt != scriptRunEndIt)
150 const ScriptRun& scriptRun = *scriptRunIt;
152 if(index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
156 else if(index >= scriptRun.characterRun.characterIndex)
158 script = scriptRun.script;
160 if(index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters)
162 // All the characters of the current run have been traversed. Get the next one for the next iteration.
175 } // namespace Toolkit