merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_vcgen_markers_term.cpp
blobda503ce83bc1e8a65bc23a6dfd068d2c1bd5ef64
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // Terminal markers generator (arrowhead/arrowtail)
18 //----------------------------------------------------------------------------
20 #include "agg_vcgen_markers_term.h"
22 namespace agg
25 //------------------------------------------------------------------------
26 void vcgen_markers_term::remove_all()
28 m_markers.remove_all();
32 //------------------------------------------------------------------------
33 void vcgen_markers_term::add_vertex(double x, double y, unsigned cmd)
35 if(is_move_to(cmd))
37 if(m_markers.size() & 1)
39 // Initial state, the first coordinate was added.
40 // If two of more calls of start_vertex() occures
41 // we just modify the last one.
42 m_markers.modify_last(coord_type(x, y));
44 else
46 m_markers.add(coord_type(x, y));
49 else
51 if(is_vertex(cmd))
53 if(m_markers.size() & 1)
55 // Initial state, the first coordinate was added.
56 // Add three more points, 0,1,1,0
57 m_markers.add(coord_type(x, y));
58 m_markers.add(m_markers[m_markers.size() - 1]);
59 m_markers.add(m_markers[m_markers.size() - 3]);
61 else
63 if(m_markers.size())
65 // Replace two last points: 0,1,1,0 -> 0,1,2,1
66 m_markers[m_markers.size() - 1] = m_markers[m_markers.size() - 2];
67 m_markers[m_markers.size() - 2] = coord_type(x, y);
75 //------------------------------------------------------------------------
76 void vcgen_markers_term::rewind(unsigned id)
78 m_curr_id = id * 2;
79 m_curr_idx = m_curr_id;
83 //------------------------------------------------------------------------
84 unsigned vcgen_markers_term::vertex(double* x, double* y)
86 if(m_curr_id > 2 || m_curr_idx >= m_markers.size())
88 return path_cmd_stop;
90 const coord_type& c = m_markers[m_curr_idx];
91 *x = c.x;
92 *y = c.y;
93 if(m_curr_idx & 1)
95 m_curr_idx += 3;
96 return path_cmd_line_to;
98 ++m_curr_idx;
99 return path_cmd_move_to;