1
2 //----------------------------------------------------------------------------
3 // Anti-Grain Geometry - Version 2.3
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 //
6 // Permission to copy, use, modify, sell and distribute this software
7 // is granted provided this copyright notice appears in all copies.
8 // This software is provided "as is" without express or implied
9 // warranty, and with no claim as to its suitability for any purpose.
10 //
11 //----------------------------------------------------------------------------
12 // Contact: [email protected]
13 // [email protected]
14 // http://www.antigrain.com
15 //----------------------------------------------------------------------------
16 #ifndef AGG_CONV_ADAPTOR_VCGEN_INCLUDED
17 #define AGG_CONV_ADAPTOR_VCGEN_INCLUDED
18 #include "agg_basics.h"
19 namespace pdfium
20 {
21 namespace agg
22 {
23 struct null_markers {
remove_allnull_markers24 void remove_all() {}
add_vertexnull_markers25 void add_vertex(float, float, unsigned) {}
prepare_srcnull_markers26 void prepare_src() {}
rewindnull_markers27 void rewind(unsigned) {}
vertexnull_markers28 unsigned vertex(float*, float*)
29 {
30 return path_cmd_stop;
31 }
32 };
33 template<class VertexSource,
34 class Generator,
35 class Markers = null_markers> class conv_adaptor_vcgen
36 {
37 enum status {
38 initial,
39 accumulate,
40 generate
41 };
42 public:
conv_adaptor_vcgen(VertexSource & source)43 conv_adaptor_vcgen(VertexSource& source) :
44 m_source(&source),
45 m_status(initial)
46 {}
set_source(VertexSource & source)47 void set_source(VertexSource& source)
48 {
49 m_source = &source;
50 }
generator()51 Generator& generator()
52 {
53 return m_generator;
54 }
generator()55 const Generator& generator() const
56 {
57 return m_generator;
58 }
markers()59 Markers& markers()
60 {
61 return m_markers;
62 }
markers()63 const Markers& markers() const
64 {
65 return m_markers;
66 }
rewind(unsigned path_id)67 void rewind(unsigned path_id)
68 {
69 m_source->rewind(path_id);
70 m_status = initial;
71 }
72 unsigned vertex(float* x, float* y);
73 private:
74 conv_adaptor_vcgen(const conv_adaptor_vcgen<VertexSource, Generator, Markers>&);
75 const conv_adaptor_vcgen<VertexSource, Generator, Markers>&
76 operator = (const conv_adaptor_vcgen<VertexSource, Generator, Markers>&);
77 VertexSource* m_source;
78 Generator m_generator;
79 Markers m_markers;
80 status m_status;
81 unsigned m_last_cmd;
82 float m_start_x;
83 float m_start_y;
84 };
85 template<class VertexSource, class Generator, class Markers>
vertex(float * x,float * y)86 unsigned conv_adaptor_vcgen<VertexSource, Generator, Markers>::vertex(float* x, float* y)
87 {
88 unsigned cmd = path_cmd_stop;
89 bool done = false;
90 while(!done) {
91 switch(m_status) {
92 case initial:
93 m_markers.remove_all();
94 m_last_cmd = m_source->vertex(&m_start_x, &m_start_y);
95 m_status = accumulate;
96 case accumulate:
97 if(is_stop(m_last_cmd)) {
98 return path_cmd_stop;
99 }
100 m_generator.remove_all();
101 m_generator.add_vertex(m_start_x, m_start_y, path_cmd_move_to);
102 m_markers.add_vertex(m_start_x, m_start_y, path_cmd_move_to);
103 for(;;) {
104 cmd = m_source->vertex(x, y);
105 if(is_vertex(cmd)) {
106 m_last_cmd = cmd;
107 if(is_move_to(cmd)) {
108 m_start_x = *x;
109 m_start_y = *y;
110 break;
111 }
112 m_generator.add_vertex(*x, *y, cmd);
113 m_markers.add_vertex(*x, *y, path_cmd_line_to);
114 } else {
115 if(is_stop(cmd)) {
116 m_last_cmd = path_cmd_stop;
117 break;
118 }
119 if(is_end_poly(cmd)) {
120 m_generator.add_vertex(*x, *y, cmd);
121 break;
122 }
123 }
124 }
125 m_generator.rewind(0);
126 m_status = generate;
127 case generate:
128 cmd = m_generator.vertex(x, y);
129 if(is_stop(cmd)) {
130 m_status = accumulate;
131 break;
132 }
133 done = true;
134 break;
135 }
136 }
137 return cmd;
138 }
139 }
140 } // namespace pdfium
141 #endif
142