[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-io.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/text-io.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/font-client.h>
23 #include <dali/devel-api/text-abstraction/script.h>
24 #include <iostream>
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Text
31 {
32 std::ostream& operator<<(std::ostream& o, const Vector<Character>& text)
33 {
34   o << std::hex;
35
36   for(unsigned int i = 0; i < text.Count(); ++i)
37   {
38     o << text[i];
39     if(i + 1 < text.Count())
40     {
41       o << " ";
42     }
43   }
44
45   return o << std::dec;
46 }
47
48 std::ostream& operator<<(std::ostream& o, const Vector<ScriptRun>& scriptRun)
49 {
50   for(unsigned int i = 0; i < scriptRun.Count(); ++i)
51   {
52     // e.g. Print "0->9: LATIN" for a ten character run staring from beginning of the model
53     o << scriptRun[i].characterRun.characterIndex << "->" << (scriptRun[i].characterRun.characterIndex + scriptRun[i].characterRun.numberOfCharacters) << ": ";
54     o << TextAbstraction::ScriptName[scriptRun[i].script];
55
56     if(i + 1 < scriptRun.Count())
57     {
58       o << ", ";
59     }
60   }
61
62   return o << std::dec;
63 }
64
65 std::ostream& operator<<(std::ostream& o, const Vector<FontRun>& fontRun)
66 {
67   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
68
69   for(unsigned int i = 0; i < fontRun.Count(); ++i)
70   {
71     // e.g. Print "0->9: ID:1 TizenSansKorean style:Regular size:10.0" for a ten character run staring from beginning of the model
72     o << fontRun[i].characterRun.characterIndex << "->" << (fontRun[i].characterRun.characterIndex + fontRun[i].characterRun.numberOfCharacters) << ": ";
73
74     FontId                           id = fontRun[i].fontId;
75     TextAbstraction::FontDescription fontDescription;
76     fontClient.GetDescription(id, fontDescription);
77     o << "ID:" << id << ", " << fontDescription.family << " width: " << fontDescription.width << " weight: " << fontDescription.weight << " slant: " << fontDescription.slant << " size:" << (fontClient.GetPointSize(id) / 64);
78
79     if(i + 1 < fontRun.Count())
80     {
81       o << ", ";
82     }
83   }
84
85   return o << std::dec;
86 }
87
88 std::ostream& operator<<(std::ostream& o, const Vector<LineRun>& lineRuns)
89 {
90   for(unsigned int i = 0; i < lineRuns.Count(); ++i)
91   {
92     // e.g. Print "Line 0 Glyphs: 0->9 Characters: 0->9 (10)" for a ten character run staring from beginning of the model
93     o << "Line " << i << " Glyphs: " << lineRuns[i].glyphRun.glyphIndex << "->" << (lineRuns[i].glyphRun.glyphIndex + lineRuns[i].glyphRun.numberOfGlyphs);
94     o << " Characters: " << lineRuns[i].characterRun.characterIndex << "->" << (lineRuns[i].characterRun.characterIndex + lineRuns[i].characterRun.numberOfCharacters);
95     o << " Width: " << lineRuns[i].width;
96     o << " Ascender: " << lineRuns[i].ascender;
97     o << " Descender: " << lineRuns[i].descender;
98
99     if(i + 1 < lineRuns.Count())
100     {
101       o << ", ";
102     }
103   }
104
105   return o << std::dec;
106 }
107
108 } // namespace Text
109
110 } // namespace Toolkit
111
112 } // namespace Dali