xref: /aosp_15_r20/external/pdfium/third_party/agg23/agg_path_storage.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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: [email protected]
18 //          [email protected]
19 //          http://www.antigrain.com
20 //----------------------------------------------------------------------------
21 //
22 // Class path_storage
23 //
24 //----------------------------------------------------------------------------
25 
26 #include "agg_path_storage.h"
27 
28 #include <string.h>
29 
30 #include "agg_math.h"
31 #include "core/fxcrt/fx_memory.h"
32 
33 namespace pdfium
34 {
35 namespace agg
36 {
~path_storage()37 path_storage::~path_storage()
38 {
39     if(m_total_blocks) {
40         float** coord_blk = m_coord_blocks + m_total_blocks - 1;
41         while(m_total_blocks--) {
42             FX_Free(*coord_blk);
43             --coord_blk;
44         }
45         FX_Free(m_coord_blocks);
46     }
47 }
48 path_storage::path_storage() = default;
path_storage(path_storage && other)49 path_storage::path_storage(path_storage&& other) {
50     m_total_vertices = other.m_total_vertices;
51     m_total_blocks = other.m_total_blocks;
52     m_max_blocks = other.m_max_blocks;
53     m_coord_blocks = other.m_coord_blocks;
54     m_cmd_blocks = other.m_cmd_blocks;
55     m_iterator = other.m_iterator;
56     other.m_total_vertices = 0;
57     other.m_total_blocks = 0;
58     other.m_max_blocks = 0;
59     other.m_coord_blocks = nullptr;
60     other.m_cmd_blocks = nullptr;
61     other.m_iterator = 0;
62 }
allocate_block(unsigned nb)63 void path_storage::allocate_block(unsigned nb)
64 {
65     if(nb >= m_max_blocks) {
66         float** new_coords =
67             FX_Alloc2D(float*, m_max_blocks + block_pool, 2);
68         unsigned char** new_cmds =
69             (unsigned char**)(new_coords + m_max_blocks + block_pool);
70         if(m_coord_blocks) {
71           memcpy(new_coords, m_coord_blocks, m_max_blocks * sizeof(float*));
72           memcpy(new_cmds, m_cmd_blocks, m_max_blocks * sizeof(unsigned char*));
73           FX_Free(m_coord_blocks);
74         }
75         m_coord_blocks = new_coords;
76         m_cmd_blocks = new_cmds;
77         m_max_blocks += block_pool;
78     }
79     m_coord_blocks[nb] =
80         FX_Alloc( float, block_size * 2 +
81                   block_size /
82                   (sizeof(float) / sizeof(unsigned char)));
83     m_cmd_blocks[nb]  =
84         (unsigned char*)(m_coord_blocks[nb] + block_size * 2);
85     m_total_blocks++;
86 }
rewind(unsigned path_id)87 void path_storage::rewind(unsigned path_id)
88 {
89     m_iterator = path_id;
90 }
curve4(float x_ctrl1,float y_ctrl1,float x_ctrl2,float y_ctrl2,float x_to,float y_to)91 void path_storage::curve4(float x_ctrl1, float y_ctrl1,
92                           float x_ctrl2, float y_ctrl2,
93                           float x_to,    float y_to)
94 {
95     add_vertex(x_ctrl1, y_ctrl1, path_cmd_curve4);
96     add_vertex(x_ctrl2, y_ctrl2, path_cmd_curve4);
97     add_vertex(x_to,    y_to,    path_cmd_curve4);
98 }
end_poly()99 void path_storage::end_poly()
100 {
101     if(m_total_vertices) {
102         if(is_vertex(command(m_total_vertices - 1))) {
103             add_vertex(0, 0, unsigned{path_cmd_end_poly} | path_flags_close);
104         }
105     }
106 }
107 }
108 }  // namespace pdfium
109