52de839e9270fa6ae7fd3591539fc3ddaaec6e09
[platform/core/uifw/dali-core.git] / dali / public-api / text / font.cpp
1 /*
2  * Copyright (c) 2014 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/public-api/text/font.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/text/character-impl.h>
23 #include <dali/internal/event/text/font-impl.h>
24 #include <dali/internal/event/text/text-impl.h>
25
26 namespace Dali
27 {
28
29 Font::Metrics::Metrics()
30 : mImpl( new Font::Metrics::Impl() )
31 {
32 }
33
34 Font::Metrics::~Metrics()
35 {
36   delete mImpl;
37 }
38
39 Font::Metrics::Metrics( const Font::Metrics& metrics )
40 : mImpl( new Font::Metrics::Impl() )
41 {
42   mImpl->advance = metrics.mImpl->advance;
43   mImpl->bearing = metrics.mImpl->bearing;
44   mImpl->width = metrics.mImpl->width;
45   mImpl->height = metrics.mImpl->height;
46 }
47
48 Font::Metrics& Font::Metrics::operator=( const Font::Metrics& metrics )
49 {
50   if( &metrics != this )
51   {
52     mImpl->advance = metrics.mImpl->advance;
53     mImpl->bearing = metrics.mImpl->bearing;
54     mImpl->width = metrics.mImpl->width;
55     mImpl->height = metrics.mImpl->height;
56   }
57   return *this;
58 }
59
60 float Font::Metrics::GetAdvance() const
61 {
62   return mImpl->advance;
63 }
64
65 float Font::Metrics::GetBearing() const
66 {
67   return mImpl->bearing;
68 }
69
70 float Font::Metrics::GetWidth() const
71 {
72   return mImpl->width;
73 }
74
75 float Font::Metrics::GetHeight() const
76 {
77   return mImpl->height;
78 }
79
80 Font::Metrics::Metrics( const Impl& implementation )
81 : mImpl( new Font::Metrics::Impl() )
82 {
83   mImpl->advance = implementation.advance;
84   mImpl->bearing = implementation.bearing;
85   mImpl->width = implementation.width;
86   mImpl->height = implementation.height;
87 }
88
89 Font::Font()
90 {
91 }
92
93 Font::Font(Internal::Font* internal)
94 : BaseHandle(internal)
95 {
96 }
97
98 Font Font::New( const FontParameters& fontParameters )
99 {
100   Internal::Font* internal = Internal::Font::New(fontParameters.GetFamilyName(), fontParameters.GetStyle(), fontParameters.GetSize() );
101   return Font(internal);
102 }
103
104 Font Font::DownCast( BaseHandle handle )
105 {
106   return Font( dynamic_cast<Dali::Internal::Font*>(handle.GetObjectPtr()) );
107 }
108
109 const std::string Font::GetFamilyForText(const Text& text)
110 {
111   return Internal::Font::GetFamilyForText( Internal::GetTextArray( text ) );
112 }
113
114 Font::~Font()
115 {
116 }
117
118 PixelSize Font::GetLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight)
119 {
120   return Internal::Font::GetLineHeightFromCapsHeight(fontFamily,fontStyle,capsHeight);
121 }
122
123 std::vector<std::string> Font::GetInstalledFonts( FontListMode mode )
124 {
125   std::vector<std::string> fontList;
126   Internal::Font::GetInstalledFonts( mode, fontList );
127
128   // VCC TODO: deprecate this method and add void Font::GetInstalledFonts( FontListMode mode, std::vector<std::string>& fontList )
129   return fontList;
130 }
131
132 float Font::MeasureTextWidth(const Text& text, float textHeightPx) const
133 {
134   return GetImplementation(*this).MeasureTextWidth( Internal::GetTextArray( text ), textHeightPx );
135 }
136
137 float Font::MeasureTextHeight(const Text& text, float textWidthPx) const
138 {
139   return GetImplementation(*this).MeasureTextHeight( Internal::GetTextArray( text ), textWidthPx );
140 }
141
142 Vector3 Font::MeasureText(const Text& text) const
143 {
144   return GetImplementation(*this).MeasureText( Internal::GetTextArray( text ) );
145 }
146
147 bool Font::AllGlyphsSupported(const Text& text) const
148 {
149   return GetImplementation(*this).AllGlyphsSupported( Internal::GetTextArray( text ) );
150 }
151
152 float Font::GetLineHeight() const
153 {
154   return GetImplementation(*this).GetLineHeight() * GetImplementation(*this).GetUnitsToPixels();
155 }
156
157 float Font::GetAscender() const
158 {
159   return GetImplementation(*this).GetAscender() * GetImplementation(*this).GetUnitsToPixels();
160 }
161
162 float Font::GetUnderlineThickness() const
163 {
164   return GetImplementation(*this).GetUnderlineThickness() * GetImplementation(*this).GetUnitsToPixels();
165 }
166
167 float Font::GetUnderlinePosition() const
168 {
169   return GetImplementation(*this).GetUnderlinePosition() * GetImplementation(*this).GetUnitsToPixels();
170 }
171
172 Font::Metrics Font::GetMetrics(const Character& character) const
173 {
174   Font::Metrics::Impl metricsImpl;
175   GetImplementation(*this).GetMetrics(character, metricsImpl);
176   return Font::Metrics( metricsImpl );
177 }
178
179 bool Font::IsDefaultSystemFont() const
180 {
181   return GetImplementation(*this).IsDefaultSystemFont();
182 }
183
184 bool Font::IsDefaultSystemSize() const
185 {
186   return GetImplementation(*this).IsDefaultSystemSize();
187 }
188
189 const std::string& Font::GetName() const
190 {
191   return GetImplementation(*this).GetName();
192 }
193
194 const std::string& Font::GetStyle() const
195 {
196   return GetImplementation(*this).GetStyle();
197 }
198
199 float Font::GetPointSize() const
200 {
201   return GetImplementation(*this).GetPointSize();
202 }
203
204 unsigned int Font::GetPixelSize() const
205 {
206   return GetImplementation(*this).GetPixelSize();
207 }
208
209 unsigned int Font::PointsToPixels( float pointSize )
210 {
211   return Internal::Font::PointsToPixels( pointSize );
212 }
213
214 float Font::PixelsToPoints( unsigned int pixelsSize )
215 {
216   return Internal::Font::PixelsToPoints( pixelsSize );
217 }
218
219 } // namespace Dali