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 // Traverse all the characters.
47 for( CharacterIndex index = startIndex; index < numberOfCharacters; ++index )
49 // The default font description and font point size.
50 TextAbstraction::FontDescription fontDescription = defaultFontDescription;
51 TextAbstraction::PointSize26Dot6 fontSize = defaultPointSize;
52 bool defaultFont = true;
54 // Traverse all the font descriptions.
55 for( Vector<FontDescriptionRun>::ConstIterator it = fontDescriptions.Begin(),
56 endIt = fontDescriptions.End();
60 // Check whether the character's font is modified by the current font description.
61 const FontDescriptionRun& fontRun = *it;
62 if( ( index >= fontRun.characterRun.characterIndex ) &&
63 ( index < fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) )
65 if( fontRun.familyDefined )
67 fontDescription.family = std::string( fontRun.familyName, fontRun.familyLength );
70 if( fontRun.weightDefined )
72 fontDescription.weight = fontRun.weight;
75 if( fontRun.widthDefined )
77 fontDescription.width = fontRun.width;
80 if( fontRun.slantDefined )
82 fontDescription.slant = fontRun.slant;
85 if( fontRun.sizeDefined )
87 fontSize = fontRun.size;
93 // Get the font id if is not the default font.
96 *( fontIdsBuffer + index - startIndex ) = fontClient.GetFontId( fontDescription, fontSize );
101 Script GetScript( Length index,
102 Vector<ScriptRun>::ConstIterator& scriptRunIt,
103 const Vector<ScriptRun>::ConstIterator& scriptRunEndIt )
105 Script script = TextAbstraction::UNKNOWN;
107 while( scriptRunIt != scriptRunEndIt )
109 const ScriptRun& scriptRun = *scriptRunIt;
111 if( index >= scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
115 else if( index >= scriptRun.characterRun.characterIndex )
117 script = scriptRun.script;
119 if( index + 1u == scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters )
121 // All the characters of the current run have been traversed. Get the next one for the next iteration.
134 } // namespace Toolkit