[dali_1.0.31] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / event / text / font-layout.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/internal/event/text/font-layout.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/glyph-set.h>
23
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace
32 {
33 const float INCH_TO_POINTS( 72.f );
34 const float POINT_TO_INCHES( 1.f / INCH_TO_POINTS );
35 }
36
37 FontLayout::FontLayout()
38   :mUnitsPerEM(0.0f)
39 {
40 }
41
42 FontLayout::FontLayout( float unitsPerEM, Vector2 dpi )
43   :mUnitsPerEM(unitsPerEM),
44    mDpi(dpi)
45 {
46 }
47
48 void FontLayout::SetMetrics( const Dali::Integration::GlobalMetrics &metrics )
49 {
50   mMetrics = metrics;
51   mUnitsPerEM = 1.0f / mMetrics.unitsPerEM;
52 }
53
54 float FontLayout::GetUnitsToPixels( const float pointSize ) const
55 {
56   const float meanDpi = (mDpi.height + mDpi.width) * 0.5f;
57   return ((meanDpi * POINT_TO_INCHES) * pointSize) * mUnitsPerEM;
58 }
59
60 const Dali::Integration::GlobalMetrics& FontLayout::GetGlobalMetrics() const
61 {
62   return mMetrics;
63 }
64
65 float FontLayout::GetLineHeight() const
66 {
67   return mMetrics.lineHeight;
68 }
69
70 float FontLayout::GetAscender() const
71 {
72   return mMetrics.ascender;
73 }
74
75 float FontLayout::GetUnderlinePosition() const
76 {
77   return mMetrics.underlinePosition;
78 }
79
80 float FontLayout::GetUnderlineThickness() const
81 {
82   return mMetrics.underlineThickness;
83 }
84
85 float FontLayout::GetUnitsPerEM() const
86 {
87   return mUnitsPerEM;
88 }
89
90 float FontLayout::GetMaxWidth() const
91 {
92   return mMetrics.maxWidth;
93 }
94
95 float FontLayout::GetMaxHeight() const
96 {
97   return mMetrics.maxHeight;
98 }
99
100 float FontLayout::GetPadAdjustX() const
101 {
102   return mMetrics.padAdjustX;
103 }
104
105 float FontLayout::GetPadAdjustY() const
106 {
107   return mMetrics.padAdjustY;
108 }
109
110 Vector2 FontLayout::GetDpi() const
111 {
112   return mDpi;
113 }
114
115 } // namespace Internal
116
117 } // namespace Dali