diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-02-15 18:31:38 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-02-15 18:31:38 +0000 |
| commit | c7f7afed83fc8453859ec98162537c7dc395568f (patch) | |
| tree | ed0592d8973b5c0c09cfc757263a934772cb3c2a /src | |
| parent | first steps (diff) | |
| parent | Adjust timeout for snap tool tips to 4 seconds (diff) | |
| download | inkscape-c7f7afed83fc8453859ec98162537c7dc395568f.tar.gz inkscape-c7f7afed83fc8453859ec98162537c7dc395568f.zip | |
update to trunk
(bzr r13645.1.11)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop-events.cpp | 41 | ||||
| -rw-r--r-- | src/desktop-events.h | 2 | ||||
| -rw-r--r-- | src/device-manager.cpp | 245 | ||||
| -rw-r--r-- | src/display/snap-indicator.cpp | 2 | ||||
| -rw-r--r-- | src/document.cpp | 38 | ||||
| -rw-r--r-- | src/extension/internal/emf-inout.cpp | 45 | ||||
| -rw-r--r-- | src/extension/internal/emf-print.cpp | 2 | ||||
| -rw-r--r-- | src/extension/internal/pdfinput/pdf-parser.cpp | 20 | ||||
| -rw-r--r-- | src/extension/internal/wmf-inout.cpp | 32 | ||||
| -rw-r--r-- | src/sp-root.cpp | 3 | ||||
| -rw-r--r-- | src/viewbox.cpp | 14 | ||||
| -rw-r--r-- | src/viewbox.h | 4 |
12 files changed, 234 insertions, 214 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 5dbe0f8dc..e80e5f6c1 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -17,13 +17,19 @@ #endif #include <map> #include <string> + #include "ui/dialog/guides.h" +#include "desktop-events.h" + +#if WITH_GTKMM_3_0 +# include <gdkmm/devicemanager.h> +#endif + #include <2geom/line.h> #include <2geom/angle.h> #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-events.h" #include "ui/dialog-events.h" #include "display/canvas-axonomgrid.h" @@ -611,36 +617,35 @@ static GdkInputSource lastType = GDK_SOURCE_MOUSE; static void init_extended() { - std::string avoidName = "pad"; + Glib::ustring avoidName("pad"); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); #if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devices = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<const Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<const Gdk::Device> > devices = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devices = gdk_devices_list(); + std::vector< Glib::RefPtr<const Gdk::Device> > devices = display->list_devices(); #endif - if ( devices ) { - for ( GList* curr = devices; curr; curr = g_list_next(curr) ) { - GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data); - gchar const *devName = gdk_device_get_name(dev); - GdkInputSource devSrc = gdk_device_get_source(dev); + if ( !devices.empty() ) { + for ( std::vector< Glib::RefPtr<const Gdk::Device> >::const_iterator dev = devices.begin(); dev != devices.end(); ++dev ) { + Glib::ustring const devName = (*dev)->get_name(); + Gdk::InputSource devSrc = (*dev)->get_source(); - if ( devName + if ( !devName.empty() && (avoidName != devName) - && (devSrc != GDK_SOURCE_MOUSE) ) { + && (devSrc != Gdk::SOURCE_MOUSE) ) { // g_message("Adding '%s' as [%d]", devName, devSrc); // Set the initial tool for the device switch ( devSrc ) { - case GDK_SOURCE_PEN: + case Gdk::SOURCE_PEN: toolToUse[devName] = TOOLS_CALLIGRAPHIC; break; - case GDK_SOURCE_ERASER: + case Gdk::SOURCE_ERASER: toolToUse[devName] = TOOLS_ERASER; break; - case GDK_SOURCE_CURSOR: + case Gdk::SOURCE_CURSOR: toolToUse[devName] = TOOLS_SELECT; break; default: @@ -651,10 +656,6 @@ static void init_extended() } } } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devices); -#endif } diff --git a/src/desktop-events.h b/src/desktop-events.h index dc85e563b..8dae9b406 100644 --- a/src/desktop-events.h +++ b/src/desktop-events.h @@ -13,6 +13,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <glib.h> + class SPDesktop; struct SPDesktopWidget; struct SPCanvasItem; diff --git a/src/device-manager.cpp b/src/device-manager.cpp index 610173d3d..aa3874da8 100644 --- a/src/device-manager.cpp +++ b/src/device-manager.cpp @@ -12,37 +12,48 @@ #include <set> #include "preferences.h" -#include <gtk/gtk.h> +#include <gdkmm/display.h> +#include <gtkmm/accelkey.h> + +#if WITH_GTKMM_3_0 +# include <gdkmm/devicemanager.h> +#endif + #include <glibmm/regex.h> +#include <gtk/gtk.h> + #define noDEBUG_VERBOSE 1 // This is a copy of the private fields of the GdkDevice object, used in order // to create a list of "fake" devices. struct GdkDeviceFake { - gchar *name; - GdkInputSource source; - GdkInputMode mode; - gboolean has_cursor; - gint num_axes; - gint num_keys; + Glib::ustring name; + Gdk::InputSource source; + Gdk::InputMode mode; + bool has_cursor; + int num_axes; + int num_keys; }; static void createFakeList(); -GdkDeviceFake fakeout[5]; -static GList* fakeList = 0; +static std::vector<GdkDeviceFake> fakeList; -static bool isValidDevice(GdkDevice *device) +static bool isValidDevice(Glib::RefPtr<Gdk::Device> device) { bool valid = true; - for (size_t i = 0; (i < G_N_ELEMENTS(fakeout)) && valid; i++) { - gboolean name_matches = (g_strcmp0 (gdk_device_get_name (device), fakeout[i].name) == 0); - gboolean source_matches = (gdk_device_get_source (device) == fakeout[i].source); - gboolean mode_matches = (gdk_device_get_mode (device) == fakeout[i].mode); - gboolean num_axes_matches = (gdk_device_get_n_axes (device) == fakeout[i].num_axes); - gboolean num_keys_matches = (gdk_device_get_n_keys (device) == fakeout[i].num_keys); + for (std::vector<GdkDeviceFake>::iterator it = fakeList.begin(); it != fakeList.end() && valid; ++it) { + const bool name_matches = (device->get_name() == (*it).name); + const bool source_matches = (device->get_source() == (*it).source); + const bool mode_matches = (device->get_mode() == (*it).mode); + const bool num_axes_matches = (device->get_n_axes() == (*it).num_axes); +#if WITH_GTKMM_3_0 + const bool num_keys_matches = (device->get_n_keys() == (*it).num_keys); +#else + const bool num_keys_matches = (gdk_device_get_n_keys(device->gobj()) == (*it).num_keys); +#endif if (name_matches && source_matches && mode_matches && num_axes_matches && num_keys_matches) @@ -157,19 +168,22 @@ InputDevice::~InputDevice() {} class InputDeviceImpl : public InputDevice { public: - InputDeviceImpl(GdkDevice* device, std::set<Glib::ustring> &knownIDs); + InputDeviceImpl(Glib::RefPtr<Gdk::Device> device, std::set<Glib::ustring> &knownIDs); virtual ~InputDeviceImpl() {} virtual Glib::ustring getId() const {return id;} virtual Glib::ustring getName() const {return name;} virtual Gdk::InputSource getSource() const {return source;} - virtual Gdk::InputMode getMode() const {return static_cast<Gdk::InputMode>(gdk_device_get_mode (device));} - virtual gint getNumAxes() const {return gdk_device_get_n_axes (device);} - virtual bool hasCursor() const {return gdk_device_get_has_cursor (device);} + virtual Gdk::InputMode getMode() const {return (device->get_mode());} + virtual gint getNumAxes() const {return device->get_n_axes();} + virtual bool hasCursor() const {return device->get_has_cursor();} + +#if WITH_GTKMM_3_0 + virtual int getNumKeys() const {return device->get_n_keys();} +#else + virtual int getNumKeys() const {return gdk_device_get_n_keys(device->gobj());} +#endif - virtual gint getNumKeys() const { - return gdk_device_get_n_keys (device); - } virtual Glib::ustring getLink() const {return link;} virtual void setLink( Glib::ustring const& link ) {this->link = link;} virtual gint getLiveAxes() const {return liveAxes;} @@ -178,7 +192,7 @@ public: virtual void setLiveButtons(gint buttons) {liveButtons = buttons;} // internal methods not on public superclass: - virtual GdkDevice *getDevice() { return device; } + virtual Glib::RefPtr<Gdk::Device> getDevice() {return device;} private: InputDeviceImpl(InputDeviceImpl const &); // no copy @@ -186,7 +200,7 @@ private: static Glib::ustring createId(Glib::ustring const &id, Gdk::InputSource source, std::set<Glib::ustring> &knownIDs); - GdkDevice* device; + Glib::RefPtr<Gdk::Device> device; Glib::ustring id; Glib::ustring name; Gdk::InputSource source; @@ -213,12 +227,12 @@ private: Glib::ustring const& target; }; -InputDeviceImpl::InputDeviceImpl(GdkDevice* device, std::set<Glib::ustring> &knownIDs) +InputDeviceImpl::InputDeviceImpl(Glib::RefPtr<Gdk::Device> device, std::set<Glib::ustring> &knownIDs) : InputDevice(), device(device), id(), - name(gdk_device_get_name (device) ? gdk_device_get_name (device) : ""), - source(static_cast<Gdk::InputSource>(gdk_device_get_source (device))), + name(!device->get_name().empty() ? device->get_name() : ""), + source(device->get_source()), link(), liveAxes(0), liveButtons(0) @@ -312,28 +326,26 @@ DeviceManagerImpl::DeviceManagerImpl() : DeviceManager(), devices() { -#if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devList = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); + +#if WITH_GTKMM_3_0 + Glib::RefPtr<Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devList = gdk_devices_list(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = display->list_devices(); #endif - if ( !fakeList ) { + if (fakeList.empty()) { createFakeList(); } //devList = fakeList; std::set<Glib::ustring> knownIDs; - for ( GList* curr = devList; curr; curr = g_list_next(curr) ) { - GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data); - if (dev) { - -#if GTK_CHECK_VERSION(3,0,0) + for ( std::vector< Glib::RefPtr<Gdk::Device> >::iterator dev = devList.begin(); dev != devList.end(); ++dev ) { +#if WITH_GTKMM_3_0 // GTK+ 3 has added keyboards to the list of supported devices. - if(gdk_device_get_source(dev) != GDK_SOURCE_KEYBOARD) { + if((*dev)->get_source() != Gdk::SOURCE_KEYBOARD) { #endif #if DEBUG_VERBOSE @@ -341,20 +353,14 @@ DeviceManagerImpl::DeviceManagerImpl() : dev->has_cursor?"Yes":"no", dev->num_axes, dev->num_keys); #endif - InputDeviceImpl* device = new InputDeviceImpl(dev, knownIDs); + InputDeviceImpl* device = new InputDeviceImpl(*dev, knownIDs); device->reference(); devices.push_back(Glib::RefPtr<InputDeviceImpl>(device)); -#if GTK_CHECK_VERSION(3,0,0) +#if WITH_GTKMM_3_0 } #endif - - } } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devList); -#endif } void DeviceManagerImpl::loadConfig() @@ -420,8 +426,8 @@ void DeviceManagerImpl::saveConfig() if (i > 0) { tmp += ";"; } - GdkDevice *device = (*it)->getDevice(); - tmp += getAxisToString()[static_cast<Gdk::AxisUse>(gdk_device_get_axis_use (device, i))]; + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + tmp += getAxisToString()[device->get_axis_use(i)]; } prefs->setString( path + "/axes", tmp ); @@ -430,11 +436,12 @@ void DeviceManagerImpl::saveConfig() if (i > 0) { tmp += ";"; } - GdkDevice *device = (*it)->getDevice(); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); guint keyval; - GdkModifierType modifiers; - gdk_device_get_key (device, i, &keyval, &modifiers); - tmp += gtk_accelerator_name(keyval, modifiers); + Gdk::ModifierType modifiers; + device->get_key(i, keyval, modifiers); + Gtk::AccelKey accelkey(keyval, modifiers); + tmp += accelkey.get_abbrev(); } prefs->setString( path + "/keys", tmp ); } @@ -454,8 +461,9 @@ void DeviceManagerImpl::setMode( Glib::ustring const & id, Gdk::InputMode mode ) { std::list<Glib::RefPtr<InputDeviceImpl> >::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id)); if ( it != devices.end() ) { - if (isValidDevice((*it)->getDevice()) && ((*it)->getMode() != mode) ) { - bool success = gdk_device_set_mode((*it)->getDevice(), static_cast<GdkInputMode>(mode)); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + if (isValidDevice(device) && ((*it)->getMode() != mode) ) { + bool success = device->set_mode(mode); if (success) { signalDeviceChangedPriv.emit(*it); } else { @@ -471,10 +479,10 @@ void DeviceManagerImpl::setAxisUse( Glib::ustring const & id, guint index, Gdk:: if ( it != devices.end() ) { if (isValidDevice((*it)->getDevice())) { if (static_cast<gint>(index) <= (*it)->getNumAxes()) { - GdkDevice *device = (*it)->getDevice(); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); - if (gdk_device_get_axis_use (device, index) != static_cast<GdkAxisUse>(use)) { - gdk_device_set_axis_use(device, index, static_cast<GdkAxisUse>(use)); + if (device->get_axis_use(index) != use) { + device->set_axis_use(index, use); signalDeviceChangedPriv.emit(*it); } } else { @@ -492,7 +500,8 @@ void DeviceManagerImpl::setKey( Glib::ustring const & id, guint index, guint key std::list<Glib::RefPtr<InputDeviceImpl> >::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id)); if ( it != devices.end() ) { if (isValidDevice((*it)->getDevice())) { - gdk_device_set_key((*it)->getDevice(), index, keyval, static_cast<GdkModifierType>(mods)); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + device->set_key(index, keyval, mods); signalDeviceChangedPriv.emit(*it); } } @@ -628,78 +637,76 @@ DeviceManager& DeviceManager::getManager() { static void createFakeList() { - if ( !fakeList ) { - fakeout[0].name = g_strdup("pad"); - fakeout[0].source = GDK_SOURCE_PEN; - fakeout[0].mode = GDK_MODE_SCREEN; - fakeout[0].has_cursor = TRUE; - fakeout[0].num_axes = 6; - fakeout[0].num_keys = 8; - - fakeout[1].name = g_strdup("eraser"); - fakeout[1].source = GDK_SOURCE_ERASER; - fakeout[1].mode = GDK_MODE_SCREEN; - fakeout[1].has_cursor = TRUE; - fakeout[1].num_axes = 6; - fakeout[1].num_keys = 7; - - fakeout[2].name = g_strdup("cursor"); - fakeout[2].source = GDK_SOURCE_CURSOR; - fakeout[2].mode = GDK_MODE_SCREEN; - fakeout[2].has_cursor = TRUE; - fakeout[2].num_axes = 6; - fakeout[2].num_keys = 7; - - fakeout[3].name = g_strdup("stylus"); - fakeout[3].source = GDK_SOURCE_PEN; - fakeout[3].mode = GDK_MODE_SCREEN; - fakeout[3].has_cursor = TRUE; - fakeout[3].num_axes = 6; - fakeout[3].num_keys = 7; + if (fakeList.empty()) { + fakeList.resize(5); + fakeList[0].name = "pad"; + fakeList[0].source = Gdk::SOURCE_PEN; + fakeList[0].mode = Gdk::MODE_SCREEN; + fakeList[0].has_cursor = true; + fakeList[0].num_axes = 6; + fakeList[0].num_keys = 8; + + fakeList[1].name = "eraser"; + fakeList[1].source = Gdk::SOURCE_ERASER; + fakeList[1].mode = Gdk::MODE_SCREEN; + fakeList[1].has_cursor = true; + fakeList[1].num_axes = 6; + fakeList[1].num_keys = 7; + + fakeList[2].name = "cursor"; + fakeList[2].source = Gdk::SOURCE_CURSOR; + fakeList[2].mode = Gdk::MODE_SCREEN; + fakeList[2].has_cursor = true; + fakeList[2].num_axes = 6; + fakeList[2].num_keys = 7; + + fakeList[3].name = "stylus"; + fakeList[3].source = Gdk::SOURCE_PEN; + fakeList[3].mode = Gdk::MODE_SCREEN; + fakeList[3].has_cursor = true; + fakeList[3].num_axes = 6; + fakeList[3].num_keys = 7; // try to find the first *real* core pointer -#if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devList = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); +#if WITH_GTKMM_3_0 + Glib::RefPtr<Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devList = gdk_devices_list(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = display->list_devices(); #endif + // Set iterator to point at beginning of device list + std::vector< Glib::RefPtr<Gdk::Device> >::iterator dev = devList.begin(); + // Skip past any items in the device list that are not mice - while ( devList && devList->data && (gdk_device_get_source ((GdkDevice*)devList->data) != GDK_SOURCE_MOUSE)) { - devList = g_list_next(devList); + while (dev != devList.end() && (*dev)->get_source() != Gdk::SOURCE_MOUSE) { + ++dev; } - if ( devList && devList->data ) { - GdkDevice *device = (GdkDevice*)devList->data; - fakeout[4].name = g_strdup(gdk_device_get_name (device)); - fakeout[4].source = gdk_device_get_source (device); - fakeout[4].mode = gdk_device_get_mode (device); - fakeout[4].has_cursor = gdk_device_get_has_cursor (device); - fakeout[4].num_axes = gdk_device_get_n_axes (device); - fakeout[4].num_keys = gdk_device_get_n_keys (device); + if (dev != devList.end()) { + Glib::RefPtr<Gdk::Device> device = *dev; + fakeList[4].name = device->get_name(); + fakeList[4].source = device->get_source(); + fakeList[4].mode = device->get_mode(); + fakeList[4].has_cursor = device->get_has_cursor(); + fakeList[4].num_axes = device->get_n_axes(); +#if WITH_GTKMM_3_0 + fakeList[4].num_keys = device->get_n_keys(); +#else + fakeList[4].num_keys = gdk_device_get_n_keys(device->gobj()); +#endif } else { - fakeout[4].name = g_strdup("Core Pointer"); - fakeout[4].source = GDK_SOURCE_MOUSE; - fakeout[4].mode = GDK_MODE_SCREEN; - fakeout[4].has_cursor = TRUE; - fakeout[4].num_axes = 2; - fakeout[4].num_keys = 0; - } - - for ( guint pos = 0; pos < G_N_ELEMENTS(fakeout); pos++) { - fakeList = g_list_append(fakeList, &(fakeout[pos])); + fakeList[4].name = "Core Pointer"; + fakeList[4].source = Gdk::SOURCE_MOUSE; + fakeList[4].mode = Gdk::MODE_SCREEN; + fakeList[4].has_cursor = true; + fakeList[4].num_axes = 2; + fakeList[4].num_keys = 0; } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devList); -#endif } - } - /* Local Variables: mode:c++ diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index bcce81f0b..8c0c8163f 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -256,7 +256,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap "shape", SP_KNOT_SHAPE_CROSS, NULL ); - const int timeout_val = 1200; // TODO add preference for snap indicator timeout? + const int timeout_val = 4000; SP_CTRL(canvasitem)->moveto(p.getPoint()); _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val); diff --git a/src/document.cpp b/src/document.cpp index 2caefb4ed..11971e63d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -637,7 +637,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) old_width_units = unit_table.getUnit(root->width.unit); - gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; @@ -646,7 +650,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) old_height_units = unit_table.getUnit(root->height.unit); - gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; @@ -678,17 +686,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) - old_units = unit_table.getUnit(root->width.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->width.value, old_units, width.unit); + old_width_units = unit_table.getUnit(root->width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_width_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); } @@ -713,17 +725,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) - old_units = unit_table.getUnit(root->height.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->height.value, old_units, height.unit); + old_height_units = unit_table.getUnit(root->height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); root->updateRepr(); } @@ -761,7 +777,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const old_height = getHeight().value("px"); Inkscape::Util::Unit const *nv_units = unit_table.getUnit("px"); - if (root->height.unit) + if (root->height.unit && (root->height.unit != SVGLength::PERCENT)) nv_units = unit_table.getUnit(root->height.unit); SPNamedView *nv = sp_document_namedview(this, NULL); diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 4b070cbaa..71b6b82f7 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -45,8 +45,8 @@ #include "display/drawing-item.h" #include "clear-n_.h" #include "svg/svg.h" -#include "util/units.h" // even though it is included indirectly by wmf-inout.h -#include "inkscape.h" // even though it is included indirectly by wmf-inout.h +#include "util/units.h" // even though it is included indirectly by emf-inout.h +#include "inkscape.h" // even though it is included indirectly by emf-inout.h #include "emf-print.h" #include "emf-inout.h" @@ -1515,6 +1515,9 @@ void Emf::common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr, int dibparams = U_BI_UNKNOWN; // type of image not yet determined tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1727,21 +1730,23 @@ std::cout << "BEFORE DRAW" ) ){ // std::cout << "PATH DRAW at TOP path" << *(d->path) << std::endl; - d->outsvg += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. - if(d->drawtype){ // explicit draw type EMR record - output_style(d, d->drawtype); - } - else if(d->mask & U_DRAW_CLOSED){ // implicit draw type - output_style(d, U_EMR_STROKEANDFILLPATH); - } - else { - output_style(d, U_EMR_STROKEPATH); + if(!(d->path.empty())){ + d->outsvg += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. + if(d->drawtype){ // explicit draw type EMR record + output_style(d, d->drawtype); + } + else if(d->mask & U_DRAW_CLOSED){ // implicit draw type + output_style(d, U_EMR_STROKEANDFILLPATH); + } + else { + output_style(d, U_EMR_STROKEPATH); + } + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; } - d->outsvg += "\n\t"; - d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. - d->outsvg += d->path; - d->outsvg += " \" /> \n"; - d->path = ""; // reset the flags d->mask = 0; d->drawtype = 0; @@ -3418,7 +3423,11 @@ std::cout << "BEFORE DRAW" tmp_rectangle << "\n\tz\""; tmp_rectangle << "\n\tstyle=\"stroke:none;fill:url(#"; tmp_rectangle << d->gradients.strings[fill_idx]; - tmp_rectangle << ");\"\n/>\n"; + tmp_rectangle << ");\"\n"; + if (d->dc[d->level].clip_id){ + tmp_rectangle << "\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } + tmp_rectangle << "/>\n"; } d->outsvg += tmp_rectangle.str().c_str(); } @@ -3538,7 +3547,7 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); - setViewBoxIfMissing(doc); + // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. return doc; } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index f7b6626c4..b22dbc0e3 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -706,7 +706,7 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) n_dash = style->stroke_dasharray.values.size(); dash = new uint32_t[n_dash]; for (i = 0; i < n_dash; i++) { - dash[i] = (uint32_t)(Inkscape::Util::Quantity::convert(1, "mm", "px") * style->stroke_dasharray.values[i]); + dash[i] = style->stroke_dasharray.values[i]; } } } diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 812fa373f..cc0b38515 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -2586,24 +2586,12 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/) } } - - -/* - * The `POPPLER_NEW_GFXFONT' stuff is for the change to GfxFont's getNextChar() call. - * Thanks to tsdgeos for the fix. - * Miklos, does this look ok? - */ - void PdfParser::doShowText(GooString *s) { GfxFont *font; int wMode; double riseX, riseY; CharCode code; -#ifdef POPPLER_NEW_GFXFONT Unicode *u = NULL; -#else - Unicode u[8]; -#endif double x, y, dx, dy, tdx, tdy; double originX, originY, tOriginX, tOriginY; double oldCTM[6], newCTM[6]; @@ -2651,11 +2639,7 @@ void PdfParser::doShowText(GooString *s) { len = s->getLength(); while (len > 0) { n = font->getNextChar(p, len, &code, -#ifdef POPPLER_NEW_GFXFONT &u, &uLen, /* TODO: This looks like a memory leak for u. */ -#else - u, (int)(sizeof(u) / sizeof(Unicode)), &uLen, -#endif &dx, &dy, &originX, &originY); dx = dx * state->getFontSize() + state->getCharSpace(); if (n == 1 && *p == ' ') { @@ -2708,11 +2692,7 @@ void PdfParser::doShowText(GooString *s) { len = s->getLength(); while (len > 0) { n = font->getNextChar(p, len, &code, -#ifdef POPPLER_NEW_GFXFONT &u, &uLen, /* TODO: This looks like a memory leak for u. */ -#else - u, (int)(sizeof(u) / sizeof(Unicode)), &uLen, -#endif &dx, &dy, &originX, &originY); if (wMode) { diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 72c1c8bd3..8eb03131c 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -1308,6 +1308,9 @@ void Wmf::common_dib_to_image(PWMF_CALLBACK_DATA d, const char *dib, int dibparams = U_BI_UNKNOWN; // type of image not yet determined tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1405,6 +1408,9 @@ void Wmf::common_bm16_to_image(PWMF_CALLBACK_DATA d, U_BITMAP16 Bm16, const char SVGOStringStream tmp_image; tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1752,13 +1758,15 @@ std::cout << "BEFORE DRAW" ) ){ // std::cout << "PATH DRAW at TOP <<+++++++++++++++++++++++++++++++++++++" << std::endl; - d->outsvg += " <path "; // this is the ONLY place <path should be used!!!! - output_style(d); - d->outsvg += "\n\t"; - d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! - d->outsvg += d->path; - d->outsvg += " \" /> \n"; - d->path = ""; //reset the path + if(!(d->path.empty())){ + d->outsvg += " <path "; // this is the ONLY place <path should be used!!!! + output_style(d); + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; //reset the path + } // reset the flags d->mask = 0; d->drawtype = 0; @@ -2600,9 +2608,9 @@ std::cout << "BEFORE DRAW" if(status==-1){ // change of escapement, emit what we have and reset TR_layout_analyze(d->tri); if (d->dc[d->level].clip_id){ - SVGOStringStream tmp_clip; - tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; - d->outsvg += tmp_clip.str().c_str(); + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); } TR_layout_2_svg(d->tri); ts << d->tri->out; @@ -2610,7 +2618,7 @@ std::cout << "BEFORE DRAW" d->tri = trinfo_clear(d->tri); (void) trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ignore return status, it must work if (d->dc[d->level].clip_id){ - d->outsvg += "\n</g>\n"; + d->outsvg += "\n</g>\n"; } } @@ -3113,7 +3121,7 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); - setViewBoxIfMissing(doc); + // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. return doc; } diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 85582e209..3a39a51c1 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -30,6 +30,7 @@ #include "svg/stringstream.h" #include "svg/svg.h" #include "xml/repr.h" +#include "util/units.h" #include "sp-factory.h" @@ -298,7 +299,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) SPItemCtx rctx = *ictx; rctx.viewport = Geom::Rect::from_xywh( this->x.computed, this->y.computed, this->width.computed, this->height.computed ); - rctx = get_rctx( &rctx ); + rctx = get_rctx( &rctx, Inkscape::Util::Quantity::convert(1, this->document->getDisplayUnit(), "px") ); /* And invoke parent method */ SPGroup::update((SPCtx *) &rctx, flags); diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 91f05668e..e1da23efa 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -14,9 +14,6 @@ #include <2geom/transforms.h> -#include "inkscape.h" -#include "document.h" -#include "util/units.h" #include "viewbox.h" #include "attributes.h" #include "enums.h" @@ -164,21 +161,20 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { } // Apply scaling from viewbox -void SPViewBox::apply_viewbox(const Geom::Rect& in) { +void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { /* Determine actual viewbox in viewport coordinates */ + // scale_none is the scale that would apply if the viewbox and page size are same size + // it is passed here because it is a double-precision variable, while 'in' is originally float double x = 0.0; double y = 0.0; double scale_x = in.width() / this->viewBox.width(); double scale_y = in.height() / this->viewBox.height(); double scale_uniform = 1.0; // used only if scaling is uniform - double scale_none = 1.0; // used only if viewbox and page size are same size if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) { // scaling is already uniform, reduce numerical error scale_uniform = (scale_x + scale_y)/2.0; - if (SP_ACTIVE_DOCUMENT) - scale_none = Inkscape::Util::Quantity::convert(1, SP_ACTIVE_DOCUMENT->getDisplayUnit(), "px"); if (Geom::are_near(scale_uniform / scale_none, 1.0, Geom::EPSILON)) scale_uniform = scale_none; // objects are same size, reduce numerical error scale_x = scale_uniform; @@ -243,7 +239,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { this->c2p = q * this->c2p; } -SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { +SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx, double scale_none) { /* Create copy of item context */ SPItemCtx rctx = *ictx; @@ -254,7 +250,7 @@ SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { if (this->viewBox_set) { // Adjusts c2p for viewbox - apply_viewbox( rctx.viewport ); + apply_viewbox( rctx.viewport, scale_none ); } rctx.i2doc = this->c2p * rctx.i2doc; diff --git a/src/viewbox.h b/src/viewbox.h index 1898cd98f..c71abb610 100644 --- a/src/viewbox.h +++ b/src/viewbox.h @@ -41,9 +41,9 @@ public: void set_preserveAspectRatio(const gchar* value); /* Adjusts c2p for viewbox */ - void apply_viewbox(const Geom::Rect& in); + void apply_viewbox(const Geom::Rect& in, double scale_none = 1.0); - SPItemCtx get_rctx( const SPItemCtx* ictx); + SPItemCtx get_rctx( const SPItemCtx* ictx, double scale_none = 1.0); }; |
