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 const TextAbstraction::FontDescription& defaultFontDescription,
35 TextAbstraction::PointSize26Dot6 defaultPointSize,
36 CharacterIndex characterIndex,
37 TextAbstraction::FontDescription& fontDescription,
38 TextAbstraction::PointSize26Dot6& fontPointSize,
41 // Initialize with the default font's point size.
42 fontPointSize = defaultPointSize;
44 // Initialize with the style parameters of the default font's style.
45 fontDescription = defaultFontDescription;
47 // Initialize as a default font.
52 Length familyIndex = 0u;
53 Length weightIndex = 0u;
54 Length widthIndex = 0u;
55 Length slantIndex = 0u;
56 Length sizeIndex = 0u;
58 bool familyOverriden = false;
59 bool weightOverriden = false;
60 bool widthOverriden = false;
61 bool slantOverriden = false;
62 bool sizeOverriden = false;
64 // Traverse all the font descriptions.
65 const FontDescriptionRun* const fontDescriptionsBuffer = fontDescriptions.Begin();
66 for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptionsBuffer,
67 endIt = fontDescriptions.End();
71 // Check whether the character's font is modified by the current font description.
72 const FontDescriptionRun& fontRun = *it;
73 if( ( characterIndex >= fontRun.characterRun.characterIndex ) &&
74 ( characterIndex < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
76 if( fontRun.familyDefined )
78 isDefaultFont = false;
79 familyOverriden = true;
80 familyIndex = runIndex;
82 if( fontRun.weightDefined )
84 isDefaultFont = false;
85 weightOverriden = true;
86 weightIndex = runIndex;
88 if( fontRun.widthDefined )
90 isDefaultFont = false;
91 widthOverriden = true;
92 widthIndex = runIndex;
94 if( fontRun.slantDefined )
96 isDefaultFont = false;
97 slantOverriden = true;
98 slantIndex = runIndex;
100 if( fontRun.sizeDefined )
102 isDefaultFont = false;
103 sizeOverriden = true;
104 sizeIndex = runIndex;
109 // Get the font's description if is not the default font.
112 if( familyOverriden )
114 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + familyIndex );
115 fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength );
118 if( weightOverriden )
120 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + weightIndex );
121 fontDescription.weight = fontRun.weight;
126 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + widthIndex );
127 fontDescription.width = fontRun.width;
132 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + slantIndex );
133 fontDescription.slant = fontRun.slant;
138 const FontDescriptionRun& fontRun = *( fontDescriptionsBuffer + sizeIndex );
139 fontPointSize = fontRun.size;
144 Script GetScript( Length index,
145 Vector<ScriptRun>::ConstIterator& scriptRunIt,
146 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt )
148 Script script = TextAbstraction::UNKNOWN;
150 while( scriptRunIt != scriptRunEndIt )
152 const ScriptRun& scriptRun = *scriptRunIt;
154 if( index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
158 else if( index >= scriptRun.characterRun.characterIndex )
160 script = scriptRun.script;
162 if( index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
164 // All the characters of the current run have been traversed. Get the next one for the next iteration.
177 } // namespace Toolkit