Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
SVGLength Class Reference

SVG length type. More...

#include <svg-length.h>

Public Types

enum  Unit {
  NONE , PX , PT , PC ,
  MM , CM , INCH , EM ,
  EX , PERCENT , LAST_UNIT = PERCENT
}
 

Public Member Functions

 SVGLength ()
 
float operator= (float v)
 
bool operator== (const SVGLength &rhs) const
 
bool operator!= (const SVGLength &rhs) const
 
 operator bool () const
 
bool read (char const *str)
 
void readOrUnset (char const *str, Unit u=NONE, float v=0, float c=0)
 
bool readAbsolute (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).
 
std::string write () const
 
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.
 
double toValue (const std::string &out_unit) const
 Caulate the length in a user unit.
 
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 set (Unit u, float v)
 
void set (Unit u, float v, float c)
 
void unset (Unit u=NONE, float v=0, float c=0)
 
void scale (double scale)
 
void update (double em, double ex, double scale)
 

Public Attributes

bool _set
 
Unit unit
 
float value
 
float computed
 

Detailed Description

SVG length type.

Definition at line 22 of file svg-length.h.

Member Enumeration Documentation

◆ Unit

Enumerator
NONE 
PX 
PT 
PC 
MM 
CM 
INCH 
EM 
EX 
PERCENT 
LAST_UNIT 

Definition at line 26 of file svg-length.h.

Constructor & Destructor Documentation

◆ SVGLength()

SVGLength::SVGLength ( )

Definition at line 142 of file svg-length.cpp.

Member Function Documentation

◆ fromString()

bool SVGLength::fromString ( const std::string &  input,
const std::string &  default_unit,
std::optional< double >  doc_scale = {} 
)

Read from user input, any non-unitised value is converted internally.

Parameters
input- The string input
default_unit- The unit used by the display. Set to empty string for xml reading.
doc_scale- The scale values with units should apply to make those units correct for this document.

Definition at line 493 of file svg-length.cpp.

References computed, NONE, PERCENT, read(), scale(), unit, and value.

Referenced by SVGBox::fromString().

◆ getUnit()

std::string SVGLength::getUnit ( ) const

Returns the unit used as a string.

Returns
unit string

Definition at line 207 of file svg-length.cpp.

References sp_svg_length_get_css_units(), and unit.

◆ isAbsolute()

bool SVGLength::isAbsolute ( )

Is this length an absolute value (uses an absolute unit).

Returns
true if unit is not NONE and not a relative unit (percent etc)

Definition at line 217 of file svg-length.cpp.

References svg_length_absolute_unit(), and unit.

◆ operator bool()

SVGLength::operator bool ( ) const
inline

Definition at line 71 of file svg-length.h.

References _set.

◆ operator!=()

bool SVGLength::operator!= ( const SVGLength rhs) const
inline

Definition at line 67 of file svg-length.h.

◆ operator=()

float SVGLength::operator= ( float  v)
inline

Definition at line 52 of file svg-length.h.

References _set, computed, NONE, unit, and value.

◆ operator==()

bool SVGLength::operator== ( const SVGLength rhs) const
inline

Definition at line 59 of file svg-length.h.

References computed, PERCENT, unit, and value.

◆ read()

◆ readAbsolute()

bool SVGLength::readAbsolute ( char const *  str)

Definition at line 177 of file svg-length.cpp.

References _set, c, computed, sp_svg_length_read_lff(), svg_length_absolute_unit(), unit, and value.

◆ readOrUnset()

◆ scale()

void SVGLength::scale ( double  scale)

Definition at line 557 of file svg-length.cpp.

References computed, scale, and value.

Referenced by fromString(), SPGenericEllipse::set_transform(), and SPRect::set_transform().

◆ set() [1/2]

◆ set() [2/2]

void SVGLength::set ( SVGLength::Unit  u,
float  v,
float  c 
)

Definition at line 541 of file svg-length.cpp.

References _set, c, computed, unit, and value.

◆ toString()

std::string SVGLength::toString ( const std::string &  out_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.

Parameters
out_unit- The unit to convert the computed px into
Returns
a string containing the value in the given units

Definition at line 458 of file svg-length.cpp.

References Inkscape::Util::format_number(), PERCENT, Inkscape::SVGOStringStream::str(), toValue(), unit, value, and write().

Referenced by SPMeshGradient::create_drawing_paintserver(), and SVGBox::toString().

◆ toValue()

double SVGLength::toValue ( const std::string &  out_unit) const

Caulate the length in a user unit.

Parameters
out_unit- The unit to convert the computed px into
Returns
a double of the computed value in this unit

Definition at line 481 of file svg-length.cpp.

References computed, and Inkscape::Util::Quantity::convert().

Referenced by toString().

◆ unset()

◆ update()

void SVGLength::update ( double  em,
double  ex,
double  scale 
)

◆ write()

Member Data Documentation

◆ _set

◆ computed

float SVGLength::computed

Definition at line 50 of file svg-length.h.

Referenced by SPText::_buildLayoutInput(), SPFlowtext::_buildLayoutInput(), Inkscape::Text::Layout::_calculateCursorShapeForEmpty(), Inkscape::UI::Widget::CanvasGrid::_createGuide(), _ungroup_compensate_source_transform(), SPHatchPath::_updateView(), Inkscape::Text::Layout::appendText(), SPUse::bbox(), SPImage::bbox(), SPHatchPath::bounds(), SPDimensions::calcDimsFromParentViewport(), SPRect::compensateRxRy(), SPLine::convert_to_guides(), SPRect::convert_to_guides(), SPMeshNodeArray::create(), SPLinearGradient::create_drawing_paintserver(), SPRadialGradient::create_drawing_paintserver(), SPImage::cropToArea(), SPImage::cropToArea(), InkFileExportCmd::do_export_png(), SPDocument::doc2dt(), Inkscape::Filters::Filter::filter_effect_area(), Inkscape::Filters::FilterPrimitive::filter_primitive_area(), Inkscape::UI::Tools::ArcTool::finishItem(), Inkscape::UI::Tools::RectTool::finishItem(), Inkscape::Text::Layout::fitToPathAlign(), SPDocument::fitToRect(), fromString(), SVGBox::get(), SPGrid::get_gap(), SPGrid::get_margin(), Inkscape::Extension::Internal::PdfBuilder::Document::get_radial_pattern(), SPUse::get_xy_offset(), SPPage::getBleed(), SPPage::getDocumentMargin(), SPDocument::getDocumentScale(), SPGrid::getEffectiveOriginAndSpacing(), SPLinearGradient::getLine(), SPGrid::getOrigin(), SPGenericEllipse::getPointAtAngle(), SPPage::getRect(), SPRect::getRect(), SPGrid::getSpacing(), SPRect::getVisibleHeight(), SPGenericEllipse::getVisibleRx(), SPRect::getVisibleRx(), SPGenericEllipse::getVisibleRy(), SPRect::getVisibleRy(), SPRect::getVisibleWidth(), SPUse::has_xy_offset(), Inkscape::Extension::Internal::PrintMetafile::hold_gradient(), TextTagAttributes::insertSingleAttribute(), TextTagAttributes::mergeInto(), operator=(), operator==(), Inkscape::Extension::Internal::PdfBuilder::DrawContext::paint_item_clone(), SPImage::print(), SPUse::print(), read(), SPMeshNodeArray::read(), readAbsolute(), Inkscape::Extension::Internal::CairoRenderer::renderHatchPath(), scale(), SPRadialGradient::set(), SPRoot::set(), SPGuide::set(), set(), set(), SPGenericEllipse::set_shape(), SPLine::set_shape(), SPRect::set_shape(), SPImage::set_transform(), SPLine::set_transform(), SPGenericEllipse::set_transform(), SPRect::set_transform(), SPPage::setDocumentRect(), SPDocument::setDocumentScale(), SPDocument::setHeight(), SPRoot::setRootDimensions(), SPRect::setVisibleHeight(), SPRect::setVisibleRx(), SPRect::setVisibleRy(), SPRect::setVisibleWidth(), SPDocument::setWidth(), SPDocument::setWidthAndHeight(), SPUse::show(), SPGenericEllipse::snappoints(), SPImage::snappoints(), SPRect::snappoints(), sp_genericellipse_side(), sp_rect_clamp_radii(), sp_textpath_to_text(), Inkscape::Extension::Internal::LaTeXTextRenderer::sp_use_render(), Inkscape::Extension::Internal::sp_use_render(), sp_validate_marker(), toValue(), unset(), update(), SPMarker::update(), SPGrid::update(), SPImage::update(), SPRoot::update(), SPSymbol::update(), SPUse::update(), SPDocument::update_desktop_affine(), SPPage::update_relatives(), SPItem::visualBounds(), SPFilter::write(), SPTextPath::write(), SPMarker::write(), SPPage::write(), SPGenericEllipse::write(), SPImage::write(), SPLine::write(), SPLinearGradient::write(), SPMeshGradient::write(), SPRadialGradient::write(), SPRoot::write(), and SPMeshNodeArray::write().

◆ unit

◆ value


The documentation for this class was generated from the following files: