1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module pango.gravity;
7 
8 import pango.matrix;
9 import pango.script;
10 import pango.c.gravity;
11 import pango.c.script;
12 
13 
14 
15 /**
16 * Gravity:
17 * South: Glyphs stand upright (default)
18 * East: Glyphs are rotated 90 degrees clockwise
19 * North: Glyphs are upside-down
20 * West: Glyphs are rotated 90 degrees counter-clockwise
21 * Auto: Gravity is resolved from the context matrix
22 *
23 * The #PangoGravity type represents the orientation of glyphs in a segment
24 * of text.  This is useful when rendering vertical text layouts.  In
25 * those situations, the layout is rotated using a non-identity PangoMatrix,
26 * and then glyph orientation is controlled using #PangoGravity.
27 * Not every value in this enumeration makes sense for every usage of
28 * #PangoGravity; for example, %PANGO_GRAVITY_AUTO only can be passed to
29 * pango_context_set_base_gravity() and can only be returned by
30 * pango_context_get_base_gravity().
31 *
32 * See also: #PangoGravityHint
33 *
34 * Since: 1.16
35 **/
36 enum Gravity {
37     South   = PangoGravity.PANGO_GRAVITY_SOUTH,
38     East    = PangoGravity.PANGO_GRAVITY_EAST,
39     North   = PangoGravity.PANGO_GRAVITY_NORTH,
40     West    = PangoGravity.PANGO_GRAVITY_WEST,
41     Auto    = PangoGravity.PANGO_GRAVITY_AUTO
42 }
43 
44 /**
45 * GravityHint:
46 * Natural: scripts will take their natural gravity based
47 * on the base gravity and the script.  This is the default.
48 * Strong: always use the base gravity set, regardless of
49 * the script.
50 * Line: for scripts not in their natural direction (eg.
51 * Latin in East gravity), choose per-script gravity such that every script
52 * respects the line progression.  This means, Latin and Arabic will take
53 * opposite gravities and both flow top-to-bottom for example.
54 *
55 * The #PangoGravityHint defines how horizontal scripts should behave in a
56 * vertical context.  That is, English excerpt in a vertical paragraph for
57 * example.
58 *
59 * See #PangoGravity.
60 *
61 * Since: 1.16
62 **/
63 enum GravityHint {
64     Natural = PangoGravityHint.PANGO_GRAVITY_HINT_NATURAL,
65     Strong  = PangoGravityHint.PANGO_GRAVITY_HINT_STRONG,
66     Line    = PangoGravityHint.PANGO_GRAVITY_HINT_LINE
67 }
68 
69 /**
70 * PANGO_GRAVITY_IS_VERTICAL:
71 * @gravity: the #PangoGravity to check
72 *
73 * Whether a #PangoGravity represents vertical writing directions.
74 *
75 * Returns: %TRUE if @gravity is %PANGO_GRAVITY_EAST or %PANGO_GRAVITY_WEST,
76 *          %FALSE otherwise.
77 *
78 * Since: 1.16
79 **/
80 @property bool vertical(Gravity gravity) {
81     return gravity == Gravity.East || gravity == Gravity.West;
82 }
83 
84 /**
85 * PANGO_GRAVITY_IS_IMPROPER:
86 * @gravity: the #PangoGravity to check
87 *
88 * Whether a #PangoGravity represents a gravity that results in reversal of text direction.
89 *
90 * Returns: %TRUE if @gravity is %PANGO_GRAVITY_WEST or %PANGO_GRAVITY_NORTH,
91 *          %FALSE otherwise.
92 *
93 * Since: 1.32
94 **/
95 @property bool improper(Gravity gravity) {
96     return gravity == Gravity.West || gravity == Gravity.North;
97 }
98 
99 
100 pure @property double rotation(Gravity gravity) {
101     return pango_gravity_to_rotation(cast(PangoGravity)gravity);
102 }
103 
104 pure Gravity gravityForMatrix(const(Matrix) matrix) {
105     return cast(Gravity)pango_gravity_get_for_matrix(matrix.nativePtr);
106 }
107 
108 pure Gravity gravityForScript(Script script, Gravity baseGravity, GravityHint hint) {
109     return cast(Gravity)pango_gravity_get_for_script(cast(PangoScript) script,
110                                                      cast(PangoGravity) baseGravity,
111                                                      cast(PangoGravityHint)hint);
112 }
113 
114 pure Gravity gravityForScriptAndWidth(Script script, bool wide,
115                                       Gravity baseGravity, GravityHint hint) {
116     return cast(Gravity)
117         pango_gravity_get_for_script_and_width(cast(PangoScript) script, wide,
118                                                cast(PangoGravity) baseGravity,
119                                                cast(PangoGravityHint)hint);
120 }
121