~centralelyon2010/inkscape/imagelinks2

3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
1
#ifndef SEEN_HELPER_FNS_H
2
#define SEEN_HELPER_FNS_H
3
/** \file
7514 by theadib
resolve Bug #339349, drop shadow effect broken
4
 *
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
5
 * Some helper functions
7514 by theadib
resolve Bug #339349, drop shadow effect broken
6
 *
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
7
 * Authors:
8889 by Felipe C. da S. Sanches
updating my email address in file headers
8
 *   Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
7514 by theadib
resolve Bug #339349, drop shadow effect broken
9
 *
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
10
 *
11
 * Copyright (C) 2006 Hugo Rodrigues
12
 *
13
 * Released under GNU GPL, read the file 'COPYING' for more information
14
 */
15
4588 by keescook
first set of updates to headers for clean gcc 4.3 builds
16
#include <string.h>
4880 by JucaBlues
tiny refactoring
17
#include <vector>
3407 by nicholasbishop
Filter effects:
18
#include <sstream>
19
4185 by kiirala
Fixed several crashes when modifying filter effect parameters with XML editor
20
// calling helperfns_read_number(string, false), it's not obvious, what
21
// that false stands for. helperfns_read_number(string, HELPERFNS_NO_WARNING)
22
// can be more clear.
23
#define HELPERFNS_NO_WARNING false
24
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
25
/* convert ascii representation to double
7514 by theadib
resolve Bug #339349, drop shadow effect broken
26
 * the function can only be used to convert numbers as given by gui elements that use localized representation
27
 * @param value ascii representation of the number
28
 * @return the converted number
29
 *
30
 * Setting warning to false disables conversion error warnings from
4185 by kiirala
Fixed several crashes when modifying filter effect parameters with XML editor
31
 * this function. This can be useful in places, where the input type
32
 * is not known beforehand. For example, see sp_feColorMatrix_set in
33
 * sp-fecolormatrix.cpp */
34
inline double helperfns_read_number(gchar const *value, bool warning = true) {
7752 by jaspervdg
Partial fix for bug 193926 , thanks to Preben Soeberg.
35
    if (!value) {
36
        g_warning("Called helperfns_read_number with value==null_ptr, this can lead to unexpected behaviour.");
37
        return 0;
38
    }
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
39
    char *end;
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
40
    double ret = g_ascii_strtod(value, &end);
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
41
    if (*end) {
4185 by kiirala
Fixed several crashes when modifying filter effect parameters with XML editor
42
        if (warning) {
7514 by theadib
resolve Bug #339349, drop shadow effect broken
43
            g_warning("helper-fns::helperfns_read_number() Unable to convert \"%s\" to number", value);
4185 by kiirala
Fixed several crashes when modifying filter effect parameters with XML editor
44
        }
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
45
        // We could leave this out, too. If strtod can't convert
46
        // anything, it will return zero.
47
        ret = 0;
48
    }
49
    return ret;
50
}
51
3753 by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation
52
inline bool helperfns_read_bool(gchar const *value, bool default_value){
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
53
    if (!value) return default_value;
54
    switch(value[0]){
55
        case 't':
56
            if (strncmp(value, "true", 4) == 0) return true;
57
            break;
58
        case 'f':
59
            if (strncmp(value, "false", 5) == 0) return false;
60
            break;
61
    }
62
    return default_value;
63
}
3364 by jucablues
setting of attributes and default values for feColorMatrix.
64
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
65
/* convert ascii representation to double
7514 by theadib
resolve Bug #339349, drop shadow effect broken
66
 * the function can only be used to convert numbers as given by gui elements that use localized representation
67
 * numbers are delimeted by space
68
 * @param value ascii representation of the number
69
 * @param size number of elements in string
70
 * @return the vector of the converted numbers
71
 */
3753 by joncruz
Refactoring SPColor to C++ and removing legacy CMYK implementation
72
inline std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
3364 by jucablues
setting of attributes and default values for feColorMatrix.
73
        std::vector<gdouble> v(size, (gdouble) 0);
3407 by nicholasbishop
Filter effects:
74
        std::istringstream is(value);
7514 by theadib
resolve Bug #339349, drop shadow effect broken
75
        for(int i = 0; i < size; i++){
76
        	std::string str;
77
            is >> str;
78
            char *end;
79
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
80
            double ret = g_ascii_strtod(str.c_str(), &end);
7514 by theadib
resolve Bug #339349, drop shadow effect broken
81
            if (*end) {
82
                g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", str.c_str());
83
                // We could leave this out, too. If strtod can't convert
84
                // anything, it will return zero.
85
                ret = 0;
86
            }
87
            v[i] = ret;
88
        };
3364 by jucablues
setting of attributes and default values for feColorMatrix.
89
        return v;
90
}
91
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
92
/* convert ascii representation to double
7514 by theadib
resolve Bug #339349, drop shadow effect broken
93
 * the function can only be used to convert numbers as given by gui elements that use localized representation
94
 * numbers are delimeted by space
95
 * @param value ascii representation of the number
96
 * @return the vector of the converted numbers
97
 */
4704 by JucaBlues
Offline work done during weekend:
98
inline std::vector<gdouble> helperfns_read_vector(const gchar* value){
99
        std::vector<gdouble> v;
7514 by theadib
resolve Bug #339349, drop shadow effect broken
100
7599 by jaspervdg
Fix for helperfns_read_vector (which could go on trying to read numbers for ever) and some quality improvements to gradient rendering and feComponentTransfer handling.
101
        gchar const* beg = value;
102
        while(isspace(*beg)) beg++;
103
        while(*beg)
7514 by theadib
resolve Bug #339349, drop shadow effect broken
104
        {
105
            char *end;
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
106
            double ret = g_ascii_strtod(beg, &end);
7599 by jaspervdg
Fix for helperfns_read_vector (which could go on trying to read numbers for ever) and some quality improvements to gradient rendering and feComponentTransfer handling.
107
            if (end==beg){
108
                g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", beg);
7514 by theadib
resolve Bug #339349, drop shadow effect broken
109
                // We could leave this out, too. If strtod can't convert
110
                // anything, it will return zero.
111
                ret = 0;
112
            }
7599 by jaspervdg
Fix for helperfns_read_vector (which could go on trying to read numbers for ever) and some quality improvements to gradient rendering and feComponentTransfer handling.
113
            v.push_back(ret);
7514 by theadib
resolve Bug #339349, drop shadow effect broken
114
7599 by jaspervdg
Fix for helperfns_read_vector (which could go on trying to read numbers for ever) and some quality improvements to gradient rendering and feComponentTransfer handling.
115
            beg = end;
116
            while(isspace(*beg)) beg++;
4704 by JucaBlues
Offline work done during weekend:
117
        }
118
        return v;
119
}
120
3314 by jucablues
refactoring: gathering some commonly copy'n'pasted functions on a common
121
#endif /* !SEEN_HELPER_FNS_H */
122
123
/*
124
  Local Variables:
125
  mode:c++
126
  c-file-style:"stroustrup"
127
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
128
  indent-tabs-mode:nil
129
  fill-column:99
130
  End:
131
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
132
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :