Inkscape
Vector Graphics Editor
|
Miscellaneous supporting code. More...
Namespaces | |
namespace | detail |
namespace | GlibValue |
Classes | |
class | AcceleratorKey |
Gtk::AccelKey but with equality and less-than operators. More... | |
class | ActionAccel |
The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track of changes in the keybindings. More... | |
class | cached_map |
A cached_map<Tk, Tv> is designed for use by a factory that takes as input keys of type Tk and produces objects of type std::unique_ptr<Tv> in response. More... | |
class | const_char_ptr |
Non-owning reference to 'const char*' Main-purpose: avoid overloads of type f(char*, str&) , f(str&, char*) , f(char*, char*) , ... More... | |
struct | Deleter |
Turn a function into a function object that can be used as a deleter for a smart pointer. More... | |
struct | DependencyRegisterer |
struct | DependencyRegisterer< Depends< T, Ts... > > |
struct | Depends |
class | EnableSingleton |
struct | EnumData |
Simplified management of enumerations of svg items with UI labels. More... | |
class | EnumDataConverter |
Simplified management of enumerations of svg items with UI labels. More... | |
class | EvaluatorException |
Special exception class for the expression evaluator. More... | |
class | EvaluatorQuantity |
EvaluatorQuantity: More... | |
class | EvaluatorToken |
EvaluatorToken. More... | |
class | ExpressionEvaluator |
ExpressionEvaluator. More... | |
class | FixedPoint |
class | ForwardPointerIterator |
class | ForwardPointerIterator< BaseType const, Strategy > |
class | FuncLog |
A FuncLog is effectively a std::vector<std::function<void()>>, with the ability to hold move-only function types and enforced run-once semantics. More... | |
class | GObjectPtr |
A smart pointer that shares ownership of a GObject. More... | |
class | HybridPointer |
A helper class holding an owning or non-owning pointer depending on the memory management requirements. More... | |
class | Pool |
A Pool is a block allocator with the following characteristics: More... | |
class | ptr_shared |
class | Quantity |
class | StaticHolder |
class | StaticHolderBase |
class | StaticsBin |
The following system provides a way of dealing with statics/singletons with unusual lifetime requirements, specifically the requirement that they be destroyed before the end of main(). More... | |
struct | TreeifyResult |
class | Unit |
struct | UnitMetric |
class | UnitTable |
Typedefs | |
typedef int | TokenType |
Enumerations | |
enum | { TOKEN_NUM = 30000 , TOKEN_IDENTIFIER = 30001 , TOKEN_ANY = 40000 , TOKEN_END = 50000 } |
TokenType. More... | |
enum | UnitType { UNIT_TYPE_DIMENSIONLESS , UNIT_TYPE_LINEAR , UNIT_TYPE_LINEAR_SCALED , UNIT_TYPE_RADIAL , UNIT_TYPE_TIME , UNIT_TYPE_FONT_HEIGHT , UNIT_TYPE_QTY , UNIT_TYPE_NONE = -1 } |
Functions | |
double | round_to_nearest_multiple_plus (double x, double c1, double c0) |
double | round_to_lower_multiple_plus (double x, double c1, double c0=0.0) |
double | round_to_upper_multiple_plus (double x, double const c1, double const c0=0) |
template<typename T > | |
int constexpr | floorlog2 (T x) |
Returns floor(log_2(x)), assuming x >= 1. | |
template<typename T , typename std::enable_if< std::is_integral< T >::value, bool >::type = true> | |
T constexpr | safemod (T a, T b) |
Returns a mod b, always in the range 0..b-1, assuming b >= 1. | |
template<typename T , typename std::enable_if< std::is_integral< T >::value, bool >::type = true> | |
T constexpr | round_down (T a, T b) |
Returns a rounded down to the nearest multiple of b, assuming b >= 1. | |
template<typename T , typename std::enable_if< std::is_integral< T >::value, bool >::type = true> | |
T constexpr | round_up (T a, T b) |
Returns a rounded up to the nearest multiple of b, assuming b >= 1. | |
template<typename T > | |
T | safeclamp (T val, T lo, T hi) |
Just like std::clamp, except it doesn't deliberately crash if lo > hi due to rounding errors, so is safe to use with floating-point types. | |
template<auto f, typename T > | |
auto | delete_with (T *p) |
Wrap a raw pointer in a std::unique_ptr with a custom function as the deleter. | |
Geom::Rect | rounded_rectangle (const Cairo::RefPtr< Cairo::Context > &ctx, const Geom::Rect &rect, double radius) |
void | circle (const Cairo::RefPtr< Cairo::Context > &ctx, const Geom::Point ¢er, double radius) |
void | draw_border (const Cairo::RefPtr< Cairo::Context > &ctx, Geom::Rect rect, double radius, const Gdk::RGBA &color, int device_scale, bool circular) |
void | draw_standard_border (const Cairo::RefPtr< Cairo::Context > &ctx, Geom::Rect rect, bool dark_theme, double radius, int device_scale, bool circular) |
std::optional< Gdk::RGBA > | lookup_background_color (Glib::RefPtr< Gtk::StyleContext > &style) |
std::optional< Gdk::RGBA > | lookup_foreground_color (Glib::RefPtr< Gtk::StyleContext > &style) |
const Glib::ustring | empty_string ("") |
template<typename T > requires std::is_enum_v<T> | |
constexpr bool | any_flag (T test) |
template<typename T > requires std::is_enum_v<T> | |
constexpr bool | has_flag (T test, T flag) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (char a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (unsigned char a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (short a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (unsigned short a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (int a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
FixedPoint< T, precision > | operator* (unsigned int a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
float | operator* (float a, FixedPoint< T, precision > b) |
template<typename T , unsigned int precision> | |
double | operator* (double a, FixedPoint< T, precision > b) |
ptr_shared | vformat (char const *format, va_list args) |
ptr_shared | format (char const *format,...) G_GNUC_PRINTF(1 |
Glib::ustring | format_size (std::size_t value) |
Glib::ustring | format_file_size (std::size_t value) |
double | read_number (gchar const *value, bool warning=true) |
bool | read_bool (gchar const *value, bool default_value) |
std::vector< gdouble > | read_vector (const gchar *value) |
std::string | format_number (double val, unsigned int precision=3) |
bool | equal (std::optional< std::string > const &a, char const *b) |
auto | to_opt (char const *s) |
auto | to_cstr (std::optional< std::string > const &s) |
bool | assign (std::optional< std::string > &a, char const *b) |
static std::byte * | round_up (std::byte *x, std::size_t m) |
ptr_shared | share_string (char const *string) |
ptr_shared | share_string (char const *string, std::size_t length) |
ptr_shared | share_unsafe (char const *string) |
ptr_shared | share_static_string (char const *string) |
template<typename F , auto = [] {}> | |
SPDocument * | cache_static_doc (F &&f) |
Wrapper for a static SPDocument to ensure it is destroyed early enough. | |
bool | is_current_theme_dark (Gtk::Widget &widget) |
std::tuple< std::uint32_t, std::uint32_t > | get_checkerboard_colors (Gtk::Widget &widget) |
TreeifyResult | treeify (int N, std::function< bool(int, int)> const &contains) |
Given a collection of nodes 0 ... N - 1 and a containment function, attempt to organise the nodes into a tree (or forest) such that contains(i, j) is true precisely when i is an ancestor of j. | |
void | trim (Glib::ustring &input, Glib::ustring const &also_remove="") |
Modifies a string in place, removing leading and trailing whitespace characters. | |
bool | are_near (Quantity const &a, Quantity const &b, double eps=Geom::EPSILON) |
Variables | |
template<auto Fp> | |
constexpr auto | make_c_callback = detail::CallbackConverter<Fp>::result |
Given a member function, make_c_callback produces a pure function with an extra void* argument at the end, into which an object pointer can be passed. | |
template<auto Fp> | |
auto | make_g_callback = reinterpret_cast<void(*)()>(make_c_callback<Fp>) |
A worse version of make_c_callback that also casts the result to a GCallback, losing even more type-safety. | |
constexpr bool | NO_WARNING = false |
const char | DEG [] = "°" |
Miscellaneous supporting code.
This namespace contains miscellaneous low-level code: an implementation of garbage-collected lists, tuples, generic pointer iterators and length unit handling.
typedef int Inkscape::Util::TokenType |
Definition at line 112 of file expression-evaluator.h.
anonymous enum |
TokenType.
Enumerator | |
---|---|
TOKEN_NUM | |
TOKEN_IDENTIFIER | |
TOKEN_ANY | |
TOKEN_END |
Definition at line 106 of file expression-evaluator.h.
|
constexpr |
|
inline |
Definition at line 140 of file units.h.
References Geom::are_near(), Inkscape::Util::Quantity::quantity, Inkscape::Util::Quantity::unit, and Inkscape::Util::Quantity::value().
|
inline |
Definition at line 31 of file optstr.h.
References equal(), and to_opt().
Referenced by SPFeBlend::set(), SPFeComposite::set(), SPFeDisplacementMap::set(), SPFeMergeNode::set(), and SPFilterPrimitive::set().
SPDocument * Inkscape::Util::cache_static_doc | ( | F && | f | ) |
Wrapper for a static SPDocument to ensure it is destroyed early enough.
SPDocuments cannot outlive FontFactory which in turn cannot outlive the end of main(). Because of these unusual lifetime requirements, managing a static SPDocument requires some extra work, which can be done by replacing this
static std::unique_ptr<SPDocument> doc = create_doc();
with this
SPDocument *doc = cache_static_doc([] { return create_doc(); });
Definition at line 27 of file static-doc.h.
Referenced by Inkscape::UI::Widget::MarkerComboBox::init_combo(), sp_gradient_load_from_svg(), and sp_marker_load_from_svg().
void Inkscape::Util::circle | ( | const Cairo::RefPtr< Cairo::Context > & | ctx, |
const Geom::Point & | center, | ||
double | radius | ||
) |
Definition at line 29 of file drawing-utils.cpp.
References Geom::Point::x(), and Geom::Point::y().
Referenced by draw_border().
auto Inkscape::Util::delete_with | ( | T * | p | ) |
Wrap a raw pointer in a std::unique_ptr with a custom function as the deleter.
Example:
auto x = delete_with<g_free>(g_strdup(...));
Definition at line 26 of file delete-with.h.
References delete_with().
Referenced by delete_with().
void Inkscape::Util::draw_border | ( | const Cairo::RefPtr< Cairo::Context > & | ctx, |
Geom::Rect | rect, | ||
double | radius, | ||
const Gdk::RGBA & | color, | ||
int | device_scale, | ||
bool | circular | ||
) |
Definition at line 34 of file drawing-utils.cpp.
References circle(), Geom::GenericRect< Coord >::from_xywh(), Geom::GenericRect< C >::height(), Geom::GenericRect< C >::max(), Geom::GenericRect< C >::midpoint(), Geom::GenericRect< C >::min(), Geom::GenericRect< C >::minExtent(), rounded_rectangle(), Geom::GenericRect< C >::shrinkBy(), and Geom::GenericRect< C >::width().
Referenced by draw_standard_border().
void Inkscape::Util::draw_standard_border | ( | const Cairo::RefPtr< Cairo::Context > & | ctx, |
Geom::Rect | rect, | ||
bool | dark_theme, | ||
double | radius, | ||
int | device_scale, | ||
bool | circular | ||
) |
Definition at line 70 of file drawing-utils.cpp.
References draw_border().
Referenced by Inkscape::UI::Widget::ColorSlider::draw_func(), and Inkscape::UI::Widget::ColorPlate::draw_plate().
const Glib::ustring Inkscape::Util::empty_string | ( | "" | ) |
|
inline |
|
constexpr |
|
inline |
Glib::ustring Inkscape::Util::format_file_size | ( | std::size_t | value | ) |
Definition at line 57 of file format_size.cpp.
References index, and Inkscape::size.
Referenced by Inkscape::UI::Widget::ImageProperties::update().
|
inline |
Definition at line 110 of file converters.h.
Referenced by Inkscape::UI::Widget::GradientWithStops::draw_func(), fmt_number(), Inkscape::UI::Dialog::ObjectsPanel::ObjectsPanel(), SPGaussianBlur::set_deviation(), and SVGLength::toString().
Glib::ustring Inkscape::Util::format_size | ( | std::size_t | value | ) |
Definition at line 10 of file format_size.cpp.
References format_size().
Referenced by format_size(), and image_crop().
std::tuple< std::uint32_t, std::uint32_t > Inkscape::Util::get_checkerboard_colors | ( | Gtk::Widget & | widget | ) |
Definition at line 20 of file theme-utils.cpp.
References is_current_theme_dark(), and Inkscape::Colors::Color::toARGB().
Referenced by Inkscape::UI::Widget::ColorSlider::draw_func().
|
constexpr |
Definition at line 128 of file enums.h.
References any_flag(), and test().
Referenced by InkscapeWindow::isFullscreen(), InkscapeWindow::isMaximised(), InkscapeWindow::isMinimised(), and SPDesktop::onWindowStateChanged().
bool Inkscape::Util::is_current_theme_dark | ( | Gtk::Widget & | widget | ) |
Definition at line 10 of file theme-utils.cpp.
References get_luminance().
Referenced by Inkscape::UI::Widget::ColorSlider::draw_func(), Inkscape::UI::Widget::ColorPlate::draw_plate(), and get_checkerboard_colors().
std::optional< Gdk::RGBA > Inkscape::Util::lookup_background_color | ( | Glib::RefPtr< Gtk::StyleContext > & | style | ) |
Definition at line 75 of file drawing-utils.cpp.
Referenced by Inkscape::UI::Widget::ColorSlider::draw_func().
std::optional< Gdk::RGBA > Inkscape::Util::lookup_foreground_color | ( | Glib::RefPtr< Gtk::StyleContext > & | style | ) |
Definition at line 83 of file drawing-utils.cpp.
Referenced by Inkscape::UI::Widget::ColorSlider::draw_func().
FixedPoint< T, precision > Inkscape::Util::operator* | ( | char | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 87 of file fixed_point.h.
double Inkscape::Util::operator* | ( | double | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 95 of file fixed_point.h.
float Inkscape::Util::operator* | ( | float | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 94 of file fixed_point.h.
FixedPoint< T, precision > Inkscape::Util::operator* | ( | int | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 91 of file fixed_point.h.
FixedPoint< T, precision > Inkscape::Util::operator* | ( | short | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 89 of file fixed_point.h.
FixedPoint< T, precision > Inkscape::Util::operator* | ( | unsigned char | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 88 of file fixed_point.h.
FixedPoint< T, precision > Inkscape::Util::operator* | ( | unsigned int | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 92 of file fixed_point.h.
FixedPoint< T, precision > Inkscape::Util::operator* | ( | unsigned short | a, |
FixedPoint< T, precision > | b | ||
) |
Definition at line 90 of file fixed_point.h.
|
inline |
Definition at line 61 of file converters.h.
Referenced by Inkscape::LivePathEffect::BoolParam::param_readSVGValue(), Inkscape::LivePathEffect::ToggleButtonParam::param_readSVGValue(), Inkscape::LivePathEffect::BoolParam::param_update_default(), Inkscape::LivePathEffect::ToggleButtonParam::param_update_default(), SPFeConvolveMatrix::set(), and SPGuide::set().
|
inline |
Definition at line 42 of file converters.h.
References end.
Referenced by SPFeColorMatrix::set(), SPFeFuncNode::set(), SPFeComposite::set(), SPFeConvolveMatrix::set(), SPFeDisplacementMap::set(), SPFeOffset::set(), and SPFeTurbulence::set().
|
inline |
Definition at line 84 of file converters.h.
References end.
Referenced by SPFeColorMatrix::set(), SPFeFuncNode::set(), and SPFeConvolveMatrix::set().
|
constexpr |
Returns a rounded down to the nearest multiple of b, assuming b >= 1.
Definition at line 82 of file mathfns.h.
References safemod().
Referenced by Inkscape::DrawingPattern::renderPattern(), and round_up().
|
inline |
Definition at line 41 of file mathfns.h.
References round_to_lower_multiple_plus().
Referenced by Inkscape::GridSnapper::get_snap_lines(), Inkscape::GridSnapper::getSnapLinesAxonom(), and round_to_lower_multiple_plus().
|
inline |
|
inline |
Definition at line 53 of file mathfns.h.
References round_to_upper_multiple_plus().
Referenced by Inkscape::GridSnapper::get_snap_lines(), Inkscape::GridSnapper::getSnapLinesAxonom(), and round_to_upper_multiple_plus().
|
static |
|
constexpr |
Returns a rounded up to the nearest multiple of b, assuming b >= 1.
Definition at line 89 of file mathfns.h.
References round_down().
Referenced by Inkscape::Util::Pool::allocate(), and Inkscape::DrawingPattern::renderPattern().
Geom::Rect Inkscape::Util::rounded_rectangle | ( | const Cairo::RefPtr< Cairo::Context > & | ctx, |
const Geom::Rect & | rect, | ||
double | radius | ||
) |
Definition at line 7 of file drawing-utils.cpp.
References Geom::GenericRect< C >::height(), height, Geom::GenericRect< C >::left(), Geom::Rect::shrunkBy(), Geom::GenericRect< C >::top(), Geom::GenericRect< C >::width(), and width.
Referenced by draw_border(), Inkscape::UI::Widget::draw_color_plate(), and Inkscape::UI::Widget::ColorSlider::draw_func().
T Inkscape::Util::safeclamp | ( | T | val, |
T | lo, | ||
T | hi | ||
) |
Just like std::clamp, except it doesn't deliberately crash if lo > hi due to rounding errors, so is safe to use with floating-point types.
(Note: compiles to branchless.)
Definition at line 99 of file mathfns.h.
Referenced by Inkscape::UI::Widget::Stores::snapshot_combine().
|
constexpr |
Returns a mod b, always in the range 0..b-1, assuming b >= 1.
Definition at line 74 of file mathfns.h.
Referenced by round_down().
|
inline |
Definition at line 95 of file share.h.
References share_unsafe().
ptr_shared Inkscape::Util::share_string | ( | char const * | string | ) |
Definition at line 20 of file share.cpp.
References share_string(), and share_unsafe().
Referenced by Inkscape::XML::SimpleDocument::createComment(), Inkscape::XML::SimpleDocument::createPI(), Inkscape::XML::SimpleDocument::createTextNode(), Inkscape::XML::SimpleDocument::createTextNode(), Inkscape::IO::Resource::get_path(), share_string(), share_string(), sp_repr_write_stream_root_element(), and vformat().
ptr_shared Inkscape::Util::share_string | ( | char const * | string, |
std::size_t | length | ||
) |
Definition at line 25 of file share.cpp.
References Inkscape::GC::ATOMIC, share_string(), and share_unsafe().
|
inline |
Definition at line 90 of file share.h.
Referenced by share_static_string(), share_string(), and share_string().
|
inline |
Definition at line 26 of file optstr.h.
Referenced by Inkscape::UI::Dialog::LivePathEffectEditor::clonetolpeitem(), Inkscape::LivePathEffect::LPECloneOriginal::doOnRemove(), SPFeComposite::write(), SPFeBlend::write(), SPFeDisplacementMap::write(), and SPFilterPrimitive::write().
|
inline |
Definition at line 21 of file optstr.h.
Referenced by assign(), Inkscape::UI::Dialog::LivePathEffectEditor::clonetolpeitem(), and Inkscape::LivePathEffect::LPECloneOriginal::doOnRemove().
TreeifyResult Inkscape::Util::treeify | ( | int | N, |
std::function< bool(int, int)> const & | contains | ||
) |
Given a collection of nodes 0 ... N - 1 and a containment function, attempt to organise the nodes into a tree (or forest) such that contains(i, j) is true precisely when i is an ancestor of j.
Definition at line 9 of file treeify.cpp.
References data, N, Inkscape::Util::TreeifyResult::preorder, and result.
Referenced by Inkscape::split_non_intersecting_paths().
|
inline |
Modifies a string in place, removing leading and trailing whitespace characters.
Optionally, it can remove other characters or ranges in addition to whitespace.
input | - a reference to a Glib::ustring which will be modified in place. |
also_remove | - optional range of characters to remove in addition to whitespace. NOTE: these characters are inserted into a regex range (square brackets) and therefore may need to be regex-escaped. It is the responsibility of the user to pass a string that will work correctly in a regex range. |
Definition at line 34 of file trim.h.
Referenced by Inkscape::UI::Dialog::SelectorsDialog::_addSelector(), Inkscape::UI::Dialog::SelectorsDialog::_getSelectorClasses(), Inkscape::UI::Dialog::SelectorsDialog::_removeClass(), Inkscape::UI::Dialog::SelectorsDialog::_removeFromSelector(), Inkscape::UI::Dialog::add_metadata(), Inkscape::UI::Dialog::InkscapePreferences::get_highlight_colors(), Inkscape::UI::Syntax::minify_svgd(), Inkscape::UI::Dialog::StyleDialog::parseStyle(), Inkscape::UI::Syntax::prettify_svgd(), Inkscape::UI::Dialog::StyleDialog::readStyleElement(), and Inkscape::UI::Dialog::XmlTree::stopNodeEditing().
|
inline |
|
constexpr |
Given a member function, make_c_callback produces a pure function with an extra void* argument at the end, into which an object pointer can be passed.
Calling the pure function then invokes the original function on this object. In other words
make_c_callback<&X::f>(..., &x)
is equivalent to
x->f(...);
This is useful for passing member functions as callbacks to C code.
Note: Actually they're not completely equivalent in that some extra forwarding might go on. Specifically, if your member function takes a T (by value) then the resulting callback will also take a T by value (because make_c_callback always exactly preserves argument types). That means your T will have to be moved from the wrapping function's argument into the wrapped function's argument. This won't make much difference if you only use this with C-compatible types.
Definition at line 58 of file callback-converter.h.
|
inline |
A worse version of make_c_callback that also casts the result to a GCallback, losing even more type-safety.
Commonly needed to interface with Glib and GTK. (See make_c_callback for more details.)
Definition at line 65 of file callback-converter.h.
|
constexpr |
Definition at line 29 of file converters.h.
Referenced by SPFeColorMatrix::set().