Merge "Add descriptions and example codes" into 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 <iostream>
23 #include <dali/devel-api/text-abstraction/font-client.h>
24 #include <dali/devel-api/text-abstraction/script.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Text
33 {
34
35 std::ostream& operator<< (std::ostream& o, const Vector<Character>& text)
36 {
37   o << std::hex;
38
39   for( unsigned int i=0; i<text.Count(); ++i )
40   {
41     o << text[i];
42     if( i+1 < text.Count() )
43     {
44       o << " ";
45     }
46   }
47
48   return o << std::dec;
49 }
50
51 std::ostream& operator<< (std::ostream& o, const Vector<ScriptRun>& scriptRun)
52 {
53   for( unsigned int i=0; i<scriptRun.Count(); ++i )
54   {
55     // e.g. Print "0->9: LATIN" for a ten character run staring from beginning of the model
56     o << scriptRun[i].characterRun.characterIndex << "->" << (scriptRun[i].characterRun.characterIndex + scriptRun[i].characterRun.numberOfCharacters ) << ": ";
57     o << TextAbstraction::ScriptName[scriptRun[i].script];
58
59     if( i+1 < scriptRun.Count() )
60     {
61       o << ", ";
62     }
63   }
64
65   return o << std::dec;
66 }
67
68 std::ostream& operator<< (std::ostream& o, const Vector<FontRun>& fontRun)
69 {
70   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
71
72   for( unsigned int i=0; i<fontRun.Count(); ++i )
73   {
74     // e.g. Print "0->9: ID:1 TizenSansKorean style:Regular size:10.0" for a ten character run staring from beginning of the model
75     o << fontRun[i].characterRun.characterIndex << "->" << (fontRun[i].characterRun.characterIndex + fontRun[i].characterRun.numberOfCharacters ) << ": ";
76
77     FontId id = fontRun[i].fontId;
78     TextAbstraction::FontDescription fontDescription;
79     fontClient.GetDescription( id, fontDescription );
80     o << "ID:" << id << ", " << fontDescription.family << " width: " << fontDescription.width << " weight: " << fontDescription.weight << " slant: " << fontDescription.slant <<  " size:" << (fontClient.GetPointSize(id) / 64);
81
82     if( i+1 < fontRun.Count() )
83     {
84       o << ", ";
85     }
86   }
87
88   return o << std::dec;
89 }
90
91 std::ostream& operator<< (std::ostream& o, const Vector<LineRun>& lineRuns)
92 {
93   for( unsigned int i=0; i<lineRuns.Count(); ++i )
94   {
95     // e.g. Print "Line 0 Glyphs: 0->9 Characters: 0->9 (10)" for a ten character run staring from beginning of the model
96     o << "Line " << i << " Glyphs: " << lineRuns[i].glyphRun.glyphIndex << "->" << (lineRuns[i].glyphRun.glyphIndex + lineRuns[i].glyphRun.numberOfGlyphs );
97     o << " Characters: " << lineRuns[i].characterRun.characterIndex << "->" << (lineRuns[i].characterRun.characterIndex + lineRuns[i].characterRun.numberOfCharacters );
98     o << " Width: " << lineRuns[i].width;
99     o << " Ascender: " << lineRuns[i].ascender;
100     o << " Descender: " << lineRuns[i].descender;
101
102     if( i+1 < lineRuns.Count() )
103     {
104       o << ", ";
105     }
106   }
107
108   return o << std::dec;
109 }
110
111 } // namespace Text
112
113 } // namespace Toolkit
114
115 } // namespace Dali