diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/object/sp-dimensions.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-upstream.tar.xz inkscape-upstream.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/object/sp-dimensions.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/object/sp-dimensions.cpp b/src/object/sp-dimensions.cpp new file mode 100644 index 0000000..b5d8c47 --- /dev/null +++ b/src/object/sp-dimensions.cpp @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * SVG dimensions implementation + * + * Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * Edward Flick (EAF) + * Abhishek Sharma + * Jon A. Cruz <jon@joncruz.org> + * + * Copyright (C) 1999-2005 Authors + * Copyright (C) 2000-2001 Ximian, Inc. + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "sp-dimensions.h" +#include "sp-item.h" +#include "svg/svg.h" + +/** + * Update computed x/y/width/height for "percent" units and/or from its + * referencing clone parent. + * + * @param assign_to_set Set `_set` to true for x/y/width/height. + * @param use If not NULL, then overwrite computed width and height from there. + */ +void SPDimensions::calcDimsFromParentViewport(const SPItemCtx *ictx, bool assign_to_set, // + SPDimensions const *use) +{ +#define ASSIGN(field) { if (assign_to_set) { field._set = true; } } + + auto const *effectivewidth = &this->width; + auto const *effectiveheight = &this->height; + + if (use) { + assert(!assign_to_set); + + if (use->width._set) { + effectivewidth = &use->width; + } + + if (use->height._set) { + effectiveheight = &use->height; + } + } + + if (this->x.unit == SVGLength::PERCENT) { + ASSIGN(x); + this->x.computed = this->x.value * ictx->viewport.width(); + } + + if (this->y.unit == SVGLength::PERCENT) { + ASSIGN(y); + this->y.computed = this->y.value * ictx->viewport.height(); + } + + if (effectivewidth->unit == SVGLength::PERCENT) { + ASSIGN(width); + this->width.computed = effectivewidth->value * ictx->viewport.width(); + } else { + this->width.computed = effectivewidth->computed; + } + + if (effectiveheight->unit == SVGLength::PERCENT) { + ASSIGN(height); + this->height.computed = effectiveheight->value * ictx->viewport.height(); + } else { + this->height.computed = effectiveheight->computed; + } +} + +/** + * Write the geometric properties (x/y/width/height) to XML attributes, if they are set. + */ +void SPDimensions::writeDimensions(Inkscape::XML::Node *repr) const +{ + if (x._set) { + repr->setAttribute("x", sp_svg_length_write_with_units(x)); + } + if (y._set) { + repr->setAttribute("y", sp_svg_length_write_with_units(y)); + } + if (width._set) { + repr->setAttribute("width", sp_svg_length_write_with_units(width)); + } + if (height._set) { + repr->setAttribute("height", sp_svg_length_write_with_units(height)); + } +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : |