/*
7 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
8 * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
10 * Copyright (C) 2011-2012 Authors
11 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
30 0.21, 0.72, 0.072, 0.0, 0.0,
31 0.21, 0.72, 0.072, 0.0, 0.0,
32 0.21, 0.72, 0.072, 0.0, 0.0,
33 0.0 , 0.0 , 0.0 , 1.0, 0.0
48 auto ret = std::thread::hardware_concurrency();
49 return ret == 0 ? 4 : ret;
53 : _canvas_item_drawing(canvas_item_drawing)
183 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 18, 0)
282 std::vector<DrawingItem*> to_cache;
286 to_cache.emplace_back(rec.item);
287 used += rec.cache_size;
289 std::sort(to_cache.begin(), to_cache.end());
293 std::vector<DrawingItem*> to_uncache;
295 to_cache.begin(), to_cache.end(),
296 std::back_inserter(to_uncache));
297 for (
auto item : to_uncache) {
298 item->_setCached(
false);
302 for (
auto item : to_cache) {
303 item->_setCached(
true);
310 std::vector<DrawingItem*> to_uncache;
312 for (
auto item : to_uncache) {
313 item->_setCached(
false,
true);
322 _clip_outline_color = prefs->getIntLimited(
"/options/wireframecolors/clips", 0x00ff00ff, 0, 0xffffffff);
323 _mask_outline_color = prefs->getIntLimited(
"/options/wireframecolors/masks", 0x0000ffff, 0, 0xffffffff);
324 _image_outline_color = prefs->getIntLimited(
"/options/wireframecolors/images", 0xff0000ff, 0, 0xffffffff);
327 _blur_quality = prefs->getInt (
"/options/blurquality/value", 0);
328 _use_dithering = prefs->getBool (
"/options/dithering/value",
true);
335 _cache_budget = (
size_t{1} << 20) * prefs->getIntLimited(
"/options/renderingcache/size", 64, 0, 4096);
346 std::unordered_map<std::string, std::function<void (
Preferences::Entry const &)>> actions;
349 actions.emplace(
"/options/wireframecolors/clips", [
this] (
auto &entry) {
setClipOutlineColor (entry.getIntLimited(0x00ff00ff, 0, 0xffffffff)); });
350 actions.emplace(
"/options/wireframecolors/masks", [
this] (
auto &entry) {
setMaskOutlineColor (entry.getIntLimited(0x0000ffff, 0, 0xffffffff)); });
351 actions.emplace(
"/options/wireframecolors/images", [
this] (
auto &entry) {
setImageOutlineColor(entry.getIntLimited(0xff0000ff, 0, 0xffffffff)); });
352 actions.emplace(
"/options/rendering/imageinoutlinemode", [
this] (
auto &entry) {
setImageOutlineMode(entry.getBool(
false)); });
354 actions.emplace(
"/options/blurquality/value", [
this] (
auto &entry) {
setBlurQuality(entry.getInt(0)); });
355 actions.emplace(
"/options/dithering/value", [
this] (
auto &entry) {
setDithering(entry.getBool(
true)); });
356 actions.emplace(
"/options/cursortolerance/value", [
this] (
auto &entry) {
setCursorTolerance(entry.getDouble(1.0)); });
357 actions.emplace(
"/options/selection/zeroopacity", [
this] (
auto &entry) {
setSelectZeroOpacity(entry.getBool(
false)); });
358 actions.emplace(
"/options/renderingcache/size", [
this] (
auto &entry) {
setCacheBudget((1 << 20) * entry.getIntLimited(64, 0, 4096)); });
359 actions.emplace(
"/options/threading/numthreads", [
this](
auto &entry) {
364 auto it = actions.find(entry.getPath());
365 if (it == actions.end())
return;
376 auto surface = Cairo::ImageSurface::create(Cairo::Surface::Format::ARGB32, area.
width(), area.
height());
388 if (!area || area->hasZeroArea()) {
393 static constexpr auto width = 200.0;
394 static constexpr auto height = 200.0;
397 auto offset = area->min() * affine;
400 auto mask = Cairo::ImageSurface::create(Cairo::Surface::Format::A8,
width,
height);
402 dc_mask.scale(affine);
404 dc_mask.setFillRule(evenodd ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
407 dc_mask.setSource(1, 1, 1, 1);
408 dc_mask.setOperator(CAIRO_OPERATOR_SOURCE);
412 auto image = Cairo::ImageSurface::create(Cairo::Surface::Format::ARGB32,
width,
height);
415 render(dc, area->roundOutwards());
Colors::Color ink_cairo_surface_average_color(cairo_surface_t *surface, cairo_surface_t *mask)
Get the average color from the given surface.
Cairo integration helpers.
Cairo::RefPtr< Cairo::ImageSurface > surface
3x3 matrix representing an affine transformation.
Axis-aligned generic rectangle that can be empty.
Axis aligned, non-empty, generic rectangle.
C height() const
Get the vertical extent of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
OptRect boundsExact() const
Two-dimensional point that doubles as a vector.
Minimal wrapper over Cairo.
void path(Geom::PathVector const &pv)
SVG drawing item for display.
@ RENDER_VISIBLE_HAIRLINES
Antialiasing _antialias
antialiasing level (default is Good)
unsigned render(DrawingContext &dc, RenderContext &rc, Geom::IntRect const &area, unsigned flags=0, DrawingItem const *stop_at=nullptr) const
Rasterize items.
DrawingItem * pick(Geom::Point const &p, double delta, unsigned flags=0)
Get the item under the specified point.
void setOpacity(float opacity)
void _markForUpdate(unsigned state, bool propagate)
Marks the item as needing a recomputation of internal data.
void update(Geom::IntRect const &area=Geom::IntRect::infinite(), UpdateContext const &ctx=UpdateContext(), unsigned flags=STATE_ALL, unsigned reset=0)
Update derived data before operations.
Geom::Affine _ctm
Total transform from item coords to display coords.
void _markForRendering()
Marks the current visual bounding box of the item for redrawing.
void _pickItemsForCaching()
uint32_t _image_outline_color
void setGrayscaleMatrix(double[20])
uint32_t _clip_outline_color
CanvasItemDrawing * _canvas_item_drawing
void setOpacity(double opacity=1.0)
void setSelectZeroOpacity(bool select_zero_opacity)
uint32_t _mask_outline_color
size_t _cache_budget
Maximum allowed size of cache.
CacheList _candidate_items
void setImageOutlineColor(uint32_t)
void setRenderMode(RenderMode)
void setRoot(DrawingItem *root)
std::optional< Geom::PathVector > _clip
void setMaskOutlineColor(uint32_t)
void setClip(std::optional< Geom::PathVector > &&clip)
void setClipOutlineColor(uint32_t)
void setColorMode(ColorMode)
Filters::FilterColorMatrix::ColorMatrixMatrix _grayscale_matrix
Colors::Color averageColor(Geom::IntRect const &area) const
void update(Geom::IntRect const &area=Geom::IntRect::infinite(), Geom::Affine const &affine=Geom::identity(), unsigned flags=DrawingItem::STATE_ALL, unsigned reset=0)
DrawingItem * pick(Geom::Point const &p, double delta, unsigned flags)
void render(DrawingContext &dc, Geom::IntRect const &area, unsigned flags=0) const
void setCacheLimit(Geom::OptIntRect const &rect)
void setCursorTolerance(double tol)
std::unique_ptr< Preferences::PreferencesObserver > _pref_tracker
void setImageOutlineMode(bool)
Drawing(CanvasItemDrawing *drawing=nullptr)
void setFilterQuality(int)
bool _select_zero_opacity
std::optional< Antialiasing > _antialiasing_override
void setAntialiasingOverride(std::optional< Antialiasing > antialiasing_override)
Geom::OptIntRect _cache_limit
bool _image_outline_mode
Always draw images as images, even in outline mode.
void setOutlineOverlay(bool)
void setCacheBudget(size_t bytes)
std::set< DrawingItem * > _cached_items
Data type representing a typeless value of a preference.
static std::unique_ptr< PreferencesObserver > create(Glib::ustring path, std::function< void(const Preferences::Entry &new_value)> callback)
static Preferences * get()
Access the singleton Preferences object.
Cairo drawing context with Inkscape extensions.
std::unique_ptr< Magick::Image > image
Helper class to stream background task notifications as a series of messages.
static auto rendermode_to_renderflags(RenderMode mode)
static auto default_numthreads()
void set_num_dispatch_threads(int num_dispatch_threads)
static auto constexpr grayscale_matrix
void apply_antialias(DrawingContext &dc, Antialiasing antialias)
Apply antialias setting to Cairo.
static T clip(T const &v, T const &a, T const &b)
TODO: insert short description here.
std::uint32_t outline_color