• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_math.h"
27 #include "agg_path_storage.h"
28 #include "core/fxcrt/fx_basic.h"
29 
30 namespace agg
31 {
~path_storage()32 path_storage::~path_storage()
33 {
34     if(m_total_blocks) {
35         FX_FLOAT** coord_blk = m_coord_blocks + m_total_blocks - 1;
36         while(m_total_blocks--) {
37             FX_Free(*coord_blk);
38             --coord_blk;
39         }
40         FX_Free(m_coord_blocks);
41     }
42 }
path_storage()43 path_storage::path_storage() :
44     m_total_vertices(0),
45     m_total_blocks(0),
46     m_max_blocks(0),
47     m_coord_blocks(0),
48     m_cmd_blocks(0),
49     m_iterator(0)
50 {
51 }
allocate_block(unsigned nb)52 void path_storage::allocate_block(unsigned nb)
53 {
54     if(nb >= m_max_blocks) {
55         FX_FLOAT** new_coords =
56             FX_Alloc2D(FX_FLOAT*, m_max_blocks + block_pool, 2);
57         unsigned char** new_cmds =
58             (unsigned char**)(new_coords + m_max_blocks + block_pool);
59         if(m_coord_blocks) {
60             FXSYS_memcpy(new_coords,
61                            m_coord_blocks,
62                            m_max_blocks * sizeof(FX_FLOAT*));
63             FXSYS_memcpy(new_cmds,
64                            m_cmd_blocks,
65                            m_max_blocks * sizeof(unsigned char*));
66             FX_Free(m_coord_blocks);
67         }
68         m_coord_blocks = new_coords;
69         m_cmd_blocks = new_cmds;
70         m_max_blocks += block_pool;
71     }
72     m_coord_blocks[nb] =
73         FX_Alloc( FX_FLOAT, block_size * 2 +
74                   block_size /
75                   (sizeof(FX_FLOAT) / sizeof(unsigned char)));
76     m_cmd_blocks[nb]  =
77         (unsigned char*)(m_coord_blocks[nb] + block_size * 2);
78     m_total_blocks++;
79 }
rewind(unsigned path_id)80 void path_storage::rewind(unsigned path_id)
81 {
82     m_iterator = path_id;
83 }
curve4(FX_FLOAT x_ctrl1,FX_FLOAT y_ctrl1,FX_FLOAT x_ctrl2,FX_FLOAT y_ctrl2,FX_FLOAT x_to,FX_FLOAT y_to)84 void path_storage::curve4(FX_FLOAT x_ctrl1, FX_FLOAT y_ctrl1,
85                           FX_FLOAT x_ctrl2, FX_FLOAT y_ctrl2,
86                           FX_FLOAT x_to,    FX_FLOAT y_to)
87 {
88     add_vertex(x_ctrl1, y_ctrl1, path_cmd_curve4);
89     add_vertex(x_ctrl2, y_ctrl2, path_cmd_curve4);
90     add_vertex(x_to,    y_to,    path_cmd_curve4);
91 }
end_poly()92 void path_storage::end_poly()
93 {
94     if(m_total_vertices) {
95         if(is_vertex(command(m_total_vertices - 1))) {
96             add_vertex(0, 0, path_cmd_end_poly | path_flags_close);
97         }
98     }
99 }
100 }
101