16#include <glibmm/regex.h>
23#define FALLBACK(i) ((i - 2 >= 0) ? (i - 2) : 0)
62std::string
SVGBox::toString(
const std::string &unit,
const Geom::Scale &doc_scale, std::optional<unsigned int> precision,
bool add_unit)
const
66 for (
int i = 3; i >= 0; i--) {
72 ret = std::string(val.
toString(unit, axis_scale, precision, add_unit)) +
" " + ret;
74 ret = std::string(val.
write()) +
" " + ret;
88 if (!value.size())
return false;
91 std::vector<Glib::ustring> elements = Glib::Regex::split_simple(
"\\s*[,\\s]\\s*", value.c_str());
94 for (
int i = 0; i < 4; i++) {
95 if ((i ==
BOX_TOP || (
int)elements.size() >= i+1) && elements[i].size() > 0) {
136void SVGBox::set(
double top,
double right,
double bottom,
double left) {
151 for (
int i = 0; i < 4; i++) {
164 if (!value || !
read(value, doc_scale)) {
void set(BoxSide side, double value, bool confine=false)
Set the value of the side, retaining it's original unit.
static Geom::Dim2 get_scale_axis(BoxSide side)
bool fromString(const std::string &value, const std::string &unit, const Geom::Scale &doc_scale)
Set the svg box from user input, with a default unit.
bool isZero() const
Returns true if the box is set, but all values are zero.
void readOrUnset(gchar const *str, const Geom::Scale &doc_scale)
std::string write() const
Write out the values into a compact form.
void update(double em, double ex, double width, double height)
Update box with em, ex and percentage scaling.
SVGBox()
An svg box is a type of css/html type which contains up to 4 svg lengths.
bool read(const std::string &value, const Geom::Scale &doc_scale)
Read in the value, may be an array of four.
std::string toString(const std::string &unit, const Geom::Scale &doc_scale, std::optional< unsigned int > precision={}, bool add_unit=true) const
Write as specific unit for user display.
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 set(Unit u, float v)
std::string write() const
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.
void update(double em, double ex, double scale)