Resolve incorrect position for Ellipsis when mixed LTR & RTL languages and set layout...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / line-helper-functions.cpp
1 /*
2  * Copyright (c) 2021 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 // FILE HEADER
19 #include <dali-toolkit/internal/text/line-helper-functions.h>
20
21 namespace Dali
22 {
23 namespace Toolkit
24 {
25 namespace Text
26 {
27 float GetPreOffsetVerticalLineAlignment(const LineRun& line, const DevelText::VerticalLineAlignment::Type& verLineAlign)
28 {
29   // Calculate vertical line alignment
30   float offset = 0.0f;
31
32   switch(verLineAlign)
33   {
34     case DevelText::VerticalLineAlignment::TOP:
35     {
36       break;
37     }
38     case DevelText::VerticalLineAlignment::MIDDLE:
39     {
40       offset = line.lineSpacing * 0.5f;
41       break;
42     }
43     case DevelText::VerticalLineAlignment::BOTTOM:
44     {
45       offset = line.lineSpacing;
46       break;
47     }
48   }
49
50   // Apply TOP case when the lineSpacing is less than zero.
51   offset = line.lineSpacing < 0.0f ? 0.0f : offset;
52
53   return offset;
54 }
55
56 float GetPostOffsetVerticalLineAlignment(const LineRun& line, const DevelText::VerticalLineAlignment::Type& verLineAlign)
57 {
58   // Calculate vertical line alignment
59   float offset = 0.0f;
60
61   switch(verLineAlign)
62   {
63     case DevelText::VerticalLineAlignment::TOP:
64     {
65       offset = line.lineSpacing;
66       break;
67     }
68     case DevelText::VerticalLineAlignment::MIDDLE:
69     {
70       offset = line.lineSpacing * 0.5f;
71       break;
72     }
73     case DevelText::VerticalLineAlignment::BOTTOM:
74     {
75       break;
76     }
77   }
78
79   // Apply TOP case when the lineSpacing is less than zero.
80   offset = line.lineSpacing < 0.0f ? line.lineSpacing : offset;
81
82   return offset;
83 }
84 } // namespace Text
85
86 } // namespace Toolkit
87
88 } // namespace Dali