[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / text-renderer-layout-helper.cpp
1 /*
2  * Copyright (c) 2020 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/devel-api/text-abstraction/text-renderer-layout-helper.h>
20
21 // EXTERNAL INCLUDES
22 #include <cmath>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/text-abstraction/font-client.h>
26
27 namespace Dali
28 {
29 namespace TextAbstraction
30 {
31 void TransformToArc(const CircularTextParameters& parameters, double& x, double& y)
32 {
33   double yP = y;
34
35   // Does the italic synthesization for circular layout.
36   if(parameters.synthesizeItalic)
37   {
38     const double xP = -yP * sin(TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE);
39     yP *= cos(TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE);
40
41     x += xP;
42   }
43
44   double angle  = 0.0;
45   double radius = parameters.radius;
46
47   // Transform to a circular layout.
48   if(parameters.isClockwise)
49   {
50     angle = parameters.beginAngle - parameters.invRadius * x;
51     radius -= yP;
52
53     x = radius * cos(angle);
54     y = -radius * sin(angle);
55   }
56   else
57   {
58     angle = parameters.beginAngle + parameters.invRadius * x;
59     radius += yP;
60
61     x = radius * cos(angle);
62     y = radius * sin(-angle);
63   }
64
65   // Transforms to the text area coordinate system.
66   x += parameters.centerX;
67   y += parameters.centerY;
68 }
69
70 } // namespace TextAbstraction
71
72 } // namespace Dali