23#include <giomm/error.h>
24#include <glib/gstdio.h>
25#include <glibmm/i18n.h>
50#define DEBUG_MESSAGE(key, ...)\
52 g_message( __VA_ARGS__ );\
56#define DEBUG_MESSAGE(key, ...)
63#define MAGIC_EPSILON 1e-9
64#define MAGIC_EPSILON_TOO 1e-18
73#define DEBUG_MESSAGE_SCISLAC(key, ...) \
75 Inkscape::Preferences *prefs = Inkscape::Preferences::get();\
76 bool dump = prefs->getBool("/options/scislac/" #key);\
77 bool dumpD = prefs->getBool("/options/scislac/" #key "D");\
78 bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2");\
79 dumpD &&= ( (update_in_progress == 0) || dumpD2 );\
82 g_message( __VA_ARGS__ );\
87 GtkWidget *dialog = gtk_message_dialog_new(NULL,\
88 GTK_DIALOG_DESTROY_WITH_PARENT, \
93 g_signal_connect_swapped(dialog, "response",\
94 G_CALLBACK(gtk_widget_destroy), \
96 gtk_widget_set_visible(dialog, true);\
100#define DEBUG_MESSAGE_SCISLAC(key, ...)
110 this->
sx = this->
sy = 1.0;
111 this->
ox = this->
oy = 0.0;
116 this->
href =
nullptr;
146 this->
href =
nullptr;
171 if (!this->
x.
read(value)) {
180 if (!this->
y.
read(value)) {
249 if (
getRepr()->attribute(
"inkscape:svg-dpi")) {
254 getRepr()->attribute(
"sodipodi:absref"),
275 pixbuf = std::shared_ptr<Inkscape::Pixbuf>(pb);
369 for (
auto &v :
views) {
431 int rs = pb.rowstride();
433 double vx = this->
ox;
434 double vy = this->
oy;
440 ctx->image_R8G8B8A8_N(px,
w, h,
rs, t, this->
style);
468 g_warning(
"Attempting to call strncmp() with a null pointer.");
469 href_desc =
g_strdup(
"(null_pointer)");
487 this->
getRepr()->attribute(
"sodipodi:absref"),
520 if (filename !=
nullptr) {
528 if (url.hasScheme(
"file")) {
529 auto native = url.toNativeFilename();
535 }
catch (
const Gio::Error &e) {
541 if (
inkpb !=
nullptr) {
548 if (filename !=
nullptr) {
550 if ( base !=
nullptr &&
href !=
nullptr ) {
551 g_warning (
"<image xlink:href=\"%s\"> did not resolve to a valid image file (base dir is %s), now trying sodipodi:absref=\"%s\"",
href, base,
absref);
553 g_warning (
"xlink:href did not resolve to a valid image file, now trying sodipodi:absref=\"%s\"",
absref);
557 if (
inkpb !=
nullptr) {
565<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}">
567 <symbol id="nope" style="fill:none;stroke:#ffffff;stroke-width:3" viewBox="0 0 10 10" preserveAspectRatio="{aspect}">
568 <circle cx="0" cy="0" r="10" style="fill:#a40000;stroke:#cc0000" />
569 <line x1="0" x2="0" y1="-5" y2="5" transform="rotate(45)" />
570 <line x1="0" x2="0" y1="-5" y2="5" transform="rotate(-45)" />
573 <rect width="100%" height="100%" style="fill:white;stroke:#cc0000;stroke-width:6%" />
574 <use xlink:href="#nope" width="30%" height="30%" x="50%" y="50%" />
586 double dpi = prefs->
getDouble(
"/dialogs/import/defaultxdpi/value", 96.0);
592 copy.replace(copy.find(
"{width}"), std::string(
"{width}").size(), std::to_string(
width));
593 copy.replace(copy.find(
"{height}"), std::string(
"{height}").size(), std::to_string(
height));
596 copy.replace(copy.find(
"{aspect}"), std::string(
"{aspect}").size(),
620 for (
auto &v :
image->views) {
688 pos = pos *
ret.inverse();
698 if ((
image->height.computed < MAGIC_EPSILON_TOO) || (
image->width.computed < MAGIC_EPSILON_TOO) || (
image->getClipObject())) {
702 if (rect->isFinite()) {
703 image->curve.emplace(*rect,
true);
718 bool free_data =
false;
721 guchar *
data =
nullptr;
723 std::string data_mimetype;
727 if (
data ==
nullptr) {
729 data_mimetype =
"image/png";
730 gdk_pixbuf_save_to_buffer(pb->
getPixbufRaw(),
reinterpret_cast<gchar**
>(&
data), &
len,
"png",
nullptr,
nullptr);
736 gsize needed_size =
len * 4 / 3 +
len * 4 / (3 * 72) + 7;
737 needed_size += 5 + 8 + data_mimetype.size();
739 gchar *buffer = (gchar *) g_malloc(needed_size);
740 gchar *buf_work = buffer;
741 buf_work += g_sprintf(buffer,
"data:%s;base64,", data_mimetype.c_str());
746 written += g_base64_encode_step(
data,
len, TRUE, buf_work, &state, &save);
747 written += g_base64_encode_close(TRUE, buf_work + written, &state, &save);
748 buf_work[written] = 0;
756 if (free_data) g_free(
data);
761 if (!g_file_test(fn.c_str(), G_FILE_TEST_EXISTS)) {
765 int val = g_stat(fn.c_str(), &stdir);
766 if (val == 0 && stdir.st_mode & S_IFDIR){
772 gchar *
data =
nullptr;
774 GError *error =
nullptr;
776 if (g_file_get_contents(fn.c_str(), &
data, &
len, &error)) {
778 if (error !=
nullptr) {
779 std::cerr <<
"Pixbuf::create_from_file: " << error->message << std::endl;
780 std::cerr <<
" (" << fn <<
")" << std::endl;
784 std::string data_mimetype =
"image/svg+xml";
789 gsize needed_size =
len * 4 / 3 +
len * 4 / (3 * 72) + 7;
790 needed_size += 5 + 8 + data_mimetype.size();
792 gchar *buffer = (gchar *) g_malloc(needed_size);
793 gchar *buf_work = buffer;
794 buf_work += g_sprintf(buffer,
"data:%s;base64,", data_mimetype.c_str());
799 written += g_base64_encode_step(
reinterpret_cast<guchar *
>(
data),
len, TRUE, buf_work, &state, &save);
800 written += g_base64_encode_close(TRUE, buf_work + written, &state, &save);
801 buf_work[written] = 0;
819 memset(&st, 0,
sizeof(st));
826 if ( st.st_mtime !=
pixbuf->modificationTime() ) {
871 if (pb->width() <= 0 || pb->height() <= 0)
Lookup dictionary for attributes/properties.
Cairo integration helpers.
3x3 matrix representing an affine transformation.
Affine inverse() const
Compute the inverse matrix.
Axis aligned, non-empty, generic rectangle.
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
Axis-aligned rectangle that can be empty.
Two-dimensional point that doubles as a vector.
Axis aligned, non-empty rectangle.
IntRect roundOutwards() const
Return the smallest integer rectangle which contains this one.
std::shared_ptr< Space::CMS > getSpace(std::string const &name) const
Get the specific color space from the list of available spaces.
void setClipbox(Geom::Rect const &box)
void setScale(double sx, double sy)
void setPixbuf(std::shared_ptr< Inkscape::Pixbuf const > pb)
void setOrigin(Geom::Point const &o)
void setStyle(SPStyle const *style, SPStyle const *context_style=nullptr) override
Process information related to the new style.
SVG drawing item for display.
Class to hold image data for raster images.
guchar const * getMimeData(gsize &len, std::string &mimetype) const
Retrieves the original compressed data for the surface, if any.
GdkPixbuf * getPixbufRaw(bool convert_format=true)
Converts the pixbuf to GdkPixbuf pixel format.
void ensurePixelFormat(PixelFormat fmt)
Convert the internal pixel format between CAIRO and GDK formats.
static Pixbuf * create_from_file(std::string const &fn, double svgddpi=0)
static Pixbuf * create_from_buffer(std::string const &, double svgddpi=0, std::string const &fn="")
static Pixbuf * create_from_data_uri(gchar const *uri, double svgdpi=0)
Preference storage class.
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
static Preferences * get()
Access the singleton Preferences object.
Storing of snapping preferences.
bool isTargetSnappable(Inkscape::SnapTargetType const target) const
Represents an URI as per RFC 2396.
static URI from_href_and_basedir(char const *href, char const *basedir)
Convenience function for the common use case given a xlink:href attribute and a local directory as th...
Interface for refcounted XML nodes.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
Wrapper around a Geom::PathVector object.
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.
Typed SVG document implementation.
bool removeResource(char const *key, SPObject *object)
char const * getDocumentBase() const
bool addResource(char const *key, SPObject *object)
Inkscape::Colors::DocumentCMS & getDocumentCMS()
static Inkscape::Pixbuf * readImage(gchar const *href, gchar const *absref, gchar const *base, double svgdpi=0)
void set(SPAttr key, char const *value) override
Inkscape::DrawingItem * show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) override
Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type) const override
static Inkscape::Pixbuf * getBrokenImage(double width, double height)
Load a standard broken image svg, used if we fail to load pixbufs from the href.
const char * displayName() const override
The item's type name as a translated human string.
std::shared_ptr< Inkscape::Pixbuf const > pixbuf
bool cropToArea(Geom::Rect area)
Crop the image (remove pixels) based on the area rectangle and translate image to componsate for move...
void print(SPPrintContext *ctx) override
void update(SPCtx *ctx, unsigned int flags) override
const char * typeName() const override
The item's type name, not node tag name.
void modified(unsigned int flags) override
char * description() const override
std::optional< SPCurve > curve
Geom::Affine set_transform(Geom::Affine const &transform) override
void snappoints(std::vector< Inkscape::SnapCandidatePoint > &p, Inkscape::SnapPreferences const *snapprefs) const override
Inkscape::URI getURI() const
Return this image's href as a URI object.
SPCurve const * get_curve() const
Return a borrowed pointer to curve (if any exists) or NULL if there is no curve.
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void build(SPDocument *document, Inkscape::XML::Node *repr) override
void refresh_if_outdated()
Base class for visual SVG elements.
Geom::Affine i2dt_affine() const
Returns the transformation from item to desktop coords.
void update(SPCtx *ctx, unsigned int flags) override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void set(SPAttr key, char const *value) override
Geom::Affine i2doc_affine() const
Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
void build(SPDocument *document, Inkscape::XML::Node *repr) override
std::vector< SPItemView > views
SPClipPath * getClipObject() const
Inkscape::XML::Node * repr
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
void set_preserveAspectRatio(const gchar *value)
void write_preserveAspectRatio(Inkscape::XML::Node *repr) const
Write preserveAspectRatio attribute to XML, if set.
SPItemCtx get_rctx(const SPItemCtx *ictx, double scale_none=1.0)
bool read(char const *str)
void unset(Unit u=NONE, float v=0, float c=0)
Access operating system wide information about color management.
vector< vpsc::Rectangle * > rs
Bitmap image belonging to an SVG drawing.
std::unique_ptr< Magick::Image > image
Affine identity()
Create an identity matrix.
void setHrefAttribute(XML::Node &node, Util::const_char_ptr value)
If the 'href' attribute already exists for the given node, then set a new value for it.
std::pair< char const *, char const * > getHrefAttribute(XML::Node const &node)
Get the 'href' or 'xlink:href' (fallback) attribute from an XML node.
static cairo_user_data_key_t key
Singleton class to access the preferences file in a convenient way.
char * xml_quote_strdup(char const *src)
TODO: insert short description here.
Some utility classes to store various kinds of snap candidates.
static void sp_image_set_curve(SPImage *image)
static void sp_image_update_arenaitem(SPImage *img, Inkscape::DrawingImage *ai)
void sp_embed_image(Inkscape::XML::Node *image_node, Inkscape::Pixbuf *pb)
static void sp_image_update_canvas_image(SPImage *image)
static std::string broken_image_svg
void sp_embed_svg(Inkscape::XML::Node *image_node, std::string const &fn)
SVG <image> implementation.
void sp_embed_image(Inkscape::XML::Node *imgnode, Inkscape::Pixbuf *pb)
Interface for XML documents.
Contains transformations to document/viewport and the viewport size.
Geom::Rect viewport
Viewport size.