20#include <glibmm/i18n.h>
21#include <gtkmm/notebook.h>
54 container.signal_realize().connect([=,
this]() {
58 container.signal_unrealize().connect([
this]() {
141 if (!dirname.empty()) {
142 path = Glib::build_filename(dirname, filename);
154 std::string test_filename = path + extension;
156 filename = test_filename;
159 for (
int i = 1; i <= 100; i++) {
160 test_filename = path +
"_copy_" + std::to_string(i) + extension;
162 filename = test_filename;
183 std::string dirname = Glib::path_get_dirname(path);
185 if (dirname.empty() || !
Inkscape::IO::file_test(dirname.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
186 if (g_mkdir_with_parents(dirname.c_str(), S_IRWXU) != 0) {
188 Glib::ustring error = g_strdup_printf(_(
"Directory <b>%s</b> does not exist and can't be created.\n"), safeDir.c_str());
205 float const &dpi,
guint32 bg_color, Glib::ustring
const &filename,
bool overwrite,
206 unsigned (*callback)(
float,
void *),
void *
data,
219 if (filename.empty()) {
225 if (!extension || !extension->
is_raster()) {
232 if (pHYs < 0.01) pHYs = dpi;
234 bool use_interlacing = extension->
get_param_bool(
"png_interlacing",
false);
235 int antialiasing = extension->
get_param_int(
"png_antialias", 2);
239 int bit_depth = pow(2, (val & 0x0F));
240 int color_type = (val & 0xF0) >> 4;
242 std::string path =
absolutizePath(doc, Glib::filename_from_utf8(filename));
249 auto fn = Glib::path_get_basename(path);
252 auto png_filename = path;
255 int tempfd_out = Glib::file_open_tmp(png_filename,
"ink_ext_");
260 std::vector<SPItem const *> selected;
268 bg_color, callback,
data,
true, selected, use_interlacing, color_type, bit_depth, zlib, antialiasing);
274 Glib::ustring error = g_strdup_printf(_(
"Could not export to filename <b>%s</b>.\n"), safeFile.c_str());
282 extension->
export_raster(doc, png_filename, path.c_str(),
false);
296 unlink(png_filename.c_str());
302 Glib::ustring
const &filename,
315 Glib::ustring
const &filename,
316 bool overwrite,
const std::vector<SPItem const *> &
items,
SPPage const *
page)
318 std::vector<SPPage const *>
pages;
332 Glib::ustring
const &filename,
333 bool overwrite,
const std::vector<SPItem const *> &
items,
const std::vector<SPPage const *> &pages)
339 if (filename.empty()) {
345 if (!extension || extension->
is_raster()) {
351 std::string path =
absolutizePath(copy_doc, Glib::filename_from_utf8(filename));
360 std::vector<SPItem const *> objects =
items;
361 std::set<std::string> obj_ids;
362 std::set<std::string> page_ids;
364 if (
auto _id =
page->getId()) {
365 page_ids.insert(std::string(_id));
368 auto page_items =
page->getOverlappingItems(
true,
true);
372 objects.insert(objects.end(), page_items.begin(), page_items.end());
374 for (
auto &
item : page_items) {
384 std::vector<SPWeakPtr<SPPage>> copy_pages;
385 copy_pages.reserve(pm.getPageCount());
386 for (
auto *
page : pm.getPages()) {
387 copy_pages.emplace_back(
page);
391 for (
auto &
page : copy_pages) {
393 auto _id =
page->getId();
394 if (_id && page_ids.find(_id) == page_ids.end()) {
401 if (!objects.empty() || !
pages.empty()) {
402 std::vector<SPObject *> objects_to_export;
404 for (
auto &
object : objects) {
405 auto _id =
object->getId();
406 if (!_id || (!obj_ids.empty() && obj_ids.find(_id) == obj_ids.end())) {
413 Glib::ustring error = g_strdup_printf(_(
"Could not export to filename <b>%s</b>. (missing object)\n"), safeFile.c_str());
422 object_set.
add(obj,
true);
423 objects_to_export.push_back(obj);
437 extension->
save(copy_doc, path.c_str());
440 Glib::ustring error = g_strdup_printf(_(
"Could not export to filename <b>%s</b>.\n"), safeFile.c_str());
455 Glib::ustring
id = _(
"bitmap");
456 if (obj && obj->
getId()) {
459 return prependDirectory(Glib::filename_from_utf8(
id), file_entry_text, doc);
485 if (Glib::path_is_absolute(
name) ||
name.empty())
488 if (Glib::path_get_basename(
name) !=
name) {
492 std::string directory;
495 directory = Glib::path_get_dirname(
orig);
498 if (directory.empty() || directory ==
".") {
502 directory = Glib::path_get_dirname(docFilename);
505 if (directory.empty() || directory ==
".") {
509 return Glib::build_filename(directory,
name);
513 const std::string &extension)
515 std::string filename;
520 filename =
prependDirectory(Glib::filename_from_utf8(_(
"bitmap")), filename_entry_text, doc);
521 filename = filename + extension;
528 object->setAttribute(
"inkscape:export-bgcolor", color.
toString());
534 if (
auto c = Inkscape::Colors::Color::parse(object->
getAttribute(
"inkscape:export-bgcolor"))) {
Axis aligned, non-empty rectangle.
bool hasZeroArea(Coord eps=EPSILON) const
Check whether the rectangle has zero area up to specified tolerance.
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
Generic failure for an undescribed reason.
void export_raster(const SPDocument *doc, std::string png_filename, gchar const *filename, bool detachbase)
Save a rendered png as a raster output.
void save(SPDocument *doc, gchar const *filename, bool detachbase=false)
Save a document as a file.
MessageId flash(MessageType type, char const *message)
Temporarily pushes a message onto the stack.
MessageId flashF(MessageType type, char const *format,...) G_GNUC_PRINTF(3
temporarily pushes a message onto the stack using printf-like formatting
bool add(SPObject *object, bool nosignal=false)
Add an SPObject to the set of selected objects.
bool fitCanvas(bool with_margins, bool skip_undo=false)
void disablePages()
Disables multi page supply by removing all the page objects.
SPPage * getFirstPage() const
void enablePages()
Enables multi page support by turning the document viewBox into the first page.
void deletePage(SPPage *page, bool contents=false)
Delete the given page.
static Preferences * get()
Access the singleton Preferences object.
The set of selected SPObjects for a given document and layer model.
void setApp(InkscapeApplication *app)
void setDesktop(SPDesktop *desktop)
void selectionModified(Inkscape::Selection *selection, guint flags)
void selectionChanged(Inkscape::Selection *selection)
void setDocument(SPDocument *document)
DialogBase is the base class for the dialog system.
SPDocument * getDocument() const
InkscapeApplication * getApp() const
SPDesktop * getDesktop() const
static bool exportRaster(Geom::Rect const &area, unsigned long int const &width, unsigned long int const &height, float const &dpi, guint32 bg_color, Glib::ustring const &filename, bool overwrite, unsigned(*callback)(float, void *), void *data, Inkscape::Extension::Output *extension, std::vector< SPItem const * > *items=nullptr)
Export to raster graphics.
SingleExport & single_image
static bool exportVector(Inkscape::Extension::Output *extension, SPDocument *doc, Glib::ustring const &filename, bool overwrite, Geom::Rect const &area)
Gtk::Notebook & export_notebook
void selectionModified(Inkscape::Selection *selection, unsigned flags) override
void selectionChanged(Inkscape::Selection *selection) override
void documentReplaced() override
static std::string prependDirectory(const std::string &name, const std::string &orig, SPDocument *doc=nullptr)
Adds the full directory path to the final part of a file name.
static bool unConflictFilename(SPDocument *doc, std::string &filename, std::string const extension)
sigc::scoped_connection notebook_signal
std::map< notebook_page, int > pages
static std::string absolutizePath(SPDocument *doc, const std::string &filename)
Convert path to absolute path.
Inkscape::Preferences * prefs
void setDefaultNotebookPage()
void onNotebookPageSwitch(Widget *page, unsigned page_number)
static std::string filePathFromObject(SPDocument *doc, SPObject *obj, const std::string &file_entry_text)
static bool checkOrCreateDirectory(std::string const &filename)
Checks if the directory exists and if not, tries to create the directory and if failed,...
void desktopReplaced() override
Called when the desktop has certainly changed.
BatchExport & batch_export
static std::string defaultFilename(SPDocument *doc, const std::string &filename_entry_text, const std::string &extension)
void selectionChanged(Inkscape::Selection *selection)
void setDesktop(SPDesktop *desktop)
void selectionModified(Inkscape::Selection *selection, guint flags)
void setDocument(SPDocument *document)
void setApp(InkscapeApplication *app)
To do: update description of desktop.
SPDocument * getDocument() const
Inkscape::MessageStack * messageStack() const
Inkscape::Selection * getSelection() const
Typed SVG document implementation.
SPRoot * getRoot()
Returns our SPRoot.
char const * getDocumentFilename() const
SPObject * getObjectById(std::string const &id) const
void fitToRect(Geom::Rect const &rect, bool with_margins=false)
Given a Geom::Rect that may, for example, correspond to the bbox of an object, this function fits the...
unsigned int vacuumDocument()
Remove unused definitions etc.
Inkscape::PageManager & getPageManager()
int ensureUpToDate(unsigned int object_modified_tag=0)
Repeatedly works on getting the document updated, since sometimes it takes more than one pass to get ...
SPObject is an abstract base class of all of the document nodes at the SVG document level.
char const * getId() const
Returns the objects current ID string.
char const * getAttribute(char const *name) const
void cropToObjects(std::vector< SPObject * > except_objects)
Removes objects which are not related to given list of objects.
void getIds(std::set< std::string > &ret) const
Accumulate this id and all it's descendants ids.
Editable view implementation.
void sp_ui_error_dialog(char const *message)
bool sp_ui_overwrite_file(std::string const &filename)
If necessary, ask the user if a file may be overwritten.
std::string homedir_path()
Glib::ustring sanitizeString(char const *str)
bool file_test(char const *utf8name, GFileTest test)
Inkscape::Colors::Color get_export_bg_color(SPObject *object, Inkscape::Colors::Color const &default_color)
void set_export_bg_color(SPObject *object, Inkscape::Colors::Color const &color)
W & get_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id)
W & get_derived_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id, Args &&... args)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
static void append(std::vector< T > &target, std::vector< T > &&source)
ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, unsigned int(*status)(float, void *), void *data, bool force_overwrite, const std::vector< SPItem const * > &items_only, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing)
Export the given document as a Portable Network Graphics (PNG) file.
Inkscape::IO::Resource - simple resource API.
static Inkscape::Colors::Color default_color(SPItem *item)
Find default color based on colors in existing fill.
SPRoot: SVG <svg> implementation.
Glib::RefPtr< Gtk::Builder > builder