1 /*
2 * Inkscape::SVG::PathString - builder for SVG path strings
3 *
4 * Copyright 2008 Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #include "svg/path-string.h"
16 #include "prefs-utils.h"
18 Inkscape::SVG::PathString::PathString() :
19 allow_relative_coordinates(0 != prefs_get_int_attribute("options.svgoutput", "allowrelativecoordinates", 1)),
20 force_repeat_commands(0 != prefs_get_int_attribute("options.svgoutput", "forcerepeatcommands", 0))
21 {}
23 void Inkscape::SVG::PathString::_appendOp(char abs_op, char rel_op) {
24 bool abs_op_repeated = _abs_state.prevop == abs_op && !force_repeat_commands;
25 bool rel_op_repeated = _rel_state.prevop == rel_op && !force_repeat_commands;
26 unsigned int const abs_added_size = abs_op_repeated ? 0 : 2;
27 unsigned int const rel_added_size = rel_op_repeated ? 0 : 2;
28 if ( _rel_state.str.size()+2 < _abs_state.str.size()+abs_added_size && allow_relative_coordinates ) {
29 // Copy rel to abs
30 _abs_state = _rel_state;
31 _abs_state.switches++;
32 abs_op_repeated = false;
33 // We do not have to copy abs to rel:
34 // _rel_state.str.size()+2 < _abs_state.str.size()+abs_added_size
35 // _rel_state.str.size()+rel_added_size < _abs_state.str.size()+2
36 // _abs_state.str.size()+2 > _rel_state.str.size()+rel_added_size
37 } else if ( _abs_state.str.size()+2 < _rel_state.str.size()+rel_added_size ) {
38 // Copy abs to rel
39 _rel_state = _abs_state;
40 _abs_state.switches++;
41 rel_op_repeated = false;
42 }
43 if ( !abs_op_repeated ) _abs_state.appendOp(abs_op);
44 if ( !rel_op_repeated ) _rel_state.appendOp(rel_op);
45 }
47 /*
48 Local Variables:
49 mode:c++
50 c-file-style:"stroustrup"
51 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
52 indent-tabs-mode:nil
53 fill-column:99
54 End:
55 */
56 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :