File: transform.rst

package info (click to toggle)
svgpp 1.3.0%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 2,548 kB
  • sloc: cpp: 30,523; makefile: 165; python: 73; xml: 48; sh: 36
file content (114 lines) | stat: -rw-r--r-- 4,800 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
.. _transform-section:

Transform 
=================

Transformation parsing is controlled by *Transform Policy* and *Transform Events Policy*. 
*Transform Policy* configures the adapter 
that simplifies application handling of coordinate system transformations (e.g. adapter
may substitute simple transformation steps translate/scale/rotate/skew with corresponding
transformation matrices, more convenient in some cases). 
*Transform Events Policy* defines how parsed data is passed to the user code.


Transform Events Policy Concept
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*Transform Events Policy* depends on compile-time settings in *Transform Policy*. 
If ``policy::transform::raw`` *Transform Policy* is used that preserves input data at much as possible
then *Transform Events Policy* becomes::

  struct transform_events_policy
  {
    typedef /*...*/ context_type; 

    static void transform_matrix(context_type & context, const boost::array<number_type, 6> & matrix);
    static void transform_translate(context_type & context, number_type tx, number_type ty);
    static void transform_translate(context_type & context, number_type tx);
    static void transform_scale(context_type & context, number_type sx, number_type sy);
    static void transform_scale(context_type & context, number_type scale);
    static void transform_rotate(context_type & context, number_type angle);
    static void transform_rotate(context_type & context, number_type angle, number_type cx, number_type cy);
    static void transform_skew_x(context_type & context, number_type angle);
    static void transform_skew_y(context_type & context, number_type angle);
  };

Depending on *Transform Policy*, some of the methods aren't called by SVG++ and therefore shouldn't be implemented.

.. note::
  Transformation matrix is passed as array of size 6 ``[a b c d e f]``, corresponding to this matrix:

  .. image:: http://www.w3.org/TR/SVG11/images/coords/Matrix.png

:ref:`Named class template parameter <named-params>` for *Transform Events Policy* is ``transform_events_policy``.

Default *Transform Events Policy* (``policy::transform_events::forward_to_method``) forwards calls to its
static methods to methods of ``context`` object::

  struct forward_to_method
  {
    typedef Context context_type; 

    template<class Number>
    static void transform_matrix(context_type & context, const boost::array<Number, 6> & matrix)
    {
      context.transform_matrix(matrix);
    }

    /*...*/
  };

Example of handling transforms with default settings (``src/samples/sample_transform01.cpp``):
  
.. literalinclude:: ../../src/samples/sample_transform01.cpp 

In this example sequential transforms are joined in user code (``src/samples/sample_transform02.cpp``):

.. literalinclude:: ../../src/samples/sample_transform02.cpp 


Transform Policy Concept
^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

  struct transform_policy_concept
  {
    static const bool join_transforms = /* true or false */;
    static const bool no_rotate_about_point = /* true or false */;
    static const bool no_shorthands = /* true or false */; 
    static const bool only_matrix_transform = /* true or false */;
  };

*Transform Policy* is a class with ``bool`` static member constants. If they all are ``false``
(as in ``policy::transform::raw``), then adapter isn't used and the parser passes parsed values as is. 
Setting some members to ``true`` programmer may simplify the application:

  ``join_transforms = true``
    All transformations in SVG attribute are joined in single transformation matrix. 
    Values of other *Transform Policy* members are ignored. 
    *Transform Events Policy* in this case contains only one method::

      struct transform_events_policy
      {
        typedef /*...*/ context_type; 

        static void transform_matrix(context_type & context, const boost::array<number_type, 6> & matrix);
      }

  ``no_rotate_about_point = true``
    **rotate(<rotate-angle> <cx> <cy>)** substituted with **translate(<cx>, <cy>) rotate(<rotate-angle>) translate(-<cx>, -<cy>)**.
    ``transform_rotate`` method of *Transform Events Policy* with parameters ``cx`` and ``cy`` is not used.

  ``no_shorthands = true``
    Calls to ``transform_translate`` and ``transform_scale`` with one number substituted with 
    corresponding calls with two numbers.

  ``only_matrix_transform = true``
    Each transformation step is substituted with corresponding call to ``transform_matrix``. 
    Therefore only this method is used in *Transform Events Policy*.

File ``svgpp/policy/transform.hpp`` contains some predefined *Transform Policies*. 
``policy::transform::matrix``, used by default, sets ``join_transforms = true``.

:ref:`Named class template parameter <named-params>` for *Transform Policy* is ``transform_policy``.