summaryrefslogtreecommitdiff
path: root/third_party/agg23/agg_path_storage.cpp
blob: c24f7952ba2af04b9dae5a64798e8698599acb61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

//----------------------------------------------------------------------------
// XYQ: 2006-01-22 Copied from AGG project.
// TODO: This file uses intensive floating point operations, so it's NOT suitable
// for platforms like Symbian OS. We need to change to FIX format.
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Class path_storage
//
//----------------------------------------------------------------------------

#include "agg_math.h"
#include "agg_path_storage.h"
#include "core/fxcrt/fx_basic.h"

namespace agg
{
path_storage::~path_storage()
{
    if(m_total_blocks) {
        float** coord_blk = m_coord_blocks + m_total_blocks - 1;
        while(m_total_blocks--) {
            FX_Free(*coord_blk);
            --coord_blk;
        }
        FX_Free(m_coord_blocks);
    }
}
path_storage::path_storage() :
    m_total_vertices(0),
    m_total_blocks(0),
    m_max_blocks(0),
    m_coord_blocks(0),
    m_cmd_blocks(0),
    m_iterator(0)
{
}
void path_storage::allocate_block(unsigned nb)
{
    if(nb >= m_max_blocks) {
        float** new_coords =
            FX_Alloc2D(float*, m_max_blocks + block_pool, 2);
        unsigned char** new_cmds =
            (unsigned char**)(new_coords + m_max_blocks + block_pool);
        if(m_coord_blocks) {
          memcpy(new_coords, m_coord_blocks, m_max_blocks * sizeof(float*));
          memcpy(new_cmds, m_cmd_blocks, m_max_blocks * sizeof(unsigned char*));
          FX_Free(m_coord_blocks);
        }
        m_coord_blocks = new_coords;
        m_cmd_blocks = new_cmds;
        m_max_blocks += block_pool;
    }
    m_coord_blocks[nb] =
        FX_Alloc( float, block_size * 2 +
                  block_size /
                  (sizeof(float) / sizeof(unsigned char)));
    m_cmd_blocks[nb]  =
        (unsigned char*)(m_coord_blocks[nb] + block_size * 2);
    m_total_blocks++;
}
void path_storage::rewind(unsigned path_id)
{
    m_iterator = path_id;
}
void path_storage::curve4(float x_ctrl1, float y_ctrl1,
                          float x_ctrl2, float y_ctrl2,
                          float x_to,    float y_to)
{
    add_vertex(x_ctrl1, y_ctrl1, path_cmd_curve4);
    add_vertex(x_ctrl2, y_ctrl2, path_cmd_curve4);
    add_vertex(x_to,    y_to,    path_cmd_curve4);
}
void path_storage::end_poly()
{
    if(m_total_vertices) {
        if(is_vertex(command(m_total_vertices - 1))) {
            add_vertex(0, 0, path_cmd_end_poly | path_flags_close);
        }
    }
}
}