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