Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
svg-length.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
13#ifndef SEEN_SP_SVG_LENGTH_H
14#define SEEN_SP_SVG_LENGTH_H
15
16#include <string>
17#include <optional>
18
22class SVGLength {
23public:
24 SVGLength();
25
39
40 // The object's value is valid / exists in SVG.
41 bool _set;
42
43 // The unit of value.
45
46 // The value of this SVGLength as found in the SVG.
47 float value;
48
49 // The value in pixels (value * pixels/unit).
50 float computed;
51
52 float operator=(float v) {
53 _set = true;
54 unit = NONE;
55 value = computed = v;
56 return v;
57 }
58
59 bool operator==(const SVGLength& rhs) const {
60 if (rhs.unit == unit) {
62 return value == rhs.value;
63 return computed == rhs.computed;
64 }
65 return false;
66 }
67 bool operator!=(const SVGLength& rhs) const {
68 return !(*this == rhs);
69 }
70
71 operator bool() const { return _set; }
72
73 bool read(char const *str);
74 void readOrUnset(char const *str, Unit u = NONE, float v = 0, float c = 0);
75 bool readAbsolute(char const *str);
76 std::string getUnit() const;
77 bool isAbsolute();
78
79 std::string write() const;
80 std::string toString(const std::string &unit, double doc_scale, std::optional<unsigned int> precision = {}, bool add_unit = true) const;
81 double toValue(const std::string &out_unit) const;
82 bool fromString(const std::string &input, const std::string &unit, std::optional<double> scale = {});
83
84 // To set 'v' use '='
85 void set(Unit u, float v); // Sets computed value based on u and v.
86 void set(Unit u, float v, float c); // Sets all three values.
87 void unset(Unit u = NONE, float v = 0, float c = 0);
88 void scale(double scale); // Scales length (value, computed), leaving unit alone.
89 void update(double em, double ex, double scale); // Updates computed value
90};
91
94
95namespace Inkscape {
96char const *refX_named_to_percent(char const *str);
97char const *refY_named_to_percent(char const *str);
98} // namespace Inkscape
99
100#endif // SEEN_SP_SVG_LENGTH_H
101
102/*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110*/
111// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
SVG length type.
Definition svg-length.h:22
double toValue(const std::string &out_unit) const
Caulate the length in a user unit.
std::string toString(const std::string &unit, double doc_scale, std::optional< unsigned int > precision={}, bool add_unit=true) const
Write out length in user unit, for the user to use.
void scale(double scale)
bool read(char const *str)
std::string getUnit() const
Returns the unit used as a string.
bool isAbsolute()
Is this length an absolute value (uses an absolute unit).
float value
Definition svg-length.h:47
bool operator!=(const SVGLength &rhs) const
Definition svg-length.h:67
std::string write() const
void readOrUnset(char const *str, Unit u=NONE, float v=0, float c=0)
bool _set
Definition svg-length.h:41
float operator=(float v)
Definition svg-length.h:52
void unset(Unit u=NONE, float v=0, float c=0)
Unit unit
Definition svg-length.h:44
bool operator==(const SVGLength &rhs) const
Definition svg-length.h:59
bool fromString(const std::string &input, const std::string &unit, std::optional< double > scale={})
Read from user input, any non-unitised value is converted internally.
bool readAbsolute(char const *str)
float computed
Definition svg-length.h:50
void update(double em, double ex, double scale)
double c[8][4]
Helper class to stream background task notifications as a series of messages.
char const * refY_named_to_percent(char const *str)
char const * refX_named_to_percent(char const *str)
bool svg_length_absolute_unit(SVGLength::Unit unit)
char const * sp_svg_length_get_css_units(SVGLength::Unit unit)