1 
2 //----------------------------------------------------------------------------
3 // XYQ: 2006-01-22 Copied from AGG project.
4 // TODO: This file uses intensive floating point operations, so it's NOT suitable
5 // for platforms like Symbian OS. We need to change to FIX format.
6 //----------------------------------------------------------------------------
7 //----------------------------------------------------------------------------
8 // Anti-Grain Geometry - Version 2.3
9 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
10 //
11 // Permission to copy, use, modify, sell and distribute this software
12 // is granted provided this copyright notice appears in all copies.
13 // This software is provided "as is" without express or implied
14 // warranty, and with no claim as to its suitability for any purpose.
15 //
16 //----------------------------------------------------------------------------
17 // Contact: mcseem@antigrain.com
18 //          mcseemagg@yahoo.com
19 //          http://www.antigrain.com
20 //----------------------------------------------------------------------------
21 //
22 // Class path_storage
23 //
24 //----------------------------------------------------------------------------
25 
26 #include "agg_path_storage.h"
27 
28 #include "agg_math.h"
29 #include "core/fxcrt/fx_memory.h"
30 
31 namespace agg
32 {
~path_storage()33 path_storage::~path_storage()
34 {
35     if(m_total_blocks) {
36         float** coord_blk = m_coord_blocks + m_total_blocks - 1;
37         while(m_total_blocks--) {
38             FX_Free(*coord_blk);
39             --coord_blk;
40         }
41         FX_Free(m_coord_blocks);
42     }
43 }
path_storage()44 path_storage::path_storage() :
45     m_total_vertices(0),
46     m_total_blocks(0),
47     m_max_blocks(0),
48     m_coord_blocks(0),
49     m_cmd_blocks(0),
50     m_iterator(0)
51 {
52 }
allocate_block(unsigned nb)53 void path_storage::allocate_block(unsigned nb)
54 {
55     if(nb >= m_max_blocks) {
56         float** new_coords =
57             FX_Alloc2D(float*, m_max_blocks + block_pool, 2);
58         unsigned char** new_cmds =
59             (unsigned char**)(new_coords + m_max_blocks + block_pool);
60         if(m_coord_blocks) {
61           memcpy(new_coords, m_coord_blocks, m_max_blocks * sizeof(float*));
62           memcpy(new_cmds, m_cmd_blocks, m_max_blocks * sizeof(unsigned char*));
63           FX_Free(m_coord_blocks);
64         }
65         m_coord_blocks = new_coords;
66         m_cmd_blocks = new_cmds;
67         m_max_blocks += block_pool;
68     }
69     m_coord_blocks[nb] =
70         FX_Alloc( float, block_size * 2 +
71                   block_size /
72                   (sizeof(float) / sizeof(unsigned char)));
73     m_cmd_blocks[nb]  =
74         (unsigned char*)(m_coord_blocks[nb] + block_size * 2);
75     m_total_blocks++;
76 }
rewind(unsigned path_id)77 void path_storage::rewind(unsigned path_id)
78 {
79     m_iterator = path_id;
80 }
curve4(float x_ctrl1,float y_ctrl1,float x_ctrl2,float y_ctrl2,float x_to,float y_to)81 void path_storage::curve4(float x_ctrl1, float y_ctrl1,
82                           float x_ctrl2, float y_ctrl2,
83                           float x_to,    float y_to)
84 {
85     add_vertex(x_ctrl1, y_ctrl1, path_cmd_curve4);
86     add_vertex(x_ctrl2, y_ctrl2, path_cmd_curve4);
87     add_vertex(x_to,    y_to,    path_cmd_curve4);
88 }
end_poly()89 void path_storage::end_poly()
90 {
91     if(m_total_vertices) {
92         if(is_vertex(command(m_total_vertices - 1))) {
93             add_vertex(0, 0, path_cmd_end_poly | path_flags_close);
94         }
95     }
96 }
97 }
98