Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-dimensions.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * SVG dimensions implementation
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Edward Flick (EAF)
8 * Abhishek Sharma
9 * Jon A. Cruz <jon@joncruz.org>
10 *
11 * Copyright (C) 1999-2005 Authors
12 * Copyright (C) 2000-2001 Ximian, Inc.
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include "sp-dimensions.h"
18#include "sp-item.h"
19#include "svg/svg.h"
20
28void SPDimensions::calcDimsFromParentViewport(const SPItemCtx *ictx, bool assign_to_set, //
29 SPDimensions const *use)
30{
31#define ASSIGN(field) { if (assign_to_set) { field._set = true; } }
32
33 auto const *effectivewidth = &this->width;
34 auto const *effectiveheight = &this->height;
35
36 if (use) {
38
39 if (use->width._set) {
40 effectivewidth = &use->width;
41 }
42
43 if (use->height._set) {
44 effectiveheight = &use->height;
45 }
46 }
47
48 if (this->x.unit == SVGLength::PERCENT) {
49 ASSIGN(x);
50 this->x.computed = this->x.value * ictx->viewport.width();
51 }
52
53 if (this->y.unit == SVGLength::PERCENT) {
54 ASSIGN(y);
55 this->y.computed = this->y.value * ictx->viewport.height();
56 }
57
61 } else {
63 }
64
68 } else {
70 }
71}
72
77{
78 if (x._set) {
80 }
81 if (y._set) {
83 }
84 if (width._set) {
86 }
87 if (height._set) {
89 }
90}
91
92/*
93 Local Variables:
94 mode:c++
95 c-file-style:"stroustrup"
96 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97 indent-tabs-mode:nil
98 fill-column:99
99 End:
100*/
101// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
C height() const
Get the vertical extent of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
Interface for refcounted XML nodes.
Definition node.h:80
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
void calcDimsFromParentViewport(const SPItemCtx *ictx, bool assign_to_set=false, SPDimensions const *use=nullptr)
Update computed x/y/width/height for "percent" units and/or from its referencing clone parent.
SVGLength y
SVGLength height
SVGLength width
void writeDimensions(Inkscape::XML::Node *) const
Write the geometric properties (x/y/width/height) to XML attributes, if they are set.
SVGLength x
float value
Definition svg-length.h:47
bool _set
Definition svg-length.h:41
Unit unit
Definition svg-length.h:44
float computed
Definition svg-length.h:50
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
Contains transformations to document/viewport and the viewport size.
Definition sp-item.h:92
Geom::Rect viewport
Viewport size.
Definition sp-item.h:97
std::string sp_svg_length_write_with_units(SVGLength const &length)
N.B. This routine will sometimes return strings with ā€˜e’ notation, so is unsuitable for CSS lengths (...