From a11039985c1101b12665e85a8368a46b77f9de10 Mon Sep 17 00:00:00 2001 From: su_v Date: Thu, 24 Jan 2013 17:44:22 +0100 Subject: Add support for libcdr (bzr r12059.1.1) --- src/Makefile.am | 2 + src/extension/init.cpp | 6 + src/extension/internal/Makefile_insert | 6 + src/extension/internal/cdr-input.cpp | 293 +++++++++++++++++++++++++++++++++ src/extension/internal/cdr-input.h | 54 ++++++ 5 files changed, 361 insertions(+) create mode 100644 src/extension/internal/cdr-input.cpp create mode 100644 src/extension/internal/cdr-input.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 46c655f9c..65baec21b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ all_libs = \ $(INKBOARD_LIBS) \ $(LIBWPG_LIBS) \ $(LIBVISIO_LIBS) \ + $(LIBCDR_LIBS) \ $(DBUS_LIBS) \ $(GDL_LIBS) \ $(IMAGEMAGICK_LIBS) @@ -72,6 +73,7 @@ INCLUDES = \ $(INKBOARD_CFLAGS) \ $(LIBWPG_CFLAGS) \ $(LIBVISIO_CFLAGS) \ + $(LIBCDR_CFLAGS) \ $(DBUS_CFLAGS) \ $(GDL_CFLAGS) \ $(XFT_CFLAGS) \ diff --git a/src/extension/init.cpp b/src/extension/init.cpp index ac3c90421..5555eddf6 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -56,6 +56,9 @@ #ifdef WITH_LIBVISIO #include "internal/vsd-input.h" #endif +#ifdef WITH_LIBCDR +#include "internal/cdr-input.h" +#endif #include "preferences.h" #include "io/sys.h" #ifdef WITH_DBUS @@ -191,6 +194,9 @@ init() #ifdef WITH_LIBVISIO Internal::VsdInput::init(); #endif +#ifdef WITH_LIBCDR + Internal::CdrInput::init(); +#endif /* Effects */ Internal::BlurEdge::init(); diff --git a/src/extension/internal/Makefile_insert b/src/extension/internal/Makefile_insert index 1ea6caca9..9e55598df 100644 --- a/src/extension/internal/Makefile_insert +++ b/src/extension/internal/Makefile_insert @@ -12,6 +12,12 @@ ink_common_sources += \ extension/internal/vsd-input.h endif +if WITH_LIBCDR +ink_common_sources += \ + extension/internal/cdr-input.cpp \ + extension/internal/cdr-input.h +endif + if USE_IMAGE_MAGICK ink_common_sources += \ extension/internal/bitmap/imagemagick.cpp \ diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp new file mode 100644 index 000000000..63531d082 --- /dev/null +++ b/src/extension/internal/cdr-input.cpp @@ -0,0 +1,293 @@ +/* + * This file came from libwpg as a source, their utility wpg2svg + * specifically. It has been modified to work as an Inkscape extension. + * The Inkscape extension code is covered by this copyright, but the + * rest is covered by the one bellow. + * + * Authors: + * Fridrich Strba (fridrich.strba@bluewin.ch) + * + * Copyright (C) 2012 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + * + */ + +#include +#include "config.h" + +#include "cdr-input.h" + +#ifdef WITH_LIBCDR + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "extension/system.h" +#include "extension/input.h" +#include "document.h" + +#include "document-private.h" +#include "document-undo.h" +#include "inkscape.h" + +#include "dialogs/dialog-events.h" +#include +#include "ui/widget/spinbutton.h" +#include "ui/widget/frame.h" +#include + +#include + +#include "svg-view.h" +#include "svg-view-widget.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { + + +class CdrImportDialog : public Gtk::Dialog { +public: + CdrImportDialog(const std::vector &vec); + virtual ~CdrImportDialog(); + + bool showDialog(); + unsigned getSelectedPage(); + void getImportSettings(Inkscape::XML::Node *prefs); + +private: + void _setPreviewPage(unsigned page); + + // Signal handlers +#if !WITH_GTKMM_3_0 + bool _onExposePreview(GdkEventExpose *event); +#endif + + void _onPageNumberChanged(); + + class Gtk::Button * cancelbutton; + class Gtk::Button * okbutton; + class Gtk::Label * _labelSelect; + class Inkscape::UI::Widget::SpinButton * _pageNumberSpin; + class Gtk::Label * _labelTotalPages; + class Gtk::VBox * vbox1; + class Gtk::VBox * vbox2; + class Gtk::Widget * _previewArea; + + const std::vector &_vec; // Document to be imported + unsigned _current_page; // Current selected page + int _preview_width, _preview_height; // Size of the preview area +}; + +CdrImportDialog::CdrImportDialog(const std::vector &vec) + : _vec(vec), _current_page(1) +{ + int num_pages = _vec.size(); + if ( num_pages <= 1 ) + return; + cancelbutton = Gtk::manage(new class Gtk::Button(Gtk::StockID("gtk-cancel"))); + okbutton = Gtk::manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))); + _labelSelect = Gtk::manage(new class Gtk::Label(_("Select page:"))); + + // Page number +#if WITH_GTKMM_3_0 + Glib::RefPtr _pageNumberSpin_adj = Gtk::Adjustment::create(1, 1, _vec.size(), 1, 10, 0); + _pageNumberSpin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(_pageNumberSpin_adj, 1, 1)); +#else + Gtk::Adjustment *_pageNumberSpin_adj = Gtk::manage( + new class Gtk::Adjustment(1, 1, _vec.size(), 1, 10, 0)); + _pageNumberSpin = Gtk::manage(new class Inkscape::UI::Widget::SpinButton(*_pageNumberSpin_adj, 1, 1)); +#endif + _labelTotalPages = Gtk::manage(new class Gtk::Label()); + gchar *label_text = g_strdup_printf(_("out of %i"), num_pages); + _labelTotalPages->set_label(label_text); + g_free(label_text); + + vbox1 = Gtk::manage(new class Gtk::VBox(false, 4)); + SPDocument *doc = SPDocument::createNewDocFromMem(_vec[0].cstr(), strlen(_vec[0].cstr()), 0); + _previewArea = Glib::wrap(sp_svg_view_widget_new(doc)); + + vbox2 = Gtk::manage(new class Gtk::VBox(false, 4)); + cancelbutton->set_can_focus(); + cancelbutton->set_can_default(); + cancelbutton->set_relief(Gtk::RELIEF_NORMAL); + okbutton->set_can_focus(); + okbutton->set_can_default(); + okbutton->set_relief(Gtk::RELIEF_NORMAL); + this->get_action_area()->property_layout_style().set_value(Gtk::BUTTONBOX_END); + _labelSelect->set_line_wrap(false); + _labelSelect->set_use_markup(false); + _labelSelect->set_selectable(false); + _pageNumberSpin->set_can_focus(); + _pageNumberSpin->set_update_policy(Gtk::UPDATE_ALWAYS); + _pageNumberSpin->set_numeric(true); + _pageNumberSpin->set_digits(0); + _pageNumberSpin->set_wrap(false); + _labelTotalPages->set_line_wrap(false); + _labelTotalPages->set_use_markup(false); + _labelTotalPages->set_selectable(false); + vbox2->pack_start(*_previewArea, Gtk::PACK_SHRINK, 0); + this->get_vbox()->set_homogeneous(false); + this->get_vbox()->set_spacing(0); + this->get_vbox()->pack_start(*vbox2); + this->set_title(_("Page Selector")); + this->set_modal(true); + sp_transientize(GTK_WIDGET(this->gobj())); //Make transient + this->property_window_position().set_value(Gtk::WIN_POS_NONE); + this->set_resizable(true); + this->property_destroy_with_parent().set_value(false); + this->get_action_area()->add(*_labelSelect); + this->add_action_widget(*_pageNumberSpin, -7); + this->get_action_area()->add(*_labelTotalPages); + this->add_action_widget(*cancelbutton, -6); + this->add_action_widget(*okbutton, -5); + cancelbutton->show(); + okbutton->show(); + _labelSelect->show(); + _pageNumberSpin->show(); + _labelTotalPages->show(); + vbox1->show(); + _previewArea->show(); + vbox2->show(); + + // Connect signals + _pageNumberSpin_adj->signal_value_changed().connect(sigc::mem_fun(*this, &CdrImportDialog::_onPageNumberChanged)); +} + +CdrImportDialog::~CdrImportDialog() {} + +bool CdrImportDialog::showDialog() +{ + show(); + gint b = run(); + hide(); + if ( b == Gtk::RESPONSE_OK ) { + return TRUE; + } else { + return FALSE; + } +} + +unsigned CdrImportDialog::getSelectedPage() +{ + return _current_page; +} + +void CdrImportDialog::_onPageNumberChanged() +{ + int page = _pageNumberSpin->get_value_as_int(); + _current_page = CLAMP(page, 1, _vec.size()); + _setPreviewPage(_current_page); +} + +/** + * \brief Renders the given page's thumbnail + */ +void CdrImportDialog::_setPreviewPage(unsigned page) +{ + SPDocument *doc = SPDocument::createNewDocFromMem(_vec[page-1].cstr(), strlen(_vec[page-1].cstr()), 0); + Gtk::Widget * tmpPreviewArea = Glib::wrap(sp_svg_view_widget_new(doc)); + std::swap(_previewArea, tmpPreviewArea); + if (tmpPreviewArea) { + _previewArea->set_size_request( tmpPreviewArea->get_width(), tmpPreviewArea->get_height() ); + delete tmpPreviewArea; + } + vbox2->pack_start(*_previewArea, Gtk::PACK_SHRINK, 0); + _previewArea->show_now(); +} + +SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) +{ + WPXFileStream input(uri); + + if (!libcdr::CDRDocument::isSupported(&input)) { + return NULL; + } + + libcdr::CDRStringVector output; + if (!libcdr::CDRDocument::generateSVG(&input, output)) { + return NULL; + } + + if (output.empty()) { + return NULL; + } + + std::vector tmpSVGOutput; + for (unsigned i=0; i\n\n"); + tmpString.append(output[i]); + tmpSVGOutput.push_back(tmpString); + } + + unsigned page_num = 1; + + // If only one page is present, import that one without bothering user + if (tmpSVGOutput.size() > 1) { + CdrImportDialog *dlg = 0; + if (inkscape_use_gui()) { + dlg = new CdrImportDialog(tmpSVGOutput); + if (!dlg->showDialog()) { + delete dlg; + return NULL; + } + } + + // Get needed page + if (dlg) { + page_num = dlg->getSelectedPage(); + if (page_num < 1) + page_num = 1; + if (page_num > tmpSVGOutput.size()) + page_num = tmpSVGOutput.size(); + } + } + + SPDocument * doc = SPDocument::createNewDocFromMem(tmpSVGOutput[page_num-1].cstr(), strlen(tmpSVGOutput[page_num-1].cstr()), TRUE); + return doc; +} + +#include "clear-n_.h" + +void CdrInput::init(void) +{ + /* CDR */ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Corel DRAW Input") "\n" + "org.inkscape.input.cdr\n" + "\n" + ".cdr\n" + "image/x-xcdr\n" + "" N_("Corel DRAW 7-X4 files (*.cdr)") "\n" + "" N_("Open files saved in Corel DRAW 7-X4") "\n" + "\n" + "", new CdrInput()); + + return; + +} // init + +} } } /* namespace Inkscape, Extension, Implementation */ +#endif /* WITH_LIBCDR */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/internal/cdr-input.h b/src/extension/internal/cdr-input.h new file mode 100644 index 000000000..10af41d5a --- /dev/null +++ b/src/extension/internal/cdr-input.h @@ -0,0 +1,54 @@ +/* + * This code abstracts the libwpg interfaces into the Inkscape + * input extension interface. + * + * Authors: + * Fridrich Strba (fridrich.strba@bluewin.ch) + * + * Copyright (C) 2012 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef __EXTENSION_INTERNAL_CDROUTPUT_H__ +#define __EXTENSION_INTERNAL_CDROUTPUT_H__ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef WITH_LIBCDR + +#include + +#include "../implementation/implementation.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { + +class CdrInput : public Inkscape::Extension::Implementation::Implementation { + CdrInput () { }; +public: + SPDocument *open( Inkscape::Extension::Input *mod, + const gchar *uri ); + static void init( void ); + +}; + +} } } /* namespace Inkscape, Extension, Implementation */ + +#endif /* WITH_LIBCDR */ +#endif /* __EXTENSION_INTERNAL_CDROUTPUT_H__ */ + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From 55b2e59196c6e980bdb3f03379de6707dd91082b Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 26 Jan 2013 16:18:08 +0000 Subject: More GObject boilerplate reduction (bzr r12064) --- src/box3d-context.cpp | 43 ++++++-------------------- src/common-context.cpp | 39 ++++-------------------- src/ege-output-action.cpp | 31 ++----------------- src/event-context.cpp | 25 ++------------- src/measure-context.cpp | 39 +++++------------------- src/pen-context.cpp | 46 ++++++---------------------- src/persp3d.cpp | 30 +----------------- src/rect-context.cpp | 44 ++++++--------------------- src/sp-flowtext.cpp | 56 +++++++++------------------------- src/sp-glyph.cpp | 50 +++++++----------------------- src/sp-missing-glyph.cpp | 46 ++++++---------------------- src/sp-object.h | 5 +-- src/sp-offset.cpp | 61 ++++++++----------------------------- src/sp-paint-server.cpp | 30 ++---------------- src/sp-paint-server.h | 9 ++---- src/sp-path.cpp | 50 +++++++----------------------- src/sp-style-elem.cpp | 40 +++++------------------- src/sp-symbol.cpp | 77 ++++++++++++++++------------------------------- src/text-context.cpp | 41 ++++++------------------- src/tweak-context.cpp | 36 ++++------------------ src/zoom-context.cpp | 39 +++++------------------- 21 files changed, 168 insertions(+), 669 deletions(-) (limited to 'src') diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index a58059e89..1af5ed29f 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -53,8 +53,6 @@ using Inkscape::DocumentUndo; -static void sp_box3d_context_class_init(Box3DContextClass *klass); -static void sp_box3d_context_init(Box3DContext *box3d_context); static void sp_box3d_context_dispose(GObject *object); static void sp_box3d_context_setup(SPEventContext *ec); @@ -66,34 +64,13 @@ static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem static void sp_box3d_drag(Box3DContext &bc, guint state); static void sp_box3d_finish(Box3DContext *bc); -static SPEventContextClass *parent_class; - -GType sp_box3d_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(Box3DContextClass), - NULL, NULL, - (GClassInitFunc) sp_box3d_context_class_init, - NULL, NULL, - sizeof(Box3DContext), - 4, - (GInstanceInitFunc) sp_box3d_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "Box3DContext", &info, (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(Box3DContext, sp_box3d_context, SP_TYPE_EVENT_CONTEXT); static void sp_box3d_context_class_init(Box3DContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; - parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass); - object_class->dispose = sp_box3d_context_dispose; event_context_class->setup = sp_box3d_context_setup; @@ -135,8 +112,8 @@ static void sp_box3d_context_finish(SPEventContext *ec) bc->sel_changed_connection.disconnect(); // sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); + if (((SPEventContextClass *) sp_box3d_context_parent_class)->finish) { + ((SPEventContextClass *) sp_box3d_context_parent_class)->finish(ec); } } @@ -166,7 +143,7 @@ static void sp_box3d_context_dispose(GObject *object) delete bc->_message_context; } - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_box3d_context_parent_class)->dispose(object); } /** @@ -211,8 +188,8 @@ static void sp_box3d_context_setup(SPEventContext *ec) { Box3DContext *bc = SP_BOX3D_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if (((SPEventContextClass *) sp_box3d_context_parent_class)->setup) { + ((SPEventContextClass *) sp_box3d_context_parent_class)->setup(ec); } ec->shape_editor = new ShapeEditor(ec->desktop); @@ -259,8 +236,8 @@ static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem break; } - if (((SPEventContextClass *) parent_class)->item_handler) { - ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event); + if (((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler) { + ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler(event_context, item, event); } return ret; @@ -572,8 +549,8 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if (((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler) { + ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/common-context.cpp b/src/common-context.cpp index 9d5dbb048..ff99b5c0b 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -19,8 +19,6 @@ #define DRAG_MAX 1.0 -static void sp_common_context_class_init(SPCommonContextClass *klass); -static void sp_common_context_init(SPCommonContext *erc); static void sp_common_context_dispose(GObject *object); static void sp_common_context_setup(SPEventContext *ec); @@ -28,38 +26,13 @@ static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Ent static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event); - -static SPEventContextClass *common_parent_class = 0; - -GType sp_common_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPCommonContextClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_common_context_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPCommonContext), - 0, // n_preallocs - (GInstanceInitFunc)sp_common_context_init, - 0 // value_table - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPCommonContext", &info, static_cast(0)); - } - return type; -} - +G_DEFINE_TYPE(SPCommonContext, sp_common_context, SP_TYPE_EVENT_CONTEXT); static void sp_common_context_class_init(SPCommonContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - common_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_common_context_dispose; event_context_class->setup = sp_common_context_setup; @@ -144,14 +117,14 @@ static void sp_common_context_dispose(GObject *object) ctx->_message_context = 0; } - G_OBJECT_CLASS(common_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } static void sp_common_context_setup(SPEventContext *ec) { - if ( common_parent_class->setup ) { - common_parent_class->setup(ec); + if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { + SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); } } @@ -199,8 +172,8 @@ static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEve if ( !ret ) { - if ( common_parent_class->root_handler ) { - ret = common_parent_class->root_handler(event_context, event); + if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler ) { + ret = SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/ege-output-action.cpp b/src/ege-output-action.cpp index 1b356c55d..214bd4b29 100644 --- a/src/ege-output-action.cpp +++ b/src/ege-output-action.cpp @@ -46,8 +46,6 @@ #include "ege-output-action.h" -static void ege_output_action_class_init( EgeOutputActionClass* klass ); -static void ege_output_action_init( EgeOutputAction* action ); static void ege_output_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); static void ege_output_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); static void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data ); @@ -55,9 +53,6 @@ static void fixup_labels( GObject *gobject, GParamSpec *arg1, gpointer user_data /* static GtkWidget* create_menu_item( GtkAction* action ); */ static GtkWidget* create_tool_item( GtkAction* action ); -static GtkActionClass* gParentClass = 0; - - struct _EgeOutputActionPrivate { gboolean useMarkup; @@ -69,34 +64,12 @@ enum { PROP_USE_MARKUP = 1, }; -GType ege_output_action_get_type( void ) -{ - static GType myType = 0; - if ( !myType ) { - static const GTypeInfo myInfo = { - sizeof( EgeOutputActionClass ), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc)ege_output_action_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof( EgeOutputAction ), - 0, /* n_preallocs */ - (GInstanceInitFunc)ege_output_action_init, - NULL - }; - - myType = g_type_register_static( GTK_TYPE_ACTION, "EgeOutputAction", &myInfo, (GTypeFlags)0 ); - } - - return myType; -} +G_DEFINE_TYPE(EgeOutputAction, ege_output_action, GTK_TYPE_ACTION); void ege_output_action_class_init( EgeOutputActionClass* klass ) { if ( klass ) { GObjectClass* objClass = G_OBJECT_CLASS( klass ); - gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) ); objClass->get_property = ege_output_action_get_property; objClass->set_property = ege_output_action_set_property; @@ -228,7 +201,7 @@ GtkWidget* create_tool_item( GtkAction* action ) g_value_unset( &value ); } else { - item = gParentClass->create_tool_item( action ); + item = GTK_ACTION_CLASS(ege_output_action_parent_class)->create_tool_item( action ); } return item; diff --git a/src/event-context.cpp b/src/event-context.cpp index 71d4a5fb9..4e5917afa 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -54,8 +54,6 @@ #include "sp-guide.h" #include "color.h" -static void sp_event_context_class_init(SPEventContextClass *klass); -static void sp_event_context_init(SPEventContext *event_context); static void sp_event_context_dispose(GObject *object); static void sp_event_context_private_setup(SPEventContext *ec); @@ -66,8 +64,6 @@ static gint sp_event_context_private_item_handler( static void set_event_location(SPDesktop * desktop, GdkEvent * event); -static GObjectClass *parent_class; - // globals for temporary switching to selector by space static bool selector_toggled = FALSE; static int switch_selector_to = 0; @@ -85,22 +81,7 @@ static guint32 scroll_event_time = 0; static gdouble scroll_multiply = 1; static guint scroll_keyval = 0; -/** - * Registers the SPEventContext class with Glib and returns its type number. - */ -GType sp_event_context_get_type(void) { - static GType type = 0; - if (!type) { - GTypeInfo info = { sizeof(SPEventContextClass), NULL, NULL, - (GClassInitFunc) sp_event_context_class_init, NULL, NULL, - sizeof(SPEventContext), 4, - (GInstanceInitFunc) sp_event_context_init, NULL, /* value_table */ - }; - type = g_type_register_static(G_TYPE_OBJECT, "SPEventContext", &info, - (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(SPEventContext, sp_event_context, G_TYPE_OBJECT); /** * Callback to set up the SPEventContext vtable. @@ -108,8 +89,6 @@ GType sp_event_context_get_type(void) { static void sp_event_context_class_init(SPEventContextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - parent_class = G_OBJECT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_event_context_dispose; klass->setup = sp_event_context_private_setup; @@ -166,7 +145,7 @@ static void sp_event_context_dispose(GObject *object) { delete ec->_delayed_snap_event; } - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_event_context_parent_class)->dispose(object); } /** diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 7a04b9915..dc23cf5c6 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -47,16 +47,12 @@ using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; -static void sp_measure_context_class_init(SPMeasureContextClass *klass); -static void sp_measure_context_init(SPMeasureContext *measure_context); static void sp_measure_context_setup(SPEventContext *ec); static void sp_measure_context_finish(SPEventContext *ec); static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEvent *event); static gint sp_measure_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event); -static SPEventContextClass *parent_class; - static gint xp = 0; // where drag started static gint yp = 0; static gint tolerance = 0; @@ -68,26 +64,7 @@ boost::optional lastEnd; std::vector measure_tmp_items; -GType sp_measure_context_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPMeasureContextClass), - NULL, NULL, - reinterpret_cast(sp_measure_context_class_init), // TODO needs two params? - NULL, NULL, - sizeof(SPMeasureContext), - 4, - reinterpret_cast(sp_measure_context_init), // TODO needs two params? - NULL, // value_table - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPMeasureContext", &info, static_cast(0)); - } - - return type; -} +G_DEFINE_TYPE(SPMeasureContext, sp_measure_context, SP_TYPE_EVENT_CONTEXT); namespace { @@ -258,8 +235,6 @@ static void sp_measure_context_class_init(SPMeasureContextClass *klass) { SPEventContextClass *event_context_class = reinterpret_cast(klass); - parent_class = static_cast(g_type_class_peek_parent(klass)); - event_context_class->setup = sp_measure_context_setup; event_context_class->finish = sp_measure_context_finish; @@ -290,8 +265,8 @@ static void sp_measure_context_finish(SPEventContext *ec) static void sp_measure_context_setup(SPEventContext *ec) { - if (parent_class->setup) { - parent_class->setup(ec); + if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) { + SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec); } } @@ -299,8 +274,8 @@ static gint sp_measure_context_item_handler(SPEventContext *event_context, SPIte { gint ret = FALSE; - if (parent_class->item_handler) { - ret = parent_class->item_handler(event_context, item, event); + if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler) { + ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler(event_context, item, event); } return ret; @@ -789,8 +764,8 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv } if (!ret) { - if (parent_class->root_handler) { - ret = parent_class->root_handler(event_context, event); + if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->root_handler) { + ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/pen-context.cpp b/src/pen-context.cpp index cb20eb3eb..6e3ed201e 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -47,9 +47,6 @@ using Inkscape::ControlManager; - -static void sp_pen_context_class_init(SPPenContextClass *klass); -static void sp_pen_context_init(SPPenContext *pc); static void sp_pen_context_dispose(GObject *object); static void sp_pen_context_setup(SPEventContext *ec); @@ -78,35 +75,12 @@ static void pen_enable_events(SPPenContext *const pc); static Geom::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; -static SPDrawContextClass *pen_parent_class; - static int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap); static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical - -/** - * Register SPPenContext with Gdk and return its type. - */ -GType sp_pen_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPPenContextClass), - NULL, NULL, - (GClassInitFunc) sp_pen_context_class_init, - NULL, NULL, - sizeof(SPPenContext), - 4, - (GInstanceInitFunc) sp_pen_context_init, - NULL, // value_table - }; - type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPenContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPPenContext, sp_pen_context, SP_TYPE_DRAW_CONTEXT); /** * Initialize the SPPenContext vtable. @@ -119,8 +93,6 @@ static void sp_pen_context_class_init(SPPenContextClass *klass) object_class = (GObjectClass *) klass; event_context_class = (SPEventContextClass *) klass; - pen_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass); - object_class->dispose = sp_pen_context_dispose; event_context_class->setup = sp_pen_context_setup; @@ -181,7 +153,7 @@ static void sp_pen_context_dispose(GObject *object) pc->cl1 = NULL; } - G_OBJECT_CLASS(pen_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_pen_context_parent_class)->dispose(object); if (pc->expecting_clicks_for_LPE > 0) { // we received too few clicks to sanely set the parameter path so we remove the LPE from the item @@ -203,8 +175,8 @@ static void sp_pen_context_setup(SPEventContext *ec) { SPPenContext *pc = SP_PEN_CONTEXT(ec); - if (((SPEventContextClass *) pen_parent_class)->setup) { - ((SPEventContextClass *) pen_parent_class)->setup(ec); + if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { + ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); } ControlManager &mgr = ControlManager::getManager(); @@ -265,8 +237,8 @@ static void sp_pen_context_finish(SPEventContext *ec) pen_cancel (pc); } - if (((SPEventContextClass *) pen_parent_class)->finish) { - ((SPEventContextClass *) pen_parent_class)->finish(ec); + if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { + ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); } } @@ -347,8 +319,8 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve } if (!ret) { - if (((SPEventContextClass *) pen_parent_class)->item_handler) - ret = ((SPEventContextClass *) pen_parent_class)->item_handler(ec, item, event); + if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) + ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); } return ret; @@ -390,7 +362,7 @@ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) if (!ret) { gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) pen_parent_class)->root_handler; + = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; if (parent_root_handler) { ret = parent_root_handler(ec, event); } diff --git a/src/persp3d.cpp b/src/persp3d.cpp index a20537d95..2744efb75 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -27,9 +27,6 @@ using Inkscape::DocumentUndo; -static void persp3d_class_init(Persp3DClass *klass); -static void persp3d_init(Persp3D *persp); - static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void persp3d_release(SPObject *object); static void persp3d_set(SPObject *object, unsigned key, gchar const *value); @@ -41,8 +38,6 @@ static void persp3d_on_repr_attr_changed (Inkscape::XML::Node * repr, const gcha static void persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image); static gchar * persp3d_pt_to_str (Persp3DImpl *persp_impl, Proj::Axis const axis); -static SPObjectClass *persp3d_parent_class; - static int global_counter = 0; /* Constructor/destructor for the internal class */ @@ -54,28 +49,7 @@ Persp3DImpl::Persp3DImpl() { my_counter = global_counter++; } -/** - * Registers Persp3d class and returns its type. - */ -GType -persp3d_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(Persp3DClass), - NULL, NULL, - (GClassInitFunc) persp3d_class_init, - NULL, NULL, - sizeof(Persp3D), - 16, - (GInstanceInitFunc) persp3d_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "Persp3D", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(Persp3D, persp3d, SP_TYPE_OBJECT); static Inkscape::XML::NodeEventVector const persp3d_repr_events = { NULL, /* child_added */ @@ -92,8 +66,6 @@ static void persp3d_class_init(Persp3DClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *) klass; - persp3d_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); - sp_object_class->build = persp3d_build; sp_object_class->release = persp3d_release; sp_object_class->set = persp3d_set; diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 33ccee93c..040127ae3 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -49,8 +49,6 @@ using Inkscape::DocumentUndo; //static const double goldenratio = 1.61803398874989484820; // golden ratio -static void sp_rect_context_class_init(SPRectContextClass *klass); -static void sp_rect_context_init(SPRectContext *rect_context); static void sp_rect_context_dispose(GObject *object); static void sp_rect_context_setup(SPEventContext *ec); @@ -64,35 +62,13 @@ static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state); static void sp_rect_finish(SPRectContext *rc); static void sp_rect_cancel(SPRectContext *rc); -static SPEventContextClass *parent_class; - - -GType sp_rect_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPRectContextClass), - NULL, NULL, - (GClassInitFunc) sp_rect_context_class_init, - NULL, NULL, - sizeof(SPRectContext), - 4, - (GInstanceInitFunc) sp_rect_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPRectContext", &info, (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(SPRectContext, sp_rect_context, SP_TYPE_EVENT_CONTEXT); static void sp_rect_context_class_init(SPRectContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; - parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass); - object_class->dispose = sp_rect_context_dispose; event_context_class->setup = sp_rect_context_setup; @@ -133,8 +109,8 @@ static void sp_rect_context_finish(SPEventContext *ec) sp_rect_finish(rc); rc->sel_changed_connection.disconnect(); - if (((SPEventContextClass *) parent_class)->finish) { - ((SPEventContextClass *) parent_class)->finish(ec); + if (((SPEventContextClass *) sp_rect_context_parent_class)->finish) { + ((SPEventContextClass *) sp_rect_context_parent_class)->finish(ec); } } @@ -161,7 +137,7 @@ static void sp_rect_context_dispose(GObject *object) delete rc->_message_context; } - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_rect_context_parent_class)->dispose(object); } /** @@ -182,8 +158,8 @@ static void sp_rect_context_setup(SPEventContext *ec) { SPRectContext *rc = SP_RECT_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if (((SPEventContextClass *) sp_rect_context_parent_class)->setup) { + ((SPEventContextClass *) sp_rect_context_parent_class)->setup(ec); } ec->shape_editor = new ShapeEditor(ec->desktop); @@ -245,8 +221,8 @@ static gint sp_rect_context_item_handler(SPEventContext *event_context, SPItem * break; } - if (((SPEventContextClass *) parent_class)->item_handler) { - ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event); + if (((SPEventContextClass *) sp_rect_context_parent_class)->item_handler) { + ret = ((SPEventContextClass *) sp_rect_context_parent_class)->item_handler(event_context, item, event); } return ret; @@ -458,8 +434,8 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if (((SPEventContextClass *) sp_rect_context_parent_class)->root_handler) { + ret = ((SPEventContextClass *) sp_rect_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index dc5b1d8bd..1d95c2f8a 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -34,8 +34,6 @@ #include "display/drawing-text.h" -static void sp_flowtext_class_init(SPFlowtextClass *klass); -static void sp_flowtext_init(SPFlowtext *group); static void sp_flowtext_dispose(GObject *object); static void sp_flowtext_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref); @@ -53,29 +51,7 @@ static void sp_flowtext_snappoints(SPItem const *item, std::vectordispose = sp_flowtext_dispose; sp_object_class->child_added = sp_flowtext_child_added; @@ -122,8 +96,8 @@ sp_flowtext_dispose(GObject *object) static void sp_flowtext_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - if (((SPObjectClass *) (parent_class))->child_added) - (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref); + if (((SPObjectClass *) (sp_flowtext_parent_class))->child_added) + (* ((SPObjectClass *) (sp_flowtext_parent_class))->child_added)(object, child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } @@ -133,8 +107,8 @@ sp_flowtext_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape:: static void sp_flowtext_remove_child(SPObject *object, Inkscape::XML::Node *child) { - if (((SPObjectClass *) (parent_class))->remove_child) - (* ((SPObjectClass *) (parent_class))->remove_child)(object, child); + if (((SPObjectClass *) (sp_flowtext_parent_class))->remove_child) + (* ((SPObjectClass *) (sp_flowtext_parent_class))->remove_child)(object, child); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } @@ -145,8 +119,8 @@ static void sp_flowtext_update(SPObject *object, SPCtx *ctx, unsigned flags) SPItemCtx *ictx = (SPItemCtx *) ctx; SPItemCtx cctx = *ictx; - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update(object, ctx, flags); + if (((SPObjectClass *) (sp_flowtext_parent_class))->update) { + ((SPObjectClass *) (sp_flowtext_parent_class))->update(object, ctx, flags); } if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -225,8 +199,8 @@ sp_flowtext_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *r { object->_requireSVGVersion(Inkscape::Version(1, 2)); - if (((SPObjectClass *) (parent_class))->build) { - (* ((SPObjectClass *) (parent_class))->build)(object, document, repr); + if (((SPObjectClass *) (sp_flowtext_parent_class))->build) { + (* ((SPObjectClass *) (sp_flowtext_parent_class))->build)(object, document, repr); } object->readAttr( "inkscape:layoutOptions" ); // must happen after css has been read @@ -284,8 +258,8 @@ sp_flowtext_set(SPObject *object, unsigned key, gchar const *value) break; } default: - if (((SPObjectClass *) (parent_class))->set) { - (* ((SPObjectClass *) (parent_class))->set)(object, key, value); + if (((SPObjectClass *) (sp_flowtext_parent_class))->set) { + (* ((SPObjectClass *) (sp_flowtext_parent_class))->set)(object, key, value); } break; } @@ -320,8 +294,8 @@ static Inkscape::XML::Node *sp_flowtext_write(SPObject *object, Inkscape::XML::D } } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_flowtext_parent_class))->write) { + ((SPObjectClass *) (sp_flowtext_parent_class))->write(object, xml_doc, repr, flags); } return repr; @@ -404,8 +378,8 @@ sp_flowtext_show(SPItem *item, Inkscape::Drawing &drawing, unsigned/* key*/, uns static void sp_flowtext_hide(SPItem *item, unsigned int key) { - if (((SPItemClass *) parent_class)->hide) - ((SPItemClass *) parent_class)->hide(item, key); + if (((SPItemClass *) sp_flowtext_parent_class)->hide) + ((SPItemClass *) sp_flowtext_parent_class)->hide(item, key); } diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp index 719375688..e14ef8667 100644 --- a/src/sp-glyph.cpp +++ b/src/sp-glyph.cpp @@ -23,46 +23,18 @@ #include "document.h" #include -static void sp_glyph_class_init(SPGlyphClass *gc); -static void sp_glyph_init(SPGlyph *glyph); - static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_glyph_release(SPObject *object); static void sp_glyph_set(SPObject *object, unsigned int key, const gchar *value); static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_glyph_update(SPObject *object, SPCtx *ctx, guint flags); -static SPObjectClass *parent_class; - -GType sp_glyph_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPGlyphClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_glyph_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPGlyph), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_glyph_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPGlyph", &info, (GTypeFlags) 0); - } - - return type; -} +G_DEFINE_TYPE(SPGlyph, sp_glyph, SP_TYPE_OBJECT); static void sp_glyph_class_init(SPGlyphClass *gc) { SPObjectClass *sp_object_class = (SPObjectClass *) gc; - parent_class = (SPObjectClass*)g_type_class_peek_parent(gc); - sp_object_class->build = sp_glyph_build; sp_object_class->release = sp_glyph_release; sp_object_class->set = sp_glyph_set; @@ -88,8 +60,8 @@ static void sp_glyph_init(SPGlyph *glyph) static void sp_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); + if (((SPObjectClass *) (sp_glyph_parent_class))->build) { + ((SPObjectClass *) (sp_glyph_parent_class))->build(object, document, repr); } object->readAttr( "unicode" ); @@ -108,8 +80,8 @@ static void sp_glyph_release(SPObject *object) { //SPGlyph *glyph = SP_GLYPH(object); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); + if (((SPObjectClass *) sp_glyph_parent_class)->release) { + ((SPObjectClass *) sp_glyph_parent_class)->release(object); } } @@ -233,8 +205,8 @@ static void sp_glyph_set(SPObject *object, unsigned int key, const gchar *value) } default: { - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); + if (((SPObjectClass *) (sp_glyph_parent_class))->set) { + ((SPObjectClass *) (sp_glyph_parent_class))->set(object, key, value); } break; } @@ -264,8 +236,8 @@ sp_glyph_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "vert-adv-y" ); } - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_glyph_parent_class)->update) { + ((SPObjectClass *) sp_glyph_parent_class)->update(object, ctx, flags); } } @@ -306,8 +278,8 @@ static Inkscape::XML::Node *sp_glyph_write(SPObject *object, Inkscape::XML::Docu COPY_ATTR(repr, object->getRepr(), "vert-adv-y"); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_glyph_parent_class))->write) { + ((SPObjectClass *) (sp_glyph_parent_class))->write(object, xml_doc, repr, flags); } return repr; diff --git a/src/sp-missing-glyph.cpp b/src/sp-missing-glyph.cpp index fdf75253e..bdf993e5b 100644 --- a/src/sp-missing-glyph.cpp +++ b/src/sp-missing-glyph.cpp @@ -21,45 +21,17 @@ #include "sp-missing-glyph.h" #include "document.h" -static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc); -static void sp_missing_glyph_init(SPMissingGlyph *glyph); - static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_missing_glyph_release(SPObject *object); static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar *value); static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *parent_class; - -GType sp_missing_glyph_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPMissingGlyphClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_missing_glyph_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPMissingGlyph), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_missing_glyph_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPMissingGlyph", &info, (GTypeFlags) 0); - } - - return type; -} +G_DEFINE_TYPE(SPMissingGlyph, sp_missing_glyph, SP_TYPE_OBJECT); static void sp_missing_glyph_class_init(SPMissingGlyphClass *gc) { SPObjectClass *sp_object_class = (SPObjectClass *) gc; - parent_class = (SPObjectClass*)g_type_class_peek_parent(gc); - sp_object_class->build = sp_missing_glyph_build; sp_object_class->release = sp_missing_glyph_release; sp_object_class->set = sp_missing_glyph_set; @@ -78,8 +50,8 @@ static void sp_missing_glyph_init(SPMissingGlyph *glyph) static void sp_missing_glyph_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); + if (((SPObjectClass *) (sp_missing_glyph_parent_class))->build) { + ((SPObjectClass *) (sp_missing_glyph_parent_class))->build(object, document, repr); } object->readAttr( "d" ); @@ -93,8 +65,8 @@ static void sp_missing_glyph_release(SPObject *object) { //SPMissingGlyph *glyph = SP_MISSING_GLYPH(object); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); + if (((SPObjectClass *) sp_missing_glyph_parent_class)->release) { + ((SPObjectClass *) sp_missing_glyph_parent_class)->release(object); } } @@ -150,8 +122,8 @@ static void sp_missing_glyph_set(SPObject *object, unsigned int key, const gchar } default: { - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); + if (((SPObjectClass *) (sp_missing_glyph_parent_class))->set) { + ((SPObjectClass *) (sp_missing_glyph_parent_class))->set(object, key, value); } break; } @@ -186,8 +158,8 @@ static Inkscape::XML::Node *sp_missing_glyph_write(SPObject *object, Inkscape::X COPY_ATTR(repr, object->getRepr(), "vert-adv-y"); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_missing_glyph_parent_class))->write) { + ((SPObjectClass *) (sp_missing_glyph_parent_class))->write(object, xml_doc, repr, flags); } return repr; diff --git a/src/sp-object.h b/src/sp-object.h index b3f3e6c2f..5828eda13 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -800,10 +800,7 @@ private: public: - /** - * Registers the SPObject class with Gdk and returns its type number. - */ - static GType get_type(); + static GType get_type() {return sp_object_get_type();} /** * Callback for attr_changed node event. diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index bc8a46252..95511aea3 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -68,8 +68,6 @@ class SPDocument; * radius (look in object-edit). */ -static void sp_offset_class_init (SPOffsetClass * klass); -static void sp_offset_init (SPOffset * offset); static void sp_offset_finalize(GObject *obj); static void sp_offset_build (SPObject * object, SPDocument * document, @@ -102,38 +100,7 @@ static void sp_offset_source_modified (SPObject *iSource, guint flags, SPItem *i // reappearing in offset when the radius becomes too large static bool use_slow_but_correct_offset_method=false; - -// nothing special here, same for every class in sodipodi/inkscape -static SPShapeClass *parent_class; - -/** - * Register SPOffset class and return its type number. - */ -GType -sp_offset_get_type (void) -{ - static GType offset_type = 0; - - if (!offset_type) - { - GTypeInfo offset_info = { - sizeof (SPOffsetClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_offset_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (SPOffset), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_offset_init, - NULL, /* value_table */ - }; - offset_type = - g_type_register_static (SP_TYPE_SHAPE, "SPOffset", &offset_info, - (GTypeFlags) 0); - } - return offset_type; -} +G_DEFINE_TYPE(SPOffset, sp_offset, SP_TYPE_SHAPE); /** * SPOffset vtable initialization. @@ -146,8 +113,6 @@ sp_offset_class_init(SPOffsetClass *klass) SPItemClass *item_class = (SPItemClass *) klass; SPShapeClass *shape_class = (SPShapeClass *) klass; - parent_class = (SPShapeClass *) g_type_class_ref (SP_TYPE_SHAPE); - gobject_class->finalize = sp_offset_finalize; sp_object_class->build = sp_offset_build; @@ -213,8 +178,8 @@ sp_offset_finalize(GObject *obj) static void sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build (object, document, repr); + if (((SPObjectClass *) sp_offset_parent_class)->build) + ((SPObjectClass *) sp_offset_parent_class)->build (object, document, repr); //XML Tree being used directly here while it shouldn't be. if (object->getRepr()->attribute("inkscape:radius")) { @@ -290,8 +255,8 @@ sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM repr->setAttribute("d", d); g_free (d); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, + if (((SPObjectClass *) (sp_offset_parent_class))->write) + ((SPObjectClass *) (sp_offset_parent_class))->write (object, xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; @@ -317,8 +282,8 @@ sp_offset_release(SPObject *object) offset->sourceHref = NULL; offset->sourceRef->detach(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); + if (((SPObjectClass *) sp_offset_parent_class)->release) { + ((SPObjectClass *) sp_offset_parent_class)->release (object); } } @@ -389,8 +354,8 @@ sp_offset_set(SPObject *object, unsigned key, gchar const *value) } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + if (((SPObjectClass *) sp_offset_parent_class)->set) + ((SPObjectClass *) sp_offset_parent_class)->set (object, key, value); break; } } @@ -411,8 +376,8 @@ sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) } offset->isUpdating=false; - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + if (((SPObjectClass *) sp_offset_parent_class)->update) + ((SPObjectClass *) sp_offset_parent_class)->update (object, ctx, flags); } /** @@ -725,8 +690,8 @@ sp_offset_set_shape(SPShape *shape) */ static void sp_offset_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - if (((SPItemClass *) parent_class)->snappoints) { - ((SPItemClass *) parent_class)->snappoints (item, p, snapprefs); + if (((SPItemClass *) sp_offset_parent_class)->snappoints) { + ((SPItemClass *) sp_offset_parent_class)->snappoints (item, p, snapprefs); } } diff --git a/src/sp-paint-server.cpp b/src/sp-paint-server.cpp index ae4a60ba6..298b39117 100644 --- a/src/sp-paint-server.cpp +++ b/src/sp-paint-server.cpp @@ -20,12 +20,8 @@ #include "sp-gradient.h" #include "xml/node.h" -static void sp_paint_server_class_init(SPPaintServerClass *psc); - static cairo_pattern_t *sp_paint_server_create_dummy_pattern(SPPaintServer *ps, cairo_t *ct, Geom::OptRect const &bbox, double opacity); -static SPObjectClass *parent_class; - SPPaintServer *SPPaintServerReference::getObject() const { return static_cast(URIReference::getObject()); @@ -36,35 +32,15 @@ bool SPPaintServerReference::_acceptObject(SPObject *obj) const return SP_IS_PAINT_SERVER(obj); } -GType SPPaintServer::get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPPaintServerClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_paint_server_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPPaintServer), - 16, /* n_preallocs */ - (GInstanceInitFunc) SPPaintServer::init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPPaintServer", &info, (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(SPPaintServer, sp_paint_server, SP_TYPE_OBJECT); static void sp_paint_server_class_init(SPPaintServerClass *psc) { psc->pattern_new = sp_paint_server_create_dummy_pattern; - - parent_class = static_cast(g_type_class_ref(SP_TYPE_OBJECT)); } -void SPPaintServer::init(SPPaintServer * /*ps*/) +static void +sp_paint_server_init(SPPaintServer * /*ps*/) { } diff --git a/src/sp-paint-server.h b/src/sp-paint-server.h index a266ee5a5..f4948dfdb 100644 --- a/src/sp-paint-server.h +++ b/src/sp-paint-server.h @@ -20,24 +20,21 @@ #include "sp-object.h" #include "uri-references.h" -#define SP_TYPE_PAINT_SERVER (SPPaintServer::get_type()) +#define SP_TYPE_PAINT_SERVER (sp_paint_server_get_type()) #define SP_PAINT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_PAINT_SERVER, SPPaintServer)) #define SP_PAINT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_PAINT_SERVER, SPPaintServerClass)) #define SP_IS_PAINT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_PAINT_SERVER)) #define SP_IS_PAINT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_PAINT_SERVER)) +GType sp_paint_server_get_type(void) G_GNUC_CONST; + struct SPPaintServer : public SPObject { protected: bool swatch; public: - static GType get_type(void); - bool isSwatch() const; bool isSolid() const; - -private: - static void init(SPPaintServer *ps); }; struct SPPaintServerClass { diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 107ceac16..478a689e3 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -51,8 +51,6 @@ #define noPATH_VERBOSE -static void sp_path_class_init(SPPathClass *klass); -static void sp_path_init(SPPath *path); static void sp_path_finalize(GObject *obj); static void sp_path_release(SPObject *object); @@ -67,31 +65,7 @@ static void sp_path_convert_to_guides(SPItem *item); static void sp_path_update(SPObject *object, SPCtx *ctx, guint flags); static void sp_path_update_patheffect(SPLPEItem *lpeitem, bool write); -static SPShapeClass *parent_class; - -/** - * Gets the GType object for SPPathClass - */ -GType -sp_path_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPPathClass), - NULL, NULL, - (GClassInitFunc) sp_path_class_init, - NULL, NULL, - sizeof(SPPath), - 16, - (GInstanceInitFunc) sp_path_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_SHAPE, "SPPath", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPPath, sp_path, SP_TYPE_SHAPE); /** * Does the object-oriented work of initializing the class structure @@ -106,8 +80,6 @@ sp_path_class_init(SPPathClass * klass) SPItemClass *item_class = (SPItemClass *) klass; SPLPEItemClass *lpe_item_class = (SPLPEItemClass *) klass; - parent_class = (SPShapeClass *)g_type_class_peek_parent(klass); - gobject_class->finalize = sp_path_finalize; sp_object_class->build = sp_path_build; @@ -216,8 +188,8 @@ sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) sp_conn_end_pair_build(object); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_path_parent_class)->build) { + ((SPObjectClass *) sp_path_parent_class)->build(object, document, repr); } object->readAttr( "inkscape:original-d" ); @@ -237,8 +209,8 @@ sp_path_release(SPObject *object) path->connEndPair.release(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); + if (((SPObjectClass *) sp_path_parent_class)->release) { + ((SPObjectClass *) sp_path_parent_class)->release(object); } } @@ -294,8 +266,8 @@ sp_path_set(SPObject *object, unsigned int key, gchar const *value) path->connEndPair.setAttr(key, value); break; default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_path_parent_class)->set) { + ((SPObjectClass *) sp_path_parent_class)->set(object, key, value); } break; } @@ -337,8 +309,8 @@ g_message("sp_path_write writes 'd' attribute"); SP_PATH(shape)->connEndPair.writeRepr(repr); - if (((SPObjectClass *)(parent_class))->write) { - ((SPObjectClass *)(parent_class))->write(object, xml_doc, repr, flags); + if (((SPObjectClass *)(sp_path_parent_class))->write) { + ((SPObjectClass *)(sp_path_parent_class))->write(object, xml_doc, repr, flags); } return repr; @@ -351,8 +323,8 @@ sp_path_update(SPObject *object, SPCtx *ctx, guint flags) flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_path_parent_class)->update) { + ((SPObjectClass *) sp_path_parent_class)->update(object, ctx, flags); } SPPath *path = SP_PATH(object); diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 2e14ae5ff..da7a575b7 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -7,42 +7,16 @@ #include "style.h" using Inkscape::XML::TEXT_NODE; -static void sp_style_elem_init(SPStyleElem *style_elem); -static void sp_style_elem_class_init(SPStyleElemClass *klass); static void sp_style_elem_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr); static void sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value); static void sp_style_elem_read_content(SPObject *); static Inkscape::XML::Node *sp_style_elem_write(SPObject *, Inkscape::XML::Document *, Inkscape::XML::Node *, guint flags); -static SPObjectClass *parent_class; - -GType -sp_style_elem_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPStyleElemClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_style_elem_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(SPStyleElem), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_style_elem_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_OBJECT, "SPStyleElem", &info, (GTypeFlags) 0); - } - - return type; -} +G_DEFINE_TYPE(SPStyleElem, sp_style_elem, SP_TYPE_OBJECT); static void sp_style_elem_class_init(SPStyleElemClass *klass) { - parent_class = (SPObjectClass *)g_type_class_ref(SP_TYPE_OBJECT); /* FIXME */ klass->build = sp_style_elem_build; @@ -89,8 +63,8 @@ sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value /* title is ignored. */ default: { - if (parent_class->set) { - parent_class->set(object, key, value); + if (SP_OBJECT_CLASS(sp_style_elem_parent_class)->set) { + SP_OBJECT_CLASS(sp_style_elem_parent_class)->set(object, key, value); } break; } @@ -138,8 +112,8 @@ sp_style_elem_write(SPObject *const object, Inkscape::XML::Document *xml_doc, In } /* todo: media */ - if (((SPObjectClass *) parent_class)->write) - ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags); + if (((SPObjectClass *) sp_style_elem_parent_class)->write) + ((SPObjectClass *) sp_style_elem_parent_class)->write(object, xml_doc, repr, flags); return repr; } @@ -402,8 +376,8 @@ sp_style_elem_build(SPObject *object, SPDocument *document, Inkscape::XML::Node }; rec_add_listener(*repr, &nodeEventVector, object); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_style_elem_parent_class)->build) { + ((SPObjectClass *) sp_style_elem_parent_class)->build(object, document, repr); } } diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 56f862bf3..d4db403e3 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -26,9 +26,6 @@ #include "sp-symbol.h" #include "document.h" -static void sp_symbol_class_init (SPSymbolClass *klass); -static void sp_symbol_init (SPSymbol *symbol); - static void sp_symbol_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_symbol_release (SPObject *object); static void sp_symbol_set (SPObject *object, unsigned int key, const gchar *value); @@ -42,35 +39,13 @@ static void sp_symbol_hide (SPItem *item, unsigned int key); static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type); static void sp_symbol_print (SPItem *item, SPPrintContext *ctx); -static SPGroupClass *parent_class; - -GType -sp_symbol_get_type (void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof (SPSymbolClass), - NULL, NULL, - (GClassInitFunc) sp_symbol_class_init, - NULL, NULL, - sizeof (SPSymbol), - 16, - (GInstanceInitFunc) sp_symbol_init, - NULL, /* value_table */ - }; - type = g_type_register_static (SP_TYPE_GROUP, "SPSymbol", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPSymbol, sp_symbol, SP_TYPE_GROUP); static void sp_symbol_class_init(SPSymbolClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *) klass; SPItemClass *sp_item_class = (SPItemClass *) klass; - parent_class = (SPGroupClass *)g_type_class_ref (SP_TYPE_GROUP); - sp_object_class->build = sp_symbol_build; sp_object_class->release = sp_symbol_release; sp_object_class->set = sp_symbol_set; @@ -97,15 +72,15 @@ static void sp_symbol_build(SPObject *object, SPDocument *document, Inkscape::XM object->readAttr( "viewBox" ); object->readAttr( "preserveAspectRatio" ); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); + if (((SPObjectClass *) sp_symbol_parent_class)->build) { + ((SPObjectClass *) sp_symbol_parent_class)->build (object, document, repr); } } static void sp_symbol_release(SPObject *object) { - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); + if (((SPObjectClass *) sp_symbol_parent_class)->release) { + ((SPObjectClass *) sp_symbol_parent_class)->release (object); } } @@ -202,16 +177,16 @@ static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + if (((SPObjectClass *) sp_symbol_parent_class)->set) + ((SPObjectClass *) sp_symbol_parent_class)->set (object, key, value); break; } } static void sp_symbol_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - if (((SPObjectClass *) (parent_class))->child_added) { - ((SPObjectClass *) (parent_class))->child_added (object, child, ref); + if (((SPObjectClass *) (sp_symbol_parent_class))->child_added) { + ((SPObjectClass *) (sp_symbol_parent_class))->child_added (object, child, ref); } } @@ -315,8 +290,8 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) } // And invoke parent method - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, (SPCtx *) &rctx, flags); + if (((SPObjectClass *) (sp_symbol_parent_class))->update) { + ((SPObjectClass *) (sp_symbol_parent_class))->update (object, (SPCtx *) &rctx, flags); } // As last step set additional transform of drawing group @@ -326,8 +301,8 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) } } else { // No-op - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, ctx, flags); + if (((SPObjectClass *) (sp_symbol_parent_class))->update) { + ((SPObjectClass *) (sp_symbol_parent_class))->update (object, ctx, flags); } } } @@ -336,8 +311,8 @@ static void sp_symbol_modified(SPObject *object, guint flags) { SP_SYMBOL(object); - if (((SPObjectClass *) (parent_class))->modified) { - (* ((SPObjectClass *) (parent_class))->modified) (object, flags); + if (((SPObjectClass *) (sp_symbol_parent_class))->modified) { + (* ((SPObjectClass *) (sp_symbol_parent_class))->modified) (object, flags); } } @@ -355,8 +330,8 @@ static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Doc //XML Tree being used directly here while it shouldn't be. repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio")); - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_symbol_parent_class))->write) { + ((SPObjectClass *) (sp_symbol_parent_class))->write (object, xml_doc, repr, flags); } return repr; @@ -369,8 +344,8 @@ static Inkscape::DrawingItem *sp_symbol_show(SPItem *item, Inkscape::Drawing &dr if (symbol->cloned) { // Cloned is actually renderable - if (((SPItemClass *) (parent_class))->show) { - ai = ((SPItemClass *) (parent_class))->show (item, drawing, key, flags); + if (((SPItemClass *) (sp_symbol_parent_class))->show) { + ai = ((SPItemClass *) (sp_symbol_parent_class))->show (item, drawing, key, flags); Inkscape::DrawingGroup *g = dynamic_cast(ai); if (g) { g->setChildTransform(symbol->c2p); @@ -387,8 +362,8 @@ static void sp_symbol_hide(SPItem *item, unsigned int key) if (symbol->cloned) { /* Cloned is actually renderable */ - if (((SPItemClass *) (parent_class))->hide) { - ((SPItemClass *) (parent_class))->hide (item, key); + if (((SPItemClass *) (sp_symbol_parent_class))->hide) { + ((SPItemClass *) (sp_symbol_parent_class))->hide (item, key); } } } @@ -401,15 +376,15 @@ static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &tran if (symbol->cloned) { // Cloned is actually renderable - if (((SPItemClass *) (parent_class))->bbox) { + if (((SPItemClass *) (sp_symbol_parent_class))->bbox) { Geom::Affine const a( symbol->c2p * transform ); - bbox = ((SPItemClass *) (parent_class))->bbox(item, a, type); + bbox = ((SPItemClass *) (sp_symbol_parent_class))->bbox(item, a, type); } } else { // Need bounding box for Symbols dialog Geom::Affine const a; - bbox = ((SPItemClass *) (parent_class))->bbox(item, a, type); + bbox = ((SPItemClass *) (sp_symbol_parent_class))->bbox(item, a, type); } return bbox; } @@ -422,8 +397,8 @@ static void sp_symbol_print(SPItem *item, SPPrintContext *ctx) sp_print_bind(ctx, symbol->c2p, 1.0); - if (((SPItemClass *) (parent_class))->print) { - ((SPItemClass *) (parent_class))->print (item, ctx); + if (((SPItemClass *) (sp_symbol_parent_class))->print) { + ((SPItemClass *) (sp_symbol_parent_class))->print (item, ctx); } sp_print_release (ctx); diff --git a/src/text-context.cpp b/src/text-context.cpp index 90715b805..1ee21e732 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -57,8 +57,6 @@ using Inkscape::ControlManager; using Inkscape::DocumentUndo; -static void sp_text_context_class_init(SPTextContextClass *klass); -static void sp_text_context_init(SPTextContext *text_context); static void sp_text_context_dispose(GObject *obj); static void sp_text_context_setup(SPEventContext *ec); @@ -81,34 +79,13 @@ static gint sptc_focus_in(GtkWidget *widget, GdkEventFocus *event, SPTextContext static gint sptc_focus_out(GtkWidget *widget, GdkEventFocus *event, SPTextContext *tc); static void sptc_commit(GtkIMContext *imc, gchar *string, SPTextContext *tc); -static SPEventContextClass *parent_class; - -GType sp_text_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPTextContextClass), - NULL, NULL, - (GClassInitFunc) sp_text_context_class_init, - NULL, NULL, - sizeof(SPTextContext), - 4, - (GInstanceInitFunc) sp_text_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPTextContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPTextContext, sp_text_context, SP_TYPE_EVENT_CONTEXT); static void sp_text_context_class_init(SPTextContextClass *klass) { GObjectClass *object_class=G_OBJECT_CLASS(klass); SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_text_context_dispose; event_context_class->setup = sp_text_context_setup; @@ -173,8 +150,8 @@ static void sp_text_context_dispose(GObject *obj) tc->text_sel_end.~iterator(); tc->text_sel_start.~iterator(); tc->text_selection_quads.~vector(); - if (G_OBJECT_CLASS(parent_class)->dispose) { - G_OBJECT_CLASS(parent_class)->dispose(obj); + if (G_OBJECT_CLASS(sp_text_context_parent_class)->dispose) { + G_OBJECT_CLASS(sp_text_context_parent_class)->dispose(obj); } if (tc->grabbed) { sp_canvas_item_ungrab(tc->grabbed, GDK_CURRENT_TIME); @@ -236,8 +213,8 @@ static void sp_text_context_setup(SPEventContext *ec) } } - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup(ec); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -455,8 +432,8 @@ static gint sp_text_context_item_handler(SPEventContext *event_context, SPItem * } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler) - ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler(event_context, item, event); + if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler) + ret = (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler(event_context, item, event); } return ret; @@ -1324,8 +1301,8 @@ static gint sp_text_context_root_handler(SPEventContext *const event_context, Gd } // if nobody consumed it so far - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { // and there's a handler in parent context, - return (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); // send event to parent + if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler) { // and there's a handler in parent context, + return (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler(event_context, event); // send event to parent } else { return FALSE; // return "I did nothing" value so that global shortcuts can be activated } diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 870b9cce1..28e4c1629 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -81,35 +81,13 @@ using Inkscape::DocumentUndo; #define DYNA_MIN_WIDTH 1.0e-6 -static void sp_tweak_context_class_init(SPTweakContextClass *klass); -static void sp_tweak_context_init(SPTweakContext *ddc); static void sp_tweak_context_dispose(GObject *object); static void sp_tweak_context_setup(SPEventContext *ec); static void sp_tweak_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val); static gint sp_tweak_context_root_handler(SPEventContext *ec, GdkEvent *event); -static SPEventContextClass *parent_class; - -GType -sp_tweak_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPTweakContextClass), - NULL, NULL, - (GClassInitFunc) sp_tweak_context_class_init, - NULL, NULL, - sizeof(SPTweakContext), - 4, - (GInstanceInitFunc) sp_tweak_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPTweakContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPTweakContext, sp_tweak_context, SP_TYPE_EVENT_CONTEXT); static void sp_tweak_context_class_init(SPTweakContextClass *klass) @@ -117,8 +95,6 @@ sp_tweak_context_class_init(SPTweakContextClass *klass) GObjectClass *object_class = G_OBJECT_CLASS(klass); SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_tweak_context_dispose; event_context_class->setup = sp_tweak_context_setup; @@ -173,7 +149,7 @@ sp_tweak_context_dispose(GObject *object) delete tc->_message_context; } - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_tweak_context_parent_class)->dispose(object); } static bool is_transform_mode (gint mode) @@ -290,8 +266,8 @@ sp_tweak_context_setup(SPEventContext *ec) { SPTweakContext *tc = SP_TWEAK_CONTEXT(ec); - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->setup(ec); } { @@ -1535,8 +1511,8 @@ sp_tweak_context_root_handler(SPEventContext *event_context, } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->root_handler(event_context, event); } } diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp index 9311901d3..7a5e4f90e 100644 --- a/src/zoom-context.cpp +++ b/src/zoom-context.cpp @@ -26,48 +26,23 @@ #include "zoom-context.h" -static void sp_zoom_context_class_init(SPZoomContextClass *klass); -static void sp_zoom_context_init(SPZoomContext *zoom_context); static void sp_zoom_context_setup(SPEventContext *ec); static void sp_zoom_context_finish (SPEventContext *ec); static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent *event); static gint sp_zoom_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event); -static SPEventContextClass *parent_class; - static gint xp = 0, yp = 0; // where drag started static gint tolerance = 0; static bool within_tolerance = false; static bool escaped; -GType sp_zoom_context_get_type(void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof(SPZoomContextClass), - NULL, NULL, - (GClassInitFunc) sp_zoom_context_class_init, - NULL, NULL, - sizeof(SPZoomContext), - 4, - (GInstanceInitFunc) sp_zoom_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPZoomContext", &info, (GTypeFlags) 0); - } - - return type; -} +G_DEFINE_TYPE(SPZoomContext, sp_zoom_context, SP_TYPE_EVENT_CONTEXT); static void sp_zoom_context_class_init(SPZoomContextClass *klass) { SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - event_context_class->setup = sp_zoom_context_setup; event_context_class->finish = sp_zoom_context_finish; @@ -107,8 +82,8 @@ static void sp_zoom_context_setup(SPEventContext *ec) ec->enableGrDrag(); } - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup(ec); } } @@ -116,8 +91,8 @@ static gint sp_zoom_context_item_handler(SPEventContext *event_context, SPItem * { gint ret = FALSE; - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->item_handler (event_context, item, event); + if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler (event_context, item, event); } return ret; @@ -264,8 +239,8 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler(event_context, event); } } -- cgit v1.2.3 From 1615436543169f305d1df4d830ed8f5ec5dc75ed Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 26 Jan 2013 19:33:04 +0000 Subject: More GObject boilerplate reduction (bzr r12065) --- src/connector-context.cpp | 39 ++--------- src/display/sp-canvas.cpp | 133 ++++++++++++-------------------------- src/display/sp-canvas.h | 6 +- src/dyna-draw-context.cpp | 42 +++--------- src/ege-adjustment-action.cpp | 41 ++---------- src/ege-color-prof-tracker.cpp | 31 +-------- src/ege-select-one-action.cpp | 40 ++---------- src/filters/blend.cpp | 49 ++++---------- src/filters/colormatrix.cpp | 49 ++++---------- src/filters/componenttransfer.cpp | 55 +++++----------- src/filters/composite.cpp | 49 ++++---------- src/filters/convolvematrix.cpp | 49 ++++---------- src/filters/diffuselighting.cpp | 60 +++++------------ src/filters/displacementmap.cpp | 49 ++++---------- src/filters/distantlight.cpp | 46 +++---------- src/filters/gaussian-blur.cpp | 49 ++++---------- src/filters/image.cpp | 48 ++++---------- src/filters/merge.cpp | 49 ++++---------- src/filters/mergenode.cpp | 45 +++---------- src/filters/morphology.cpp | 49 ++++---------- src/filters/offset.cpp | 49 ++++---------- src/filters/pointlight.cpp | 46 +++---------- src/filters/specularlighting.cpp | 60 +++++------------ src/filters/spotlight.cpp | 46 +++---------- src/filters/tile.cpp | 49 ++++---------- src/filters/turbulence.cpp | 49 ++++---------- src/gradient-context.cpp | 36 ++--------- src/helper/action.cpp | 41 ++---------- src/helper/unit-menu.cpp | 27 +------- src/ink-comboboxentry-action.cpp | 44 +++---------- src/lpe-tool-context.cpp | 49 ++++---------- src/mesh-context.cpp | 36 ++--------- src/pencil-context.cpp | 37 ++--------- src/sp-filter.cpp | 58 +++++------------ src/sp-lpe-item.cpp | 63 ++++++------------ src/sp-mask.cpp | 45 +++---------- src/sp-metadata.cpp | 49 ++++---------- src/sp-pattern.cpp | 42 ++---------- src/sp-title.cpp | 30 +-------- src/ui/tool/node-tool.cpp | 78 +++++++++------------- src/widgets/button.cpp | 45 +++++-------- src/widgets/icon.cpp | 44 +++---------- src/widgets/icon.h | 6 +- 43 files changed, 463 insertions(+), 1544 deletions(-) (limited to 'src') diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 24a7203ac..9631eecb1 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -109,8 +109,6 @@ using Inkscape::DocumentUndo; -static void sp_connector_context_class_init(SPConnectorContextClass *klass); -static void sp_connector_context_init(SPConnectorContext *conn_context); static void sp_connector_context_dispose(GObject *object); static void sp_connector_context_setup(SPEventContext *ec); @@ -156,8 +154,6 @@ static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *nam /*static Geom::Point connector_drag_origin_w(0, 0); static bool connector_within_tolerance = false;*/ -static SPEventContextClass *parent_class; - static Inkscape::XML::NodeEventVector shape_repr_events = { NULL, /* child_added */ @@ -175,26 +171,7 @@ static Inkscape::XML::NodeEventVector layer_repr_events = { NULL /* order_changed */ }; - -GType -sp_connector_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPConnectorContextClass), - NULL, NULL, - (GClassInitFunc) sp_connector_context_class_init, - NULL, NULL, - sizeof(SPConnectorContext), - 4, - (GInstanceInitFunc) sp_connector_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPConnectorContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPConnectorContext, sp_connector_context, SP_TYPE_EVENT_CONTEXT); static void sp_connector_context_class_init(SPConnectorContextClass *klass) @@ -202,8 +179,6 @@ sp_connector_context_class_init(SPConnectorContextClass *klass) GObjectClass *object_class = G_OBJECT_CLASS(klass); SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_connector_context_dispose; event_context_class->setup = sp_connector_context_setup; @@ -283,7 +258,7 @@ sp_connector_context_dispose(GObject *object) } g_assert( cc->newConnRef == NULL ); - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_connector_context_parent_class)->dispose(object); } @@ -293,8 +268,8 @@ sp_connector_context_setup(SPEventContext *ec) SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); SPDesktop *dt = ec->desktop; - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->setup) { + (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->setup(ec); } cc->selection = sp_desktop_selection(dt); @@ -358,8 +333,8 @@ sp_connector_context_finish(SPEventContext *ec) spcc_connector_finish(cc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; - if ((SP_EVENT_CONTEXT_CLASS(parent_class))->finish) { - (SP_EVENT_CONTEXT_CLASS(parent_class))->finish(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->finish) { + (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->finish(ec); } if (cc->selection) { @@ -560,7 +535,7 @@ sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event) if (!ret) { gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler; + = (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->root_handler; if (parent_root_handler) { ret = parent_root_handler(ec, event); } diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index eb51860ab..8b20ab2de 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -226,21 +226,6 @@ public: */ static int pickCurrentItem(SPCanvas *canvas, GdkEvent *event); - /** - * Class initialization function for SPCanvasClass. - */ - static void classInit(SPCanvasClass *klass); - - /** - * Callback: object initialization for SPCanvas. - */ - static void init(SPCanvas *canvas); - - /** - * Destroy handler for SPCanvas. - */ - static void dispose(GObject *object); - /** * The canvas widget's realize callback. */ @@ -368,26 +353,12 @@ public: */ static void add_idle(SPCanvas *canvas); - /** - * Convenience function to remove the idle handler of a canvas. - */ - static void remove_idle(SPCanvas *canvas); - - /** - * Removes the transient state of the canvas (idle handler, grabs). - */ - static void shutdown_transients(SPCanvas *canvas); - /** * Update callback for canvas widget. */ static void requestCanvasUpdate(SPCanvas *canvas); - - static GtkWidgetClass *parentClass; }; -GtkWidgetClass *SPCanvasImpl::parentClass = 0; - GType SPCanvasItem::getType() { static GType object_type = 0; @@ -437,9 +408,9 @@ void sp_canvas_item_class_init(SPCanvasItemClass *klass) G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT); - gobject_class->dispose = sp_canvas_item_dispose; + gobject_class->dispose = sp_canvas_item_dispose; gobject_class->finalize = sp_canvas_item_finalize; - klass->destroy = sp_canvas_item_real_destroy; + klass->destroy = sp_canvas_item_real_destroy; object_signals[DESTROY] = g_signal_new ("destroy", @@ -1218,68 +1189,46 @@ void SPCanvasGroup::remove(SPCanvasItem *item) } } -/** - * Registers the SPCanvas class if necessary, and returns the type ID - * associated to it. - * - * @return The type ID of the SPCanvas class. - */ -GType SPCanvas::getType(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPCanvasClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)SPCanvasImpl::classInit, - 0, // class_finalize - 0, // class_data - sizeof(SPCanvas), - 0, // n_preallocs - (GInstanceInitFunc)SPCanvasImpl::init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_WIDGET, "SPCanvas", &info, static_cast(0)); - } - return type; -} +static void sp_canvas_dispose (GObject *object); +static void sp_canvas_shutdown_transients(SPCanvas *canvas); -void SPCanvasImpl::classInit(SPCanvasClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; +G_DEFINE_TYPE(SPCanvas, sp_canvas, GTK_TYPE_WIDGET); - parentClass = reinterpret_cast(g_type_class_peek_parent(klass)); +static void +sp_canvas_class_init(SPCanvasClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - object_class->dispose = SPCanvasImpl::dispose; + object_class->dispose = sp_canvas_dispose; - widget_class->realize = SPCanvasImpl::realize; - widget_class->unrealize = SPCanvasImpl::unrealize; + widget_class->realize = SPCanvasImpl::realize; + widget_class->unrealize = SPCanvasImpl::unrealize; #if GTK_CHECK_VERSION(3,0,0) - widget_class->get_preferred_width = SPCanvasImpl::getPreferredWidth; + widget_class->get_preferred_width = SPCanvasImpl::getPreferredWidth; widget_class->get_preferred_height = SPCanvasImpl::getPreferredHeight; - widget_class->draw = SPCanvasImpl::handleDraw; + widget_class->draw = SPCanvasImpl::handleDraw; #else - widget_class->size_request = SPCanvasImpl::sizeRequest; - widget_class->expose_event = SPCanvasImpl::handleExpose; + widget_class->size_request = SPCanvasImpl::sizeRequest; + widget_class->expose_event = SPCanvasImpl::handleExpose; #endif - widget_class->size_allocate = SPCanvasImpl::sizeAllocate; - widget_class->button_press_event = SPCanvasImpl::button; + widget_class->size_allocate = SPCanvasImpl::sizeAllocate; + widget_class->button_press_event = SPCanvasImpl::button; widget_class->button_release_event = SPCanvasImpl::button; - widget_class->motion_notify_event = SPCanvasImpl::handleMotion; - widget_class->scroll_event = SPCanvasImpl::handleScroll; - widget_class->key_press_event = SPCanvasImpl::handleKeyEvent; - widget_class->key_release_event = SPCanvasImpl::handleKeyEvent; - widget_class->enter_notify_event = SPCanvasImpl::handleCrossing; - widget_class->leave_notify_event = SPCanvasImpl::handleCrossing; - widget_class->focus_in_event = SPCanvasImpl::handleFocusIn; - widget_class->focus_out_event = SPCanvasImpl::handleFocusOut; + widget_class->motion_notify_event = SPCanvasImpl::handleMotion; + widget_class->scroll_event = SPCanvasImpl::handleScroll; + widget_class->key_press_event = SPCanvasImpl::handleKeyEvent; + widget_class->key_release_event = SPCanvasImpl::handleKeyEvent; + widget_class->enter_notify_event = SPCanvasImpl::handleCrossing; + widget_class->leave_notify_event = SPCanvasImpl::handleCrossing; + widget_class->focus_in_event = SPCanvasImpl::handleFocusIn; + widget_class->focus_out_event = SPCanvasImpl::handleFocusOut; } -void SPCanvasImpl::init(SPCanvas *canvas) +static void +sp_canvas_init(SPCanvas *canvas) { gtk_widget_set_has_window (GTK_WIDGET (canvas), TRUE); gtk_widget_set_double_buffered (GTK_WIDGET (canvas), FALSE); @@ -1318,7 +1267,7 @@ void SPCanvasImpl::init(SPCanvas *canvas) canvas->is_scrolling = false; } -void SPCanvasImpl::remove_idle(SPCanvas *canvas) +static void sp_canvas_remove_idle(SPCanvas *canvas) { if (canvas->idle_id) { g_source_remove (canvas->idle_id); @@ -1326,7 +1275,8 @@ void SPCanvasImpl::remove_idle(SPCanvas *canvas) } } -void SPCanvasImpl::shutdown_transients(SPCanvas *canvas) +static void +sp_canvas_shutdown_transients(SPCanvas *canvas) { // We turn off the need_redraw flag, since if the canvas is mapped again // it will request a redraw anyways. We do not turn off the need_update @@ -1352,10 +1302,11 @@ void SPCanvasImpl::shutdown_transients(SPCanvas *canvas) #endif } - remove_idle(canvas); + sp_canvas_remove_idle(canvas); } -void SPCanvasImpl::dispose(GObject *object) +static void +sp_canvas_dispose(GObject *object) { SPCanvas *canvas = SP_CANVAS(object); @@ -1364,12 +1315,12 @@ void SPCanvasImpl::dispose(GObject *object) canvas->root = NULL; } - shutdown_transients(canvas); + sp_canvas_shutdown_transients(canvas); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) canvas->cms_key.~ustring(); #endif - if (G_OBJECT_CLASS(parentClass)->dispose) { - (* G_OBJECT_CLASS(parentClass)->dispose)(object); + if (G_OBJECT_CLASS(sp_canvas_parent_class)->dispose) { + (* G_OBJECT_CLASS(sp_canvas_parent_class)->dispose)(object); } } @@ -1388,7 +1339,7 @@ void trackLatency(GdkEvent const *event) GtkWidget *SPCanvas::createAA() { - SPCanvas *canvas = reinterpret_cast(g_object_new(SPCanvas::getType(), NULL)); + SPCanvas *canvas = SP_CANVAS(g_object_new(SP_TYPE_CANVAS, NULL)); return GTK_WIDGET(canvas); } @@ -1456,10 +1407,10 @@ void SPCanvasImpl::unrealize(GtkWidget *widget) canvas->grabbed_item = NULL; canvas->focused_item = NULL; - shutdown_transients(canvas); + sp_canvas_shutdown_transients(canvas); - if (GTK_WIDGET_CLASS(parentClass)->unrealize) - (* GTK_WIDGET_CLASS(parentClass)->unrealize)(widget); + if (GTK_WIDGET_CLASS(sp_canvas_parent_class)->unrealize) + (* GTK_WIDGET_CLASS(sp_canvas_parent_class)->unrealize)(widget); } diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index f0366a2e5..b570b739e 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS -#define SP_TYPE_CANVAS (SPCanvas::getType()) +#define SP_TYPE_CANVAS (sp_canvas_get_type()) #define SP_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_CANVAS, SPCanvas)) #define SP_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_CANVAS)) @@ -71,14 +71,14 @@ G_END_DECLS class SPCanvasImpl; +GType sp_canvas_get_type() G_GNUC_CONST; + /** * Port of GnomeCanvas for inkscape needs. */ struct SPCanvas { friend class SPCanvasImpl; - static GType getType(); - /** * Returns new canvas as widget. */ diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index b30950f5a..742d52f09 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -81,8 +81,6 @@ using Inkscape::DocumentUndo; #define DYNA_MIN_WIDTH 1.0e-6 -static void sp_dyna_draw_context_class_init(SPDynaDrawContextClass *klass); -static void sp_dyna_draw_context_init(SPDynaDrawContext *ddc); static void sp_dyna_draw_context_dispose(GObject *object); static void sp_dyna_draw_context_setup(SPEventContext *ec); @@ -101,29 +99,7 @@ static Geom::Point sp_dyna_draw_get_npoint(SPDynaDrawContext const *ddc, Geom::P static Geom::Point sp_dyna_draw_get_vpoint(SPDynaDrawContext const *ddc, Geom::Point n); static void draw_temporary_box(SPDynaDrawContext *dc); - -static SPEventContextClass *dd_parent_class = 0; - -GType sp_dyna_draw_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPDynaDrawContextClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_dyna_draw_context_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPDynaDrawContext), - 0, // n_preallocs - (GInstanceInitFunc)sp_dyna_draw_context_init, - 0 // value_table - }; - type = g_type_register_static(SP_TYPE_COMMON_CONTEXT, "SPDynaDrawContext", &info, static_cast(0)); - } - return type; -} +G_DEFINE_TYPE(SPDynaDrawContext, sp_dyna_draw_context, SP_TYPE_COMMON_CONTEXT); static void sp_dyna_draw_context_class_init(SPDynaDrawContextClass *klass) @@ -131,8 +107,6 @@ sp_dyna_draw_context_class_init(SPDynaDrawContextClass *klass) GObjectClass *object_class = G_OBJECT_CLASS(klass); SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - dd_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_dyna_draw_context_dispose; event_context_class->setup = sp_dyna_draw_context_setup; @@ -182,7 +156,7 @@ sp_dyna_draw_context_dispose(GObject *object) } - G_OBJECT_CLASS(dd_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_dyna_draw_context_parent_class)->dispose(object); ddc->hatch_pointer_past.~list(); ddc->hatch_nearest_past.~list(); @@ -195,8 +169,8 @@ sp_dyna_draw_context_setup(SPEventContext *ec) { SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - if ((SP_EVENT_CONTEXT_CLASS(dd_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(dd_parent_class))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup) + (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup(ec); ddc->accumulated = new SPCurve(); ddc->currentcurve = new SPCurve(); @@ -262,8 +236,8 @@ sp_dyna_draw_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) ddc->keep_selected = val->getBool(); } else { //pass on up to parent class to handle common attributes. - if ( dd_parent_class->set ) { - dd_parent_class->set(ec, val); + if ( SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set ) { + SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set(ec, val); } } @@ -974,8 +948,8 @@ sp_dyna_draw_context_root_handler(SPEventContext *event_context, } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(dd_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(dd_parent_class))->root_handler(event_context, event); + if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler) { + ret = (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler(event_context, event); } } diff --git a/src/ege-adjustment-action.cpp b/src/ege-adjustment-action.cpp index 8253818d2..5a827096f 100644 --- a/src/ege-adjustment-action.cpp +++ b/src/ege-adjustment-action.cpp @@ -50,8 +50,6 @@ #include "ui/widget/gimpspinscale.h" -static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ); -static void ege_adjustment_action_init( EgeAdjustmentAction* action ); static void ege_adjustment_action_finalize( GObject* object ); static void ege_adjustment_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); static void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); @@ -70,8 +68,6 @@ static void ege_adjustment_action_defocus( EgeAdjustmentAction* action ); static void egeAct_free_description( gpointer data, gpointer user_data ); static void egeAct_free_all_descriptions( EgeAdjustmentAction* action ); - -static GtkActionClass* gParentClass = 0; static EgeCreateAdjWidgetCB gFactoryCb = 0; static GQuark gDataName = 0; @@ -146,34 +142,11 @@ enum { BUMP_CUSTOM = 100 }; -GType ege_adjustment_action_get_type( void ) -{ - static GType myType = 0; - if ( !myType ) { - static const GTypeInfo myInfo = { - sizeof( EgeAdjustmentActionClass ), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc)ege_adjustment_action_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof( EgeAdjustmentAction ), - 0, /* n_preallocs */ - (GInstanceInitFunc)ege_adjustment_action_init, - NULL - }; - - myType = g_type_register_static( GTK_TYPE_ACTION, "EgeAdjustmentAction", &myInfo, (GTypeFlags)0 ); - } - - return myType; -} - +G_DEFINE_TYPE(EgeAdjustmentAction, ege_adjustment_action, GTK_TYPE_ACTION); static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) { if ( klass ) { - gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) ); GObjectClass * objClass = G_OBJECT_CLASS( klass ); gDataName = g_quark_from_string("ege-adj-action"); @@ -308,8 +281,8 @@ static void ege_adjustment_action_finalize( GObject* object ) egeAct_free_all_descriptions( action ); - if ( G_OBJECT_CLASS(gParentClass)->finalize ) { - (*G_OBJECT_CLASS(gParentClass)->finalize)(object); + if ( G_OBJECT_CLASS(ege_adjustment_action_parent_class)->finalize ) { + (*G_OBJECT_CLASS(ege_adjustment_action_parent_class)->finalize)(object); } } @@ -772,7 +745,7 @@ static GtkWidget* create_menu_item( GtkAction* action ) gtk_widget_show_all( subby ); g_value_unset( &value ); } else { - item = gParentClass->create_menu_item( action ); + item = GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->create_menu_item( action ); } return item; @@ -910,7 +883,7 @@ static GtkWidget* create_tool_item( GtkAction* action ) g_value_unset( &value ); } else { - item = gParentClass->create_tool_item( action ); + item = GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->create_tool_item( action ); } return item; @@ -918,12 +891,12 @@ static GtkWidget* create_tool_item( GtkAction* action ) static void connect_proxy( GtkAction *action, GtkWidget *proxy ) { - gParentClass->connect_proxy( action, proxy ); + GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->connect_proxy( action, proxy ); } static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ) { - gParentClass->disconnect_proxy( action, proxy ); + GTK_ACTION_CLASS(ege_adjustment_action_parent_class)->disconnect_proxy( action, proxy ); } void ege_adjustment_action_defocus( EgeAdjustmentAction* action ) diff --git a/src/ege-color-prof-tracker.cpp b/src/ege-color-prof-tracker.cpp index c0e095a98..2e1b8188f 100644 --- a/src/ege-color-prof-tracker.cpp +++ b/src/ege-color-prof-tracker.cpp @@ -90,11 +90,9 @@ enum { ADDED, REMOVED, MODIFIED, - LAST_SIGNAL}; - + LAST_SIGNAL +}; -static void ege_color_prof_tracker_class_init( EgeColorProfTrackerClass* klass ); -static void ege_color_prof_tracker_init( EgeColorProfTracker* tracker ); static void ege_color_prof_tracker_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); static void ege_color_prof_tracker_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); @@ -114,7 +112,6 @@ void handle_property_change(GdkScreen* screen, const gchar* name); void add_x11_tracking_for_screen(GdkScreen* screen, ScreenTrack* screenTrack); #endif /* GDK_WINDOWING_X11 */ -static GObjectClass* gParentClass = 0; static guint signals[LAST_SIGNAL] = {0}; static GSList* tracked_screens = 0; @@ -140,33 +137,11 @@ static void clear_profile( GdkScreen* screen, guint monitor ); static void set_profile( GdkScreen* screen, guint monitor, const guint8* data, guint len ); static void track_screen( GdkScreen* screen, EgeColorProfTracker* tracker ); -GType ege_color_prof_tracker_get_type( void ) -{ - static GType myType = 0; - if ( !myType ) { - static const GTypeInfo myInfo = { - sizeof( EgeColorProfTrackerClass ), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc)ege_color_prof_tracker_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof( EgeColorProfTracker ), - 0, /* n_preallocs */ - (GInstanceInitFunc)ege_color_prof_tracker_init, - NULL - }; - - myType = g_type_register_static( G_TYPE_OBJECT, "EgeColorProfTracker", &myInfo, (GTypeFlags)0 ); - } - - return myType; -} +G_DEFINE_TYPE(EgeColorProfTracker, ege_color_prof_tracker, G_TYPE_OBJECT); void ege_color_prof_tracker_class_init( EgeColorProfTrackerClass* klass ) { if ( klass ) { - gParentClass = G_OBJECT_CLASS( g_type_class_peek_parent( klass ) ); GObjectClass* objClass = G_OBJECT_CLASS( klass ); objClass->get_property = ege_color_prof_tracker_get_property; diff --git a/src/ege-select-one-action.cpp b/src/ege-select-one-action.cpp index a5d92e809..33cfd04f2 100644 --- a/src/ege-select-one-action.cpp +++ b/src/ege-select-one-action.cpp @@ -49,9 +49,6 @@ enum { CHANGED = 0, LAST_SIGNAL}; - -static void ege_select_one_action_class_init( EgeSelectOneActionClass* klass ); -static void ege_select_one_action_init( EgeSelectOneAction* action ); static void ege_select_one_action_finalize( GObject* action ); static void ege_select_one_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); static void ege_select_one_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); @@ -73,7 +70,6 @@ static void disconnect_proxy( GtkAction *action, GtkWidget *proxy ); static int scan_max_width( GtkTreeModel *model, gint labelColumn ); -static GtkActionClass* gParentClass = 0; static guint signals[LAST_SIGNAL] = {0}; static GQuark gDataName = 0; @@ -126,28 +122,7 @@ enum { PROP_SELECTION }; -GType ege_select_one_action_get_type( void ) -{ - static GType myType = 0; - if ( !myType ) { - static const GTypeInfo myInfo = { - sizeof( EgeSelectOneActionClass ), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc)ege_select_one_action_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof( EgeSelectOneAction ), - 0, /* n_preallocs */ - (GInstanceInitFunc)ege_select_one_action_init, - NULL - }; - - myType = g_type_register_static( GTK_TYPE_ACTION, "EgeSelectOneAction", &myInfo, (GTypeFlags)0 ); - } - - return myType; -} +G_DEFINE_TYPE(EgeSelectOneAction, ege_select_one_action, GTK_TYPE_ACTION); GtkTreeModel *ege_select_one_action_get_model(EgeSelectOneAction* action ){ return GTK_TREE_MODEL(action->private_data->model); @@ -155,7 +130,6 @@ GtkTreeModel *ege_select_one_action_get_model(EgeSelectOneAction* action ){ void ege_select_one_action_class_init( EgeSelectOneActionClass* klass ) { if ( klass ) { - gParentClass = GTK_ACTION_CLASS( g_type_class_peek_parent( klass ) ); GObjectClass* objClass = G_OBJECT_CLASS( klass ); gDataName = g_quark_from_string("ege-select1-action"); @@ -292,8 +266,8 @@ void ege_select_one_action_finalize( GObject* object ) g_free( action->private_data->appearance ); g_free( action->private_data->selection ); - if ( G_OBJECT_CLASS(gParentClass)->finalize ) { - (*G_OBJECT_CLASS(gParentClass)->finalize)(object); + if ( G_OBJECT_CLASS(ege_select_one_action_parent_class)->finalize ) { + (*G_OBJECT_CLASS(ege_select_one_action_parent_class)->finalize)(object); } } @@ -631,7 +605,7 @@ GtkWidget* create_menu_item( GtkAction* action ) g_free(sss); } else { - item = gParentClass->create_menu_item( action ); + item = GTK_ACTION_CLASS(ege_select_one_action_parent_class)->create_menu_item( action ); } return item; @@ -855,7 +829,7 @@ GtkWidget* create_tool_item( GtkAction* action ) gtk_widget_show_all( item ); } else { - item = gParentClass->create_tool_item( action ); + item = GTK_ACTION_CLASS(ege_select_one_action_parent_class)->create_tool_item( action ); } return item; @@ -864,12 +838,12 @@ GtkWidget* create_tool_item( GtkAction* action ) void connect_proxy( GtkAction *action, GtkWidget *proxy ) { - gParentClass->connect_proxy( action, proxy ); + GTK_ACTION_CLASS(ege_select_one_action_parent_class)->connect_proxy( action, proxy ); } void disconnect_proxy( GtkAction *action, GtkWidget *proxy ) { - gParentClass->disconnect_proxy( action, proxy ); + GTK_ACTION_CLASS(ege_select_one_action_parent_class)->disconnect_proxy( action, proxy ); } diff --git a/src/filters/blend.cpp b/src/filters/blend.cpp index 809bd6c00..a43927e81 100644 --- a/src/filters/blend.cpp +++ b/src/filters/blend.cpp @@ -31,10 +31,6 @@ #include "display/nr-filter-types.h" /* FeBlend base class */ - -static void sp_feBlend_class_init(SPFeBlendClass *klass); -static void sp_feBlend_init(SPFeBlend *feBlend); - static void sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feBlend_release(SPObject *object); static void sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value); @@ -42,28 +38,7 @@ static void sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feBlend_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feBlend_build_renderer(SPFilterPrimitive *sp_prim, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feBlend_parent_class; - -GType -sp_feBlend_get_type() -{ - static GType feBlend_type = 0; - - if (!feBlend_type) { - GTypeInfo feBlend_info = { - sizeof(SPFeBlendClass), - NULL, NULL, - (GClassInitFunc) sp_feBlend_class_init, - NULL, NULL, - sizeof(SPFeBlend), - 16, - (GInstanceInitFunc) sp_feBlend_init, - NULL, /* value_table */ - }; - feBlend_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeBlend", &feBlend_info, (GTypeFlags)0); - } - return feBlend_type; -} +G_DEFINE_TYPE(SPFeBlend, sp_feBlend, SP_TYPE_FILTER_PRIMITIVE); static void sp_feBlend_class_init(SPFeBlendClass *klass) @@ -71,8 +46,6 @@ sp_feBlend_class_init(SPFeBlendClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feBlend_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feBlend_build; sp_object_class->release = sp_feBlend_release; sp_object_class->write = sp_feBlend_write; @@ -98,8 +71,8 @@ sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re { SPFeBlend *blend = SP_FEBLEND(object); - if (((SPObjectClass *) feBlend_parent_class)->build) { - ((SPObjectClass *) feBlend_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feBlend_parent_class)->build) { + ((SPObjectClass *) sp_feBlend_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -123,8 +96,8 @@ sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re static void sp_feBlend_release(SPObject *object) { - if (((SPObjectClass *) feBlend_parent_class)->release) - ((SPObjectClass *) feBlend_parent_class)->release(object); + if (((SPObjectClass *) sp_feBlend_parent_class)->release) + ((SPObjectClass *) sp_feBlend_parent_class)->release(object); } static Inkscape::Filters::FilterBlendMode sp_feBlend_readmode(gchar const *value) @@ -186,8 +159,8 @@ sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - if (((SPObjectClass *) feBlend_parent_class)->set) - ((SPObjectClass *) feBlend_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feBlend_parent_class)->set) + ((SPObjectClass *) sp_feBlend_parent_class)->set(object, key, value); break; } @@ -218,8 +191,8 @@ sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags) object->getRepr()->setAttribute("in2", sp_filter_name_for_image(parent, blend->in2)); } - if (((SPObjectClass *) feBlend_parent_class)->update) { - ((SPObjectClass *) feBlend_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feBlend_parent_class)->update) { + ((SPObjectClass *) sp_feBlend_parent_class)->update(object, ctx, flags); } } @@ -267,8 +240,8 @@ sp_feBlend_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML:: } repr->setAttribute("mode", mode); - if (((SPObjectClass *) feBlend_parent_class)->write) { - ((SPObjectClass *) feBlend_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feBlend_parent_class)->write) { + ((SPObjectClass *) sp_feBlend_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/colormatrix.cpp b/src/filters/colormatrix.cpp index b88b84037..aaf1c2986 100644 --- a/src/filters/colormatrix.cpp +++ b/src/filters/colormatrix.cpp @@ -30,10 +30,6 @@ #include "display/nr-filter-colormatrix.h" /* FeColorMatrix base class */ - -static void sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass); -static void sp_feColorMatrix_init(SPFeColorMatrix *feColorMatrix); - static void sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feColorMatrix_release(SPObject *object); static void sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *value); @@ -41,28 +37,7 @@ static void sp_feColorMatrix_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feColorMatrix_parent_class; - -GType -sp_feColorMatrix_get_type() -{ - static GType feColorMatrix_type = 0; - - if (!feColorMatrix_type) { - GTypeInfo feColorMatrix_info = { - sizeof(SPFeColorMatrixClass), - NULL, NULL, - (GClassInitFunc) sp_feColorMatrix_class_init, - NULL, NULL, - sizeof(SPFeColorMatrix), - 16, - (GInstanceInitFunc) sp_feColorMatrix_init, - NULL, /* value_table */ - }; - feColorMatrix_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeColorMatrix", &feColorMatrix_info, (GTypeFlags)0); - } - return feColorMatrix_type; -} +G_DEFINE_TYPE(SPFeColorMatrix, sp_feColorMatrix, SP_TYPE_FILTER_PRIMITIVE); static void sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass) @@ -70,8 +45,6 @@ sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feColorMatrix_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feColorMatrix_build; sp_object_class->release = sp_feColorMatrix_release; sp_object_class->write = sp_feColorMatrix_write; @@ -93,8 +66,8 @@ sp_feColorMatrix_init(SPFeColorMatrix */*feColorMatrix*/) static void sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feColorMatrix_parent_class)->build) { - ((SPObjectClass *) feColorMatrix_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feColorMatrix_parent_class)->build) { + ((SPObjectClass *) sp_feColorMatrix_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -108,8 +81,8 @@ sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::No static void sp_feColorMatrix_release(SPObject *object) { - if (((SPObjectClass *) feColorMatrix_parent_class)->release) - ((SPObjectClass *) feColorMatrix_parent_class)->release(object); + if (((SPObjectClass *) sp_feColorMatrix_parent_class)->release) + ((SPObjectClass *) sp_feColorMatrix_parent_class)->release(object); } static Inkscape::Filters::FilterColorMatrixType sp_feColorMatrix_read_type(gchar const *value){ @@ -158,8 +131,8 @@ sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *str) } break; default: - if (((SPObjectClass *) feColorMatrix_parent_class)->set) - ((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, str); + if (((SPObjectClass *) sp_feColorMatrix_parent_class)->set) + ((SPObjectClass *) sp_feColorMatrix_parent_class)->set(object, key, str); break; } } @@ -177,8 +150,8 @@ sp_feColorMatrix_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feColorMatrix_parent_class)->update) { - ((SPObjectClass *) feColorMatrix_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feColorMatrix_parent_class)->update) { + ((SPObjectClass *) sp_feColorMatrix_parent_class)->update(object, ctx, flags); } } @@ -194,8 +167,8 @@ sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape: repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feColorMatrix_parent_class)->write) { - ((SPObjectClass *) feColorMatrix_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feColorMatrix_parent_class)->write) { + ((SPObjectClass *) sp_feColorMatrix_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/componenttransfer.cpp b/src/filters/componenttransfer.cpp index 8cc388dd0..71e1ffe8e 100644 --- a/src/filters/componenttransfer.cpp +++ b/src/filters/componenttransfer.cpp @@ -28,10 +28,6 @@ #include "display/nr-filter-component-transfer.h" /* FeComponentTransfer base class */ - -static void sp_feComponentTransfer_class_init(SPFeComponentTransferClass *klass); -static void sp_feComponentTransfer_init(SPFeComponentTransfer *feComponentTransfer); - static void sp_feComponentTransfer_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feComponentTransfer_release(SPObject *object); static void sp_feComponentTransfer_set(SPObject *object, unsigned int key, gchar const *value); @@ -40,35 +36,14 @@ static void sp_feComponentTransfer_build_renderer(SPFilterPrimitive *primitive, static void sp_feComponentTransfer_remove_child(SPObject *object, Inkscape::XML::Node *child); static void sp_feComponentTransfer_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref); static Inkscape::XML::Node *sp_feComponentTransfer_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPFilterPrimitiveClass *feComponentTransfer_parent_class; -GType -sp_feComponentTransfer_get_type() -{ - static GType feComponentTransfer_type = 0; - - if (!feComponentTransfer_type) { - GTypeInfo feComponentTransfer_info = { - sizeof(SPFeComponentTransferClass), - NULL, NULL, - (GClassInitFunc) sp_feComponentTransfer_class_init, - NULL, NULL, - sizeof(SPFeComponentTransfer), - 16, - (GInstanceInitFunc) sp_feComponentTransfer_init, - NULL, /* value_table */ - }; - feComponentTransfer_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeComponentTransfer", &feComponentTransfer_info, (GTypeFlags)0); - } - return feComponentTransfer_type; -} +G_DEFINE_TYPE(SPFeComponentTransfer, sp_feComponentTransfer, SP_TYPE_FILTER_PRIMITIVE); static void sp_feComponentTransfer_class_init(SPFeComponentTransferClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feComponentTransfer_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); sp_object_class->build = sp_feComponentTransfer_build; sp_object_class->release = sp_feComponentTransfer_release; @@ -93,8 +68,8 @@ sp_feComponentTransfer_init(SPFeComponentTransfer */*feComponentTransfer*/) static void sp_feComponentTransfer_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feComponentTransfer_parent_class)->build) { - ((SPObjectClass *) feComponentTransfer_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->build) { + ((SPObjectClass *) sp_feComponentTransfer_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -144,8 +119,8 @@ sp_feComponentTransfer_child_added(SPObject *object, Inkscape::XML::Node *child, { SPFeComponentTransfer *f = SP_FECOMPONENTTRANSFER(object); - if (((SPObjectClass *) feComponentTransfer_parent_class)->child_added) - (* ((SPObjectClass *) feComponentTransfer_parent_class)->child_added)(object, child, ref); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->child_added) + (* ((SPObjectClass *) sp_feComponentTransfer_parent_class)->child_added)(object, child, ref); sp_feComponentTransfer_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -160,8 +135,8 @@ sp_feComponentTransfer_remove_child(SPObject *object, Inkscape::XML::Node *child { SPFeComponentTransfer *f = SP_FECOMPONENTTRANSFER(object); - if (((SPObjectClass *) feComponentTransfer_parent_class)->remove_child) - (* ((SPObjectClass *) feComponentTransfer_parent_class)->remove_child)(object, child); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->remove_child) + (* ((SPObjectClass *) sp_feComponentTransfer_parent_class)->remove_child)(object, child); sp_feComponentTransfer_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -173,8 +148,8 @@ sp_feComponentTransfer_remove_child(SPObject *object, Inkscape::XML::Node *child static void sp_feComponentTransfer_release(SPObject *object) { - if (((SPObjectClass *) feComponentTransfer_parent_class)->release) - ((SPObjectClass *) feComponentTransfer_parent_class)->release(object); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->release) + ((SPObjectClass *) sp_feComponentTransfer_parent_class)->release(object); } /** @@ -189,8 +164,8 @@ sp_feComponentTransfer_set(SPObject *object, unsigned int key, gchar const *valu switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ default: - if (((SPObjectClass *) feComponentTransfer_parent_class)->set) - ((SPObjectClass *) feComponentTransfer_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->set) + ((SPObjectClass *) sp_feComponentTransfer_parent_class)->set(object, key, value); break; } } @@ -208,8 +183,8 @@ sp_feComponentTransfer_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feComponentTransfer_parent_class)->update) { - ((SPObjectClass *) feComponentTransfer_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->update) { + ((SPObjectClass *) sp_feComponentTransfer_parent_class)->update(object, ctx, flags); } } @@ -225,8 +200,8 @@ sp_feComponentTransfer_write(SPObject *object, Inkscape::XML::Document *doc, Ink repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feComponentTransfer_parent_class)->write) { - ((SPObjectClass *) feComponentTransfer_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feComponentTransfer_parent_class)->write) { + ((SPObjectClass *) sp_feComponentTransfer_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/composite.cpp b/src/filters/composite.cpp index 66e8e3415..d490f336c 100644 --- a/src/filters/composite.cpp +++ b/src/filters/composite.cpp @@ -26,10 +26,6 @@ #include "sp-filter.h" /* FeComposite base class */ - -static void sp_feComposite_class_init(SPFeCompositeClass *klass); -static void sp_feComposite_init(SPFeComposite *feComposite); - static void sp_feComposite_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feComposite_release(SPObject *object); static void sp_feComposite_set(SPObject *object, unsigned int key, gchar const *value); @@ -37,28 +33,7 @@ static void sp_feComposite_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feComposite_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feComposite_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feComposite_parent_class; - -GType -sp_feComposite_get_type() -{ - static GType feComposite_type = 0; - - if (!feComposite_type) { - GTypeInfo feComposite_info = { - sizeof(SPFeCompositeClass), - NULL, NULL, - (GClassInitFunc) sp_feComposite_class_init, - NULL, NULL, - sizeof(SPFeComposite), - 16, - (GInstanceInitFunc) sp_feComposite_init, - NULL, /* value_table */ - }; - feComposite_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeComposite", &feComposite_info, (GTypeFlags)0); - } - return feComposite_type; -} +G_DEFINE_TYPE(SPFeComposite, sp_feComposite, SP_TYPE_FILTER_PRIMITIVE); static void sp_feComposite_class_init(SPFeCompositeClass *klass) @@ -66,8 +41,6 @@ sp_feComposite_class_init(SPFeCompositeClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feComposite_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feComposite_build; sp_object_class->release = sp_feComposite_release; sp_object_class->write = sp_feComposite_write; @@ -96,8 +69,8 @@ sp_feComposite_init(SPFeComposite *feComposite) static void sp_feComposite_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feComposite_parent_class)->build) { - ((SPObjectClass *) feComposite_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feComposite_parent_class)->build) { + ((SPObjectClass *) sp_feComposite_parent_class)->build(object, document, repr); } SPFeComposite *comp = SP_FECOMPOSITE(object); @@ -128,8 +101,8 @@ sp_feComposite_build(SPObject *object, SPDocument *document, Inkscape::XML::Node static void sp_feComposite_release(SPObject *object) { - if (((SPObjectClass *) feComposite_parent_class)->release) - ((SPObjectClass *) feComposite_parent_class)->release(object); + if (((SPObjectClass *) sp_feComposite_parent_class)->release) + ((SPObjectClass *) sp_feComposite_parent_class)->release(object); } static FeCompositeOperator @@ -212,8 +185,8 @@ sp_feComposite_set(SPObject *object, unsigned int key, gchar const *value) break; default: - if (((SPObjectClass *) feComposite_parent_class)->set) - ((SPObjectClass *) feComposite_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feComposite_parent_class)->set) + ((SPObjectClass *) sp_feComposite_parent_class)->set(object, key, value); break; } @@ -246,8 +219,8 @@ sp_feComposite_update(SPObject *object, SPCtx *ctx, guint flags) object->getRepr()->setAttribute("in2", sp_filter_name_for_image(parent, comp->in2)); } - if (((SPObjectClass *) feComposite_parent_class)->update) { - ((SPObjectClass *) feComposite_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feComposite_parent_class)->update) { + ((SPObjectClass *) sp_feComposite_parent_class)->update(object, ctx, flags); } } @@ -309,8 +282,8 @@ sp_feComposite_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::X repr->setAttribute("k4", 0); } - if (((SPObjectClass *) feComposite_parent_class)->write) { - ((SPObjectClass *) feComposite_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feComposite_parent_class)->write) { + ((SPObjectClass *) sp_feComposite_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/convolvematrix.cpp b/src/filters/convolvematrix.cpp index 470bfb64a..d002ef731 100644 --- a/src/filters/convolvematrix.cpp +++ b/src/filters/convolvematrix.cpp @@ -29,10 +29,6 @@ #include "display/nr-filter-convolve-matrix.h" /* FeConvolveMatrix base class */ - -static void sp_feConvolveMatrix_class_init(SPFeConvolveMatrixClass *klass); -static void sp_feConvolveMatrix_init(SPFeConvolveMatrix *feConvolveMatrix); - static void sp_feConvolveMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feConvolveMatrix_release(SPObject *object); static void sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value); @@ -40,28 +36,7 @@ static void sp_feConvolveMatrix_update(SPObject *object, SPCtx *ctx, guint flags static Inkscape::XML::Node *sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feConvolveMatrix_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feConvolveMatrix_parent_class; - -GType -sp_feConvolveMatrix_get_type() -{ - static GType feConvolveMatrix_type = 0; - - if (!feConvolveMatrix_type) { - GTypeInfo feConvolveMatrix_info = { - sizeof(SPFeConvolveMatrixClass), - NULL, NULL, - (GClassInitFunc) sp_feConvolveMatrix_class_init, - NULL, NULL, - sizeof(SPFeConvolveMatrix), - 16, - (GInstanceInitFunc) sp_feConvolveMatrix_init, - NULL, /* value_table */ - }; - feConvolveMatrix_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeConvolveMatrix", &feConvolveMatrix_info, (GTypeFlags)0); - } - return feConvolveMatrix_type; -} +G_DEFINE_TYPE(SPFeConvolveMatrix, sp_feConvolveMatrix, SP_TYPE_FILTER_PRIMITIVE); static void sp_feConvolveMatrix_class_init(SPFeConvolveMatrixClass *klass) @@ -69,8 +44,6 @@ sp_feConvolveMatrix_class_init(SPFeConvolveMatrixClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feConvolveMatrix_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feConvolveMatrix_build; sp_object_class->release = sp_feConvolveMatrix_release; sp_object_class->write = sp_feConvolveMatrix_write; @@ -104,8 +77,8 @@ sp_feConvolveMatrix_init(SPFeConvolveMatrix *feConvolveMatrix) static void sp_feConvolveMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feConvolveMatrix_parent_class)->build) { - ((SPObjectClass *) feConvolveMatrix_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feConvolveMatrix_parent_class)->build) { + ((SPObjectClass *) sp_feConvolveMatrix_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -126,8 +99,8 @@ sp_feConvolveMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML: static void sp_feConvolveMatrix_release(SPObject *object) { - if (((SPObjectClass *) feConvolveMatrix_parent_class)->release) - ((SPObjectClass *) feConvolveMatrix_parent_class)->release(object); + if (((SPObjectClass *) sp_feConvolveMatrix_parent_class)->release) + ((SPObjectClass *) sp_feConvolveMatrix_parent_class)->release(object); } static Inkscape::Filters::FilterConvolveMatrixEdgeMode sp_feConvolveMatrix_read_edgeMode(gchar const *value){ @@ -265,8 +238,8 @@ sp_feConvolveMatrix_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - if (((SPObjectClass *) feConvolveMatrix_parent_class)->set) - ((SPObjectClass *) feConvolveMatrix_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feConvolveMatrix_parent_class)->set) + ((SPObjectClass *) sp_feConvolveMatrix_parent_class)->set(object, key, value); break; } @@ -285,8 +258,8 @@ sp_feConvolveMatrix_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feConvolveMatrix_parent_class)->update) { - ((SPObjectClass *) feConvolveMatrix_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feConvolveMatrix_parent_class)->update) { + ((SPObjectClass *) sp_feConvolveMatrix_parent_class)->update(object, ctx, flags); } } @@ -303,8 +276,8 @@ sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Document *doc, Inksca } - if (((SPObjectClass *) feConvolveMatrix_parent_class)->write) { - ((SPObjectClass *) feConvolveMatrix_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feConvolveMatrix_parent_class)->write) { + ((SPObjectClass *) sp_feConvolveMatrix_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/diffuselighting.cpp b/src/filters/diffuselighting.cpp index 0f2f29d67..2e69f7555 100644 --- a/src/filters/diffuselighting.cpp +++ b/src/filters/diffuselighting.cpp @@ -31,10 +31,6 @@ #include "display/nr-filter-diffuselighting.h" /* FeDiffuseLighting base class */ - -static void sp_feDiffuseLighting_class_init(SPFeDiffuseLightingClass *klass); -static void sp_feDiffuseLighting_init(SPFeDiffuseLighting *feDiffuseLighting); - static void sp_feDiffuseLighting_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feDiffuseLighting_release(SPObject *object); static void sp_feDiffuseLighting_set(SPObject *object, unsigned int key, gchar const *value); @@ -52,35 +48,13 @@ static Inkscape::XML::Node *sp_feDiffuseLighting_write(SPObject *object, Inkscap static void sp_feDiffuseLighting_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); static void sp_feDiffuseLighting_children_modified(SPFeDiffuseLighting *sp_diffuselighting); -static SPFilterPrimitiveClass *feDiffuseLighting_parent_class; - -GType -sp_feDiffuseLighting_get_type() -{ - static GType feDiffuseLighting_type = 0; - - if (!feDiffuseLighting_type) { - GTypeInfo feDiffuseLighting_info = { - sizeof(SPFeDiffuseLightingClass), - NULL, NULL, - (GClassInitFunc) sp_feDiffuseLighting_class_init, - NULL, NULL, - sizeof(SPFeDiffuseLighting), - 16, - (GInstanceInitFunc) sp_feDiffuseLighting_init, - NULL, /* value_table */ - }; - feDiffuseLighting_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeDiffuseLighting", &feDiffuseLighting_info, (GTypeFlags)0); - } - return feDiffuseLighting_type; -} +G_DEFINE_TYPE(SPFeDiffuseLighting, sp_feDiffuseLighting, SP_TYPE_FILTER_PRIMITIVE); static void sp_feDiffuseLighting_class_init(SPFeDiffuseLightingClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feDiffuseLighting_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); sp_object_class->build = sp_feDiffuseLighting_build; sp_object_class->release = sp_feDiffuseLighting_release; @@ -116,8 +90,8 @@ sp_feDiffuseLighting_init(SPFeDiffuseLighting *feDiffuseLighting) static void sp_feDiffuseLighting_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feDiffuseLighting_parent_class)->build) { - ((SPObjectClass *) feDiffuseLighting_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->build) { + ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -134,8 +108,8 @@ sp_feDiffuseLighting_build(SPObject *object, SPDocument *document, Inkscape::XML static void sp_feDiffuseLighting_release(SPObject *object) { - if (((SPObjectClass *) feDiffuseLighting_parent_class)->release) - ((SPObjectClass *) feDiffuseLighting_parent_class)->release(object); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->release) + ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->release(object); } /** @@ -213,8 +187,8 @@ sp_feDiffuseLighting_set(SPObject *object, unsigned int key, gchar const *value) object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) feDiffuseLighting_parent_class)->set) - ((SPObjectClass *) feDiffuseLighting_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->set) + ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->set(object, key, value); break; } @@ -233,8 +207,8 @@ sp_feDiffuseLighting_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "lighting-color" ); } - if (((SPObjectClass *) feDiffuseLighting_parent_class)->update) { - ((SPObjectClass *) feDiffuseLighting_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->update) { + ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->update(object, ctx, flags); } } @@ -269,8 +243,8 @@ sp_feDiffuseLighting_write(SPObject *object, Inkscape::XML::Document *doc, Inksc } else repr->setAttribute("lighting-color", NULL); - if (((SPObjectClass *) feDiffuseLighting_parent_class)->write) { - ((SPObjectClass *) feDiffuseLighting_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->write) { + ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->write(object, doc, repr, flags); } return repr; @@ -284,8 +258,8 @@ sp_feDiffuseLighting_child_added(SPObject *object, Inkscape::XML::Node *child, I { SPFeDiffuseLighting *f = SP_FEDIFFUSELIGHTING(object); - if (((SPObjectClass *) feDiffuseLighting_parent_class)->child_added) - (* ((SPObjectClass *) feDiffuseLighting_parent_class)->child_added)(object, child, ref); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->child_added) + (* ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->child_added)(object, child, ref); sp_feDiffuseLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -300,8 +274,8 @@ sp_feDiffuseLighting_remove_child(SPObject *object, Inkscape::XML::Node *child) { SPFeDiffuseLighting *f = SP_FEDIFFUSELIGHTING(object); - if (((SPObjectClass *) feDiffuseLighting_parent_class)->remove_child) - (* ((SPObjectClass *) feDiffuseLighting_parent_class)->remove_child)(object, child); + if (((SPObjectClass *) sp_feDiffuseLighting_parent_class)->remove_child) + (* ((SPObjectClass *) sp_feDiffuseLighting_parent_class)->remove_child)(object, child); sp_feDiffuseLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -311,8 +285,8 @@ static void sp_feDiffuseLighting_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) { SPFeDiffuseLighting *f = SP_FEDIFFUSELIGHTING(object); - if (((SPObjectClass *) (feDiffuseLighting_parent_class))->order_changed) - (* ((SPObjectClass *) (feDiffuseLighting_parent_class))->order_changed) (object, child, old_ref, new_ref); + if (((SPObjectClass *) (sp_feDiffuseLighting_parent_class))->order_changed) + (* ((SPObjectClass *) (sp_feDiffuseLighting_parent_class))->order_changed) (object, child, old_ref, new_ref); sp_feDiffuseLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/filters/displacementmap.cpp b/src/filters/displacementmap.cpp index 69a678c26..408ffce9e 100644 --- a/src/filters/displacementmap.cpp +++ b/src/filters/displacementmap.cpp @@ -26,10 +26,6 @@ #include "display/nr-filter-displacement-map.h" /* FeDisplacementMap base class */ - -static void sp_feDisplacementMap_class_init(SPFeDisplacementMapClass *klass); -static void sp_feDisplacementMap_init(SPFeDisplacementMap *feDisplacementMap); - static void sp_feDisplacementMap_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feDisplacementMap_release(SPObject *object); static void sp_feDisplacementMap_set(SPObject *object, unsigned int key, gchar const *value); @@ -37,28 +33,7 @@ static void sp_feDisplacementMap_update(SPObject *object, SPCtx *ctx, guint flag static void sp_feDisplacementMap_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); static Inkscape::XML::Node *sp_feDisplacementMap_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPFilterPrimitiveClass *feDisplacementMap_parent_class; - -GType -sp_feDisplacementMap_get_type() -{ - static GType feDisplacementMap_type = 0; - - if (!feDisplacementMap_type) { - GTypeInfo feDisplacementMap_info = { - sizeof(SPFeDisplacementMapClass), - NULL, NULL, - (GClassInitFunc) sp_feDisplacementMap_class_init, - NULL, NULL, - sizeof(SPFeDisplacementMap), - 16, - (GInstanceInitFunc) sp_feDisplacementMap_init, - NULL, /* value_table */ - }; - feDisplacementMap_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeDisplacementMap", &feDisplacementMap_info, (GTypeFlags)0); - } - return feDisplacementMap_type; -} +G_DEFINE_TYPE(SPFeDisplacementMap, sp_feDisplacementMap, SP_TYPE_FILTER_PRIMITIVE); static void sp_feDisplacementMap_class_init(SPFeDisplacementMapClass *klass) @@ -66,8 +41,6 @@ sp_feDisplacementMap_class_init(SPFeDisplacementMapClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feDisplacementMap_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feDisplacementMap_build; sp_object_class->release = sp_feDisplacementMap_release; sp_object_class->write = sp_feDisplacementMap_write; @@ -93,8 +66,8 @@ sp_feDisplacementMap_init(SPFeDisplacementMap *feDisplacementMap) static void sp_feDisplacementMap_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feDisplacementMap_parent_class)->build) { - ((SPObjectClass *) feDisplacementMap_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feDisplacementMap_parent_class)->build) { + ((SPObjectClass *) sp_feDisplacementMap_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -121,8 +94,8 @@ sp_feDisplacementMap_build(SPObject *object, SPDocument *document, Inkscape::XML static void sp_feDisplacementMap_release(SPObject *object) { - if (((SPObjectClass *) feDisplacementMap_parent_class)->release) - ((SPObjectClass *) feDisplacementMap_parent_class)->release(object); + if (((SPObjectClass *) sp_feDisplacementMap_parent_class)->release) + ((SPObjectClass *) sp_feDisplacementMap_parent_class)->release(object); } static FilterDisplacementMapChannelSelector sp_feDisplacementMap_readChannelSelector(gchar const *value) @@ -191,8 +164,8 @@ sp_feDisplacementMap_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - if (((SPObjectClass *) feDisplacementMap_parent_class)->set) - ((SPObjectClass *) feDisplacementMap_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feDisplacementMap_parent_class)->set) + ((SPObjectClass *) sp_feDisplacementMap_parent_class)->set(object, key, value); break; } @@ -224,8 +197,8 @@ sp_feDisplacementMap_update(SPObject *object, SPCtx *ctx, guint flags) object->getRepr()->setAttribute("in2", sp_filter_name_for_image(parent, disp->in2)); } - if (((SPObjectClass *) feDisplacementMap_parent_class)->update) { - ((SPObjectClass *) feDisplacementMap_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feDisplacementMap_parent_class)->update) { + ((SPObjectClass *) sp_feDisplacementMap_parent_class)->update(object, ctx, flags); } } @@ -277,8 +250,8 @@ sp_feDisplacementMap_write(SPObject *object, Inkscape::XML::Document *doc, Inksc repr->setAttribute("yChannelSelector", get_channelselector_name(disp->yChannelSelector)); - if (((SPObjectClass *) feDisplacementMap_parent_class)->write) { - ((SPObjectClass *) feDisplacementMap_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feDisplacementMap_parent_class)->write) { + ((SPObjectClass *) sp_feDisplacementMap_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/distantlight.cpp b/src/filters/distantlight.cpp index 891049415..5e1c35a95 100644 --- a/src/filters/distantlight.cpp +++ b/src/filters/distantlight.cpp @@ -30,47 +30,19 @@ #include "macros.h" /* FeDistantLight class */ - -static void sp_fedistantlight_class_init(SPFeDistantLightClass *klass); -static void sp_fedistantlight_init(SPFeDistantLight *fedistantlight); - static void sp_fedistantlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_fedistantlight_release(SPObject *object); static void sp_fedistantlight_set(SPObject *object, unsigned int key, gchar const *value); static void sp_fedistantlight_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_fedistantlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *feDistantLight_parent_class; - -GType -sp_fedistantlight_get_type() -{ - static GType fedistantlight_type = 0; - - if (!fedistantlight_type) { - GTypeInfo fedistantlight_info = { - sizeof(SPFeDistantLightClass), - NULL, NULL, - (GClassInitFunc) sp_fedistantlight_class_init, - NULL, NULL, - sizeof(SPFeDistantLight), - 16, - (GInstanceInitFunc) sp_fedistantlight_init, - NULL, /* value_table */ - }; - fedistantlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeDistantLight", &fedistantlight_info, (GTypeFlags)0); - } - return fedistantlight_type; -} +G_DEFINE_TYPE(SPFeDistantLight, sp_fedistantlight, SP_TYPE_OBJECT); static void sp_fedistantlight_class_init(SPFeDistantLightClass *klass) { - SPObjectClass *sp_object_class = (SPObjectClass *)klass; - feDistantLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_fedistantlight_build; sp_object_class->release = sp_fedistantlight_release; sp_object_class->write = sp_fedistantlight_write; @@ -95,8 +67,8 @@ sp_fedistantlight_init(SPFeDistantLight *fedistantlight) static void sp_fedistantlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feDistantLight_parent_class)->build) { - ((SPObjectClass *) feDistantLight_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_fedistantlight_parent_class)->build) { + ((SPObjectClass *) sp_fedistantlight_parent_class)->build(object, document, repr); } //Read values of key attributes from XML nodes into object. @@ -170,8 +142,8 @@ sp_fedistantlight_set(SPObject *object, unsigned int key, gchar const *value) break; default: // See if any parents need this value. - if (((SPObjectClass *) feDistantLight_parent_class)->set) { - ((SPObjectClass *) feDistantLight_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_fedistantlight_parent_class)->set) { + ((SPObjectClass *) sp_fedistantlight_parent_class)->set(object, key, value); } break; } @@ -192,8 +164,8 @@ sp_fedistantlight_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "elevation" ); } - if (((SPObjectClass *) feDistantLight_parent_class)->update) { - ((SPObjectClass *) feDistantLight_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_fedistantlight_parent_class)->update) { + ((SPObjectClass *) sp_fedistantlight_parent_class)->update(object, ctx, flags); } } @@ -214,8 +186,8 @@ sp_fedistantlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape if (fedistantlight->elevation_set) sp_repr_set_css_double(repr, "elevation", fedistantlight->elevation); - if (((SPObjectClass *) feDistantLight_parent_class)->write) { - ((SPObjectClass *) feDistantLight_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_fedistantlight_parent_class)->write) { + ((SPObjectClass *) sp_fedistantlight_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/gaussian-blur.cpp b/src/filters/gaussian-blur.cpp index ee1af8904..ca93cf6d8 100644 --- a/src/filters/gaussian-blur.cpp +++ b/src/filters/gaussian-blur.cpp @@ -31,10 +31,6 @@ //#include "macros.h" /* GaussianBlur base class */ - -static void sp_gaussianBlur_class_init(SPGaussianBlurClass *klass); -static void sp_gaussianBlur_init(SPGaussianBlur *gaussianBlur); - static void sp_gaussianBlur_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_gaussianBlur_release(SPObject *object); static void sp_gaussianBlur_set(SPObject *object, unsigned int key, gchar const *value); @@ -42,28 +38,7 @@ static void sp_gaussianBlur_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_gaussianBlur_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_gaussianBlur_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *gaussianBlur_parent_class; - -GType -sp_gaussianBlur_get_type() -{ - static GType gaussianBlur_type = 0; - - if (!gaussianBlur_type) { - GTypeInfo gaussianBlur_info = { - sizeof(SPGaussianBlurClass), - NULL, NULL, - (GClassInitFunc) sp_gaussianBlur_class_init, - NULL, NULL, - sizeof(SPGaussianBlur), - 16, - (GInstanceInitFunc) sp_gaussianBlur_init, - NULL, /* value_table */ - }; - gaussianBlur_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPGaussianBlur", &gaussianBlur_info, (GTypeFlags)0); - } - return gaussianBlur_type; -} +G_DEFINE_TYPE(SPGaussianBlur, sp_gaussianBlur, SP_TYPE_FILTER_PRIMITIVE); static void sp_gaussianBlur_class_init(SPGaussianBlurClass *klass) @@ -71,8 +46,6 @@ sp_gaussianBlur_class_init(SPGaussianBlurClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - gaussianBlur_parent_class = (SPFilterPrimitiveClass *)g_type_class_peek_parent(klass); - sp_object_class->build = sp_gaussianBlur_build; sp_object_class->release = sp_gaussianBlur_release; sp_object_class->write = sp_gaussianBlur_write; @@ -95,8 +68,8 @@ sp_gaussianBlur_init(SPGaussianBlur */*gaussianBlur*/) static void sp_gaussianBlur_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) gaussianBlur_parent_class)->build) { - ((SPObjectClass *) gaussianBlur_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_gaussianBlur_parent_class)->build) { + ((SPObjectClass *) sp_gaussianBlur_parent_class)->build(object, document, repr); } object->readAttr( "stdDeviation" ); @@ -110,8 +83,8 @@ static void sp_gaussianBlur_release(SPObject *object) { - if (((SPObjectClass *) gaussianBlur_parent_class)->release) - ((SPObjectClass *) gaussianBlur_parent_class)->release(object); + if (((SPObjectClass *) sp_gaussianBlur_parent_class)->release) + ((SPObjectClass *) sp_gaussianBlur_parent_class)->release(object); } /** @@ -128,8 +101,8 @@ sp_gaussianBlur_set(SPObject *object, unsigned int key, gchar const *value) object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) gaussianBlur_parent_class)->set) - ((SPObjectClass *) gaussianBlur_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_gaussianBlur_parent_class)->set) + ((SPObjectClass *) sp_gaussianBlur_parent_class)->set(object, key, value); break; } @@ -145,8 +118,8 @@ sp_gaussianBlur_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "stdDeviation" ); } - if (((SPObjectClass *) gaussianBlur_parent_class)->update) { - ((SPObjectClass *) gaussianBlur_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_gaussianBlur_parent_class)->update) { + ((SPObjectClass *) sp_gaussianBlur_parent_class)->update(object, ctx, flags); } } @@ -162,8 +135,8 @@ sp_gaussianBlur_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape:: repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) gaussianBlur_parent_class)->write) { - ((SPObjectClass *) gaussianBlur_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_gaussianBlur_parent_class)->write) { + ((SPObjectClass *) sp_gaussianBlur_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/image.cpp b/src/filters/image.cpp index f6ef310f7..ec31e59a7 100644 --- a/src/filters/image.cpp +++ b/src/filters/image.cpp @@ -30,10 +30,6 @@ #include "display/nr-filter-image.h" /* FeImage base class */ - -static void sp_feImage_class_init(SPFeImageClass *klass); -static void sp_feImage_init(SPFeImage *feImage); - static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feImage_release(SPObject *object); static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value); @@ -41,35 +37,13 @@ static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feImage_parent_class; - -GType sp_feImage_get_type() -{ - static GType feImage_type = 0; - - if (!feImage_type) { - GTypeInfo feImage_info = { - sizeof(SPFeImageClass), - NULL, NULL, - (GClassInitFunc) sp_feImage_class_init, - NULL, NULL, - sizeof(SPFeImage), - 16, - (GInstanceInitFunc) sp_feImage_init, - NULL, /* value_table */ - }; - feImage_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeImage", &feImage_info, (GTypeFlags)0); - } - return feImage_type; -} +G_DEFINE_TYPE(SPFeImage, sp_feImage, SP_TYPE_FILTER_PRIMITIVE); static void sp_feImage_class_init(SPFeImageClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass * sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feImage_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feImage_build; sp_object_class->release = sp_feImage_release; sp_object_class->write = sp_feImage_write; @@ -96,8 +70,8 @@ static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::X SPFeImage *feImage = SP_FEIMAGE(object); feImage->document = document; - if (((SPObjectClass *) feImage_parent_class)->build) { - ((SPObjectClass *) feImage_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feImage_parent_class)->build) { + ((SPObjectClass *) sp_feImage_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -117,8 +91,8 @@ static void sp_feImage_release(SPObject *object) feImage->_href_modified_connection.disconnect(); if (feImage->SVGElemRef) delete feImage->SVGElemRef; - if (((SPObjectClass *) feImage_parent_class)->release) - ((SPObjectClass *) feImage_parent_class)->release(object); + if (((SPObjectClass *) sp_feImage_parent_class)->release) + ((SPObjectClass *) sp_feImage_parent_class)->release(object); } static void sp_feImage_elem_modified(SPObject* /*href*/, guint /*flags*/, SPObject* obj) @@ -247,8 +221,8 @@ static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *valu break; default: - if (((SPObjectClass *) feImage_parent_class)->set) - ((SPObjectClass *) feImage_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feImage_parent_class)->set) + ((SPObjectClass *) sp_feImage_parent_class)->set(object, key, value); break; } @@ -266,8 +240,8 @@ static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags) /* do something to trigger redisplay, updates? */ } - if (((SPObjectClass *) feImage_parent_class)->update) { - ((SPObjectClass *) feImage_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feImage_parent_class)->update) { + ((SPObjectClass *) sp_feImage_parent_class)->update(object, ctx, flags); } } @@ -282,8 +256,8 @@ static Inkscape::XML::Node * sp_feImage_write(SPObject *object, Inkscape::XML::D repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feImage_parent_class)->write) { - ((SPObjectClass *) feImage_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feImage_parent_class)->write) { + ((SPObjectClass *) sp_feImage_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/merge.cpp b/src/filters/merge.cpp index b5a6d7dad..7346a0892 100644 --- a/src/filters/merge.cpp +++ b/src/filters/merge.cpp @@ -25,10 +25,6 @@ #include "display/nr-filter-merge.h" /* FeMerge base class */ - -static void sp_feMerge_class_init(SPFeMergeClass *klass); -static void sp_feMerge_init(SPFeMerge *feMerge); - static void sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feMerge_release(SPObject *object); static void sp_feMerge_set(SPObject *object, unsigned int key, gchar const *value); @@ -36,28 +32,7 @@ static void sp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feMerge_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feMerge_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feMerge_parent_class; - -GType -sp_feMerge_get_type() -{ - static GType feMerge_type = 0; - - if (!feMerge_type) { - GTypeInfo feMerge_info = { - sizeof(SPFeMergeClass), - NULL, NULL, - (GClassInitFunc) sp_feMerge_class_init, - NULL, NULL, - sizeof(SPFeMerge), - 16, - (GInstanceInitFunc) sp_feMerge_init, - NULL, /* value_table */ - }; - feMerge_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeMerge", &feMerge_info, (GTypeFlags)0); - } - return feMerge_type; -} +G_DEFINE_TYPE(SPFeMerge, sp_feMerge, SP_TYPE_FILTER_PRIMITIVE); static void sp_feMerge_class_init(SPFeMergeClass *klass) @@ -65,8 +40,6 @@ sp_feMerge_class_init(SPFeMergeClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feMerge_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feMerge_build; sp_object_class->release = sp_feMerge_release; sp_object_class->write = sp_feMerge_write; @@ -89,8 +62,8 @@ sp_feMerge_init(SPFeMerge */*feMerge*/) static void sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feMerge_parent_class)->build) { - ((SPObjectClass *) feMerge_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feMerge_parent_class)->build) { + ((SPObjectClass *) sp_feMerge_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -102,8 +75,8 @@ sp_feMerge_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *re static void sp_feMerge_release(SPObject *object) { - if (((SPObjectClass *) feMerge_parent_class)->release) - ((SPObjectClass *) feMerge_parent_class)->release(object); + if (((SPObjectClass *) sp_feMerge_parent_class)->release) + ((SPObjectClass *) sp_feMerge_parent_class)->release(object); } /** @@ -118,8 +91,8 @@ sp_feMerge_set(SPObject *object, unsigned int key, gchar const *value) switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ default: - if (((SPObjectClass *) feMerge_parent_class)->set) - ((SPObjectClass *) feMerge_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feMerge_parent_class)->set) + ((SPObjectClass *) sp_feMerge_parent_class)->set(object, key, value); break; } @@ -135,8 +108,8 @@ sp_feMerge_update(SPObject *object, SPCtx *ctx, guint flags) object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } - if (((SPObjectClass *) feMerge_parent_class)->update) { - ((SPObjectClass *) feMerge_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feMerge_parent_class)->update) { + ((SPObjectClass *) sp_feMerge_parent_class)->update(object, ctx, flags); } } @@ -153,8 +126,8 @@ sp_feMerge_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML:: } - if (((SPObjectClass *) feMerge_parent_class)->write) { - ((SPObjectClass *) feMerge_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feMerge_parent_class)->write) { + ((SPObjectClass *) sp_feMerge_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/mergenode.cpp b/src/filters/mergenode.cpp index 639928305..fa193ad77 100644 --- a/src/filters/mergenode.cpp +++ b/src/filters/mergenode.cpp @@ -23,46 +23,19 @@ #include "filters/merge.h" #include "display/nr-filter-types.h" -static void sp_feMergeNode_class_init(SPFeMergeNodeClass *klass); -static void sp_feMergeNode_init(SPFeMergeNode *skeleton); - static void sp_feMergeNode_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feMergeNode_release(SPObject *object); static void sp_feMergeNode_set(SPObject *object, unsigned int key, gchar const *value); static void sp_feMergeNode_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feMergeNode_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *feMergeNode_parent_class; - -GType -sp_feMergeNode_get_type() -{ - static GType feMergeNode_type = 0; - - if (!feMergeNode_type) { - GTypeInfo feMergeNode_info = { - sizeof(SPFeMergeNodeClass), - NULL, NULL, - (GClassInitFunc) sp_feMergeNode_class_init, - NULL, NULL, - sizeof(SPFeMergeNode), - 16, - (GInstanceInitFunc) sp_feMergeNode_init, - NULL, /* value_table */ - }; - feMergeNode_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeMergeNode", &feMergeNode_info, (GTypeFlags)0); - } - return feMergeNode_type; -} +G_DEFINE_TYPE(SPFeMergeNode, sp_feMergeNode, SP_TYPE_OBJECT); static void sp_feMergeNode_class_init(SPFeMergeNodeClass *klass) { - //GObjectClass *gobject_class = (GObjectClass *)klass; SPObjectClass *sp_object_class = (SPObjectClass *)klass; - feMergeNode_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feMergeNode_build; sp_object_class->release = sp_feMergeNode_release; sp_object_class->write = sp_feMergeNode_write; @@ -95,8 +68,8 @@ sp_feMergeNode_release(SPObject *object) { /* deal with our children and our selves here */ - if (((SPObjectClass *) feMergeNode_parent_class)->release) - ((SPObjectClass *) feMergeNode_parent_class)->release(object); + if (((SPObjectClass *) sp_feMergeNode_parent_class)->release) + ((SPObjectClass *) sp_feMergeNode_parent_class)->release(object); } /** @@ -117,8 +90,8 @@ sp_feMergeNode_set(SPObject *object, unsigned int key, gchar const *value) } /* See if any parents need this value. */ - if (((SPObjectClass *) feMergeNode_parent_class)->set) { - ((SPObjectClass *) feMergeNode_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feMergeNode_parent_class)->set) { + ((SPObjectClass *) sp_feMergeNode_parent_class)->set(object, key, value); } } @@ -134,8 +107,8 @@ sp_feMergeNode_update(SPObject *object, SPCtx *ctx, guint flags) object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } - if (((SPObjectClass *) feMergeNode_parent_class)->update) { - ((SPObjectClass *) feMergeNode_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feMergeNode_parent_class)->update) { + ((SPObjectClass *) sp_feMergeNode_parent_class)->update(object, ctx, flags); } } @@ -157,8 +130,8 @@ sp_feMergeNode_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::X } } - if (((SPObjectClass *) feMergeNode_parent_class)->write) { - ((SPObjectClass *) feMergeNode_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feMergeNode_parent_class)->write) { + ((SPObjectClass *) sp_feMergeNode_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/morphology.cpp b/src/filters/morphology.cpp index 42327d59f..886a10311 100644 --- a/src/filters/morphology.cpp +++ b/src/filters/morphology.cpp @@ -27,10 +27,6 @@ #include "display/nr-filter-morphology.h" /* FeMorphology base class */ - -static void sp_feMorphology_class_init(SPFeMorphologyClass *klass); -static void sp_feMorphology_init(SPFeMorphology *feMorphology); - static void sp_feMorphology_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feMorphology_release(SPObject *object); static void sp_feMorphology_set(SPObject *object, unsigned int key, gchar const *value); @@ -38,36 +34,13 @@ static void sp_feMorphology_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feMorphology_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feMorphology_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feMorphology_parent_class; - -GType -sp_feMorphology_get_type() -{ - static GType feMorphology_type = 0; - - if (!feMorphology_type) { - GTypeInfo feMorphology_info = { - sizeof(SPFeMorphologyClass), - NULL, NULL, - (GClassInitFunc) sp_feMorphology_class_init, - NULL, NULL, - sizeof(SPFeMorphology), - 16, - (GInstanceInitFunc) sp_feMorphology_init, - NULL, /* value_table */ - }; - feMorphology_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeMorphology", &feMorphology_info, (GTypeFlags)0); - } - return feMorphology_type; -} +G_DEFINE_TYPE(SPFeMorphology, sp_feMorphology, SP_TYPE_FILTER_PRIMITIVE); static void sp_feMorphology_class_init(SPFeMorphologyClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - - feMorphology_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); sp_object_class->build = sp_feMorphology_build; sp_object_class->release = sp_feMorphology_release; @@ -92,8 +65,8 @@ sp_feMorphology_init(SPFeMorphology *feMorphology) static void sp_feMorphology_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feMorphology_parent_class)->build) { - ((SPObjectClass *) feMorphology_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feMorphology_parent_class)->build) { + ((SPObjectClass *) sp_feMorphology_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -107,8 +80,8 @@ sp_feMorphology_build(SPObject *object, SPDocument *document, Inkscape::XML::Nod static void sp_feMorphology_release(SPObject *object) { - if (((SPObjectClass *) feMorphology_parent_class)->release) - ((SPObjectClass *) feMorphology_parent_class)->release(object); + if (((SPObjectClass *) sp_feMorphology_parent_class)->release) + ((SPObjectClass *) sp_feMorphology_parent_class)->release(object); } static Inkscape::Filters::FilterMorphologyOperator sp_feMorphology_read_operator(gchar const *value){ @@ -151,8 +124,8 @@ sp_feMorphology_set(SPObject *object, unsigned int key, gchar const *value) object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) feMorphology_parent_class)->set) - ((SPObjectClass *) feMorphology_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feMorphology_parent_class)->set) + ((SPObjectClass *) sp_feMorphology_parent_class)->set(object, key, value); break; } @@ -171,8 +144,8 @@ sp_feMorphology_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feMorphology_parent_class)->update) { - ((SPObjectClass *) feMorphology_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feMorphology_parent_class)->update) { + ((SPObjectClass *) sp_feMorphology_parent_class)->update(object, ctx, flags); } } @@ -188,8 +161,8 @@ sp_feMorphology_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape:: repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feMorphology_parent_class)->write) { - ((SPObjectClass *) feMorphology_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feMorphology_parent_class)->write) { + ((SPObjectClass *) sp_feMorphology_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/offset.cpp b/src/filters/offset.cpp index f45169aba..2851f4f7d 100644 --- a/src/filters/offset.cpp +++ b/src/filters/offset.cpp @@ -26,10 +26,6 @@ #include "display/nr-filter-offset.h" /* FeOffset base class */ - -static void sp_feOffset_class_init(SPFeOffsetClass *klass); -static void sp_feOffset_init(SPFeOffset *feOffset); - static void sp_feOffset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feOffset_release(SPObject *object); static void sp_feOffset_set(SPObject *object, unsigned int key, gchar const *value); @@ -37,28 +33,7 @@ static void sp_feOffset_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feOffset_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feOffset_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feOffset_parent_class; - -GType -sp_feOffset_get_type() -{ - static GType feOffset_type = 0; - - if (!feOffset_type) { - GTypeInfo feOffset_info = { - sizeof(SPFeOffsetClass), - NULL, NULL, - (GClassInitFunc) sp_feOffset_class_init, - NULL, NULL, - sizeof(SPFeOffset), - 16, - (GInstanceInitFunc) sp_feOffset_init, - NULL, /* value_table */ - }; - feOffset_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeOffset", &feOffset_info, (GTypeFlags)0); - } - return feOffset_type; -} +G_DEFINE_TYPE(SPFeOffset, sp_feOffset, SP_TYPE_FILTER_PRIMITIVE); static void sp_feOffset_class_init(SPFeOffsetClass *klass) @@ -66,8 +41,6 @@ sp_feOffset_class_init(SPFeOffsetClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feOffset_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feOffset_build; sp_object_class->release = sp_feOffset_release; sp_object_class->write = sp_feOffset_write; @@ -92,8 +65,8 @@ sp_feOffset_init(SPFeOffset *feOffset) static void sp_feOffset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feOffset_parent_class)->build) { - ((SPObjectClass *) feOffset_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feOffset_parent_class)->build) { + ((SPObjectClass *) sp_feOffset_parent_class)->build(object, document, repr); } object->readAttr( "dx" ); @@ -106,8 +79,8 @@ sp_feOffset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *r static void sp_feOffset_release(SPObject *object) { - if (((SPObjectClass *) feOffset_parent_class)->release) - ((SPObjectClass *) feOffset_parent_class)->release(object); + if (((SPObjectClass *) sp_feOffset_parent_class)->release) + ((SPObjectClass *) sp_feOffset_parent_class)->release(object); } /** @@ -137,8 +110,8 @@ sp_feOffset_set(SPObject *object, unsigned int key, gchar const *value) /*DEAL WITH SETTING ATTRIBUTES HERE*/ default: - if (((SPObjectClass *) feOffset_parent_class)->set) - ((SPObjectClass *) feOffset_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feOffset_parent_class)->set) + ((SPObjectClass *) sp_feOffset_parent_class)->set(object, key, value); break; } @@ -155,8 +128,8 @@ sp_feOffset_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "dy" ); } - if (((SPObjectClass *) feOffset_parent_class)->update) { - ((SPObjectClass *) feOffset_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feOffset_parent_class)->update) { + ((SPObjectClass *) sp_feOffset_parent_class)->update(object, ctx, flags); } } @@ -172,8 +145,8 @@ sp_feOffset_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML: repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feOffset_parent_class)->write) { - ((SPObjectClass *) feOffset_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feOffset_parent_class)->write) { + ((SPObjectClass *) sp_feOffset_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/pointlight.cpp b/src/filters/pointlight.cpp index ee6824d00..a512172d1 100644 --- a/src/filters/pointlight.cpp +++ b/src/filters/pointlight.cpp @@ -30,47 +30,19 @@ #include "macros.h" /* FePointLight class */ - -static void sp_fepointlight_class_init(SPFePointLightClass *klass); -static void sp_fepointlight_init(SPFePointLight *fepointlight); - static void sp_fepointlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_fepointlight_release(SPObject *object); static void sp_fepointlight_set(SPObject *object, unsigned int key, gchar const *value); static void sp_fepointlight_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_fepointlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *fePointLight_parent_class; - -GType -sp_fepointlight_get_type() -{ - static GType fepointlight_type = 0; - - if (!fepointlight_type) { - GTypeInfo fepointlight_info = { - sizeof(SPFePointLightClass), - NULL, NULL, - (GClassInitFunc) sp_fepointlight_class_init, - NULL, NULL, - sizeof(SPFePointLight), - 16, - (GInstanceInitFunc) sp_fepointlight_init, - NULL, /* value_table */ - }; - fepointlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFePointLight", &fepointlight_info, (GTypeFlags)0); - } - return fepointlight_type; -} +G_DEFINE_TYPE(SPFePointLight, sp_fepointlight, SP_TYPE_OBJECT); static void sp_fepointlight_class_init(SPFePointLightClass *klass) { - SPObjectClass *sp_object_class = (SPObjectClass *)klass; - fePointLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_fepointlight_build; sp_object_class->release = sp_fepointlight_release; sp_object_class->write = sp_fepointlight_write; @@ -98,8 +70,8 @@ sp_fepointlight_init(SPFePointLight *fepointlight) static void sp_fepointlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) fePointLight_parent_class)->build) { - ((SPObjectClass *) fePointLight_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_fepointlight_parent_class)->build) { + ((SPObjectClass *) sp_fepointlight_parent_class)->build(object, document, repr); } //Read values of key attributes from XML nodes into object. @@ -192,8 +164,8 @@ sp_fepointlight_set(SPObject *object, unsigned int key, gchar const *value) break; default: // See if any parents need this value. - if (((SPObjectClass *) fePointLight_parent_class)->set) { - ((SPObjectClass *) fePointLight_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_fepointlight_parent_class)->set) { + ((SPObjectClass *) sp_fepointlight_parent_class)->set(object, key, value); } break; } @@ -215,8 +187,8 @@ sp_fepointlight_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "z" ); } - if (((SPObjectClass *) fePointLight_parent_class)->update) { - ((SPObjectClass *) fePointLight_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_fepointlight_parent_class)->update) { + ((SPObjectClass *) sp_fepointlight_parent_class)->update(object, ctx, flags); } } @@ -239,8 +211,8 @@ sp_fepointlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape:: if (fepointlight->z_set) sp_repr_set_css_double(repr, "z", fepointlight->z); - if (((SPObjectClass *) fePointLight_parent_class)->write) { - ((SPObjectClass *) fePointLight_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_fepointlight_parent_class)->write) { + ((SPObjectClass *) sp_fepointlight_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/specularlighting.cpp b/src/filters/specularlighting.cpp index 71a705c94..44eeff35a 100644 --- a/src/filters/specularlighting.cpp +++ b/src/filters/specularlighting.cpp @@ -31,10 +31,6 @@ #include "display/nr-filter-specularlighting.h" /* FeSpecularLighting base class */ - -static void sp_feSpecularLighting_class_init(SPFeSpecularLightingClass *klass); -static void sp_feSpecularLighting_init(SPFeSpecularLighting *feSpecularLighting); - static void sp_feSpecularLighting_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feSpecularLighting_release(SPObject *object); static void sp_feSpecularLighting_set(SPObject *object, unsigned int key, gchar const *value); @@ -52,35 +48,13 @@ static Inkscape::XML::Node *sp_feSpecularLighting_write(SPObject *object, Inksca static void sp_feSpecularLighting_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); static void sp_feSpecularLighting_children_modified(SPFeSpecularLighting *sp_specularlighting); -static SPFilterPrimitiveClass *feSpecularLighting_parent_class; - -GType -sp_feSpecularLighting_get_type() -{ - static GType feSpecularLighting_type = 0; - - if (!feSpecularLighting_type) { - GTypeInfo feSpecularLighting_info = { - sizeof(SPFeSpecularLightingClass), - NULL, NULL, - (GClassInitFunc) sp_feSpecularLighting_class_init, - NULL, NULL, - sizeof(SPFeSpecularLighting), - 16, - (GInstanceInitFunc) sp_feSpecularLighting_init, - NULL, /* value_table */ - }; - feSpecularLighting_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeSpecularLighting", &feSpecularLighting_info, (GTypeFlags)0); - } - return feSpecularLighting_type; -} +G_DEFINE_TYPE(SPFeSpecularLighting, sp_feSpecularLighting, SP_TYPE_FILTER_PRIMITIVE); static void sp_feSpecularLighting_class_init(SPFeSpecularLightingClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feSpecularLighting_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); sp_object_class->build = sp_feSpecularLighting_build; sp_object_class->release = sp_feSpecularLighting_release; @@ -118,8 +92,8 @@ sp_feSpecularLighting_init(SPFeSpecularLighting *feSpecularLighting) static void sp_feSpecularLighting_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feSpecularLighting_parent_class)->build) { - ((SPObjectClass *) feSpecularLighting_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->build) { + ((SPObjectClass *) sp_feSpecularLighting_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -137,8 +111,8 @@ sp_feSpecularLighting_build(SPObject *object, SPDocument *document, Inkscape::XM static void sp_feSpecularLighting_release(SPObject *object) { - if (((SPObjectClass *) feSpecularLighting_parent_class)->release) - ((SPObjectClass *) feSpecularLighting_parent_class)->release(object); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->release) + ((SPObjectClass *) sp_feSpecularLighting_parent_class)->release(object); } /** @@ -239,8 +213,8 @@ sp_feSpecularLighting_set(SPObject *object, unsigned int key, gchar const *value object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) feSpecularLighting_parent_class)->set) - ((SPObjectClass *) feSpecularLighting_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->set) + ((SPObjectClass *) sp_feSpecularLighting_parent_class)->set(object, key, value); break; } @@ -260,8 +234,8 @@ sp_feSpecularLighting_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "lighting-color" ); } - if (((SPObjectClass *) feSpecularLighting_parent_class)->update) { - ((SPObjectClass *) feSpecularLighting_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->update) { + ((SPObjectClass *) sp_feSpecularLighting_parent_class)->update(object, ctx, flags); } } @@ -292,8 +266,8 @@ sp_feSpecularLighting_write(SPObject *object, Inkscape::XML::Document *doc, Inks sp_svg_write_color(c, sizeof(c), fespecularlighting->lighting_color); repr->setAttribute("lighting-color", c); } - if (((SPObjectClass *) feSpecularLighting_parent_class)->write) { - ((SPObjectClass *) feSpecularLighting_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->write) { + ((SPObjectClass *) sp_feSpecularLighting_parent_class)->write(object, doc, repr, flags); } return repr; @@ -307,8 +281,8 @@ sp_feSpecularLighting_child_added(SPObject *object, Inkscape::XML::Node *child, { SPFeSpecularLighting *f = SP_FESPECULARLIGHTING(object); - if (((SPObjectClass *) feSpecularLighting_parent_class)->child_added) - (* ((SPObjectClass *) feSpecularLighting_parent_class)->child_added)(object, child, ref); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->child_added) + (* ((SPObjectClass *) sp_feSpecularLighting_parent_class)->child_added)(object, child, ref); sp_feSpecularLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -323,8 +297,8 @@ sp_feSpecularLighting_remove_child(SPObject *object, Inkscape::XML::Node *child) { SPFeSpecularLighting *f = SP_FESPECULARLIGHTING(object); - if (((SPObjectClass *) feSpecularLighting_parent_class)->remove_child) - (* ((SPObjectClass *) feSpecularLighting_parent_class)->remove_child)(object, child); + if (((SPObjectClass *) sp_feSpecularLighting_parent_class)->remove_child) + (* ((SPObjectClass *) sp_feSpecularLighting_parent_class)->remove_child)(object, child); sp_feSpecularLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -334,8 +308,8 @@ static void sp_feSpecularLighting_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) { SPFeSpecularLighting *f = SP_FESPECULARLIGHTING(object); - if (((SPObjectClass *) (feSpecularLighting_parent_class))->order_changed) - (* ((SPObjectClass *) (feSpecularLighting_parent_class))->order_changed) (object, child, old_ref, new_ref); + if (((SPObjectClass *) (sp_feSpecularLighting_parent_class))->order_changed) + (* ((SPObjectClass *) (sp_feSpecularLighting_parent_class))->order_changed) (object, child, old_ref, new_ref); sp_feSpecularLighting_children_modified(f); object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/filters/spotlight.cpp b/src/filters/spotlight.cpp index 7be83ed00..181e39990 100644 --- a/src/filters/spotlight.cpp +++ b/src/filters/spotlight.cpp @@ -30,47 +30,19 @@ #include "macros.h" /* FeSpotLight class */ - -static void sp_fespotlight_class_init(SPFeSpotLightClass *klass); -static void sp_fespotlight_init(SPFeSpotLight *fespotlight); - static void sp_fespotlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_fespotlight_release(SPObject *object); static void sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value); static void sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_fespotlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *feSpotLight_parent_class; - -GType -sp_fespotlight_get_type() -{ - static GType fespotlight_type = 0; - - if (!fespotlight_type) { - GTypeInfo fespotlight_info = { - sizeof(SPFeSpotLightClass), - NULL, NULL, - (GClassInitFunc) sp_fespotlight_class_init, - NULL, NULL, - sizeof(SPFeSpotLight), - 16, - (GInstanceInitFunc) sp_fespotlight_init, - NULL, /* value_table */ - }; - fespotlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeSpotLight", &fespotlight_info, (GTypeFlags)0); - } - return fespotlight_type; -} +G_DEFINE_TYPE(SPFeSpotLight, sp_fespotlight, SP_TYPE_OBJECT); static void sp_fespotlight_class_init(SPFeSpotLightClass *klass) { - SPObjectClass *sp_object_class = (SPObjectClass *)klass; - feSpotLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_fespotlight_build; sp_object_class->release = sp_fespotlight_release; sp_object_class->write = sp_fespotlight_write; @@ -108,8 +80,8 @@ sp_fespotlight_init(SPFeSpotLight *fespotlight) static void sp_fespotlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feSpotLight_parent_class)->build) { - ((SPObjectClass *) feSpotLight_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_fespotlight_parent_class)->build) { + ((SPObjectClass *) sp_fespotlight_parent_class)->build(object, document, repr); } //Read values of key attributes from XML nodes into object. @@ -290,8 +262,8 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) break; default: // See if any parents need this value. - if (((SPObjectClass *) feSpotLight_parent_class)->set) { - ((SPObjectClass *) feSpotLight_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_fespotlight_parent_class)->set) { + ((SPObjectClass *) sp_fespotlight_parent_class)->set(object, key, value); } break; } @@ -318,8 +290,8 @@ sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags) object->readAttr( "limitingConeAngle" ); } - if (((SPObjectClass *) feSpotLight_parent_class)->update) { - ((SPObjectClass *) feSpotLight_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_fespotlight_parent_class)->update) { + ((SPObjectClass *) sp_fespotlight_parent_class)->update(object, ctx, flags); } } @@ -352,8 +324,8 @@ sp_fespotlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::X if (fespotlight->limitingConeAngle_set) sp_repr_set_css_double(repr, "limitingConeAngle", fespotlight->limitingConeAngle); - if (((SPObjectClass *) feSpotLight_parent_class)->write) { - ((SPObjectClass *) feSpotLight_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_fespotlight_parent_class)->write) { + ((SPObjectClass *) sp_fespotlight_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/tile.cpp b/src/filters/tile.cpp index 42a59ede8..d2725f50c 100644 --- a/src/filters/tile.cpp +++ b/src/filters/tile.cpp @@ -23,10 +23,6 @@ #include "display/nr-filter-tile.h" /* FeTile base class */ - -static void sp_feTile_class_init(SPFeTileClass *klass); -static void sp_feTile_init(SPFeTile *feTile); - static void sp_feTile_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feTile_release(SPObject *object); static void sp_feTile_set(SPObject *object, unsigned int key, gchar const *value); @@ -34,28 +30,7 @@ static void sp_feTile_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feTile_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feTile_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feTile_parent_class; - -GType -sp_feTile_get_type() -{ - static GType feTile_type = 0; - - if (!feTile_type) { - GTypeInfo feTile_info = { - sizeof(SPFeTileClass), - NULL, NULL, - (GClassInitFunc) sp_feTile_class_init, - NULL, NULL, - sizeof(SPFeTile), - 16, - (GInstanceInitFunc) sp_feTile_init, - NULL, /* value_table */ - }; - feTile_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeTile", &feTile_info, (GTypeFlags)0); - } - return feTile_type; -} +G_DEFINE_TYPE(SPFeTile, sp_feTile, SP_TYPE_FILTER_PRIMITIVE); static void sp_feTile_class_init(SPFeTileClass *klass) @@ -63,8 +38,6 @@ sp_feTile_class_init(SPFeTileClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feTile_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feTile_build; sp_object_class->release = sp_feTile_release; sp_object_class->write = sp_feTile_write; @@ -86,8 +59,8 @@ sp_feTile_init(SPFeTile */*feTile*/) static void sp_feTile_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feTile_parent_class)->build) { - ((SPObjectClass *) feTile_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feTile_parent_class)->build) { + ((SPObjectClass *) sp_feTile_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -99,8 +72,8 @@ sp_feTile_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep static void sp_feTile_release(SPObject *object) { - if (((SPObjectClass *) feTile_parent_class)->release) - ((SPObjectClass *) feTile_parent_class)->release(object); + if (((SPObjectClass *) sp_feTile_parent_class)->release) + ((SPObjectClass *) sp_feTile_parent_class)->release(object); } /** @@ -115,8 +88,8 @@ sp_feTile_set(SPObject *object, unsigned int key, gchar const *value) switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ default: - if (((SPObjectClass *) feTile_parent_class)->set) - ((SPObjectClass *) feTile_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feTile_parent_class)->set) + ((SPObjectClass *) sp_feTile_parent_class)->set(object, key, value); break; } @@ -135,8 +108,8 @@ sp_feTile_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feTile_parent_class)->update) { - ((SPObjectClass *) feTile_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feTile_parent_class)->update) { + ((SPObjectClass *) sp_feTile_parent_class)->update(object, ctx, flags); } } @@ -152,8 +125,8 @@ sp_feTile_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::N repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feTile_parent_class)->write) { - ((SPObjectClass *) feTile_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feTile_parent_class)->write) { + ((SPObjectClass *) sp_feTile_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/filters/turbulence.cpp b/src/filters/turbulence.cpp index 9d1448c70..c4d4ca4ae 100644 --- a/src/filters/turbulence.cpp +++ b/src/filters/turbulence.cpp @@ -29,10 +29,6 @@ #include "display/nr-filter-turbulence.h" /* FeTurbulence base class */ - -static void sp_feTurbulence_class_init(SPFeTurbulenceClass *klass); -static void sp_feTurbulence_init(SPFeTurbulence *feTurbulence); - static void sp_feTurbulence_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_feTurbulence_release(SPObject *object); static void sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value); @@ -40,28 +36,7 @@ static void sp_feTurbulence_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_feTurbulence_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_feTurbulence_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter); -static SPFilterPrimitiveClass *feTurbulence_parent_class; - -GType -sp_feTurbulence_get_type() -{ - static GType feTurbulence_type = 0; - - if (!feTurbulence_type) { - GTypeInfo feTurbulence_info = { - sizeof(SPFeTurbulenceClass), - NULL, NULL, - (GClassInitFunc) sp_feTurbulence_class_init, - NULL, NULL, - sizeof(SPFeTurbulence), - 16, - (GInstanceInitFunc) sp_feTurbulence_init, - NULL, /* value_table */ - }; - feTurbulence_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeTurbulence", &feTurbulence_info, (GTypeFlags)0); - } - return feTurbulence_type; -} +G_DEFINE_TYPE(SPFeTurbulence, sp_feTurbulence, SP_TYPE_FILTER_PRIMITIVE); static void sp_feTurbulence_class_init(SPFeTurbulenceClass *klass) @@ -69,8 +44,6 @@ sp_feTurbulence_class_init(SPFeTurbulenceClass *klass) SPObjectClass *sp_object_class = (SPObjectClass *)klass; SPFilterPrimitiveClass * sp_primitive_class = (SPFilterPrimitiveClass *)klass; - feTurbulence_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_feTurbulence_build; sp_object_class->release = sp_feTurbulence_release; sp_object_class->write = sp_feTurbulence_write; @@ -94,8 +67,8 @@ sp_feTurbulence_init(SPFeTurbulence *feTurbulence) static void sp_feTurbulence_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) feTurbulence_parent_class)->build) { - ((SPObjectClass *) feTurbulence_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_feTurbulence_parent_class)->build) { + ((SPObjectClass *) sp_feTurbulence_parent_class)->build(object, document, repr); } /*LOAD ATTRIBUTES FROM REPR HERE*/ @@ -112,8 +85,8 @@ sp_feTurbulence_build(SPObject *object, SPDocument *document, Inkscape::XML::Nod static void sp_feTurbulence_release(SPObject *object) { - if (((SPObjectClass *) feTurbulence_parent_class)->release) - ((SPObjectClass *) feTurbulence_parent_class)->release(object); + if (((SPObjectClass *) sp_feTurbulence_parent_class)->release) + ((SPObjectClass *) sp_feTurbulence_parent_class)->release(object); } static bool sp_feTurbulence_read_stitchTiles(gchar const *value){ @@ -200,8 +173,8 @@ sp_feTurbulence_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - if (((SPObjectClass *) feTurbulence_parent_class)->set) - ((SPObjectClass *) feTurbulence_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_feTurbulence_parent_class)->set) + ((SPObjectClass *) sp_feTurbulence_parent_class)->set(object, key, value); break; } @@ -220,8 +193,8 @@ sp_feTurbulence_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) feTurbulence_parent_class)->update) { - ((SPObjectClass *) feTurbulence_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_feTurbulence_parent_class)->update) { + ((SPObjectClass *) sp_feTurbulence_parent_class)->update(object, ctx, flags); } } @@ -237,8 +210,8 @@ sp_feTurbulence_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape:: repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) feTurbulence_parent_class)->write) { - ((SPObjectClass *) feTurbulence_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_feTurbulence_parent_class)->write) { + ((SPObjectClass *) sp_feTurbulence_parent_class)->write(object, doc, repr, flags); } /* turbulence doesn't take input */ diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 231490771..8fd002d70 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -51,8 +51,6 @@ using Inkscape::DocumentUndo; -static void sp_gradient_context_class_init(SPGradientContextClass *klass); -static void sp_gradient_context_init(SPGradientContext *gr_context); static void sp_gradient_context_dispose(GObject *object); static void sp_gradient_context_setup(SPEventContext *ec); @@ -61,35 +59,13 @@ static gint sp_gradient_context_root_handler(SPEventContext *event_context, GdkE static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint state, guint32 etime); -static SPEventContextClass *parent_class; - - -GType sp_gradient_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPGradientContextClass), - NULL, NULL, - (GClassInitFunc) sp_gradient_context_class_init, - NULL, NULL, - sizeof(SPGradientContext), - 4, - (GInstanceInitFunc) sp_gradient_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPGradientContext", &info, (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(SPGradientContext, sp_gradient_context, SP_TYPE_EVENT_CONTEXT); static void sp_gradient_context_class_init(SPGradientContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; - parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass); - object_class->dispose = sp_gradient_context_dispose; event_context_class->setup = sp_gradient_context_setup; @@ -127,7 +103,7 @@ static void sp_gradient_context_dispose(GObject *object) rc->subselcon->disconnect(); delete rc->subselcon; - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_gradient_context_parent_class)->dispose(object); } const gchar *gr_handle_descr [] = { @@ -204,8 +180,8 @@ static void sp_gradient_context_setup(SPEventContext *ec) { SPGradientContext *rc = SP_GRADIENT_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if (((SPEventContextClass *) sp_gradient_context_parent_class)->setup) { + ((SPEventContextClass *) sp_gradient_context_parent_class)->setup(ec); } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -879,8 +855,8 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if (((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler) { + ret = ((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 4fafa191e..0e9957ca3 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -19,34 +19,9 @@ #include "document.h" #include "helper/action.h" -static void sp_action_class_init (SPActionClass *klass); -static void sp_action_init (SPAction *action); static void sp_action_finalize (GObject *object); -static GObjectClass *parent_class; - -/** - * Register SPAction class and return its type. - */ -GType -sp_action_get_type (void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPActionClass), - NULL, NULL, - (GClassInitFunc) sp_action_class_init, - NULL, NULL, - sizeof(SPAction), - 0, - (GInstanceInitFunc) sp_action_init, - NULL - }; - type = g_type_register_static(G_TYPE_OBJECT, "SPAction", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPAction, sp_action, G_TYPE_OBJECT); /** * SPAction vtable initialization. @@ -54,8 +29,6 @@ sp_action_get_type (void) static void sp_action_class_init (SPActionClass *klass) { - parent_class = (GObjectClass*) g_type_class_ref(G_TYPE_OBJECT); - GObjectClass *object_class = (GObjectClass *) klass; object_class->finalize = sp_action_finalize; } @@ -84,19 +57,19 @@ sp_action_init (SPAction *action) static void sp_action_finalize (GObject *object) { - SPAction *action = SP_ACTION(object); + SPAction *action = SP_ACTION(object); - g_free (action->image); - g_free (action->tip); - g_free (action->name); - g_free (action->id); + g_free (action->image); + g_free (action->tip); + g_free (action->name); + g_free (action->id); action->signal_perform.~signal(); action->signal_set_sensitive.~signal(); action->signal_set_active.~signal(); action->signal_set_name.~signal(); - parent_class->finalize (object); + G_OBJECT_CLASS(sp_action_parent_class)->finalize (object); } /** diff --git a/src/helper/unit-menu.cpp b/src/helper/unit-menu.cpp index bb2254a1b..af07c03c1 100644 --- a/src/helper/unit-menu.cpp +++ b/src/helper/unit-menu.cpp @@ -52,39 +52,16 @@ struct SPUnitSelectorClass { enum {SET_UNIT, LAST_SIGNAL}; -static void sp_unit_selector_class_init(SPUnitSelectorClass *klass); -static void sp_unit_selector_init(SPUnitSelector *selector); static void sp_unit_selector_finalize(GObject *object); -static GtkHBoxClass *unit_selector_parent_class; static guint signals[LAST_SIGNAL] = {0}; -GType sp_unit_selector_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPUnitSelectorClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_unit_selector_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPUnitSelector), - 0, // n_preallocs - (GInstanceInitFunc)sp_unit_selector_init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_HBOX, "SPUnitSelector", &info, static_cast(0)); - } - return type; -} +G_DEFINE_TYPE(SPUnitSelector, sp_unit_selector, GTK_TYPE_HBOX); static void sp_unit_selector_class_init(SPUnitSelectorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - unit_selector_parent_class = GTK_HBOX_CLASS(g_type_class_peek_parent(klass)); signals[SET_UNIT] = g_signal_new("set_unit", G_TYPE_FROM_CLASS(klass), @@ -142,7 +119,7 @@ sp_unit_selector_finalize(GObject *object) selector->unit = NULL; - G_OBJECT_CLASS(unit_selector_parent_class)->finalize(object); + G_OBJECT_CLASS(sp_unit_selector_parent_class)->finalize(object); } GtkWidget * diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index d9b1b0965..8df16ec9a 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -63,9 +63,13 @@ enum { }; static guint signals[N_SIGNALS] = {0}; -static GtkActionClass *ink_comboboxentry_action_parent_class = NULL; static GQuark gDataName = 0; +static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action); +static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass); + +G_DEFINE_TYPE(Ink_ComboBoxEntry_Action, ink_comboboxentry_action, GTK_TYPE_ACTION); + static void ink_comboboxentry_action_finalize (GObject *object) { // Free any allocated resources. @@ -174,8 +178,8 @@ ink_comboboxentry_action_connect_proxy (GtkAction *action, GTK_ACTION_CLASS (ink_comboboxentry_action_parent_class)->connect_proxy (action, proxy); } - -static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass) +static void +ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); @@ -192,8 +196,6 @@ static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass * klass->parent_class.create_tool_item = create_tool_item; klass->parent_class.create_menu_item = create_menu_item; - ink_comboboxentry_action_parent_class = GTK_ACTION_CLASS(g_type_class_peek_parent (klass) ); - g_object_class_install_property ( gobject_class, PROP_MODEL, @@ -292,34 +294,6 @@ static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action) action->focusWidget = NULL; } -GType ink_comboboxentry_action_get_type () -{ - static GType ink_comboboxentry_action_type = 0; - - if (!ink_comboboxentry_action_type) { - static const GTypeInfo ink_comboboxentry_action_info = { - sizeof(Ink_ComboBoxEntry_ActionClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) ink_comboboxentry_action_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(Ink_ComboBoxEntry_Action), - 0, /* n_preallocs */ - (GInstanceInitFunc)ink_comboboxentry_action_init, /* instance_init */ - NULL /* value_table */ - }; - - ink_comboboxentry_action_type = g_type_register_static (GTK_TYPE_ACTION, - "Ink_ComboBoxEntry_Action", - &ink_comboboxentry_action_info, - (GTypeFlags)0 ); - } - - return ink_comboboxentry_action_type; -} - - Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name, const gchar *label, const gchar *tooltip, @@ -439,7 +413,7 @@ GtkWidget* create_tool_item( GtkAction* action ) } else { - item = ink_comboboxentry_action_parent_class->create_tool_item( action ); + item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_tool_item( action ); } @@ -451,7 +425,7 @@ GtkWidget* create_menu_item( GtkAction* action ) { GtkWidget* item = 0; - item = ink_comboboxentry_action_parent_class->create_menu_item( action ); + item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_menu_item( action ); g_warning( "ink_comboboxentry_action: create_menu_item not implemented" ); // One can easily modify ege-select-one-action routine to implement this. return item; diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index fc755b9dc..feabfa02d 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -41,8 +41,6 @@ #include "lpe-tool-context.h" -static void sp_lpetool_context_class_init(SPLPEToolContextClass *klass); -static void sp_lpetool_context_init(SPLPEToolContext *erc); static void sp_lpetool_context_dispose(GObject *object); static void sp_lpetool_context_setup(SPEventContext *ec); @@ -66,28 +64,7 @@ SubtoolEntry lpesubtools[] = { {Inkscape::LivePathEffect::MIRROR_SYMMETRY, "draw-geometry-mirror"} }; -static SPPenContextClass *lpetool_parent_class = 0; - -GType sp_lpetool_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPLPEToolContextClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_lpetool_context_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPLPEToolContext), - 0, // n_preallocs - (GInstanceInitFunc)sp_lpetool_context_init, - 0 // value_table - }; - type = g_type_register_static(SP_TYPE_PEN_CONTEXT, "SPLPEToolContext", &info, static_cast(0)); - } - return type; -} +G_DEFINE_TYPE(SPLPEToolContext, sp_lpetool_context, SP_TYPE_PEN_CONTEXT); static void sp_lpetool_context_class_init(SPLPEToolContextClass *klass) @@ -95,8 +72,6 @@ sp_lpetool_context_class_init(SPLPEToolContextClass *klass) GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; - lpetool_parent_class = (SPPenContextClass*)g_type_class_peek_parent(klass); - object_class->dispose = sp_lpetool_context_dispose; event_context_class->setup = sp_lpetool_context_setup; @@ -140,7 +115,7 @@ sp_lpetool_context_dispose(GObject *object) delete lc->_lpetool_message_context; } - G_OBJECT_CLASS(lpetool_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_lpetool_context_parent_class)->dispose(object); } static void @@ -148,8 +123,8 @@ sp_lpetool_context_setup(SPEventContext *ec) { SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec); - if (((SPEventContextClass *) lpetool_parent_class)->setup) - ((SPEventContextClass *) lpetool_parent_class)->setup(ec); + if (((SPEventContextClass *) sp_lpetool_context_parent_class)->setup) + ((SPEventContextClass *) sp_lpetool_context_parent_class)->setup(ec); Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); SPItem *item = selection->singleItem(); @@ -204,8 +179,8 @@ sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) /* //pass on up to parent class to handle common attributes. - if ( lpetool_parent_class->set ) { - lpetool_parent_class->set(ec, key, val); + if ( sp_lpetool_context_parent_class->set ) { + sp_lpetool_context_parent_class->set(ec, key, val); } */ } @@ -234,8 +209,8 @@ sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *even } if (!ret) { - if (((SPEventContextClass *) lpetool_parent_class)->item_handler) - ret = ((SPEventContextClass *) lpetool_parent_class)->item_handler(ec, item, event); + if (((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler) + ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler(ec, item, event); } return ret; @@ -252,7 +227,7 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) if (sp_pen_context_has_waiting_LPE(lc)) { // quit when we are waiting for a LPE to be applied - ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event); + ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); return ret; } @@ -284,7 +259,7 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type)); // we pass the mouse click on to pen tool as the first click which it should collect - ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event); + ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); } break; @@ -320,8 +295,8 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) lpetool_parent_class)->root_handler) { - ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event); + if (((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler) { + ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp index 8fd016702..36712d15d 100644 --- a/src/mesh-context.cpp +++ b/src/mesh-context.cpp @@ -53,8 +53,6 @@ using Inkscape::DocumentUndo; -static void sp_mesh_context_class_init(SPMeshContextClass *klass); -static void sp_mesh_context_init(SPMeshContext *gr_context); static void sp_mesh_context_dispose(GObject *object); static void sp_mesh_context_setup(SPEventContext *ec); @@ -63,35 +61,13 @@ static gint sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const pt, guint state, guint32 etime); -static SPEventContextClass *parent_class; - - -GType sp_mesh_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPMeshContextClass), - NULL, NULL, - (GClassInitFunc) sp_mesh_context_class_init, - NULL, NULL, - sizeof(SPMeshContext), - 4, - (GInstanceInitFunc) sp_mesh_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPMeshContext", &info, (GTypeFlags) 0); - } - return type; -} +G_DEFINE_TYPE(SPMeshContext, sp_mesh_context, SP_TYPE_EVENT_CONTEXT); static void sp_mesh_context_class_init(SPMeshContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; - parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass); - object_class->dispose = sp_mesh_context_dispose; event_context_class->setup = sp_mesh_context_setup; @@ -129,7 +105,7 @@ static void sp_mesh_context_dispose(GObject *object) rc->subselcon->disconnect(); delete rc->subselcon; - G_OBJECT_CLASS(parent_class)->dispose(object); + G_OBJECT_CLASS(sp_mesh_context_parent_class)->dispose(object); } const gchar *ms_handle_descr [] = { @@ -270,8 +246,8 @@ static void sp_mesh_context_setup(SPEventContext *ec) { SPMeshContext *rc = SP_MESH_CONTEXT(ec); - if (((SPEventContextClass *) parent_class)->setup) { - ((SPEventContextClass *) parent_class)->setup(ec); + if (((SPEventContextClass *) sp_mesh_context_parent_class)->setup) { + ((SPEventContextClass *) sp_mesh_context_parent_class)->setup(ec); } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -948,8 +924,8 @@ sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) parent_class)->root_handler) { - ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); + if (((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler) { + ret = ((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler(event_context, event); } } diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 19a040b24..090a43a25 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -45,9 +45,6 @@ #include "display/curve.h" #include "livarot/Path.h" - -static void sp_pencil_context_class_init(SPPencilContextClass *klass); -static void sp_pencil_context_init(SPPencilContext *pc); static void sp_pencil_context_setup(SPEventContext *ec); static void sp_pencil_context_dispose(GObject *object); @@ -66,34 +63,12 @@ static void fit_and_split(SPPencilContext *pc); static void interpolate(SPPencilContext *pc); static void sketch_interpolate(SPPencilContext *pc); -static SPDrawContextClass *pencil_parent_class; static Geom::Point pencil_drag_origin_w(0, 0); static bool pencil_within_tolerance = false; static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } -/** - * Register SPPencilContext class with Gdk and return its type number. - */ -GType -sp_pencil_context_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPPencilContextClass), - NULL, NULL, - (GClassInitFunc) sp_pencil_context_class_init, - NULL, NULL, - sizeof(SPPencilContext), - 4, - (GInstanceInitFunc) sp_pencil_context_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPencilContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPPencilContext, sp_pencil_context, SP_TYPE_DRAW_CONTEXT); /** * Initialize SPPencilContext vtable. @@ -107,8 +82,6 @@ sp_pencil_context_class_init(SPPencilContextClass *klass) object_class = (GObjectClass *) klass; event_context_class = (SPEventContextClass *) klass; - pencil_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass); - object_class->dispose = sp_pencil_context_dispose; event_context_class->setup = sp_pencil_context_setup; @@ -147,8 +120,8 @@ sp_pencil_context_setup(SPEventContext *ec) ec->enableSelectionCue(); } - if (((SPEventContextClass *) pencil_parent_class)->setup) { - ((SPEventContextClass *) pencil_parent_class)->setup(ec); + if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { + ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); } SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); @@ -160,7 +133,7 @@ sp_pencil_context_setup(SPEventContext *ec) static void sp_pencil_context_dispose(GObject *object) { - G_OBJECT_CLASS(pencil_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_pencil_context_parent_class)->dispose(object); } /** Snaps new node relative to the previous node. */ @@ -218,7 +191,7 @@ sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) if (!ret) { gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) pencil_parent_class)->root_handler; + = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; if (parent_root_handler) { ret = parent_root_handler(ec, event); } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index c7dce3850..e3a44d8bb 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -38,10 +38,6 @@ using std::pair; #include "display/nr-filter.h" /* Filter base class */ - -static void sp_filter_class_init(SPFilterClass *klass); -static void sp_filter_init(SPFilter *filter); - static void sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_filter_release(SPObject *object); static void sp_filter_set(SPObject *object, unsigned int key, gchar const *value); @@ -55,37 +51,13 @@ static Inkscape::XML::Node *sp_filter_write(SPObject *object, Inkscape::XML::Doc static void filter_ref_changed(SPObject *old_ref, SPObject *ref, SPFilter *filter); static void filter_ref_modified(SPObject *href, guint flags, SPFilter *filter); -static SPObjectClass *filter_parent_class; - -GType -sp_filter_get_type() -{ - static GType filter_type = 0; - - if (!filter_type) { - GTypeInfo filter_info = { - sizeof(SPFilterClass), - NULL, NULL, - (GClassInitFunc) sp_filter_class_init, - NULL, NULL, - sizeof(SPFilter), - 16, - (GInstanceInitFunc) sp_filter_init, - NULL, /* value_table */ - }; - filter_type = g_type_register_static(SP_TYPE_OBJECT, "SPFilter", &filter_info, (GTypeFlags)0); - } - return filter_type; -} +G_DEFINE_TYPE(SPFilter, sp_filter, SP_TYPE_OBJECT); static void sp_filter_class_init(SPFilterClass *klass) { - SPObjectClass *sp_object_class = (SPObjectClass *)klass; - filter_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass); - sp_object_class->build = sp_filter_build; sp_object_class->release = sp_filter_release; sp_object_class->write = sp_filter_write; @@ -141,8 +113,8 @@ sp_filter_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep object->readAttr( "filterRes" ); object->readAttr( "xlink:href" ); - if (((SPObjectClass *) filter_parent_class)->build) { - ((SPObjectClass *) filter_parent_class)->build(object, document, repr); + if (((SPObjectClass *) sp_filter_parent_class)->build) { + ((SPObjectClass *) sp_filter_parent_class)->build(object, document, repr); } //is this necessary? @@ -174,8 +146,8 @@ static void sp_filter_release(SPObject *object) filter->modified_connection.~connection(); delete filter->_image_name; - if (((SPObjectClass *) filter_parent_class)->release) - ((SPObjectClass *) filter_parent_class)->release(object); + if (((SPObjectClass *) sp_filter_parent_class)->release) + ((SPObjectClass *) sp_filter_parent_class)->release(object); } /** @@ -249,8 +221,8 @@ sp_filter_set(SPObject *object, unsigned int key, gchar const *value) break; default: // See if any parents need this value. - if (((SPObjectClass *) filter_parent_class)->set) { - ((SPObjectClass *) filter_parent_class)->set(object, key, value); + if (((SPObjectClass *) sp_filter_parent_class)->set) { + ((SPObjectClass *) sp_filter_parent_class)->set(object, key, value); } break; } @@ -271,8 +243,8 @@ sp_filter_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) filter_parent_class)->update) { - ((SPObjectClass *) filter_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_filter_parent_class)->update) { + ((SPObjectClass *) sp_filter_parent_class)->update(object, ctx, flags); } } @@ -367,8 +339,8 @@ sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::N g_free(uri_string); } - if (((SPObjectClass *) filter_parent_class)->write) { - ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_filter_parent_class)->write) { + ((SPObjectClass *) sp_filter_parent_class)->write(object, doc, repr, flags); } return repr; @@ -407,8 +379,8 @@ sp_filter_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XM { //SPFilter *f = SP_FILTER(object); - if (((SPObjectClass *) filter_parent_class)->child_added) - (* ((SPObjectClass *) filter_parent_class)->child_added)(object, child, ref); + if (((SPObjectClass *) sp_filter_parent_class)->child_added) + (* ((SPObjectClass *) sp_filter_parent_class)->child_added)(object, child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } @@ -421,8 +393,8 @@ sp_filter_remove_child(SPObject *object, Inkscape::XML::Node *child) { // SPFilter *f = SP_FILTER(object); - if (((SPObjectClass *) filter_parent_class)->remove_child) - (* ((SPObjectClass *) filter_parent_class)->remove_child)(object, child); + if (((SPObjectClass *) sp_filter_parent_class)->remove_child) + (* ((SPObjectClass *) sp_filter_parent_class)->remove_child)(object, child); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 3b8999eda..e8629ff70 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -39,9 +39,6 @@ #include /* LPEItem base class */ - -static void sp_lpe_item_class_init(SPLPEItemClass *klass); -static void sp_lpe_item_init(SPLPEItem *lpe_item); static void sp_lpe_item_finalize(GObject *object); static void sp_lpe_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); @@ -64,34 +61,12 @@ typedef std::list HRefList; static std::string patheffectlist_write_svg(PathEffectList const & list); static std::string hreflist_write_svg(HRefList const & list); -static SPItemClass *parent_class; - -GType -sp_lpe_item_get_type() -{ - static GType lpe_item_type = 0; - - if (!lpe_item_type) { - GTypeInfo lpe_item_info = { - sizeof(SPLPEItemClass), - NULL, NULL, - (GClassInitFunc) sp_lpe_item_class_init, - NULL, NULL, - sizeof(SPLPEItem), - 16, - (GInstanceInitFunc) sp_lpe_item_init, - NULL, /* value_table */ - }; - lpe_item_type = g_type_register_static(SP_TYPE_ITEM, "SPLPEItem", &lpe_item_info, (GTypeFlags)0); - } - return lpe_item_type; -} +G_DEFINE_TYPE(SPLPEItem, sp_lpe_item, SP_TYPE_ITEM); static void sp_lpe_item_class_init(SPLPEItemClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS(klass); SPObjectClass *sp_object_class = SP_OBJECT_CLASS(klass); - parent_class = SP_ITEM_CLASS(g_type_class_peek_parent(klass)); gobject_class->finalize = sp_lpe_item_finalize; sp_object_class->build = sp_lpe_item_build; @@ -119,8 +94,8 @@ sp_lpe_item_init(SPLPEItem *lpeitem) static void sp_lpe_item_finalize(GObject *object) { - if (((GObjectClass *) (parent_class))->finalize) { - (* ((GObjectClass *) (parent_class))->finalize)(object); + if (((GObjectClass *) (sp_lpe_item_parent_class))->finalize) { + (* ((GObjectClass *) (sp_lpe_item_parent_class))->finalize)(object); } } @@ -133,8 +108,8 @@ static void sp_lpe_item_build(SPObject *object, SPDocument *document, Inkscape:: { object->readAttr( "inkscape:path-effect" ); - if ((SP_OBJECT_CLASS(parent_class))->build) { - (SP_OBJECT_CLASS(parent_class))->build(object, document, repr); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->build) { + (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->build(object, document, repr); } } @@ -165,8 +140,8 @@ static void sp_lpe_item_release(SPObject *object) delete lpeitem->path_effect_list; lpeitem->path_effect_list = NULL; - if ((SP_OBJECT_CLASS(parent_class))->release) - (SP_OBJECT_CLASS(parent_class))->release(object); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->release) + (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->release(object); } /** @@ -234,8 +209,8 @@ static void sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *val } break; default: - if ((SP_OBJECT_CLASS(parent_class))->set) { - (SP_OBJECT_CLASS(parent_class))->set(object, key, value); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->set) { + (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->set(object, key, value); } break; } @@ -247,8 +222,8 @@ static void sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *val static void sp_lpe_item_update(SPObject *object, SPCtx *ctx, guint flags) { - if ((SP_OBJECT_CLASS(parent_class))->update) { - (SP_OBJECT_CLASS(parent_class))->update(object, ctx, flags); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->update) { + (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->update(object, ctx, flags); } // update the helperpaths of all LPEs applied to the item @@ -264,8 +239,8 @@ static void sp_lpe_item_modified (SPObject *object, unsigned int flags) sp_lpe_item_update_patheffect(SP_LPE_ITEM(object), true, true); } - if ((SP_OBJECT_CLASS(parent_class))->modified) { - (* (SP_OBJECT_CLASS(parent_class))->modified) (object, flags); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->modified) { + (* (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->modified) (object, flags); } } @@ -285,8 +260,8 @@ static Inkscape::XML::Node * sp_lpe_item_write(SPObject *object, Inkscape::XML:: } } - if ((SP_OBJECT_CLASS(parent_class))->write) { - (SP_OBJECT_CLASS(parent_class))->write(object, xml_doc, repr, flags); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->write) { + (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->write(object, xml_doc, repr, flags); } return repr; @@ -666,8 +641,8 @@ void sp_lpe_item_edit_next_param_oncanvas(SPLPEItem *lpeitem, SPDesktop *dt) static void sp_lpe_item_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - if ((SP_OBJECT_CLASS(parent_class))->child_added) - (* (SP_OBJECT_CLASS(parent_class))->child_added) (object, child, ref); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->child_added) + (* (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->child_added) (object, child, ref); if (SP_IS_LPE_ITEM(object) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(object))) { SPObject *ochild = object->get_child_by_repr(child); @@ -686,8 +661,8 @@ static void sp_lpe_item_remove_child(SPObject * object, Inkscape::XML::Node * ch } } - if ((SP_OBJECT_CLASS(parent_class))->remove_child) - (* (SP_OBJECT_CLASS(parent_class))->remove_child) (object, child); + if ((SP_OBJECT_CLASS(sp_lpe_item_parent_class))->remove_child) + (* (SP_OBJECT_CLASS(sp_lpe_item_parent_class))->remove_child) (object, child); } static std::string patheffectlist_write_svg(PathEffectList const & list) diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index 785a626f8..4243c9811 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -34,9 +34,6 @@ struct SPMaskView { Geom::OptRect bbox; }; -static void sp_mask_class_init (SPMaskClass *klass); -static void sp_mask_init (SPMask *mask); - static void sp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_mask_release (SPObject * object); static void sp_mask_set (SPObject *object, unsigned int key, const gchar *value); @@ -48,33 +45,11 @@ static Inkscape::XML::Node *sp_mask_write (SPObject *object, Inkscape::XML::Docu SPMaskView *sp_mask_view_new_prepend (SPMaskView *list, unsigned int key, Inkscape::DrawingItem *arenaitem); SPMaskView *sp_mask_view_list_remove (SPMaskView *list, SPMaskView *view); -static SPObjectGroupClass *parent_class; - -GType -sp_mask_get_type (void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof (SPMaskClass), - NULL, NULL, - (GClassInitFunc) sp_mask_class_init, - NULL, NULL, - sizeof (SPMask), - 16, - (GInstanceInitFunc) sp_mask_init, - NULL, /* value_table */ - }; - type = g_type_register_static (SP_TYPE_OBJECTGROUP, "SPMask", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPMask, sp_mask, SP_TYPE_OBJECTGROUP); static void sp_mask_class_init (SPMaskClass *klass) { - parent_class = SP_OBJECTGROUP_CLASS(g_type_class_ref(SP_TYPE_OBJECTGROUP)); - SPObjectClass *sp_object_class = (SPObjectClass *) klass; sp_object_class->build = sp_mask_build; sp_object_class->release = sp_mask_release; @@ -100,8 +75,8 @@ sp_mask_init (SPMask *mask) static void sp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); + if (((SPObjectClass *) sp_mask_parent_class)->build) { + ((SPObjectClass *) sp_mask_parent_class)->build (object, document, repr); } object->readAttr( "maskUnits" ); @@ -124,8 +99,8 @@ static void sp_mask_release (SPObject * object) cp->display = sp_mask_view_list_remove (cp->display, cp->display); } - if (((SPObjectClass *) (parent_class))->release) { - ((SPObjectClass *) parent_class)->release (object); + if (((SPObjectClass *) (sp_mask_parent_class))->release) { + ((SPObjectClass *) sp_mask_parent_class)->release (object); } } @@ -162,8 +137,8 @@ sp_mask_set (SPObject *object, unsigned int key, const gchar *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + if (((SPObjectClass *) sp_mask_parent_class)->set) + ((SPObjectClass *) sp_mask_parent_class)->set (object, key, value); break; } } @@ -172,7 +147,7 @@ static void sp_mask_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { /* Invoke SPObjectGroup implementation */ - ((SPObjectClass *) (parent_class))->child_added (object, child, ref); + ((SPObjectClass *) (sp_mask_parent_class))->child_added (object, child, ref); /* Show new object */ SPObject *ochild = object->document->getObjectByRepr(child); @@ -258,8 +233,8 @@ sp_mask_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML repr = xml_doc->createElement("svg:mask"); } - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + if (((SPObjectClass *) (sp_mask_parent_class))->write) + ((SPObjectClass *) (sp_mask_parent_class))->write (object, xml_doc, repr, flags); return repr; } diff --git a/src/sp-metadata.cpp b/src/sp-metadata.cpp index 831bb5a70..9978d0a3a 100644 --- a/src/sp-metadata.cpp +++ b/src/sp-metadata.cpp @@ -33,46 +33,19 @@ /* Metadata base class */ -static void sp_metadata_class_init (SPMetadataClass *klass); -static void sp_metadata_init (SPMetadata *metadata); - static void sp_metadata_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr); static void sp_metadata_release (SPObject *object); static void sp_metadata_set (SPObject *object, unsigned int key, const gchar *value); static void sp_metadata_update(SPObject *object, SPCtx *ctx, guint flags); static Inkscape::XML::Node *sp_metadata_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *metadata_parent_class; - -GType -sp_metadata_get_type (void) -{ - static GType metadata_type = 0; - - if (!metadata_type) { - GTypeInfo metadata_info = { - sizeof (SPMetadataClass), - NULL, NULL, - (GClassInitFunc) sp_metadata_class_init, - NULL, NULL, - sizeof (SPMetadata), - 16, - (GInstanceInitFunc) sp_metadata_init, - NULL, /* value_table */ - }; - metadata_type = g_type_register_static (SP_TYPE_OBJECT, "SPMetadata", &metadata_info, (GTypeFlags)0); - } - return metadata_type; -} +G_DEFINE_TYPE(SPMetadata, sp_metadata, SP_TYPE_OBJECT); static void sp_metadata_class_init (SPMetadataClass *klass) { - //GObjectClass *gobject_class = (GObjectClass *)klass; SPObjectClass *sp_object_class = (SPObjectClass *)klass; - metadata_parent_class = (SPObjectClass*)g_type_class_peek_parent (klass); - sp_object_class->build = sp_metadata_build; sp_object_class->release = sp_metadata_release; sp_object_class->write = sp_metadata_write; @@ -123,8 +96,8 @@ static void sp_metadata_build(SPObject *object, SPDocument *document, Inkscape:: } } - if (((SPObjectClass *) metadata_parent_class)->build) - ((SPObjectClass *) metadata_parent_class)->build (object, document, repr); + if (((SPObjectClass *) sp_metadata_parent_class)->build) + ((SPObjectClass *) sp_metadata_parent_class)->build (object, document, repr); } /** @@ -136,8 +109,8 @@ static void sp_metadata_release(SPObject *object) // handle ourself - if (((SPObjectClass *) metadata_parent_class)->release) - ((SPObjectClass *) metadata_parent_class)->release (object); + if (((SPObjectClass *) sp_metadata_parent_class)->release) + ((SPObjectClass *) sp_metadata_parent_class)->release (object); } /** @@ -150,8 +123,8 @@ static void sp_metadata_set(SPObject *object, unsigned int key, const gchar *val SP_METADATA(object); // ensures the object is of the proper type. // see if any parents need this value - if (reinterpret_cast(metadata_parent_class)->set) { - reinterpret_cast(metadata_parent_class)->set(object, key, value); + if (reinterpret_cast(sp_metadata_parent_class)->set) { + reinterpret_cast(sp_metadata_parent_class)->set(object, key, value); } } @@ -170,8 +143,8 @@ static void sp_metadata_update(SPObject *object, SPCtx *ctx, guint flags) } - if (((SPObjectClass *) metadata_parent_class)->update) - ((SPObjectClass *) metadata_parent_class)->update(object, ctx, flags); + if (((SPObjectClass *) sp_metadata_parent_class)->update) + ((SPObjectClass *) sp_metadata_parent_class)->update(object, ctx, flags); } /** @@ -190,8 +163,8 @@ static Inkscape::XML::Node *sp_metadata_write(SPObject *object, Inkscape::XML::D } } - if (((SPObjectClass *) metadata_parent_class)->write) { - ((SPObjectClass *) metadata_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_metadata_parent_class)->write) { + ((SPObjectClass *) sp_metadata_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index f18199e96..754a75e87 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -40,10 +40,6 @@ /* * Pattern */ - -static void sp_pattern_class_init (SPPatternClass *klass); -static void sp_pattern_init (SPPattern *gr); - static void sp_pattern_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); static void sp_pattern_release (SPObject *object); static void sp_pattern_set (SPObject *object, unsigned int key, const gchar *value); @@ -55,29 +51,7 @@ static void pattern_ref_modified (SPObject *ref, guint flags, SPPattern *pattern static cairo_pattern_t *sp_pattern_create_pattern(SPPaintServer *ps, cairo_t *ct, Geom::OptRect const &bbox, double opacity); -static SPPaintServerClass * pattern_parent_class; - -GType -sp_pattern_get_type (void) -{ - static GType pattern_type = 0; - if (!pattern_type) { - GTypeInfo pattern_info = { - sizeof (SPPatternClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_pattern_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (SPPattern), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_pattern_init, - NULL, /* value_table */ - }; - pattern_type = g_type_register_static (SP_TYPE_PAINT_SERVER, "SPPattern", &pattern_info, (GTypeFlags)0); - } - return pattern_type; -} +G_DEFINE_TYPE(SPPattern, sp_pattern, SP_TYPE_PAINT_SERVER); static void sp_pattern_class_init (SPPatternClass *klass) @@ -88,8 +62,6 @@ sp_pattern_class_init (SPPatternClass *klass) sp_object_class = (SPObjectClass *) klass; ps_class = (SPPaintServerClass *) klass; - pattern_parent_class = (SPPaintServerClass*)g_type_class_ref (SP_TYPE_PAINT_SERVER); - sp_object_class->build = sp_pattern_build; sp_object_class->release = sp_pattern_release; sp_object_class->set = sp_pattern_set; @@ -129,8 +101,8 @@ sp_pattern_init (SPPattern *pat) static void sp_pattern_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) pattern_parent_class)->build) - (* ((SPObjectClass *) pattern_parent_class)->build) (object, document, repr); + if (((SPObjectClass *) sp_pattern_parent_class)->build) + (* ((SPObjectClass *) sp_pattern_parent_class)->build) (object, document, repr); object->readAttr( "patternUnits" ); object->readAttr( "patternContentUnits" ); @@ -164,8 +136,8 @@ static void sp_pattern_release(SPObject *object) pat->modified_connection.~connection(); - if (((SPObjectClass *) pattern_parent_class)->release) { - ((SPObjectClass *) pattern_parent_class)->release (object); + if (((SPObjectClass *) sp_pattern_parent_class)->release) { + ((SPObjectClass *) sp_pattern_parent_class)->release (object); } } @@ -280,8 +252,8 @@ sp_pattern_set (SPObject *object, unsigned int key, const gchar *value) } break; default: - if (((SPObjectClass *) pattern_parent_class)->set) - ((SPObjectClass *) pattern_parent_class)->set (object, key, value); + if (((SPObjectClass *) sp_pattern_parent_class)->set) + ((SPObjectClass *) sp_pattern_parent_class)->set (object, key, value); break; } } diff --git a/src/sp-title.cpp b/src/sp-title.cpp index ddeccede2..489a6f448 100644 --- a/src/sp-title.cpp +++ b/src/sp-title.cpp @@ -16,38 +16,14 @@ #include "sp-title.h" #include "xml/repr.h" -static void sp_title_class_init(SPTitleClass *klass); -static void sp_title_init(SPTitle *rect); static Inkscape::XML::Node *sp_title_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *title_parent_class; - -GType -sp_title_get_type (void) -{ - static GType title_type = 0; - - if (!title_type) { - GTypeInfo title_info = { - sizeof (SPTitleClass), - NULL, NULL, - (GClassInitFunc) sp_title_class_init, - NULL, NULL, - sizeof (SPTitle), - 16, - (GInstanceInitFunc) sp_title_init, - NULL, /* value_table */ - }; - title_type = g_type_register_static (SP_TYPE_OBJECT, "SPTitle", &title_info, (GTypeFlags)0); - } - return title_type; -} +G_DEFINE_TYPE(SPTitle, sp_title, SP_TYPE_OBJECT); static void sp_title_class_init(SPTitleClass *klass) { SPObjectClass *sp_object_class = (SPObjectClass *) klass; - title_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); sp_object_class->write = sp_title_write; } @@ -66,8 +42,8 @@ static Inkscape::XML::Node *sp_title_write(SPObject *object, Inkscape::XML::Docu repr = object->getRepr()->duplicate(doc); } - if (((SPObjectClass *) title_parent_class)->write) { - ((SPObjectClass *) title_parent_class)->write(object, doc, repr, flags); + if (((SPObjectClass *) sp_title_parent_class)->write) { + ((SPObjectClass *) sp_title_parent_class)->write(object, doc, repr, flags); } return repr; diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index 7b6502ec3..e743e0efc 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -107,8 +107,6 @@ using Inkscape::ControlManager; namespace { SPCanvasGroup *create_control_group(SPDesktop *d); -void ink_node_tool_class_init(InkNodeToolClass *klass); -void ink_node_tool_init(InkNodeTool *node_context); void ink_node_tool_dispose(GObject *object); void ink_node_tool_setup(SPEventContext *ec); @@ -126,39 +124,10 @@ void handleControlUiStyleChange(InkNodeTool *nt); } // anonymous namespace -GType ink_node_tool_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(InkNodeToolClass), - NULL, NULL, - (GClassInitFunc) ink_node_tool_class_init, - NULL, NULL, - sizeof(InkNodeTool), - 4, - (GInstanceInitFunc) ink_node_tool_init, - NULL, /* value_table */ - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "InkNodeTool", &info, (GTypeFlags)0); - } - return type; -} - -namespace { - -SPCanvasGroup *create_control_group(SPDesktop *d) -{ - return reinterpret_cast(sp_canvas_item_new( - sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL)); -} - -void destroy_group(SPCanvasGroup *g) -{ - sp_canvas_item_destroy(SP_CANVAS_ITEM(g)); -} +G_DEFINE_TYPE(InkNodeTool, ink_node_tool, SP_TYPE_EVENT_CONTEXT); -void ink_node_tool_class_init(InkNodeToolClass *klass) +static void +ink_node_tool_class_init(InkNodeToolClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; SPEventContextClass *event_context_class = (SPEventContextClass *) klass; @@ -171,7 +140,8 @@ void ink_node_tool_class_init(InkNodeToolClass *klass) event_context_class->item_handler = ink_node_tool_item_handler; } -void ink_node_tool_init(InkNodeTool *nt) +static void +ink_node_tool_init(InkNodeTool *nt) { SPEventContext *event_context = SP_EVENT_CONTEXT(nt); @@ -191,6 +161,19 @@ void ink_node_tool_init(InkNodeTool *nt) new (&nt->_shape_editors) ShapeEditors(); } +namespace { + +SPCanvasGroup *create_control_group(SPDesktop *d) +{ + return reinterpret_cast(sp_canvas_item_new( + sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL)); +} + +void destroy_group(SPCanvasGroup *g) +{ + sp_canvas_item_destroy(SP_CANVAS_ITEM(g)); +} + void ink_node_tool_dispose(GObject *object) { InkNodeTool *nt = INK_NODE_TOOL(object); @@ -228,15 +211,15 @@ void ink_node_tool_dispose(GObject *object) delete nt->_node_message_context; } - G_OBJECT_CLASS(g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)))->dispose(object); + G_OBJECT_CLASS(ink_node_tool_parent_class)->dispose(object); } void ink_node_tool_setup(SPEventContext *ec) { InkNodeTool *nt = INK_NODE_TOOL(ec); - SPEventContextClass *parent = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)); - if (parent->setup) parent->setup(ec); + if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup) + SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup(ec); nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); @@ -372,10 +355,8 @@ void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) nt->edit_masks = value->getBool(); ink_node_tool_selection_changed(nt, nt->desktop->selection); } else { - SPEventContextClass *parent_class = - (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)); - if (parent_class->set) - parent_class->set(ec, value); + if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set) + SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set(ec, value); } } @@ -556,9 +537,9 @@ gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event) default: break; } - SPEventContextClass *parent_class = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)); - if (parent_class->root_handler) - return parent_class->root_handler(event_context, event); + if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler) + return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler(event_context, event); + return FALSE; } @@ -622,10 +603,9 @@ void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event) gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { - SPEventContextClass *parent_class = - (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)); - if (parent_class->item_handler) - return parent_class->item_handler(event_context, item, event); + if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler) + return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler(event_context, item, event); + return FALSE; } diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index d7be6c9f0..467f0d70e 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -25,8 +25,6 @@ #include "button.h" -static void sp_button_class_init (SPButtonClass *klass); -static void sp_button_init (SPButton *button); static void sp_button_dispose(GObject *object); #if GTK_CHECK_VERSION(3,0,0) @@ -50,28 +48,7 @@ static void sp_button_set_doubleclick_action (SPButton *button, SPAction *action static void sp_button_action_set_active (SPButton *button, bool active); static void sp_button_set_composed_tooltip (GtkWidget *widget, SPAction *action); -static GtkToggleButtonClass *parent_class; - -GType sp_button_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPButtonClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_button_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPButton), - 0, // n_preallocs - (GInstanceInitFunc)sp_button_init, - 0 // value_table - }; - type = g_type_register_static(GTK_TYPE_TOGGLE_BUTTON, "SPButton", &info, static_cast(0)); - } - return type; -} +G_DEFINE_TYPE(SPButton, sp_button, GTK_TYPE_TOGGLE_BUTTON); static void sp_button_class_init (SPButtonClass *klass) @@ -80,8 +57,6 @@ sp_button_class_init (SPButtonClass *klass) GtkWidgetClass *widget_class=GTK_WIDGET_CLASS(klass); GtkButtonClass *button_class=GTK_BUTTON_CLASS(klass); - parent_class = GTK_TOGGLE_BUTTON_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_button_dispose; #if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = sp_button_get_preferred_width; @@ -120,10 +95,10 @@ static void sp_button_dispose(GObject *object) sp_button_set_doubleclick_action (button, NULL); } - button->c_set_active.~connection(); - button->c_set_sensitive.~connection(); + button->c_set_active.~connection(); + button->c_set_sensitive.~connection(); - (G_OBJECT_CLASS(parent_class))->dispose(object); + (G_OBJECT_CLASS(sp_button_parent_class))->dispose(object); } @@ -185,7 +160,7 @@ sp_button_clicked (GtkButton *button) SPButton *sp_button=SP_BUTTON (button); if (sp_button->type == SP_BUTTON_TYPE_TOGGLE) { - (GTK_BUTTON_CLASS(parent_class))->clicked (button); + (GTK_BUTTON_CLASS(sp_button_parent_class))->clicked (button); } } @@ -340,3 +315,13 @@ sp_button_new_from_data( Inkscape::IconSize size, return button; } +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 7866989b1..8470e93db 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -41,9 +41,6 @@ #include "icon.h" struct IconImpl { - static void classInit(SPIconClass *klass); - static void init(SPIcon *icon); - static GtkWidget *newFull( Inkscape::IconSize lsize, gchar const *name ); static void dispose(GObject *object); @@ -104,12 +101,10 @@ struct IconImpl { private: static const std::string magicNumber; - static GtkWidgetClass *parent_class; static std::map legacyNames; }; const std::string IconImpl::magicNumber = "1.0"; -GtkWidgetClass *IconImpl::parent_class = 0; std::map IconImpl::legacyNames; @@ -141,34 +136,14 @@ public: static std::map > iconSetCache; static std::set internalNames; -GType SPIcon::getType() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPIconClass), - NULL, - NULL, - reinterpret_cast(IconImpl::classInit), - NULL, - NULL, - sizeof(SPIcon), - 0, - reinterpret_cast(IconImpl::init), - NULL - }; - type = g_type_register_static(GTK_TYPE_WIDGET, "SPIcon", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPIcon, sp_icon, GTK_TYPE_WIDGET); -void IconImpl::classInit(SPIconClass *klass) +static void +sp_icon_class_init(SPIconClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); - parent_class = GTK_WIDGET_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = IconImpl::dispose; #if GTK_CHECK_VERSION(3,0,0) @@ -184,7 +159,8 @@ void IconImpl::classInit(SPIconClass *klass) widget_class->style_set = IconImpl::styleSet; } -void IconImpl::init(SPIcon *icon) +static void +sp_icon_init(SPIcon *icon) { gtk_widget_set_has_window (GTK_WIDGET (icon), FALSE); icon->lsize = Inkscape::ICON_SIZE_BUTTON; @@ -202,7 +178,7 @@ void IconImpl::dispose(GObject *object) icon->name = 0; } - (G_OBJECT_CLASS(parent_class))->dispose(object); + (G_OBJECT_CLASS(sp_icon_parent_class))->dispose(object); } void IconImpl::reset( SPIcon *icon ) @@ -375,8 +351,8 @@ GdkPixbuf* IconImpl::renderup( gchar const* name, Inkscape::IconSize lsize, unsi void IconImpl::screenChanged( GtkWidget *widget, GdkScreen *previous_screen ) { - if ( GTK_WIDGET_CLASS( parent_class )->screen_changed ) { - GTK_WIDGET_CLASS( parent_class )->screen_changed( widget, previous_screen ); + if ( GTK_WIDGET_CLASS( sp_icon_parent_class )->screen_changed ) { + GTK_WIDGET_CLASS( sp_icon_parent_class )->screen_changed( widget, previous_screen ); } SPIcon *icon = SP_ICON(widget); themeChanged(icon); @@ -384,8 +360,8 @@ void IconImpl::screenChanged( GtkWidget *widget, GdkScreen *previous_screen ) void IconImpl::styleSet( GtkWidget *widget, GtkStyle *previous_style ) { - if ( GTK_WIDGET_CLASS( parent_class )->style_set ) { - GTK_WIDGET_CLASS( parent_class )->style_set( widget, previous_style ); + if ( GTK_WIDGET_CLASS( sp_icon_parent_class )->style_set ) { + GTK_WIDGET_CLASS( sp_icon_parent_class )->style_set( widget, previous_style ); } SPIcon *icon = SP_ICON(widget); themeChanged(icon); diff --git a/src/widgets/icon.h b/src/widgets/icon.h index 3f6aa2455..6bce2e330 100644 --- a/src/widgets/icon.h +++ b/src/widgets/icon.h @@ -17,7 +17,7 @@ #include #include "icon-size.h" -#define SP_TYPE_ICON SPIcon::getType() +#define SP_TYPE_ICON sp_icon_get_type() #define SP_ICON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_ICON, SPIcon)) #define SP_IS_ICON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SP_TYPE_ICON)) @@ -29,6 +29,8 @@ struct SPIconClass { GtkWidgetClass parent_class; }; +GType sp_icon_get_type() G_GNUC_CONST; + struct SPIcon { GtkWidget widget; @@ -38,8 +40,6 @@ struct SPIcon { GdkPixbuf *pb; - static GType getType(void); - friend class SPIconImpl; }; -- cgit v1.2.3 From 5ebf0c12c2b1be530bf4742236768a55e549494b Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 27 Jan 2013 14:19:11 +0000 Subject: Migrate ruler position tracking to new track_widget API Fixed bugs: - https://launchpad.net/bugs/1105504 (bzr r12067) --- src/desktop-events.cpp | 3 --- src/desktop.cpp | 6 ------ src/desktop.h | 1 - src/event-context.cpp | 3 +-- src/seltrans.cpp | 2 -- src/ui/view/edit-widget-interface.h | 3 --- src/ui/view/view.cpp | 17 ----------------- src/ui/view/view.h | 5 ----- src/widgets/desktop-widget.cpp | 10 +++------- src/widgets/desktop-widget.h | 2 -- 10 files changed, 4 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 1cfe018ce..9942e3a13 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -196,7 +196,6 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge sp_guideline_set_position(SP_GUIDELINE(guide), event_dt); desktop->set_coordinate_status(event_dt); - desktop->setPosition(event_dt); } break; case GDK_BUTTON_RELEASE: @@ -395,7 +394,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } moved = true; desktop->set_coordinate_status(motion_dt); - desktop->setPosition(motion_dt); ret = TRUE; } @@ -483,7 +481,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } moved = false; desktop->set_coordinate_status(event_dt); - desktop->setPosition (event_dt); } drag_type = SP_DRAG_NONE; sp_canvas_item_ungrab(item, event->button.time); diff --git a/src/desktop.cpp b/src/desktop.cpp index ea23ebb9c..c7a763ae1 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1538,12 +1538,6 @@ void SPDesktop::toggleSnapGlobal() //---------------------------------------------------------------------- // Callback implementations. The virtual ones are connected by the view. -void -SPDesktop::onPositionSet (double x, double y) -{ - _widget->viewSetPosition (Geom::Point(x,y)); -} - void SPDesktop::onResized (double /*x*/, double /*y*/) { diff --git a/src/desktop.h b/src/desktop.h index 529199692..93cf3201c 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -431,7 +431,6 @@ private: sigc::connection _commit_connection; sigc::connection _modified_connection; - virtual void onPositionSet (double, double); virtual void onResized (double, double); virtual void onRedrawRequested(); virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message); diff --git a/src/event-context.cpp b/src/event-context.cpp index 4e5917afa..096b310c3 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -1082,7 +1082,7 @@ gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPIte } /** - * Emits 'position_set' signal on desktop and shows coordinates on status bar. + * Shows coordinates on status bar. */ static void set_event_location(SPDesktop *desktop, GdkEvent *event) { if (event->type != GDK_MOTION_NOTIFY) { @@ -1091,7 +1091,6 @@ static void set_event_location(SPDesktop *desktop, GdkEvent *event) { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - desktop->setPosition(button_dt); desktop->set_coordinate_status(button_dt); } diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 64bb95508..b6c6baaf7 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -813,8 +813,6 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, Geom::Point *position, return TRUE; } - knot->desktop->setPosition(*position); - // When holding shift while rotating or skewing, the transformation will be // relative to the point opposite of the handle; otherwise it will be relative // to the center as set for the selection diff --git a/src/ui/view/edit-widget-interface.h b/src/ui/view/edit-widget-interface.h index 412c7ff8c..26e47abbb 100644 --- a/src/ui/view/edit-widget-interface.h +++ b/src/ui/view/edit-widget-interface.h @@ -101,9 +101,6 @@ struct EditWidgetInterface /// Update the "inactive desktop" indicator virtual void deactivateDesktop() = 0; - /// Set rulers to position - virtual void viewSetPosition (Geom::Point p) = 0; - /// Update rulers from current values virtual void updateRulers() = 0; diff --git a/src/ui/view/view.cpp b/src/ui/view/view.cpp index e13976cc4..72548e213 100644 --- a/src/ui/view/view.cpp +++ b/src/ui/view/view.cpp @@ -26,12 +26,6 @@ namespace Inkscape { namespace UI { namespace View { -static void -_onPositionSet (double x, double y, View* v) -{ - v->onPositionSet (x,y); -} - static void _onResized (double x, double y, View* v) { @@ -69,7 +63,6 @@ View::View() _message_stack = GC::release(new Inkscape::MessageStack()); _tips_message_context = new Inkscape::MessageContext(_message_stack); - _position_set_connection = _position_set_signal.connect (sigc::bind (sigc::ptr_fun (&_onPositionSet), this)); _resized_connection = _resized_signal.connect (sigc::bind (sigc::ptr_fun (&_onResized), this)); _redraw_requested_connection = _redraw_requested_signal.connect (sigc::bind (sigc::ptr_fun (&_onRedrawRequested), this)); @@ -102,16 +95,6 @@ void View::_close() { Inkscape::Verb::delete_all_view (this); } -void View::setPosition (double x, double y) -{ - _position_set_signal.emit (x,y); -} - -void View::setPosition(Geom::Point const &p) -{ - setPosition (double(p[Geom::X]), double(p[Geom::Y])); -} - void View::emitResized (double width, double height) { _resized_signal.emit (width, height); diff --git a/src/ui/view/view.h b/src/ui/view/view.h index 6ed9f476c..48f4d2549 100644 --- a/src/ui/view/view.h +++ b/src/ui/view/view.h @@ -90,8 +90,6 @@ public: Inkscape::MessageContext *tipsMessageContext() const { return _tips_message_context; } - void setPosition(gdouble x, gdouble y); - void setPosition(Geom::Point const &p); void emitResized(gdouble width, gdouble height); void requestRedraw(); @@ -101,7 +99,6 @@ public: virtual void mouseover() = 0; virtual void mouseout() = 0; - virtual void onPositionSet (double, double) = 0; virtual void onResized (double, double) = 0; virtual void onRedrawRequested() = 0; virtual void onStatusMessage (Inkscape::MessageType type, gchar const *message) = 0; @@ -126,13 +123,11 @@ protected: */ virtual void setDocument(SPDocument *doc); - sigc::signal _position_set_signal; sigc::signal _resized_signal; sigc::signal _document_uri_set_signal; sigc::signal _redraw_requested_signal; private: - sigc::connection _position_set_connection; sigc::connection _resized_connection; sigc::connection _redraw_requested_connection; sigc::connection _message_changed_connection; // foreign diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index a7432c32a..8a47b345e 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -520,6 +520,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) gtk_widget_set_can_focus (GTK_WIDGET (dtw->canvas), TRUE); + sp_ruler_add_track_widget (SP_RULER(dtw->hruler), GTK_WIDGET(dtw->canvas)); + sp_ruler_add_track_widget (SP_RULER(dtw->vruler), GTK_WIDGET(dtw->canvas)); + #if GTK_CHECK_VERSION(3,0,0) GdkRGBA white = {1,1,1,1}; gtk_widget_override_background_color(GTK_WIDGET(dtw->canvas), @@ -1685,13 +1688,6 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) return dtw; } -void -SPDesktopWidget::viewSetPosition (Geom::Point p) -{ - Geom::Point const origin = ( p - ruler_origin ); - sp_ruler_set_position(SP_RULER(hruler), origin[Geom::X]); - sp_ruler_set_position(SP_RULER(vruler), origin[Geom::Y]); -} void sp_desktop_widget_update_rulers (SPDesktopWidget *dtw) diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index 73194304f..dedda7123 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -168,8 +168,6 @@ struct SPDesktopWidget { { sp_dtw_desktop_activate (_dtw); } virtual void deactivateDesktop() { sp_dtw_desktop_deactivate (_dtw); } - virtual void viewSetPosition (Geom::Point p) - { _dtw->viewSetPosition (p); } virtual void updateRulers() { sp_desktop_widget_update_rulers (_dtw); } virtual void updateScrollbars (double scale) -- cgit v1.2.3 From aca87f3d80cf0f83414918cf013ea4eb20336576 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 27 Jan 2013 15:28:36 +0000 Subject: desktop-widget: Add callback to ensure that ruler ranges are correctly updated when canvas table resizes Fixed bugs: - https://launchpad.net/bugs/950552 (bzr r12068) --- src/widgets/desktop-widget.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 8a47b345e..e6fabd50b 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -312,6 +312,22 @@ sp_desktop_widget_class_init (SPDesktopWidgetClass *klass) widget_class->realize = sp_desktop_widget_realize; } +/** + * Callback for changes in size of the canvas table (i.e. the container for + * the canvas, the rulers etc). + * + * This adjusts the range of the rulers when the dock container is adjusted + * (fixes lp:950552) + */ +static void +canvas_tbl_size_allocate(GtkWidget *widget, + GdkRectangle *allocation, + gpointer data) +{ + SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data); + sp_desktop_widget_update_rulers (dtw); +} + /** * Callback for SPDesktopWidget object initialization. */ @@ -743,6 +759,13 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) } overallTimer = 0; } + + // Ensure that ruler ranges are updated correctly whenever the canvas table + // is resized + g_signal_connect (G_OBJECT (canvas_tbl), + "size-allocate", + G_CALLBACK (canvas_tbl_size_allocate), + dtw); } /** -- cgit v1.2.3 From 7d0ffab9f60904f429176eec7a8196e3478bfebf Mon Sep 17 00:00:00 2001 From: su_v Date: Mon, 28 Jan 2013 17:07:35 +0100 Subject: libcdr: add remaining CorelDRAW formats (CDT, CCX, CMX) to internal support (bzr r12059.1.4) --- src/extension/internal/cdr-input.cpp | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src') diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index 63531d082..8abf772b8 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -274,6 +274,45 @@ void CdrInput::init(void) "\n" "", new CdrInput()); + /* CDT */ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Corel DRAW templates input") "\n" + "org.inkscape.input.cdt\n" + "\n" + ".cdt\n" + "application/x-xcdt\n" + "" N_("Corel DRAW 7-13 template files (*.cdt)") "\n" + "" N_("Open files saved in Corel DRAW 7-13") "\n" + "\n" + "", new CdrInput()); + + /* CCX */ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Corel DRAW Compressed Exchange files input") "\n" + "org.inkscape.input.ccx\n" + "\n" + ".ccx\n" + "application/x-xccx\n" + "" N_("Corel DRAW Compressed Exchange files (*.ccx)") "\n" + "" N_("Open compressed exchange files saved in Corel DRAW") "\n" + "\n" + "", new CdrInput()); + + /* CMX */ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Corel DRAW Presentation Exchange files input") "\n" + "org.inkscape.input.cmx\n" + "\n" + ".cmx\n" + "application/x-xcmx\n" + "" N_("Corel DRAW Presentation Exchange files (*.cmx)") "\n" + "" N_("Open presentation exchange files saved in Corel DRAW") "\n" + "\n" + "", new CdrInput()); + return; } // init -- cgit v1.2.3 From bb82bced04efb9fd9b35e06c76cc8043d0306c44 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Mon, 28 Jan 2013 15:53:29 -0500 Subject: Path::OutlineJoin. remove redundant nodes which are causing glitches (Bug 820425) Fixed bugs: - https://launchpad.net/bugs/820425 (bzr r12069) --- src/livarot/Path.h | 2 +- src/livarot/PathOutline.cpp | 48 +++++++++++++++++++++++++++++---------------- src/splivarot.cpp | 4 ++-- 3 files changed, 34 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/livarot/Path.h b/src/livarot/Path.h index 1f0e7a244..cd939bf7d 100644 --- a/src/livarot/Path.h +++ b/src/livarot/Path.h @@ -335,7 +335,7 @@ public: PathDescrBezierTo & fin, bool before, Geom::Point & pos, Geom::Point & tgt, double &len, double &rad); static void OutlineJoin (Path * dest, Geom::Point pos, Geom::Point stNor, Geom::Point enNor, - double width, JoinType join, double miter); + double width, JoinType join, double miter, int nType); static bool IsNulCurve (std::vector const &cmd, int curD, Geom::Point const &curX); diff --git a/src/livarot/PathOutline.cpp b/src/livarot/PathOutline.cpp index f00798c8a..1993a7862 100644 --- a/src/livarot/PathOutline.cpp +++ b/src/livarot/PathOutline.cpp @@ -387,7 +387,7 @@ void Path::SubContractOutline(int off, int num_pd, if (closeIfNeeded) { if ( Geom::LInfty (curX- firstP) < 0.0001 ) { OutlineJoin (dest, firstP, curT, firstT, width, join, - miter); + miter, nType); dest->Close (); } else { PathDescrLineTo temp(firstP); @@ -404,7 +404,7 @@ void Path::SubContractOutline(int off, int num_pd, Geom::Point pos; pos = curX; OutlineJoin (dest, pos, curT, stNor, width, join, - miter); + miter, nType); } dest->LineTo (enPos+width*enNor); @@ -413,7 +413,7 @@ void Path::SubContractOutline(int off, int num_pd, Geom::Point pos; pos = firstP; OutlineJoin (dest, enPos, enNor, firstT, width, join, - miter); + miter, nType); dest->Close (); } } @@ -429,7 +429,7 @@ void Path::SubContractOutline(int off, int num_pd, if (Geom::LInfty (curX - firstP) < 0.0001) { OutlineJoin (dest, firstP, curT, firstT, width, join, - miter); + miter, nType); dest->Close (); } else @@ -445,7 +445,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure { OutlineJoin (dest, stPos, curT, stNor, width, join, - miter); + miter, nType); } dest->LineTo (enPos+width*enNor); @@ -453,7 +453,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure { OutlineJoin (dest, enPos, enNor, firstT, width, join, - miter); + miter, nType); dest->Close (); } } @@ -497,7 +497,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure Geom::Point pos; pos = curX; - OutlineJoin (dest, pos, curT, stNor, width, join, miter); + OutlineJoin (dest, pos, curT, stNor, width, join, miter, nType); } int n_d = dest->LineTo (nextX+width*enNor); @@ -547,7 +547,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure Geom::Point pos; pos = curX; - OutlineJoin (dest, pos, curT, stNor, width, join, miter); + OutlineJoin (dest, pos, curT, stNor, width, join, miter, nType); } callsData.piece = curP; @@ -603,7 +603,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure Geom::Point pos; pos = curX; - OutlineJoin (dest, pos, curT, stNor, width, join, miter); + OutlineJoin (dest, pos, curT, stNor, width, join, miter, nType); } callsData.piece = curP; @@ -661,7 +661,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure Geom::Point pos; pos = curX; - if (stTle > 0) OutlineJoin (dest, pos, curT, stNor, width, join, miter); + if (stTle > 0) OutlineJoin (dest, pos, curT, stNor, width, join, miter, nType); } int n_d = dest->LineTo (nextX+width*enNor); if (n_d >= 0) { @@ -692,7 +692,7 @@ void Path::SubContractOutline(int off, int num_pd, // jointure Geom::Point pos; pos = curX; - OutlineJoin (dest, pos, curT, stNor, width, join, miter); + OutlineJoin (dest, pos, curT, stNor, width, join, miter, nType); } callsData.piece = curP; @@ -729,7 +729,7 @@ void Path::SubContractOutline(int off, int num_pd, } else { // jointure Geom::Point pos=curX; - OutlineJoin (dest, pos, stTgt, stNor, width, join, miter); + OutlineJoin (dest, pos, stTgt, stNor, width, join, miter, nType); // dest->LineTo(curX+width*stNor.x,curY+width*stNor.y); } } @@ -1164,7 +1164,7 @@ Path::TangentOnBezAt (double at, Geom::Point const &iS, void Path::OutlineJoin (Path * dest, Geom::Point pos, Geom::Point stNor, Geom::Point enNor, double width, - JoinType join, double miter) + JoinType join, double miter, int nType) { /* Arbitrarily decide if we're on the inside or outside of a half turn. @@ -1188,8 +1188,16 @@ Path::OutlineJoin (Path * dest, Geom::Point pos, Geom::Point stNor, Geom::Point } else { if ((angSi > 0 && width >= 0) || (angSi < 0 && width < 0)) { // This is an inside join -> join is independent of chosen JoinType. - dest->LineTo (pos); - dest->LineTo (pos + width*enNor); + if ((dest->descr_cmd[dest->descr_cmd.size() - 1]->getType() == descr_lineto) && (nType == descr_lineto)) { + PathDescrLineTo* nLine = dynamic_cast(dest->descr_cmd[dest->descr_cmd.size() - 1]); + Geom::Point const biss = unit_vector(Geom::rot90( stNor - enNor )); + double c2 = Geom::dot (biss, enNor); + double l = width / c2; + nLine->p = pos + l*biss; // relocate to bisector + } else { +// dest->LineTo (pos); // redundant + dest->LineTo (pos + width*enNor); + } } else if (angSi == 0 && TurnInside) { // Half turn (180 degrees) ... inside (see above). dest->LineTo (pos + width*enNor); } else { // This is an outside join -> chosen JoinType should be applied. @@ -1241,8 +1249,14 @@ Path::OutlineJoin (Path * dest, Geom::Point pos, Geom::Point stNor, Geom::Point if ( fabs(l) > miter) { dest->LineTo (pos + width*enNor); } else { - dest->LineTo (pos+l*biss); - dest->LineTo (pos+width*enNor); + if (dest->descr_cmd[dest->descr_cmd.size() - 1]->getType() == descr_lineto) { + PathDescrLineTo* nLine = dynamic_cast(dest->descr_cmd[dest->descr_cmd.size() - 1]); + nLine->p = pos+l*biss; // relocate to bisector + } else { + dest->LineTo (pos+l*biss); + } + if (nType != descr_lineto) + dest->LineTo (pos+width*enNor); } } else { // Bevel join dest->LineTo (pos + width*enNor); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index f04d92616..68664cb3c 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -1002,8 +1002,8 @@ sp_selected_path_outline(SPDesktop *desktop) break; } - if (o_width < 0.1) - o_width = 0.1; + if (o_width < 0.01) + o_width = 0.01; o_miter = i_style->stroke_miterlimit.value * o_width; } -- cgit v1.2.3 From 7900b2459ca0a6f6e11a367443046582c4852752 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 29 Jan 2013 15:23:22 +0100 Subject: Filter color values always defined as sRGB (or ICC). (bzr r12070) --- src/display/cairo-utils.cpp | 9 ++++++++ src/display/cairo-utils.h | 1 + src/display/nr-filter-diffuselighting.cpp | 37 +++++++++++++++++++++++++++--- src/display/nr-filter-diffuselighting.h | 3 +++ src/display/nr-filter-flood.cpp | 17 ++++++++++---- src/display/nr-filter-specularlighting.cpp | 37 +++++++++++++++++++++++++++--- src/display/nr-filter-specularlighting.h | 3 +++ src/filters/diffuselighting.cpp | 17 ++++++++++++++ src/filters/diffuselighting.h | 8 +++---- src/filters/specularlighting.cpp | 17 ++++++++++++++ src/filters/specularlighting.h | 3 +++ 11 files changed, 137 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 9655fc194..831b37899 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -597,6 +597,15 @@ void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, a = CLAMP(a, 0.0, 1.0); } +void srgb_to_linear( double* c ) { + + if( *c < 0.04045 ) { + *c /= 12.92; + } else { + *c = pow( (*c+0.055)/1.055, 2.4 ); + } +} + void srgb_to_linear( guint32* c, guint32 a ) { *c = unpremul_alpha( *c, a ); diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index af4727c01..04d6c6810 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -108,6 +108,7 @@ guint32 ink_cairo_surface_average_color(cairo_surface_t *surface); void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a); void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a); +void srgb_to_linear( double *c); int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface); int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface); diff --git a/src/display/nr-filter-diffuselighting.cpp b/src/display/nr-filter-diffuselighting.cpp index faf56a4ca..22e6731c3 100644 --- a/src/display/nr-filter-diffuselighting.cpp +++ b/src/display/nr-filter-diffuselighting.cpp @@ -21,6 +21,8 @@ #include "display/nr-filter-units.h" #include "display/nr-filter-utils.h" #include "display/nr-light.h" +#include "svg/svg-icc-color.h" +#include "svg/svg-color.h" namespace Inkscape { namespace Filters { @@ -126,12 +128,37 @@ void FilterDiffuseLighting::render_cairo(FilterSlot &slot) cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + double r = SP_RGBA32_R_F(lighting_color); + double g = SP_RGBA32_G_F(lighting_color); + double b = SP_RGBA32_B_F(lighting_color); + +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) + + if (icc) { + guchar ru, gu, bu; + icc_color_to_sRGB(icc, &ru, &gu, &bu); + r = SP_COLOR_U_TO_F(ru); + g = SP_COLOR_U_TO_F(gu); + b = SP_COLOR_U_TO_F(bu); + } +#endif + // Only alpha channel of input is used, no need to check input color_interpolation_filter value. SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; if( _style ) { ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + + // Lighting color is always defined in terms of sRGB, preconvert to linearRGB + // if color_interpolation_filters set to linearRGB (for efficiency assuming + // next filter primitive has same value of cif). + if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { + srgb_to_linear( &r ); + srgb_to_linear( &g ); + srgb_to_linear( &b ); + } } set_cairo_surface_ci(out, ci_fp ); + guint32 color = SP_RGBA32_F_COMPOSE( r, g, b, 1.0 ); Geom::Rect slot_area = slot.get_slot_area(); Geom::Point p = slot_area.min(); @@ -142,15 +169,15 @@ void FilterDiffuseLighting::render_cairo(FilterSlot &slot) switch (light_type) { case DISTANT_LIGHT: ink_cairo_surface_synthesize(out, - DiffuseDistantLight(input, light.distant, lighting_color, scale, diffuseConstant)); + DiffuseDistantLight(input, light.distant, color, scale, diffuseConstant)); break; case POINT_LIGHT: ink_cairo_surface_synthesize(out, - DiffusePointLight(input, light.point, lighting_color, trans, scale, diffuseConstant, x0, y0)); + DiffusePointLight(input, light.point, color, trans, scale, diffuseConstant, x0, y0)); break; case SPOT_LIGHT: ink_cairo_surface_synthesize(out, - DiffuseSpotLight(input, light.spot, lighting_color, trans, scale, diffuseConstant, x0, y0)); + DiffuseSpotLight(input, light.spot, color, trans, scale, diffuseConstant, x0, y0)); break; default: { cairo_t *ct = cairo_create(out); @@ -165,6 +192,10 @@ void FilterDiffuseLighting::render_cairo(FilterSlot &slot) cairo_surface_destroy(out); } +void FilterDiffuseLighting::set_icc(SVGICCColor *icc_color) { + icc = icc_color; +} + void FilterDiffuseLighting::area_enlarge(Geom::IntRect &area, Geom::Affine const & /*trans*/) { // TODO: support kernelUnitLength diff --git a/src/display/nr-filter-diffuselighting.h b/src/display/nr-filter-diffuselighting.h index 0da6cc218..315bf9f48 100644 --- a/src/display/nr-filter-diffuselighting.h +++ b/src/display/nr-filter-diffuselighting.h @@ -22,6 +22,7 @@ class SPFeDistantLight; class SPFePointLight; class SPFeSpotLight; +class SVGICCColor; namespace Inkscape { namespace Filters { @@ -32,6 +33,7 @@ public: static FilterPrimitive *create(); virtual ~FilterDiffuseLighting(); virtual void render_cairo(FilterSlot &slot); + virtual void set_icc(SVGICCColor *icc_color); virtual void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans); virtual double complexity(Geom::Affine const &ctm); @@ -46,6 +48,7 @@ public: guint32 lighting_color; private: + SVGICCColor *icc; }; } /* namespace Filters */ diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 7117e0343..0c581762d 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -45,8 +45,6 @@ void FilterFlood::render_cairo(FilterSlot &slot) #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - // DOES THIS REALLY BELONG HERE? SHOULDN'T ICC BE APPLIED AFTER ALL COMPOSITING? - // What if color_interpolation_filter is set to linear RGB? if (icc) { guchar ru, gu, bu; icc_color_to_sRGB(icc, &ru, &gu, &bu); @@ -57,10 +55,21 @@ void FilterFlood::render_cairo(FilterSlot &slot) #endif cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); - // color_interpolation_filter is determined by CSS value (see spec. Turbulence). + + SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; if( _style ) { - set_cairo_surface_ci(out, (SPColorInterpolation)_style->color_interpolation_filters.computed ); + ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + + // Flood color is always defined in terms of sRGB, preconvert to linearRGB + // if color_interpolation_filters set to linearRGB (for efficiency assuming + // next filter primitive has same value of cif). + if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { + srgb_to_linear( &r ); + srgb_to_linear( &g ); + srgb_to_linear( &b ); + } } + set_cairo_surface_ci(out, ci_fp ); // Get filter primitive area in user units Geom::Rect fp = filter_primitive_area( slot.get_units() ); diff --git a/src/display/nr-filter-specularlighting.cpp b/src/display/nr-filter-specularlighting.cpp index 50f1b48c5..535633143 100644 --- a/src/display/nr-filter-specularlighting.cpp +++ b/src/display/nr-filter-specularlighting.cpp @@ -21,6 +21,8 @@ #include "display/nr-filter-units.h" #include "display/nr-filter-utils.h" #include "display/nr-light.h" +#include "svg/svg-icc-color.h" +#include "svg/svg-color.h" namespace Inkscape { namespace Filters { @@ -139,12 +141,37 @@ void FilterSpecularLighting::render_cairo(FilterSlot &slot) cairo_surface_t *input = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); + double r = SP_RGBA32_R_F(lighting_color); + double g = SP_RGBA32_G_F(lighting_color); + double b = SP_RGBA32_B_F(lighting_color); + +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) + + if (icc) { + guchar ru, gu, bu; + icc_color_to_sRGB(icc, &ru, &gu, &bu); + r = SP_COLOR_U_TO_F(ru); + g = SP_COLOR_U_TO_F(gu); + b = SP_COLOR_U_TO_F(bu); + } +#endif + // Only alpha channel of input is used, no need to check input color_interpolation_filter value. SPColorInterpolation ci_fp = SP_CSS_COLOR_INTERPOLATION_AUTO; if( _style ) { ci_fp = (SPColorInterpolation)_style->color_interpolation_filters.computed; + + // Lighting color is always defined in terms of sRGB, preconvert to linearRGB + // if color_interpolation_filters set to linearRGB (for efficiency assuming + // next filter primitive has same value of cif). + if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { + srgb_to_linear( &r ); + srgb_to_linear( &g ); + srgb_to_linear( &b ); + } } set_cairo_surface_ci(out, ci_fp ); + guint32 color = SP_RGBA32_F_COMPOSE( r, g, b, 1.0 ); Geom::Affine trans = slot.get_units().get_matrix_primitiveunits2pb(); Geom::Point p = slot.get_slot_area().min(); @@ -157,15 +184,15 @@ void FilterSpecularLighting::render_cairo(FilterSlot &slot) switch (light_type) { case DISTANT_LIGHT: ink_cairo_surface_synthesize(out, - SpecularDistantLight(input, light.distant, lighting_color, scale, ks, se)); + SpecularDistantLight(input, light.distant, color, scale, ks, se)); break; case POINT_LIGHT: ink_cairo_surface_synthesize(out, - SpecularPointLight(input, light.point, lighting_color, trans, scale, ks, se, x0, y0)); + SpecularPointLight(input, light.point, color, trans, scale, ks, se, x0, y0)); break; case SPOT_LIGHT: ink_cairo_surface_synthesize(out, - SpecularSpotLight(input, light.spot, lighting_color, trans, scale, ks, se, x0, y0)); + SpecularSpotLight(input, light.spot, color, trans, scale, ks, se, x0, y0)); break; default: { cairo_t *ct = cairo_create(out); @@ -180,6 +207,10 @@ void FilterSpecularLighting::render_cairo(FilterSlot &slot) cairo_surface_destroy(out); } +void FilterSpecularLighting::set_icc(SVGICCColor *icc_color) { + icc = icc_color; +} + void FilterSpecularLighting::area_enlarge(Geom::IntRect &area, Geom::Affine const & /*trans*/) { // TODO: support kernelUnitLength diff --git a/src/display/nr-filter-specularlighting.h b/src/display/nr-filter-specularlighting.h index 33ea17a87..4f8c2d112 100644 --- a/src/display/nr-filter-specularlighting.h +++ b/src/display/nr-filter-specularlighting.h @@ -20,6 +20,7 @@ class SPFeDistantLight; class SPFePointLight; class SPFeSpotLight; +class SVGICCColor; namespace Inkscape { namespace Filters { @@ -33,6 +34,7 @@ public: virtual ~FilterSpecularLighting(); virtual void render_cairo(FilterSlot &slot); + virtual void set_icc(SVGICCColor *icc_color); virtual void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans); virtual double complexity(Geom::Affine const &ctm); @@ -48,6 +50,7 @@ public: guint32 lighting_color; private: + SVGICCColor *icc; }; } /* namespace Filters */ diff --git a/src/filters/diffuselighting.cpp b/src/filters/diffuselighting.cpp index 2e69f7555..66dd825f6 100644 --- a/src/filters/diffuselighting.cpp +++ b/src/filters/diffuselighting.cpp @@ -18,10 +18,13 @@ # include "config.h" #endif +#include "strneq.h" + #include "attributes.h" #include "svg/svg.h" #include "sp-object.h" #include "svg/svg-color.h" +#include "svg/svg-icc-color.h" #include "filters/diffuselighting.h" #include "filters/distantlight.h" #include "filters/pointlight.h" @@ -74,6 +77,8 @@ sp_feDiffuseLighting_init(SPFeDiffuseLighting *feDiffuseLighting) feDiffuseLighting->surfaceScale = 1; feDiffuseLighting->diffuseConstant = 1; feDiffuseLighting->lighting_color = 0xffffffff; + feDiffuseLighting->icc = NULL; + //TODO kernelUnit feDiffuseLighting->renderer = NULL; @@ -176,6 +181,16 @@ sp_feDiffuseLighting_set(SPObject *object, unsigned int key, gchar const *value) feDiffuseLighting->lighting_color = sp_svg_read_color(value, &cend_ptr, 0xffffffff); //if a value was read if (cend_ptr) { + while (g_ascii_isspace(*cend_ptr)) { + ++cend_ptr; + } + if (strneq(cend_ptr, "icc-color(", 10)) { + if (!feDiffuseLighting->icc) feDiffuseLighting->icc = new SVGICCColor(); + if ( ! sp_svg_read_icc_color( cend_ptr, feDiffuseLighting->icc ) ) { + delete feDiffuseLighting->icc; + feDiffuseLighting->icc = NULL; + } + } feDiffuseLighting->lighting_color_set = TRUE; } else { //lighting_color already contains the default value @@ -328,6 +343,8 @@ static void sp_feDiffuseLighting_build_renderer(SPFilterPrimitive *primitive, In nr_diffuselighting->diffuseConstant = sp_diffuselighting->diffuseConstant; nr_diffuselighting->surfaceScale = sp_diffuselighting->surfaceScale; nr_diffuselighting->lighting_color = sp_diffuselighting->lighting_color; + nr_diffuselighting->set_icc(sp_diffuselighting->icc); + //We assume there is at most one child nr_diffuselighting->light_type = Inkscape::Filters::NO_LIGHT; if (SP_IS_FEDISTANTLIGHT(primitive->children)) { diff --git a/src/filters/diffuselighting.h b/src/filters/diffuselighting.h index a23346622..99dccb394 100644 --- a/src/filters/diffuselighting.h +++ b/src/filters/diffuselighting.h @@ -15,17 +15,14 @@ #include "sp-filter-primitive.h" #include "number-opt-number.h" -namespace Inkscape { -namespace Filters { -class FilterDiffuseLighting; -} } - #define SP_TYPE_FEDIFFUSELIGHTING (sp_feDiffuseLighting_get_type()) #define SP_FEDIFFUSELIGHTING(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_FEDIFFUSELIGHTING, SPFeDiffuseLighting)) #define SP_FEDIFFUSELIGHTING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_FEDIFFUSELIGHTING, SPFeDiffuseLightingClass)) #define SP_IS_FEDIFFUSELIGHTING(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FEDIFFUSELIGHTING)) #define SP_IS_FEDIFFUSELIGHTING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_FEDIFFUSELIGHTING)) +class SVGICCColor; + namespace Inkscape { namespace Filters { class FilterDiffuseLighting; @@ -42,6 +39,7 @@ struct SPFeDiffuseLighting : public SPFilterPrimitive { guint32 lighting_color; guint lighting_color_set : 1; Inkscape::Filters::FilterDiffuseLighting *renderer; + SVGICCColor *icc; }; struct SPFeDiffuseLightingClass { diff --git a/src/filters/specularlighting.cpp b/src/filters/specularlighting.cpp index 44eeff35a..a7a19e11d 100644 --- a/src/filters/specularlighting.cpp +++ b/src/filters/specularlighting.cpp @@ -18,10 +18,13 @@ # include "config.h" #endif +#include "strneq.h" + #include "attributes.h" #include "svg/svg.h" #include "sp-object.h" #include "svg/svg-color.h" +#include "svg/svg-icc-color.h" #include "filters/specularlighting.h" #include "filters/distantlight.h" #include "filters/pointlight.h" @@ -75,6 +78,8 @@ sp_feSpecularLighting_init(SPFeSpecularLighting *feSpecularLighting) feSpecularLighting->specularConstant = 1; feSpecularLighting->specularExponent = 1; feSpecularLighting->lighting_color = 0xffffffff; + feSpecularLighting->icc = NULL; + //TODO kernelUnit feSpecularLighting->renderer = NULL; @@ -202,6 +207,16 @@ sp_feSpecularLighting_set(SPObject *object, unsigned int key, gchar const *value feSpecularLighting->lighting_color = sp_svg_read_color(value, &cend_ptr, 0xffffffff); //if a value was read if (cend_ptr) { + while (g_ascii_isspace(*cend_ptr)) { + ++cend_ptr; + } + if (strneq(cend_ptr, "icc-color(", 10)) { + if (!feSpecularLighting->icc) feSpecularLighting->icc = new SVGICCColor(); + if ( ! sp_svg_read_icc_color( cend_ptr, feSpecularLighting->icc ) ) { + delete feSpecularLighting->icc; + feSpecularLighting->icc = NULL; + } + } feSpecularLighting->lighting_color_set = TRUE; } else { //lighting_color already contains the default value @@ -352,6 +367,8 @@ static void sp_feSpecularLighting_build_renderer(SPFilterPrimitive *primitive, I nr_specularlighting->specularExponent = sp_specularlighting->specularExponent; nr_specularlighting->surfaceScale = sp_specularlighting->surfaceScale; nr_specularlighting->lighting_color = sp_specularlighting->lighting_color; + nr_specularlighting->set_icc(sp_specularlighting->icc); + //We assume there is at most one child nr_specularlighting->light_type = Inkscape::Filters::NO_LIGHT; if (SP_IS_FEDISTANTLIGHT(primitive->children)) { diff --git a/src/filters/specularlighting.h b/src/filters/specularlighting.h index 90d1f9f62..44bd98c6c 100644 --- a/src/filters/specularlighting.h +++ b/src/filters/specularlighting.h @@ -23,6 +23,8 @@ #define SP_IS_FESPECULARLIGHTING(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FESPECULARLIGHTING)) #define SP_IS_FESPECULARLIGHTING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_FESPECULARLIGHTING)) +class SVGICCColor; + namespace Inkscape { namespace Filters { class FilterSpecularLighting; @@ -41,6 +43,7 @@ struct SPFeSpecularLighting : public SPFilterPrimitive { NumberOptNumber kernelUnitLength; guint32 lighting_color; guint lighting_color_set : 1; + SVGICCColor *icc; Inkscape::Filters::FilterSpecularLighting *renderer; }; -- cgit v1.2.3 From 32ff8baed32f34bf6083d05fa27b8bb1b2d0d596 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 29 Jan 2013 18:12:40 +0100 Subject: Crash. Partial fix for Bug #1046068 (Inkscape (GTK+/Quartz) calls output extensions or crashes when quitting while clipboard not empty). (bzr r12071) --- src/document.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/document.cpp b/src/document.cpp index 172037518..97b3bf584 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1435,10 +1435,12 @@ bool SPDocument::isSeeking() const { void SPDocument::setModifiedSinceSave(bool modified) { this->modified_since_save = modified; - Gtk::Window *parent = SP_ACTIVE_DESKTOP->getToplevel(); - g_assert(parent != NULL); - SPDesktopWidget *dtw = static_cast(parent->get_data("desktopwidget")); - dtw->updateTitle( this->getName() ); + if (SP_ACTIVE_DESKTOP) { + Gtk::Window *parent = SP_ACTIVE_DESKTOP->getToplevel(); + g_assert(parent != NULL); + SPDesktopWidget *dtw = static_cast(parent->get_data("desktopwidget")); + dtw->updateTitle( this->getName() ); + } } -- cgit v1.2.3 From 2fd49c7b03821f690f088a9478ee4780c211d748 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Tue, 29 Jan 2013 16:00:01 -0500 Subject: for Stroke to Path, change minimum stroke width from 0.01 to 0.032 (Bug 820425, comment 5) Fixed bugs: - https://launchpad.net/bugs/820425 (bzr r12072) --- src/splivarot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 68664cb3c..7cbd92eeb 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -1002,8 +1002,8 @@ sp_selected_path_outline(SPDesktop *desktop) break; } - if (o_width < 0.01) - o_width = 0.01; + if (o_width < 0.032) + o_width = 0.032; o_miter = i_style->stroke_miterlimit.value * o_width; } -- cgit v1.2.3 From 3b1cc7dc98905cae76a8ec526758a8dc4c695e10 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 30 Jan 2013 12:23:57 +0100 Subject: Filters. New Shadow only mode for the Drop shadow filter. Translations. Translation template and French translation update. (bzr r12073) --- src/extension/internal/filter/shadows.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/extension/internal/filter/shadows.h b/src/extension/internal/filter/shadows.h index d76358a96..415776607 100644 --- a/src/extension/internal/filter/shadows.h +++ b/src/extension/internal/filter/shadows.h @@ -3,7 +3,7 @@ /* Change the 'SHADOWS' above to be your file name */ /* - * Copyright (C) 2011 Authors: + * Copyright (C) 2013 Authors: * Ivan Louette (filters) * Nicolas Dufour (UI) * @@ -39,6 +39,7 @@ namespace Filter { inner = composite1 (operator="out"), composite2 (operator="atop", in1="offset", in2="SourceGraphic") innercut = composite1 (operator="in"), composite2 (operator="out", in1="offset", in2="SourceGraphic") outercut = composite1 (operator="out"), composite2 (operator="in", in1="SourceGraphic", in2="offset") + shadow = composite1 (operator="out"), composite2 (operator="atop", in1="offset", in2="offset") * Color (guint, default 0,0,0,127) -> flood (flood-opacity, flood-color) * Use object's color (boolean, default false) -> composite1 (in1, in2) */ @@ -60,11 +61,12 @@ public: "3.0\n" "6.0\n" "6.0\n" - "\n" + "\n" "<_item value=\"outer\">" N_("Outer") "\n" "<_item value=\"inner\">" N_("Inner") "\n" "<_item value=\"outercut\">" N_("Outer cutout") "\n" "<_item value=\"innercut\">" N_("Inner cutout") "\n" + "<_item value=\"shadow\">" N_("Shadow only") "\n" "\n" "\n" "\n" @@ -151,11 +153,16 @@ ColorizableDropShadow::get_filter_text (Inkscape::Extension::Extension * ext) comp2op << "out"; comp2in1 << "offset"; comp2in2 << "SourceGraphic"; - } else { //innercut + } else if ((g_ascii_strcasecmp("innercut", type) == 0)){ comp1op << "out"; comp1in1 << "flood"; comp1in2 << "SourceGraphic"; comp2op << "in"; + } else { //shadow + comp1op << "in"; + comp2op << "atop"; + comp2in1 << "offset"; + comp2in2 << "offset"; } _filter = g_strdup_printf( -- cgit v1.2.3 From 7e9c34bc1550c2cd6a29575cb61a6fd271f36e44 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 30 Jan 2013 18:20:48 +0100 Subject: typo (bzr r12074) --- src/extension/internal/filter/filter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index af597685b..9f7a45f7f 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -172,7 +172,7 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie // no filter if (filternode == NULL) { - g_warning("no assoziating filter found!"); + g_warning("no assigned filter found!"); continue; } -- cgit v1.2.3 From da8fb2e6a998f8b7ead1aea5f1057439bc92956c Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 30 Jan 2013 18:22:10 +0100 Subject: drop old, unused and error prone dxf2svg extension (bzr r12075) --- src/extension/CMakeLists.txt | 11 - src/extension/dxf2svg/GPL.txt | 340 ---------- src/extension/dxf2svg/LGPL.txt | 504 -------------- src/extension/dxf2svg/Makefile | 21 - src/extension/dxf2svg/README | 41 -- src/extension/dxf2svg/aci2rgb.cpp | 114 ---- src/extension/dxf2svg/blocks.cpp | 83 --- src/extension/dxf2svg/blocks.h | 38 -- src/extension/dxf2svg/dxf2svg.cpp | 99 --- src/extension/dxf2svg/dxf_input.inx | 16 - src/extension/dxf2svg/dxf_input_windows.inx | 17 - src/extension/dxf2svg/entities.cpp | 996 ---------------------------- src/extension/dxf2svg/entities.h | 256 ------- src/extension/dxf2svg/entities2elements.cpp | 678 ------------------- src/extension/dxf2svg/entities2elements.h | 53 -- src/extension/dxf2svg/read_dxf.cpp | 275 -------- src/extension/dxf2svg/read_dxf.h | 32 - src/extension/dxf2svg/tables.cpp | 211 ------ src/extension/dxf2svg/tables.h | 71 -- src/extension/dxf2svg/tables2svg_info.cpp | 37 -- src/extension/dxf2svg/tables2svg_info.h | 9 - src/extension/dxf2svg/test_dxf.cpp | 99 --- 22 files changed, 4001 deletions(-) delete mode 100644 src/extension/dxf2svg/GPL.txt delete mode 100644 src/extension/dxf2svg/LGPL.txt delete mode 100644 src/extension/dxf2svg/Makefile delete mode 100644 src/extension/dxf2svg/README delete mode 100644 src/extension/dxf2svg/aci2rgb.cpp delete mode 100644 src/extension/dxf2svg/blocks.cpp delete mode 100644 src/extension/dxf2svg/blocks.h delete mode 100644 src/extension/dxf2svg/dxf2svg.cpp delete mode 100644 src/extension/dxf2svg/dxf_input.inx delete mode 100644 src/extension/dxf2svg/dxf_input_windows.inx delete mode 100644 src/extension/dxf2svg/entities.cpp delete mode 100644 src/extension/dxf2svg/entities.h delete mode 100644 src/extension/dxf2svg/entities2elements.cpp delete mode 100644 src/extension/dxf2svg/entities2elements.h delete mode 100644 src/extension/dxf2svg/read_dxf.cpp delete mode 100644 src/extension/dxf2svg/read_dxf.h delete mode 100644 src/extension/dxf2svg/tables.cpp delete mode 100644 src/extension/dxf2svg/tables.h delete mode 100644 src/extension/dxf2svg/tables2svg_info.cpp delete mode 100644 src/extension/dxf2svg/tables2svg_info.h delete mode 100644 src/extension/dxf2svg/test_dxf.cpp (limited to 'src') diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index e1f04fa10..b5634f42f 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -63,17 +63,6 @@ set(extension_SRC script/InkscapeScript.cpp - # dxf2svg/aci2rgb.cpp - # dxf2svg/entities2elements.cpp - # dxf2svg/tables2svg_info.cpp - # dxf2svg/blocks.cpp - # dxf2svg/entities.cpp - # dxf2svg/tables.cpp - # dxf2svg/dxf2svg.cpp - # dxf2svg/read_dxf.cpp - # dxf2svg/test_dxf.cpp - - # ------ # Header db.h diff --git a/src/extension/dxf2svg/GPL.txt b/src/extension/dxf2svg/GPL.txt deleted file mode 100644 index 3912109b5..000000000 --- a/src/extension/dxf2svg/GPL.txt +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/src/extension/dxf2svg/LGPL.txt b/src/extension/dxf2svg/LGPL.txt deleted file mode 100644 index 8add30ad5..000000000 --- a/src/extension/dxf2svg/LGPL.txt +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/src/extension/dxf2svg/Makefile b/src/extension/dxf2svg/Makefile deleted file mode 100644 index d0f06daf0..000000000 --- a/src/extension/dxf2svg/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -objs = read_dxf.o entities.o entities2elements.o tables.o tables2svg_info.o blocks.o -flags = -O1 - -dxf2svg : dxf2svg.cpp $(objs) - g++ $(flags) -o dxf2svg dxf2svg.cpp $(objs) - -test : test_dxf.cpp $(objs) - g++ $(flags) -o test test_dxf.cpp $(objs) - -%.o : %.cpp %.h - g++ $(flags) -c $< - -clean : - rm dxf2svg $(objs) - -install: - echo ****User intervention required**** - echo - echo Copy dxf2svg executable and dxf2svg.inx to share/extension directory - echo Make sure file permissions are set correctly - diff --git a/src/extension/dxf2svg/README b/src/extension/dxf2svg/README deleted file mode 100644 index dbf98d2cc..000000000 --- a/src/extension/dxf2svg/README +++ /dev/null @@ -1,41 +0,0 @@ -26 Aug 05 - -To use: -I have only gotten this to work with Inkscape under linux (debian sarge). But the converter works from the commandline if you want to test it otherwise. - -1. Run make and copy dxf2svg to somewhere that is looked at by the PATH variable. Or add the current directory to your path -2. Copy the dxf_import.inx to ../Inkscape/share/extensions -3. Run Inkscape -4. Click on open or import and the dxf option should be there - -I have compiled and then succesfully converted dxf files to svg files with the following setups - -WinXP Pro, Cygwin, g++ 3.3.3 -Debian Sarge, AMD x86_64, g++ 4.0.2 -RedHat(?), x86(?), g++ 3.2.3 - -I have weakly tried and failed to compile using -Borland's free compiler bcc32 -MinGW - -What is supported: -polylines, lines, arc, circles, blocks, text, and a little linetypes - -currently not supported but I hope will be in the near future (probably after Sept 05) -layers, colors, trace, splines, dimentions - -If you don't have dxf files of your own, but would like to easily test some I would suggest a few places... - -www.newfocus.com -- look under optomechanics. There are a variety of mounts and such that are posted in dxf and pdf -www.thorlabs.com -- dido what I said about newfocus - -Free CAD programs: -Windows -- A free and not too bad CAD program for windows is CadStd Lite. It exports to dxf and has a variety of samples. -Windows/Linux -- QCad is ok. It has a lot of nice features but when I used it a year ago it would import dxf files but then you couldn't edit what was imported. It is free but with a time limit. My experience is that it can be a little annoying. Because of that and others comments I didn't use their libraries for dxf reading. - - -Matt Squires -squiresm@colorado.edu - -27 Aug 05, Fixed a fair number of bugs, and broken conversions. LWPOLYLINE works now, text rotation is ok but needs multiple transfomations to get it right, can read broken dxf files (w/o dxf EOF information) - diff --git a/src/extension/dxf2svg/aci2rgb.cpp b/src/extension/dxf2svg/aci2rgb.cpp deleted file mode 100644 index 57e488bfc..000000000 --- a/src/extension/dxf2svg/aci2rgb.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include - - -char* RGB(double R, double G, double B); -char* RGB(double R, double G, double B){ - int r = int (R); - int g = int (G); - int b = int (B); - - char out[6]; - char *chr_ptr; - string output; - stringstream oss; - - if (r < 16 ){ - oss << 0; - } - oss << hex << r; - - if (g < 16 ){ - oss << 0; - } - oss << hex << g; - - if (b < 16 ){ - oss << 0; - } - oss << hex << b; - - output = oss.str(); - - for (int i = 0; i < 6; i++){ - out[i] = output[i]; - } - chr_ptr = &out; - return chr_ptr; -} - - -float aci_to_rgb(int aci); - -float aci_to_rgb(int aci) - { - aci = abs(aci); // hidden layers have negative color values - if (aci<10 || aci>249) // values of these ranges are special colors - { - switch (aci) - { - case 1: return RGB(255,0,0); // basic colors - case 2: return RGB(255,255,0); - case 3: return RGB(0,255,0); - case 4: return RGB(0,255,255); - case 5: return RGB(0,0,255); - case 6: return RGB(255,0,255); - case 7: return RGB(255,255,255); - case 8: return RGB(128,128,128); - case 9: return RGB(192,192,192); - case 250: return RGB(51,51,51); // grey shades - case 251: return RGB(91,91,91); - case 252: return RGB(132,132,132); - case 253: return RGB(173,173,173); - case 254: return RGB(214,214,214); - case 255: return RGB(255,255,255); - case 256: // "by layer" - // Here you should decide how to handle "by layer" logical color. - // Maybe it is a good idea to return a value like -1. - // The outer code will find what is the color of the layer which - // this entity belongs to. - return -1; - } - } - // for all the rest of ACI codes - float H,S,L, R,G,B; - int remainder = aci % 10; - H = 1.5f * (aci - remainder - 10); // hue in range 0-360 - S = ((aci % 2) ? 0.5f : 1.0f); // odd colors have 50% of saturation, even - 100% - // set lighteness, the last digit of aci code stands for this - if (reminder == 0 || reminder == 1) L = 1.0f; - if (reminder == 2 || reminder == 3) L = 0.8f; - if (reminder == 4 || reminder == 5) L = 0.6f; - if (reminder == 6 || reminder == 7) L = 0.5f; - if (reminder == 8 || reminder == 9) L = 0.3f; - // here we have H,S,L set already - // let's convert it to RGB, first without consideration of S and L - if (H<=120) - { - R = (120-H)/60; - G = H/60; - B = 0; - } - if (H>120 && H<=240) - { - R = 0; - G = (240-H)/60; - B = (H-120)/60; - } - if (H>240 && H<=360) - { - R = (H-240)/60; - G = 0; - B = (360-H)/60; - } - R = min(R, 1); - G = min(G, 1); - B = min(B, 1); - // influence of S and L - float max_value = max(R,max(G,B)); - R = (max_value-S*(max_value-R)) * L * 255; - G = (max_value-S*(max_value-G)) * L * 255; - B = (max_value-S*(max_value-B)) * L * 255; - return RGB(R,G,B); - } \ No newline at end of file diff --git a/src/extension/dxf2svg/blocks.cpp b/src/extension/dxf2svg/blocks.cpp deleted file mode 100644 index 36f2b9e7e..000000000 --- a/src/extension/dxf2svg/blocks.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Read Blocks from file and convert to vectors of entities - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - -#include"blocks.h" -#include - -block::block(std::vector< std::vector< dxfpair > > sections) : entities( sections ){ - // Inherit most of the functionality of the entitites section - - basic_entity( sections[0] ); - block_info( sections[0] ); -} - -char* block::name(char* string){ - return( strcpy(string,block_name) ); -} - - -void block::block_info( std::vector< dxfpair > info){ - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 2: // Block name - strcpy( string," "); // Clear the string out - info[i].value_char(string); - strcpy(block_name,string); - break; - } - } -} - - -blocks::blocks(std::vector< std::vector< dxfpair > > sections){ - // Read the main information about the entities section and then put it in the enetites class - char string[10000]; - std::vector< dxfpair > single_line; - std::vector< std::vector< dxfpair > > ents; - ents.clear(); - single_line.clear(); - - int n_loop = sections.size(); - n_loop--; - //for(int i = 0; i < (sections.size()-1); i++){ // It is odd but the last value seems to be bad so don't use it - // I am not really sure if I need the -1. I needed it once upon a time to make things work but I don't have time to test it well right now - // But sections.size() is an unsigned int so when you subtract 1 it becomes 4294967295 and tries to run the loop so work around that by making n_loop that is signed - for(int i = 0; i < n_loop; i++){ // It is odd but the last value seems to be bad so don't use it - sections[i][0].value_char(string); - ents.clear(); // First clear out the pline information - - - // Get everything from the start of the BLOCK designation to an ENDBLK value - if ( strncmp(string,"BLOCK",5) == 0 && (i < sections.size())){ - do{ - ents.push_back( sections[i] ); - sections[++i][0].value_char(string); - }while( strncmp(string,"ENDBLK",6) != 0 && (i < sections.size()-1) ); - blocks_blocks.push_back( block( ents ) ); - } - } -} - -block blocks::ret_block(char block_name[10000]){ - int string_len = 0; - char temp[10000]; - - for (int i = 0; i < blocks_blocks.size();i++){ - string_len = strlen(blocks_blocks[i].name(temp)); - if (strncmp(blocks_blocks[i].name(temp),block_name,string_len) == 0 ) return blocks_blocks[i]; - } - return blocks_blocks[0]; -} - - - diff --git a/src/extension/dxf2svg/blocks.h b/src/extension/dxf2svg/blocks.h deleted file mode 100644 index 27e0b8be1..000000000 --- a/src/extension/dxf2svg/blocks.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Read Blocks from file and convert to vectors of entities -Matt Squires -Google SOC 2005 -*/ - -#ifndef DXF_BLOCKS_H -#define DXF_BLOCKS_H - -#include"read_dxf.h" -#include"entities.h" -#include - - -class block : public entity, public entities{// : public entities, { - public: - block( std::vector< std::vector< dxfpair > > sections ); // Group all of the blocks as entities - char* name(char* string); - //void blocks_display(); - - - protected: - char block_name[10000]; - double rotation; - - private: - void block_info(std::vector< dxfpair > info); -}; - -class blocks{ - public: - blocks(std::vector< std::vector< dxfpair > > sections); - block ret_block(char block_name[10000]); - - protected: - std::vector< block > blocks_blocks; -}; - -#endif diff --git a/src/extension/dxf2svg/dxf2svg.cpp b/src/extension/dxf2svg/dxf2svg.cpp deleted file mode 100644 index 4884ed3fe..000000000 --- a/src/extension/dxf2svg/dxf2svg.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Build a SVG from an dxf, will support conversion to Inkscape types - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - -#include -#include -#include"read_dxf.h" -#include"entities.h" -#include"blocks.h" -#include"entities2elements.h" - - -int main(int argc,char *argv[]){ - // Later include options for different conversions like converting as much as possible into paths - - if(argc > 1){ - double scaling = 90; // converstion from in to pt - - // Read the DXF file - std::vector< std::vector< dxfpair > > output, entities_info, tables_info, blocks_info; - //std::cout << "About to read file \n" << std::endl; - output = dxf_get_sections(argv[1]); - //std::cout << "Finished reading file \n" << std::endl; - - entities_info = separate_parts(output[4]); // Entities is the 5th part of the file. - entities ents(entities_info); // Sort entities into their respective parts - - tables_info = separate_parts(output[2]); // Tables is the 3rd part of a dxf file. - tables tbls(tables_info); // Sort the information in the tables - - blocks_info = separate_parts(output[3]); // Tables is the 4th part of a dxf file. - blocks blks(blocks_info); // Sort the information in the tables - - - - // Get the various file informations - /*std::vector< polyline > plines = ents.ret_plines(); - std::vector< lwpolyline > lwplines = ents.ret_lwplines(); - std::vector< arc > arcs = ents.ret_arcs(); - std::vector< circle > circs = ents.ret_circles(); - std::vector< line > lns = ents.ret_lines(); - std::vector< text > txts = ents.ret_texts(); - std::vector< insert > ins = ents.ret_inserts(); - */ - - - std::vector< layer > layers = tbls.ret_layers(); - - char units[5] = "in"; - char tmp_char[100000]; - char layer_string[500]; - // int ink = 1; // Assume for now there is no inkscape stuff to add extra - - /*if (ink < 1){ - // Write a general svg header - std::cout << "\n\n\n"; - std::cout << "\tx=\"0.00000000\"\n\ty=\"0.00000000\"\n\twidth=\"744.09448\"\n\theight=\"-1052.3622\"" << std::endl; - } - else{*/ - std::cout << "" << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - //} - - - // Now write SVG elements to file - if ( layers.size() < 1 ){ - write_all(0, ents, tbls, blks, scaling, units, tmp_char); - } - else{ - for (int i = 0; i < layers.size(); i++){ - std::cout << "\t" << std::endl; - write_by_layer(0, ents, tbls, blks, scaling, units, layers[i].name(layer_string), tmp_char); - std::cout << "\t" << std::endl; - } - } - - // Close SVG - std::cout << ""; - } - - return 0; -} diff --git a/src/extension/dxf2svg/dxf_input.inx b/src/extension/dxf2svg/dxf_input.inx deleted file mode 100644 index b96274ade..000000000 --- a/src/extension/dxf2svg/dxf_input.inx +++ /dev/null @@ -1,16 +0,0 @@ - - DXF Input - org.inkscape.input.dxf - dxf2svg - org.inkscape.input.svg - - .dxf - image/x-svgz - AutoCAD DXF (*.dxf) - Import AutoCAD's Document Exchange Format - org.inkscape.output.svg - - - diff --git a/src/extension/dxf2svg/dxf_input_windows.inx b/src/extension/dxf2svg/dxf_input_windows.inx deleted file mode 100644 index 7dbe6a11b..000000000 --- a/src/extension/dxf2svg/dxf_input_windows.inx +++ /dev/null @@ -1,17 +0,0 @@ - - DXF Input - org.inkscape.input.dxf - dxf2svg.exe - org.inkscape.input.svg - - .dxf - image/x-svgz - AutoCAD DXF (*.dxf) - Import AutoCAD's Document Exchange Format - org.inkscape.output.svg - - - diff --git a/src/extension/dxf2svg/entities.cpp b/src/extension/dxf2svg/entities.cpp deleted file mode 100644 index 4e2f83ee7..000000000 --- a/src/extension/dxf2svg/entities.cpp +++ /dev/null @@ -1,996 +0,0 @@ -/* - * Class for interpereting the entities found in a DXF file - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - -#include"entities.h" -#include -#include - -int detmine_entity(char* value){ - // Common Elements as far as I am concerend - if ( strncmp(value,"POLYLINE",8) == 0 ) return 0; - if ( strncmp(value,"ARC",3) == 0 ) return 1; - if ( strncmp(value,"CIRCLE",6) == 0 ) return 2; - if ( strncmp(value,"LINE",4) == 0 ) return 3; - if ( strncmp(value,"SPLINE",6) == 0 ) return 4; - if ( strncmp(value,"XLINE",5) == 0 ) return 5; - if ( strncmp(value,"RAY",3) == 0 ) return 6; - if ( strncmp(value,"DIMENSION",9) == 0 ) return 7; - if ( strncmp(value,"ELLIPSE",7) == 0 ) return 8; - if ( strncmp(value,"INSERT",6) == 0 ) return 9; - if ( strncmp(value,"VERTEX",6) == 0 ) return 10; - if ( strncmp(value,"TEXT",4) == 0 ) return 11; - - // Less Common eletities as far as I am concerend - if ( strncmp(value,"3DSOLID",7) == 0 ) return 12; - if ( strncmp(value,"ACAD_PROXY_ENTITY",17) == 0 ) return 13; - if ( strncmp(value,"ARCALIGNEDTEXT",14) == 0 ) return 14; - if ( strncmp(value,"ATTDEF",6) == 0 ) return 15; - if ( strncmp(value,"ATTRIB",6) == 0 ) return 16; - if ( strncmp(value,"BODY",4) == 0 ) return 17; - if ( strncmp(value,"HATCH",5) == 0 ) return 18; - if ( strncmp(value,"IMAGE",5) == 0 ) return 19; - if ( strncmp(value,"LEADER",6) == 0 ) return 20; - if ( strncmp(value,"LWPOLYLINE",10) == 0 ) return 21; - if ( strncmp(value,"MLINE",5) == 0 ) return 22; - if ( strncmp(value,"MTEXT",5) == 0 ) return 23; - if ( strncmp(value,"OLEFRAME",8) == 0 ) return 24; - if ( strncmp(value,"POINT",5) == 0 ) return 25; - if ( strncmp(value,"REGION",6) == 0 ) return 26; - if ( strncmp(value,"RTEXT",5) == 0 ) return 27; - if ( strncmp(value,"SEQEND",6) == 0 ) return 28; - if ( strncmp(value,"SHAPE",5) == 0 ) return 29; - if ( strncmp(value,"SOLID",5) == 0 ) return 30; - if ( strncmp(value,"3DFACE",6) == 0 ) return 31; - if ( strncmp(value,"TOLERANCE",9) == 0 ) return 32; - if ( strncmp(value,"TRACE",5) == 0 ) return 33; - if ( strncmp(value,"VIEWPORT",8) == 0 ) return 34; - if ( strncmp(value,"WIPEOUT",7) == 0 ) return 35; - else return -1; -} - - -void entity::basic_entity( std::vector< dxfpair > info){ - // Extract all of the typical entity information (e.g. layer name, positions) - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 6: - strcpy( string," "); // Clear the string out - info[i].value_char(string); - strcpy(linetype,string); - break; - case 8: - strcpy( string," "); // Clear the string out - info[i].value_char(string); - strcpy(layer,string); - break; - case 10: - info[i].value_char(string); - x = atof(string); - if ( x < min_x ){ - min_x = x; - } - if ( x > max_x ){ - max_x = x; - } - break; - case 20: - info[i].value_char(string); - y = atof(string); - if ( y < min_y ){ - min_y = y; - } - if ( y > max_y ){ - max_y = y; - } - break; - case 30: - info[i].value_char(string); - z = atof(string); - break; - } - } - -} - -void entity::entity_display(){ - std::cout << "\tlayer = " << layer << "\n\tlinetype = " << linetype << "\n\tx = " << x << "\ty = " << y << "\tz = " << z << std::flush; -} - -double entity::ret_x(){ - return x; -} - -double entity::ret_y(){ - return y; -} - -double entity::ret_z(){ - return z; -} - - -char* entity::ret_layer_name(char* string){ - return( strcpy(string,layer) ); -} - -char* entity::ret_ltype_name(char* string){ - return( strcpy(string,linetype) ); -} - -double entity::ret_min_x(){ - return min_x; -} - -double entity::ret_max_x(){ - return max_x; -} - -double entity::ret_min_y(){ - return min_y; -} - -double entity::ret_max_y(){ - return max_y; -} - -void entity::test_coord(double x, double y){ - if ( x < min_x ){ - min_x = x; - } - if ( x > max_x ){ - max_x = x; - } - if ( y < min_y ){ - min_y = y; - } - if ( y > max_y ){ - max_y = y; - } -} - - -void entity::reset_extents(){ - min_x = -1e20; - max_x = 1e20; - min_y = -1e20; - max_y = 1e20; -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// VERTEX -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -vertex::vertex( std::vector< dxfpair > info){ - // Get the vertex information - - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 42: - info[i].value_char(string); - bulge = atof(string); - break; - } - } -} - -double vertex::ret_bulge(){ - return bulge; -} - -void vertex::display(){ - std::cout << "VERTEX\n"; - std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush; -} - - - - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// POLYLINE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -// The polyline is handled a little differently compared to the other entities because a POLYLINE is built from a bunch of VERTEX entities -polyline::polyline( std::vector< std::vector< dxfpair > > sections ){ - buldge = 0; - pline_flag = 0; - reset_extents(); - // get the polyline information - basic_entity( sections[0] ); - points.clear(); - static char string[10000]; - for (int i = 0; i < sections[0].size(); i++){ - switch( sections[0][i].group_code ){ - case 70: - sections[0][i].value_char(string); - pline_flag = atoi(string); - break; - case 40: - sections[0][i].value_char(string); - start_width = atoi(string); - break; - case 41: - sections[0][i].value_char(string); - end_width = atoi(string); - break; - case 75: - sections[0][i].value_char(string); - curves_flag = atoi(string); - break; - } - } - curves_flag = 0; - - // Now add the VERTEX entities to the POLYLINE - for (int i = 1; i < sections.size(); i++){ - points.push_back( vertex( sections[i] ) ); - } -} - - -std::vector< vertex > polyline::ret_points(){ - return points; -} - -double polyline::bulge(int point){ - return points[point].ret_bulge(); -} - -double polyline::bulge_r(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) return 0; - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - return r; -} - -double polyline::bulge_start_angle(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) - { - return 0; - } - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - if (dx > 0) - { - sb *= -1; // Correct for different point ordering and bulge direction - } - - // Now calculate the angle - double theta = asin(points[point].ret_x()/r); - if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi - - return theta; -} - -double polyline::bulge_end_angle(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) - { - return 0; - } - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - // Now calculate the angle - double theta = asin(points[point+1].ret_x()/r); - if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi - - return theta; -} - -bool polyline::is_closed(){ - // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators - return bool(pline_flag&1); -} - -void polyline::display(){ - std::cout << "POLYLINE\n"; - entity_display(); - std::cout << std::endl; - for (int i = 0; i < points.size(); i++){ - points[i].display(); - std::cout << std::endl; - } - std::cout << std::endl; -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LWPOLYLINE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -// The lwpolyline is different than the polyline because there are no vertex entities. Use the same basic process as the polyline but parse it out differently -lwpolyline::lwpolyline( std::vector< dxfpair > section ){ - - // First break up the data into the same format that is used by the polyline entity - std::vector< std::vector< dxfpair > > sections; - std::vector< dxfpair > first; - std::vector< dxfpair > others; - - sections.clear(); - first.clear(); - others.clear(); - - int gc; // make a shorter name for group_code; - - int vertex_part; - int already_found = 0; - - for (int i = 0; i < section.size(); i++){ - gc = section[i].group_code; - // Encode bitwise information to keep track of what has been found - vertex_part = 0; - if (gc == 10 ) vertex_part += 1; - if (gc == 20 ) vertex_part += 2; - if (gc == 30 ) vertex_part += 4; - if (gc == 40 ) vertex_part += 8; - if (gc == 41 ) vertex_part += 16; - if (gc == 42 ) vertex_part += 32; - //std::cout << "\n\nvertex_part = " << vertex_part << std::endl << "already_found = " << already_found << std::endl << "(vertex_part&already_found) = " << (vertex_part&already_found) << std::endl; - if ( vertex_part == 0 ){ - // If header stuff has been found save it under first. - // I.E. in a polyline the first set of information is linetype and layer, all of what should be in here - first.push_back( section[i] ); - } - else if ( (vertex_part&already_found) == 0 ){ - // Now work on what would be the vertex information - // New information is still being found so keep saving it - others.push_back( section[i] ); - //std::cout << "add to others" << std::endl; - already_found += vertex_part; // Keep track of what has been found - } - else{ - sections.push_back( others ); - //std::cout << "sections.size() = " << sections.size() << std::endl; - // Now clear the information out and start over - others.clear(); - others.push_back( section[i] ); - already_found = vertex_part; - } - } - - // Now put on the last data that was found - if (!others.empty()){ - sections.push_back(others); - } - - reset_extents(); - basic_entity( first ); - points.clear(); - static char string[10000]; - buldge = 0; - pline_flag = 0; - curves_flag = 0; - for (int i = 0; i < first.size(); i++){ - switch( sections[0][i].group_code ){ - case 70: - first[i].value_char(string); - pline_flag = atoi(string); - break; - case 40: - first[i].value_char(string); - start_width = atoi(string); - break; - case 41: - first[i].value_char(string); - end_width = atoi(string); - break; - case 75: - first[i].value_char(string); - curves_flag = atoi(string); - break; - } - } - // Now add the VERTEX entities to the POLYLINE - for (int i = 0; i < sections.size(); i++){ - points.push_back( vertex( sections[i] ) ); - } -} - - - -std::vector< vertex > lwpolyline::ret_points(){ - return points; -} - - -double lwpolyline::bulge(int point){ - return points[point].ret_bulge(); -} - -double lwpolyline::bulge_r(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) return 0; - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - return r; -} - -double lwpolyline::bulge_start_angle(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) return 0; - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - // Now calculate the angle - double theta = asin(points[point].ret_x()/r); - if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi - - return theta; -} - -double lwpolyline::bulge_end_angle(int point){ - // Make sure we are not exceeding the bounds of the points vector - if (point >= (points.size()-1)) return 0; - - double dx = points[point+1].ret_x() - points[point].ret_x(); - double dy = points[point+1].ret_y() - points[point].ret_y(); - double bulge = points[point].ret_bulge(); - double l = sqrt(dx*dx + dy*dy); - double r = fabs(l*(bulge*bulge+1)/bulge/4); - - // Now calculate the angle - double theta = asin(points[point+1].ret_x()/r); - if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi - - return theta; -} - -bool lwpolyline::is_closed(){ - // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators - return bool(pline_flag&1); -} - -void lwpolyline::display(){ - std::cout << "lwpolyline\n"; - entity_display(); - std::cout << std::endl; - for (int i = 0; i < points.size(); i++){ - points[i].display(); - std::cout << std::endl; - } - std::cout << std::endl; -} - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// ARC -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -arc::arc( std::vector< dxfpair > info){ - - reset_extents(); - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 40: - info[i].value_char(string); - radius = atof(string); - test_coord(x+radius,y+radius); - test_coord(x-radius,y-radius); - break; - case 50: - info[i].value_char(string); - start_angle = atof(string); - break; - case 51: - info[i].value_char(string); - end_angle = atof(string); - break; - default: - break; - } - } -} - -double arc::ret_radius(){ - return radius; -} - - -double arc::ret_srt_ang(){ - return start_angle; -} - - -double arc::ret_end_ang(){ - return end_angle; -} - - -void arc::display(){ - std::cout << "ARC\n"; - entity_display(); - std::cout << "\n\tradius = " << radius << "\tstart_angle = " << start_angle << "end_angle = " << end_angle << std::flush; -} - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// CIRCLE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -circle::circle( std::vector< dxfpair > info){ - - reset_extents(); - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 40: - info[i].value_char(string); - radius = atof(string); - test_coord(x+radius,y+radius); - test_coord(x-radius,y-radius); - break; - } - } -} - -void circle::display(){ - std::cout << "CIRCLE\n"; - entity_display(); - std::cout << "\n\tradius = " << radius << std::flush; -} - - -double circle::ret_radius(){ - return radius; -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LINE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -line::line( std::vector< dxfpair > info){ - - reset_extents(); - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 11: - info[i].value_char(string); - xf = atof(string); - break; - case 21: - info[i].value_char(string); - yf = atof(string); - break; - case 31: - info[i].value_char(string); - zf = atof(string); - break; - } - } - test_coord(xf,yf); - -} - -void line::display(){ - std::cout << "LINE\n"; - entity_display(); - std::cout << "\n\txf = " << xf << "\tyf = " << yf << "\tzf = " << zf << std::flush; -} - - -double line::ret_xf(){ - return xf; -} - -double line::ret_yf(){ - return yf; -} - -double line::ret_zf(){ - return zf; -} - - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// TEXT -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -text::text( std::vector< dxfpair > info){ - - reset_extents(); - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 1: - info[i].value_char(dxf_text); // directly copy the text into a string - break; - case 40: - info[i].value_char(string); - text_height = atof(string); - break; - case 50: - info[i].value_char(string); - text_rotation = atof(string); - break; - } - } -} - -char * text::ret_text(char *string){ - return( strcpy(string,dxf_text) ); -} - -double text::ret_txt_ht(){ - return text_height; -} - -double text::ret_txt_rot(){ - return text_rotation; -} - -void text::display(){ - char tmp[10000]; - std::cout << "TEXT\n"; - entity_display(); - std::cout << "\ndxf_text = " << ret_text(tmp) << std::flush; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// INSERT -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -insert::insert( std::vector< dxfpair > info){ - ret_x_sf = 0; - ret_y_sf = 0; - ret_z_sf = 0; - ret_rotation = 0; - - basic_entity( info ); - static char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 2: - info[i].value_char(block_name); // directly copy the text into a string - break; - case 41: - info[i].value_char(string); - x_scale_factor = atof(string); - break; - case 42: - info[i].value_char(string); - y_scale_factor = atof(string); - break; - case 43: - info[i].value_char(string); - z_scale_factor = atof(string); - break; - case 50: - info[i].value_char(string); - rotation = atof(string); - break; - } - } -} - - -char * insert::name(char *string){ - return( strcpy(string,block_name) ); -} - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// entities -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - -entities::entities(std::vector< std::vector< dxfpair > > sections){ - // Read the main information about the entities section and then put it in the enetites class - int value; - char string[10000]; - std::vector< dxfpair > single_line; - std::vector< std::vector< dxfpair > > pline; - pline.clear(); - single_line.clear(); - - for(int i = 0; i < sections.size(); i++){ - sections[i][0].value_char(string); - value = detmine_entity(string); - switch( value ){ - case 0: - // Get everything from the start of the polyline designation to an SEQEND value - pline.clear(); // First clear out the pline information - do{ - pline.push_back( sections[i] ); - sections[++i][0].value_char(string); - }while( strncmp(string,"SEQEND",6) != 0 ); - ents_polyline.push_back( polyline( pline ) ); - break; - - case 1: - // ARC - ents_arc.push_back( arc( sections[i] ) ); - break; - - case 2: - // CIRCLE - ents_circle.push_back( circle( sections[i] ) ); - break; - - case 3: - // LINE - ents_line.push_back( line( sections[i] ) ); - break; - case 11: - // TEXT - ents_text.push_back( text( sections[i] ) ); - break; - case 21: - // LWPOLYLINE - ents_lwpolyline.push_back( lwpolyline( sections[i] ) ); - case 9: - // INSERT - ents_insert.push_back( insert( sections[i] ) ); - - //default: - // Nothing here - } - - } - -} - - -// Maybe all of this could be turned into fewer function by using templates, but no time right now. MBS - -std::vector< polyline > entities::ret_plines(){ - std::vector< polyline > pls; - pls.clear(); - for(int i = 0; i < ents_polyline.size();i++){ - pls.push_back( ents_polyline[i] ); - } - return pls; -} - -std::vector< lwpolyline > entities::ret_lwplines(){ - std::vector< lwpolyline > lwpls; - lwpls.clear(); - for(int i = 0; i < ents_lwpolyline.size();i++){ - lwpls.push_back( ents_lwpolyline[i] ); - } - return lwpls; -} - - -std::vector< arc > entities::ret_arcs(){ - std::vector< arc > a; - a.clear(); - for(int i = 0; i < ents_arc.size();i++){ - a.push_back( ents_arc[i] ); - } - return a; -} - -std::vector< circle > entities::ret_circles(){ - std::vector< circle > circs; - circs.clear(); - for(int i = 0; i < ents_circle.size();i++){ - circs.push_back( ents_circle[i] ); - } - return circs; -} - - -std::vector< line > entities::ret_lines(){ - std::vector< line > lns; - lns.clear(); - for(int i = 0; i < ents_line.size();i++){ - lns.push_back( ents_line[i] ); - } - return lns; -} - - -std::vector< text > entities::ret_texts(){ - std::vector< text > txts; - txts.clear(); - for(int i = 0; i < ents_text.size();i++){ - txts.push_back( ents_text[i] ); - } - return txts; -} - - -std::vector< insert > entities::ret_inserts(){ - std::vector< insert > ins; - ins.clear(); - for(int i = 0; i < ents_insert.size();i++){ - ins.push_back( ents_insert[i] ); - } - return ins; -} - - - -// Overload the return function to depend on the layer -std::vector< polyline > entities::ret_plines(char * layer){ - char temp[10000]; - std::vector< polyline > pls; - pls.clear(); - - for(int i = 0; i < ents_polyline.size();i++){ - if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){ - pls.push_back( ents_polyline[i] ); - } - } - return pls; -} - - -std::vector< lwpolyline > entities::ret_lwplines(char * layer){ - char temp[10000]; - std::vector< lwpolyline > lwpls; - lwpls.clear(); - - for(int i = 0; i < ents_lwpolyline.size();i++){ - if ( strcmp( layer,ents_lwpolyline[i].ret_layer_name(temp) ) == 0 ){ - lwpls.push_back( ents_lwpolyline[i] ); - } - } - return lwpls; -} - - -std::vector< circle > entities::ret_circles(char * layer){ - char temp[10000]; - std::vector< circle > circs; - circs.clear(); - - for(int i = 0; i < ents_circle.size();i++){ - if ( strcmp( layer,ents_circle[i].ret_layer_name(temp) ) == 0 ){ - circs.push_back( ents_circle[i] ); - } - } - return circs; -} - - -std::vector< line > entities::ret_lines(char * layer){ - char temp[10000]; - std::vector< line > lns; - lns.clear(); - - for(int i = 0; i < ents_line.size();i++){ - if ( strcmp( layer,ents_line[i].ret_layer_name(temp) ) == 0 ){ - lns.push_back( ents_line[i] ); - } - } - return lns; -} - - -std::vector< text > entities::ret_texts(char * layer){ - char temp[10000]; - std::vector< text > txts; - txts.clear(); - - for(int i = 0; i < ents_text.size();i++){ - if ( strcmp( layer,ents_text[i].ret_layer_name(temp) ) == 0 ){ - txts.push_back( ents_text[i] ); - } - } - return txts; -} - - -/*std::vector< ellipse > entities::ret_ellipses(char * layer){ - char temp[10000]; - std::vector< polyline > pls; - pls.clear(); - - for(int i = 0; i < ents_polyline.size();i++){ - if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){ - pls.push_back( ents_polyline[i] ); - } - } - return pls; -}*/ - - -std::vector< arc > entities::ret_arcs(char * layer){ - char temp[10000]; - std::vector< arc > a; - a.clear(); - - for(int i = 0; i < ents_arc.size();i++){ - if ( strcmp( layer,ents_arc[i].ret_layer_name(temp) ) == 0 ){ - a.push_back( ents_arc[i] ); - } - } - return a; -} - - -std::vector< insert > entities::ret_inserts(char * layer){ - char temp[10000]; - std::vector< insert > ins; - ins.clear(); - - for(int i = 0; i < ents_insert.size();i++){ - if ( strcmp( layer,ents_insert[i].ret_layer_name(temp) ) == 0 ){ - ins.push_back( ents_insert[i] ); - } - } - return ins; -} - - - - -void entities::display_all(){ - for (int i = 0; i < ents_polyline.size(); i++){ - ents_polyline[i].display(); - } - std::cout << std::endl; - for (int i = 0; i < ents_lwpolyline.size(); i++){ - ents_lwpolyline[i].display(); - } - std::cout << std::endl; - for (int i = 0; i < ents_circle.size(); i++){ - ents_circle[i].display(); - } - std::cout << std::endl; - for (int i = 0; i < ents_text.size(); i++){ - ents_text[i].display(); - } -} - - diff --git a/src/extension/dxf2svg/entities.h b/src/extension/dxf2svg/entities.h deleted file mode 100644 index 3afd949b0..000000000 --- a/src/extension/dxf2svg/entities.h +++ /dev/null @@ -1,256 +0,0 @@ -/* Class for interpereting the entities found in a DXF file -Matt Squires -Google SOC -2 July 05 -*/ - -#ifndef DXF_ENTITIES_H -#define DXF_ENTITIES_H - -#include"read_dxf.h" -#include - - - - -class entity{ - public: - void basic_entity( std::vector< dxfpair > info); // Extract all of the typical entity information (e.g. layer name, positions) - void entity_display(); - double ret_x(); - double ret_y(); - double ret_z(); - char* ret_layer_name(char* string); - char* ret_ltype_name(char* string); - double ret_min_x(); - double ret_max_x(); - double ret_min_y(); - double ret_max_y(); - - - protected: - char layer[10000]; - char linetype[10000]; - double x; - double y; - double z; - double min_x; - double max_x; - double min_y; - double max_y; - void reset_extents(); - void test_coord(double x, double y); -}; - - - - - -class vertex : public entity { - public: - vertex( std::vector< dxfpair > info); - void display(); - double ret_bulge(); - - private: - double bulge; -}; - - - - - -class polyline : public entity { - public: - polyline( std::vector< std::vector< dxfpair > > sections ); - std::vector< vertex > ret_points(); - double bulge(int point); - double bulge_r(int point); - double bulge_start_angle(int point); - double bulge_end_angle(int point); - bool is_closed(); - void display(); - - private: - double buldge; - int pline_flag; // 70 - double start_width; // 40 - double end_width; // 41 - int curves_flag; - std::vector< vertex > points; -}; - -class lwpolyline : public entity { - public: - lwpolyline( std::vector< dxfpair > section ); - std::vector< vertex > ret_points(); - double bulge(int point); - double bulge_r(int point); - double bulge_start_angle(int point); - double bulge_end_angle(int point); - bool is_closed(); - void display(); - - private: - double buldge; - int pline_flag; // 70 - double start_width; // 40 - double end_width; // 41 - int curves_flag; - std::vector< vertex > points; -}; - -class arc : public entity { - public: - arc( std::vector< dxfpair > info); - double ret_radius(); - double ret_srt_ang(); - double ret_end_ang(); - void display(); - - private: - double radius; - double start_angle; - double end_angle; -}; - - - - -class circle : public entity { - public: - circle( std::vector< dxfpair > info); - void display(); - double ret_radius(); - - private: - double radius; -}; - - -class line : public entity { - public: - line( std::vector< dxfpair > info); - void display(); - double ret_xf(); - double ret_yf(); - double ret_zf(); - - private: - double xf; - double yf; - double zf; -}; - -class ellipse : public entity { - public: - ellipse( std::vector< dxfpair > info); - void display(); - double ret_x_ma; - double ret_y_ma; - double ret_z_ma; - double ret_ratio; - double ret_start_p; - double ret_end_p; - - - private: - double x_major_axis; - double y_major_axis; - double z_major_axis; - double ratio; - double start_param; - double end_param; -}; - - - -class text : public entity { - public: - text( std::vector< dxfpair > info); - void display(); - char * ret_text(char *string); - double ret_txt_ht(); - double ret_txt_rot(); - - private: - char dxf_text[10000]; - double text_height; // dxf 40 - double text_rotation; //dxf 50 -}; - - -class insert : public entity { - public: - insert( std::vector< dxfpair > info); - void display(); - char* name(char* string); - double ret_x_sf; - double ret_y_sf; - double ret_z_sf; - double ret_rotation; - - private: - char block_name[10000]; - double x_scale_factor; - double y_scale_factor; - double z_scale_factor; - double rotation; -}; - - - - - - -class entities{ - // Well I said that I would only use STL containers internally, but I would have to use a dynamically linked list, and I haven't done for a long time soo STL is my crutch. - // I also think that there are others in my same boat that prefer stl containers because they are much easier to use - public: - entities(std::vector< std::vector< dxfpair > > sections); // Put the various entities into their respective vectors - void display_all(); - std::vector< polyline > ret_plines(); - std::vector< circle > ret_circles(); - std::vector< line > ret_lines(); - std::vector< text > ret_texts(); - std::vector< ellipse > ret_ellipses(); - std::vector< arc > ret_arcs(); - std::vector< lwpolyline > ret_lwplines(); - std::vector< insert > ret_inserts(); - // Overload the return function to depend on the layer - std::vector< polyline > ret_plines(char * layer); - std::vector< circle > ret_circles(char * layer); - std::vector< line > ret_lines(char * layer); - std::vector< text > ret_texts(char * layer); - std::vector< ellipse > ret_ellipses(char * layer); - std::vector< arc > ret_arcs(char * layer); - std::vector< lwpolyline > ret_lwplines(char * layer); - std::vector< insert > ret_inserts(char * layer); - - int plines_size(); - int circles_size(); - int lines_size(); - int texts_size(); - - - - private: - void add_polyline(polyline pline); - void add_circle(circle circ); - void add_line(line ln); - - std::vector< polyline > ents_polyline; - std::vector< arc > ents_arc; - std::vector< circle > ents_circle; - std::vector< line > ents_line; - std::vector< ellipse > ents_ellipse; - std::vector< text > ents_text; - std::vector< lwpolyline > ents_lwpolyline; - std::vector< insert > ents_insert; - - -}; - - - -#endif diff --git a/src/extension/dxf2svg/entities2elements.cpp b/src/extension/dxf2svg/entities2elements.cpp deleted file mode 100644 index 8a17a0d84..000000000 --- a/src/extension/dxf2svg/entities2elements.cpp +++ /dev/null @@ -1,678 +0,0 @@ -/* - * Code for converting dxf entities to SVG elements - * There are multiple ways for converting different items - * If possible most DXF enetities will be converted to paths because that is the most flexable object - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - - -/* - -Matt Squires -SoC 2005 - -*/ - -#include "entities2elements.h" -#include "tables2svg_info.h" -#include -#include -#include -#include -// The names indicate the DXF entitiy first and the SVG element last - -// Common elements -char* to_arc(double bulge, double r, double start_ang, double end_ang, int precision,char* delim, char * units, double scaling, char *out){ - // This is used for arcs, polylines, and lwpolylines - char temp[50]; - - // Assume that we are adding to the input and not starting over - strcat(out," A "); - // For arcs there is only one radius - strcat(out,gcvt(scaling*r,precision,temp) ); - strcat(out,","); - strcat(out,gcvt(scaling*r,precision,temp) ); - - strcat(out," 0"); // For arc assume no x-axis rotation. That seems to apply to elipse elements only - // Determine if it is a large arc - if ( (end_ang > start_ang) && ( (end_ang - start_ang) > 180) ){ - //strcat(out," 1,0 "); // Large arc flag...Always use a zero sweep flag - strcat(out," 1, "); // Large arc flag...Always use a zero sweep flag - } - else{ - //strcat(out," 0,0 "); // Small arc flag...Always use a zero sweep flag - strcat(out," 0,"); - } - // This may be easier if I allow r to be plus and minus, but for now this works - if (bulge > 0){ - strcat(out,"0 "); - } - else{ - strcat(out,"1 "); - } -} - -// Build Coordinate -void coord(entity *ent, int precision,char* delim, char * units, double scaling, char *out){ - // Pairs of coords with units will be used so often build a function build a dedicated function for returning such - - char temp[20]; - if (units != NULL) scaling = 1; // If units have been defined then ignore the scaling parameter - strcat(out, gcvt(scaling*ent->ret_x(),precision,temp) ); // There must be a better function for double to ascii conversion that is defined in most libraries - if (units != NULL) strcat(out, units); - strcat(out, delim); - strcat(out, gcvt(-scaling*ent->ret_y(),precision,temp) ); // Because SVG has a the Y-axis pointed down multiply by -1 - if (units != NULL) strcat(out, units); - strcat(out, " "); -} - -// DXF Polyline -> SVG -// General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported -void pline2svg(polyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){ - // 0 is pline2path - // 1 is pline2pline - // 2 is pline2polygon - - - char delim[2]; - - std::vector< vertex >::iterator vver_iter; - std::vector< vertex > points = pline.ret_points(); - - if (type < 1){ - // Put the first Move To at the first, everything else will be a lineto - strcpy(delim," "); - strcat(out, "M "); - coord( &points[0], precision, delim, units, scaling, out ); - double prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude - if ( prev_mag_bulge > pow(0.1,precision) ){ - to_arc(pline.bulge(0), pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, units, scaling, out); - } - for (int i = 1; i < points.size(); i++){ - if ( prev_mag_bulge < pow(0.1,precision) ){ - // If the previous point was a bulge then don't use a line to - strcat(out, "L "); - } - coord( &points[i], precision, delim, units, scaling, out ); - // If bulge > some precsion then add bulge - double mag_bulge = sqrt(pow(points[i].ret_bulge(),2)); - if ( (mag_bulge > pow(0.1,precision)) && (i < (points.size() - 1) )){ - to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out); - } - prev_mag_bulge = mag_bulge; - } - if ( pline.is_closed() ){ - strcat(out,"z"); - } - strcat(out,"\" "); - } - else{ - strcpy(delim,","); - for (int i = 0; i < points.size(); i++){ - coord( &points[i], precision, delim, NULL, scaling, out ); - // If bulge > some precsion then add bulge - } - // if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point - if ( (type == 1) && pline.is_closed() ){ - coord( &points[0], precision, delim, NULL, scaling, out ); - } - } - -} - -char* pline2path(polyline pline, char * units, double scaling, tables plot_info){ - // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element - char *out_ptr; - char out[10000] = "ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information - - strcat(out," />"); - out_ptr = out; - return out_ptr; -} - -char* pline2pline(polyline pline, char * units, double scaling, tables plot_info){ - // Convert a dxf polyline to a SVG polyline. The conversion is not 1:1 because the SVG pline doesn't support closed objects or curves - entity *ent_ptr = &pline; - char temp[2000]; - int precision = 6; - - char out[10000] = "ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); - pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information - //strcpy(temp," "); - - strcat(out,"points=\""); - - //strcat(out,""); - char *out_ptr = out; - return out_ptr; -} -char* pline2polygon(polyline pline, char * units, double scaling, tables plot_info){ - // Convert a dxf polyline to a SVG polygon. The conversion is not 1:1 because the SVG polygone assumes a closed path. If the pline is not closed it will be forced closed - //return pline2svg(pline, 2, 6, units, double scaling,out); -} - - -// DXF LWPolyline -> SVG - - -// This could be a template with polyline and lwpolyline but right now it is not that important -void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out); // General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported -void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){ - // 0 is pline2path - // 1 is pline2pline - // 2 is pline2polygon - - - char delim[2]; - - std::vector< vertex >::iterator vver_iter; - std::vector< vertex > points = pline.ret_points(); - - if (type < 1){ - // Put the first Move To at the first, everything else will be a lineto - strcpy(delim," "); - strcat(out, "M "); - coord( &points[0], precision, delim, NULL, scaling, out ); - double prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude - if ( prev_mag_bulge > pow(0.1,precision) ){ - to_arc(pline.bulge(0),pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, NULL, scaling, out); - } - - for (int i = 1; i < points.size(); i++){ - if ( prev_mag_bulge < pow(0.1,precision) ){ - // If the previous point was a bulge then don't use a line to - strcat(out, "L "); - } - coord( &points[i], precision, delim, NULL , scaling, out ); - // If bulge > some precsion then add bulge - double mag_bulge = sqrt(pow(points[i].ret_bulge(),2)); - if ( ( mag_bulge > pow(0.1,precision) ) && (i < (points.size() - 1) )){ // Make sure the final point doesn't add a bulge on accident - to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out); - } - prev_mag_bulge = mag_bulge; - } - if ( pline.is_closed() ){ - strcat(out,"z"); - } - strcat(out,"\" "); - } - else{ - strcpy(delim,","); - for (int i = 0; i < points.size(); i++){ - coord( &points[i], precision, delim, units, scaling, out ); - // If bulge > some precsion then add bulge - } - // if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point - if ( (type == 1) && pline.is_closed() ){ - coord( &points[0], precision, delim, units, scaling, out ); - } - } - -} - -char* lwpline2path(lwpolyline pline, char * units, double scaling, tables plot_info){ - // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element - char *out_ptr; - char out[10000] = "ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information - - strcat(out," />"); - out_ptr = out; - return out_ptr; -} - -// DXF ARC -> SVG -char* arc2path(arc a, int precision, char * units, double scaling, tables plot_info, char *out){ - // So far this appears to be the only way to convert arcs into something recognized by SVG - char *out_ptr; - char temp[20]; - entity *ent_ptr = &a; - - strcpy(out,"ret_x()+a.ret_radius()*cos( a.ret_srt_ang()*3.14159/180 )),precision,temp) ); - strcat(out," "); - strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_srt_ang()*3.14159/180 )),precision,temp) ); - strcat(out," A "); - // For arcs there is only one radius - strcat(out,gcvt(scaling*a.ret_radius(),precision,temp) ); - strcat(out,","); - strcat(out,gcvt(scaling*a.ret_radius(),precision,temp) ); - - strcat(out," 0"); // For arc assume no x-axis rotation. That seems to apply to elipse elements only - // Determine if it is a large arc - if ( (a.ret_end_ang() > a.ret_srt_ang()) && ( (a.ret_end_ang() - a.ret_srt_ang()) > 180) ){ - strcat(out," 1,0 "); // Large arc flag...Always use a zero sweep flag - } - else{ - strcat(out," 0,0 "); // Small arc flag...Always use a zero sweep flag - } - - //The final point - strcat(out,gcvt(scaling*(ent_ptr->ret_x()+a.ret_radius()*cos( a.ret_end_ang()*3.14159/180 )),precision,temp) ); - strcat(out,","); - strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_end_ang()*3.14159/180 )),precision,temp) ); - strcat(out,"\" fill=\"none\" stroke=\"black\" stroke-width=\"1\" "); - ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); - pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information - strcat(out, " />"); - - - out_ptr = out; - return out_ptr; - -} - - -// DXF Circle -> SVG -char* circle2circle(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){ - // Direct conversion of DXF circle to SVG circle - char *out_ptr; - char temp[1000]="\" cy=\""; - entity *ent_ptr = ˆ - strcpy(out,"ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); - //plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); - pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information - //pattern2dasharray(plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)), precision, scaling, out); // Add the linetype information - strcat(out, " />"); - out_ptr = out; - return out_ptr; -} - -char* circle2path(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){ - // Conversion of DXF circle to SVG circle assuming the path will represent the circle - - char *out_ptr; - char temp[20]=","; - entity *ent_ptr = ˆ - - strcpy(out,"ret_x()-circ.ret_radius(),precision,temp) ); - strcat(out," "); - strcat(out,gcvt(ent_ptr->ret_y(),precision,temp) ); - - strcat(out," a"); - strcat(out,gcvt(circ.ret_radius(),precision,temp) ); - strcat(out,","); - strcat(out,gcvt(circ.ret_radius(),precision,temp) ); - strcat(out,"0 0,0 0,0\" fill=\"none\" stroke=\"black\" stroke-width=\"1\""); - - out_ptr = out; - return out_ptr; -} - - -// DXF Line -> SVG -char* line2line(line ln, int precision, char * units, double scaling, tables plot_info, char *out){ - // Directly convert DXF to SVG because it works - char *out_ptr; - char temp[20]; - entity *ent_ptr = &ln; - - strcpy(out,"ret_x(),precision,temp) ); - strcat(out,units); - strcat(out,"\" y1=\""); - strcat(out,gcvt(-1*ent_ptr->ret_y(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis - strcat(out,units); - - strcat(out,"\" x2=\""); - strcat(out,gcvt(ln.ret_xf(),precision,temp) ); - strcat(out,units); - strcat(out,"\" y2=\""); - strcat(out,gcvt(-1*ln.ret_yf(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis - strcat(out,units); - strcat(out,"\" stroke-width=\"1\" stroke=\"black\" "); - ltype linfo = plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)); - pattern2dasharray(linfo, precision, scaling, out); // Add the linetype information - strcat(out, " />"); - - out_ptr = out; - return out_ptr; -} - - -char* line2path(line ln, int precision, char * units, double scaling, tables plot_info, char *out){ - // Convert DXF line to SVG path - - char *out_ptr; - char temp[20]; - entity *ent_ptr = &ln; - - strcpy(out,"ret_x(),precision,temp) ); - strcat(out," "); - strcat(out,gcvt(scaling*ent_ptr->ret_y(),precision,temp) ); - - strcat(out," L"); - strcat(out,gcvt(scaling*ln.ret_xf(),precision,temp) ); - strcat(out," "); - strcat(out,gcvt(scaling*ln.ret_yf(),precision,temp) ); - strcat(out,"\" fill=\"none\" stroke=\"black\" stroke-width=\"1\" /"); - - out_ptr = out; - return out_ptr; -} - -// DXF Text -> SVG -char* text2text(text txt, int precision, char * units, double scaling, tables plot_info, char *out){ - // Directly convert DXF to SVG because it works - char *out_ptr; - char temp[10000]; - entity *ent_ptr = &txt; - - // If the text is rotated use the transform matrix - - if ( txt.ret_txt_rot() > precision ){ - double ca = cos(0.017453*txt.ret_txt_rot()); // ca = cosine(a) - double sa = sin(-0.017453*txt.ret_txt_rot()); // sa = sine(a) - double tx = ent_ptr->ret_x()*scaling; - double ty = -ent_ptr->ret_y()*scaling; - // Apply a translation to the orgin, then a rotation, then a translation back to the original position - double a = ca; - double b = sa; - double c = -sa; - double d = ca; - double e = -1*(tx*ca-ty*sa-tx); - double f = -1*(tx*sa+ty*ca-ty); - - strcpy(out, "\nret_x(),precision,temp) ); - strcat(out,units); - strcat(out,"\" y=\"-"); // Put in an extra minus because of the way SVG has defined the axis - strcat(out,gcvt(ent_ptr->ret_y(),precision,temp) ); - strcat(out,units); - */ - strcat(out,gcvt(ent_ptr->ret_x()*scaling,precision,temp) ); - //strcat(out,units); - strcat(out,"\" y=\"-"); // Put in an extra minus because of the way SVG has defined the axis - strcat(out,gcvt(ent_ptr->ret_y()*scaling,precision,temp) ); - //strcat(out,units); - strcat(out,"\" font-family=\"Verdana\" font-size=\""); - strcat(out,gcvt(scaling*txt.ret_txt_ht(),precision,temp) ); - strcat(out,"\" Fill=\"black\""); - - strcat(out," >"); - // Now put in the text - strcat(out,txt.ret_text(temp)); - - // Now close the text element - strcat(out,""); - // If the text was rotated finish off the tranform group - if ( txt.ret_txt_rot() > precision ){ - strcat(out,""); - } - - out_ptr = out; - return out_ptr; -} - - - -// DXF Insert -> SVG -char* insert2group(insert in, int precision, char * units, double scaling, tables plot_info, blocks blks, char *out){ - char *out_ptr; - char tmp_char[100000]; - - // get the block using the name from the insert information - block blk = blks.ret_block(in.name(tmp_char)); - - entity *ent_ptr = ∈ - entities *ents_ptr = &blk; - // For now just translations MBS 22 Aug 05 - strcpy(out, "ret_x(),precision,tmp_char) ); - strcat(out,","); - strcat(out,gcvt(-scaling*ent_ptr->ret_y(),precision,tmp_char) ); - strcat(out,")\" >\n"); - - - // Now convert the entities in the block - std::vector< polyline > plines = ents_ptr->ret_plines(); - std::vector< lwpolyline > lwplines = ents_ptr->ret_lwplines(); - std::vector< arc > arcs = ents_ptr->ret_arcs(); - std::vector< circle > circs = ents_ptr->ret_circles(); - std::vector< line > lns = ents_ptr->ret_lines(); - std::vector< text > txts = ents_ptr->ret_texts(); - - - - for(int i = 0; i < plines.size();i++){ - strcat( out,pline2pline(plines[i], units, scaling, plot_info ) ); - strcat( out, "\n" ); - } - for(int i = 0; i < lwplines.size();i++){ - strcat( out,lwpline2path(lwplines[i], units, scaling, plot_info ) ); - strcat( out, "\n" ); - } - for(int i = 0; i < arcs.size();i++){ - strcat( out, arc2path(arcs[i], 6,units, scaling, plot_info, tmp_char ) ); - strcat( out, "\n" ); - } - for(int i = 0; i < circs.size();i++){ - strcat( out, circle2circle(circs[i], 6, units, scaling, plot_info, tmp_char) ); - strcat( out, "\n" ); - } - for(int i = 0; i < lns.size();i++){ - strcat( out, line2line(lns[i], 6, units, scaling, plot_info, tmp_char) ); - strcat( out, "\n" ); - } - for(int i = 0; i < txts.size();i++){ - strcat( out, text2text(txts[i], 6, units, scaling, plot_info, tmp_char) ); - strcat( out, "\n" ); - } - // End the group - strcat(out,""); - - out_ptr = out; - return out_ptr; -} - - - -char* write_by_layer(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * layer, char * out){ - // output_type = 0 is to std:out - // output_type = 1 is to the input filename but with .dxf on the end - - // For now everything will go to stdout later may directed to other places - - // Get the various file informations as dependent on the layer type - std::vector< polyline > plines = ents.ret_plines(layer); - std::vector< lwpolyline > lwplines = ents.ret_lwplines(layer); - std::vector< arc > arcs = ents.ret_arcs(layer); - std::vector< circle > circs = ents.ret_circles(layer); - std::vector< line > lns = ents.ret_lines(layer); - std::vector< text > txts = ents.ret_texts(layer); - std::vector< insert > ins = ents.ret_inserts(layer); - - // It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better - char tmp_char[100000]; - for(int i = 0; i < plines.size();i++){ - if (output_type == 0){ - std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; - } - } - for(int i = 0; i < lwplines.size();i++){ - if (output_type == 0){ - std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; - } - } - for(int i = 0; i < arcs.size();i++){ - if (output_type == 0){ - std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; - } - } - for(int i = 0; i < circs.size();i++){ - if (output_type == 0){ - std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < lns.size();i++){ - if (output_type == 0){ - std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < txts.size();i++){ - if (output_type == 0){ - std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < ins.size();i++){ - if (output_type == 0){ - std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; - } - } -} - - - -char* write_all(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * out){ - // output_type = 0 is to std:out - // output_type = 1 is to the input filename but with .dxf on the end - - // For now everything will go to stdout later may directed to other places - - // Get the various file informations as dependent on the layer type - std::vector< polyline > plines = ents.ret_plines(); - std::vector< lwpolyline > lwplines = ents.ret_lwplines(); - std::vector< arc > arcs = ents.ret_arcs(); - std::vector< circle > circs = ents.ret_circles(); - std::vector< line > lns = ents.ret_lines(); - std::vector< text > txts = ents.ret_texts(); - std::vector< insert > ins = ents.ret_inserts(); - - // It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better - char tmp_char[100000]; - for(int i = 0; i < plines.size();i++){ - if (output_type == 0){ - std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << pline2path(plines[i], NULL, scaling, tbls ) << std::endl; - } - } - for(int i = 0; i < lwplines.size();i++){ - if (output_type == 0){ - std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << lwpline2path(lwplines[i], units, scaling, tbls ) << std::endl; - } - } - for(int i = 0; i < arcs.size();i++){ - if (output_type == 0){ - std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << arc2path(arcs[i], 6,units, scaling, tbls, tmp_char ) << std::endl; - } - } - for(int i = 0; i < circs.size();i++){ - if (output_type == 0){ - std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << circle2circle(circs[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < lns.size();i++){ - if (output_type == 0){ - std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << line2line(lns[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < txts.size();i++){ - if (output_type == 0){ - std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << text2text(txts[i], 6, units, scaling, tbls, tmp_char) << std::endl; - } - } - for(int i = 0; i < ins.size();i++){ - if (output_type == 0){ - std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; - } - else if (output_type == 1){ - std::cout << "\t" << insert2group(ins[i], 6, units, scaling, tbls, blks, tmp_char) << std::endl; - } - } -} - - - diff --git a/src/extension/dxf2svg/entities2elements.h b/src/extension/dxf2svg/entities2elements.h deleted file mode 100644 index cceefcf15..000000000 --- a/src/extension/dxf2svg/entities2elements.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Method for converting dxf entities to SVG elements -There are multiple ways for converting different items - -If possible most DXF enetities will be converted to paths because that is the most flexable object - -Matt Squires -SoC 2005 - -*/ - -#include"entities.h" -#include"tables.h" -#include"blocks.h" - -// The names indicate the DXF entitiy first and the SVG element last - -// Common elements -char* to_arc(double bulge, double r, double start_ang, double end_ang, int precision,char* delim, char * units, double scaling, char *out); // This is used for arcs, polylines, and lwpolylines - -// DXF Polyline -> SVG - -char* pline2path(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element -char* pline2pline(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG polyline. The conversion is not 1:1 because the SVG pline doesn't support closed objects or curves -char* pline2polygon(polyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG polygon. The conversion is not 1:1 because the SVG polygone assumes a closed path. If the pline is not closed it will be forced closed - -// DXF LWPolyline -> SVG -char* lwpline2path(lwpolyline pline, char * units, double scaling, tables plot_info); // Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element - -// DXF ARC -> SVG -char* arc2path(arc a, int precision, char * units, double scaling, tables plot_info, char *out); // So far this appears to be the only way to convert arcs into something recognized by SVG - - -// DXF Circle -> SVG -char* circle2circle(circle circ, int precision, char * units, double scaling, tables plot_info, char *out); // Direct conversion of DXF circle to SVG circle -char* circle2path(circle circ, int precision, char * units, double scaling, tables plot_info, char *out); // Conversion of DXF circle to SVG circle assuming the path will represent the circle - - -// DXF Line -> SVG -char* line2line(line ln, int precision, char * units, double scaling, tables plot_info, char *out); // Directly convert DXF to SVG because it works -char* line2path(line ln, int precision, char * units, double scaling, tables plot_info, char *out); // Convert DXF line to SVG path - -// DXF Text -> SVG -char* text2text(text txt, int precision, char * units, double scaling, tables plot_info, char *out); // Directly convert DXF to SVF assuming VERANDA font - -// DXF Insert -> SVG -char* insert2group(insert in, int precision, char * units, double scaling, tables plot_info, blocks blks, char *out); - -// Write all of the possible enties with a variety of options - -char* write_by_layer(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * layer, char * out); // Write out the entities by layer designation -char* write_all(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * out); - - diff --git a/src/extension/dxf2svg/read_dxf.cpp b/src/extension/dxf2svg/read_dxf.cpp deleted file mode 100644 index 1a4eefbc9..000000000 --- a/src/extension/dxf2svg/read_dxf.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * For reading and slight parsing of dxf files - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - - -#include -#include -#include "read_dxf.h" - -#include -#include -#include -using namespace std; - - -int MAX_STR_LN = 10000; - -int section(char* value){ - if ( strncmp(value,"HEADER",6) == 0 ) return 0; - if ( strncmp(value,"CLASSES",7) == 0 ) return 1; - if ( strncmp(value,"TABLES",6) == 0 ) return 2; - if ( strncmp(value,"BLOCKS",6) == 0 ) return 3; - if ( strncmp(value,"ENTITIES",8) == 0 ) return 4; - if ( strncmp(value,"OBJECTS",7) == 0 ) return 5; - if ( strncmp(value,"THUMBNAILIMAGE",14) == 0 ) return 6; -} - - -dxfpair::dxfpair(int gcode, char val[10000]){ - group_code = gcode; - // Dynamically save the strings, otherwise the memory uses is bad - - for (int i = 0; i < strlen(val); i++){ - value.push_back(val[i]); - } -} - - -dxfpair::~dxfpair(){ - //delete [] value; -} - -char * dxfpair::value_char(char *string){ - int size = value.size(); - while( ( size > 0 ) && int(value[size-1]) < 33){ - // Strip off any control characters and spaces off the end of the string - size--; - } - for(int i = 0; i < size; i++){ - string[i] = value[i]; - } - string[size]=0; -} - -std::vector< std::vector< dxfpair > > dxf_get_sections(char* filename){ - // In the dxf format information is paired into group codes that indicate the information that follows on the next line. The information on the next line is called the value - - int n =0; - - int group_code; - char value[MAX_STR_LN]; - - int section_num; - - - - - std::vector< std::vector< dxfpair > > out; - - std::vector< dxfpair > header; - std::vector< dxfpair > classes; - std::vector< dxfpair > tables; - std::vector< dxfpair > blocks; - std::vector< dxfpair > entities; - std::vector< dxfpair > objects; - std::vector< dxfpair > thumbnailimage; - - header.clear(); - classes.clear(); - tables.clear(); - blocks.clear(); - entities.clear(); - objects.clear(); - thumbnailimage.clear(); - - - // Open dxf file for reading - std::ifstream file(filename); - - if (!file.is_open()){ - exit (1); // Change this to an exception - } - - // Find the first SECTION header - - while ( (!file.eof()) ){ - n++; - - // get the first group code and value - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - - do{ - - // TO DO set all the chars to be caps for later comparison - - // Find the SECTION codes - if ( (group_code == 0 ) && ( strncmp(value,"SECTION",7) == 0 ) ){ - // Directly after a section value is the type of section ( e.g. HEADER, TABLES ) - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - section_num = section( value ); - if ( group_code == 2 ){ - // Make sure the the group code is 2 for the SECTION name - // This is a big block of mostly repetitive code, it will result in larger code, but would be faster than putting the switch in another while loop. If I still live in a time when file size mattered alot I would change it - //std::cout << "section_num = " << section_num << std::endl; - switch ( section_num ){ - case 0: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - header.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - break; - case 1: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - if ( (group_code != 0) || (strncmp(value,"ENDSEC",6) != 0) ){ - // Some dxf files have blank sections. These are not handled by the do/while loop so break about if needed - do{ - classes.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - } - break; - case 2: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - tables.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); - break; - case 3: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - blocks.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - break; - case 4: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - entities.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - break; - case 5: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - objects.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - break; - case 6: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - do{ - thumbnailimage.push_back( dxfpair( group_code, value ) ); - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - }while( ( (group_code != 0) || strncmp(value,"ENDSEC",6) != 0 ) && (!file.eof()) ); // I put in the (group_code != 0) in the hope that it will be a faster bool compare than the string compare. Test this later - break; - default: - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - } - } - } - file.getline(value,MAX_STR_LN); - group_code = atoi(value); - file.getline(value,MAX_STR_LN); - - n++; - }while( ( strncmp(value,"EOF",3) != 0 ) && (!file.eof()) ); - } - - out.push_back(header); - out.push_back(classes); - out.push_back(tables); - out.push_back(blocks); - out.push_back(entities); - out.push_back(objects); - out.push_back(thumbnailimage); - - return out; -} - - -std::vector< std::vector< dxfpair > > separate_parts( std::vector< dxfpair > section){ - //std::cout << "1" << std::endl; - //std::cout << "section.size() = " << section.size() << std::endl; - // Find where the major sections are and break into smaller parts - // Major section is defined as anything beween group_code 0 to 0 - std::vector< dxfpair > inner; - std::vector< std::vector< dxfpair > > outer; - //std::cout << "2" << std::endl; - for (int i = 0; i < section.size(); i++){ - //std::cout << "i = " << i << std::endl; - //std::cout << "section[i].value.size() = " << section[i].value.size() << std::endl; - - // Make sure no control codes like LF or CR are making it past this section - if ( (section[i].value.size() > 0) && int(section[i].value.back()) < 32 ){ - section[i].value.pop_back(); - } - //for(int j = 0;j < section[i].value.size();j++ ) std::cout << section[i].value[j]; - //std::cout << std::endl; - - inner.push_back( section[i] ); - - // If the next group code is 0 then push the previously found info on outer and start looking for data again - if (section[i+1].group_code == 0){ - //std::cout << "inner.push_back" << std::endl; - outer.push_back( inner ); - inner.clear(); - } - } - // Because putting the data on outer depends on find a GC=0 the last bit of data may be left behind so it inner has data in it put it on outer - if (!inner.empty()){ - outer.push_back( inner ); - inner.clear(); - } - //std::cout << "3" << std::endl; - if (section.back().group_code == 0){ - //outer.push_back( inner ); // Put the last part on if there is information, but I don't think it needs to. - } - - return outer; -} - diff --git a/src/extension/dxf2svg/read_dxf.h b/src/extension/dxf2svg/read_dxf.h deleted file mode 100644 index 7e008b4e0..000000000 --- a/src/extension/dxf2svg/read_dxf.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Header file for reading dxf information and basic parsing. Interprting information is found in other files -*/ - -#ifndef READ_DXF_H -#define READ_DXF_H - -#include - - - -class dxfpair{ -public: - dxfpair(int gcode, char val[10000]); - virtual ~dxfpair(); - - char * value_char(char *string); - - // Leave this data public - int group_code; - std::vector< char > value; -}; - - - - -int section(char* value); // Convert the section titles into integers - -std::vector< std::vector< dxfpair > > dxf_get_sections(char* filename); - -std::vector< std::vector< dxfpair > > separate_parts( std::vector< dxfpair > section ); // Find where the major sections are and break into smaller parts - -#endif diff --git a/src/extension/dxf2svg/tables.cpp b/src/extension/dxf2svg/tables.cpp deleted file mode 100644 index fcaff33c0..000000000 --- a/src/extension/dxf2svg/tables.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Code for the conversion of DXF information in the TABLES section - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - -#include"tables.h" -#include - - - - -int determine_table(char* value){ - // Common Elements as far as I am concerend - if ( strncmp(value,"LAYER",5) == 0 ) return 0; - if ( strncmp(value,"LTYPE",5) == 0 ) return 1; - if ( strncmp(value,"STYLE",5) == 0 ) return 2; - if ( strncmp(value,"UCS",3) == 0 ) return 3; - if ( strncmp(value,"VIEW",4) == 0 ) return 4; - if ( strncmp(value,"VPORT",4) == 0 ) return 5; - if ( strncmp(value,"APPID",5) == 0 ) return 6; - if ( strncmp(value,"BLOCK_RECORD",12) == 0 ) return 7; - else return -1; -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// TABLE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -int table::ret_maxN(){ - return max_number; -} - - - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LAYER -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -layer::layer( std::vector< dxfpair > info){ - // Get the vertex information - - //basic_entity( info ); - //static char string[10000]; - char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 2: - info[i].value_char(layer_name); - break; - case 6: - info[i].value_char(ltype_name); - break; - - case 62: - info[i].value_char(string); - color_number = atoi(string); - //std::cout << "I found a color and its number = " << color_number << std::endl; - break; - case 290: - info[i].value_char(string); - plotting_flag = atoi(string); - break; - } - } -} - -void layer::display(){ - std::cout << "LAYER\n"; - //std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush; -} - -char* layer::name(char* string){ - return( strcpy(string,layer_name) ); -} - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LTYPE -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -ltype::ltype( std::vector< dxfpair > info){ - // Get the linetype information - - //static char string[10000]; - char string[10000]; - for (int i = 0; i < info.size(); i++){ - switch( info[i].group_code ){ - case 2: - info[i].value_char(ltype_name); - break; - case 3: - info[i].value_char(descriptive_txt); - break; - case 73: - info[i].value_char(string); - num_elements = atoi(string); - break; - case 40: - info[i].value_char(string); - pattern_length = atof(string); - break; - case 49: - info[i].value_char(string); - pattern.push_back( atof(string) ); - break; - } - } -} - - - -char* ltype::name(char* string){ - return( strcpy(string,ltype_name) ); -} - - -std::vector< double > ltype::ret_pattern(){ - return pattern; -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// tables -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - -tables::tables(std::vector< std::vector< dxfpair > > sections){ - // Read the main information about the entities section and then put it in the enetites class - int value; - char string[10000]; - - for(int i = 0; i < sections.size(); i++){ - //std::cout << "start" << std::endl; - sections[i][0].value_char(string); - value = determine_table(string); - //std::cout << "sections.size() = " << sections.size() << std::endl << "i = " << i << std::endl << "string = " << string << std::endl; - switch( value ){ - case 0: - // LAYER - //std::cout << "tables start layer " << std::endl; - tables_layer.push_back( layer( sections[i] ) ); - //std::cout << "tables end layer " << std::endl; - break; - - case 1: - // LTYPE - //std::cout << "tables start ltype " << std::endl; - tables_ltype.push_back( ltype( sections[i] ) ); - //std::cout << "tables end ltype " << std::endl; - break; - - //case 3: - // break; - - default: - break; - // Nothing here - } - - } - -} - - - - -ltype tables::ret_ltype(char ltype_name[10000], char layer_name[10000]){ - int string_len = 0; - char name[10000]; - char temp[10000]; - // The ltype information may be given in the entitity or in the layer information - // Assume that if there is a name defined in the linetype that it trumps any other layer information - if ( strlen(ltype_name) > 0 ) strcpy(name,ltype_name); - else strcpy(name,layer_name); - for (int i = 0; i < tables_ltype.size();i++){ - string_len = strlen(tables_ltype[i].name(temp)); - if (strncmp(tables_ltype[i].name(temp),name,string_len) == 0 ) return tables_ltype[i]; - } - return tables_ltype[0]; -} - - -layer tables::ret_layer(char layer_name[10000]){ - int string_len = 0; - char temp[10000]; - - for (int i = 0; i < tables_layer.size();i++){ - string_len = strlen(tables_layer[i].name(temp)); - if (strncmp(tables_layer[i].name(temp),layer_name,string_len) == 0 ) return tables_layer[i]; - } - return tables_layer[0]; -} - - -std::vector< layer > tables::ret_layers(){ - return tables_layer; -} diff --git a/src/extension/dxf2svg/tables.h b/src/extension/dxf2svg/tables.h deleted file mode 100644 index f63122eaf..000000000 --- a/src/extension/dxf2svg/tables.h +++ /dev/null @@ -1,71 +0,0 @@ -/* Code for the conversion of DXF information in the TABLES section -Matt Squires -SoC -2005*/ - -#ifndef DXF_TABLES_H -#define DXF_TABLES_H - -#include -#include"read_dxf.h" - -class table{ - public: - int ret_maxN(); - private: - int max_number; -}; - - -class layer : public table{ - public: - layer( std::vector< dxfpair > info); - void display(); - char* name(char* string); - private: - char layer_name[10000]; - char ltype_name[10000]; // The layer may also hold the ltype infomation - int color_number; - int plotting_flag; - -}; - - -class ltype : public table{ - public: - ltype( std::vector< dxfpair > info); - char* name(char* string); - std::vector< double > ret_pattern(); - private: - char ltype_name[10000]; - char descriptive_txt[10000]; - int num_elements; - double pattern_length; - std::vector< double > pattern; - -}; - - -class tables{ - // Well I said that I would only use STL containers internally, but I would have to use a dynamically linked list, and I haven't done for a long time soo STL is my crutch. - public: - tables(std::vector< std::vector< dxfpair > > sections); // Put the various entities into their respective vectors - void display_all(); - - ltype ret_ltype(char ltype_name[10000], char layer_name[10000]); - layer ret_layer(char layer_name[10000]); - - std::vector< layer > ret_layers(); - - - private: - //void add_dimstyle(polyline pline); - void add_layer(layer layr); - void add_ltype(ltype line_type); - - std::vector< layer > tables_layer; - std::vector< ltype > tables_ltype; -}; - - -#endif diff --git a/src/extension/dxf2svg/tables2svg_info.cpp b/src/extension/dxf2svg/tables2svg_info.cpp deleted file mode 100644 index c59060306..000000000 --- a/src/extension/dxf2svg/tables2svg_info.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Convert DXF table information to a format that is recognized by SVG - * - * Author: - * Matt Squires - * - * Copyright (C) 2005 Matt Squires - * - * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details - */ - - -#include "tables2svg_info.h" -#include -#include -#include -#include - -char* pattern2dasharray(ltype info, int precision, double scaling, char* out){ - std::vector< double > pattern = info.ret_pattern(); - char temp[50]; - char *out_ptr; - - - if (!pattern.empty()){ - strcat(out," stroke-dasharray=\""); - for(int i = 0; i < pattern.size()-1;i++){ - strcat(out,gcvt(scaling*sqrt(pow(pattern[i],2)),precision,temp) ); - strcat(out,","); - } - strcat( out,gcvt(scaling*sqrt(pow(pattern[pattern.size()-1],2)),precision,temp) ); - strcat(out,"\" "); - } - - out_ptr = out; - return out_ptr; -} diff --git a/src/extension/dxf2svg/tables2svg_info.h b/src/extension/dxf2svg/tables2svg_info.h deleted file mode 100644 index 2c99f034e..000000000 --- a/src/extension/dxf2svg/tables2svg_info.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Convert DXF table information to a format that is recognized by SVG -Matt Squires -SOC 2005 -*/ - - -#include"tables.h" - -char* pattern2dasharray(ltype info, int precision, double scaling, char* temp); diff --git a/src/extension/dxf2svg/test_dxf.cpp b/src/extension/dxf2svg/test_dxf.cpp deleted file mode 100644 index c3bbdc141..000000000 --- a/src/extension/dxf2svg/test_dxf.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* test read_dxf */ -#include"read_dxf.h" -#include"entities.h" -#include"blocks.h" -#include"tables.h" -#include -#include"entities2elements.h" - -using namespace std; - -int main(){ - std::vector< std::vector< dxfpair > > output, entities_info, blocks_info, tables_info; - //output = dxf_get_sections("circ_sqr.dxf"); - //output = dxf_get_sections("Labjack.dxf"); - //output = dxf_get_sections("mini_post.dxf"); - //output = dxf_get_sections("../8599-E0W.dxf"); - //output = dxf_get_sections("../bulged_lwpoly.dxf"); - //output = dxf_get_sections("../aspheric_lens.dxf"); - output = dxf_get_sections("../layers_colors.dxf"); - /*std::vector< dxfpair > header; - std::vector< dxfpair > classes; - std::vector< dxfpair > tables; - std::vector< dxfpair > blocks; - std::vector< dxfpair > entities; - std::vector< dxfpair > objects; - std::vector< dxfpair > thumbnailimage; - */ - - - //dxf_get_sections("circ_sqr.dxf",header,classes,tables,blocks,entities,objects,thumbnailimage); - //dxf_get_sections("mini_post.dxf",header,classes,tables,blocks,entities,objects,thumbnailimage); - - //cout << entities.size() << endl; - for (int i=0;i pl_tmp= ents.ret_plines(); - //cout << "pline2pline\n" << pline2pline(pl_tmp[0], units ) << endl; - //cout << "pline2pline\n" << pline2pline(ents.ret_plines()[0], units ) << endl; - //cout << "pline2path\n" << pline2path(ents.ret_plines()[0], units ); - - // char tmp_char[10000]; - - cout << "\nCircle conversion\n"; - //cout << "circle2circle\n" << circle2circle(ents.ret_circles()[0], 3, units, tmp_char) << endl; - - return 0; -} -- cgit v1.2.3 From 1d66df63a0263476b774fe9fe4854afea60489f2 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 30 Jan 2013 18:24:39 +0100 Subject: removing some more unused functions (bzr r12076) --- src/trace/filterset.cpp | 35 ---------------------- src/trace/filterset.h | 6 ---- src/trace/imagemap-gdk.cpp | 75 ---------------------------------------------- src/trace/imagemap-gdk.h | 8 ----- 4 files changed, 124 deletions(-) (limited to 'src') diff --git a/src/trace/filterset.cpp b/src/trace/filterset.cpp index 908985225..f6c025956 100644 --- a/src/trace/filterset.cpp +++ b/src/trace/filterset.cpp @@ -365,41 +365,6 @@ grayMapCanny(GrayMap *gm, double lowThreshold, double highThreshold) - - - - -/** - * - */ -GdkPixbuf * -gdkCanny(GdkPixbuf *img, double lowThreshold, double highThreshold) -{ - if (!img) - return NULL; - - - GrayMap *grayMap = gdkPixbufToGrayMap(img); - if (!grayMap) - return NULL; - - /*grayMap->writePPM(grayMap, "gbefore.ppm");*/ - - GrayMap *cannyGm = grayMapCanny(grayMap,lowThreshold, highThreshold); - - grayMap->destroy(grayMap); - - if (!cannyGm) - return NULL; - - /*grayMap->writePPM(grayMap, "gafter.ppm");*/ - - GdkPixbuf *newImg = grayMapToGdkPixbuf(cannyGm); - - - return newImg; -} - /*######################################################################### ### Q U A N T I Z A T I O N #########################################################################*/ diff --git a/src/trace/filterset.h b/src/trace/filterset.h index eeafc079f..820d225c3 100644 --- a/src/trace/filterset.h +++ b/src/trace/filterset.h @@ -37,12 +37,6 @@ RgbMap *rgbMapGaussian(RgbMap *rgbmap); GrayMap *grayMapCanny(GrayMap *gmap, double lowThreshold, double highThreshold); -/** - * - */ -GdkPixbuf *gdkCanny(GdkPixbuf *img, - double lowThreshold, double highThreshold); - /** * */ diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index 06f355de7..7c7139002 100644 --- a/src/trace/imagemap-gdk.cpp +++ b/src/trace/imagemap-gdk.cpp @@ -122,44 +122,6 @@ PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf) return ppMap; } -/*GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) -{ - if (!ppMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * ppMap->width * ppMap->height * 3); - if (!pixdata) - return NULL; - - int n_channels = 3; - int rowstride = ppMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, ppMap->width, ppMap->height, - rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; x++) - { - unsigned long rgb = ppMap->getPixel(ppMap, x, y); - p[0] = (rgb >> 16) & 0xff; - p[1] = (rgb >> 8) & 0xff; - p[2] = (rgb ) & 0xff; - p += n_channels; - } - row += rowstride; - } - - return buf; -} -*/ - /*######################################################################### ## R G B M A P @@ -203,44 +165,7 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) return rgbMap; } -/* -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) -{ - if (!rgbMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * rgbMap->width * rgbMap->height * 3); - if (!pixdata) - return NULL; - - int n_channels = 3; - int rowstride = rgbMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, rgbMap->width, rgbMap->height, - rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; x++) - { - RGB rgb = rgbMap->getPixel(rgbMap, x, y); - p[0] = rgb.r & 0xff; - p[1] = rgb.g & 0xff; - p[2] = rgb.b & 0xff; - p += n_channels; - } - row += rowstride; - } - return buf; -} -*/ /*######################################################################### ## I N D E X E D M A P diff --git a/src/trace/imagemap-gdk.h b/src/trace/imagemap-gdk.h index 3b4631f50..63281658a 100644 --- a/src/trace/imagemap-gdk.h +++ b/src/trace/imagemap-gdk.h @@ -24,17 +24,9 @@ extern "C" { #endif GrayMap *gdkPixbufToGrayMap(GdkPixbuf *buf); - GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap); - PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf); - -//GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); - RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf); - -//GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); - GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap); -- cgit v1.2.3 From a7c6061c0b32affc13bfb818161ca7fc002ef210 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Wed, 30 Jan 2013 21:47:35 +0100 Subject: code cleanup. don't use pointers when you don't have to. use const whereever you can. (bzr r12077) --- src/display/cairo-utils.cpp | 41 ++++++++++++------------------ src/display/cairo-utils.h | 17 ++++++++++--- src/display/nr-filter-diffuselighting.cpp | 6 ++--- src/display/nr-filter-flood.cpp | 6 ++--- src/display/nr-filter-specularlighting.cpp | 6 ++--- 5 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 831b37899..8eeee0277 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -597,20 +597,11 @@ void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, a = CLAMP(a, 0.0, 1.0); } -void srgb_to_linear( double* c ) { +static guint32 srgb_to_linear( const guint32 c, const guint32 a ) { - if( *c < 0.04045 ) { - *c /= 12.92; - } else { - *c = pow( (*c+0.055)/1.055, 2.4 ); - } -} - -void srgb_to_linear( guint32* c, guint32 a ) { - - *c = unpremul_alpha( *c, a ); + const guint32 c1 = unpremul_alpha( c, a ); - double cc = *c/255.0; + double cc = c1/255.0; if( cc < 0.04045 ) { cc /= 12.92; @@ -619,16 +610,16 @@ void srgb_to_linear( guint32* c, guint32 a ) { } cc *= 255.0; - *c = (int)cc; + const guint32 c2 = (int)cc; - *c = premul_alpha( *c, a ); + return premul_alpha( c2, a ); } -void linear_to_srgb( guint32* c, guint32 a ) { +static guint32 linear_to_srgb( const guint32 c, const guint32 a ) { - *c = unpremul_alpha( *c, a ); + const guint32 c1 = unpremul_alpha( c, a ); - double cc = *c/255.0; + double cc = c1/255.0; if( cc < 0.0031308 ) { cc *= 12.92; @@ -637,9 +628,9 @@ void linear_to_srgb( guint32* c, guint32 a ) { } cc *= 255.0; - *c = (int)cc; + const guint32 c2 = (int)cc; - *c = premul_alpha( *c, a ); + return premul_alpha( c2, a ); } int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface) @@ -656,9 +647,9 @@ int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface) guint32 px = *reinterpret_cast(data + 4*x); EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting if( a != 0 ) { - srgb_to_linear( &r, a ); - srgb_to_linear( &g, a ); - srgb_to_linear( &b, a ); + r = srgb_to_linear( r, a ); + g = srgb_to_linear( g, a ); + b = srgb_to_linear( b, a ); } ASSEMBLE_ARGB32(px2, a,r,g,b); *reinterpret_cast(data + 4*x) = px2; @@ -681,9 +672,9 @@ int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface) guint32 px = *reinterpret_cast(data + 4*x); EXTRACT_ARGB32(px, a,r,g,b) ; // Unneeded semi-colon for indenting if( a != 0 ) { - linear_to_srgb( &r, a ); - linear_to_srgb( &g, a ); - linear_to_srgb( &b, a ); + r = linear_to_srgb( r, a ); + g = linear_to_srgb( g, a ); + b = linear_to_srgb( b, a ); } ASSEMBLE_ARGB32(px2, a,r,g,b); *reinterpret_cast(data + 4*x) = px2; diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index 04d6c6810..2596cd969 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -108,7 +108,7 @@ guint32 ink_cairo_surface_average_color(cairo_surface_t *surface); void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a); void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a); -void srgb_to_linear( double *c); +double srgb_to_linear( const double c ); int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface); int ink_cairo_surface_linear_to_srgb(cairo_surface_t *surface); @@ -128,13 +128,13 @@ G_GNUC_CONST guint32 argb32_from_rgba(guint32 in); G_GNUC_CONST inline guint32 -premul_alpha(guint32 color, guint32 alpha) +premul_alpha(const guint32 color, const guint32 alpha) { - guint32 temp = alpha * color + 128; + const guint32 temp = alpha * color + 128; return (temp + (temp >> 8)) >> 8; } G_GNUC_CONST inline guint32 -unpremul_alpha(guint32 color, guint32 alpha) +unpremul_alpha(const guint32 color, const guint32 alpha) { // NOTE: you must check for alpha != 0 yourself. return (255 * color + alpha/2) / alpha; @@ -154,6 +154,15 @@ void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv); #define ASSEMBLE_ARGB32(px,a,r,g,b) \ guint32 px = (a << 24) | (r << 16) | (g << 8) | b; +inline double srgb_to_linear( const double c ) { + if( c < 0.04045 ) { + return c / 12.92; + } else { + return pow( (c+0.055)/1.055, 2.4 ); + } +} + + namespace Inkscape { namespace Display diff --git a/src/display/nr-filter-diffuselighting.cpp b/src/display/nr-filter-diffuselighting.cpp index 22e6731c3..c6724e3ba 100644 --- a/src/display/nr-filter-diffuselighting.cpp +++ b/src/display/nr-filter-diffuselighting.cpp @@ -152,9 +152,9 @@ void FilterDiffuseLighting::render_cairo(FilterSlot &slot) // if color_interpolation_filters set to linearRGB (for efficiency assuming // next filter primitive has same value of cif). if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { - srgb_to_linear( &r ); - srgb_to_linear( &g ); - srgb_to_linear( &b ); + r = srgb_to_linear( r ); + g = srgb_to_linear( g ); + b = srgb_to_linear( b ); } } set_cairo_surface_ci(out, ci_fp ); diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 0c581762d..d1fe3e13f 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -64,9 +64,9 @@ void FilterFlood::render_cairo(FilterSlot &slot) // if color_interpolation_filters set to linearRGB (for efficiency assuming // next filter primitive has same value of cif). if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { - srgb_to_linear( &r ); - srgb_to_linear( &g ); - srgb_to_linear( &b ); + r = srgb_to_linear( r ); + g = srgb_to_linear( g ); + b = srgb_to_linear( b ); } } set_cairo_surface_ci(out, ci_fp ); diff --git a/src/display/nr-filter-specularlighting.cpp b/src/display/nr-filter-specularlighting.cpp index 535633143..2ce02adee 100644 --- a/src/display/nr-filter-specularlighting.cpp +++ b/src/display/nr-filter-specularlighting.cpp @@ -165,9 +165,9 @@ void FilterSpecularLighting::render_cairo(FilterSlot &slot) // if color_interpolation_filters set to linearRGB (for efficiency assuming // next filter primitive has same value of cif). if( ci_fp == SP_CSS_COLOR_INTERPOLATION_LINEARRGB ) { - srgb_to_linear( &r ); - srgb_to_linear( &g ); - srgb_to_linear( &b ); + r = srgb_to_linear( r ); + g = srgb_to_linear( g ); + b = srgb_to_linear( b ); } } set_cairo_surface_ci(out, ci_fp ); -- cgit v1.2.3 From 1b96d99480729ccc54d4f5292c305dd4bfa34655 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Wed, 30 Jan 2013 23:11:40 +0000 Subject: Disconnect size_allocation signal handler before disposing desktop widget Fixed bugs: - https://launchpad.net/bugs/1108930 (bzr r12078) --- src/widgets/desktop-widget.cpp | 46 ++++++++++++++++++++++-------------------- src/widgets/desktop-widget.h | 6 +++++- 2 files changed, 29 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index e6fabd50b..95ac7f949 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -324,8 +324,8 @@ canvas_tbl_size_allocate(GtkWidget *widget, GdkRectangle *allocation, gpointer data) { - SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data); - sp_desktop_widget_update_rulers (dtw); + SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data); + sp_desktop_widget_update_rulers (dtw); } /** @@ -401,14 +401,14 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) GtkWidget *tbl = gtk_grid_new(); - GtkWidget *canvas_tbl = gtk_grid_new(); + dtw->canvas_tbl = gtk_grid_new(); - gtk_grid_attach(GTK_GRID(canvas_tbl), eventbox, 1, 0, 1, 1); + gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), eventbox, 1, 0, 1, 1); #else GtkWidget *tbl = gtk_table_new(2, 3, FALSE); - GtkWidget *canvas_tbl = gtk_table_new(3, 3, FALSE); + dtw->canvas_tbl = gtk_table_new(3, 3, FALSE); - gtk_table_attach(GTK_TABLE(canvas_tbl), + gtk_table_attach(GTK_TABLE(dtw->canvas_tbl), eventbox, 1, 2, 0, 1, GTK_FILL, GTK_FILL, @@ -426,9 +426,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); #if GTK_CHECK_VERSION(3,0,0) - gtk_grid_attach(GTK_GRID(canvas_tbl), eventbox, 0, 1, 1, 1); + gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), eventbox, 0, 1, 1, 1); #else - gtk_table_attach(GTK_TABLE (canvas_tbl), + gtk_table_attach(GTK_TABLE (dtw->canvas_tbl), eventbox, 0, 1, 1, 2, GTK_FILL, GTK_FILL, @@ -444,11 +444,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) dtw->hscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (dtw->hadj)); - gtk_grid_attach(GTK_GRID(canvas_tbl), dtw->hscrollbar, 1, 2, 1, 1); + gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), dtw->hscrollbar, 1, 2, 1, 1); dtw->vscrollbar_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #else dtw->hscrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (dtw->hadj)); - gtk_table_attach(GTK_TABLE (canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, + gtk_table_attach(GTK_TABLE (dtw->canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, GTK_FILL, GTK_SHRINK, 0, 0); dtw->vscrollbar_box = gtk_vbox_new (FALSE, 0); @@ -476,9 +476,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->vscrollbar, TRUE, TRUE, 0); #if GTK_CHECK_VERSION(3,0,0) - gtk_grid_attach(GTK_GRID(canvas_tbl), dtw->vscrollbar_box, 2, 0, 1, 2); + gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), dtw->vscrollbar_box, 2, 0, 1, 2); #else - gtk_table_attach(GTK_TABLE(canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, + gtk_table_attach(GTK_TABLE(dtw->canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, GTK_SHRINK, GTK_FILL, 0, 0); #endif @@ -514,9 +514,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #if GTK_CHECK_VERSION(3,0,0) - gtk_grid_attach( GTK_GRID(canvas_tbl), dtw->cms_adjust, 2, 2, 1, 1); + gtk_grid_attach( GTK_GRID(dtw->canvas_tbl), dtw->cms_adjust, 2, 2, 1, 1); #else - gtk_table_attach( GTK_TABLE(canvas_tbl), dtw->cms_adjust, 2, 3, 2, 3, + gtk_table_attach( GTK_TABLE(dtw->canvas_tbl), dtw->cms_adjust, 2, 3, 2, 3, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_SHRINK), 0, 0); @@ -560,9 +560,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) #if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(dtw->canvas), TRUE); - gtk_grid_attach(GTK_GRID(canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 1, 1, 1); + gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 1, 1, 1); #else - gtk_table_attach (GTK_TABLE (canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0); + gtk_table_attach (GTK_TABLE (dtw->canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0); #endif /* Dock */ @@ -579,7 +579,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) Gtk::HPaned *paned = new Gtk::HPaned(); #endif - paned->pack1(*Glib::wrap(canvas_tbl)); + paned->pack1(*Glib::wrap(dtw->canvas_tbl)); paned->pack2(dtw->dock->getWidget(), Gtk::FILL); /* Prevent the paned from catching F6 and F8 by unsetting the default callbacks */ @@ -599,11 +599,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) } else { #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_hexpand(GTK_WIDGET(canvas_tbl), TRUE); - gtk_widget_set_vexpand(GTK_WIDGET(canvas_tbl), TRUE); - gtk_grid_attach(GTK_GRID(tbl), GTK_WIDGET (canvas_tbl), 1, 1, 1, 1); + gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas_tbl), TRUE); + gtk_widget_set_vexpand(GTK_WIDGET(dtw->canvas_tbl), TRUE); + gtk_grid_attach(GTK_GRID(tbl), GTK_WIDGET (dtw->canvas_tbl), 1, 1, 1, 1); #else - gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (dtw->canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); #endif } @@ -762,7 +762,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) // Ensure that ruler ranges are updated correctly whenever the canvas table // is resized - g_signal_connect (G_OBJECT (canvas_tbl), + g_signal_connect (G_OBJECT (dtw->canvas_tbl), "size-allocate", G_CALLBACK (canvas_tbl_size_allocate), dtw); @@ -787,6 +787,8 @@ static void sp_desktop_widget_dispose(GObject *object) g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_value_changed), dtw); g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_populate_popup), dtw); g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->canvas), (gpointer) G_CALLBACK (sp_desktop_widget_event), dtw); + g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->canvas_tbl), (gpointer) G_CALLBACK (canvas_tbl_size_allocate), dtw); + dtw->layer_selector->setDesktop(NULL); dtw->layer_selector->unreference(); diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index dedda7123..0ffedd112 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -105,7 +105,11 @@ struct SPDesktopWidget { unsigned int _interaction_disabled_counter; - SPCanvas *canvas; + SPCanvas *canvas; + + /** A table for displaying the canvas, rulers etc */ + GtkWidget *canvas_tbl; + Geom::Point ruler_origin; double dt2r; -- cgit v1.2.3 From 25d130b355b637193ee24937c7f287acf6dfa7d5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 31 Jan 2013 15:04:28 +0100 Subject: Partial fix for bug 595432 "Clicking Arial Black selects Arial Bold" (bzr r12080) --- src/libnrtype/FontFactory.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 98904a47a..af46d6986 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -454,7 +454,7 @@ Glib::ustring font_factory::ReplaceFontSpecificationFamily(const Glib::ustring & // what constitutes a "family" in our own UI may be different from how Pango // sees it. - // Find the PangoFontDescription associated with the font specification string. + // Find the PangoFontDescription associated with the old font specification string. PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec); @@ -464,15 +464,23 @@ Glib::ustring font_factory::ReplaceFontSpecificationFamily(const Glib::ustring & // Make copy PangoFontDescription *descr = pango_font_description_copy((*it).second); - // Grab the UI Family string from the descr + // Grab the old UI Family string from the descr Glib::ustring uiFamily = GetUIFamilyString(descr); // Replace the UI Family name with the new family name std::size_t found = fontSpec.find(uiFamily); if (found != Glib::ustring::npos) { + + // Add comma to end of newFamily... commas at end don't hurt but are + // required if the last part of a family name is a valid font style + // (e.g. "Arial Black"). + Glib::ustring newFamilyComma = newFamily; + if( *newFamilyComma.rbegin() != ',' ) { + newFamilyComma += ","; + } newFontSpec = fontSpec; newFontSpec.erase(found, uiFamily.size()); - newFontSpec.insert(found, newFamily); + newFontSpec.insert(found, newFamilyComma); // If the new font specification does not exist in the reference maps, // search for the next best match for the faces in that style @@ -716,6 +724,7 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map) FamilyToStylesMap::iterator iter = map->find(familyUIName); + // Insert new family if (iter == map->end()) { map->insert(std::make_pair(familyUIName, std::list())); } -- cgit v1.2.3 From baa52078f68c3c07e4e88447b4808d8bb791332b Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 31 Jan 2013 17:52:48 +0100 Subject: Partial fix to allow change of style when the font-family is a font list. (bzr r12081) --- src/libnrtype/FontFactory.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index af46d6986..2cf4b8673 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -824,7 +824,12 @@ font_instance* font_factory::FaceFromUIStrings(char const *uiFamily, char const g_assert(uiFamily && uiStyle); if (uiFamily && uiStyle) { - Glib::ustring uiString = Glib::ustring(uiFamily) + Glib::ustring(uiStyle); + + // If font list, take only first font in list + gchar** tokens = g_strsplit( uiFamily, ",", 0 ); + g_strstrip( tokens[0] ); + + Glib::ustring uiString = Glib::ustring(tokens[0]) + Glib::ustring(uiStyle); UIStringToPangoStringMap::iterator uiToPangoIter = fontStringMap.find(uiString); -- cgit v1.2.3 From 6a597dc85342abf8c88a5b4f1ba99d50589f64ef Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 31 Jan 2013 19:35:26 +0100 Subject: Text toolbar will display style options for the first font in a font-family list. Also, fix mem leak. (bzr r12082) --- src/libnrtype/FontFactory.cpp | 2 ++ src/widgets/text-toolbar.cpp | 7 +++++++ 2 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 2cf4b8673..fdb02aa0f 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -831,6 +831,8 @@ font_instance* font_factory::FaceFromUIStrings(char const *uiFamily, char const Glib::ustring uiString = Glib::ustring(tokens[0]) + Glib::ustring(uiStyle); + g_strfreev( tokens ); + UIStringToPangoStringMap::iterator uiToPangoIter = fontStringMap.find(uiString); if (uiToPangoIter != fontStringMap.end ()) { diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 6c22c81e3..1f60c6214 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -178,6 +178,11 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) return; } + // If font list, take only first font in list + gchar** tokens = g_strsplit( current_font, ",", 0 ); + g_strstrip( tokens[0] ); + current_font = tokens[0]; + // Get an iter to the selected font from the model data // We cant get it from the combo, cause it might not have been created yet gboolean found = false; @@ -197,6 +202,8 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) valid = gtk_tree_model_iter_next( model, &iter ); } + g_strfreev( tokens ); + if (!found) { return; } -- cgit v1.2.3 From 71b23adf38b7d0cdc586327214ddb363f60af994 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 31 Jan 2013 21:55:46 +0000 Subject: Clean up Cairo rendering in a couple of widgets (bzr r12083) --- src/ui/dialog/filter-effects-dialog.cpp | 29 ++++------------ src/widgets/sp-color-slider.cpp | 59 ++++++++++----------------------- 2 files changed, 25 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 418132abb..50f30e8f4 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1730,8 +1730,6 @@ bool FilterEffectsDialog::PrimitiveList::on_draw_signal(const Cairo::RefPtrsave(); -#if GTK_CHECK_VERSION(3,0,0) - gdk_cairo_set_source_rgba(cr->cobj(), &black); -#else - gdk_cairo_set_source_color(cr->cobj(), &(style->black)); -#endif + cr->set_source_rgb(0.0, 0.0, 0.0); cr->move_to(outline_x, con_drag_y); cr->line_to(mx, con_drag_y); cr->line_to(mx, my); @@ -1936,8 +1930,6 @@ void FilterEffectsDialog::PrimitiveList::draw_connection(const Cairo::RefPtrcobj(), &mid_color); - else - gdk_cairo_set_source_rgba(cr->cobj(), &black); +#if GTK_CHECK_VERSION(3,0,0) + gdk_cairo_set_source_rgba(cr->cobj(), &mid_color); #else - if(use_default && is_first) - gdk_cairo_set_source_color(cr->cobj(), &(style->dark[GTK_STATE_NORMAL])); - else - gdk_cairo_set_source_color(cr->cobj(), &(style->black)); + gdk_cairo_set_source_color(cr->cobj(), &(style->dark[GTK_STATE_NORMAL])); #endif + else + cr->set_source_rgb(0.0, 0.0, 0.0); cr->rectangle(end_x-2, y1-2, 5, 5); cr->fill_preserve(); @@ -1993,11 +1982,7 @@ void FilterEffectsDialog::PrimitiveList::draw_connection(const Cairo::RefPtrcobj(), &black); -#else - gdk_cairo_set_source_color(cr->cobj(), &(style->black)); -#endif + cr->set_source_rgb(0.0, 0.0, 0.0); cr->move_to(x1, y1); cr->line_to(x2-fheight/4, y1); cr->line_to(x2, y1-fheight/4); diff --git a/src/widgets/sp-color-slider.cpp b/src/widgets/sp-color-slider.cpp index 37cccda9f..471ee3852 100644 --- a/src/widgets/sp-color-slider.cpp +++ b/src/widgets/sp-color-slider.cpp @@ -642,49 +642,26 @@ static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr) gint x = (int)(slider->value * (carea.width - 1) - ARROW_SIZE / 2 + carea.x); gint y1 = carea.y; gint y2 = carea.y + carea.height - 1; - gint w = ARROW_SIZE; cairo_set_line_width(cr, 1.0); -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA white = {1,1,1,1}; - GdkRGBA black = {0,0,0,1}; -#else - GdkColor white, black; - gdk_color_parse("#fff", &white); - gdk_color_parse("#000", &black); -#endif - - while ( w > 0 ) - { -#if GTK_CHECK_VERSION(3,0,0) - gdk_cairo_set_source_rgba(cr, &white); -#else - gdk_cairo_set_source_color(cr, &white); -#endif - cairo_move_to(cr, x - 0.5, y1 + 0.5); - cairo_line_to(cr, x + w - 1 + 0.5, y1 + 0.5); - cairo_move_to(cr, x - 0.5, y2 + 0.5); - cairo_line_to(cr, x + w - 1 + 0.5, y2 + 0.5); - cairo_stroke(cr); - w -=2; - x++; - if ( w > 0 ) - { -#if GTK_CHECK_VERSION(3,0,0) - gdk_cairo_set_source_rgba(cr, &black); -#else - gdk_cairo_set_source_color(cr, &black); -#endif - cairo_move_to(cr, x - 0.5, y1 + 0.5); - cairo_line_to(cr, x + w - 1 + 0.5, y1 + 0.5); - cairo_move_to(cr, x - 0.5, y2 + 0.5); - cairo_line_to(cr, x + w - 1 + 0.5, y2 + 0.5); - cairo_stroke(cr); - } - y1++; - y2--; - } - + // Define top arrow + cairo_move_to(cr, x - 0.5, y1 + 0.5); + cairo_line_to(cr, x + ARROW_SIZE - 0.5, y1 + 0.5); + cairo_line_to(cr, x + (ARROW_SIZE-1)/2.0, y1 + ARROW_SIZE/2.0 + 0.5); + cairo_line_to(cr, x - 0.5, y1 + 0.5); + + // Define bottom arrow + cairo_move_to(cr, x - 0.5, y2 + 0.5); + cairo_line_to(cr, x + ARROW_SIZE - 0.5, y2 + 0.5); + cairo_line_to(cr, x + (ARROW_SIZE-1)/2.0, y2 - ARROW_SIZE/2.0 + 0.5); + cairo_line_to(cr, x - 0.5, y2 + 0.5); + + // Render both arrows + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + cairo_stroke_preserve(cr); + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_fill(cr); + return FALSE; } -- cgit v1.2.3 From a40122dd68cf8424af1c585f2028a0e52dbaab77 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Thu, 31 Jan 2013 18:40:05 -0500 Subject: Path::OutlineJoin. for inside join, simplify nodes only for obtuse angle (Bug 820425, comment 8) Fixed bugs: - https://launchpad.net/bugs/820425 (bzr r12084) --- src/livarot/PathOutline.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/livarot/PathOutline.cpp b/src/livarot/PathOutline.cpp index 1993a7862..7f8853e31 100644 --- a/src/livarot/PathOutline.cpp +++ b/src/livarot/PathOutline.cpp @@ -1189,11 +1189,15 @@ Path::OutlineJoin (Path * dest, Geom::Point pos, Geom::Point stNor, Geom::Point if ((angSi > 0 && width >= 0) || (angSi < 0 && width < 0)) { // This is an inside join -> join is independent of chosen JoinType. if ((dest->descr_cmd[dest->descr_cmd.size() - 1]->getType() == descr_lineto) && (nType == descr_lineto)) { - PathDescrLineTo* nLine = dynamic_cast(dest->descr_cmd[dest->descr_cmd.size() - 1]); Geom::Point const biss = unit_vector(Geom::rot90( stNor - enNor )); double c2 = Geom::dot (biss, enNor); - double l = width / c2; - nLine->p = pos + l*biss; // relocate to bisector + if (fabs(c2) > 0.707107) { // apply only to obtuse angles + double l = width / c2; + PathDescrLineTo* nLine = dynamic_cast(dest->descr_cmd[dest->descr_cmd.size() - 1]); + nLine->p = pos + l*biss; // relocate to bisector + } else { + dest->LineTo (pos + width*enNor); + } } else { // dest->LineTo (pos); // redundant dest->LineTo (pos + width*enNor); -- cgit v1.2.3 From 5801c9a1acae9403433ff60c8d3e6a02c3abb056 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 1 Feb 2013 15:47:04 +0900 Subject: Fix for 1091582 : Problem when entering space in text after space tool toggling. (bzr r12085) --- src/event-context.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/event-context.cpp b/src/event-context.cpp index 096b310c3..11b814aab 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -712,6 +712,7 @@ static gint sp_event_context_private_root_handler( sp_toggle_selector(desktop); ret = TRUE; } + within_tolerance = false; break; case GDK_KEY_Q: case GDK_KEY_q: -- cgit v1.2.3 From 371a87c6c93385b996261f15901f66bb2c195b9e Mon Sep 17 00:00:00 2001 From: su_v Date: Fri, 1 Feb 2013 13:41:12 +0100 Subject: libcdr, libvisio: fix compiler warnings (comparison between signed and unsigned integer expressions) (bzr r12059.1.7) --- src/extension/internal/cdr-input.cpp | 4 ++-- src/extension/internal/vsd-input.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index 8abf772b8..e6c400fb5 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -185,8 +185,8 @@ unsigned CdrImportDialog::getSelectedPage() void CdrImportDialog::_onPageNumberChanged() { - int page = _pageNumberSpin->get_value_as_int(); - _current_page = CLAMP(page, 1, _vec.size()); + unsigned page = static_cast(_pageNumberSpin->get_value_as_int()); + _current_page = CLAMP(page, 1U, _vec.size()); _setPreviewPage(_current_page); } diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 187318417..12e5150cb 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -185,8 +185,8 @@ unsigned VsdImportDialog::getSelectedPage() void VsdImportDialog::_onPageNumberChanged() { - int page = _pageNumberSpin->get_value_as_int(); - _current_page = CLAMP(page, 1, _vec.size()); + unsigned page = static_cast(_pageNumberSpin->get_value_as_int()); + _current_page = CLAMP(page, 1U, _vec.size()); _setPreviewPage(_current_page); } -- cgit v1.2.3 From 5207a0b3c1c4a4dbb6c7432ad55817fc1e7ed08d Mon Sep 17 00:00:00 2001 From: Ted Janeczko Date: Fri, 1 Feb 2013 19:09:32 +0100 Subject: Fix for Bug #1110397: Opacity of clipped group is ignored (regression) Fixed bugs: - https://launchpad.net/bugs/1110397 (bzr r12086) --- src/display/drawing-item.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 1e6e44d6f..80664d822 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -550,10 +550,12 @@ DrawingItem::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flag // for overlapping clip children. To fix this we use the SOURCE operator // instead of the default OVER. ict.setOperator(CAIRO_OPERATOR_SOURCE); + ict.paint(); if (_clip) { + ict.pushGroup(); _clip->clip(ict, *carea); // fixme: carea or area? - } else { - // if there is no clipping path, fill the entire surface with alpha = opacity. + ict.popGroupToSource(); + ict.setOperator(CAIRO_OPERATOR_IN); ict.paint(); } ict.setOperator(CAIRO_OPERATOR_OVER); // reset back to default -- cgit v1.2.3 From bc5979b0e1e7ab3b9279e8f9ef58255f139937be Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 2 Feb 2013 16:18:34 +0900 Subject: Fix for 1091582 : Problem with key release when pressing space with cursor off canvas. (bzr r12088) --- src/widgets/desktop-widget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 95ac7f949..9e078cabb 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -998,12 +998,13 @@ sp_desktop_widget_event (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dt if (GTK_WIDGET_CLASS (dtw_parent_class)->event) { return (* GTK_WIDGET_CLASS (dtw_parent_class)->event) (widget, event); } else { - // The keypress events need to be passed to desktop handler explicitly, - // because otherwise the event contexts only receive keypresses when the mouse cursor - // is over the canvas. This redirection is only done for keypresses and only if there's no + // The key press/release events need to be passed to desktop handler explicitly, + // because otherwise the event contexts only receive key events when the mouse cursor + // is over the canvas. This redirection is only done for key events and only if there's no // current item on the canvas, because item events and all mouse events are caught // and passed on by the canvas acetate (I think). --bb - if (event->type == GDK_KEY_PRESS && !dtw->canvas->current_item) { + if ((event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE) + && !dtw->canvas->current_item) { return sp_desktop_root_handler (NULL, event, dtw->desktop); } } -- cgit v1.2.3 From b4394b6d2a5db9fe935824c946d8a81333614ae8 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 2 Feb 2013 16:44:07 +0900 Subject: Fix for 1002757 : Regressions with new default font 'sans-serif' (bzr r12089) --- src/libnrtype/FontFactory.cpp | 42 +++++++++++++++++++++++++++++++------ src/libnrtype/FontFactory.h | 3 +++ src/libnrtype/FontInstance.cpp | 4 ++-- src/libnrtype/Layout-TNG-Output.cpp | 4 ++-- src/sp-text.cpp | 2 +- src/ui/dialog/font-substitution.cpp | 2 +- 6 files changed, 45 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index fdb02aa0f..6c95c0363 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -28,7 +28,7 @@ typedef INK_UNORDERED_MAP fontNameMap; + std::map::iterator it; + + fontNameMap.insert(std::make_pair("Sans", "sans-serif")); + fontNameMap.insert(std::make_pair("Serif", "serif")); + fontNameMap.insert(std::make_pair("Monospace", "monospace")); + //fontNameMap.insert(std::make_pair("", "cursive")); + //fontNameMap.insert(std::make_pair("", "fantasy")); + + const char *pangoFamily = pango_font_description_get_family(fontDescr); + + if (pangoFamily && ((it = fontNameMap.find(pangoFamily)) != fontNameMap.end())) { + return ((Glib::ustring)it->second).c_str(); + } + + return pangoFamily; +} + Glib::ustring font_factory::GetUIFamilyString(PangoFontDescription const *fontDescr) { Glib::ustring family; @@ -403,7 +430,8 @@ Glib::ustring font_factory::GetUIFamilyString(PangoFontDescription const *fontDe if (fontDescr) { // For now, keep it as family name taken from pango - const char *pangoFamily = pango_font_description_get_family(fontDescr); + const char *pangoFamily = sp_font_description_get_family(fontDescr); + if( pangoFamily ) { family = pangoFamily; } @@ -719,6 +747,7 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map) Glib::ustring styleUIName = GetUIStyleString(faceDescr); if (!familyUIName.empty() && !styleUIName.empty()) { + // Find the right place to put the style information, adding // a map entry for the family name if it doesn't yet exist @@ -754,6 +783,7 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map) ConstructFontSpecification(faceDescr))); fontInstanceMap.insert( std::make_pair(ConstructFontSpecification(faceDescr), faceDescr)); + } else { pango_font_description_free(faceDescr); } @@ -870,7 +900,7 @@ font_instance* font_factory::FaceFromPangoString(char const *pangoString) descr = pango_font_description_from_string(pangoString); } - if (descr && (pango_font_description_get_family(descr) != NULL)) { + if (descr && (sp_font_description_get_family(descr) != NULL)) { fontInstance = Face(descr); } @@ -918,7 +948,7 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail) // workaround for bug #1025565. // fonts without families blow up Pango. - if (pango_font_description_get_family(descr) != NULL) { + if (sp_font_description_get_family(descr) != NULL) { nFace = pango_font_map_load_font(fontServer,fontContext,descr); } else { diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h index 42f975ab7..12046079e 100644 --- a/src/libnrtype/FontFactory.h +++ b/src/libnrtype/FontFactory.h @@ -54,6 +54,9 @@ struct font_descr_equal : public std::binary_function > FamilyToStylesMap; diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index f26b157da..61225ad0c 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -285,14 +285,14 @@ unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int bool b = (weight >= PANGO_WEIGHT_BOLD); res = g_strdup_printf ("%s%s%s%s", - pango_font_description_get_family(descr), + sp_font_description_get_family(descr), (b || i || o) ? "-" : "", (b) ? "Bold" : "", (i) ? "Italic" : ((o) ? "Oblique" : "") ); free_res = true; } } else if ( strcmp(key,"family") == 0 ) { - res=(char*)pango_font_description_get_family(descr); + res=(char*)sp_font_description_get_family(descr); free_res=false; } else if ( strcmp(key,"style") == 0 ) { PangoStyle v=pango_font_description_get_style(descr); diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index bf746b41f..1d086b57b 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -340,7 +340,7 @@ Glib::ustring Layout::getFontFamily(unsigned span_index) const return ""; if (_spans[span_index].font) { - return pango_font_description_get_family(_spans[span_index].font->descr); + return sp_font_description_get_family(_spans[span_index].font->descr); } return ""; @@ -368,7 +368,7 @@ Glib::ustring Layout::dumpAsText() const snprintf(line, sizeof(line), " in chunk %d (x=%f, baselineshift=%f)\n", _spans[span_index].in_chunk, _chunks[_spans[span_index].in_chunk].left_x, _spans[span_index].baseline_shift); result += line; if (_spans[span_index].font) { - snprintf(line, sizeof(line), " font '%s' %f %s %s\n", pango_font_description_get_family(_spans[span_index].font->descr), _spans[span_index].font_size, style_to_text(pango_font_description_get_style(_spans[span_index].font->descr)), weight_to_text(pango_font_description_get_weight(_spans[span_index].font->descr))); + snprintf(line, sizeof(line), " font '%s' %f %s %s\n", sp_font_description_get_family(_spans[span_index].font->descr), _spans[span_index].font_size, style_to_text(pango_font_description_get_style(_spans[span_index].font->descr)), weight_to_text(pango_font_description_get_weight(_spans[span_index].font->descr))); result += line; } snprintf(line, sizeof(line), " x_start = %f, x_end = %f\n", _spans[span_index].x_start, _spans[span_index].x_end); diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 1b4246483..8d42b7d59 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -384,7 +384,7 @@ static char * sp_text_description(SPItem *item) char name_buf[256]; char *n; if (tf) { - tf->Name(name_buf, sizeof(name_buf)); + tf->Family(name_buf, sizeof(name_buf)); n = xml_quote_strdup(name_buf); tf->Unref(); } else { diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 24588946e..07e73cec8 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -260,7 +260,7 @@ Glib::ustring FontSubstitution::getSubstituteFontName (Glib::ustring font) font_instance *res = (font_factory::Default())->Face(descr); if (res->pFont) { PangoFontDescription *nFaceDesc = pango_font_describe(res->pFont); - out = pango_font_description_get_family(nFaceDesc); + out = sp_font_description_get_family(nFaceDesc); } pango_font_description_free(descr); -- cgit v1.2.3 From fe9078f74cb1dbf160b712408f9c3f2e1ca53f5e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 2 Feb 2013 09:54:40 +0100 Subject: Text-Toolbar font-family entry-box warning-icon tooltip now includes list of missing fonts. (bzr r12090) --- src/ink-comboboxentry-action.cpp | 67 +++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index 8df16ec9a..a28ec4f53 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ static GtkWidget* create_menu_item( GtkAction* action ); // Internal static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text ); -static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action ); +static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ); // Callbacks static void combo_box_changed_cb( GtkComboBox* widget, gpointer data ); @@ -469,10 +470,12 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink gtk_entry_set_text( ink_comboboxentry_action->entry, text ); // Show or hide warning + bool clear = true; if( ink_comboboxentry_action->active == -1 && - ink_comboboxentry_action->warning != NULL && - check_comma_separated_text( ink_comboboxentry_action ) ) { - { + ink_comboboxentry_action->warning != NULL ) { + Glib::ustring missing = check_comma_separated_text( ink_comboboxentry_action ); + if( !missing.empty() ) { + GtkStockItem item; gboolean isStock = gtk_stock_lookup( GTK_STOCK_DIALOG_WARNING, &item ); if (isStock) { @@ -484,15 +487,21 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_DIALOG_WARNING ); } + // Can't add tooltip until icon set + Glib::ustring warning = ink_comboboxentry_action->warning; + warning += ": "; + warning += missing; + gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry, + GTK_ENTRY_ICON_SECONDARY, + warning.c_str() ); + clear = false; } - // Can't add tooltip until icon set - gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry, - GTK_ENTRY_ICON_SECONDARY, - ink_comboboxentry_action->warning ); - } else { + } + + if( clear ) { gtk_entry_set_icon_from_icon_name( GTK_ENTRY(ink_comboboxentry_action->entry), - GTK_ENTRY_ICON_SECONDARY, - NULL ); + GTK_ENTRY_ICON_SECONDARY, + NULL ); gtk_entry_set_icon_from_stock( GTK_ENTRY(ink_comboboxentry_action->entry), GTK_ENTRY_ICON_SECONDARY, NULL ); @@ -631,18 +640,21 @@ gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* ta } -// Checks if all comma separated text fragments are in the list. +// Checks if all comma separated text fragments are in the list and +// returns a ustring with a list of missing fragments. // This is useful for checking if all fonts in a font-family fallback // list are available on the system. -// The return value is set to the number of missing text fragments. +// // This routine could also create a Pango Markup string to show which -// fragments are invalid. -// It is envisioned that one can construct a Pango Markup String here -// so that individual text fragments can be flagged as not being in the -// list. -static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) { +// fragments are invalid in the entry box itself. See: +// http://developer.gnome.org/pango/stable/PangoMarkupFormat.html +// However... it appears that while one can retrieve the PangoLayout +// for a GtkEntry box, it is only a copy and changing it has no effect. +// PangoLayout * pl = gtk_entry_get_layout( entry ); +// pango_layout_set_markup( pl, "NEW STRING", -1 ); // DOESN'T WORK +static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) { - gint ret_val = 0; + Glib::ustring missing; // Parse fallback_list using a comma as deliminator gchar** tokens = g_strsplit( action->text, ",", 0 ); @@ -654,21 +666,18 @@ static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) { g_strstrip( tokens[i] ); if( get_active_row_from_text( action, tokens[i] ) == -1 ) { - ret_val += 1; + missing += tokens[i]; + missing += ", "; } ++i; } g_strfreev( tokens ); - // Pango Markup notes: - // GString* Pango_Markup = g_string_new(""); - // if not present: - // g_string_sprintfa( Pango_Markup, "%s", tokens[i] ); - // PangoLayout * pl = gtk_entry_get_layout( entry ); - // pango_layout_set_markup( pl, Pango_Markup->str, -1 ); - // g_string_free( Pango_Markup, TRUE ); - - return ret_val; + // Remove extra comma and space from end. + if( missing.size() >= 2 ) { + missing.resize( missing.size()-2 ); + } + return missing; } // Callbacks --------------------------------------------------- -- cgit v1.2.3 From 36dd99ae68825bb28b7428f8018fbfdfb003bf36 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 2 Feb 2013 12:29:34 +0100 Subject: cppcheck (bzr r12092) --- src/dom/domimpl.cpp | 34 ++++++++++++++++++-------------- src/dom/domimpl.h | 14 ++++++------- src/dom/events.h | 48 +++++++++++++++++++++++++++++++++++---------- src/dom/io/domstream.h | 11 +++++++++-- src/dom/io/gzipstream.cpp | 2 +- src/dom/lsimpl.cpp | 2 +- src/dom/odf/odfdocument.cpp | 16 ++++++++------- src/dom/smil.h | 28 ++++++++++++++++++-------- src/dom/traversal.h | 18 ++++++++--------- 9 files changed, 113 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/dom/domimpl.cpp b/src/dom/domimpl.cpp index 9f25cb3be..3d9a29592 100644 --- a/src/dom/domimpl.cpp +++ b/src/dom/domimpl.cpp @@ -1701,7 +1701,6 @@ void ElementImpl::normalizeNamespaces() if (attrNode->getNodeType() != Node::ATTRIBUTE_NODE) continue; AttrImplPtr attr = reinterpret_cast(attrNode.get()); - DOMString attrNS = attr->getNamespaceURI(); DOMString attrName = attr->getLocalName(); DOMString attrPrefix = attr->getPrefix(); DOMString attrValue = attr->getNodeValue(); @@ -1826,7 +1825,6 @@ void ElementImpl::normalizeNamespaces() AttrPtr attr = reinterpret_cast(attrNode.get()); DOMString attrNS = attr->getNamespaceURI(); DOMString attrPrefix = attr->getPrefix(); - DOMString attrValue = attr->getNodeValue(); if (attrNS == XMLNSNAME) continue; @@ -2360,12 +2358,15 @@ CDATASectionImpl::~CDATASectionImpl() DocumentTypeImpl::DocumentTypeImpl(const DOMString& theName, const DOMString& thePublicId, const DOMString& theSystemId) - : NodeImpl() + : NodeImpl(), + name(), //what with this variable? + publicId(thePublicId), + systemId(theSystemId), + entities(), + notations() { - nodeType = DOCUMENT_TYPE_NODE; - nodeName = theName; - publicId = thePublicId; - systemId = theSystemId; + nodeType = DOCUMENT_TYPE_NODE;//of class NodeImpl + nodeName = theName;//of class NodeImpl } /** @@ -3017,19 +3018,22 @@ NodePtr DocumentImpl::renameNode(const NodePtr node, DocumentImpl::DocumentImpl(const DOMImplementation *domImpl, const DOMString &/*theNamespaceURI*/, const DOMString &theQualifiedName, - const DocumentTypePtr theDoctype) : NodeImpl() -{ - nodeType = DOCUMENT_NODE; - nodeName = "#document"; - parent = const_cast(domImpl); - //documentURI = stringCache(theNamespaceURI); - qualifiedName = theQualifiedName; + const DocumentTypePtr theDoctype) + : NodeImpl(), + namespaceIndex(0), + parent(const_cast(domImpl)), + qualifiedName(theQualifiedName), + xmlStandalone(false), + strictErrorChecking(false), + domConfig(NULL) +{ + nodeType = DOCUMENT_NODE;//of class NodeImpl + nodeName = "#document";//of class NodeImpl if (theDoctype.get()) //only assign if not null. doctype = theDoctype; else doctype = new DocumentTypeImpl("", "", ""); documentElement = new ElementImpl(this, "root"); - namespaceIndex = 0; } diff --git a/src/dom/domimpl.h b/src/dom/domimpl.h index 5fe508076..df586f35e 100644 --- a/src/dom/domimpl.h +++ b/src/dom/domimpl.h @@ -526,11 +526,11 @@ protected: UserDataEntry(const DOMString &theKey, const DOMUserData *theData, const UserDataHandler *theHandler) + : next(NULL), + key(theKey), + data(const_cast(theData)), + handler(const_cast(theHandler)) { - next = NULL; - key = theKey; - data = const_cast(theData); - handler = const_cast(theHandler); } virtual ~UserDataEntry() @@ -1967,10 +1967,10 @@ protected: next = NULL; } NamedElementItem(const DOMString &nameArg, ElementPtr elemArg) + : next (NULL), + name (nameArg), + elem (elemArg) { - next = NULL; - name = nameArg; - elem = elemArg; } ~NamedElementItem() { diff --git a/src/dom/events.h b/src/dom/events.h index 9f44fe591..59d83afcf 100644 --- a/src/dom/events.h +++ b/src/dom/events.h @@ -643,8 +643,8 @@ public: * */ EventTarget(const EventTarget &other) + : listeners (other.listeners) { - listeners = other.listeners; } /** @@ -704,7 +704,9 @@ public: /** * */ - DocumentEvent() {} + DocumentEvent() + : dispatchable(false) + {} /** * @@ -791,7 +793,10 @@ public: /** * */ - CustomEvent() {} + CustomEvent() + : propagationStopped(false), + immediatePropagationStopped(false) + {} /** * @@ -884,15 +889,19 @@ public: /** * */ - UIEvent() {} + UIEvent() + : view(), + detail(0) + {} /** * */ - UIEvent(const UIEvent &other) : Event(other) + UIEvent(const UIEvent &other) + : Event(other), + view(other.view), + detail(other.detail) { - view = other.view; - detail = other.detail; } /** @@ -1152,7 +1161,18 @@ public: /** * */ - MouseEvent() {} + MouseEvent() + : screenX(0), + screenY(0), + clientX(0), + clientY(0), + ctrlKey(false), + shiftKey(false), + altKey(false), + metaKey(false), + button(0), + relatedTarget(NULL) + {} /** * @@ -1322,7 +1342,14 @@ public: /** * */ - KeyboardEvent() {} + KeyboardEvent() + : keyIdentifier(), + keyLocation(0), + ctrlKey(false), + shiftKey(false), + altKey(false), + metaKey(false) + {} /** * @@ -1472,8 +1499,9 @@ public: * */ MutationEvent() + : relatedNodePtr (NULL), + attrChange(0) { - relatedNodePtr = NULL; } /** diff --git a/src/dom/io/domstream.h b/src/dom/io/domstream.h index b2e308653..1a93e73b2 100644 --- a/src/dom/io/domstream.h +++ b/src/dom/io/domstream.h @@ -51,7 +51,8 @@ class StreamException public: StreamException(const DOMString &theReason) throw() - { reason = theReason; } + : reason(theReason) + {} virtual ~StreamException() throw() { } char const *what() @@ -576,7 +577,13 @@ protected: Writer *destination; BasicWriter() - { destination = NULL; } + { + destination = NULL; + for(int k=0;k<2048;++k) + { + formatBuf[k]=0; + } + } //Used for printf() or other things that might //require formatting before sending down the stream diff --git a/src/dom/io/gzipstream.cpp b/src/dom/io/gzipstream.cpp index e1f9f9a60..2a2f8a5b5 100644 --- a/src/dom/io/gzipstream.cpp +++ b/src/dom/io/gzipstream.cpp @@ -188,7 +188,7 @@ void GzipOutputStream::close() */ void GzipOutputStream::flush() { - if (closed || buffer.size()<1) + if (closed || buffer.empty()) return; std::vector compBuf; diff --git a/src/dom/lsimpl.cpp b/src/dom/lsimpl.cpp index 94b0adeb7..d4da0d5ce 100644 --- a/src/dom/lsimpl.cpp +++ b/src/dom/lsimpl.cpp @@ -227,7 +227,7 @@ bool LSSerializerImpl::writeToURI(const NodePtr nodeArg, DOMString uri = uriArg; char *fileName = (char *) uri.c_str(); //temporary hack - FILE *f = fopen(fileName, "rb"); + FILE *f = fopen(fileName, "wb"); if (!f) return false; for (unsigned int i=0 ; i &buf) + : fileName (fname), + data (buf) + { - fileName = fname; - data = buf; } /** * */ ImageData::ImageData(const ImageData &other) + : fileName (other.fileName), + data (other.data) + { - fileName = other.fileName; - data = other.data; } /** @@ -120,10 +122,10 @@ OdfDocument::OdfDocument() : /** * */ -OdfDocument::OdfDocument(const OdfDocument &other) +OdfDocument::OdfDocument(const OdfDocument &other) : + content (other.content), + images (other.images) { - content = other.content; - images = other.images; } diff --git a/src/dom/smil.h b/src/dom/smil.h index 15bc361ac..14870a4e4 100644 --- a/src/dom/smil.h +++ b/src/dom/smil.h @@ -193,7 +193,12 @@ public: /** * */ - ElementLayout() {} + ElementLayout() : + title(), + backgroundColor(), + height(0), + width(0) + {} /** * @@ -274,8 +279,9 @@ public: /** * */ - SMILRegionInterface(const SMILRegionInterface &other) - { regionElement = other.regionElement; } + SMILRegionInterface(const SMILRegionInterface &other) : + regionElement (other.regionElement) + {} /** * @@ -542,9 +548,9 @@ public: /** * */ - TimeList(const TimeList &other) + TimeList(const TimeList &other) : + items (other.items) { - items = other.items; } /** @@ -1586,7 +1592,15 @@ public: /** * */ - ElementTest() + ElementTest() : + systemBitrate (0), + systemCaptions (false), + systemLanguage (), + systemRequired (false), + systemScreenSize (false), + systemScreenDepth (false), + systemOverdubOrSubtitle (), + systemAudioDesc (false) { } @@ -1629,8 +1643,6 @@ public: protected: - - long systemBitrate; bool systemCaptions; DOMString systemLanguage; diff --git a/src/dom/traversal.h b/src/dom/traversal.h index 13850f78e..302ac2b1f 100644 --- a/src/dom/traversal.h +++ b/src/dom/traversal.h @@ -295,11 +295,11 @@ public: /** * */ - NodeIterator(const NodeIterator &other) + NodeIterator(const NodeIterator &other) : + whatToShow (other.whatToShow), + filter (other.filter), + expandEntityReferences (other.expandEntityReferences) { - whatToShow = other.whatToShow; - filter = other.filter; - expandEntityReferences = other.expandEntityReferences; } /** @@ -499,12 +499,12 @@ public: /** * */ - TreeWalker(const TreeWalker &other) + TreeWalker(const TreeWalker &other) : + whatToShow (other.whatToShow), + filter (other.filter), + expandEntityReferences (other.expandEntityReferences), + currentNode (other.currentNode) { - whatToShow = other.whatToShow; - filter = other.filter; - expandEntityReferences = other.expandEntityReferences; - currentNode = other.currentNode; } /** -- cgit v1.2.3 From c84cc8045be0f7374f0668df62b4f34ef8b9df9c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 2 Feb 2013 13:15:56 +0100 Subject: Allow simple font style changes even if first font-family in font list is not on users system. (bzr r12093) --- src/widgets/text-toolbar.cpp | 53 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 1f60c6214..9fdc1ea7b 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -204,14 +204,6 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) g_strfreev( tokens ); - if (!found) { - return; - } - - // Get the list of styles from the selected font - GList *list = NULL; - gtk_tree_model_get (model, &iter, 1, &list, -1); - Ink_ComboBoxEntry_Action* fontStyleAction = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontStyleAction" ) ); gchar *current_style = ink_comboboxentry_action_get_active_text( fontStyleAction ); @@ -219,11 +211,30 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) GtkListStore *store = GTK_LIST_STORE( ink_comboboxentry_action_get_model( fontStyleAction ) ); gtk_list_store_clear ( store ); - // Add list of styles to the style combo - for (GList *l=list; l; l = l->next) - { + // Get the list of styles from the selected font + GList *list = NULL; + + if (found) { + + // Add list of styles to the style combo + gtk_tree_model_get (model, &iter, 1, &list, -1); + for (GList *l=list; l; l = l->next) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); + } + + } else { + + // Create generic list if selected font-family not available on system + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Normal", -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Italic", -1); + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Bold", -1); gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); + gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); } // Select the style in the combo that best matches font @@ -526,7 +537,7 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj SPCSSAttr *css = sp_repr_css_attr_new (); - gchar *current_style = ink_comboboxentry_action_get_active_text( act ); + Glib::ustring current_style = ink_comboboxentry_action_get_active_text( act ); Glib::ustring fontFamily = ""; if (query->text->font_family.set) { @@ -537,9 +548,10 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj fontFamily = ink_comboboxentry_action_get_active_text( act ); } - font_instance *font = (font_factory::Default())->FaceFromUIStrings (fontFamily.c_str(), current_style); + font_instance *font = (font_factory::Default())->FaceFromUIStrings (fontFamily.c_str(), current_style.c_str()); if (font) { + gchar c[256]; font->Attribute( "weight", c, 256); @@ -556,6 +568,19 @@ static void sp_text_fontstyle_value_changed( Ink_ComboBoxEntry_Action *act, GObj font->Unref(); font = NULL; + + } else { + + // Font not found on system, blindly update style + // Options match choices in sp_text_fontstyle_populate + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "font-style", "normal" ); + if( current_style.find("Bold") != Glib::ustring::npos ) { + sp_repr_css_set_property (css, "font-weight", "bold"); + } + if( current_style.find("Italic") != Glib::ustring::npos ) { + sp_repr_css_set_property (css, "font-style", "italic"); + } } // If querying returned nothing, update default style. -- cgit v1.2.3 From c37431c37889fed55de3b8c76a0dc0569f0fe42d Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 3 Feb 2013 19:37:58 +0100 Subject: fix crash Fixed bugs: - https://launchpad.net/bugs/1114243 (bzr r12094) --- src/widgets/font-selector.cpp | 4 ++++ src/widgets/text-toolbar.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index b17dcf470..0f0e27746 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -442,6 +442,10 @@ GtkWidget *sp_font_selector_new() */ unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) { + if ( !font || !list) { + return 0; + } + font_instance *tempFont = NULL; unsigned int currentStyleNumber = 0; unsigned int bestStyleNumber = 0; diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 9fdc1ea7b..f9921864c 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -238,7 +238,7 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) } // Select the style in the combo that best matches font - if (font) { + if (font && list) { unsigned int index = sp_font_selector_get_best_style(font, list); -- cgit v1.2.3 From 61eb37a18f652117804d6e3a890ebde5959be214 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 3 Feb 2013 19:40:00 +0100 Subject: add todo comment for fixing fontstyle fall-back behaviour (bzr r12095) --- src/widgets/text-toolbar.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index f9921864c..060bb4a80 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -235,6 +235,8 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) gtk_list_store_set (store, &iter, 0, "Bold", -1); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); + + /// \todo \c list should be initialized here with "Normal", "Italic", etc too } // Select the style in the combo that best matches font -- cgit v1.2.3 From 04ba54c3e2586155cef3421ef2a9b27565a8dbe7 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 4 Feb 2013 10:33:03 +0900 Subject: Fix for 1002757 : Regressions with new default font 'sans-serif' - fix map (bzr r12096) --- src/libnrtype/FontFactory.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 6c95c0363..a9220d867 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -407,11 +407,11 @@ const char *sp_font_description_get_family(PangoFontDescription const *fontDescr static std::map fontNameMap; std::map::iterator it; - fontNameMap.insert(std::make_pair("Sans", "sans-serif")); - fontNameMap.insert(std::make_pair("Serif", "serif")); - fontNameMap.insert(std::make_pair("Monospace", "monospace")); - //fontNameMap.insert(std::make_pair("", "cursive")); - //fontNameMap.insert(std::make_pair("", "fantasy")); + if (fontNameMap.empty()) { + fontNameMap.insert(std::make_pair("Sans", "sans-serif")); + fontNameMap.insert(std::make_pair("Serif", "serif")); + fontNameMap.insert(std::make_pair("Monospace", "monospace")); + } const char *pangoFamily = pango_font_description_get_family(fontDescr); -- cgit v1.2.3 From 2c7d2b2cd8f2571cc65d2ba7ac628bb8b43e5c7a Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Feb 2013 10:47:19 +0100 Subject: Better fix for 1114243, crash on launch with default prefs from stable (bzr r12097) --- src/widgets/text-toolbar.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 060bb4a80..dc4a6be27 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -211,32 +211,31 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) GtkListStore *store = GTK_LIST_STORE( ink_comboboxentry_action_get_model( fontStyleAction ) ); gtk_list_store_clear ( store ); - // Get the list of styles from the selected font + // Get the list of styles from the selected font. GList *list = NULL; if (found) { - // Add list of styles to the style combo + // Use precompiled list if font-family on system. gtk_tree_model_get (model, &iter, 1, &list, -1); - for (GList *l=list; l; l = l->next) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); - } } else { - // Create generic list if selected font-family not available on system - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Normal", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Italic", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Bold", -1); - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "Bold Italic", -1); + // Use generic list if font-family not on system. + static GList *glist = NULL; + if( glist == NULL ) { + glist = g_list_append (glist, (void*)"Normal"); + glist = g_list_append (glist, (void*)"Italic"); + glist = g_list_append (glist, (void*)"Bold"); + glist = g_list_append (glist, (void*)"Bold Italic"); + } + list = glist; + } - /// \todo \c list should be initialized here with "Normal", "Italic", etc too + for (GList *l=list; l; l = l->next) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, (char*)l->data, -1); } // Select the style in the combo that best matches font -- cgit v1.2.3 From 048beb0d69537f56f6b662830356553e469a4259 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Feb 2013 19:54:53 +0100 Subject: Only set up text-tool bar if has actually been created. Ensures proper initialization after creation. (bzr r12099) --- src/widgets/text-toolbar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index dc4a6be27..6adff8bfb 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1173,6 +1173,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ std::cout << selected_text << std::endl; #endif + // Check if the toolbar has been created; quit if it has not. + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + if( fontFamilyAction->combobox == NULL ) { + return; + } + // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { #ifdef DEBUG_TEXT -- cgit v1.2.3 From cf9a08aa62dae3bc0d48a5926d9d21583d9492e2 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 5 Feb 2013 19:04:03 +0100 Subject: Build. Adding test for external GDL build (--enable-gtk3-experimental option). (bzr r12100) --- src/ui/dialog/export.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index f267c5ae9..ecdfd3346 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -63,7 +63,12 @@ #include "helper/png-write.h" +#if WITH_EXT_GDL +#include +#else #include "libgdl/gdl-dock-item.h" +#endif + // required to set status message after export #include "desktop.h" -- cgit v1.2.3 From f7810c8932b5097aebb9c1b11e346d1a56b4a11e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 5 Feb 2013 19:45:34 +0100 Subject: Second try at getting text toolbar properly initialized when there is no prefs file. (bzr r12101) --- src/widgets/text-toolbar.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 6adff8bfb..3eccf1d2f 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1173,13 +1173,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ std::cout << selected_text << std::endl; #endif - // Check if the toolbar has been created; quit if it has not. - Ink_ComboBoxEntry_Action* fontFamilyAction = - INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); - if( fontFamilyAction->combobox == NULL ) { - return; - } - // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { #ifdef DEBUG_TEXT @@ -1243,7 +1236,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ return; } - g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + // To ensure the value of the combobox is properly set on start-up, only mark + // the prefs set if the combobox has already been constructed. + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + if( fontFamilyAction->combobox != NULL ) { + g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + } } else { g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE)); } -- cgit v1.2.3 From 634a9ec8e118dc3a2c1decbca6a82e8a4600508c Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 5 Feb 2013 21:33:13 +0100 Subject: Win32. Fixing Glib and GTKmm deprecations. (bzr r12102) --- src/ui/dialog/filedialogimpl-win32.cpp | 22 +++++++++++++++++++++- src/ui/dialog/filedialogimpl-win32.h | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp index 6425d9fee..496836c4d 100644 --- a/src/ui/dialog/filedialogimpl-win32.cpp +++ b/src/ui/dialog/filedialogimpl-win32.cpp @@ -26,6 +26,9 @@ #include #include #include +#if GLIB_CHECK_VERSION(2,32,0) +#include +#endif #include //Inkscape includes @@ -133,7 +136,11 @@ FileDialogBaseWin32::FileDialogBaseWin32(Gtk::Window &parent, Glib::RefPtr parentWindow = parent.get_window(); g_assert(parentWindow->gobj() != NULL); +#if WITH_GTKMM_3_0 + _ownerHwnd = (HWND)gdk_win32_window_get_handle((GdkWindow*)parentWindow->gobj()); +#else _ownerHwnd = (HWND)gdk_win32_drawable_get_handle((GdkDrawable*)parentWindow->gobj()); +#endif } FileDialogBaseWin32::~FileDialogBaseWin32() @@ -1576,16 +1583,23 @@ FileOpenDialogImplWin32::show() // We can only run one worker thread at a time if(_mutex != NULL) return false; +#if !GLIB_CHECK_VERSION(2,32,0) if(!Glib::thread_supported()) Glib::thread_init(); +#endif _result = false; _finished = false; _file_selected = false; - _mutex = new Glib::Mutex(); _main_loop = g_main_loop_new(g_main_context_default(), FALSE); +#if GLIB_CHECK_VERSION(2,32,0) + _mutex = new Glib::Threads::Mutex(); + if(Glib::Threads::Thread::create(sigc::mem_fun(*this, &FileOpenDialogImplWin32::GetOpenFileName_thread))) +#else + _mutex = new Glib::Mutex(); if(Glib::Thread::create(sigc::mem_fun(*this, &FileOpenDialogImplWin32::GetOpenFileName_thread), true)) +#endif { while(1) { @@ -1870,15 +1884,21 @@ void FileSaveDialogImplWin32::GetSaveFileName_thread() bool FileSaveDialogImplWin32::show() { +#if !GLIB_CHECK_VERSION(2,32,0) if(!Glib::thread_supported()) Glib::thread_init(); +#endif _result = false; _main_loop = g_main_loop_new(g_main_context_default(), FALSE); if(_main_loop != NULL) { +#if GLIB_CHECK_VERSION(2,32,0) + if(Glib::Threads::Thread::create(sigc::mem_fun(*this, &FileSaveDialogImplWin32::GetSaveFileName_thread))) +#else if(Glib::Thread::create(sigc::mem_fun(*this, &FileSaveDialogImplWin32::GetSaveFileName_thread), true)) +#endif g_main_loop_run(_main_loop); if(_result && _extension) diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index 15953f9d8..e9d8829f7 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -226,7 +226,11 @@ private: /// This mutex is used to ensure that the worker thread /// that calls GetOpenFileName cannot collide with the /// main Inkscape thread +#if GLIB_CHECK_VERSION(2,32,0) + Glib::Threads::Mutex *_mutex; +#else Glib::Mutex *_mutex; +#endif /// The controller function for the thread which calls -- cgit v1.2.3 From 39e5510c9bed6a057db554fbcfd2e4b77aea1d76 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 5 Feb 2013 21:50:41 +0100 Subject: Supress Pango error message. (bzr r12103) --- src/widgets/font-selector.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 0f0e27746..b0b4b5504 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -466,7 +466,9 @@ unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) tempFont = NULL; } - pango_font_description_unset_fields(bestMatchForFont, PANGO_FONT_MASK_SIZE); + if( bestMatchForFont != NULL ) { + pango_font_description_unset_fields(bestMatchForFont, PANGO_FONT_MASK_SIZE); + } list = list->next; -- cgit v1.2.3 From aeabdef63219b5369907c767f692e929013c3507 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 6 Feb 2013 10:07:00 +0100 Subject: Add fonts (and font-lists) used in document to top of Text tool-bar font-family drop-down menu. If font is not on system, draws strikethrough on top of font name. (bzr r12104) --- src/ink-comboboxentry-action.cpp | 34 +++++-- src/libnrtype/font-lister.cpp | 2 +- src/libnrtype/font-lister.h | 5 + src/widgets/text-toolbar.cpp | 213 +++++++++++++++++++++++++++++++++++---- 4 files changed, 224 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index a28ec4f53..78becbd53 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -37,7 +37,7 @@ static GtkWidget* create_tool_item( GtkAction* action ); static GtkWidget* create_menu_item( GtkAction* action ); // Internal -static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text ); +static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude = false ); static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ); // Callbacks @@ -611,8 +611,11 @@ void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* actio // Internal --------------------------------------------------- -// Return row of active text or -1 if not found. -gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text ) { +// Return row of active text or -1 if not found. If exclude is true, +// use 3d colunm if available to exclude row from checking (useful to +// skip rows added for font-families included in doc and not on +// system) +gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude ) { // Check if text in list gint row = 0; @@ -621,15 +624,24 @@ gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* ta gboolean valid = gtk_tree_model_get_iter_first( action->model, &iter ); while ( valid ) { - // Get text from list entry - gchar* text = 0; - gtk_tree_model_get( action->model, &iter, 0, &text, -1 ); // Column 0 + // See if we should exclude a row + gboolean check = true; // If true, font-family is on system. + if( exclude && gtk_tree_model_get_n_columns( action->model ) > 2 ) { + gtk_tree_model_get( action->model, &iter, 2, &check, -1 ); + } + + if( check ) { + // Get text from list entry + gchar* text = 0; + gtk_tree_model_get( action->model, &iter, 0, &text, -1 ); // Column 0 - // Check for match - if( strcmp( target_text, text ) == 0 ){ - found = true; - break; + // Check for match + if( strcmp( target_text, text ) == 0 ){ + found = true; + break; + } } + ++row; valid = gtk_tree_model_iter_next( action->model, &iter ); } @@ -665,7 +677,7 @@ static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* actio // Remove any surrounding white space. g_strstrip( tokens[i] ); - if( get_active_row_from_text( action, tokens[i] ) == -1 ) { + if( get_active_row_from_text( action, tokens[i], true ) == -1 ) { missing += tokens[i]; missing += ", "; } diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 710e0b84f..6df576866 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -52,7 +52,7 @@ namespace Inkscape } (*treeModelIter)[FontList.styles] = styles; - + (*treeModelIter)[FontList.onSystem] = true; font_list_store_iter_map.insert(std::make_pair(familyName, Gtk::TreePath(treeModelIter))); } } diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index c9ab7b21d..7a7db5615 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -54,10 +54,15 @@ namespace Inkscape */ Gtk::TreeModelColumn styles; + /** Column containing flag if font is on system + */ + Gtk::TreeModelColumn onSystem; + FontListClass () { add (font); add (styles); + add (onSystem); } }; diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 3eccf1d2f..8b3612db4 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -18,7 +18,7 @@ * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2013 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -39,6 +39,7 @@ #include "../desktop-handles.h" #include "../desktop-style.h" #include "document-undo.h" +#include "../sp-root.h" #include "../verbs.h" #include "../inkscape.h" #include "../connection-pool.h" @@ -105,6 +106,10 @@ static void sp_print_font( SPStyle *query ) { << " FontSpec: " << (query->text->font_specification.value ? query->text->font_specification.value : "No value") << std::endl; + std::cout << " LineHeight: " << query->line_height.computed + << " WordSpacing: " << query->word_spacing.computed + << " LetterSpacing: " << query->letter_spacing.computed + << std::endl; } static void sp_print_fontweight( SPStyle *query ) { @@ -128,40 +133,88 @@ static void sp_print_fontstyle( SPStyle *query ) { } #endif +void sp_text_toolbox_get_font_list_in_doc (SPObject *r, std::list *l); +void sp_text_toolbox_update_font_list( GtkListStore* model ); + // Format family drop-down menu. static void cell_data_func(GtkCellLayout * /*cell_layout*/, GtkCellRenderer *cell, - GtkTreeModel *tree_model, + GtkTreeModel *model, GtkTreeIter *iter, gpointer /*data*/) { gchar *family; - gtk_tree_model_get(tree_model, iter, 0, &family, -1); - gchar *const family_escaped = g_markup_escape_text(family, -1); + gboolean onSystem = false; + gtk_tree_model_get(model, iter, 0, &family, 2, &onSystem, -1); + Glib::ustring family_escaped = g_markup_escape_text(family, -1); + g_free(family); + Glib::ustring markup; + + if( !onSystem ) { + markup = ""; + + /* See if font-family on system */ + std::vector tokens = Glib::Regex::split_simple("\\s*,\\s*", family_escaped ); + for( size_t i=0; i < tokens.size(); ++i ) { + + Glib::ustring token = tokens[i]; + + GtkTreeIter iter; + gboolean valid; + gchar *family = 0; + gboolean onSystem = true; + gboolean found = false; + for( valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter ); + valid; + valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ) ) { + + gtk_tree_model_get(model, &iter, 0, &family, 2, &onSystem, -1); + if( onSystem && token.compare( family ) == 0 ) { + found = true; + break; + } + } + if( found ) { + markup += g_markup_escape_text(token.c_str(), -1); + markup += ", "; + } else { + markup += ""; + markup += g_markup_escape_text(token.c_str(), -1); + markup += ""; + markup += ", "; + } + } + // Remove extra comma and space from end. + if( markup.size() >= 2 ) { + markup.resize( markup.size()-2 ); + } + markup += ""; + // std::cout << markup << std::endl; + } else { + markup = family_escaped; + } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1); if (show_sample) { Glib::ustring sample = prefs->getString("/tools/text/font_sample"); - gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1); - - std::stringstream markup; - markup << family_escaped << " " << sample_escaped << ""; - g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL); + Glib::ustring sample_escaped = g_markup_escape_text(sample.data(), -1); - g_free(sample_escaped); - } else { - g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL); + markup += " "; + markup += sample_escaped; + markup += ""; } + + g_object_set (G_OBJECT (cell), "markup", markup.c_str(), NULL); + // This doesn't work for two reasons... it set both selected and not selected backgrounds // to white.. which means that white foreground text is invisible. It also only effects // the text region, leaving the padding untouched. // g_object_set (G_OBJECT (cell), "cell-background", "white", "cell-background-set", true, NULL); - g_free(family); - g_free(family_escaped); } /* @@ -256,7 +309,6 @@ static void sp_text_fontstyle_populate(GObject *tbl, font_instance *font=NULL) } else if (current_style) { ink_comboboxentry_action_set_active_text( fontStyleAction, current_style ); } - } // Font family @@ -1184,6 +1236,14 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + // Update font list, but only if widget already created. + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + if( fontFamilyAction->combobox != NULL ) { + sp_text_toolbox_update_font_list( GTK_LIST_STORE(ink_comboboxentry_action_get_model(fontFamilyAction)) ); + } + + // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; @@ -1238,8 +1298,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // To ensure the value of the combobox is properly set on start-up, only mark // the prefs set if the combobox has already been constructed. - Ink_ComboBoxEntry_Action* fontFamilyAction = - INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); if( fontFamilyAction->combobox != NULL ) { g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); } @@ -1482,6 +1540,124 @@ sp_text_toolbox_subselection_changed (gpointer /*tc*/, GObject *tbl) sp_text_toolbox_selection_changed (NULL, tbl); } + +/* Recursively extract all "font-family" attributes from a document. */ +void +sp_text_toolbox_get_font_list_in_doc_recursive (SPObject *r, std::list *l) +{ + if (!r) { + return; + } + + const gchar *style = r->getRepr()->attribute("style"); + if( style != NULL ) { + //std::cout << style << std::endl; + std::vector tokens = Glib::Regex::split_simple(";", style ); + for( size_t i=0; i < tokens.size(); ++i ) { + Glib::ustring token = tokens[i]; + size_t found = token.find("font-family:"); + if( found != Glib::ustring::npos ) { + // Remove "font-family:" + token.erase(found,12); + // Remove any leading single or double quote + if( token[0] == '\'' || token[0] == '"' ) { + token.erase(0,1); + } + // Remove any trailing single or double quote + if( token[token.length()-1] == '\'' || token[token.length()-1] == '"' ) { + token.erase(token.length()-1); + } + l->push_back( token ); + } + } + } + + for (SPObject *child = r->firstChild(); child; child = child->getNext()) { + sp_text_toolbox_get_font_list_in_doc_recursive( child, l ); + } +} + +/* Extract all unique "font-family" attributes (including font-family fallbacks) + * from a document in a reverse sorted list. + */ +void +sp_text_toolbox_get_font_list_in_doc (SPObject *r, std::list *l) { + + sp_text_toolbox_get_font_list_in_doc_recursive (r, l); + + l->sort(); + l->unique(); + l->reverse(); + + // for(std::list::iterator i = l->begin(); i != l->end(); ++i) { + // std::cout << " font_family in doc: " << *i << std::endl; + // } +} + +/* Update font-family list with "font-family" attributes used in a document. */ +void +sp_text_toolbox_update_font_list( GtkListStore* model ) { + + /* Create default styles for use when font-family is unknown on system. */ + static GList *default_styles = NULL; + if( default_styles == NULL ) { + default_styles = g_list_append( default_styles, g_strdup("Normal") ); + default_styles = g_list_append( default_styles, g_strdup("Italic") ); + default_styles = g_list_append( default_styles, g_strdup("Bold") ); + default_styles = g_list_append( default_styles, g_strdup("Bold Italic") ); + } + + /* Get "font-family" attributes used in document */ + std::list fontfamilies; + sp_text_toolbox_get_font_list_in_doc( (sp_desktop_document(SP_ACTIVE_DESKTOP))->getRoot(), &fontfamilies ); + + /* Delete all old doc font-family entries */ + GtkTreeIter iter; + gboolean valid; + for( valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter ); valid; ) { + gchar *family = 0; + gboolean onSystem = true; + gtk_tree_model_get( GTK_TREE_MODEL(model), &iter, 0, &family, 2, &onSystem, -1 ); + //std::cout << "List: " << family << ": " << (onSystem ? "Yes" : "No") << std::endl; + if( !onSystem ) { + valid = gtk_list_store_remove( model, &iter ); + } else { + valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ); + } + } + + /* Insert doc font-family entries, list is already reverse sorted with duplicates removed. */ + std::list::iterator i; + for(i=fontfamilies.begin(); i != fontfamilies.end(); ++i) { + + GList *styles = default_styles; + gtk_list_store_insert( model, &iter, 0 ); // iter points to new row + + /* See if font-family (or first in fallback list) is on system. If so, get styles. */ + std::vector tokens = Glib::Regex::split_simple(",", *i ); + if( !tokens[0].empty() ) { + + GtkTreeIter iter2; + gboolean valid2; + for( valid2 = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter2 ); + valid2; + valid2 = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter2 ) ) { + + gchar* family = 0; + gboolean onSystem = true; + gtk_tree_model_get( GTK_TREE_MODEL(model), &iter2, 0, &family, 2, &onSystem, -1 ); + if( onSystem && tokens[0].compare( family ) == 0 ) { + gtk_tree_model_get( GTK_TREE_MODEL(model), &iter2, 1, &styles, -1 ); + break; + } + } + + } + + gtk_list_store_set( model, &iter, 0, (*i).c_str(), 1, styles, 2, false, -1 ); + } +} + // Define all the "widgets" in the toolbar. void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { @@ -1498,6 +1674,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje // Font list Glib::RefPtr store = Inkscape::FontLister::get_instance()->get_font_list(); GtkListStore* model = store->gobj(); + sp_text_toolbox_update_font_list( model ); Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction", _("Font Family"), -- cgit v1.2.3 From a3d3d3df4c67f666083e7c4c2ea56bb94705bbbf Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 7 Feb 2013 12:47:37 +0100 Subject: Add separator between fonts in document and fonts on sytem in font-family drop-down menu. Separator style depends on GTK theme (may be invisible). (bzr r12105) --- src/ink-comboboxentry-action.cpp | 28 +++++++++++++++++++++++++++- src/ink-comboboxentry-action.h | 2 ++ src/widgets/text-toolbar.cpp | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index 78becbd53..5adc3e73a 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -53,6 +53,7 @@ enum { PROP_ENTRY_WIDTH, PROP_EXTRA_WIDTH, PROP_CELL_DATA_FUNC, + PROP_SEPARATOR_FUNC, PROP_POPUP, PROP_FOCUS_WIDGET }; @@ -109,6 +110,10 @@ static void ink_comboboxentry_action_set_property (GObject *object, guint proper action->cell_data_func = g_value_get_pointer( value ); break; + case PROP_SEPARATOR_FUNC: + action->separator_func = g_value_get_pointer( value ); + break; + case PROP_POPUP: action->popup = g_value_get_boolean( value ); break; @@ -154,6 +159,10 @@ static void ink_comboboxentry_action_get_property (GObject *object, guint proper g_value_set_pointer (value, action->cell_data_func); break; + case PROP_SEPARATOR_FUNC: + g_value_set_pointer (value, action->separator_func); + break; + case PROP_POPUP: g_value_set_boolean (value, action->popup); break; @@ -247,6 +256,14 @@ ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass) "Cell Deta Function", (GParamFlags)G_PARAM_READWRITE)); + g_object_class_install_property ( + gobject_class, + PROP_SEPARATOR_FUNC, + g_param_spec_pointer ("separator_func", + "Separator Func", + "Separator Function", + (GParamFlags)G_PARAM_READWRITE)); + g_object_class_install_property ( gobject_class, PROP_POPUP, @@ -303,6 +320,7 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name, gint entry_width, gint extra_width, void *cell_data_func, + void *separator_func, GtkWidget *focusWidget) { g_return_val_if_fail (name != NULL, NULL); @@ -316,6 +334,7 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name, "entry_width", entry_width, "extra_width", extra_width, "cell_data_func", cell_data_func, + "separator_func", separator_func, "focus-widget", focusWidget, NULL); } @@ -365,6 +384,13 @@ GtkWidget* create_tool_item( GtkAction* action ) NULL, NULL ); } + // Optionally add separator function... + if( ink_comboboxentry_action->separator_func != NULL ) { + gtk_combo_box_set_row_separator_func( ink_comboboxentry_action->combobox, + GtkTreeViewRowSeparatorFunc (ink_comboboxentry_action->separator_func), + NULL, NULL ); + } + // Optionally widen the combobox width... which widens the drop-down list in list mode. if( ink_comboboxentry_action->extra_width > 0 ) { GtkRequisition req; @@ -469,7 +495,7 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink // Explicitly set text in GtkEntry box (won't be set if text not in list). gtk_entry_set_text( ink_comboboxentry_action->entry, text ); - // Show or hide warning + // Show or hide warning -- this might be better moved to text-toolbox.cpp bool clear = true; if( ink_comboboxentry_action->active == -1 && ink_comboboxentry_action->warning != NULL ) { diff --git a/src/ink-comboboxentry-action.h b/src/ink-comboboxentry-action.h index 7d4093f4e..f0dc0ee7e 100644 --- a/src/ink-comboboxentry-action.h +++ b/src/ink-comboboxentry-action.h @@ -51,6 +51,7 @@ struct _Ink_ComboBoxEntry_Action { GtkWidget *indicator; gpointer cell_data_func; // drop-down menu format + gpointer separator_func; gint active; // Index of active menu item (-1 if not in list). gchar *text; // Text of active menu item or entry box. @@ -76,6 +77,7 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new ( const gchar *name, gint entry_width = -1, gint extra_width = -1, gpointer cell_data_func = NULL, + gpointer separator_func = NULL, GtkWidget* focusWidget = NULL); GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action ); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 8b3612db4..42d309994 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -217,6 +217,16 @@ static void cell_data_func(GtkCellLayout * /*cell_layout*/, } +// Separator function (if true, a separator will be drawn) +static gboolean separator_func(GtkTreeModel *model, + GtkTreeIter *iter, + gpointer /*data*/) +{ + gchar* text = 0; + gtk_tree_model_get(model, iter, 0, &text, -1 ); // Column 0 + return (text && strcmp(text,"separatoR") == 0); +} + /* * Fill the font style combobox with the available font styles for the selected font family * Set the selected style to that in font @@ -1626,6 +1636,13 @@ sp_text_toolbox_update_font_list( GtkListStore* model ) { } } + /* Insert separator */ + if( !fontfamilies.empty() ) { + gtk_list_store_insert( model, &iter, 0 ); // iter points to new row + gtk_list_store_set( model, &iter, 0, "separatoR", -1 ); + } + + /* Insert doc font-family entries, list is already reverse sorted with duplicates removed. */ std::list::iterator i; for(i=fontfamilies.begin(); i != fontfamilies.end(); ++i) { @@ -1676,15 +1693,17 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje GtkListStore* model = store->gobj(); sp_text_toolbox_update_font_list( model ); - Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction", - _("Font Family"), - _("Select Font Family (Alt-X to access)"), - NULL, - GTK_TREE_MODEL(model), - -1, // Entry width - 50, // Extra list width - (gpointer)cell_data_func,// Cell layout - GTK_WIDGET(desktop->canvas)); // Focus widget + Ink_ComboBoxEntry_Action* act = + ink_comboboxentry_action_new( "TextFontFamilyAction", + _("Font Family"), + _("Select Font Family (Alt-X to access)"), + NULL, + GTK_TREE_MODEL(model), + -1, // Entry width + 50, // Extra list width + (gpointer)cell_data_func, // Cell layout + (gpointer)separator_func, + GTK_WIDGET(desktop->canvas)); // Focus widget ink_comboboxentry_action_popup_enable( act ); // Enable entry completion gchar *const warning = _("Font not found on system"); ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font @@ -1721,6 +1740,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje 4, // Width in characters 0, // Extra list width NULL, // Cell layout + NULL, // Separator GTK_WIDGET(desktop->canvas)); // Focus widget g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontsize_value_changed), holder ); @@ -1740,6 +1760,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje 12, // Width in characters 0, // Extra list width NULL, // Cell layout + NULL, // Separator GTK_WIDGET(desktop->canvas)); // Focus widget g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontstyle_value_changed), holder ); -- cgit v1.2.3 From 55e21b98d8eda49df5d2c2d8ea940dd2d0802bc5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 7 Feb 2013 15:14:00 +0100 Subject: Widen the separator in font-family drop-down so it is visible in more themes. (bzr r12106) --- src/widgets/text-toolbar.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 42d309994..8d37891ac 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1718,7 +1718,13 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "{\n" " GtkComboBox::appears-as-list = 1\n" "}\n" - "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\""); + "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\"" + "style \"fontfamily-separator-style\"\n" + "{\n" + " GtkWidget::wide-separators = 1\n" + " GtkWidget::separator-height = 6\n" + "}\n" + "class \"GtkTreeView\" style \"fontfamily-separator-style\""); } /* Font size */ -- cgit v1.2.3 From 1db4e9f22c0412532f0c3fb9798cd1983a74c9de Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 8 Feb 2013 09:08:06 +0100 Subject: Better rc matching for text-toolbar font-family drop-down separator. From John Smith. (bzr r12107) --- src/widgets/text-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 8d37891ac..f19ee7cee 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1724,7 +1724,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje " GtkWidget::wide-separators = 1\n" " GtkWidget::separator-height = 6\n" "}\n" - "class \"GtkTreeView\" style \"fontfamily-separator-style\""); + "widget \"*gtk-combobox-popup-window.GtkScrolledWindow.GtkTreeView\" style \"fontfamily-separator-style\""); } /* Font size */ -- cgit v1.2.3 From ecdaa96827420efb95a897e56660c33e30553f6a Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 8 Feb 2013 20:48:24 +0100 Subject: cppcheck (should fix a.o. copy paste error in SVGAnimatedPreserveAspectRatio) (bzr r12108) --- src/dom/svgimpl.h | 9 +- src/dom/svgtypes.h | 239 +++++++++++++++++++++++++++-------------------------- 2 files changed, 128 insertions(+), 120 deletions(-) (limited to 'src') diff --git a/src/dom/svgimpl.h b/src/dom/svgimpl.h index 83d56fa22..2ee5c8bc7 100644 --- a/src/dom/svgimpl.h +++ b/src/dom/svgimpl.h @@ -980,7 +980,14 @@ public: /** * */ - SVGSVGElementImpl() : SVGElementImpl() + SVGSVGElementImpl() : SVGElementImpl(), + pixelUnitToMillimeterX(0), + pixelUnitToMillimeterY(0), + screenPixelToMillimeterX(0), + screenPixelToMillimeterY(0), + useCurrentView(false), + currentScale(0), + currentTime(0) {} diff --git a/src/dom/svgtypes.h b/src/dom/svgtypes.h index 41b4de307..bb828571f 100644 --- a/src/dom/svgtypes.h +++ b/src/dom/svgtypes.h @@ -645,20 +645,20 @@ public: /** * */ - SVGTransform() + SVGTransform() : + type (SVG_TRANSFORM_UNKNOWN), + angle (0.0) { - type = SVG_TRANSFORM_UNKNOWN; - angle = 0.0; } /** * */ - SVGTransform(const SVGTransform &other) + SVGTransform(const SVGTransform &other) : + type (other.type), + angle (other.angle), + matrix (other.matrix) { - type = other.type; - angle = other.angle; - matrix = other.matrix; } /** @@ -834,9 +834,9 @@ public: /** * */ - SVGTransformList(const SVGTransformList &other) + SVGTransformList(const SVGTransformList &other) : + items (other.items) { - items = other.items; } /** @@ -893,10 +893,10 @@ public: /** * */ - SVGAnimatedTransformList(const SVGAnimatedTransformList &other) + SVGAnimatedTransformList(const SVGAnimatedTransformList &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -1181,9 +1181,9 @@ public: /** * */ - SVGStringList(const SVGStringList &other) + SVGStringList(const SVGStringList &other) : + items (other.items) { - items = other.items; } /** @@ -1657,9 +1657,9 @@ public: /** * */ - SVGNumberList(const SVGNumberList &other) + SVGNumberList(const SVGNumberList &other) : + items (other.items) { - items = other.items; } /** @@ -1719,10 +1719,10 @@ public: /** * */ - SVGAnimatedNumberList(const SVGAnimatedNumberList &other) + SVGAnimatedNumberList(const SVGAnimatedNumberList &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -1934,10 +1934,10 @@ public: /** * */ - SVGAnimatedLength(const SVGAnimatedLength &other) + SVGAnimatedLength(const SVGAnimatedLength &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -2085,9 +2085,9 @@ public: /** * */ - SVGLengthList(const SVGLengthList &other) + SVGLengthList(const SVGLengthList &other) : + items (other.items) { - items = other.items; } /** @@ -2147,10 +2147,10 @@ public: /** * */ - SVGAnimatedLengthList(const SVGAnimatedLengthList &other) + SVGAnimatedLengthList(const SVGAnimatedLengthList &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -2357,16 +2357,17 @@ public: /** * */ - SVGAnimatedAngle(const SVGAngle &angle) - { baseVal = angle; } + SVGAnimatedAngle(const SVGAngle &angle) : + baseVal (angle) + {} /** * */ - SVGAnimatedAngle(const SVGAnimatedAngle &other) + SVGAnimatedAngle(const SVGAnimatedAngle &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -2434,10 +2435,10 @@ public: /** * */ - SVGICCColor(const SVGICCColor &other) + SVGICCColor(const SVGICCColor &other) : + colorProfile (other.colorProfile), + colors (other.colors) { - colorProfile = other.colorProfile; - colors = other.colors; } /** @@ -2448,7 +2449,6 @@ public: protected: DOMString colorProfile; - SVGNumberList colors; }; @@ -2732,10 +2732,10 @@ public: /** * */ - SVGAnimatedRect(const SVGAnimatedRect &other) + SVGAnimatedRect(const SVGAnimatedRect &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - animVal = other.animVal; } /** @@ -2956,9 +2956,9 @@ public: /** * */ - SVGPointList(const SVGPointList &other) + SVGPointList(const SVGPointList &other) : + items (other.items) { - items = other.items; } @@ -3071,10 +3071,10 @@ public: /** * */ - SVGStylable(const SVGStylable &other) + SVGStylable(const SVGStylable &other) : + className (other.className), + style (other.style) { - className = other.className; - style = other.style; } /** @@ -3168,7 +3168,10 @@ public: /** * */ - SVGLocatable(const SVGLocatable &/*other*/) + SVGLocatable(const SVGLocatable &/*other*/) : + bbox(), + ctm(), + screenCtm() { } @@ -3224,9 +3227,9 @@ public: /** * */ - SVGTransformable(const SVGTransformable &other) : SVGLocatable(other) + SVGTransformable(const SVGTransformable &other) : SVGLocatable(other), + transforms (other.transforms) { - transforms = other.transforms; } /** @@ -3303,11 +3306,11 @@ public: /** * */ - SVGTests(const SVGTests &other) + SVGTests(const SVGTests &other) : + requiredFeatures (other.requiredFeatures), + requiredExtensions (other.requiredExtensions), + systemLanguage (other.systemLanguage) { - requiredFeatures = other.requiredFeatures; - requiredExtensions = other.requiredExtensions; - systemLanguage = other.systemLanguage; } /** @@ -3445,9 +3448,9 @@ public: /** * */ - SVGExternalResourcesRequired(const SVGExternalResourcesRequired &other) + SVGExternalResourcesRequired(const SVGExternalResourcesRequired &other) : + required (other.required) { - required = other.required; } /** @@ -3611,10 +3614,10 @@ public: /** * */ - SVGAnimatedPreserveAspectRatio(const SVGAnimatedPreserveAspectRatio &other) + SVGAnimatedPreserveAspectRatio(const SVGAnimatedPreserveAspectRatio &other) : + baseVal (other.baseVal), + animVal (other.animVal) { - baseVal = other.baseVal; - baseVal = other.animVal; } /** @@ -3671,10 +3674,10 @@ public: * */ - SVGFitToViewBox(const SVGFitToViewBox &other) + SVGFitToViewBox(const SVGFitToViewBox &other) : + viewBox (other.viewBox), + preserveAspectRatio (other.preserveAspectRatio) { - viewBox = other.viewBox; - preserveAspectRatio = other.preserveAspectRatio; } /** @@ -3685,7 +3688,6 @@ public: protected: SVGAnimatedRect viewBox; - SVGAnimatedPreserveAspectRatio preserveAspectRatio; }; @@ -3828,18 +3830,19 @@ public: /** * */ - SVGViewSpec() + SVGViewSpec() : + viewTarget (NULL), + transform () { - viewTarget = NULL; } /** * */ - SVGViewSpec(const SVGViewSpec &other) : SVGZoomAndPan(other), SVGFitToViewBox(other) + SVGViewSpec(const SVGViewSpec &other) : SVGZoomAndPan(other), SVGFitToViewBox(other), + viewTarget (other.viewTarget), + transform (other.transform) { - viewTarget = other.viewTarget; - transform = other.transform; } /** @@ -3884,14 +3887,16 @@ public: /** * */ - SVGURIReference() {} + SVGURIReference() : + href () + {} /** * */ - SVGURIReference(const SVGURIReference &other) + SVGURIReference(const SVGURIReference &other) : + href (other.href) { - href = other.href; } /** @@ -6135,9 +6140,9 @@ public: /** * */ - SVGPathSegList(const SVGPathSegList &other) + SVGPathSegList(const SVGPathSegList &other) : + items (other.items) { - items = other.items; } @@ -6272,10 +6277,10 @@ public: /** * */ - SVGAnimatedPoints(const SVGAnimatedPoints &other) + SVGAnimatedPoints(const SVGAnimatedPoints &other) : + points (other.points), + animatedPoints (other.animatedPoints) { - points = other.points; - animatedPoints = other.animatedPoints; } /** @@ -6366,19 +6371,19 @@ public: /** * */ - SVGPaint() + SVGPaint() : + paintType (SVG_PAINTTYPE_UNKNOWN), + uri ("") { - uri = ""; - paintType = SVG_PAINTTYPE_UNKNOWN; } /** * */ - SVGPaint(const SVGPaint &other) : css::CSSValue(other), SVGColor(other) + SVGPaint(const SVGPaint &other) : css::CSSValue(other), SVGColor(other), + paintType (SVG_PAINTTYPE_UNKNOWN), + uri ("") { - uri = ""; - paintType = SVG_PAINTTYPE_UNKNOWN; } /** @@ -6452,17 +6457,19 @@ public: /** * */ - SVGColorProfileRule() {} + SVGColorProfileRule() : + renderingIntent(0) + {} /** * */ SVGColorProfileRule(const SVGColorProfileRule &other) - : SVGCSSRule(other), SVGRenderingIntent(other) + : SVGCSSRule(other), SVGRenderingIntent(other), + renderingIntent (other.renderingIntent), + src (other.src), + name (other.name) { - renderingIntent = other.renderingIntent; - src = other.src; - name = other.name; } /** @@ -6540,13 +6547,13 @@ public: * */ SVGFilterPrimitiveStandardAttributes(const SVGFilterPrimitiveStandardAttributes &other) - : SVGStylable(other) + : SVGStylable(other), + x (other.x), + y (other.y), + width (other.width), + height (other.height), + result (other.result) { - x = other.x; - y = other.y; - width = other.width; - height = other.height; - result = other.result; } /** @@ -6567,13 +6574,6 @@ protected: - - - - - - - /*######################################################################### ## SVGEvent #########################################################################*/ @@ -6660,20 +6660,26 @@ public: /** * */ - SVGZoomEvent() + SVGZoomEvent(): + zoomRectScreen(), + previousScale(0), + previousTranslate(), + newScale(0), + newTranslate() {} /** * */ - SVGZoomEvent(const SVGZoomEvent &other) : events::Event(other), - events::UIEvent(other) + SVGZoomEvent(const SVGZoomEvent &other) : + events::Event(other), + events::UIEvent(other), + zoomRectScreen(other.zoomRectScreen), + previousScale(other.previousScale), + previousTranslate(other.previousTranslate), + newScale(other.newScale), + newTranslate(other.newTranslate) { - zoomRectScreen = other.zoomRectScreen; - previousScale = other.previousScale; - previousTranslate = other.previousTranslate; - newScale = other.newScale; - newTranslate = other.newTranslate; } /** @@ -6776,13 +6782,18 @@ public: /** * */ - SVGElementInstance() {} + SVGElementInstance() : + correspondingElement(NULL), + correspondingUseElement(NULL) + {} /** * */ SVGElementInstance(const SVGElementInstance &other) - : events::EventTarget(other) + : events::EventTarget(other), + correspondingElement(NULL), + correspondingUseElement(NULL) { } @@ -6858,9 +6869,9 @@ public: /** * */ - SVGElementInstanceList(const SVGElementInstanceList &other) + SVGElementInstanceList(const SVGElementInstanceList &other) : + items (other.items) { - items = other.items; } /** @@ -6877,16 +6888,6 @@ protected: - - - - - - - - - - } //namespace svg } //namespace dom } //namespace w3c -- cgit v1.2.3 From c7c7405b0417093650d312ce00a3e9009ca49ee6 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 8 Feb 2013 20:59:10 +0100 Subject: removed some unused files (bzr r12109) --- src/dom/CMakeLists.txt | 12 - src/dom/Makefile_insert | 11 +- src/dom/odf/odfdocument.cpp | 167 --- src/dom/odf/odfdocument.h | 150 --- src/dom/util/digest.cpp | 1456 --------------------- src/dom/util/digest.h | 654 ---------- src/dom/util/thread.cpp | 126 -- src/dom/util/thread.h | 156 --- src/dom/util/ziptool.cpp | 3025 ------------------------------------------- src/dom/util/ziptool.h | 567 -------- 10 files changed, 1 insertion(+), 6323 deletions(-) delete mode 100644 src/dom/odf/odfdocument.cpp delete mode 100644 src/dom/odf/odfdocument.h delete mode 100644 src/dom/util/digest.cpp delete mode 100644 src/dom/util/digest.h delete mode 100644 src/dom/util/thread.cpp delete mode 100644 src/dom/util/thread.h delete mode 100644 src/dom/util/ziptool.cpp delete mode 100644 src/dom/util/ziptool.h (limited to 'src') diff --git a/src/dom/CMakeLists.txt b/src/dom/CMakeLists.txt index df2411b13..bc2f58c29 100644 --- a/src/dom/CMakeLists.txt +++ b/src/dom/CMakeLists.txt @@ -26,12 +26,6 @@ set(dom_SRC io/stringstream.cpp io/uristream.cpp - odf/odfdocument.cpp - - util/digest.cpp - util/thread.cpp - util/ziptool.cpp - # ------- # Headers @@ -64,18 +58,12 @@ set(dom_SRC xpathparser.h xpathtoken.h - odf/odfdocument.h - io/base64stream.h io/bufferstream.h io/domstream.h io/gzipstream.h io/stringstream.h io/uristream.h - - util/digest.h - util/thread.h - util/ziptool.h ) add_inkscape_lib(dom_LIB "${dom_SRC}") diff --git a/src/dom/Makefile_insert b/src/dom/Makefile_insert index ace53b4a2..66333ba47 100644 --- a/src/dom/Makefile_insert +++ b/src/dom/Makefile_insert @@ -63,13 +63,4 @@ dom_libdom_a_SOURCES = \ dom/io/stringstream.cpp \ dom/io/stringstream.h \ dom/io/uristream.cpp \ - dom/io/uristream.h \ - dom/odf/odfdocument.cpp \ - dom/odf/odfdocument.h \ - dom/util/digest.h \ - dom/util/digest.cpp \ - dom/util/thread.h \ - dom/util/thread.cpp \ - dom/util/ziptool.h \ - dom/util/ziptool.cpp - + dom/io/uristream.h diff --git a/src/dom/odf/odfdocument.cpp b/src/dom/odf/odfdocument.cpp deleted file mode 100644 index cf460c964..000000000 --- a/src/dom/odf/odfdocument.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * - * This class contains an ODF Document. - * Initially, we are just concerned with .odg content.xml + resources - * - * --------------------------------------------------------------------- - * - * Copyright (C) 2006-2008 Bob Jamison - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * For more information, please write to rwjj@earthlink.net - * - * RWJ : 080207: Changed to GPL2 by me - * - */ - -#include "odfdocument.h" - - -namespace odf -{ - - -//######################################################################## -//# I M A G E D A T A -//######################################################################## - - -/** - * - */ -ImageData::ImageData(const std::string &fname, - const std::vector &buf) - : fileName (fname), - data (buf) - -{ -} - -/** - * - */ -ImageData::ImageData(const ImageData &other) - : fileName (other.fileName), - data (other.data) - -{ -} - -/** - * - */ -ImageData::~ImageData() -{ -} - -/** - * - */ -std::string ImageData::getFileName() -{ - return fileName; -} - -/** - * - */ -void ImageData::setFileName(const std::string &val) -{ - fileName = val; -} - -/** - * - */ -std::vector &ImageData::getData() -{ - return data; -} - -/** - * - */ -void ImageData::setData(const std::vector &buf) -{ - data = buf; -} - - - - - -//######################################################################## -//# O D F D O C U M E N T -//######################################################################## - - - -/** - * - */ -OdfDocument::OdfDocument() : - content(0), - images() -{ -} - - -/** - * - */ -OdfDocument::OdfDocument(const OdfDocument &other) : - content (other.content), - images (other.images) -{ -} - - -/** - * - */ -OdfDocument::~OdfDocument() -{ -} - -/** - * - */ -bool OdfDocument::readFile(const std::string &/*fileName*/) -{ - return true; -} - -/** - * - */ -bool OdfDocument::writeFile(const std::string &/*fileName*/) -{ - return true; -} - - - - - -} //namespace odf - - - - -//######################################################################## -//# E N D O F F I L E -//######################################################################## - diff --git a/src/dom/odf/odfdocument.h b/src/dom/odf/odfdocument.h deleted file mode 100644 index 168df11c7..000000000 --- a/src/dom/odf/odfdocument.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef SEEN_ODF_DOCUMENT_H -#define SEEN_ODF_DOCUMENT_H -/* - * Copyright (C) 2006 Bob Jamison - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * For more information, please write to rwjj@earthlink.net - * - * RWJ : 080207: Changed to GPL2 by me - */ - -#include -#include - -#include "dom/dom.h" - -namespace odf -{ - - -//######################################################################## -//# I M A G E D A T A -//######################################################################## - -/** - * - */ -class ImageData -{ -public: - - /** - * - */ - ImageData(const std::string &fileName, - const std::vector &buf); - - /** - * - */ - ImageData(const ImageData &other); - - /** - * - */ - virtual ~ImageData(); - - /** - * - */ - virtual std::string getFileName(); - - /** - * - */ - virtual void setFileName(const std::string &val); - - /** - * - */ - virtual std::vector &getData(); - - /** - * - */ - virtual void setData(const std::vector &buf); - -private: - - std::string fileName; - - std::vector data; - -}; - - - - - -//######################################################################## -//# O D F D O C U M E N T -//######################################################################## - - -/** - * - * This class contains an ODF Document. - * Initially, we are just concerned with .odg content.xml + resources - */ -class OdfDocument -{ -public: - - /** - * - */ - OdfDocument(); - - /** - * Copy constructor - */ - OdfDocument(const OdfDocument &other); - - /** - * - */ - virtual ~OdfDocument(); - - /** - * - */ - virtual bool readFile(const std::string &fileName); - - /** - * - */ - virtual bool writeFile(const std::string &fileName); - - -private: - - org::w3c::dom::Document *content; - - std::vector images; - -}; - -} //namespace odf - - - -#endif // SEEN_ODF_DOCUMENT_H - -//######################################################################## -//# E N D O F F I L E -//######################################################################## - diff --git a/src/dom/util/digest.cpp b/src/dom/util/digest.cpp deleted file mode 100644 index 2baed4860..000000000 --- a/src/dom/util/digest.cpp +++ /dev/null @@ -1,1456 +0,0 @@ -/* - * Secure Hashing Tool - * * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2008 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "digest.h" - - -//######################################################################## -//## U T I L I T Y -//######################################################################## - -/** - * Use this to print out a 64-bit int when otherwise difficult - */ -/* -static void pl(uint64_t val) -{ - for (int shift=56 ; shift>=0 ; shift-=8) - { - int ch = (val >> shift) & 0xff; - printf("%02x", ch); - } -} -*/ - - - -/** - * 3These truncate their arguments to - * unsigned 32-bit or unsigned 64-bit. - */ -#define TR32(x) ((x) & 0xffffffffL) -#define TR64(x) ((x) & 0xffffffffffffffffLL) - - -static const char *hexDigits = "0123456789abcdef"; - -static std::string toHex(const std::vector &bytes) -{ - std::string str; - std::vector::const_iterator iter; - for (iter = bytes.begin() ; iter != bytes.end() ; ++iter) - { - unsigned char ch = *iter; - str.push_back(hexDigits[(ch>>4) & 0x0f]); - str.push_back(hexDigits[(ch ) & 0x0f]); - } - return str; -} - - -//######################################################################## -//## D I G E S T -//######################################################################## - - -/** - * - */ -std::string Digest::finishHex() -{ - std::vector hash = finish(); - std::string str = toHex(hash); - return str; -} - -/** - * Convenience method. This is a simple way of getting a hash - */ -std::vector Digest::hash(Digest::HashType typ, - unsigned char *buf, - int len) -{ - std::vector ret; - switch (typ) - { - case HASH_MD5: - { - Md5 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - case HASH_SHA1: - { - Sha1 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - case HASH_SHA224: - { - Sha224 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - case HASH_SHA256: - { - Sha256 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - case HASH_SHA384: - { - Sha384 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - case HASH_SHA512: - { - Sha512 digest; - digest.append(buf, len); - ret = digest.finish(); - break; - } - default: - { - break; - } - } - return ret; -} - - -/** - * Convenience method. Same as above, but for a std::string - */ -std::vector Digest::hash(Digest::HashType typ, - const std::string &str) -{ - return hash(typ, (unsigned char *)str.c_str(), str.size()); -} - -/** - * Convenience method. Return a hexidecimal string of the hash of the buffer. - */ -std::string Digest::hashHex(Digest::HashType typ, - unsigned char *buf, - int len) -{ - std::vector dig = hash(typ, buf, len); - return toHex(dig); -} - -/** - * Convenience method. Return a hexidecimal string of the hash of the - * string argument - */ -std::string Digest::hashHex(Digest::HashType typ, - const std::string &str) -{ - std::vector dig = hash(typ, str); - return toHex(dig); -} - - - -//4.1.1 and 4.1.2 -#define SHA_ROTL(X,n) ((((X) << (n)) & 0xffffffffL) | (((X) >> (32-(n))) & 0xffffffffL)) -#define SHA_Ch(x,y,z) ((z)^((x)&((y)^(z)))) -#define SHA_Maj(x,y,z) (((x)&(y))^((z)&((x)^(y)))) - - -//######################################################################## -//## S H A 1 -//######################################################################## - - -/** - * - */ -void Sha1::reset() -{ - longNr = 0; - byteNr = 0; - - // Initialize H with the magic constants (see FIPS180 for constants) - hashBuf[0] = 0x67452301L; - hashBuf[1] = 0xefcdab89L; - hashBuf[2] = 0x98badcfeL; - hashBuf[3] = 0x10325476L; - hashBuf[4] = 0xc3d2e1f0L; - - for (int i = 0; i < 4; i++) - inb[i] = 0; - - for (int i = 0; i < 80; i++) - inBuf[i] = 0; - - clearByteCount(); -} - - -/** - * - */ -void Sha1::update(unsigned char ch) -{ - incByteCount(); - - inb[byteNr++] = (uint32_t)ch; - if (byteNr >= 4) - { - inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | - inb[2] << 8 | inb[3]; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - -void Sha1::transform() -{ - uint32_t *W = inBuf; - uint32_t *H = hashBuf; - - //for (int t = 0; t < 16 ; t++) - // printf("%2d %08lx\n", t, W[t]); - - //see 6.1.2 - for (int t = 16; t < 80 ; t++) - W[t] = SHA_ROTL((W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]), 1); - - uint32_t a = H[0]; - uint32_t b = H[1]; - uint32_t c = H[2]; - uint32_t d = H[3]; - uint32_t e = H[4]; - - uint32_t T; - - int t = 0; - for ( ; t < 20 ; t++) - { - //see 4.1.1 for the boolops on B,C, and D - T = TR32(SHA_ROTL(a,5) + ((b&c)|((~b)&d)) + //Ch(b,c,d)) - e + 0x5a827999L + W[t]); - e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; - //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); - } - for ( ; t < 40 ; t++) - { - T = TR32(SHA_ROTL(a,5) + (b^c^d) + e + 0x6ed9eba1L + W[t]); - e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; - //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); - } - for ( ; t < 60 ; t++) - { - T = TR32(SHA_ROTL(a,5) + ((b&c)^(b&d)^(c&d)) + - e + 0x8f1bbcdcL + W[t]); - e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; - //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); - } - for ( ; t < 80 ; t++) - { - T = TR32(SHA_ROTL(a,5) + (b^c^d) + - e + 0xca62c1d6L + W[t]); - e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; - //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); - } - - H[0] = TR32(H[0] + a); - H[1] = TR32(H[1] + b); - H[2] = TR32(H[2] + c); - H[3] = TR32(H[3] + d); - H[4] = TR32(H[4] + e); -} - - - - -/** - * - */ -std::vector Sha1::finish() -{ - //snapshot the bit count now before padding - getBitCount(); - - //Append terminal char - update(0x80); - - //pad until we have a 56 of 64 bytes, allowing for 8 bytes at the end - while ((nrBytes & 63) != 56) - update(0); - - //##### Append length in bits - appendBitCount(); - - //copy out answer - std::vector res; - for (int i=0 ; i<5 ; i++) - { - res.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - } - - // Re-initialize the context (also zeroizes contents) - reset(); - - return res; -} - - - - -//######################################################################## -//## SHA224 -//######################################################################## - - -/** - * SHA-224 and SHA-512 share the same operations and constants - */ - -#define SHA_Rot32(x,s) ((((x) >> s)&0xffffffffL) | (((x) << (32 - s))&0xffffffffL)) -#define SHA_SIGMA0(x) (SHA_Rot32(x, 2) ^ SHA_Rot32(x, 13) ^ SHA_Rot32(x, 22)) -#define SHA_SIGMA1(x) (SHA_Rot32(x, 6) ^ SHA_Rot32(x, 11) ^ SHA_Rot32(x, 25)) -#define SHA_sigma0(x) (SHA_Rot32(x, 7) ^ SHA_Rot32(x, 18) ^ ((x) >> 3)) -#define SHA_sigma1(x) (SHA_Rot32(x, 17) ^ SHA_Rot32(x, 19) ^ ((x) >> 10)) - - -static uint32_t sha256table[64] = -{ - 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, - 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, - 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, - 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, - 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, - 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, - 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, - 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, - 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, - 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, - 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, - 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, - 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, - 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, - 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, - 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL -}; - - - - - -/** - * - */ -void Sha224::reset() -{ - longNr = 0; - byteNr = 0; - - // Initialize H with the magic constants (see FIPS180 for constants) - hashBuf[0] = 0xc1059ed8L; - hashBuf[1] = 0x367cd507L; - hashBuf[2] = 0x3070dd17L; - hashBuf[3] = 0xf70e5939L; - hashBuf[4] = 0xffc00b31L; - hashBuf[5] = 0x68581511L; - hashBuf[6] = 0x64f98fa7L; - hashBuf[7] = 0xbefa4fa4L; - - for (int i = 0 ; i < 64 ; i++) - inBuf[i] = 0; - - for (int i = 0 ; i < 4 ; i++) - inb[i] = 0; - - clearByteCount(); -} - - -/** - * - */ -void Sha224::update(unsigned char ch) -{ - incByteCount(); - - inb[byteNr++] = (uint32_t)ch; - if (byteNr >= 4) - { - inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | - inb[2] << 8 | inb[3]; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - -void Sha224::transform() -{ - uint32_t *W = inBuf; - uint32_t *H = hashBuf; - - //for (int t = 0; t < 16 ; t++) - // printf("%2d %08lx\n", t, W[t]); - - //see 6.2.2 - for (int t = 16; t < 64 ; t++) - W[t] = TR32(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); - - uint32_t a = H[0]; - uint32_t b = H[1]; - uint32_t c = H[2]; - uint32_t d = H[3]; - uint32_t e = H[4]; - uint32_t f = H[5]; - uint32_t g = H[6]; - uint32_t h = H[7]; - - for (int t = 0 ; t < 64 ; t++) - { - //see 4.1.1 for the boolops - uint32_t T1 = TR32(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + - sha256table[t] + W[t]); - uint32_t T2 = TR32(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); - h = g; g = f; f = e; e = TR32(d + T1); d = c; c = b; b = a; a = TR32(T1 + T2); - //printf("%2d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", - // t, a, b, c, d, e, f, g, h); - } - - H[0] = TR32(H[0] + a); - H[1] = TR32(H[1] + b); - H[2] = TR32(H[2] + c); - H[3] = TR32(H[3] + d); - H[4] = TR32(H[4] + e); - H[5] = TR32(H[5] + f); - H[6] = TR32(H[6] + g); - H[7] = TR32(H[7] + h); -} - - - -/** - * - */ -std::vector Sha224::finish() -{ - //save our size before padding - getBitCount(); - - // Pad with a binary 1 (0x80) - update(0x80); - //append 0's to make a 56-byte buf. - while ((nrBytes & 63) != 56) - update(0); - - //##### Append length in bits - appendBitCount(); - - // Output hash - std::vector ret; - for (int i = 0 ; i < 7 ; i++) - { - ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - } - - // Re-initialize the context (also zeroizes contents) - reset(); - - return ret; - -} - - - -//######################################################################## -//## SHA256 -//######################################################################## - - -/** - * - */ -void Sha256::reset() -{ - longNr = 0; - byteNr = 0; - - // Initialize H with the magic constants (see FIPS180 for constants) - hashBuf[0] = 0x6a09e667L; - hashBuf[1] = 0xbb67ae85L; - hashBuf[2] = 0x3c6ef372L; - hashBuf[3] = 0xa54ff53aL; - hashBuf[4] = 0x510e527fL; - hashBuf[5] = 0x9b05688cL; - hashBuf[6] = 0x1f83d9abL; - hashBuf[7] = 0x5be0cd19L; - - for (int i = 0 ; i < 64 ; i++) - inBuf[i] = 0; - for (int i = 0 ; i < 4 ; i++) - inb[i] = 0; - - clearByteCount(); -} - - -/** - * - */ -void Sha256::update(unsigned char ch) -{ - incByteCount(); - - inb[byteNr++] = (uint32_t)ch; - if (byteNr >= 4) - { - inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | - inb[2] << 8 | inb[3]; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - - - -void Sha256::transform() -{ - uint32_t *H = hashBuf; - uint32_t *W = inBuf; - - //for (int t = 0; t < 16 ; t++) - // printf("%2d %08lx\n", t, W[t]); - - //see 6.2.2 - for (int t = 16; t < 64 ; t++) - W[t] = TR32(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); - - uint32_t a = H[0]; - uint32_t b = H[1]; - uint32_t c = H[2]; - uint32_t d = H[3]; - uint32_t e = H[4]; - uint32_t f = H[5]; - uint32_t g = H[6]; - uint32_t h = H[7]; - - for (int t = 0 ; t < 64 ; t++) - { - //see 4.1.1 for the boolops - uint32_t T1 = TR32(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + - sha256table[t] + W[t]); - uint32_t T2 = TR32(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); - h = g; g = f; f = e; e = TR32(d + T1); d = c; c = b; b = a; a = TR32(T1 + T2); - //printf("%2d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", - // t, a, b, c, d, e, f, g, h); - } - - H[0] = TR32(H[0] + a); - H[1] = TR32(H[1] + b); - H[2] = TR32(H[2] + c); - H[3] = TR32(H[3] + d); - H[4] = TR32(H[4] + e); - H[5] = TR32(H[5] + f); - H[6] = TR32(H[6] + g); - H[7] = TR32(H[7] + h); -} - - - -/** - * - */ -std::vector Sha256::finish() -{ - //save our size before padding - getBitCount(); - - // Pad with a binary 1 (0x80) - update(0x80); - //append 0's to make a 56-byte buf. - while ((nrBytes & 63) != 56) - update(0); - - //##### Append length in bits - appendBitCount(); - - // Output hash - std::vector ret; - for (int i = 0 ; i < 8 ; i++) - { - ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - } - - // Re-initialize the context (also zeroizes contents) - reset(); - - return ret; - -} - - - -//######################################################################## -//## SHA384 -//######################################################################## - - -/** - * SHA-384 and SHA-512 share the same operations and constants - */ - -#undef SHA_SIGMA0 -#undef SHA_SIGMA1 -#undef SHA_sigma0 -#undef SHA_sigma1 - -#define SHA_Rot64(x,s) (((x) >> s) | ((x) << (64 - s))) -#define SHA_SIGMA0(x) (SHA_Rot64(x, 28) ^ SHA_Rot64(x, 34) ^ SHA_Rot64(x, 39)) -#define SHA_SIGMA1(x) (SHA_Rot64(x, 14) ^ SHA_Rot64(x, 18) ^ SHA_Rot64(x, 41)) -#define SHA_sigma0(x) (SHA_Rot64(x, 1) ^ SHA_Rot64(x, 8) ^ ((x) >> 7)) -#define SHA_sigma1(x) (SHA_Rot64(x, 19) ^ SHA_Rot64(x, 61) ^ ((x) >> 6)) - - -static uint64_t sha512table[80] = -{ - 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, - 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, - 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, - 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, - 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, - 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, - 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, - 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, - 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, - 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, - 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, - 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, - 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, - 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, - 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, - 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, - 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, - 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, - 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, - 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, - 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, - 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, - 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, - 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, - 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, - 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, - 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, - 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, - 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, - 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, - 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, - 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, - 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, - 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, - 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, - 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, - 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, - 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, - 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, - 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL -}; - - - - -/** - * - */ -void Sha384::reset() -{ - longNr = 0; - byteNr = 0; - - // SHA-384 differs from SHA-512 by these constants - hashBuf[0] = 0xcbbb9d5dc1059ed8ULL; - hashBuf[1] = 0x629a292a367cd507ULL; - hashBuf[2] = 0x9159015a3070dd17ULL; - hashBuf[3] = 0x152fecd8f70e5939ULL; - hashBuf[4] = 0x67332667ffc00b31ULL; - hashBuf[5] = 0x8eb44a8768581511ULL; - hashBuf[6] = 0xdb0c2e0d64f98fa7ULL; - hashBuf[7] = 0x47b5481dbefa4fa4ULL; - - for (int i = 0 ; i < 80 ; i++) - inBuf[i] = 0; - for (int i = 0 ; i < 8 ; i++) - inb[i] = 0; - - clearByteCount(); -} - - -/** - * Note that this version of update() handles 64-bit inBuf - * values. - */ -void Sha384::update(unsigned char ch) -{ - incByteCount(); - - inb[byteNr++] = (uint64_t)ch; - if (byteNr >= 8) - { - inBuf[longNr++] = inb[0] << 56 | inb[1] << 48 | - inb[2] << 40 | inb[3] << 32 | - inb[4] << 24 | inb[5] << 16 | - inb[6] << 8 | inb[7]; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - - - -void Sha384::transform() -{ - uint64_t *H = hashBuf; - uint64_t *W = inBuf; - - /* - for (int t = 0; t < 16 ; t++) - { - printf("%2d ", t); - pl(W[t]); - printf("\n"); - } - */ - - //see 6.2.2 - for (int t = 16; t < 80 ; t++) - W[t] = TR64(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); - - uint64_t a = H[0]; - uint64_t b = H[1]; - uint64_t c = H[2]; - uint64_t d = H[3]; - uint64_t e = H[4]; - uint64_t f = H[5]; - uint64_t g = H[6]; - uint64_t h = H[7]; - - for (int t = 0 ; t < 80 ; t++) - { - //see 4.1.1 for the boolops - uint64_t T1 = TR64(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + - sha512table[t] + W[t]); - uint64_t T2 = TR64(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); - h = g; g = f; f = e; e = TR64(d + T1); d = c; c = b; b = a; a = TR64(T1 + T2); - } - - H[0] = TR64(H[0] + a); - H[1] = TR64(H[1] + b); - H[2] = TR64(H[2] + c); - H[3] = TR64(H[3] + d); - H[4] = TR64(H[4] + e); - H[5] = TR64(H[5] + f); - H[6] = TR64(H[6] + g); - H[7] = TR64(H[7] + h); -} - - - -/** - * - */ -std::vector Sha384::finish() -{ - //save our size before padding - getBitCount(); - - // Pad with a binary 1 (0x80) - update((unsigned char)0x80); - //append 0's to make a 112-byte buf. - //we will loop around once if already over 112 - while ((nrBytes & 127) != 112) - update(0); - - //append 128-bit size - //64 upper bits - for (int i = 0 ; i < 8 ; i++) - update((unsigned char)0x00); - //64 lower bits - //##### Append length in bits - appendBitCount(); - - // Output hash - //for SHA-384, we use the left-most 6 64-bit words - std::vector ret; - for (int i = 0 ; i < 6 ; i++) - { - ret.push_back((unsigned char)((hashBuf[i] >> 56) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 48) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 40) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 32) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - } - - // Re-initialize the context (also zeroizes contents) - reset(); - - return ret; - -} - - -//######################################################################## -//## SHA512 -//######################################################################## - - - - - -/** - * - */ -void Sha512::reset() -{ - longNr = 0; - byteNr = 0; - - // Initialize H with the magic constants (see FIPS180 for constants) - hashBuf[0] = 0x6a09e667f3bcc908ULL; - hashBuf[1] = 0xbb67ae8584caa73bULL; - hashBuf[2] = 0x3c6ef372fe94f82bULL; - hashBuf[3] = 0xa54ff53a5f1d36f1ULL; - hashBuf[4] = 0x510e527fade682d1ULL; - hashBuf[5] = 0x9b05688c2b3e6c1fULL; - hashBuf[6] = 0x1f83d9abfb41bd6bULL; - hashBuf[7] = 0x5be0cd19137e2179ULL; - - for (int i = 0 ; i < 80 ; i++) - inBuf[i] = 0; - for (int i = 0 ; i < 8 ; i++) - inb[i] = 0; - - clearByteCount(); -} - - -/** - * Note that this version of update() handles 64-bit inBuf - * values. - */ -void Sha512::update(unsigned char ch) -{ - incByteCount(); - - inb[byteNr++] = (uint64_t)ch; - if (byteNr >= 8) - { - inBuf[longNr++] = inb[0] << 56 | inb[1] << 48 | - inb[2] << 40 | inb[3] << 32 | - inb[4] << 24 | inb[5] << 16 | - inb[6] << 8 | inb[7]; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - - - -void Sha512::transform() -{ - uint64_t *W = inBuf; - uint64_t *H = hashBuf; - - /* - for (int t = 0; t < 16 ; t++) - { - printf("%2d ", t); - pl(W[t]); - printf("\n"); - } - */ - - //see 6.2.2 - for (int t = 16; t < 80 ; t++) - W[t] = TR64(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); - - uint64_t a = H[0]; - uint64_t b = H[1]; - uint64_t c = H[2]; - uint64_t d = H[3]; - uint64_t e = H[4]; - uint64_t f = H[5]; - uint64_t g = H[6]; - uint64_t h = H[7]; - - for (int t = 0 ; t < 80 ; t++) - { - //see 4.1.1 for the boolops - uint64_t T1 = TR64(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + - sha512table[t] + W[t]); - uint64_t T2 = TR64(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); - h = g; g = f; f = e; e = TR64(d + T1); d = c; c = b; b = a; a = TR64(T1 + T2); - } - - H[0] = TR64(H[0] + a); - H[1] = TR64(H[1] + b); - H[2] = TR64(H[2] + c); - H[3] = TR64(H[3] + d); - H[4] = TR64(H[4] + e); - H[5] = TR64(H[5] + f); - H[6] = TR64(H[6] + g); - H[7] = TR64(H[7] + h); -} - - - -/** - * - */ -std::vector Sha512::finish() -{ - //save our size before padding - getBitCount(); - - // Pad with a binary 1 (0x80) - update(0x80); - //append 0's to make a 112-byte buf. - //we will loop around once if already over 112 - while ((nrBytes & 127) != 112) - update(0); - - //append 128-bit size - //64 upper bits - for (int i = 0 ; i < 8 ; i++) - update((unsigned char)0x00); - //64 lower bits - //##### Append length in bits - appendBitCount(); - - // Output hash - std::vector ret; - for (int i = 0 ; i < 8 ; i++) - { - ret.push_back((unsigned char)((hashBuf[i] >> 56) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 48) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 40) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 32) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - } - - // Re-initialize the context (also zeroizes contents) - reset(); - - return ret; - -} - - - -//######################################################################## -//## M D 5 -//######################################################################## - -/** - * - */ -void Md5::reset() -{ - hashBuf[0] = 0x67452301; - hashBuf[1] = 0xefcdab89; - hashBuf[2] = 0x98badcfe; - hashBuf[3] = 0x10325476; - - for (int i=0 ; i<16 ; i++) - inBuf[i] = 0; - for (int i=0 ; i<4 ; i++) - inb[i] = 0; - - clearByteCount(); - - byteNr = 0; - longNr = 0; -} - - -/** - * - */ -void Md5::update(unsigned char ch) -{ - incByteCount(); - - //pack 64 bytes into 16 longs - inb[byteNr++] = (uint32_t)ch; - if (byteNr >= 4) - { - //note the little-endianness - uint32_t val = - inb[3] << 24 | inb[2] << 16 | inb[1] << 8 | inb[0]; - inBuf[longNr++] = val; - byteNr = 0; - } - if (longNr >= 16) - { - transform(); - longNr = 0; - } -} - - - -//# The four core functions - F1 is optimized somewhat - -// #define F1(x, y, z) (x & y | ~x & z) -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -// ## This is the central step in the MD5 algorithm. -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w = TR32(w + (f(x, y, z) + data)), w = w<>(32-s), w = TR32(w + x) ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - * @parm buf points to an array of 4 unsigned 32bit (at least) integers - * @parm in points to an array of 16 unsigned 32bit (at least) integers - */ -void Md5::transform() -{ - uint32_t *i = inBuf; - uint32_t a = hashBuf[0]; - uint32_t b = hashBuf[1]; - uint32_t c = hashBuf[2]; - uint32_t d = hashBuf[3]; - - MD5STEP(F1, a, b, c, d, i[ 0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, i[ 1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, i[ 2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, i[ 3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, i[ 4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, i[ 5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, i[ 6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, i[ 7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, i[ 8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, i[ 9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, i[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, i[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, i[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, i[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, i[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, i[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, i[ 1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, i[ 6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, i[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, i[ 0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, i[ 5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, i[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, i[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, i[ 4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, i[ 9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, i[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, i[ 3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, i[ 8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, i[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, i[ 2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, i[ 7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, i[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, i[ 5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, i[ 8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, i[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, i[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, i[ 1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, i[ 4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, i[ 7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, i[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, i[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, i[ 0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, i[ 3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, i[ 6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, i[ 9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, i[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, i[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, i[ 2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, i[ 0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, i[ 7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, i[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, i[ 5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, i[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, i[ 3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, i[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, i[ 1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, i[ 8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, i[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, i[ 6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, i[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, i[ 4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, i[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, i[ 2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, i[ 9] + 0xeb86d391, 21); - - hashBuf[0] = TR32(hashBuf[0] + a); - hashBuf[1] = TR32(hashBuf[1] + b); - hashBuf[2] = TR32(hashBuf[2] + c); - hashBuf[3] = TR32(hashBuf[3] + d); -} - - -/** - * - */ -std::vector Md5::finish() -{ - //snapshot the bit count now before padding - getBitCount(); - - //Append terminal char - update(0x80); - - //pad until we have a 56 of 64 bytes, allowing for 8 bytes at the end - while (longNr != 14) - update(0); - - //##### Append length in bits - // Don't use appendBitCount(), since md5 is little-endian - update((unsigned char)((nrBits ) & 0xff)); - update((unsigned char)((nrBits>> 8) & 0xff)); - update((unsigned char)((nrBits>>16) & 0xff)); - update((unsigned char)((nrBits>>24) & 0xff)); - update((unsigned char)((nrBits>>32) & 0xff)); - update((unsigned char)((nrBits>>40) & 0xff)); - update((unsigned char)((nrBits>>48) & 0xff)); - update((unsigned char)((nrBits>>56) & 0xff)); - - //copy out answer - std::vector res; - for (int i=0 ; i<4 ; i++) - { - //note the little-endianness - res.push_back((unsigned char)((hashBuf[i] ) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); - res.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); - } - - reset(); // Security! ;-) - - return res; -} - - - - - - -//######################################################################## -//## T E S T S -//######################################################################## - -/** - * Compile this file alone with -DDIGEST_TEST to run the - * tests below: - * > gcc -DDIGEST_TEST digest.cpp -o testdigest - * > testdigest - * - * If you add any new algorithms to this suite, then it is highly - * recommended that you add it to these tests and run it. - */ - -#ifdef DIGEST_TEST - - -typedef struct -{ - const char *msg; - const char *val; -} TestPair; - -static TestPair md5tests[] = -{ - { - "", - "d41d8cd98f00b204e9800998ecf8427e" - }, - { - "a", - "0cc175b9c0f1b6a831c399e269772661" - }, - { - "abc", - "900150983cd24fb0d6963f7d28e17f72" - }, - { - "message digest", - "f96b697d7cb7938d525a2f31aaf161d0" - }, - { - "abcdefghijklmnopqrstuvwxyz", - "c3fcd3d76192e4007dfb496cca67e13b" - }, - { - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f" - }, - { - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "57edf4a22be3c955ac49da2e2107b67a" - }, - { - NULL, - NULL - } -}; - - - -static TestPair sha1tests[] = -{ - { - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1" - }, - { - NULL, - NULL - } -}; - -static TestPair sha224tests[] = -{ - { - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" - }, - { - NULL, - NULL - } -}; - -static TestPair sha256tests[] = -{ - { - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" - }, - { - NULL, - NULL - } -}; - -static TestPair sha384tests[] = -{ - { - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", - "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712" - "fcc7c71a557e2db966c3e9fa91746039" - }, - { - NULL, - NULL - } -}; - -static TestPair sha512tests[] = -{ - { - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", - "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" - "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" - }, - { - NULL, - NULL - } -}; - - -bool hashTests(Digest &digest, TestPair *tp) -{ - for (TestPair *pair = tp ; pair->msg ; pair++) - { - digest.reset(); - std::string msg = pair->msg; - std::string val = pair->val; - digest.append(msg); - std::string res = digest.finishHex(); - printf("### Msg '%s':\n hash '%s'\n exp '%s'\n", - msg.c_str(), res.c_str(), val.c_str()); - if (res != val) - { - printf("ERROR: Hash mismatch\n"); - return false; - } - } - return true; -} - - -bool millionATest(Digest &digest, const std::string &exp) -{ - digest.reset(); - for (int i=0 ; i<1000000 ; i++) - digest.append('a'); - std::string res = digest.finishHex(); - printf("\nHash of 1,000,000 'a'\n calc %s\n exp %s\n", - res.c_str(), exp.c_str()); - if (res != exp) - { - printf("ERROR: Mismatch.\n"); - return false; - } - return true; -} - -static bool doTests() -{ - printf("##########################################\n"); - printf("## MD5\n"); - printf("##########################################\n"); - Md5 md5; - if (!hashTests(md5, md5tests)) - return false; - if (!millionATest(md5, "7707d6ae4e027c70eea2a935c2296f21")) - return false; - printf("\n\n\n"); - printf("##########################################\n"); - printf("## SHA1\n"); - printf("##########################################\n"); - Sha1 sha1; - if (!hashTests(sha1, sha1tests)) - return false; - if (!millionATest(sha1, "34aa973cd4c4daa4f61eeb2bdbad27316534016f")) - return false; - printf("\n\n\n"); - printf("##########################################\n"); - printf("## SHA224\n"); - printf("##########################################\n"); - Sha224 sha224; - if (!hashTests(sha224, sha224tests)) - return false; - if (!millionATest(sha224, - "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67")) - return false; - printf("\n\n\n"); - printf("##########################################\n"); - printf("## SHA256\n"); - printf("##########################################\n"); - Sha256 sha256; - if (!hashTests(sha256, sha256tests)) - return false; - if (!millionATest(sha256, - "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0")) - return false; - printf("\n\n\n"); - printf("##########################################\n"); - printf("## SHA384\n"); - printf("##########################################\n"); - Sha384 sha384; - if (!hashTests(sha384, sha384tests)) - return false; - /**/ - if (!millionATest(sha384, - "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b" - "07b8b3dc38ecc4ebae97ddd87f3d8985")) - return false; - /**/ - printf("\n\n\n"); - printf("##########################################\n"); - printf("## SHA512\n"); - printf("##########################################\n"); - Sha512 sha512; - if (!hashTests(sha512, sha512tests)) - return false; - if (!millionATest(sha512, - "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb" - "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b")) - return false; - return true; -} - - -int main(int argc, char **argv) -{ - doTests(); - printf("####### done ########\n"); - return 0; -} - - -#endif /* DIGEST_TEST */ - -//######################################################################## -//## E N D O F F I L E -//######################################################################## diff --git a/src/dom/util/digest.h b/src/dom/util/digest.h deleted file mode 100644 index c161b86bb..000000000 --- a/src/dom/util/digest.h +++ /dev/null @@ -1,654 +0,0 @@ -#ifndef SEEN_DIGEST_H -#define SEEN_DIGEST_H -/* - * - * Author: - * Bob Jamison - * - * Copyright (C) 2006-2008 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * This base class and its subclasses provide an easy API for providing - * several different types of secure hashing functions for whatever use - * a developer might need. This is not intended as a high-performance - * replacement for the fine implementations already available. Rather, it - * is a small and simple (and maybe a bit slow?) tool for moderate common - * hashing requirements, like for communications and authentication. - * - * These hashes are intended to be simple to use. For example: - * Sha256 digest; - * digest.append("The quick brown dog"); - * std::string result = digest.finishHex(); - * - * Or, use one of the static convenience methods: - * - * example: std::string digest = - * Digest::hashHex(Digest::HASH_XXX, str); - * - * ...where HASH_XXX represents one of the hash - * algorithms listed in HashType. - * - * There are several forms of append() for convenience. - * finish() and finishHex() call reset() for both security and - * to prepare for the next use. - * - * - * Much effort has been applied to make this code portable, and it - * has been tested on various 32- and 64-bit machines. If you - * add another algorithm, please test it likewise. - * - * - * The SHA algorithms are derived directly from FIPS-180-3. The - * SHA tests at the bottom of digest.cpp are also directly from - * that document. - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - * - * The MD5 algorithm is from RFC 1321 - * - * To run the tests, compile standalone with -DDIGEST_TEST. Example: - * - * g++ -DDIGEST_TEST digest.cpp -o testdigest - * or - * g++ -DDIGEST_TEST -m64 digest.cpp -o testdigest - * - */ - -#include -#include - -#include - - - -/** - * Base class. Do not use instantiate class directly. Rather, use of of the - * subclasses below, or call one of this class's static convenience methods. - * - * For all subclasses, overload reset(), update(unsigned char), - * transform(), and finish() - */ -class Digest -{ -public: - - /** - * Different types of hash algorithms. - */ - typedef enum - { - HASH_NONE, - HASH_SHA1, - HASH_SHA224, - HASH_SHA256, - HASH_SHA384, - HASH_SHA512, - HASH_MD5 - } HashType; - - /** - * Constructor, with no type - */ - Digest() : hashType(HASH_NONE) - { reset(); } - - /** - * Destructor - */ - virtual ~Digest() - { reset(); } - - /** - * Return one of the enumerated hash types above - */ - virtual int getType() - { return hashType; } - - /** - * Append a single byte to the hash - */ - void append(unsigned char ch) - { update(ch); } - - /** - * Append a string to the hash - */ - virtual void append(const std::string &str) - { - for (unsigned int i=0 ; i &buf) - { //NOTE: function seems to be unused - for (unsigned int i=0 ; i finish() - { - std::vector ret; - return ret; - } - - - //######################## - //# Convenience methods - //######################## - - /** - * Convenience method. This is a simple way of getting a hash. - * Returns a byte buffer with the digest output. - * call with: std::vector digest = - * Digest::hash(Digest::HASH_XXX, buf, len); - */ - static std::vector hash(HashType typ, - unsigned char *buf, - int len); - /** - * Convenience method. This is a simple way of getting a hash. - * Returns a byte buffer with the digest output. - * call with: std::vector digest = - * Digest::hash(Digest::HASH_XXX, str); - */ - static std::vector hash(HashType typ, - const std::string &str); - - /** - * Convenience method. This is a simple way of getting a hash. - * Returns a string with the hexidecimal form of the digest output. - * call with: std::string digest = - * Digest::hash(Digest::HASH_XXX, buf, len); - */ - static std::string hashHex(HashType typ, - unsigned char *buf, - int len); - /** - * Convenience method. This is a simple way of getting a hash. - * Returns a string with the hexidecimal form of the digest output. - * call with: std::string digest = - * Digest::hash(Digest::HASH_XXX, str); - */ - static std::string hashHex(HashType typ, - const std::string &str); - -protected: - - /** - * Update the hash with a given byte - * Overload this in every subclass - */ - virtual void update(unsigned char /*ch*/) - {} - - /** - * Perform the particular block hashing algorithm for a - * particular type of hash. - * Overload this in every subclass - */ - virtual void transform() - {} - - - /** - * The enumerated type of the hash - */ - int hashType; - - /** - * Increment the count of bytes processed so far. Should be called - * in update() - */ - void incByteCount() - { - nrBytes++; - } - - /** - * Clear the byte / bit count information. Both for processing - * another message, also for security. Should be called in reset() - */ - void clearByteCount() - { - nrBytes = nrBits = 0; - } - - /** - * Calculates the bit count from the current byte count. Should be called - * in finish(), before any padding is added. This basically does a - * snapshot of the bitcount value before the padding. - */ - void getBitCount() - { - nrBits = (nrBytes << 3) & 0xFFFFFFFFFFFFFFFFLL; - } - - /** - * Common code for appending the 64-bit bitcount to the end of the - * message, after the padding. Should be called after padding, just - * before outputting the result. - */ - void appendBitCount() - { - update((unsigned char)((nrBits>>56) & 0xff)); - update((unsigned char)((nrBits>>48) & 0xff)); - update((unsigned char)((nrBits>>40) & 0xff)); - update((unsigned char)((nrBits>>32) & 0xff)); - update((unsigned char)((nrBits>>24) & 0xff)); - update((unsigned char)((nrBits>>16) & 0xff)); - update((unsigned char)((nrBits>> 8) & 0xff)); - update((unsigned char)((nrBits ) & 0xff)); - } - - /** - * Bit and byte counts - */ - uint64_t nrBytes; - uint64_t nrBits; -}; - - - - - -/** - * SHA-1, - * Section 6.1, SECURE HASH STANDARD - * Federal Information Processing Standards Publication 180-2 - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - */ -class Sha1 : public Digest -{ -public: - - /** - * Constructor - */ - Sha1() - { hashType = HASH_SHA1; reset(); } - - /** - * Destructor - */ - virtual ~Sha1() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - -private: - - uint32_t hashBuf[5]; - uint32_t inBuf[80]; - - int longNr; - int byteNr; - uint32_t inb[4]; - -}; - - - - - - -/** - * SHA-224, - * Section 6.1, SECURE HASH STANDARD - * Federal Information Processing Standards Publication 180-2 - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - */ -class Sha224 : public Digest -{ -public: - - /** - * Constructor - */ - Sha224() - { hashType = HASH_SHA224; reset(); } - - /** - * Destructor - */ - virtual ~Sha224() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - -private: - - uint32_t hashBuf[8]; - uint32_t inBuf[64]; - int longNr; - int byteNr; - uint32_t inb[4]; - -}; - - - -/** - * SHA-256, - * Section 6.1, SECURE HASH STANDARD - * Federal Information Processing Standards Publication 180-2 - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - */ -class Sha256 : public Digest -{ -public: - - /** - * Constructor - */ - Sha256() - { hashType = HASH_SHA256; reset(); } - - /** - * Destructor - */ - virtual ~Sha256() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - -private: - - uint32_t hashBuf[8]; - uint32_t inBuf[64]; - int longNr; - int byteNr; - uint32_t inb[4]; - -}; - - - -/** - * SHA-384, - * Section 6.1, SECURE HASH STANDARD - * Federal Information Processing Standards Publication 180-2 - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - */ -class Sha384 : public Digest -{ -public: - - /** - * Constructor - */ - Sha384() - { hashType = HASH_SHA384; reset(); } - - /** - * Destructor - */ - virtual ~Sha384() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - - - -private: - - uint64_t hashBuf[8]; - uint64_t inBuf[80]; - int longNr; - int byteNr; - uint64_t inb[8]; - -}; - - - - -/** - * SHA-512, - * Section 6.1, SECURE HASH STANDARD - * Federal Information Processing Standards Publication 180-2 - * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf - */ -class Sha512 : public Digest -{ -public: - - /** - * Constructor - */ - Sha512() - { hashType = HASH_SHA512; reset(); } - - /** - * Destructor - */ - virtual ~Sha512() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - -private: - - uint64_t hashBuf[8]; - uint64_t inBuf[80]; - int longNr; - int byteNr; - uint64_t inb[8]; - -}; - - - - - - - - - -/** - * IETF RFC 1321, MD5 Specification - * http://www.ietf.org/rfc/rfc1321.txt - */ -class Md5 : public Digest -{ -public: - - /** - * Constructor - */ - Md5() - { hashType = HASH_MD5; reset(); } - - /** - * Destructor - */ - virtual ~Md5() - { reset(); } - - /** - * Overloaded from Digest - */ - virtual void reset(); - - /** - * Overloaded from Digest - */ - virtual std::vector finish(); - -protected: - - /** - * Overloaded from Digest - */ - virtual void update(unsigned char val); - - /** - * Overloaded from Digest - */ - virtual void transform(); - -private: - - uint32_t hashBuf[4]; - uint32_t inBuf[16]; - - uint32_t inb[4]; // Buffer for input bytes as longs - int byteNr; // which byte in long - int longNr; // which long in 16-long buffer - -}; - - - - - - - - - -#endif /* __DIGEST_H__ */ - - diff --git a/src/dom/util/thread.cpp b/src/dom/util/thread.cpp deleted file mode 100644 index d5368ef59..000000000 --- a/src/dom/util/thread.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Phoebe DOM Implementation. - * - * This is a C++ approximation of the W3C DOM model, which follows - * fairly closely the specifications in the various .idl files, copies of - * which are provided for reference. Most important is this one: - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * Thread wrapper. This provides a platform-independent thread - * class for IO and testing. - * - */ - -#include "thread.h" -#include -#include - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace util -{ - - -#ifdef __WIN32__ -#include - -static DWORD WINAPI WinThreadFunction(LPVOID context) -{ - Thread *thread = static_cast(context); - thread->execute(); - return 0; -} - - -void Thread::start() -{ - DWORD dwThreadId; - HANDLE hThread = CreateThread(NULL, 0, WinThreadFunction, - (LPVOID)this, 0, &dwThreadId); - //Make sure the thread is started before 'this' is deallocated - while (!started) - sleep(10); - CloseHandle(hThread); -} - -void Thread::sleep(unsigned long millis) -{ - Sleep(millis); -} - - - -#else /* UNIX */ -#include - -void *PthreadThreadFunction(void *context) -{ - Thread *thread = static_cast(context); - thread->execute(); - return NULL; -} - - -void Thread::start() -{ - pthread_t thread; - - int ret = pthread_create(&thread, NULL, - PthreadThreadFunction, (void *)this); - if (ret != 0) - printf("Thread::start: thread creation failed: %s\n", strerror(ret)); - - //Make sure the thread is started before 'this' is deallocated - while (!started) - sleep(10); - -} - -void Thread::sleep(unsigned long millis) -{ - timespec requested; - requested.tv_sec = millis / 1000; - requested.tv_nsec = (millis % 1000 ) * 1000000L; - nanosleep(&requested, NULL); -} - -#endif /* __WIN32__ */ - -} //namespace util -} //namespace dom -} //namespace w3c -} //namespace org - - - -//######################################################################### -//# E N D O F F I L E -//######################################################################### - - diff --git a/src/dom/util/thread.h b/src/dom/util/thread.h deleted file mode 100644 index 1408cd78f..000000000 --- a/src/dom/util/thread.h +++ /dev/null @@ -1,156 +0,0 @@ -#ifndef SEEN_DOM_THREAD_H -#define SEEN_DOM_THREAD_H -/** - * Phoebe DOM Implementation. - * - * This is a C++ approximation of the W3C DOM model, which follows - * fairly closely the specifications in the various .idl files, copies of - * which are provided for reference. Most important is this one: - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Thread wrapper. This provides a platform-independent thread - * class for IO and testing. - * - */ - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace util -{ - - -/** - * This is the interface for a delegate class which can - * be run by a Thread. - * Thread thread(runnable); - * thread.start(); - */ -class Runnable -{ -public: - - Runnable() - {} - virtual ~Runnable() - {} - - /** - * The method of a delegate class which can - * be run by a Thread. Thread is completed when this - * method is done. - */ - virtual void run() = 0; - -}; - - - -/** - * A simple wrapper of native threads in a portable class. - * It can be used either to execute its own run() method, or - * delegate to a Runnable class's run() method. - */ -class Thread -{ -public: - - /** - * Create a thread which will execute its own run() method. - */ - Thread() - { runnable = (Runnable *)0 ; started = false; } - - /** - * Create a thread which will run a Runnable class's run() method. - */ - Thread(const Runnable &runner) - { runnable = (Runnable *)&runner; started = false; } - - /** - * This does not kill a spawned thread. - */ - virtual ~Thread() - {} - - /** - * Static method to pause the current thread for a given - * number of milliseconds. - */ - static void sleep(unsigned long millis); - - /** - * This method will be executed if the Thread was created with - * no delegated Runnable class. The thread is completed when - * the method is done. - */ - virtual void run() - {} - - /** - * Starts the thread. - */ - virtual void start(); - - /** - * Calls either this class's run() method, or that of a Runnable. - * A user would normally not call this directly. - */ - virtual void execute() - { - started = true; - if (runnable) - runnable->run(); - else - run(); - } - -private: - - Runnable *runnable; - - bool started; - -}; - - -} //namespace util -} //namespace dom -} //namespace w3c -} //namespace org - - - -#endif // SEEN_DOM_THREAD_H -//######################################################################### -//# E N D O F F I L E -//######################################################################### - - diff --git a/src/dom/util/ziptool.cpp b/src/dom/util/ziptool.cpp deleted file mode 100644 index 9d9d5685c..000000000 --- a/src/dom/util/ziptool.cpp +++ /dev/null @@ -1,3025 +0,0 @@ -/* - * This is intended to be a standalone, reduced capability - * implementation of Gzip and Zip functionality. Its - * targeted use case is for archiving and retrieving single files - * which use these encoding types. Being memory based and - * non-optimized, it is not useful in cases where very large - * archives are needed or where high performance is desired. - * However, it should hopefully work very well for smaller, - * one-at-a-time tasks. What you get in return is the ability - * to drop these files into your project and remove the dependencies - * on ZLib and Info-Zip. Enjoy. - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include -#include -#include - -#include - -#include "ziptool.h" - - - - - - -//######################################################################## -//# A D L E R 3 2 -//######################################################################## - -/** - * Constructor - */ -Adler32::Adler32() -{ - reset(); -} - -/** - * Destructor - */ -Adler32::~Adler32() -{ -} - -/** - * Reset Adler-32 checksum to initial value. - */ -void Adler32::reset() -{ - value = 1; -} - -// ADLER32_BASE is the largest prime number smaller than 65536 -#define ADLER32_BASE 65521 - -void Adler32::update(unsigned char b) -{ - unsigned long s1 = value & 0xffff; - unsigned long s2 = (value >> 16) & 0xffff; - s1 += b & 0xff; - s2 += s1; - value = ((s2 % ADLER32_BASE) << 16) | (s1 % ADLER32_BASE); -} - -void Adler32::update(char *str) -{ - if (str) - while (*str) - update((unsigned char)*str++); -} - - -/** - * Returns current checksum value. - */ -unsigned long Adler32::getValue() -{ - return value & 0xffffffffL; -} - - - -//######################################################################## -//# C R C 3 2 -//######################################################################## - -/** - * Constructor - */ -Crc32::Crc32() -{ - reset(); -} - -/** - * Destructor - */ -Crc32::~Crc32() -{ -} - -static bool crc_table_ready = false; -static unsigned long crc_table[256]; - -/** - * make the table for a fast CRC. - */ -static void makeCrcTable() -{ - if (crc_table_ready) - return; - for (int n = 0; n < 256; n++) - { - unsigned long c = n; - for (int k = 8; --k >= 0; ) - { - if ((c & 1) != 0) - c = 0xedb88320 ^ (c >> 1); - else - c >>= 1; - } - crc_table[n] = c; - } - crc_table_ready = true; -} - - -/** - * Reset CRC-32 checksum to initial value. - */ -void Crc32::reset() -{ - value = 0; - makeCrcTable(); -} - -void Crc32::update(unsigned char b) -{ - unsigned long c = ~value; - - c &= 0xffffffff; - c = crc_table[(c ^ b) & 0xff] ^ (c >> 8); - value = ~c; -} - - -void Crc32::update(char *str) -{ - if (str) - while (*str) - update((unsigned char)*str++); -} - -void Crc32::update(const std::vector &buf) -{ - std::vector::const_iterator iter; - for (iter=buf.begin() ; iter!=buf.end() ; ++iter) - { - unsigned char ch = *iter; - update(ch); - } -} - - -/** - * Returns current checksum value. - */ -unsigned long Crc32::getValue() -{ - return value & 0xffffffffL; -} - -//######################################################################## -//# I N F L A T E R -//######################################################################## - - -/** - * - */ -typedef struct -{ - int *count; // number of symbols of each length - int *symbol; // canonically ordered symbols -} Huffman; - -/** - * - */ -class Inflater -{ -public: - - Inflater(); - - virtual ~Inflater(); - - static const int MAXBITS = 15; // max bits in a code - static const int MAXLCODES = 286; // max number of literal/length codes - static const int MAXDCODES = 30; // max number of distance codes - static const int MAXCODES = 316; // max codes lengths to read - static const int FIXLCODES = 288; // number of fixed literal/length codes - - /** - * - */ - bool inflate(std::vector &destination, - std::vector &source); - -private: - - /** - * - */ - void error(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - /** - * - */ - void trace(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - /** - * - */ - void dump(); - - /** - * - */ - int buildHuffman(Huffman *h, int *length, int n); - - /** - * - */ - bool getBits(int need, int *oval); - - /** - * - */ - int doDecode(Huffman *h); - - /** - * - */ - bool doCodes(Huffman *lencode, Huffman *distcode); - - /** - * - */ - bool doStored(); - - /** - * - */ - bool doFixed(); - - /** - * - */ - bool doDynamic(); - - - std::vectordest; - - std::vectorsrc; - unsigned long srcPos; //current read position - int bitBuf; - int bitCnt; - -}; - - -/** - * - */ -Inflater::Inflater() : - dest(), - src(), - srcPos(0), - bitBuf(0), - bitCnt(0) -{ -} - -/** - * - */ -Inflater::~Inflater() -{ -} - -/** - * - */ -void Inflater::error(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "Inflater error:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -/** - * - */ -void Inflater::trace(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "Inflater:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - - -/** - * - */ -void Inflater::dump() -{ - for (unsigned int i=0 ; icount[len] = 0; - for (int symbol = 0; symbol < n; symbol++) - (h->count[length[symbol]])++; // assumes lengths are within bounds - if (h->count[0] == n) // no codes! - { - error("huffman tree will result in failed decode"); - return -1; - } - - // check for an over-subscribed or incomplete set of lengths - int left = 1; // number of possible codes left of current length - for (int len = 1; len <= MAXBITS; len++) - { - left <<= 1; // one more bit, double codes left - left -= h->count[len]; // deduct count from possible codes - if (left < 0) - { - error("huffman over subscribed"); - return -1; - } - } - - // generate offsets into symbol table for each length for sorting - int offs[MAXBITS+1]; //offsets in symbol table for each length - offs[1] = 0; - for (int len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + h->count[len]; - - /* - * put symbols in table sorted by length, by symbol order within each - * length - */ - for (int symbol = 0; symbol < n; symbol++) - if (length[symbol] != 0) - h->symbol[offs[length[symbol]]++] = symbol; - - // return zero for complete set, positive for incomplete set - return left; -} - - -/** - * - */ -bool Inflater::getBits(int requiredBits, int *oval) -{ - long val = bitBuf; - - //add more bytes if needed - while (bitCnt < requiredBits) - { - if (srcPos >= src.size()) - { - error("premature end of input"); - return false; - } - val |= ((long)(src[srcPos++])) << bitCnt; - bitCnt += 8; - } - - //update the buffer and return the data - bitBuf = (int)(val >> requiredBits); - bitCnt -= requiredBits; - *oval = (int)(val & ((1L << requiredBits) - 1)); - - return true; -} - - -/** - * - */ -int Inflater::doDecode(Huffman *h) -{ - int bitTmp = bitBuf; - int left = bitCnt; - int code = 0; - int first = 0; - int index = 0; - int len = 1; - int *next = h->count + 1; - while (true) - { - while (left--) - { - code |= bitTmp & 1; - bitTmp >>= 1; - int count = *next++; - if (code < first + count) - { /* if length len, return symbol */ - bitBuf = bitTmp; - bitCnt = (bitCnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS+1) - len; - if (left == 0) - break; - if (srcPos >= src.size()) - { - error("premature end of input"); - dump(); - return -1; - } - bitTmp = src[srcPos++]; - if (left > 8) - left = 8; - } - - error("no end of block found"); - return -1; -} - -/** - * - */ -bool Inflater::doCodes(Huffman *lencode, Huffman *distcode) -{ - static const int lens[29] = { // Size base for length codes 257..285 - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; - static const int lext[29] = { // Extra bits for length codes 257..285 - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; - static const int dists[30] = { // Offset base for distance codes 0..29 - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577}; - static const int dext[30] = { // Extra bits for distance codes 0..29 - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13}; - - //decode literals and length/distance pairs - while (true) - { - int symbol = doDecode(lencode); - if (symbol == 256) - break; - if (symbol < 0) - { - return false; - } - if (symbol < 256) //literal - { - dest.push_back(symbol); - } - else if (symbol > 256)//length - { - symbol -= 257; - if (symbol >= 29) - { - error("invalid fixed code"); - return false; - } - int ret; - if (!getBits(lext[symbol], &ret)) - return false; - int len = lens[symbol] + ret; - - symbol = doDecode(distcode);//distance - if (symbol < 0) - { - return false; - } - - if (!getBits(dext[symbol], &ret)) - return false; - unsigned int dist = dists[symbol] + ret; - if (dist > dest.size()) - { - error("distance too far back %d/%d", dist, dest.size()); - dump(); - //printf("pos:%d\n", srcPos); - return false; - } - - // copy length bytes from distance bytes back - //dest.push_back('{'); - while (len--) - { - dest.push_back(dest[dest.size() - dist]); - } - //dest.push_back('}'); - - } - } - - return true; -} - -/** - */ -bool Inflater::doStored() -{ - //trace("### stored ###"); - - // clear bits from current byte - bitBuf = 0; - bitCnt = 0; - - // length - if (srcPos + 4 > src.size()) - { - error("not enough input"); - return false; - } - - int len = src[srcPos++]; - len |= src[srcPos++] << 8; - //trace("### len:%d", len); - // check complement - if (src[srcPos++] != (~len & 0xff) || - src[srcPos++] != ((~len >> 8) & 0xff)) - { - error("twos complement for storage size do not match"); - return false; - } - - // copy data - if (srcPos + len > src.size()) - { - error("Not enough input for stored block"); - return false; - } - while (len--) - dest.push_back(src[srcPos++]); - - return true; -} - -/** - */ -bool Inflater::doFixed() -{ - //trace("### fixed ###"); - - static bool firstTime = true; - static int lencnt[MAXBITS+1], lensym[FIXLCODES]; - static int distcnt[MAXBITS+1], distsym[MAXDCODES]; - static Huffman lencode = {lencnt, lensym}; - static Huffman distcode = {distcnt, distsym}; - - if (firstTime) - { - firstTime = false; - - int lengths[FIXLCODES]; - - // literal/length table - int symbol = 0; - for ( ; symbol < 144; symbol++) - lengths[symbol] = 8; - for ( ; symbol < 256; symbol++) - lengths[symbol] = 9; - for ( ; symbol < 280; symbol++) - lengths[symbol] = 7; - for ( ; symbol < FIXLCODES; symbol++) - lengths[symbol] = 8; - buildHuffman(&lencode, lengths, FIXLCODES); - - // distance table - for (int symbol = 0; symbol < MAXDCODES; symbol++) - lengths[symbol] = 5; - buildHuffman(&distcode, lengths, MAXDCODES); - } - - // decode data until end-of-block code - bool ret = doCodes(&lencode, &distcode); - return ret; -} - -/** - */ -bool Inflater::doDynamic() -{ - //trace("### dynamic ###"); - int lengths[MAXCODES]; // descriptor code lengths - int lencnt[MAXBITS+1], lensym[MAXLCODES]; // lencode memory - int distcnt[MAXBITS+1], distsym[MAXDCODES]; // distcode memory - Huffman lencode = {lencnt, lensym}; // length code - Huffman distcode = {distcnt, distsym}; // distance code - static const int order[19] = // permutation of code length codes - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - // get number of lengths in each table, check lengths - int ret; - if (!getBits(5, &ret)) - return false; - int nlen = ret + 257; - if (!getBits(5, &ret)) - return false; - int ndist = ret + 1; - if (!getBits(4, &ret)) - return false; - int ncode = ret + 4; - if (nlen > MAXLCODES || ndist > MAXDCODES) - { - error("Bad codes"); - return false; - } - - // get code length code lengths - int index = 0; - for ( ; index < ncode; index++) - { - if (!getBits(3, &ret)) - return false; - lengths[order[index]] = ret; - } - for ( ; index < 19; index++) - lengths[order[index]] = 0; - - // build huffman table for code lengths codes - if (buildHuffman(&lencode, lengths, 19) != 0) - return false; - - // read length/literal and distance code length tables - index = 0; - while (index < nlen + ndist) - { - int symbol = doDecode(&lencode); - if (symbol < 16) // length in 0..15 - lengths[index++] = symbol; - else - { // repeat instruction - int len = 0; // assume repeating zeros - if (symbol == 16) - { // repeat last length 3..6 times - if (index == 0) - { - error("no last length"); - return false; - } - len = lengths[index - 1];// last length - if (!getBits(2, &ret)) - return false; - symbol = 3 + ret; - } - else if (symbol == 17) // repeat zero 3..10 times - { - if (!getBits(3, &ret)) - return false; - symbol = 3 + ret; - } - else // == 18, repeat zero 11..138 times - { - if (!getBits(7, &ret)) - return false; - symbol = 11 + ret; - } - if (index + symbol > nlen + ndist) - { - error("too many lengths"); - return false; - } - while (symbol--) // repeat last or zero symbol times - lengths[index++] = len; - } - } - - // build huffman table for literal/length codes - int err = buildHuffman(&lencode, lengths, nlen); - if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) - { - error("incomplete length codes"); - //return false; - } - // build huffman table for distance codes - err = buildHuffman(&distcode, lengths + nlen, ndist); - if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) - { - error("incomplete dist codes"); - return false; - } - - // decode data until end-of-block code - bool retn = doCodes(&lencode, &distcode); - return retn; -} - -/** - */ -bool Inflater::inflate(std::vector &destination, - std::vector &source) -{ - dest.clear(); - src = source; - srcPos = 0; - bitBuf = 0; - bitCnt = 0; - - while (true) - { - int last; // one if last block - if (!getBits(1, &last)) - return false; - int type; // block type 0..3 - if (!getBits(2, &type)) - return false; - switch (type) - { - case 0: - if (!doStored()) - return false; - break; - case 1: - if (!doFixed()) - return false; - break; - case 2: - if (!doDynamic()) - return false; - break; - default: - error("Unknown block type %d", type); - return false; - } - if (last) - break; - } - - destination = dest; - - return true; -} - - - - - - -//######################################################################## -//# D E F L A T E R -//######################################################################## - - -#define DEFLATER_BUF_SIZE 32768 -class Deflater -{ -public: - - /** - * - */ - Deflater(); - - /** - * - */ - virtual ~Deflater(); - - /** - * - */ - virtual void reset(); - - /** - * - */ - virtual bool update(int ch); - - /** - * - */ - virtual bool finish(); - - /** - * - */ - virtual std::vector &getCompressed(); - - /** - * - */ - bool deflate(std::vector &dest, - const std::vector &src); - - void encodeDistStatic(unsigned int len, unsigned int dist); - -private: - - //debug messages - void error(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - void trace(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - bool compressWindow(); - - bool compress(); - - std::vector compressed; - - std::vector uncompressed; - - std::vector window; - - unsigned int windowPos; - - //#### Output - unsigned int outputBitBuf; - unsigned int outputNrBits; - - void put(int ch); - - void putWord(int ch); - - void putFlush(); - - void putBits(unsigned int ch, unsigned int bitsWanted); - - void putBitsR(unsigned int ch, unsigned int bitsWanted); - - //#### Huffman Encode - void encodeLiteralStatic(unsigned int ch); - - unsigned char windowBuf[DEFLATER_BUF_SIZE]; - //assume 32-bit ints - unsigned int windowHashBuf[DEFLATER_BUF_SIZE]; -}; - - -//######################################################################## -//# A P I -//######################################################################## - - -/** - * - */ -Deflater::Deflater() -{ - reset(); -} - -/** - * - */ -Deflater::~Deflater() -{ - -} - -/** - * - */ -void Deflater::reset() -{ - compressed.clear(); - uncompressed.clear(); - window.clear(); - windowPos = 0; - outputBitBuf = 0; - outputNrBits = 0; - for (int k=0; k &Deflater::getCompressed() -{ - return compressed; -} - - -/** - * - */ -bool Deflater::deflate(std::vector &dest, - const std::vector &src) -{ - reset(); - uncompressed = src; - if (!compress()) - return false; - dest = compressed; - return true; -} - - - - - - - -//######################################################################## -//# W O R K I N G C O D E -//######################################################################## - - -//############################# -//# M E S S A G E S -//############################# - -/** - * Print error messages - */ -void Deflater::error(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "Deflater error:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -/** - * Print trace messages - */ -void Deflater::trace(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "Deflater:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - - - - -//############################# -//# O U T P U T -//############################# - -/** - * - */ -void Deflater::put(int ch) -{ - compressed.push_back(ch); - outputBitBuf = 0; - outputNrBits = 0; -} - -/** - * - */ -void Deflater::putWord(int ch) -{ - int lo = (ch ) & 0xff; - int hi = (ch>>8) & 0xff; - put(lo); - put(hi); -} - -/** - * - */ -void Deflater::putFlush() -{ - if (outputNrBits > 0) - { - put(outputBitBuf & 0xff); - } - outputBitBuf = 0; - outputNrBits = 0; -} - -/** - * - */ -void Deflater::putBits(unsigned int ch, unsigned int bitsWanted) -{ - //trace("n:%4u, %d\n", ch, bitsWanted); - - while (bitsWanted--) - { - //add bits to position 7. shift right - outputBitBuf = (outputBitBuf>>1) + (ch<<7 & 0x80); - ch >>= 1; - outputNrBits++; - if (outputNrBits >= 8) - { - unsigned char b = outputBitBuf & 0xff; - //printf("b:%02x\n", b); - put(b); - } - } -} - -static unsigned int bitReverse(unsigned int code, unsigned int nrBits) -{ - unsigned int outb = 0; - while (nrBits--) - { - outb = (outb << 1) | (code & 0x01); - code >>= 1; - } - return outb; -} - - -/** - * - */ -void Deflater::putBitsR(unsigned int ch, unsigned int bitsWanted) -{ - //trace("r:%4u, %d", ch, bitsWanted); - - unsigned int rcode = bitReverse(ch, bitsWanted); - - putBits(rcode, bitsWanted); - -} - - -//############################# -//# E N C O D E -//############################# - - - -void Deflater::encodeLiteralStatic(unsigned int ch) -{ - //trace("c: %d", ch); - - if (ch < 144) - { - putBitsR(ch + 0x0030 , 8); // 00110000 - } - else if (ch < 256) - { - putBitsR(ch - 144 + 0x0190 , 9); // 110010000 - } - else if (ch < 280) - { - putBitsR(ch - 256 + 0x0000 , 7); // 0000000 - } - else if (ch < 288) - { - putBitsR(ch - 280 + 0x00c0 , 8); // 11000000 - } - else //out of range - { - error("Literal out of range: %d", ch); - } - -} - - -typedef struct -{ - unsigned int base; - unsigned int range; - unsigned int bits; -} LenBase; - -LenBase lenBases[] = -{ - { 3, 1, 0 }, - { 4, 1, 0 }, - { 5, 1, 0 }, - { 6, 1, 0 }, - { 7, 1, 0 }, - { 8, 1, 0 }, - { 9, 1, 0 }, - { 10, 1, 0 }, - { 11, 2, 1 }, - { 13, 2, 1 }, - { 15, 2, 1 }, - { 17, 2, 1 }, - { 19, 4, 2 }, - { 23, 4, 2 }, - { 27, 4, 2 }, - { 31, 4, 2 }, - { 35, 8, 3 }, - { 43, 8, 3 }, - { 51, 8, 3 }, - { 59, 8, 3 }, - { 67, 16, 4 }, - { 83, 16, 4 }, - { 99, 16, 4 }, - { 115, 16, 4 }, - { 131, 32, 5 }, - { 163, 32, 5 }, - { 195, 32, 5 }, - { 227, 32, 5 }, - { 258, 1, 0 } -}; - -typedef struct -{ - unsigned int base; - unsigned int range; - unsigned int bits; -} DistBase; - -DistBase distBases[] = -{ - { 1, 1, 0 }, - { 2, 1, 0 }, - { 3, 1, 0 }, - { 4, 1, 0 }, - { 5, 2, 1 }, - { 7, 2, 1 }, - { 9, 4, 2 }, - { 13, 4, 2 }, - { 17, 8, 3 }, - { 25, 8, 3 }, - { 33, 16, 4 }, - { 49, 16, 4 }, - { 65, 32, 5 }, - { 97, 32, 5 }, - { 129, 64, 6 }, - { 193, 64, 6 }, - { 257, 128, 7 }, - { 385, 128, 7 }, - { 513, 256, 8 }, - { 769, 256, 8 }, - { 1025, 512, 9 }, - { 1537, 512, 9 }, - { 2049, 1024, 10 }, - { 3073, 1024, 10 }, - { 4097, 2048, 11 }, - { 6145, 2048, 11 }, - { 8193, 4096, 12 }, - { 12289, 4096, 12 }, - { 16385, 8192, 13 }, - { 24577, 8192, 13 } -}; - -void Deflater::encodeDistStatic(unsigned int len, unsigned int dist) -{ - - //## Output length - - if (len < 3 || len > 258) - { - error("Length out of range:%d", len); - return; - } - - bool found = false; - for (int i=0 ; i<30 ; i++) - { - unsigned int base = lenBases[i].base; - unsigned int range = lenBases[i].range; - if (base + range > len) - { - unsigned int lenCode = 257 + i; - unsigned int length = len - base; - //trace("--- %d %d %d %d", len, base, range, length); - encodeLiteralStatic(lenCode); - putBits(length, lenBases[i].bits); - found = true; - break; - } - } - if (!found) - { - error("Length not found in table:%d", len); - return; - } - - //## Output distance - - if (dist < 4 || dist > 32768) - { - error("Distance out of range:%d", dist); - return; - } - - found = false; - for (int i=0 ; i<30 ; i++) - { - unsigned int base = distBases[i].base; - unsigned int range = distBases[i].range; - if (base + range > dist) - { - unsigned int distCode = i; - unsigned int distance = dist - base; - //error("--- %d %d %d %d", dist, base, range, distance); - putBitsR(distCode, 5); - putBits(distance, distBases[i].bits); - found = true; - break; - } - } - if (!found) - { - error("Distance not found in table:%d", dist); - return; - } -} - - -//############################# -//# C O M P R E S S -//############################# - - -/** - * This method does the dirty work of dictionary - * compression. Basically it looks for redundant - * strings and has the current duplicate refer back - * to the previous one. - */ -bool Deflater::compressWindow() -{ - windowPos = 0; - unsigned int windowSize = window.size(); - //### Compress as much of the window as possible - - unsigned int hash = 0; - //Have each value be a long with the byte at this position, - //plus the 3 bytes after it in the window - for (int i=windowSize-1 ; i>=0 ; i--) - { - unsigned char ch = window[i]; - windowBuf[i] = ch; - hash = ((hash<<8) & 0xffffff00) | ch; - windowHashBuf[i] = hash; - } - - while (windowPos < windowSize - 3) - { - //### Find best match, if any - unsigned int bestMatchLen = 0; - unsigned int bestMatchDist = 0; - if (windowPos >= 4) - { - for (unsigned int lookBack=0 ; lookBack= windowPos -4 ) - lookAheadMax = windowPos - 4 - lookBack; - if (lookAheadMax > 258) - lookAheadMax = 258; - unsigned char *wp = &(windowBuf[windowPos+4]); - unsigned char *lb = &(windowBuf[lookBack+4]); - while (lookAhead bestMatchLen) - { - bestMatchLen = lookAhead; - bestMatchDist = windowPos - lookBack; - } - } - } - } - if (bestMatchLen > 3) - { - //Distance encode - //trace("### distance"); - /* - printf("### 1 '"); - for (int i=0 ; i < bestMatchLen ; i++) - fputc(window[windowPos+i], stdout); - printf("'\n### 2 '"); - for (int i=0 ; i < bestMatchLen ; i++) - fputc(window[windowPos-bestMatchDist+i], stdout); - printf("'\n"); - */ - encodeDistStatic(bestMatchLen, bestMatchDist); - windowPos += bestMatchLen; - } - else - { - //Literal encode - //trace("### literal"); - encodeLiteralStatic(windowBuf[windowPos]); - windowPos++; - } - } - - while (windowPos < windowSize) - encodeLiteralStatic(windowBuf[windowPos++]); - - encodeLiteralStatic(256); - return true; -} - - -/** - * - */ -bool Deflater::compress() -{ - //trace("compress"); - unsigned long total = 0L; - windowPos = 0; - std::vector::iterator iter; - for (iter = uncompressed.begin(); iter != uncompressed.end() ; ) - { - total += windowPos; - trace("total:%ld", total); - if (windowPos > window.size()) - windowPos = window.size(); - window.erase(window.begin() , window.begin()+windowPos); - while (window.size() < 32768 && iter != uncompressed.end()) - { - window.push_back(*iter); - ++iter; - } - if (window.size() >= 32768) - putBits(0x00, 1); //0 -- more blocks - else - putBits(0x01, 1); //1 -- last block - putBits(0x01, 2); //01 -- static trees - if (!compressWindow()) - return false; - } - putFlush(); - return true; -} - - - - - -//######################################################################## -//# G Z I P F I L E -//######################################################################## - -/** - * Constructor - */ -GzipFile::GzipFile() : - data(), - fileName(), - fileBuf(), - fileBufPos(0), - compressionMethod(0) -{ -} - -/** - * Destructor - */ -GzipFile::~GzipFile() -{ -} - -/** - * Print error messages - */ -void GzipFile::error(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "GzipFile error:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -/** - * Print trace messages - */ -void GzipFile::trace(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "GzipFile:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -/** - * - */ -void GzipFile::put(unsigned char ch) -{ - data.push_back(ch); -} - -/** - * - */ -void GzipFile::setData(const std::vector &str) -{ - data = str; -} - -/** - * - */ -void GzipFile::clearData() -{ - data.clear(); -} - -/** - * - */ -std::vector &GzipFile::getData() -{ - return data; -} - -/** - * - */ -std::string &GzipFile::getFileName() -{ - return fileName; -} - -/** - * - */ -void GzipFile::setFileName(const std::string &val) -{ - fileName = val; -} - - - -//##################################### -//# U T I L I T Y -//##################################### - -/** - * Loads a new file into an existing GzipFile - */ -bool GzipFile::loadFile(const std::string &fName) -{ - FILE *f = fopen(fName.c_str() , "rb"); - if (!f) - { - error("Cannot open file %s", fName.c_str()); - return false; - } - while (true) - { - int ch = fgetc(f); - if (ch < 0) - break; - data.push_back(ch); - } - fclose(f); - setFileName(fName); - return true; -} - - - -//##################################### -//# W R I T E -//##################################### - -/** - * - */ -bool GzipFile::putByte(unsigned char ch) -{ - fileBuf.push_back(ch); - return true; -} - - - -/** - * - */ -bool GzipFile::putLong(unsigned long val) -{ - fileBuf.push_back( (unsigned char)((val ) & 0xff)); - fileBuf.push_back( (unsigned char)((val>> 8) & 0xff)); - fileBuf.push_back( (unsigned char)((val>>16) & 0xff)); - fileBuf.push_back( (unsigned char)((val>>24) & 0xff)); - return true; -} - - - -/** - * - */ -bool GzipFile::write() -{ - fileBuf.clear(); - - putByte(0x1f); //magic - putByte(0x8b); //magic - putByte( 8); //compression method - putByte(0x08); //flags. say we have a crc and file name - - unsigned long ltime = (unsigned long) time(NULL); - putLong(ltime); - - //xfl - putByte(0); - //OS - putByte(0); - - //file name - for (unsigned int i=0 ; i compBuf; - Deflater deflater; - if (!deflater.deflate(compBuf, data)) - { - return false; - } - - std::vector::iterator iter; - for (iter=compBuf.begin() ; iter!=compBuf.end() ; ++iter) - { - unsigned char ch = *iter; - putByte(ch); - } - - Crc32 crcEngine; - crcEngine.update(data); - unsigned long crc = crcEngine.getValue(); - putLong(crc); - - putLong(data.size()); - - return true; -} - - -/** - * - */ -bool GzipFile::writeBuffer(std::vector &outBuf) -{ - if (!write()) - return false; - outBuf.clear(); - outBuf = fileBuf; - return true; -} - - -/** - * - */ -bool GzipFile::writeFile(const std::string &fileName) -{ - if (!write()) - return false; - FILE *f = fopen(fileName.c_str(), "wb"); - if (!f) - return false; - std::vector::iterator iter; - for (iter=fileBuf.begin() ; iter!=fileBuf.end() ; ++iter) - { - unsigned char ch = *iter; - fputc(ch, f); - } - fclose(f); - return true; -} - - -//##################################### -//# R E A D -//##################################### - -bool GzipFile::getByte(unsigned char *ch) -{ - if (fileBufPos >= fileBuf.size()) - { - error("unexpected end of data"); - return false; - } - *ch = fileBuf[fileBufPos++]; - return true; -} - -/** - * - */ -bool GzipFile::getLong(unsigned long *val) -{ - if (fileBuf.size() - fileBufPos < 4) - return false; - int ch1 = fileBuf[fileBufPos++]; - int ch2 = fileBuf[fileBufPos++]; - int ch3 = fileBuf[fileBufPos++]; - int ch4 = fileBuf[fileBufPos++]; - *val = ((ch4<<24) & 0xff000000L) | - ((ch3<<16) & 0x00ff0000L) | - ((ch2<< 8) & 0x0000ff00L) | - ((ch1 ) & 0x000000ffL); - return true; -} - -bool GzipFile::read() -{ - fileBufPos = 0; - - unsigned char ch; - - //magic cookie - if (!getByte(&ch)) - return false; - if (ch != 0x1f) - { - error("bad gzip header"); - return false; - } - if (!getByte(&ch)) - return false; - if (ch != 0x8b) - { - error("bad gzip header"); - return false; - } - - //## compression method - if (!getByte(&ch)) - return false; - compressionMethod = ch & 0xff; - - //## flags - if (!getByte(&ch)) - return false; - //bool ftext = ch & 0x01; - bool fhcrc = ch & 0x02; - bool fextra = ch & 0x04; - bool fname = ch & 0x08; - bool fcomment = ch & 0x10; - - //trace("cm:%d ftext:%d fhcrc:%d fextra:%d fname:%d fcomment:%d", - // cm, ftext, fhcrc, fextra, fname, fcomment); - - //## file time - unsigned long ltime; - if (!getLong(<ime)) - return false; - //time_t mtime = (time_t)ltime; - - //## XFL - if (!getByte(&ch)) - return false; - //int xfl = ch; - - //## OS - if (!getByte(&ch)) - return false; - //int os = ch; - - //std::string timestr = ctime(&mtime); - //trace("xfl:%d os:%d mtime:%s", xfl, os, timestr.c_str()); - - if (fextra) - { - if (!getByte(&ch)) - return false; - long xlen = ch; - if (!getByte(&ch)) - return false; - xlen = (xlen << 8) + ch; - for (long l=0 ; l compBuf; - while (fileBufPos < fileBuf.size() - 8) - { - if (!getByte(&ch)) - return false; - compBuf.push_back(ch); - } - //uncompress - data.clear(); - Inflater inflater; - if (!inflater.inflate(data, compBuf)) - { - return false; - } - - //Get the CRC and compare - Crc32 crcEngine; - crcEngine.update(data); - unsigned long calcCrc = crcEngine.getValue(); - unsigned long givenCrc; - if (!getLong(&givenCrc)) - return false; - if (givenCrc != calcCrc) - { - error("Specified crc, %ud, not what received: %ud", - givenCrc, calcCrc); - return false; - } - - //Get the file size and compare - unsigned long givenFileSize; - if (!getLong(&givenFileSize)) - return false; - if (givenFileSize != data.size()) - { - error("Specified data size, %ld, not what received: %ld", - givenFileSize, data.size()); - return false; - } - - return true; -} - - - -/** - * - */ -bool GzipFile::readBuffer(const std::vector &inbuf) -{ - fileBuf = inbuf; - if (!read()) - return false; - return true; -} - - -/** - * - */ -bool GzipFile::readFile(const std::string &fileName) -{ - fileBuf.clear(); - FILE *f = fopen(fileName.c_str(), "rb"); - if (!f) - return false; - while (true) - { - int ch = fgetc(f); - if (ch < 0) - break; - fileBuf.push_back(ch); - } - fclose(f); - if (!read()) - return false; - return true; -} - - - - - - - - -//######################################################################## -//# Z I P F I L E -//######################################################################## - -/** - * Constructor - */ -ZipEntry::ZipEntry() -{ - crc = 0L; - compressionMethod = 8; - position = 0; -} - -/** - * - */ -ZipEntry::ZipEntry(const std::string &fileNameArg, - const std::string &commentArg) -{ - crc = 0L; - compressionMethod = 8; - fileName = fileNameArg; - comment = commentArg; - position = 0; -} - -/** - * Destructor - */ -ZipEntry::~ZipEntry() -{ -} - - -/** - * - */ -std::string ZipEntry::getFileName() -{ - return fileName; -} - -/** - * - */ -void ZipEntry::setFileName(const std::string &val) -{ - fileName = val; -} - -/** - * - */ -std::string ZipEntry::getComment() -{ - return comment; -} - -/** - * - */ -void ZipEntry::setComment(const std::string &val) -{ - comment = val; -} - -/** - * - */ -unsigned long ZipEntry::getCompressedSize() -{ - return (unsigned long)compressedData.size(); -} - -/** - * - */ -int ZipEntry::getCompressionMethod() -{ - return compressionMethod; -} - -/** - * - */ -void ZipEntry::setCompressionMethod(int val) -{ - compressionMethod = val; -} - -/** - * - */ -std::vector &ZipEntry::getCompressedData() -{ - return compressedData; -} - -/** - * - */ -void ZipEntry::setCompressedData(const std::vector &val) -{ - compressedData = val; -} - -/** - * - */ -unsigned long ZipEntry::getUncompressedSize() -{ - return (unsigned long)uncompressedData.size(); -} - -/** - * - */ -std::vector &ZipEntry::getUncompressedData() -{ - return uncompressedData; -} - -/** - * - */ -void ZipEntry::setUncompressedData(const std::vector &val) -{ - uncompressedData = val; -} - -/** - * - */ -unsigned long ZipEntry::getCrc() -{ - return crc; -} - -/** - * - */ -void ZipEntry::setCrc(unsigned long val) -{ - crc = val; -} - -/** - * - */ -void ZipEntry::write(unsigned char ch) -{ - uncompressedData.push_back(ch); -} - -/** - * - */ -void ZipEntry::finish() -{ - Crc32 c32; - std::vector::iterator iter; - for (iter = uncompressedData.begin() ; - iter!= uncompressedData.end() ; ++iter) - { - unsigned char ch = *iter; - c32.update(ch); - } - crc = c32.getValue(); - switch (compressionMethod) - { - case 0: //none - { - for (iter = uncompressedData.begin() ; - iter!= uncompressedData.end() ; ++iter) - { - unsigned char ch = *iter; - compressedData.push_back(ch); - } - break; - } - case 8: //deflate - { - Deflater deflater; - if (!deflater.deflate(compressedData, uncompressedData)) - { - //some error - } - break; - } - default: - { - printf("error: unknown compression method %d\n", - compressionMethod); - } - } -} - - - - -/** - * - */ -bool ZipEntry::readFile(const std::string &fileNameArg, - const std::string &commentArg) -{ - crc = 0L; - uncompressedData.clear(); - fileName = fileNameArg; - comment = commentArg; - FILE *f = fopen(fileName.c_str(), "rb"); - if (!f) - { - return false; - } - while (true) - { - int ch = fgetc(f); - if (ch < 0) - break; - uncompressedData.push_back((unsigned char)ch); - } - fclose(f); - finish(); - return true; -} - - -/** - * - */ -void ZipEntry::setPosition(unsigned long val) -{ - position = val; -} - -/** - * - */ -unsigned long ZipEntry::getPosition() -{ - return position; -} - - - - - - - -/** - * Constructor - */ -ZipFile::ZipFile() : - entries(), - fileBuf(), - fileBufPos(0), - comment() -{ -} - -/** - * Destructor - */ -ZipFile::~ZipFile() -{ - std::vector::iterator iter; - for (iter=entries.begin() ; iter!=entries.end() ; ++iter) - { - ZipEntry *entry = *iter; - delete entry; - } - entries.clear(); -} - -/** - * - */ -void ZipFile::setComment(const std::string &val) -{ - comment = val; -} - -/** - * - */ -std::string ZipFile::getComment() -{ - return comment; -} - - -/** - * - */ -std::vector &ZipFile::getEntries() -{ - return entries; -} - - - -//##################################### -//# M E S S A G E S -//##################################### - -void ZipFile::error(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "ZipFile error:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -void ZipFile::trace(char const *fmt, ...) -{ - va_list args; - va_start(args, fmt); - fprintf(stdout, "ZipFile:"); - vfprintf(stdout, fmt, args); - fprintf(stdout, "\n"); - va_end(args); -} - -//##################################### -//# U T I L I T Y -//##################################### - -/** - * - */ -ZipEntry *ZipFile::addFile(const std::string &fileName, - const std::string &comment) -{ - ZipEntry *ze = new ZipEntry(); - if (!ze->readFile(fileName, comment)) - { - delete ze; - return NULL; - } - entries.push_back(ze); - return ze; -} - - -/** - * - */ -ZipEntry *ZipFile::newEntry(const std::string &fileName, - const std::string &comment) -{ - ZipEntry *ze = new ZipEntry(fileName, comment); - entries.push_back(ze); - return ze; -} - - -//##################################### -//# W R I T E -//##################################### - -/** - * - */ -bool ZipFile::putLong(unsigned long val) -{ - fileBuf.push_back( ((int)(val )) & 0xff); - fileBuf.push_back( ((int)(val>> 8)) & 0xff); - fileBuf.push_back( ((int)(val>>16)) & 0xff); - fileBuf.push_back( ((int)(val>>24)) & 0xff); - return true; -} - - -/** - * - */ -bool ZipFile::putInt(unsigned int val) -{ - fileBuf.push_back( (val ) & 0xff); - fileBuf.push_back( (val>> 8) & 0xff); - return true; -} - -/** - * - */ -bool ZipFile::putByte(unsigned char val) -{ - fileBuf.push_back(val); - return true; -} - -/** - * - */ -bool ZipFile::writeFileData() -{ - std::vector::iterator iter; - for (iter = entries.begin() ; iter != entries.end() ; ++iter) - { - ZipEntry *entry = *iter; - entry->setPosition(fileBuf.size()); - //##### HEADER - std::string fname = entry->getFileName(); - putLong(0x04034b50L); - putInt(20); //versionNeeded - putInt(0); //gpBitFlag - //putInt(0); //compression method - putInt(entry->getCompressionMethod()); //compression method - putInt(0); //mod time - putInt(0); //mod date - putLong(entry->getCrc()); //crc32 - putLong(entry->getCompressedSize()); - putLong(entry->getUncompressedSize()); - putInt(fname.size());//fileName length - putInt(8);//extra field length - //file name - for (unsigned int i=0 ; i &buf = entry->getCompressedData(); - std::vector::iterator iter; - for (iter = buf.begin() ; iter != buf.end() ; ++iter) - { - unsigned char ch = (unsigned char) *iter; - putByte(ch); - } - } - return true; -} - -/** - * - */ -bool ZipFile::writeCentralDirectory() -{ - unsigned long cdPosition = fileBuf.size(); - std::vector::iterator iter; - for (iter = entries.begin() ; iter != entries.end() ; ++iter) - { - ZipEntry *entry = *iter; - std::string fname = entry->getFileName(); - std::string ecomment = entry->getComment(); - putLong(0x02014b50L); //magic cookie - putInt(2386); //versionMadeBy - putInt(20); //versionNeeded - putInt(0); //gpBitFlag - putInt(entry->getCompressionMethod()); //compression method - putInt(0); //mod time - putInt(0); //mod date - putLong(entry->getCrc()); //crc32 - putLong(entry->getCompressedSize()); - putLong(entry->getUncompressedSize()); - putInt(fname.size());//fileName length - putInt(4);//extra field length - putInt(ecomment.size());//comment length - putInt(0); //disk number start - putInt(0); //internal attributes - putLong(0); //external attributes - putLong(entry->getPosition()); - - //file name - for (unsigned int i=0 ; i &outBuf) -{ - if (!write()) - return false; - outBuf.clear(); - outBuf = fileBuf; - return true; -} - - -/** - * - */ -bool ZipFile::writeFile(const std::string &fileName) -{ - if (!write()) - return false; - FILE *f = fopen(fileName.c_str(), "wb"); - if (!f) - return false; - std::vector::iterator iter; - for (iter=fileBuf.begin() ; iter!=fileBuf.end() ; ++iter) - { - unsigned char ch = *iter; - fputc(ch, f); - } - fclose(f); - return true; -} - -//##################################### -//# R E A D -//##################################### - -/** - * - */ -bool ZipFile::getLong(unsigned long *val) -{ - if (fileBuf.size() - fileBufPos < 4) - return false; - int ch1 = fileBuf[fileBufPos++]; - int ch2 = fileBuf[fileBufPos++]; - int ch3 = fileBuf[fileBufPos++]; - int ch4 = fileBuf[fileBufPos++]; - *val = ((ch4<<24) & 0xff000000L) | - ((ch3<<16) & 0x00ff0000L) | - ((ch2<< 8) & 0x0000ff00L) | - ((ch1 ) & 0x000000ffL); - return true; -} - -/** - * - */ -bool ZipFile::getInt(unsigned int *val) -{ - if (fileBuf.size() - fileBufPos < 2) - return false; - int ch1 = fileBuf[fileBufPos++]; - int ch2 = fileBuf[fileBufPos++]; - *val = ((ch2<< 8) & 0xff00) | - ((ch1 ) & 0x00ff); - return true; -} - - -/** - * - */ -bool ZipFile::getByte(unsigned char *val) -{ - if (fileBuf.size() <= fileBufPos) - return false; - *val = fileBuf[fileBufPos++]; - return true; -} - - -/** - * - */ -bool ZipFile::readFileData() -{ - //printf("#################################################\n"); - //printf("###D A T A\n"); - //printf("#################################################\n"); - while (true) - { - unsigned long magicCookie; - if (!getLong(&magicCookie)) - { - error("magic cookie not found"); - break; - } - trace("###Cookie:%lx", magicCookie); - if (magicCookie == 0x02014b50L) //central directory - break; - if (magicCookie != 0x04034b50L) - { - error("file header not found"); - return false; - } - unsigned int versionNeeded; - if (!getInt(&versionNeeded)) - { - error("bad version needed found"); - return false; - } - unsigned int gpBitFlag; - if (!getInt(&gpBitFlag)) - { - error("bad bit flag found"); - return false; - } - unsigned int compressionMethod; - if (!getInt(&compressionMethod)) - { - error("bad compressionMethod found"); - return false; - } - unsigned int modTime; - if (!getInt(&modTime)) - { - error("bad modTime found"); - return false; - } - unsigned int modDate; - if (!getInt(&modDate)) - { - error("bad modDate found"); - return false; - } - unsigned long crc32; - if (!getLong(&crc32)) - { - error("bad crc32 found"); - return false; - } - unsigned long compressedSize; - if (!getLong(&compressedSize)) - { - error("bad compressedSize found"); - return false; - } - unsigned long uncompressedSize; - if (!getLong(&uncompressedSize)) - { - error("bad uncompressedSize found"); - return false; - } - unsigned int fileNameLength; - if (!getInt(&fileNameLength)) - { - error("bad fileNameLength found"); - return false; - } - unsigned int extraFieldLength; - if (!getInt(&extraFieldLength)) - { - error("bad extraFieldLength found"); - return false; - } - std::string fileName; - for (unsigned int i=0 ; i compBuf; - if (gpBitFlag & 0x8)//bit 3 was set. means we dont know compressed size - { - unsigned char c1, c2, c3, c4; - c1 = c2 = c3 = c4 = 0; - while (true) - { - unsigned char ch; - if (!getByte(&ch)) - { - error("premature end of data"); - break; - } - compBuf.push_back(ch); - c1 = c2; c2 = c3; c3 = c4; c4 = ch; - if (c1 == 0x50 && c2 == 0x4b && c3 == 0x07 && c4 == 0x08) - { - trace("found end of compressed data"); - //remove the cookie - compBuf.erase(compBuf.end() -4, compBuf.end()); - break; - } - } - } - else - { - for (unsigned long bnr = 0 ; bnr < compressedSize ; bnr++) - { - unsigned char ch; - if (!getByte(&ch)) - { - error("premature end of data"); - break; - } - compBuf.push_back(ch); - } - } - - printf("### data: "); - for (int i=0 ; i<10 ; i++) - printf("%02x ", compBuf[i] & 0xff); - printf("\n"); - - if (gpBitFlag & 0x8)//only if bit 3 set - { - /* this cookie was read in the loop above - unsigned long dataDescriptorSignature ; - if (!getLong(&dataDescriptorSignature)) - break; - if (dataDescriptorSignature != 0x08074b50L) - { - error("bad dataDescriptorSignature found"); - return false; - } - */ - unsigned long crc32; - if (!getLong(&crc32)) - { - error("bad crc32 found"); - return false; - } - unsigned long compressedSize; - if (!getLong(&compressedSize)) - { - error("bad compressedSize found"); - return false; - } - unsigned long uncompressedSize; - if (!getLong(&uncompressedSize)) - { - error("bad uncompressedSize found"); - return false; - } - }//bit 3 was set - //break; - - std::vector uncompBuf; - switch (compressionMethod) - { - case 8: //deflate - { - Inflater inflater; - if (!inflater.inflate(uncompBuf, compBuf)) - { - return false; - } - break; - } - default: - { - error("Unimplemented compression method %d", compressionMethod); - return false; - } - } - - if (uncompressedSize != uncompBuf.size()) - { - error("Size mismatch. Expected %ld, received %ld", - uncompressedSize, uncompBuf.size()); - return false; - } - - Crc32 crcEngine; - crcEngine.update(uncompBuf); - unsigned long crc = crcEngine.getValue(); - if (crc != crc32) - { - error("Crc mismatch. Calculated %08ux, received %08ux", crc, crc32); - return false; - } - - ZipEntry *ze = new ZipEntry(fileName, comment); - ze->setCompressionMethod(compressionMethod); - ze->setCompressedData(compBuf); - ze->setUncompressedData(uncompBuf); - ze->setCrc(crc); - entries.push_back(ze); - - - } - return true; -} - - -/** - * - */ -bool ZipFile::readCentralDirectory() -{ - //printf("#################################################\n"); - //printf("###D I R E C T O R Y\n"); - //printf("#################################################\n"); - while (true) - { - //We start with a central directory cookie already - //Check at the bottom of the loop. - unsigned int version; - if (!getInt(&version)) - { - error("bad version found"); - return false; - } - unsigned int versionNeeded; - if (!getInt(&versionNeeded)) - { - error("bad version found"); - return false; - } - unsigned int gpBitFlag; - if (!getInt(&gpBitFlag)) - { - error("bad bit flag found"); - return false; - } - unsigned int compressionMethod; - if (!getInt(&compressionMethod)) - { - error("bad compressionMethod found"); - return false; - } - unsigned int modTime; - if (!getInt(&modTime)) - { - error("bad modTime found"); - return false; - } - unsigned int modDate; - if (!getInt(&modDate)) - { - error("bad modDate found"); - return false; - } - unsigned long crc32; - if (!getLong(&crc32)) - { - error("bad crc32 found"); - return false; - } - unsigned long compressedSize; - if (!getLong(&compressedSize)) - { - error("bad compressedSize found"); - return false; - } - unsigned long uncompressedSize; - if (!getLong(&uncompressedSize)) - { - error("bad uncompressedSize found"); - return false; - } - unsigned int fileNameLength; - if (!getInt(&fileNameLength)) - { - error("bad fileNameLength found"); - return false; - } - unsigned int extraFieldLength; - if (!getInt(&extraFieldLength)) - { - error("bad extraFieldLength found"); - return false; - } - unsigned int fileCommentLength; - if (!getInt(&fileCommentLength)) - { - error("bad fileCommentLength found"); - return false; - } - unsigned int diskNumberStart; - if (!getInt(&diskNumberStart)) - { - error("bad diskNumberStart found"); - return false; - } - unsigned int internalFileAttributes; - if (!getInt(&internalFileAttributes)) - { - error("bad internalFileAttributes found"); - return false; - } - unsigned long externalFileAttributes; - if (!getLong(&externalFileAttributes)) - { - error("bad externalFileAttributes found"); - return false; - } - unsigned long localHeaderOffset; - if (!getLong(&localHeaderOffset)) - { - error("bad localHeaderOffset found"); - return false; - } - std::string fileName; - for (unsigned int i=0 ; i &inbuf) -{ - fileBuf = inbuf; - if (!read()) - return false; - return true; -} - - -/** - * - */ -bool ZipFile::readFile(const std::string &fileName) -{ - fileBuf.clear(); - FILE *f = fopen(fileName.c_str(), "rb"); - if (!f) - return false; - while (true) - { - int ch = fgetc(f); - if (ch < 0) - break; - fileBuf.push_back(ch); - } - fclose(f); - if (!read()) - return false; - return true; -} - - - - - - - - - -//######################################################################## -//# E N D O F F I L E -//######################################################################## - - diff --git a/src/dom/util/ziptool.h b/src/dom/util/ziptool.h deleted file mode 100644 index dbae8ac60..000000000 --- a/src/dom/util/ziptool.h +++ /dev/null @@ -1,567 +0,0 @@ -#ifndef SEEN_ZIPTOOL_H -#define SEEN_ZIPTOOL_H -/** - * This is intended to be a standalone, reduced capability - * implementation of Gzip and Zip functionality. Its - * targeted use case is for archiving and retrieving single files - * which use these encoding types. Being memory based and - * non-optimized, it is not useful in cases where very large - * archives are needed or where high performance is desired. - * However, it should hopefully work well for smaller, - * one-at-a-time tasks. What you get in return is the ability - * to drop these files into your project and remove the dependencies - * on ZLib and Info-Zip. Enjoy. - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include -#include - - -//######################################################################## -//# A D L E R 3 2 -//######################################################################## - -class Adler32 -{ -public: - - Adler32(); - - virtual ~Adler32(); - - void reset(); - - void update(unsigned char b); - - void update(char *str); - - unsigned long getValue(); - -private: - - unsigned long value; - -}; - - -//######################################################################## -//# C R C 3 2 -//######################################################################## - -class Crc32 -{ -public: - - Crc32(); - - virtual ~Crc32(); - - void reset(); - - void update(unsigned char b); - - void update(char *str); - - void update(const std::vector &buf); - - unsigned long getValue(); - -private: - - unsigned long value; - -}; - - - - - - -//######################################################################## -//# G Z I P S T R E A M S -//######################################################################## - -class GzipFile -{ -public: - - /** - * - */ - GzipFile(); - - /** - * - */ - virtual ~GzipFile(); - - /** - * - */ - virtual void put(unsigned char ch); - - /** - * - */ - virtual void setData(const std::vector &str); - - /** - * - */ - virtual void clearData(); - - /** - * - */ - virtual std::vector &getData(); - - /** - * - */ - virtual std::string &getFileName(); - - /** - * - */ - virtual void setFileName(const std::string &val); - - - //###################### - //# U T I L I T Y - //###################### - - /** - * - */ - virtual bool readFile(const std::string &fName); - - //###################### - //# W R I T E - //###################### - - /** - * - */ - virtual bool write(); - - /** - * - */ - virtual bool writeBuffer(std::vector &outbuf); - - /** - * - */ - virtual bool writeFile(const std::string &fileName); - - - //###################### - //# R E A D - //###################### - - - /** - * - */ - virtual bool read(); - - /** - * - */ - virtual bool readBuffer(const std::vector &inbuf); - - /** - * - */ - virtual bool loadFile(const std::string &fileName); - - - -private: - - std::vector data; - std::string fileName; - - //debug messages - void error(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - void trace(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - std::vector fileBuf; - unsigned long fileBufPos; - - bool getByte(unsigned char *ch); - bool getLong(unsigned long *val); - - bool putByte(unsigned char ch); - bool putLong(unsigned long val); - - int compressionMethod; -}; - - - - -//######################################################################## -//# Z I P F I L E -//######################################################################## - - -/** - * - */ -class ZipEntry -{ -public: - - /** - * - */ - ZipEntry(); - - /** - * - */ - ZipEntry(const std::string &fileName, - const std::string &comment); - - /** - * - */ - virtual ~ZipEntry(); - - /** - * - */ - virtual std::string getFileName(); - - /** - * - */ - virtual void setFileName(const std::string &val); - - /** - * - */ - virtual std::string getComment(); - - /** - * - */ - virtual void setComment(const std::string &val); - - /** - * - */ - virtual unsigned long getCompressedSize(); - - /** - * - */ - virtual int getCompressionMethod(); - - /** - * - */ - virtual void setCompressionMethod(int val); - - /** - * - */ - virtual std::vector &getCompressedData(); - - /** - * - */ - virtual void setCompressedData(const std::vector &val); - - /** - * - */ - virtual unsigned long getUncompressedSize(); - - /** - * - */ - virtual std::vector &getUncompressedData(); - - /** - * - */ - virtual void setUncompressedData(const std::vector &val); - - /** - * - */ - virtual void write(unsigned char ch); - - /** - * - */ - virtual void finish(); - - /** - * - */ - virtual unsigned long getCrc(); - - /** - * - */ - virtual void setCrc(unsigned long crc); - - /** - * - */ - virtual bool readFile(const std::string &fileNameArg, - const std::string &commentArg); - - /** - * - */ - virtual void setPosition(unsigned long val); - - /** - * - */ - virtual unsigned long getPosition(); - -private: - - unsigned long crc; - - std::string fileName; - std::string comment; - - int compressionMethod; - - std::vector compressedData; - std::vector uncompressedData; - - unsigned long position; -}; - - - - - - - - - -/** - * This class sits over the zlib and gzip code to - * implement a PKWare or Info-Zip .zip file reader and - * writer - */ -class ZipFile -{ -public: - - /** - * - */ - ZipFile(); - - /** - * - */ - virtual ~ZipFile(); - - //###################### - //# V A R I A B L E S - //###################### - - /** - * - */ - virtual void setComment(const std::string &val); - - /** - * - */ - virtual std::string getComment(); - - /** - * Return the list of entries currently in this file - */ - std::vector &getEntries(); - - - //###################### - //# U T I L I T Y - //###################### - - /** - * - */ - virtual ZipEntry *addFile(const std::string &fileNameArg, - const std::string &commentArg); - - /** - * - */ - virtual ZipEntry *newEntry(const std::string &fileNameArg, - const std::string &commentArg); - - //###################### - //# W R I T E - //###################### - - /** - * - */ - virtual bool write(); - - /** - * - */ - virtual bool writeBuffer(std::vector &outbuf); - - /** - * - */ - virtual bool writeFile(const std::string &fileName); - - - //###################### - //# R E A D - //###################### - - - /** - * - */ - virtual bool read(); - - /** - * - */ - virtual bool readBuffer(const std::vector &inbuf); - - /** - * - */ - virtual bool readFile(const std::string &fileName); - - -private: - - //debug messages - void error(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - void trace(char const *fmt, ...) - #ifdef G_GNUC_PRINTF - G_GNUC_PRINTF(2, 3) - #endif - ; - - //# Private writing methods - - /** - * - */ - bool putLong(unsigned long val); - - /** - * - */ - bool putInt(unsigned int val); - - - /** - * - */ - bool putByte(unsigned char val); - - /** - * - */ - bool writeFileData(); - - /** - * - */ - bool writeCentralDirectory(); - - - //# Private reading methods - - /** - * - */ - bool getLong(unsigned long *val); - - /** - * - */ - bool getInt(unsigned int *val); - - /** - * - */ - bool getByte(unsigned char *val); - - /** - * - */ - bool readFileData(); - - /** - * - */ - bool readCentralDirectory(); - - - std::vector entries; - - std::vector fileBuf; - unsigned long fileBufPos; - - std::string comment; -}; - - - - - - -#endif // SEEN_ZIPTOOL_H - - -//######################################################################## -//# E N D O F F I L E -//######################################################################## - -- cgit v1.2.3 From dba2f7dfcf0c7792a40acf5f1fc1e50b385adaa8 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 9 Feb 2013 07:53:01 +0100 Subject: partially reverted previous commit (bzr r12110) --- src/dom/CMakeLists.txt | 6 + src/dom/Makefile_insert | 7 +- src/dom/util/digest.cpp | 1456 ++++++++++++++++++++++ src/dom/util/digest.h | 654 ++++++++++ src/dom/util/ziptool.cpp | 3025 ++++++++++++++++++++++++++++++++++++++++++++++ src/dom/util/ziptool.h | 567 +++++++++ 6 files changed, 5714 insertions(+), 1 deletion(-) create mode 100644 src/dom/util/digest.cpp create mode 100644 src/dom/util/digest.h create mode 100644 src/dom/util/ziptool.cpp create mode 100644 src/dom/util/ziptool.h (limited to 'src') diff --git a/src/dom/CMakeLists.txt b/src/dom/CMakeLists.txt index bc2f58c29..15b4ba74d 100644 --- a/src/dom/CMakeLists.txt +++ b/src/dom/CMakeLists.txt @@ -26,6 +26,9 @@ set(dom_SRC io/stringstream.cpp io/uristream.cpp + util/digest.cpp + util/ziptool.cpp + # ------- # Headers @@ -64,6 +67,9 @@ set(dom_SRC io/gzipstream.h io/stringstream.h io/uristream.h + + util/digest.h + util/ziptool.h ) add_inkscape_lib(dom_LIB "${dom_SRC}") diff --git a/src/dom/Makefile_insert b/src/dom/Makefile_insert index 66333ba47..17bab94ac 100644 --- a/src/dom/Makefile_insert +++ b/src/dom/Makefile_insert @@ -63,4 +63,9 @@ dom_libdom_a_SOURCES = \ dom/io/stringstream.cpp \ dom/io/stringstream.h \ dom/io/uristream.cpp \ - dom/io/uristream.h + dom/io/uristream.h \ + dom/util/digest.h \ + dom/util/digest.cpp \ + dom/util/ziptool.h \ + dom/util/ziptool.cpp + diff --git a/src/dom/util/digest.cpp b/src/dom/util/digest.cpp new file mode 100644 index 000000000..2baed4860 --- /dev/null +++ b/src/dom/util/digest.cpp @@ -0,0 +1,1456 @@ +/* + * Secure Hashing Tool + * * + * Authors: + * Bob Jamison + * + * Copyright (C) 2006-2008 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "digest.h" + + +//######################################################################## +//## U T I L I T Y +//######################################################################## + +/** + * Use this to print out a 64-bit int when otherwise difficult + */ +/* +static void pl(uint64_t val) +{ + for (int shift=56 ; shift>=0 ; shift-=8) + { + int ch = (val >> shift) & 0xff; + printf("%02x", ch); + } +} +*/ + + + +/** + * 3These truncate their arguments to + * unsigned 32-bit or unsigned 64-bit. + */ +#define TR32(x) ((x) & 0xffffffffL) +#define TR64(x) ((x) & 0xffffffffffffffffLL) + + +static const char *hexDigits = "0123456789abcdef"; + +static std::string toHex(const std::vector &bytes) +{ + std::string str; + std::vector::const_iterator iter; + for (iter = bytes.begin() ; iter != bytes.end() ; ++iter) + { + unsigned char ch = *iter; + str.push_back(hexDigits[(ch>>4) & 0x0f]); + str.push_back(hexDigits[(ch ) & 0x0f]); + } + return str; +} + + +//######################################################################## +//## D I G E S T +//######################################################################## + + +/** + * + */ +std::string Digest::finishHex() +{ + std::vector hash = finish(); + std::string str = toHex(hash); + return str; +} + +/** + * Convenience method. This is a simple way of getting a hash + */ +std::vector Digest::hash(Digest::HashType typ, + unsigned char *buf, + int len) +{ + std::vector ret; + switch (typ) + { + case HASH_MD5: + { + Md5 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + case HASH_SHA1: + { + Sha1 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + case HASH_SHA224: + { + Sha224 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + case HASH_SHA256: + { + Sha256 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + case HASH_SHA384: + { + Sha384 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + case HASH_SHA512: + { + Sha512 digest; + digest.append(buf, len); + ret = digest.finish(); + break; + } + default: + { + break; + } + } + return ret; +} + + +/** + * Convenience method. Same as above, but for a std::string + */ +std::vector Digest::hash(Digest::HashType typ, + const std::string &str) +{ + return hash(typ, (unsigned char *)str.c_str(), str.size()); +} + +/** + * Convenience method. Return a hexidecimal string of the hash of the buffer. + */ +std::string Digest::hashHex(Digest::HashType typ, + unsigned char *buf, + int len) +{ + std::vector dig = hash(typ, buf, len); + return toHex(dig); +} + +/** + * Convenience method. Return a hexidecimal string of the hash of the + * string argument + */ +std::string Digest::hashHex(Digest::HashType typ, + const std::string &str) +{ + std::vector dig = hash(typ, str); + return toHex(dig); +} + + + +//4.1.1 and 4.1.2 +#define SHA_ROTL(X,n) ((((X) << (n)) & 0xffffffffL) | (((X) >> (32-(n))) & 0xffffffffL)) +#define SHA_Ch(x,y,z) ((z)^((x)&((y)^(z)))) +#define SHA_Maj(x,y,z) (((x)&(y))^((z)&((x)^(y)))) + + +//######################################################################## +//## S H A 1 +//######################################################################## + + +/** + * + */ +void Sha1::reset() +{ + longNr = 0; + byteNr = 0; + + // Initialize H with the magic constants (see FIPS180 for constants) + hashBuf[0] = 0x67452301L; + hashBuf[1] = 0xefcdab89L; + hashBuf[2] = 0x98badcfeL; + hashBuf[3] = 0x10325476L; + hashBuf[4] = 0xc3d2e1f0L; + + for (int i = 0; i < 4; i++) + inb[i] = 0; + + for (int i = 0; i < 80; i++) + inBuf[i] = 0; + + clearByteCount(); +} + + +/** + * + */ +void Sha1::update(unsigned char ch) +{ + incByteCount(); + + inb[byteNr++] = (uint32_t)ch; + if (byteNr >= 4) + { + inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | + inb[2] << 8 | inb[3]; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + +void Sha1::transform() +{ + uint32_t *W = inBuf; + uint32_t *H = hashBuf; + + //for (int t = 0; t < 16 ; t++) + // printf("%2d %08lx\n", t, W[t]); + + //see 6.1.2 + for (int t = 16; t < 80 ; t++) + W[t] = SHA_ROTL((W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]), 1); + + uint32_t a = H[0]; + uint32_t b = H[1]; + uint32_t c = H[2]; + uint32_t d = H[3]; + uint32_t e = H[4]; + + uint32_t T; + + int t = 0; + for ( ; t < 20 ; t++) + { + //see 4.1.1 for the boolops on B,C, and D + T = TR32(SHA_ROTL(a,5) + ((b&c)|((~b)&d)) + //Ch(b,c,d)) + e + 0x5a827999L + W[t]); + e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; + //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); + } + for ( ; t < 40 ; t++) + { + T = TR32(SHA_ROTL(a,5) + (b^c^d) + e + 0x6ed9eba1L + W[t]); + e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; + //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); + } + for ( ; t < 60 ; t++) + { + T = TR32(SHA_ROTL(a,5) + ((b&c)^(b&d)^(c&d)) + + e + 0x8f1bbcdcL + W[t]); + e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; + //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); + } + for ( ; t < 80 ; t++) + { + T = TR32(SHA_ROTL(a,5) + (b^c^d) + + e + 0xca62c1d6L + W[t]); + e = d; d = c; c = SHA_ROTL(b, 30); b = a; a = T; + //printf("%2d %08lx %08lx %08lx %08lx %08lx\n", t, a, b, c, d, e); + } + + H[0] = TR32(H[0] + a); + H[1] = TR32(H[1] + b); + H[2] = TR32(H[2] + c); + H[3] = TR32(H[3] + d); + H[4] = TR32(H[4] + e); +} + + + + +/** + * + */ +std::vector Sha1::finish() +{ + //snapshot the bit count now before padding + getBitCount(); + + //Append terminal char + update(0x80); + + //pad until we have a 56 of 64 bytes, allowing for 8 bytes at the end + while ((nrBytes & 63) != 56) + update(0); + + //##### Append length in bits + appendBitCount(); + + //copy out answer + std::vector res; + for (int i=0 ; i<5 ; i++) + { + res.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + } + + // Re-initialize the context (also zeroizes contents) + reset(); + + return res; +} + + + + +//######################################################################## +//## SHA224 +//######################################################################## + + +/** + * SHA-224 and SHA-512 share the same operations and constants + */ + +#define SHA_Rot32(x,s) ((((x) >> s)&0xffffffffL) | (((x) << (32 - s))&0xffffffffL)) +#define SHA_SIGMA0(x) (SHA_Rot32(x, 2) ^ SHA_Rot32(x, 13) ^ SHA_Rot32(x, 22)) +#define SHA_SIGMA1(x) (SHA_Rot32(x, 6) ^ SHA_Rot32(x, 11) ^ SHA_Rot32(x, 25)) +#define SHA_sigma0(x) (SHA_Rot32(x, 7) ^ SHA_Rot32(x, 18) ^ ((x) >> 3)) +#define SHA_sigma1(x) (SHA_Rot32(x, 17) ^ SHA_Rot32(x, 19) ^ ((x) >> 10)) + + +static uint32_t sha256table[64] = +{ + 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, + 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, + 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, + 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, + 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, + 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, + 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, + 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, + 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, + 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, + 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, + 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, + 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, + 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, + 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, + 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL +}; + + + + + +/** + * + */ +void Sha224::reset() +{ + longNr = 0; + byteNr = 0; + + // Initialize H with the magic constants (see FIPS180 for constants) + hashBuf[0] = 0xc1059ed8L; + hashBuf[1] = 0x367cd507L; + hashBuf[2] = 0x3070dd17L; + hashBuf[3] = 0xf70e5939L; + hashBuf[4] = 0xffc00b31L; + hashBuf[5] = 0x68581511L; + hashBuf[6] = 0x64f98fa7L; + hashBuf[7] = 0xbefa4fa4L; + + for (int i = 0 ; i < 64 ; i++) + inBuf[i] = 0; + + for (int i = 0 ; i < 4 ; i++) + inb[i] = 0; + + clearByteCount(); +} + + +/** + * + */ +void Sha224::update(unsigned char ch) +{ + incByteCount(); + + inb[byteNr++] = (uint32_t)ch; + if (byteNr >= 4) + { + inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | + inb[2] << 8 | inb[3]; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + +void Sha224::transform() +{ + uint32_t *W = inBuf; + uint32_t *H = hashBuf; + + //for (int t = 0; t < 16 ; t++) + // printf("%2d %08lx\n", t, W[t]); + + //see 6.2.2 + for (int t = 16; t < 64 ; t++) + W[t] = TR32(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); + + uint32_t a = H[0]; + uint32_t b = H[1]; + uint32_t c = H[2]; + uint32_t d = H[3]; + uint32_t e = H[4]; + uint32_t f = H[5]; + uint32_t g = H[6]; + uint32_t h = H[7]; + + for (int t = 0 ; t < 64 ; t++) + { + //see 4.1.1 for the boolops + uint32_t T1 = TR32(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + + sha256table[t] + W[t]); + uint32_t T2 = TR32(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); + h = g; g = f; f = e; e = TR32(d + T1); d = c; c = b; b = a; a = TR32(T1 + T2); + //printf("%2d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", + // t, a, b, c, d, e, f, g, h); + } + + H[0] = TR32(H[0] + a); + H[1] = TR32(H[1] + b); + H[2] = TR32(H[2] + c); + H[3] = TR32(H[3] + d); + H[4] = TR32(H[4] + e); + H[5] = TR32(H[5] + f); + H[6] = TR32(H[6] + g); + H[7] = TR32(H[7] + h); +} + + + +/** + * + */ +std::vector Sha224::finish() +{ + //save our size before padding + getBitCount(); + + // Pad with a binary 1 (0x80) + update(0x80); + //append 0's to make a 56-byte buf. + while ((nrBytes & 63) != 56) + update(0); + + //##### Append length in bits + appendBitCount(); + + // Output hash + std::vector ret; + for (int i = 0 ; i < 7 ; i++) + { + ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + } + + // Re-initialize the context (also zeroizes contents) + reset(); + + return ret; + +} + + + +//######################################################################## +//## SHA256 +//######################################################################## + + +/** + * + */ +void Sha256::reset() +{ + longNr = 0; + byteNr = 0; + + // Initialize H with the magic constants (see FIPS180 for constants) + hashBuf[0] = 0x6a09e667L; + hashBuf[1] = 0xbb67ae85L; + hashBuf[2] = 0x3c6ef372L; + hashBuf[3] = 0xa54ff53aL; + hashBuf[4] = 0x510e527fL; + hashBuf[5] = 0x9b05688cL; + hashBuf[6] = 0x1f83d9abL; + hashBuf[7] = 0x5be0cd19L; + + for (int i = 0 ; i < 64 ; i++) + inBuf[i] = 0; + for (int i = 0 ; i < 4 ; i++) + inb[i] = 0; + + clearByteCount(); +} + + +/** + * + */ +void Sha256::update(unsigned char ch) +{ + incByteCount(); + + inb[byteNr++] = (uint32_t)ch; + if (byteNr >= 4) + { + inBuf[longNr++] = inb[0] << 24 | inb[1] << 16 | + inb[2] << 8 | inb[3]; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + + + +void Sha256::transform() +{ + uint32_t *H = hashBuf; + uint32_t *W = inBuf; + + //for (int t = 0; t < 16 ; t++) + // printf("%2d %08lx\n", t, W[t]); + + //see 6.2.2 + for (int t = 16; t < 64 ; t++) + W[t] = TR32(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); + + uint32_t a = H[0]; + uint32_t b = H[1]; + uint32_t c = H[2]; + uint32_t d = H[3]; + uint32_t e = H[4]; + uint32_t f = H[5]; + uint32_t g = H[6]; + uint32_t h = H[7]; + + for (int t = 0 ; t < 64 ; t++) + { + //see 4.1.1 for the boolops + uint32_t T1 = TR32(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + + sha256table[t] + W[t]); + uint32_t T2 = TR32(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); + h = g; g = f; f = e; e = TR32(d + T1); d = c; c = b; b = a; a = TR32(T1 + T2); + //printf("%2d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", + // t, a, b, c, d, e, f, g, h); + } + + H[0] = TR32(H[0] + a); + H[1] = TR32(H[1] + b); + H[2] = TR32(H[2] + c); + H[3] = TR32(H[3] + d); + H[4] = TR32(H[4] + e); + H[5] = TR32(H[5] + f); + H[6] = TR32(H[6] + g); + H[7] = TR32(H[7] + h); +} + + + +/** + * + */ +std::vector Sha256::finish() +{ + //save our size before padding + getBitCount(); + + // Pad with a binary 1 (0x80) + update(0x80); + //append 0's to make a 56-byte buf. + while ((nrBytes & 63) != 56) + update(0); + + //##### Append length in bits + appendBitCount(); + + // Output hash + std::vector ret; + for (int i = 0 ; i < 8 ; i++) + { + ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + } + + // Re-initialize the context (also zeroizes contents) + reset(); + + return ret; + +} + + + +//######################################################################## +//## SHA384 +//######################################################################## + + +/** + * SHA-384 and SHA-512 share the same operations and constants + */ + +#undef SHA_SIGMA0 +#undef SHA_SIGMA1 +#undef SHA_sigma0 +#undef SHA_sigma1 + +#define SHA_Rot64(x,s) (((x) >> s) | ((x) << (64 - s))) +#define SHA_SIGMA0(x) (SHA_Rot64(x, 28) ^ SHA_Rot64(x, 34) ^ SHA_Rot64(x, 39)) +#define SHA_SIGMA1(x) (SHA_Rot64(x, 14) ^ SHA_Rot64(x, 18) ^ SHA_Rot64(x, 41)) +#define SHA_sigma0(x) (SHA_Rot64(x, 1) ^ SHA_Rot64(x, 8) ^ ((x) >> 7)) +#define SHA_sigma1(x) (SHA_Rot64(x, 19) ^ SHA_Rot64(x, 61) ^ ((x) >> 6)) + + +static uint64_t sha512table[80] = +{ + 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, + 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, + 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, + 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, + 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, + 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, + 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, + 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, + 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, + 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, + 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, + 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, + 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, + 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, + 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, + 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, + 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, + 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, + 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, + 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, + 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, + 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, + 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, + 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, + 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, + 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, + 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, + 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, + 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, + 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, + 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, + 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, + 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, + 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, + 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, + 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, + 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, + 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, + 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, + 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL +}; + + + + +/** + * + */ +void Sha384::reset() +{ + longNr = 0; + byteNr = 0; + + // SHA-384 differs from SHA-512 by these constants + hashBuf[0] = 0xcbbb9d5dc1059ed8ULL; + hashBuf[1] = 0x629a292a367cd507ULL; + hashBuf[2] = 0x9159015a3070dd17ULL; + hashBuf[3] = 0x152fecd8f70e5939ULL; + hashBuf[4] = 0x67332667ffc00b31ULL; + hashBuf[5] = 0x8eb44a8768581511ULL; + hashBuf[6] = 0xdb0c2e0d64f98fa7ULL; + hashBuf[7] = 0x47b5481dbefa4fa4ULL; + + for (int i = 0 ; i < 80 ; i++) + inBuf[i] = 0; + for (int i = 0 ; i < 8 ; i++) + inb[i] = 0; + + clearByteCount(); +} + + +/** + * Note that this version of update() handles 64-bit inBuf + * values. + */ +void Sha384::update(unsigned char ch) +{ + incByteCount(); + + inb[byteNr++] = (uint64_t)ch; + if (byteNr >= 8) + { + inBuf[longNr++] = inb[0] << 56 | inb[1] << 48 | + inb[2] << 40 | inb[3] << 32 | + inb[4] << 24 | inb[5] << 16 | + inb[6] << 8 | inb[7]; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + + + +void Sha384::transform() +{ + uint64_t *H = hashBuf; + uint64_t *W = inBuf; + + /* + for (int t = 0; t < 16 ; t++) + { + printf("%2d ", t); + pl(W[t]); + printf("\n"); + } + */ + + //see 6.2.2 + for (int t = 16; t < 80 ; t++) + W[t] = TR64(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); + + uint64_t a = H[0]; + uint64_t b = H[1]; + uint64_t c = H[2]; + uint64_t d = H[3]; + uint64_t e = H[4]; + uint64_t f = H[5]; + uint64_t g = H[6]; + uint64_t h = H[7]; + + for (int t = 0 ; t < 80 ; t++) + { + //see 4.1.1 for the boolops + uint64_t T1 = TR64(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + + sha512table[t] + W[t]); + uint64_t T2 = TR64(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); + h = g; g = f; f = e; e = TR64(d + T1); d = c; c = b; b = a; a = TR64(T1 + T2); + } + + H[0] = TR64(H[0] + a); + H[1] = TR64(H[1] + b); + H[2] = TR64(H[2] + c); + H[3] = TR64(H[3] + d); + H[4] = TR64(H[4] + e); + H[5] = TR64(H[5] + f); + H[6] = TR64(H[6] + g); + H[7] = TR64(H[7] + h); +} + + + +/** + * + */ +std::vector Sha384::finish() +{ + //save our size before padding + getBitCount(); + + // Pad with a binary 1 (0x80) + update((unsigned char)0x80); + //append 0's to make a 112-byte buf. + //we will loop around once if already over 112 + while ((nrBytes & 127) != 112) + update(0); + + //append 128-bit size + //64 upper bits + for (int i = 0 ; i < 8 ; i++) + update((unsigned char)0x00); + //64 lower bits + //##### Append length in bits + appendBitCount(); + + // Output hash + //for SHA-384, we use the left-most 6 64-bit words + std::vector ret; + for (int i = 0 ; i < 6 ; i++) + { + ret.push_back((unsigned char)((hashBuf[i] >> 56) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 48) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 40) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 32) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + } + + // Re-initialize the context (also zeroizes contents) + reset(); + + return ret; + +} + + +//######################################################################## +//## SHA512 +//######################################################################## + + + + + +/** + * + */ +void Sha512::reset() +{ + longNr = 0; + byteNr = 0; + + // Initialize H with the magic constants (see FIPS180 for constants) + hashBuf[0] = 0x6a09e667f3bcc908ULL; + hashBuf[1] = 0xbb67ae8584caa73bULL; + hashBuf[2] = 0x3c6ef372fe94f82bULL; + hashBuf[3] = 0xa54ff53a5f1d36f1ULL; + hashBuf[4] = 0x510e527fade682d1ULL; + hashBuf[5] = 0x9b05688c2b3e6c1fULL; + hashBuf[6] = 0x1f83d9abfb41bd6bULL; + hashBuf[7] = 0x5be0cd19137e2179ULL; + + for (int i = 0 ; i < 80 ; i++) + inBuf[i] = 0; + for (int i = 0 ; i < 8 ; i++) + inb[i] = 0; + + clearByteCount(); +} + + +/** + * Note that this version of update() handles 64-bit inBuf + * values. + */ +void Sha512::update(unsigned char ch) +{ + incByteCount(); + + inb[byteNr++] = (uint64_t)ch; + if (byteNr >= 8) + { + inBuf[longNr++] = inb[0] << 56 | inb[1] << 48 | + inb[2] << 40 | inb[3] << 32 | + inb[4] << 24 | inb[5] << 16 | + inb[6] << 8 | inb[7]; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + + + +void Sha512::transform() +{ + uint64_t *W = inBuf; + uint64_t *H = hashBuf; + + /* + for (int t = 0; t < 16 ; t++) + { + printf("%2d ", t); + pl(W[t]); + printf("\n"); + } + */ + + //see 6.2.2 + for (int t = 16; t < 80 ; t++) + W[t] = TR64(SHA_sigma1(W[t-2]) + W[t-7] + SHA_sigma0(W[t-15]) + W[t-16]); + + uint64_t a = H[0]; + uint64_t b = H[1]; + uint64_t c = H[2]; + uint64_t d = H[3]; + uint64_t e = H[4]; + uint64_t f = H[5]; + uint64_t g = H[6]; + uint64_t h = H[7]; + + for (int t = 0 ; t < 80 ; t++) + { + //see 4.1.1 for the boolops + uint64_t T1 = TR64(h + SHA_SIGMA1(e) + SHA_Ch(e,f,g) + + sha512table[t] + W[t]); + uint64_t T2 = TR64(SHA_SIGMA0(a) + SHA_Maj(a,b,c)); + h = g; g = f; f = e; e = TR64(d + T1); d = c; c = b; b = a; a = TR64(T1 + T2); + } + + H[0] = TR64(H[0] + a); + H[1] = TR64(H[1] + b); + H[2] = TR64(H[2] + c); + H[3] = TR64(H[3] + d); + H[4] = TR64(H[4] + e); + H[5] = TR64(H[5] + f); + H[6] = TR64(H[6] + g); + H[7] = TR64(H[7] + h); +} + + + +/** + * + */ +std::vector Sha512::finish() +{ + //save our size before padding + getBitCount(); + + // Pad with a binary 1 (0x80) + update(0x80); + //append 0's to make a 112-byte buf. + //we will loop around once if already over 112 + while ((nrBytes & 127) != 112) + update(0); + + //append 128-bit size + //64 upper bits + for (int i = 0 ; i < 8 ; i++) + update((unsigned char)0x00); + //64 lower bits + //##### Append length in bits + appendBitCount(); + + // Output hash + std::vector ret; + for (int i = 0 ; i < 8 ; i++) + { + ret.push_back((unsigned char)((hashBuf[i] >> 56) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 48) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 40) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 32) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + ret.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + } + + // Re-initialize the context (also zeroizes contents) + reset(); + + return ret; + +} + + + +//######################################################################## +//## M D 5 +//######################################################################## + +/** + * + */ +void Md5::reset() +{ + hashBuf[0] = 0x67452301; + hashBuf[1] = 0xefcdab89; + hashBuf[2] = 0x98badcfe; + hashBuf[3] = 0x10325476; + + for (int i=0 ; i<16 ; i++) + inBuf[i] = 0; + for (int i=0 ; i<4 ; i++) + inb[i] = 0; + + clearByteCount(); + + byteNr = 0; + longNr = 0; +} + + +/** + * + */ +void Md5::update(unsigned char ch) +{ + incByteCount(); + + //pack 64 bytes into 16 longs + inb[byteNr++] = (uint32_t)ch; + if (byteNr >= 4) + { + //note the little-endianness + uint32_t val = + inb[3] << 24 | inb[2] << 16 | inb[1] << 8 | inb[0]; + inBuf[longNr++] = val; + byteNr = 0; + } + if (longNr >= 16) + { + transform(); + longNr = 0; + } +} + + + +//# The four core functions - F1 is optimized somewhat + +// #define F1(x, y, z) (x & y | ~x & z) +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +// ## This is the central step in the MD5 algorithm. +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w = TR32(w + (f(x, y, z) + data)), w = w<>(32-s), w = TR32(w + x) ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + * @parm buf points to an array of 4 unsigned 32bit (at least) integers + * @parm in points to an array of 16 unsigned 32bit (at least) integers + */ +void Md5::transform() +{ + uint32_t *i = inBuf; + uint32_t a = hashBuf[0]; + uint32_t b = hashBuf[1]; + uint32_t c = hashBuf[2]; + uint32_t d = hashBuf[3]; + + MD5STEP(F1, a, b, c, d, i[ 0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, i[ 1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, i[ 2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, i[ 3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, i[ 4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, i[ 5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, i[ 6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, i[ 7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, i[ 8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, i[ 9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, i[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, i[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, i[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, i[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, i[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, i[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, i[ 1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, i[ 6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, i[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, i[ 0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, i[ 5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, i[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, i[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, i[ 4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, i[ 9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, i[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, i[ 3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, i[ 8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, i[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, i[ 2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, i[ 7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, i[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, i[ 5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, i[ 8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, i[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, i[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, i[ 1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, i[ 4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, i[ 7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, i[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, i[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, i[ 0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, i[ 3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, i[ 6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, i[ 9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, i[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, i[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, i[ 2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, i[ 0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, i[ 7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, i[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, i[ 5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, i[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, i[ 3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, i[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, i[ 1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, i[ 8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, i[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, i[ 6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, i[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, i[ 4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, i[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, i[ 2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, i[ 9] + 0xeb86d391, 21); + + hashBuf[0] = TR32(hashBuf[0] + a); + hashBuf[1] = TR32(hashBuf[1] + b); + hashBuf[2] = TR32(hashBuf[2] + c); + hashBuf[3] = TR32(hashBuf[3] + d); +} + + +/** + * + */ +std::vector Md5::finish() +{ + //snapshot the bit count now before padding + getBitCount(); + + //Append terminal char + update(0x80); + + //pad until we have a 56 of 64 bytes, allowing for 8 bytes at the end + while (longNr != 14) + update(0); + + //##### Append length in bits + // Don't use appendBitCount(), since md5 is little-endian + update((unsigned char)((nrBits ) & 0xff)); + update((unsigned char)((nrBits>> 8) & 0xff)); + update((unsigned char)((nrBits>>16) & 0xff)); + update((unsigned char)((nrBits>>24) & 0xff)); + update((unsigned char)((nrBits>>32) & 0xff)); + update((unsigned char)((nrBits>>40) & 0xff)); + update((unsigned char)((nrBits>>48) & 0xff)); + update((unsigned char)((nrBits>>56) & 0xff)); + + //copy out answer + std::vector res; + for (int i=0 ; i<4 ; i++) + { + //note the little-endianness + res.push_back((unsigned char)((hashBuf[i] ) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] >> 8) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] >> 16) & 0xff)); + res.push_back((unsigned char)((hashBuf[i] >> 24) & 0xff)); + } + + reset(); // Security! ;-) + + return res; +} + + + + + + +//######################################################################## +//## T E S T S +//######################################################################## + +/** + * Compile this file alone with -DDIGEST_TEST to run the + * tests below: + * > gcc -DDIGEST_TEST digest.cpp -o testdigest + * > testdigest + * + * If you add any new algorithms to this suite, then it is highly + * recommended that you add it to these tests and run it. + */ + +#ifdef DIGEST_TEST + + +typedef struct +{ + const char *msg; + const char *val; +} TestPair; + +static TestPair md5tests[] = +{ + { + "", + "d41d8cd98f00b204e9800998ecf8427e" + }, + { + "a", + "0cc175b9c0f1b6a831c399e269772661" + }, + { + "abc", + "900150983cd24fb0d6963f7d28e17f72" + }, + { + "message digest", + "f96b697d7cb7938d525a2f31aaf161d0" + }, + { + "abcdefghijklmnopqrstuvwxyz", + "c3fcd3d76192e4007dfb496cca67e13b" + }, + { + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f" + }, + { + "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a" + }, + { + NULL, + NULL + } +}; + + + +static TestPair sha1tests[] = +{ + { + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "84983e441c3bd26ebaae4aa1f95129e5e54670f1" + }, + { + NULL, + NULL + } +}; + +static TestPair sha224tests[] = +{ + { + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" + }, + { + NULL, + NULL + } +}; + +static TestPair sha256tests[] = +{ + { + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" + }, + { + NULL, + NULL + } +}; + +static TestPair sha384tests[] = +{ + { + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712" + "fcc7c71a557e2db966c3e9fa91746039" + }, + { + NULL, + NULL + } +}; + +static TestPair sha512tests[] = +{ + { + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" + "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" + }, + { + NULL, + NULL + } +}; + + +bool hashTests(Digest &digest, TestPair *tp) +{ + for (TestPair *pair = tp ; pair->msg ; pair++) + { + digest.reset(); + std::string msg = pair->msg; + std::string val = pair->val; + digest.append(msg); + std::string res = digest.finishHex(); + printf("### Msg '%s':\n hash '%s'\n exp '%s'\n", + msg.c_str(), res.c_str(), val.c_str()); + if (res != val) + { + printf("ERROR: Hash mismatch\n"); + return false; + } + } + return true; +} + + +bool millionATest(Digest &digest, const std::string &exp) +{ + digest.reset(); + for (int i=0 ; i<1000000 ; i++) + digest.append('a'); + std::string res = digest.finishHex(); + printf("\nHash of 1,000,000 'a'\n calc %s\n exp %s\n", + res.c_str(), exp.c_str()); + if (res != exp) + { + printf("ERROR: Mismatch.\n"); + return false; + } + return true; +} + +static bool doTests() +{ + printf("##########################################\n"); + printf("## MD5\n"); + printf("##########################################\n"); + Md5 md5; + if (!hashTests(md5, md5tests)) + return false; + if (!millionATest(md5, "7707d6ae4e027c70eea2a935c2296f21")) + return false; + printf("\n\n\n"); + printf("##########################################\n"); + printf("## SHA1\n"); + printf("##########################################\n"); + Sha1 sha1; + if (!hashTests(sha1, sha1tests)) + return false; + if (!millionATest(sha1, "34aa973cd4c4daa4f61eeb2bdbad27316534016f")) + return false; + printf("\n\n\n"); + printf("##########################################\n"); + printf("## SHA224\n"); + printf("##########################################\n"); + Sha224 sha224; + if (!hashTests(sha224, sha224tests)) + return false; + if (!millionATest(sha224, + "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67")) + return false; + printf("\n\n\n"); + printf("##########################################\n"); + printf("## SHA256\n"); + printf("##########################################\n"); + Sha256 sha256; + if (!hashTests(sha256, sha256tests)) + return false; + if (!millionATest(sha256, + "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0")) + return false; + printf("\n\n\n"); + printf("##########################################\n"); + printf("## SHA384\n"); + printf("##########################################\n"); + Sha384 sha384; + if (!hashTests(sha384, sha384tests)) + return false; + /**/ + if (!millionATest(sha384, + "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b" + "07b8b3dc38ecc4ebae97ddd87f3d8985")) + return false; + /**/ + printf("\n\n\n"); + printf("##########################################\n"); + printf("## SHA512\n"); + printf("##########################################\n"); + Sha512 sha512; + if (!hashTests(sha512, sha512tests)) + return false; + if (!millionATest(sha512, + "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb" + "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b")) + return false; + return true; +} + + +int main(int argc, char **argv) +{ + doTests(); + printf("####### done ########\n"); + return 0; +} + + +#endif /* DIGEST_TEST */ + +//######################################################################## +//## E N D O F F I L E +//######################################################################## diff --git a/src/dom/util/digest.h b/src/dom/util/digest.h new file mode 100644 index 000000000..c161b86bb --- /dev/null +++ b/src/dom/util/digest.h @@ -0,0 +1,654 @@ +#ifndef SEEN_DIGEST_H +#define SEEN_DIGEST_H +/* + * + * Author: + * Bob Jamison + * + * Copyright (C) 2006-2008 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * This base class and its subclasses provide an easy API for providing + * several different types of secure hashing functions for whatever use + * a developer might need. This is not intended as a high-performance + * replacement for the fine implementations already available. Rather, it + * is a small and simple (and maybe a bit slow?) tool for moderate common + * hashing requirements, like for communications and authentication. + * + * These hashes are intended to be simple to use. For example: + * Sha256 digest; + * digest.append("The quick brown dog"); + * std::string result = digest.finishHex(); + * + * Or, use one of the static convenience methods: + * + * example: std::string digest = + * Digest::hashHex(Digest::HASH_XXX, str); + * + * ...where HASH_XXX represents one of the hash + * algorithms listed in HashType. + * + * There are several forms of append() for convenience. + * finish() and finishHex() call reset() for both security and + * to prepare for the next use. + * + * + * Much effort has been applied to make this code portable, and it + * has been tested on various 32- and 64-bit machines. If you + * add another algorithm, please test it likewise. + * + * + * The SHA algorithms are derived directly from FIPS-180-3. The + * SHA tests at the bottom of digest.cpp are also directly from + * that document. + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + * + * The MD5 algorithm is from RFC 1321 + * + * To run the tests, compile standalone with -DDIGEST_TEST. Example: + * + * g++ -DDIGEST_TEST digest.cpp -o testdigest + * or + * g++ -DDIGEST_TEST -m64 digest.cpp -o testdigest + * + */ + +#include +#include + +#include + + + +/** + * Base class. Do not use instantiate class directly. Rather, use of of the + * subclasses below, or call one of this class's static convenience methods. + * + * For all subclasses, overload reset(), update(unsigned char), + * transform(), and finish() + */ +class Digest +{ +public: + + /** + * Different types of hash algorithms. + */ + typedef enum + { + HASH_NONE, + HASH_SHA1, + HASH_SHA224, + HASH_SHA256, + HASH_SHA384, + HASH_SHA512, + HASH_MD5 + } HashType; + + /** + * Constructor, with no type + */ + Digest() : hashType(HASH_NONE) + { reset(); } + + /** + * Destructor + */ + virtual ~Digest() + { reset(); } + + /** + * Return one of the enumerated hash types above + */ + virtual int getType() + { return hashType; } + + /** + * Append a single byte to the hash + */ + void append(unsigned char ch) + { update(ch); } + + /** + * Append a string to the hash + */ + virtual void append(const std::string &str) + { + for (unsigned int i=0 ; i &buf) + { //NOTE: function seems to be unused + for (unsigned int i=0 ; i finish() + { + std::vector ret; + return ret; + } + + + //######################## + //# Convenience methods + //######################## + + /** + * Convenience method. This is a simple way of getting a hash. + * Returns a byte buffer with the digest output. + * call with: std::vector digest = + * Digest::hash(Digest::HASH_XXX, buf, len); + */ + static std::vector hash(HashType typ, + unsigned char *buf, + int len); + /** + * Convenience method. This is a simple way of getting a hash. + * Returns a byte buffer with the digest output. + * call with: std::vector digest = + * Digest::hash(Digest::HASH_XXX, str); + */ + static std::vector hash(HashType typ, + const std::string &str); + + /** + * Convenience method. This is a simple way of getting a hash. + * Returns a string with the hexidecimal form of the digest output. + * call with: std::string digest = + * Digest::hash(Digest::HASH_XXX, buf, len); + */ + static std::string hashHex(HashType typ, + unsigned char *buf, + int len); + /** + * Convenience method. This is a simple way of getting a hash. + * Returns a string with the hexidecimal form of the digest output. + * call with: std::string digest = + * Digest::hash(Digest::HASH_XXX, str); + */ + static std::string hashHex(HashType typ, + const std::string &str); + +protected: + + /** + * Update the hash with a given byte + * Overload this in every subclass + */ + virtual void update(unsigned char /*ch*/) + {} + + /** + * Perform the particular block hashing algorithm for a + * particular type of hash. + * Overload this in every subclass + */ + virtual void transform() + {} + + + /** + * The enumerated type of the hash + */ + int hashType; + + /** + * Increment the count of bytes processed so far. Should be called + * in update() + */ + void incByteCount() + { + nrBytes++; + } + + /** + * Clear the byte / bit count information. Both for processing + * another message, also for security. Should be called in reset() + */ + void clearByteCount() + { + nrBytes = nrBits = 0; + } + + /** + * Calculates the bit count from the current byte count. Should be called + * in finish(), before any padding is added. This basically does a + * snapshot of the bitcount value before the padding. + */ + void getBitCount() + { + nrBits = (nrBytes << 3) & 0xFFFFFFFFFFFFFFFFLL; + } + + /** + * Common code for appending the 64-bit bitcount to the end of the + * message, after the padding. Should be called after padding, just + * before outputting the result. + */ + void appendBitCount() + { + update((unsigned char)((nrBits>>56) & 0xff)); + update((unsigned char)((nrBits>>48) & 0xff)); + update((unsigned char)((nrBits>>40) & 0xff)); + update((unsigned char)((nrBits>>32) & 0xff)); + update((unsigned char)((nrBits>>24) & 0xff)); + update((unsigned char)((nrBits>>16) & 0xff)); + update((unsigned char)((nrBits>> 8) & 0xff)); + update((unsigned char)((nrBits ) & 0xff)); + } + + /** + * Bit and byte counts + */ + uint64_t nrBytes; + uint64_t nrBits; +}; + + + + + +/** + * SHA-1, + * Section 6.1, SECURE HASH STANDARD + * Federal Information Processing Standards Publication 180-2 + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + */ +class Sha1 : public Digest +{ +public: + + /** + * Constructor + */ + Sha1() + { hashType = HASH_SHA1; reset(); } + + /** + * Destructor + */ + virtual ~Sha1() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + +private: + + uint32_t hashBuf[5]; + uint32_t inBuf[80]; + + int longNr; + int byteNr; + uint32_t inb[4]; + +}; + + + + + + +/** + * SHA-224, + * Section 6.1, SECURE HASH STANDARD + * Federal Information Processing Standards Publication 180-2 + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + */ +class Sha224 : public Digest +{ +public: + + /** + * Constructor + */ + Sha224() + { hashType = HASH_SHA224; reset(); } + + /** + * Destructor + */ + virtual ~Sha224() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + +private: + + uint32_t hashBuf[8]; + uint32_t inBuf[64]; + int longNr; + int byteNr; + uint32_t inb[4]; + +}; + + + +/** + * SHA-256, + * Section 6.1, SECURE HASH STANDARD + * Federal Information Processing Standards Publication 180-2 + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + */ +class Sha256 : public Digest +{ +public: + + /** + * Constructor + */ + Sha256() + { hashType = HASH_SHA256; reset(); } + + /** + * Destructor + */ + virtual ~Sha256() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + +private: + + uint32_t hashBuf[8]; + uint32_t inBuf[64]; + int longNr; + int byteNr; + uint32_t inb[4]; + +}; + + + +/** + * SHA-384, + * Section 6.1, SECURE HASH STANDARD + * Federal Information Processing Standards Publication 180-2 + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + */ +class Sha384 : public Digest +{ +public: + + /** + * Constructor + */ + Sha384() + { hashType = HASH_SHA384; reset(); } + + /** + * Destructor + */ + virtual ~Sha384() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + + + +private: + + uint64_t hashBuf[8]; + uint64_t inBuf[80]; + int longNr; + int byteNr; + uint64_t inb[8]; + +}; + + + + +/** + * SHA-512, + * Section 6.1, SECURE HASH STANDARD + * Federal Information Processing Standards Publication 180-2 + * http://csrc.nist.gov/publications/drafts/fips_180-3/draft_fips-180-3_June-08-2007.pdf + */ +class Sha512 : public Digest +{ +public: + + /** + * Constructor + */ + Sha512() + { hashType = HASH_SHA512; reset(); } + + /** + * Destructor + */ + virtual ~Sha512() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + +private: + + uint64_t hashBuf[8]; + uint64_t inBuf[80]; + int longNr; + int byteNr; + uint64_t inb[8]; + +}; + + + + + + + + + +/** + * IETF RFC 1321, MD5 Specification + * http://www.ietf.org/rfc/rfc1321.txt + */ +class Md5 : public Digest +{ +public: + + /** + * Constructor + */ + Md5() + { hashType = HASH_MD5; reset(); } + + /** + * Destructor + */ + virtual ~Md5() + { reset(); } + + /** + * Overloaded from Digest + */ + virtual void reset(); + + /** + * Overloaded from Digest + */ + virtual std::vector finish(); + +protected: + + /** + * Overloaded from Digest + */ + virtual void update(unsigned char val); + + /** + * Overloaded from Digest + */ + virtual void transform(); + +private: + + uint32_t hashBuf[4]; + uint32_t inBuf[16]; + + uint32_t inb[4]; // Buffer for input bytes as longs + int byteNr; // which byte in long + int longNr; // which long in 16-long buffer + +}; + + + + + + + + + +#endif /* __DIGEST_H__ */ + + diff --git a/src/dom/util/ziptool.cpp b/src/dom/util/ziptool.cpp new file mode 100644 index 000000000..9d9d5685c --- /dev/null +++ b/src/dom/util/ziptool.cpp @@ -0,0 +1,3025 @@ +/* + * This is intended to be a standalone, reduced capability + * implementation of Gzip and Zip functionality. Its + * targeted use case is for archiving and retrieving single files + * which use these encoding types. Being memory based and + * non-optimized, it is not useful in cases where very large + * archives are needed or where high performance is desired. + * However, it should hopefully work very well for smaller, + * one-at-a-time tasks. What you get in return is the ability + * to drop these files into your project and remove the dependencies + * on ZLib and Info-Zip. Enjoy. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2006-2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include +#include + +#include + +#include "ziptool.h" + + + + + + +//######################################################################## +//# A D L E R 3 2 +//######################################################################## + +/** + * Constructor + */ +Adler32::Adler32() +{ + reset(); +} + +/** + * Destructor + */ +Adler32::~Adler32() +{ +} + +/** + * Reset Adler-32 checksum to initial value. + */ +void Adler32::reset() +{ + value = 1; +} + +// ADLER32_BASE is the largest prime number smaller than 65536 +#define ADLER32_BASE 65521 + +void Adler32::update(unsigned char b) +{ + unsigned long s1 = value & 0xffff; + unsigned long s2 = (value >> 16) & 0xffff; + s1 += b & 0xff; + s2 += s1; + value = ((s2 % ADLER32_BASE) << 16) | (s1 % ADLER32_BASE); +} + +void Adler32::update(char *str) +{ + if (str) + while (*str) + update((unsigned char)*str++); +} + + +/** + * Returns current checksum value. + */ +unsigned long Adler32::getValue() +{ + return value & 0xffffffffL; +} + + + +//######################################################################## +//# C R C 3 2 +//######################################################################## + +/** + * Constructor + */ +Crc32::Crc32() +{ + reset(); +} + +/** + * Destructor + */ +Crc32::~Crc32() +{ +} + +static bool crc_table_ready = false; +static unsigned long crc_table[256]; + +/** + * make the table for a fast CRC. + */ +static void makeCrcTable() +{ + if (crc_table_ready) + return; + for (int n = 0; n < 256; n++) + { + unsigned long c = n; + for (int k = 8; --k >= 0; ) + { + if ((c & 1) != 0) + c = 0xedb88320 ^ (c >> 1); + else + c >>= 1; + } + crc_table[n] = c; + } + crc_table_ready = true; +} + + +/** + * Reset CRC-32 checksum to initial value. + */ +void Crc32::reset() +{ + value = 0; + makeCrcTable(); +} + +void Crc32::update(unsigned char b) +{ + unsigned long c = ~value; + + c &= 0xffffffff; + c = crc_table[(c ^ b) & 0xff] ^ (c >> 8); + value = ~c; +} + + +void Crc32::update(char *str) +{ + if (str) + while (*str) + update((unsigned char)*str++); +} + +void Crc32::update(const std::vector &buf) +{ + std::vector::const_iterator iter; + for (iter=buf.begin() ; iter!=buf.end() ; ++iter) + { + unsigned char ch = *iter; + update(ch); + } +} + + +/** + * Returns current checksum value. + */ +unsigned long Crc32::getValue() +{ + return value & 0xffffffffL; +} + +//######################################################################## +//# I N F L A T E R +//######################################################################## + + +/** + * + */ +typedef struct +{ + int *count; // number of symbols of each length + int *symbol; // canonically ordered symbols +} Huffman; + +/** + * + */ +class Inflater +{ +public: + + Inflater(); + + virtual ~Inflater(); + + static const int MAXBITS = 15; // max bits in a code + static const int MAXLCODES = 286; // max number of literal/length codes + static const int MAXDCODES = 30; // max number of distance codes + static const int MAXCODES = 316; // max codes lengths to read + static const int FIXLCODES = 288; // number of fixed literal/length codes + + /** + * + */ + bool inflate(std::vector &destination, + std::vector &source); + +private: + + /** + * + */ + void error(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + /** + * + */ + void trace(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + /** + * + */ + void dump(); + + /** + * + */ + int buildHuffman(Huffman *h, int *length, int n); + + /** + * + */ + bool getBits(int need, int *oval); + + /** + * + */ + int doDecode(Huffman *h); + + /** + * + */ + bool doCodes(Huffman *lencode, Huffman *distcode); + + /** + * + */ + bool doStored(); + + /** + * + */ + bool doFixed(); + + /** + * + */ + bool doDynamic(); + + + std::vectordest; + + std::vectorsrc; + unsigned long srcPos; //current read position + int bitBuf; + int bitCnt; + +}; + + +/** + * + */ +Inflater::Inflater() : + dest(), + src(), + srcPos(0), + bitBuf(0), + bitCnt(0) +{ +} + +/** + * + */ +Inflater::~Inflater() +{ +} + +/** + * + */ +void Inflater::error(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "Inflater error:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +/** + * + */ +void Inflater::trace(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "Inflater:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + + +/** + * + */ +void Inflater::dump() +{ + for (unsigned int i=0 ; icount[len] = 0; + for (int symbol = 0; symbol < n; symbol++) + (h->count[length[symbol]])++; // assumes lengths are within bounds + if (h->count[0] == n) // no codes! + { + error("huffman tree will result in failed decode"); + return -1; + } + + // check for an over-subscribed or incomplete set of lengths + int left = 1; // number of possible codes left of current length + for (int len = 1; len <= MAXBITS; len++) + { + left <<= 1; // one more bit, double codes left + left -= h->count[len]; // deduct count from possible codes + if (left < 0) + { + error("huffman over subscribed"); + return -1; + } + } + + // generate offsets into symbol table for each length for sorting + int offs[MAXBITS+1]; //offsets in symbol table for each length + offs[1] = 0; + for (int len = 1; len < MAXBITS; len++) + offs[len + 1] = offs[len] + h->count[len]; + + /* + * put symbols in table sorted by length, by symbol order within each + * length + */ + for (int symbol = 0; symbol < n; symbol++) + if (length[symbol] != 0) + h->symbol[offs[length[symbol]]++] = symbol; + + // return zero for complete set, positive for incomplete set + return left; +} + + +/** + * + */ +bool Inflater::getBits(int requiredBits, int *oval) +{ + long val = bitBuf; + + //add more bytes if needed + while (bitCnt < requiredBits) + { + if (srcPos >= src.size()) + { + error("premature end of input"); + return false; + } + val |= ((long)(src[srcPos++])) << bitCnt; + bitCnt += 8; + } + + //update the buffer and return the data + bitBuf = (int)(val >> requiredBits); + bitCnt -= requiredBits; + *oval = (int)(val & ((1L << requiredBits) - 1)); + + return true; +} + + +/** + * + */ +int Inflater::doDecode(Huffman *h) +{ + int bitTmp = bitBuf; + int left = bitCnt; + int code = 0; + int first = 0; + int index = 0; + int len = 1; + int *next = h->count + 1; + while (true) + { + while (left--) + { + code |= bitTmp & 1; + bitTmp >>= 1; + int count = *next++; + if (code < first + count) + { /* if length len, return symbol */ + bitBuf = bitTmp; + bitCnt = (bitCnt - len) & 7; + return h->symbol[index + (code - first)]; + } + index += count; + first += count; + first <<= 1; + code <<= 1; + len++; + } + left = (MAXBITS+1) - len; + if (left == 0) + break; + if (srcPos >= src.size()) + { + error("premature end of input"); + dump(); + return -1; + } + bitTmp = src[srcPos++]; + if (left > 8) + left = 8; + } + + error("no end of block found"); + return -1; +} + +/** + * + */ +bool Inflater::doCodes(Huffman *lencode, Huffman *distcode) +{ + static const int lens[29] = { // Size base for length codes 257..285 + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; + static const int lext[29] = { // Extra bits for length codes 257..285 + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; + static const int dists[30] = { // Offset base for distance codes 0..29 + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, + 8193, 12289, 16385, 24577}; + static const int dext[30] = { // Extra bits for distance codes 0..29 + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, + 12, 12, 13, 13}; + + //decode literals and length/distance pairs + while (true) + { + int symbol = doDecode(lencode); + if (symbol == 256) + break; + if (symbol < 0) + { + return false; + } + if (symbol < 256) //literal + { + dest.push_back(symbol); + } + else if (symbol > 256)//length + { + symbol -= 257; + if (symbol >= 29) + { + error("invalid fixed code"); + return false; + } + int ret; + if (!getBits(lext[symbol], &ret)) + return false; + int len = lens[symbol] + ret; + + symbol = doDecode(distcode);//distance + if (symbol < 0) + { + return false; + } + + if (!getBits(dext[symbol], &ret)) + return false; + unsigned int dist = dists[symbol] + ret; + if (dist > dest.size()) + { + error("distance too far back %d/%d", dist, dest.size()); + dump(); + //printf("pos:%d\n", srcPos); + return false; + } + + // copy length bytes from distance bytes back + //dest.push_back('{'); + while (len--) + { + dest.push_back(dest[dest.size() - dist]); + } + //dest.push_back('}'); + + } + } + + return true; +} + +/** + */ +bool Inflater::doStored() +{ + //trace("### stored ###"); + + // clear bits from current byte + bitBuf = 0; + bitCnt = 0; + + // length + if (srcPos + 4 > src.size()) + { + error("not enough input"); + return false; + } + + int len = src[srcPos++]; + len |= src[srcPos++] << 8; + //trace("### len:%d", len); + // check complement + if (src[srcPos++] != (~len & 0xff) || + src[srcPos++] != ((~len >> 8) & 0xff)) + { + error("twos complement for storage size do not match"); + return false; + } + + // copy data + if (srcPos + len > src.size()) + { + error("Not enough input for stored block"); + return false; + } + while (len--) + dest.push_back(src[srcPos++]); + + return true; +} + +/** + */ +bool Inflater::doFixed() +{ + //trace("### fixed ###"); + + static bool firstTime = true; + static int lencnt[MAXBITS+1], lensym[FIXLCODES]; + static int distcnt[MAXBITS+1], distsym[MAXDCODES]; + static Huffman lencode = {lencnt, lensym}; + static Huffman distcode = {distcnt, distsym}; + + if (firstTime) + { + firstTime = false; + + int lengths[FIXLCODES]; + + // literal/length table + int symbol = 0; + for ( ; symbol < 144; symbol++) + lengths[symbol] = 8; + for ( ; symbol < 256; symbol++) + lengths[symbol] = 9; + for ( ; symbol < 280; symbol++) + lengths[symbol] = 7; + for ( ; symbol < FIXLCODES; symbol++) + lengths[symbol] = 8; + buildHuffman(&lencode, lengths, FIXLCODES); + + // distance table + for (int symbol = 0; symbol < MAXDCODES; symbol++) + lengths[symbol] = 5; + buildHuffman(&distcode, lengths, MAXDCODES); + } + + // decode data until end-of-block code + bool ret = doCodes(&lencode, &distcode); + return ret; +} + +/** + */ +bool Inflater::doDynamic() +{ + //trace("### dynamic ###"); + int lengths[MAXCODES]; // descriptor code lengths + int lencnt[MAXBITS+1], lensym[MAXLCODES]; // lencode memory + int distcnt[MAXBITS+1], distsym[MAXDCODES]; // distcode memory + Huffman lencode = {lencnt, lensym}; // length code + Huffman distcode = {distcnt, distsym}; // distance code + static const int order[19] = // permutation of code length codes + {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; + + // get number of lengths in each table, check lengths + int ret; + if (!getBits(5, &ret)) + return false; + int nlen = ret + 257; + if (!getBits(5, &ret)) + return false; + int ndist = ret + 1; + if (!getBits(4, &ret)) + return false; + int ncode = ret + 4; + if (nlen > MAXLCODES || ndist > MAXDCODES) + { + error("Bad codes"); + return false; + } + + // get code length code lengths + int index = 0; + for ( ; index < ncode; index++) + { + if (!getBits(3, &ret)) + return false; + lengths[order[index]] = ret; + } + for ( ; index < 19; index++) + lengths[order[index]] = 0; + + // build huffman table for code lengths codes + if (buildHuffman(&lencode, lengths, 19) != 0) + return false; + + // read length/literal and distance code length tables + index = 0; + while (index < nlen + ndist) + { + int symbol = doDecode(&lencode); + if (symbol < 16) // length in 0..15 + lengths[index++] = symbol; + else + { // repeat instruction + int len = 0; // assume repeating zeros + if (symbol == 16) + { // repeat last length 3..6 times + if (index == 0) + { + error("no last length"); + return false; + } + len = lengths[index - 1];// last length + if (!getBits(2, &ret)) + return false; + symbol = 3 + ret; + } + else if (symbol == 17) // repeat zero 3..10 times + { + if (!getBits(3, &ret)) + return false; + symbol = 3 + ret; + } + else // == 18, repeat zero 11..138 times + { + if (!getBits(7, &ret)) + return false; + symbol = 11 + ret; + } + if (index + symbol > nlen + ndist) + { + error("too many lengths"); + return false; + } + while (symbol--) // repeat last or zero symbol times + lengths[index++] = len; + } + } + + // build huffman table for literal/length codes + int err = buildHuffman(&lencode, lengths, nlen); + if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) + { + error("incomplete length codes"); + //return false; + } + // build huffman table for distance codes + err = buildHuffman(&distcode, lengths + nlen, ndist); + if (err < 0 || (err > 0 && nlen - lencode.count[0] != 1)) + { + error("incomplete dist codes"); + return false; + } + + // decode data until end-of-block code + bool retn = doCodes(&lencode, &distcode); + return retn; +} + +/** + */ +bool Inflater::inflate(std::vector &destination, + std::vector &source) +{ + dest.clear(); + src = source; + srcPos = 0; + bitBuf = 0; + bitCnt = 0; + + while (true) + { + int last; // one if last block + if (!getBits(1, &last)) + return false; + int type; // block type 0..3 + if (!getBits(2, &type)) + return false; + switch (type) + { + case 0: + if (!doStored()) + return false; + break; + case 1: + if (!doFixed()) + return false; + break; + case 2: + if (!doDynamic()) + return false; + break; + default: + error("Unknown block type %d", type); + return false; + } + if (last) + break; + } + + destination = dest; + + return true; +} + + + + + + +//######################################################################## +//# D E F L A T E R +//######################################################################## + + +#define DEFLATER_BUF_SIZE 32768 +class Deflater +{ +public: + + /** + * + */ + Deflater(); + + /** + * + */ + virtual ~Deflater(); + + /** + * + */ + virtual void reset(); + + /** + * + */ + virtual bool update(int ch); + + /** + * + */ + virtual bool finish(); + + /** + * + */ + virtual std::vector &getCompressed(); + + /** + * + */ + bool deflate(std::vector &dest, + const std::vector &src); + + void encodeDistStatic(unsigned int len, unsigned int dist); + +private: + + //debug messages + void error(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + void trace(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + bool compressWindow(); + + bool compress(); + + std::vector compressed; + + std::vector uncompressed; + + std::vector window; + + unsigned int windowPos; + + //#### Output + unsigned int outputBitBuf; + unsigned int outputNrBits; + + void put(int ch); + + void putWord(int ch); + + void putFlush(); + + void putBits(unsigned int ch, unsigned int bitsWanted); + + void putBitsR(unsigned int ch, unsigned int bitsWanted); + + //#### Huffman Encode + void encodeLiteralStatic(unsigned int ch); + + unsigned char windowBuf[DEFLATER_BUF_SIZE]; + //assume 32-bit ints + unsigned int windowHashBuf[DEFLATER_BUF_SIZE]; +}; + + +//######################################################################## +//# A P I +//######################################################################## + + +/** + * + */ +Deflater::Deflater() +{ + reset(); +} + +/** + * + */ +Deflater::~Deflater() +{ + +} + +/** + * + */ +void Deflater::reset() +{ + compressed.clear(); + uncompressed.clear(); + window.clear(); + windowPos = 0; + outputBitBuf = 0; + outputNrBits = 0; + for (int k=0; k &Deflater::getCompressed() +{ + return compressed; +} + + +/** + * + */ +bool Deflater::deflate(std::vector &dest, + const std::vector &src) +{ + reset(); + uncompressed = src; + if (!compress()) + return false; + dest = compressed; + return true; +} + + + + + + + +//######################################################################## +//# W O R K I N G C O D E +//######################################################################## + + +//############################# +//# M E S S A G E S +//############################# + +/** + * Print error messages + */ +void Deflater::error(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "Deflater error:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +/** + * Print trace messages + */ +void Deflater::trace(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "Deflater:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + + + + +//############################# +//# O U T P U T +//############################# + +/** + * + */ +void Deflater::put(int ch) +{ + compressed.push_back(ch); + outputBitBuf = 0; + outputNrBits = 0; +} + +/** + * + */ +void Deflater::putWord(int ch) +{ + int lo = (ch ) & 0xff; + int hi = (ch>>8) & 0xff; + put(lo); + put(hi); +} + +/** + * + */ +void Deflater::putFlush() +{ + if (outputNrBits > 0) + { + put(outputBitBuf & 0xff); + } + outputBitBuf = 0; + outputNrBits = 0; +} + +/** + * + */ +void Deflater::putBits(unsigned int ch, unsigned int bitsWanted) +{ + //trace("n:%4u, %d\n", ch, bitsWanted); + + while (bitsWanted--) + { + //add bits to position 7. shift right + outputBitBuf = (outputBitBuf>>1) + (ch<<7 & 0x80); + ch >>= 1; + outputNrBits++; + if (outputNrBits >= 8) + { + unsigned char b = outputBitBuf & 0xff; + //printf("b:%02x\n", b); + put(b); + } + } +} + +static unsigned int bitReverse(unsigned int code, unsigned int nrBits) +{ + unsigned int outb = 0; + while (nrBits--) + { + outb = (outb << 1) | (code & 0x01); + code >>= 1; + } + return outb; +} + + +/** + * + */ +void Deflater::putBitsR(unsigned int ch, unsigned int bitsWanted) +{ + //trace("r:%4u, %d", ch, bitsWanted); + + unsigned int rcode = bitReverse(ch, bitsWanted); + + putBits(rcode, bitsWanted); + +} + + +//############################# +//# E N C O D E +//############################# + + + +void Deflater::encodeLiteralStatic(unsigned int ch) +{ + //trace("c: %d", ch); + + if (ch < 144) + { + putBitsR(ch + 0x0030 , 8); // 00110000 + } + else if (ch < 256) + { + putBitsR(ch - 144 + 0x0190 , 9); // 110010000 + } + else if (ch < 280) + { + putBitsR(ch - 256 + 0x0000 , 7); // 0000000 + } + else if (ch < 288) + { + putBitsR(ch - 280 + 0x00c0 , 8); // 11000000 + } + else //out of range + { + error("Literal out of range: %d", ch); + } + +} + + +typedef struct +{ + unsigned int base; + unsigned int range; + unsigned int bits; +} LenBase; + +LenBase lenBases[] = +{ + { 3, 1, 0 }, + { 4, 1, 0 }, + { 5, 1, 0 }, + { 6, 1, 0 }, + { 7, 1, 0 }, + { 8, 1, 0 }, + { 9, 1, 0 }, + { 10, 1, 0 }, + { 11, 2, 1 }, + { 13, 2, 1 }, + { 15, 2, 1 }, + { 17, 2, 1 }, + { 19, 4, 2 }, + { 23, 4, 2 }, + { 27, 4, 2 }, + { 31, 4, 2 }, + { 35, 8, 3 }, + { 43, 8, 3 }, + { 51, 8, 3 }, + { 59, 8, 3 }, + { 67, 16, 4 }, + { 83, 16, 4 }, + { 99, 16, 4 }, + { 115, 16, 4 }, + { 131, 32, 5 }, + { 163, 32, 5 }, + { 195, 32, 5 }, + { 227, 32, 5 }, + { 258, 1, 0 } +}; + +typedef struct +{ + unsigned int base; + unsigned int range; + unsigned int bits; +} DistBase; + +DistBase distBases[] = +{ + { 1, 1, 0 }, + { 2, 1, 0 }, + { 3, 1, 0 }, + { 4, 1, 0 }, + { 5, 2, 1 }, + { 7, 2, 1 }, + { 9, 4, 2 }, + { 13, 4, 2 }, + { 17, 8, 3 }, + { 25, 8, 3 }, + { 33, 16, 4 }, + { 49, 16, 4 }, + { 65, 32, 5 }, + { 97, 32, 5 }, + { 129, 64, 6 }, + { 193, 64, 6 }, + { 257, 128, 7 }, + { 385, 128, 7 }, + { 513, 256, 8 }, + { 769, 256, 8 }, + { 1025, 512, 9 }, + { 1537, 512, 9 }, + { 2049, 1024, 10 }, + { 3073, 1024, 10 }, + { 4097, 2048, 11 }, + { 6145, 2048, 11 }, + { 8193, 4096, 12 }, + { 12289, 4096, 12 }, + { 16385, 8192, 13 }, + { 24577, 8192, 13 } +}; + +void Deflater::encodeDistStatic(unsigned int len, unsigned int dist) +{ + + //## Output length + + if (len < 3 || len > 258) + { + error("Length out of range:%d", len); + return; + } + + bool found = false; + for (int i=0 ; i<30 ; i++) + { + unsigned int base = lenBases[i].base; + unsigned int range = lenBases[i].range; + if (base + range > len) + { + unsigned int lenCode = 257 + i; + unsigned int length = len - base; + //trace("--- %d %d %d %d", len, base, range, length); + encodeLiteralStatic(lenCode); + putBits(length, lenBases[i].bits); + found = true; + break; + } + } + if (!found) + { + error("Length not found in table:%d", len); + return; + } + + //## Output distance + + if (dist < 4 || dist > 32768) + { + error("Distance out of range:%d", dist); + return; + } + + found = false; + for (int i=0 ; i<30 ; i++) + { + unsigned int base = distBases[i].base; + unsigned int range = distBases[i].range; + if (base + range > dist) + { + unsigned int distCode = i; + unsigned int distance = dist - base; + //error("--- %d %d %d %d", dist, base, range, distance); + putBitsR(distCode, 5); + putBits(distance, distBases[i].bits); + found = true; + break; + } + } + if (!found) + { + error("Distance not found in table:%d", dist); + return; + } +} + + +//############################# +//# C O M P R E S S +//############################# + + +/** + * This method does the dirty work of dictionary + * compression. Basically it looks for redundant + * strings and has the current duplicate refer back + * to the previous one. + */ +bool Deflater::compressWindow() +{ + windowPos = 0; + unsigned int windowSize = window.size(); + //### Compress as much of the window as possible + + unsigned int hash = 0; + //Have each value be a long with the byte at this position, + //plus the 3 bytes after it in the window + for (int i=windowSize-1 ; i>=0 ; i--) + { + unsigned char ch = window[i]; + windowBuf[i] = ch; + hash = ((hash<<8) & 0xffffff00) | ch; + windowHashBuf[i] = hash; + } + + while (windowPos < windowSize - 3) + { + //### Find best match, if any + unsigned int bestMatchLen = 0; + unsigned int bestMatchDist = 0; + if (windowPos >= 4) + { + for (unsigned int lookBack=0 ; lookBack= windowPos -4 ) + lookAheadMax = windowPos - 4 - lookBack; + if (lookAheadMax > 258) + lookAheadMax = 258; + unsigned char *wp = &(windowBuf[windowPos+4]); + unsigned char *lb = &(windowBuf[lookBack+4]); + while (lookAhead bestMatchLen) + { + bestMatchLen = lookAhead; + bestMatchDist = windowPos - lookBack; + } + } + } + } + if (bestMatchLen > 3) + { + //Distance encode + //trace("### distance"); + /* + printf("### 1 '"); + for (int i=0 ; i < bestMatchLen ; i++) + fputc(window[windowPos+i], stdout); + printf("'\n### 2 '"); + for (int i=0 ; i < bestMatchLen ; i++) + fputc(window[windowPos-bestMatchDist+i], stdout); + printf("'\n"); + */ + encodeDistStatic(bestMatchLen, bestMatchDist); + windowPos += bestMatchLen; + } + else + { + //Literal encode + //trace("### literal"); + encodeLiteralStatic(windowBuf[windowPos]); + windowPos++; + } + } + + while (windowPos < windowSize) + encodeLiteralStatic(windowBuf[windowPos++]); + + encodeLiteralStatic(256); + return true; +} + + +/** + * + */ +bool Deflater::compress() +{ + //trace("compress"); + unsigned long total = 0L; + windowPos = 0; + std::vector::iterator iter; + for (iter = uncompressed.begin(); iter != uncompressed.end() ; ) + { + total += windowPos; + trace("total:%ld", total); + if (windowPos > window.size()) + windowPos = window.size(); + window.erase(window.begin() , window.begin()+windowPos); + while (window.size() < 32768 && iter != uncompressed.end()) + { + window.push_back(*iter); + ++iter; + } + if (window.size() >= 32768) + putBits(0x00, 1); //0 -- more blocks + else + putBits(0x01, 1); //1 -- last block + putBits(0x01, 2); //01 -- static trees + if (!compressWindow()) + return false; + } + putFlush(); + return true; +} + + + + + +//######################################################################## +//# G Z I P F I L E +//######################################################################## + +/** + * Constructor + */ +GzipFile::GzipFile() : + data(), + fileName(), + fileBuf(), + fileBufPos(0), + compressionMethod(0) +{ +} + +/** + * Destructor + */ +GzipFile::~GzipFile() +{ +} + +/** + * Print error messages + */ +void GzipFile::error(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "GzipFile error:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +/** + * Print trace messages + */ +void GzipFile::trace(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "GzipFile:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +/** + * + */ +void GzipFile::put(unsigned char ch) +{ + data.push_back(ch); +} + +/** + * + */ +void GzipFile::setData(const std::vector &str) +{ + data = str; +} + +/** + * + */ +void GzipFile::clearData() +{ + data.clear(); +} + +/** + * + */ +std::vector &GzipFile::getData() +{ + return data; +} + +/** + * + */ +std::string &GzipFile::getFileName() +{ + return fileName; +} + +/** + * + */ +void GzipFile::setFileName(const std::string &val) +{ + fileName = val; +} + + + +//##################################### +//# U T I L I T Y +//##################################### + +/** + * Loads a new file into an existing GzipFile + */ +bool GzipFile::loadFile(const std::string &fName) +{ + FILE *f = fopen(fName.c_str() , "rb"); + if (!f) + { + error("Cannot open file %s", fName.c_str()); + return false; + } + while (true) + { + int ch = fgetc(f); + if (ch < 0) + break; + data.push_back(ch); + } + fclose(f); + setFileName(fName); + return true; +} + + + +//##################################### +//# W R I T E +//##################################### + +/** + * + */ +bool GzipFile::putByte(unsigned char ch) +{ + fileBuf.push_back(ch); + return true; +} + + + +/** + * + */ +bool GzipFile::putLong(unsigned long val) +{ + fileBuf.push_back( (unsigned char)((val ) & 0xff)); + fileBuf.push_back( (unsigned char)((val>> 8) & 0xff)); + fileBuf.push_back( (unsigned char)((val>>16) & 0xff)); + fileBuf.push_back( (unsigned char)((val>>24) & 0xff)); + return true; +} + + + +/** + * + */ +bool GzipFile::write() +{ + fileBuf.clear(); + + putByte(0x1f); //magic + putByte(0x8b); //magic + putByte( 8); //compression method + putByte(0x08); //flags. say we have a crc and file name + + unsigned long ltime = (unsigned long) time(NULL); + putLong(ltime); + + //xfl + putByte(0); + //OS + putByte(0); + + //file name + for (unsigned int i=0 ; i compBuf; + Deflater deflater; + if (!deflater.deflate(compBuf, data)) + { + return false; + } + + std::vector::iterator iter; + for (iter=compBuf.begin() ; iter!=compBuf.end() ; ++iter) + { + unsigned char ch = *iter; + putByte(ch); + } + + Crc32 crcEngine; + crcEngine.update(data); + unsigned long crc = crcEngine.getValue(); + putLong(crc); + + putLong(data.size()); + + return true; +} + + +/** + * + */ +bool GzipFile::writeBuffer(std::vector &outBuf) +{ + if (!write()) + return false; + outBuf.clear(); + outBuf = fileBuf; + return true; +} + + +/** + * + */ +bool GzipFile::writeFile(const std::string &fileName) +{ + if (!write()) + return false; + FILE *f = fopen(fileName.c_str(), "wb"); + if (!f) + return false; + std::vector::iterator iter; + for (iter=fileBuf.begin() ; iter!=fileBuf.end() ; ++iter) + { + unsigned char ch = *iter; + fputc(ch, f); + } + fclose(f); + return true; +} + + +//##################################### +//# R E A D +//##################################### + +bool GzipFile::getByte(unsigned char *ch) +{ + if (fileBufPos >= fileBuf.size()) + { + error("unexpected end of data"); + return false; + } + *ch = fileBuf[fileBufPos++]; + return true; +} + +/** + * + */ +bool GzipFile::getLong(unsigned long *val) +{ + if (fileBuf.size() - fileBufPos < 4) + return false; + int ch1 = fileBuf[fileBufPos++]; + int ch2 = fileBuf[fileBufPos++]; + int ch3 = fileBuf[fileBufPos++]; + int ch4 = fileBuf[fileBufPos++]; + *val = ((ch4<<24) & 0xff000000L) | + ((ch3<<16) & 0x00ff0000L) | + ((ch2<< 8) & 0x0000ff00L) | + ((ch1 ) & 0x000000ffL); + return true; +} + +bool GzipFile::read() +{ + fileBufPos = 0; + + unsigned char ch; + + //magic cookie + if (!getByte(&ch)) + return false; + if (ch != 0x1f) + { + error("bad gzip header"); + return false; + } + if (!getByte(&ch)) + return false; + if (ch != 0x8b) + { + error("bad gzip header"); + return false; + } + + //## compression method + if (!getByte(&ch)) + return false; + compressionMethod = ch & 0xff; + + //## flags + if (!getByte(&ch)) + return false; + //bool ftext = ch & 0x01; + bool fhcrc = ch & 0x02; + bool fextra = ch & 0x04; + bool fname = ch & 0x08; + bool fcomment = ch & 0x10; + + //trace("cm:%d ftext:%d fhcrc:%d fextra:%d fname:%d fcomment:%d", + // cm, ftext, fhcrc, fextra, fname, fcomment); + + //## file time + unsigned long ltime; + if (!getLong(<ime)) + return false; + //time_t mtime = (time_t)ltime; + + //## XFL + if (!getByte(&ch)) + return false; + //int xfl = ch; + + //## OS + if (!getByte(&ch)) + return false; + //int os = ch; + + //std::string timestr = ctime(&mtime); + //trace("xfl:%d os:%d mtime:%s", xfl, os, timestr.c_str()); + + if (fextra) + { + if (!getByte(&ch)) + return false; + long xlen = ch; + if (!getByte(&ch)) + return false; + xlen = (xlen << 8) + ch; + for (long l=0 ; l compBuf; + while (fileBufPos < fileBuf.size() - 8) + { + if (!getByte(&ch)) + return false; + compBuf.push_back(ch); + } + //uncompress + data.clear(); + Inflater inflater; + if (!inflater.inflate(data, compBuf)) + { + return false; + } + + //Get the CRC and compare + Crc32 crcEngine; + crcEngine.update(data); + unsigned long calcCrc = crcEngine.getValue(); + unsigned long givenCrc; + if (!getLong(&givenCrc)) + return false; + if (givenCrc != calcCrc) + { + error("Specified crc, %ud, not what received: %ud", + givenCrc, calcCrc); + return false; + } + + //Get the file size and compare + unsigned long givenFileSize; + if (!getLong(&givenFileSize)) + return false; + if (givenFileSize != data.size()) + { + error("Specified data size, %ld, not what received: %ld", + givenFileSize, data.size()); + return false; + } + + return true; +} + + + +/** + * + */ +bool GzipFile::readBuffer(const std::vector &inbuf) +{ + fileBuf = inbuf; + if (!read()) + return false; + return true; +} + + +/** + * + */ +bool GzipFile::readFile(const std::string &fileName) +{ + fileBuf.clear(); + FILE *f = fopen(fileName.c_str(), "rb"); + if (!f) + return false; + while (true) + { + int ch = fgetc(f); + if (ch < 0) + break; + fileBuf.push_back(ch); + } + fclose(f); + if (!read()) + return false; + return true; +} + + + + + + + + +//######################################################################## +//# Z I P F I L E +//######################################################################## + +/** + * Constructor + */ +ZipEntry::ZipEntry() +{ + crc = 0L; + compressionMethod = 8; + position = 0; +} + +/** + * + */ +ZipEntry::ZipEntry(const std::string &fileNameArg, + const std::string &commentArg) +{ + crc = 0L; + compressionMethod = 8; + fileName = fileNameArg; + comment = commentArg; + position = 0; +} + +/** + * Destructor + */ +ZipEntry::~ZipEntry() +{ +} + + +/** + * + */ +std::string ZipEntry::getFileName() +{ + return fileName; +} + +/** + * + */ +void ZipEntry::setFileName(const std::string &val) +{ + fileName = val; +} + +/** + * + */ +std::string ZipEntry::getComment() +{ + return comment; +} + +/** + * + */ +void ZipEntry::setComment(const std::string &val) +{ + comment = val; +} + +/** + * + */ +unsigned long ZipEntry::getCompressedSize() +{ + return (unsigned long)compressedData.size(); +} + +/** + * + */ +int ZipEntry::getCompressionMethod() +{ + return compressionMethod; +} + +/** + * + */ +void ZipEntry::setCompressionMethod(int val) +{ + compressionMethod = val; +} + +/** + * + */ +std::vector &ZipEntry::getCompressedData() +{ + return compressedData; +} + +/** + * + */ +void ZipEntry::setCompressedData(const std::vector &val) +{ + compressedData = val; +} + +/** + * + */ +unsigned long ZipEntry::getUncompressedSize() +{ + return (unsigned long)uncompressedData.size(); +} + +/** + * + */ +std::vector &ZipEntry::getUncompressedData() +{ + return uncompressedData; +} + +/** + * + */ +void ZipEntry::setUncompressedData(const std::vector &val) +{ + uncompressedData = val; +} + +/** + * + */ +unsigned long ZipEntry::getCrc() +{ + return crc; +} + +/** + * + */ +void ZipEntry::setCrc(unsigned long val) +{ + crc = val; +} + +/** + * + */ +void ZipEntry::write(unsigned char ch) +{ + uncompressedData.push_back(ch); +} + +/** + * + */ +void ZipEntry::finish() +{ + Crc32 c32; + std::vector::iterator iter; + for (iter = uncompressedData.begin() ; + iter!= uncompressedData.end() ; ++iter) + { + unsigned char ch = *iter; + c32.update(ch); + } + crc = c32.getValue(); + switch (compressionMethod) + { + case 0: //none + { + for (iter = uncompressedData.begin() ; + iter!= uncompressedData.end() ; ++iter) + { + unsigned char ch = *iter; + compressedData.push_back(ch); + } + break; + } + case 8: //deflate + { + Deflater deflater; + if (!deflater.deflate(compressedData, uncompressedData)) + { + //some error + } + break; + } + default: + { + printf("error: unknown compression method %d\n", + compressionMethod); + } + } +} + + + + +/** + * + */ +bool ZipEntry::readFile(const std::string &fileNameArg, + const std::string &commentArg) +{ + crc = 0L; + uncompressedData.clear(); + fileName = fileNameArg; + comment = commentArg; + FILE *f = fopen(fileName.c_str(), "rb"); + if (!f) + { + return false; + } + while (true) + { + int ch = fgetc(f); + if (ch < 0) + break; + uncompressedData.push_back((unsigned char)ch); + } + fclose(f); + finish(); + return true; +} + + +/** + * + */ +void ZipEntry::setPosition(unsigned long val) +{ + position = val; +} + +/** + * + */ +unsigned long ZipEntry::getPosition() +{ + return position; +} + + + + + + + +/** + * Constructor + */ +ZipFile::ZipFile() : + entries(), + fileBuf(), + fileBufPos(0), + comment() +{ +} + +/** + * Destructor + */ +ZipFile::~ZipFile() +{ + std::vector::iterator iter; + for (iter=entries.begin() ; iter!=entries.end() ; ++iter) + { + ZipEntry *entry = *iter; + delete entry; + } + entries.clear(); +} + +/** + * + */ +void ZipFile::setComment(const std::string &val) +{ + comment = val; +} + +/** + * + */ +std::string ZipFile::getComment() +{ + return comment; +} + + +/** + * + */ +std::vector &ZipFile::getEntries() +{ + return entries; +} + + + +//##################################### +//# M E S S A G E S +//##################################### + +void ZipFile::error(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "ZipFile error:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +void ZipFile::trace(char const *fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stdout, "ZipFile:"); + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); + va_end(args); +} + +//##################################### +//# U T I L I T Y +//##################################### + +/** + * + */ +ZipEntry *ZipFile::addFile(const std::string &fileName, + const std::string &comment) +{ + ZipEntry *ze = new ZipEntry(); + if (!ze->readFile(fileName, comment)) + { + delete ze; + return NULL; + } + entries.push_back(ze); + return ze; +} + + +/** + * + */ +ZipEntry *ZipFile::newEntry(const std::string &fileName, + const std::string &comment) +{ + ZipEntry *ze = new ZipEntry(fileName, comment); + entries.push_back(ze); + return ze; +} + + +//##################################### +//# W R I T E +//##################################### + +/** + * + */ +bool ZipFile::putLong(unsigned long val) +{ + fileBuf.push_back( ((int)(val )) & 0xff); + fileBuf.push_back( ((int)(val>> 8)) & 0xff); + fileBuf.push_back( ((int)(val>>16)) & 0xff); + fileBuf.push_back( ((int)(val>>24)) & 0xff); + return true; +} + + +/** + * + */ +bool ZipFile::putInt(unsigned int val) +{ + fileBuf.push_back( (val ) & 0xff); + fileBuf.push_back( (val>> 8) & 0xff); + return true; +} + +/** + * + */ +bool ZipFile::putByte(unsigned char val) +{ + fileBuf.push_back(val); + return true; +} + +/** + * + */ +bool ZipFile::writeFileData() +{ + std::vector::iterator iter; + for (iter = entries.begin() ; iter != entries.end() ; ++iter) + { + ZipEntry *entry = *iter; + entry->setPosition(fileBuf.size()); + //##### HEADER + std::string fname = entry->getFileName(); + putLong(0x04034b50L); + putInt(20); //versionNeeded + putInt(0); //gpBitFlag + //putInt(0); //compression method + putInt(entry->getCompressionMethod()); //compression method + putInt(0); //mod time + putInt(0); //mod date + putLong(entry->getCrc()); //crc32 + putLong(entry->getCompressedSize()); + putLong(entry->getUncompressedSize()); + putInt(fname.size());//fileName length + putInt(8);//extra field length + //file name + for (unsigned int i=0 ; i &buf = entry->getCompressedData(); + std::vector::iterator iter; + for (iter = buf.begin() ; iter != buf.end() ; ++iter) + { + unsigned char ch = (unsigned char) *iter; + putByte(ch); + } + } + return true; +} + +/** + * + */ +bool ZipFile::writeCentralDirectory() +{ + unsigned long cdPosition = fileBuf.size(); + std::vector::iterator iter; + for (iter = entries.begin() ; iter != entries.end() ; ++iter) + { + ZipEntry *entry = *iter; + std::string fname = entry->getFileName(); + std::string ecomment = entry->getComment(); + putLong(0x02014b50L); //magic cookie + putInt(2386); //versionMadeBy + putInt(20); //versionNeeded + putInt(0); //gpBitFlag + putInt(entry->getCompressionMethod()); //compression method + putInt(0); //mod time + putInt(0); //mod date + putLong(entry->getCrc()); //crc32 + putLong(entry->getCompressedSize()); + putLong(entry->getUncompressedSize()); + putInt(fname.size());//fileName length + putInt(4);//extra field length + putInt(ecomment.size());//comment length + putInt(0); //disk number start + putInt(0); //internal attributes + putLong(0); //external attributes + putLong(entry->getPosition()); + + //file name + for (unsigned int i=0 ; i &outBuf) +{ + if (!write()) + return false; + outBuf.clear(); + outBuf = fileBuf; + return true; +} + + +/** + * + */ +bool ZipFile::writeFile(const std::string &fileName) +{ + if (!write()) + return false; + FILE *f = fopen(fileName.c_str(), "wb"); + if (!f) + return false; + std::vector::iterator iter; + for (iter=fileBuf.begin() ; iter!=fileBuf.end() ; ++iter) + { + unsigned char ch = *iter; + fputc(ch, f); + } + fclose(f); + return true; +} + +//##################################### +//# R E A D +//##################################### + +/** + * + */ +bool ZipFile::getLong(unsigned long *val) +{ + if (fileBuf.size() - fileBufPos < 4) + return false; + int ch1 = fileBuf[fileBufPos++]; + int ch2 = fileBuf[fileBufPos++]; + int ch3 = fileBuf[fileBufPos++]; + int ch4 = fileBuf[fileBufPos++]; + *val = ((ch4<<24) & 0xff000000L) | + ((ch3<<16) & 0x00ff0000L) | + ((ch2<< 8) & 0x0000ff00L) | + ((ch1 ) & 0x000000ffL); + return true; +} + +/** + * + */ +bool ZipFile::getInt(unsigned int *val) +{ + if (fileBuf.size() - fileBufPos < 2) + return false; + int ch1 = fileBuf[fileBufPos++]; + int ch2 = fileBuf[fileBufPos++]; + *val = ((ch2<< 8) & 0xff00) | + ((ch1 ) & 0x00ff); + return true; +} + + +/** + * + */ +bool ZipFile::getByte(unsigned char *val) +{ + if (fileBuf.size() <= fileBufPos) + return false; + *val = fileBuf[fileBufPos++]; + return true; +} + + +/** + * + */ +bool ZipFile::readFileData() +{ + //printf("#################################################\n"); + //printf("###D A T A\n"); + //printf("#################################################\n"); + while (true) + { + unsigned long magicCookie; + if (!getLong(&magicCookie)) + { + error("magic cookie not found"); + break; + } + trace("###Cookie:%lx", magicCookie); + if (magicCookie == 0x02014b50L) //central directory + break; + if (magicCookie != 0x04034b50L) + { + error("file header not found"); + return false; + } + unsigned int versionNeeded; + if (!getInt(&versionNeeded)) + { + error("bad version needed found"); + return false; + } + unsigned int gpBitFlag; + if (!getInt(&gpBitFlag)) + { + error("bad bit flag found"); + return false; + } + unsigned int compressionMethod; + if (!getInt(&compressionMethod)) + { + error("bad compressionMethod found"); + return false; + } + unsigned int modTime; + if (!getInt(&modTime)) + { + error("bad modTime found"); + return false; + } + unsigned int modDate; + if (!getInt(&modDate)) + { + error("bad modDate found"); + return false; + } + unsigned long crc32; + if (!getLong(&crc32)) + { + error("bad crc32 found"); + return false; + } + unsigned long compressedSize; + if (!getLong(&compressedSize)) + { + error("bad compressedSize found"); + return false; + } + unsigned long uncompressedSize; + if (!getLong(&uncompressedSize)) + { + error("bad uncompressedSize found"); + return false; + } + unsigned int fileNameLength; + if (!getInt(&fileNameLength)) + { + error("bad fileNameLength found"); + return false; + } + unsigned int extraFieldLength; + if (!getInt(&extraFieldLength)) + { + error("bad extraFieldLength found"); + return false; + } + std::string fileName; + for (unsigned int i=0 ; i compBuf; + if (gpBitFlag & 0x8)//bit 3 was set. means we dont know compressed size + { + unsigned char c1, c2, c3, c4; + c1 = c2 = c3 = c4 = 0; + while (true) + { + unsigned char ch; + if (!getByte(&ch)) + { + error("premature end of data"); + break; + } + compBuf.push_back(ch); + c1 = c2; c2 = c3; c3 = c4; c4 = ch; + if (c1 == 0x50 && c2 == 0x4b && c3 == 0x07 && c4 == 0x08) + { + trace("found end of compressed data"); + //remove the cookie + compBuf.erase(compBuf.end() -4, compBuf.end()); + break; + } + } + } + else + { + for (unsigned long bnr = 0 ; bnr < compressedSize ; bnr++) + { + unsigned char ch; + if (!getByte(&ch)) + { + error("premature end of data"); + break; + } + compBuf.push_back(ch); + } + } + + printf("### data: "); + for (int i=0 ; i<10 ; i++) + printf("%02x ", compBuf[i] & 0xff); + printf("\n"); + + if (gpBitFlag & 0x8)//only if bit 3 set + { + /* this cookie was read in the loop above + unsigned long dataDescriptorSignature ; + if (!getLong(&dataDescriptorSignature)) + break; + if (dataDescriptorSignature != 0x08074b50L) + { + error("bad dataDescriptorSignature found"); + return false; + } + */ + unsigned long crc32; + if (!getLong(&crc32)) + { + error("bad crc32 found"); + return false; + } + unsigned long compressedSize; + if (!getLong(&compressedSize)) + { + error("bad compressedSize found"); + return false; + } + unsigned long uncompressedSize; + if (!getLong(&uncompressedSize)) + { + error("bad uncompressedSize found"); + return false; + } + }//bit 3 was set + //break; + + std::vector uncompBuf; + switch (compressionMethod) + { + case 8: //deflate + { + Inflater inflater; + if (!inflater.inflate(uncompBuf, compBuf)) + { + return false; + } + break; + } + default: + { + error("Unimplemented compression method %d", compressionMethod); + return false; + } + } + + if (uncompressedSize != uncompBuf.size()) + { + error("Size mismatch. Expected %ld, received %ld", + uncompressedSize, uncompBuf.size()); + return false; + } + + Crc32 crcEngine; + crcEngine.update(uncompBuf); + unsigned long crc = crcEngine.getValue(); + if (crc != crc32) + { + error("Crc mismatch. Calculated %08ux, received %08ux", crc, crc32); + return false; + } + + ZipEntry *ze = new ZipEntry(fileName, comment); + ze->setCompressionMethod(compressionMethod); + ze->setCompressedData(compBuf); + ze->setUncompressedData(uncompBuf); + ze->setCrc(crc); + entries.push_back(ze); + + + } + return true; +} + + +/** + * + */ +bool ZipFile::readCentralDirectory() +{ + //printf("#################################################\n"); + //printf("###D I R E C T O R Y\n"); + //printf("#################################################\n"); + while (true) + { + //We start with a central directory cookie already + //Check at the bottom of the loop. + unsigned int version; + if (!getInt(&version)) + { + error("bad version found"); + return false; + } + unsigned int versionNeeded; + if (!getInt(&versionNeeded)) + { + error("bad version found"); + return false; + } + unsigned int gpBitFlag; + if (!getInt(&gpBitFlag)) + { + error("bad bit flag found"); + return false; + } + unsigned int compressionMethod; + if (!getInt(&compressionMethod)) + { + error("bad compressionMethod found"); + return false; + } + unsigned int modTime; + if (!getInt(&modTime)) + { + error("bad modTime found"); + return false; + } + unsigned int modDate; + if (!getInt(&modDate)) + { + error("bad modDate found"); + return false; + } + unsigned long crc32; + if (!getLong(&crc32)) + { + error("bad crc32 found"); + return false; + } + unsigned long compressedSize; + if (!getLong(&compressedSize)) + { + error("bad compressedSize found"); + return false; + } + unsigned long uncompressedSize; + if (!getLong(&uncompressedSize)) + { + error("bad uncompressedSize found"); + return false; + } + unsigned int fileNameLength; + if (!getInt(&fileNameLength)) + { + error("bad fileNameLength found"); + return false; + } + unsigned int extraFieldLength; + if (!getInt(&extraFieldLength)) + { + error("bad extraFieldLength found"); + return false; + } + unsigned int fileCommentLength; + if (!getInt(&fileCommentLength)) + { + error("bad fileCommentLength found"); + return false; + } + unsigned int diskNumberStart; + if (!getInt(&diskNumberStart)) + { + error("bad diskNumberStart found"); + return false; + } + unsigned int internalFileAttributes; + if (!getInt(&internalFileAttributes)) + { + error("bad internalFileAttributes found"); + return false; + } + unsigned long externalFileAttributes; + if (!getLong(&externalFileAttributes)) + { + error("bad externalFileAttributes found"); + return false; + } + unsigned long localHeaderOffset; + if (!getLong(&localHeaderOffset)) + { + error("bad localHeaderOffset found"); + return false; + } + std::string fileName; + for (unsigned int i=0 ; i &inbuf) +{ + fileBuf = inbuf; + if (!read()) + return false; + return true; +} + + +/** + * + */ +bool ZipFile::readFile(const std::string &fileName) +{ + fileBuf.clear(); + FILE *f = fopen(fileName.c_str(), "rb"); + if (!f) + return false; + while (true) + { + int ch = fgetc(f); + if (ch < 0) + break; + fileBuf.push_back(ch); + } + fclose(f); + if (!read()) + return false; + return true; +} + + + + + + + + + +//######################################################################## +//# E N D O F F I L E +//######################################################################## + + diff --git a/src/dom/util/ziptool.h b/src/dom/util/ziptool.h new file mode 100644 index 000000000..dbae8ac60 --- /dev/null +++ b/src/dom/util/ziptool.h @@ -0,0 +1,567 @@ +#ifndef SEEN_ZIPTOOL_H +#define SEEN_ZIPTOOL_H +/** + * This is intended to be a standalone, reduced capability + * implementation of Gzip and Zip functionality. Its + * targeted use case is for archiving and retrieving single files + * which use these encoding types. Being memory based and + * non-optimized, it is not useful in cases where very large + * archives are needed or where high performance is desired. + * However, it should hopefully work well for smaller, + * one-at-a-time tasks. What you get in return is the ability + * to drop these files into your project and remove the dependencies + * on ZLib and Info-Zip. Enjoy. + */ +/* + * Authors: + * Bob Jamison + * + * Copyright (C) 2006-2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include + + +//######################################################################## +//# A D L E R 3 2 +//######################################################################## + +class Adler32 +{ +public: + + Adler32(); + + virtual ~Adler32(); + + void reset(); + + void update(unsigned char b); + + void update(char *str); + + unsigned long getValue(); + +private: + + unsigned long value; + +}; + + +//######################################################################## +//# C R C 3 2 +//######################################################################## + +class Crc32 +{ +public: + + Crc32(); + + virtual ~Crc32(); + + void reset(); + + void update(unsigned char b); + + void update(char *str); + + void update(const std::vector &buf); + + unsigned long getValue(); + +private: + + unsigned long value; + +}; + + + + + + +//######################################################################## +//# G Z I P S T R E A M S +//######################################################################## + +class GzipFile +{ +public: + + /** + * + */ + GzipFile(); + + /** + * + */ + virtual ~GzipFile(); + + /** + * + */ + virtual void put(unsigned char ch); + + /** + * + */ + virtual void setData(const std::vector &str); + + /** + * + */ + virtual void clearData(); + + /** + * + */ + virtual std::vector &getData(); + + /** + * + */ + virtual std::string &getFileName(); + + /** + * + */ + virtual void setFileName(const std::string &val); + + + //###################### + //# U T I L I T Y + //###################### + + /** + * + */ + virtual bool readFile(const std::string &fName); + + //###################### + //# W R I T E + //###################### + + /** + * + */ + virtual bool write(); + + /** + * + */ + virtual bool writeBuffer(std::vector &outbuf); + + /** + * + */ + virtual bool writeFile(const std::string &fileName); + + + //###################### + //# R E A D + //###################### + + + /** + * + */ + virtual bool read(); + + /** + * + */ + virtual bool readBuffer(const std::vector &inbuf); + + /** + * + */ + virtual bool loadFile(const std::string &fileName); + + + +private: + + std::vector data; + std::string fileName; + + //debug messages + void error(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + void trace(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + std::vector fileBuf; + unsigned long fileBufPos; + + bool getByte(unsigned char *ch); + bool getLong(unsigned long *val); + + bool putByte(unsigned char ch); + bool putLong(unsigned long val); + + int compressionMethod; +}; + + + + +//######################################################################## +//# Z I P F I L E +//######################################################################## + + +/** + * + */ +class ZipEntry +{ +public: + + /** + * + */ + ZipEntry(); + + /** + * + */ + ZipEntry(const std::string &fileName, + const std::string &comment); + + /** + * + */ + virtual ~ZipEntry(); + + /** + * + */ + virtual std::string getFileName(); + + /** + * + */ + virtual void setFileName(const std::string &val); + + /** + * + */ + virtual std::string getComment(); + + /** + * + */ + virtual void setComment(const std::string &val); + + /** + * + */ + virtual unsigned long getCompressedSize(); + + /** + * + */ + virtual int getCompressionMethod(); + + /** + * + */ + virtual void setCompressionMethod(int val); + + /** + * + */ + virtual std::vector &getCompressedData(); + + /** + * + */ + virtual void setCompressedData(const std::vector &val); + + /** + * + */ + virtual unsigned long getUncompressedSize(); + + /** + * + */ + virtual std::vector &getUncompressedData(); + + /** + * + */ + virtual void setUncompressedData(const std::vector &val); + + /** + * + */ + virtual void write(unsigned char ch); + + /** + * + */ + virtual void finish(); + + /** + * + */ + virtual unsigned long getCrc(); + + /** + * + */ + virtual void setCrc(unsigned long crc); + + /** + * + */ + virtual bool readFile(const std::string &fileNameArg, + const std::string &commentArg); + + /** + * + */ + virtual void setPosition(unsigned long val); + + /** + * + */ + virtual unsigned long getPosition(); + +private: + + unsigned long crc; + + std::string fileName; + std::string comment; + + int compressionMethod; + + std::vector compressedData; + std::vector uncompressedData; + + unsigned long position; +}; + + + + + + + + + +/** + * This class sits over the zlib and gzip code to + * implement a PKWare or Info-Zip .zip file reader and + * writer + */ +class ZipFile +{ +public: + + /** + * + */ + ZipFile(); + + /** + * + */ + virtual ~ZipFile(); + + //###################### + //# V A R I A B L E S + //###################### + + /** + * + */ + virtual void setComment(const std::string &val); + + /** + * + */ + virtual std::string getComment(); + + /** + * Return the list of entries currently in this file + */ + std::vector &getEntries(); + + + //###################### + //# U T I L I T Y + //###################### + + /** + * + */ + virtual ZipEntry *addFile(const std::string &fileNameArg, + const std::string &commentArg); + + /** + * + */ + virtual ZipEntry *newEntry(const std::string &fileNameArg, + const std::string &commentArg); + + //###################### + //# W R I T E + //###################### + + /** + * + */ + virtual bool write(); + + /** + * + */ + virtual bool writeBuffer(std::vector &outbuf); + + /** + * + */ + virtual bool writeFile(const std::string &fileName); + + + //###################### + //# R E A D + //###################### + + + /** + * + */ + virtual bool read(); + + /** + * + */ + virtual bool readBuffer(const std::vector &inbuf); + + /** + * + */ + virtual bool readFile(const std::string &fileName); + + +private: + + //debug messages + void error(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + void trace(char const *fmt, ...) + #ifdef G_GNUC_PRINTF + G_GNUC_PRINTF(2, 3) + #endif + ; + + //# Private writing methods + + /** + * + */ + bool putLong(unsigned long val); + + /** + * + */ + bool putInt(unsigned int val); + + + /** + * + */ + bool putByte(unsigned char val); + + /** + * + */ + bool writeFileData(); + + /** + * + */ + bool writeCentralDirectory(); + + + //# Private reading methods + + /** + * + */ + bool getLong(unsigned long *val); + + /** + * + */ + bool getInt(unsigned int *val); + + /** + * + */ + bool getByte(unsigned char *val); + + /** + * + */ + bool readFileData(); + + /** + * + */ + bool readCentralDirectory(); + + + std::vector entries; + + std::vector fileBuf; + unsigned long fileBufPos; + + std::string comment; +}; + + + + + + +#endif // SEEN_ZIPTOOL_H + + +//######################################################################## +//# E N D O F F I L E +//######################################################################## + -- cgit v1.2.3 From e330f37cfa5949bb505bb846a467f10c2c711d8f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 9 Feb 2013 10:30:08 +0100 Subject: Add function to add document font-family entries to store. Remove font-family to interator map as we can now have duplicate font-family names in store. (bzr r12111) --- src/libnrtype/font-lister.cpp | 149 +++++++++++++++++++++++++++++++++++++++++- src/libnrtype/font-lister.h | 40 +++++------- 2 files changed, 165 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 6df576866..9949be208 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -14,6 +14,11 @@ #include "font-lister.h" #include "FontFactory.h" +#include "sp-object.h" +#include "sp-root.h" +#include "document.h" +#include "xml/repr.h" + namespace Inkscape { FontLister::FontLister () @@ -53,11 +58,153 @@ namespace Inkscape (*treeModelIter)[FontList.styles] = styles; (*treeModelIter)[FontList.onSystem] = true; - font_list_store_iter_map.insert(std::make_pair(familyName, Gtk::TreePath(treeModelIter))); } } } + // Example of how to use "foreach_iter" + // bool + // FontLister::print_document_font( const Gtk::TreeModel::iterator &iter ) { + // Gtk::TreeModel::Row row = *iter; + // if( !row[FontList.onSystem] ) { + // std::cout << " Not on system: " << row[FontList.font] << std::endl; + // return false; + // } + // return true; + // } + // font_list_store->foreach_iter( sigc::mem_fun(*this, &FontLister::print_document_font )); + + void + FontLister::update_font_list( SPDocument* document ) { + + SPObject *r = document->getRoot(); + if( !r ) { + return; + } + + /* Clear all old document font-family entries */ + Gtk::TreeModel::iterator iter = font_list_store->get_iter( "0" ); + while( iter != font_list_store->children().end() ) { + Gtk::TreeModel::Row row = *iter; + if( !row[FontList.onSystem] ) { + // std::cout << " Not on system: " << row[FontList.font] << std::endl; + iter = font_list_store->erase( iter ); + } else { + // std::cout << " First on system: " << row[FontList.font] << std::endl; + break; + } + } + + /* Create default styles for use when font-family is unknown on system. */ + static GList *default_styles = NULL; + if( default_styles == NULL ) { + default_styles = g_list_append( default_styles, g_strdup("Normal") ); + default_styles = g_list_append( default_styles, g_strdup("Italic") ); + default_styles = g_list_append( default_styles, g_strdup("Bold") ); + default_styles = g_list_append( default_styles, g_strdup("Bold Italic") ); + default_styles = g_list_append( default_styles, g_strdup("Loopy") ); + } + + /* Get "font-family"s used in document. */ + std::list fontfamilies; + update_font_list_recursive( r, &fontfamilies ); + + fontfamilies.sort(); + fontfamilies.unique(); + fontfamilies.reverse(); + + /* Insert separator */ + if( !fontfamilies.empty() ) { + Gtk::TreeModel::iterator treeModelIter = font_list_store->prepend(); + (*treeModelIter)[FontList.font] = "separatoR"; + (*treeModelIter)[FontList.onSystem] = false; + } + + /* Insert font-family's in document. */ + std::list::iterator i; + for( i = fontfamilies.begin(); i != fontfamilies.end(); ++i) { + + GList *styles = default_styles; + + /* See if font-family (or first in fallback list) is on system. If so, get styles. */ + std::vector tokens = Glib::Regex::split_simple(",", *i ); + if( !tokens[0].empty() ) { + + Gtk::TreeModel::iterator iter2 = font_list_store->get_iter( "0" ); + while( iter2 != font_list_store->children().end() ) { + Gtk::TreeModel::Row row = *iter2; + if( row[FontList.onSystem] && tokens[0].compare( row[FontList.font] ) == 0 ) { + styles = row[FontList.styles]; + break; + } + ++iter2; + } + } + + Gtk::TreeModel::iterator treeModelIter = font_list_store->prepend(); + (*treeModelIter)[FontList.font] = reinterpret_cast(g_strdup((*i).c_str())); + (*treeModelIter)[FontList.styles] = styles; + (*treeModelIter)[FontList.onSystem] = false; + } + } + + void + FontLister::update_font_list_recursive( SPObject *r, std::list *l ) { + + const gchar *style = r->getRepr()->attribute("style"); + if( style != NULL ) { + + std::vector tokens = Glib::Regex::split_simple(";", style ); + for( size_t i=0; i < tokens.size(); ++i ) { + + Glib::ustring token = tokens[i]; + size_t found = token.find("font-family:"); + + if( found != Glib::ustring::npos ) { + + // Remove "font-family:" + token.erase(found,12); + + // Remove any leading single or double quote + if( token[0] == '\'' || token[0] == '"' ) { + token.erase(0,1); + } + + // Remove any trailing single or double quote + if( token[token.length()-1] == '\'' || token[token.length()-1] == '"' ) { + token.erase(token.length()-1); + } + + l->push_back( token ); + } + } + } + + for (SPObject *child = r->firstChild(); child; child = child->getNext()) { + update_font_list_recursive( child, l ); + } + } + + Gtk::TreePath + FontLister::get_row_for_font (Glib::ustring family) + { + Gtk::TreePath path; + + Gtk::TreeModel::iterator iter = font_list_store->get_iter( "0" ); + while( iter != font_list_store->children().end() ) { + + Gtk::TreeModel::Row row = *iter; + + if( family.compare( row[FontList.font] ) == 0 ) { + return font_list_store->get_path( iter ); + } + + ++iter; + } + + throw FAMILY_NOT_FOUND; + } + FontLister::~FontLister () { }; diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index 7a7db5615..d4c48dd52 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -7,9 +7,11 @@ * Authors: * Chris Lahey * Lauris Kaplinski + * Tavmjong Bah * * Copyright (C) 1999-2001 Ximian, Inc. * Copyright (C) 2002 Lauris Kaplinski + * Copyright (C) 2013 Tavmjong Bah * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,6 +23,9 @@ #include #include "nr-type-primitives.h" +class SPObject; +class SPDocument; + namespace Inkscape { /** @@ -66,22 +71,7 @@ namespace Inkscape } }; - /* Case-insensitive < compare for standard strings */ - class StringLessThan - { - public: - bool operator () (std::string str1, std::string str2) const - { - std::string s1=str1; // Can't transform the originals! - std::string s2=str2; - std::transform(s1.begin(), s1.end(), s1.begin(), (int(*)(int)) toupper); - std::transform(s2.begin(), s2.end(), s2.begin(), (int(*)(int)) toupper); - return s1 IterMapType; /** Returns the ListStore with the font names * @@ -92,6 +82,17 @@ namespace Inkscape const Glib::RefPtr get_font_list () const; + /** Updates font list to include fonts in document + * + */ + void + update_font_list ( SPDocument* document); + + private: + void + update_font_list_recursive( SPObject *r, std::list *l ); + + public: static Inkscape::FontLister* get_instance () { @@ -100,12 +101,7 @@ namespace Inkscape } Gtk::TreePath - get_row_for_font (Glib::ustring family) - { - IterMapType::iterator iter = font_list_store_iter_map.find (family); - if (iter == font_list_store_iter_map.end ()) throw FAMILY_NOT_FOUND; - return (*iter).second; - } + get_row_for_font (Glib::ustring family); const NRNameList get_name_list () const @@ -113,7 +109,6 @@ namespace Inkscape return families; } - private: FontLister (); @@ -121,7 +116,6 @@ namespace Inkscape NRNameList families; Glib::RefPtr font_list_store; - IterMapType font_list_store_iter_map; }; } -- cgit v1.2.3 From 83ae846627474ee5aad75c1f4816a3faa7240a47 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 9 Feb 2013 13:52:04 +0100 Subject: Use update_font_list() in font-lister.cpp. Remove equivalent code in text-toolbar.cpp. Change separator "tag" from "separatoR" to "#" in attempt to speed up start up. (bzr r12112) --- src/libnrtype/font-lister.cpp | 2 +- src/widgets/text-toolbar.cpp | 100 +++--------------------------------------- 2 files changed, 7 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 9949be208..1e51d8803 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -116,7 +116,7 @@ namespace Inkscape /* Insert separator */ if( !fontfamilies.empty() ) { Gtk::TreeModel::iterator treeModelIter = font_list_store->prepend(); - (*treeModelIter)[FontList.font] = "separatoR"; + (*treeModelIter)[FontList.font] = "#"; (*treeModelIter)[FontList.onSystem] = false; } diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index f19ee7cee..5ba2065b9 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -133,9 +133,6 @@ static void sp_print_fontstyle( SPStyle *query ) { } #endif -void sp_text_toolbox_get_font_list_in_doc (SPObject *r, std::list *l); -void sp_text_toolbox_update_font_list( GtkListStore* model ); - // Format family drop-down menu. static void cell_data_func(GtkCellLayout * /*cell_layout*/, GtkCellRenderer *cell, @@ -224,7 +221,7 @@ static gboolean separator_func(GtkTreeModel *model, { gchar* text = 0; gtk_tree_model_get(model, iter, 0, &text, -1 ); // Column 0 - return (text && strcmp(text,"separatoR") == 0); + return (text && strcmp(text,"#") == 0); } /* @@ -1250,7 +1247,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ Ink_ComboBoxEntry_Action* fontFamilyAction = INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); if( fontFamilyAction->combobox != NULL ) { - sp_text_toolbox_update_font_list( GTK_LIST_STORE(ink_comboboxentry_action_get_model(fontFamilyAction)) ); + Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); + fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP )); } @@ -1587,93 +1585,6 @@ sp_text_toolbox_get_font_list_in_doc_recursive (SPObject *r, std::list *l) { - - sp_text_toolbox_get_font_list_in_doc_recursive (r, l); - - l->sort(); - l->unique(); - l->reverse(); - - // for(std::list::iterator i = l->begin(); i != l->end(); ++i) { - // std::cout << " font_family in doc: " << *i << std::endl; - // } -} - -/* Update font-family list with "font-family" attributes used in a document. */ -void -sp_text_toolbox_update_font_list( GtkListStore* model ) { - - /* Create default styles for use when font-family is unknown on system. */ - static GList *default_styles = NULL; - if( default_styles == NULL ) { - default_styles = g_list_append( default_styles, g_strdup("Normal") ); - default_styles = g_list_append( default_styles, g_strdup("Italic") ); - default_styles = g_list_append( default_styles, g_strdup("Bold") ); - default_styles = g_list_append( default_styles, g_strdup("Bold Italic") ); - } - - /* Get "font-family" attributes used in document */ - std::list fontfamilies; - sp_text_toolbox_get_font_list_in_doc( (sp_desktop_document(SP_ACTIVE_DESKTOP))->getRoot(), &fontfamilies ); - - /* Delete all old doc font-family entries */ - GtkTreeIter iter; - gboolean valid; - for( valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter ); valid; ) { - gchar *family = 0; - gboolean onSystem = true; - gtk_tree_model_get( GTK_TREE_MODEL(model), &iter, 0, &family, 2, &onSystem, -1 ); - //std::cout << "List: " << family << ": " << (onSystem ? "Yes" : "No") << std::endl; - if( !onSystem ) { - valid = gtk_list_store_remove( model, &iter ); - } else { - valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ); - } - } - - /* Insert separator */ - if( !fontfamilies.empty() ) { - gtk_list_store_insert( model, &iter, 0 ); // iter points to new row - gtk_list_store_set( model, &iter, 0, "separatoR", -1 ); - } - - - /* Insert doc font-family entries, list is already reverse sorted with duplicates removed. */ - std::list::iterator i; - for(i=fontfamilies.begin(); i != fontfamilies.end(); ++i) { - - GList *styles = default_styles; - gtk_list_store_insert( model, &iter, 0 ); // iter points to new row - - /* See if font-family (or first in fallback list) is on system. If so, get styles. */ - std::vector tokens = Glib::Regex::split_simple(",", *i ); - if( !tokens[0].empty() ) { - - GtkTreeIter iter2; - gboolean valid2; - for( valid2 = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter2 ); - valid2; - valid2 = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter2 ) ) { - - gchar* family = 0; - gboolean onSystem = true; - gtk_tree_model_get( GTK_TREE_MODEL(model), &iter2, 0, &family, 2, &onSystem, -1 ); - if( onSystem && tokens[0].compare( family ) == 0 ) { - gtk_tree_model_get( GTK_TREE_MODEL(model), &iter2, 1, &styles, -1 ); - break; - } - } - - } - - gtk_list_store_set( model, &iter, 0, (*i).c_str(), 1, styles, 2, false, -1 ); - } -} // Define all the "widgets" in the toolbar. void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) @@ -1689,9 +1600,10 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje /* Font family */ { // Font list - Glib::RefPtr store = Inkscape::FontLister::get_instance()->get_font_list(); + Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); + fontlister->update_font_list( sp_desktop_document( SP_ACTIVE_DESKTOP )); + Glib::RefPtr store = fontlister->get_font_list(); GtkListStore* model = store->gobj(); - sp_text_toolbox_update_font_list( model ); Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction", -- cgit v1.2.3 From d950a5453a26c6d887e3fcd597da9a7818bab7f3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 10 Feb 2013 07:33:41 +0100 Subject: Attempt to speed up font-family handling be freezing/thawing Gtk::ListStore when modifying. (bzr r12113) --- src/libnrtype/font-lister.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 1e51d8803..647bbc056 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -24,7 +24,8 @@ namespace Inkscape FontLister::FontLister () { font_list_store = Gtk::ListStore::create (FontList); - + font_list_store->freeze_notify(); + FamilyToStylesMap familyStyleMap; font_factory::Default()->GetUIFamiliesAndStyles(&familyStyleMap); @@ -60,6 +61,7 @@ namespace Inkscape (*treeModelIter)[FontList.onSystem] = true; } } + font_list_store->thaw_notify(); } // Example of how to use "foreach_iter" @@ -82,6 +84,8 @@ namespace Inkscape return; } + font_list_store->freeze_notify(); + /* Clear all old document font-family entries */ Gtk::TreeModel::iterator iter = font_list_store->get_iter( "0" ); while( iter != font_list_store->children().end() ) { @@ -146,6 +150,8 @@ namespace Inkscape (*treeModelIter)[FontList.styles] = styles; (*treeModelIter)[FontList.onSystem] = false; } + + font_list_store->thaw_notify(); } void -- cgit v1.2.3 From 6fc40123cf5d5d73ed01d18547edf3c3c8114769 Mon Sep 17 00:00:00 2001 From: Raphael Rosch Date: Mon, 11 Feb 2013 03:42:50 -0400 Subject: adding dockbar/switcher style toggles in prefs ui Fixed bugs: - https://launchpad.net/bugs/1098416 (bzr r12115) --- src/ui/dialog/inkscape-preferences.cpp | 18 ++++++++++++++++++ src/ui/dialog/inkscape-preferences.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index d963e0c7f..57f815730 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -601,6 +601,24 @@ void InkscapePreferences::initPageUI() _page_ui.add_line(false, "", _show_filters_info_box, "", _("Show icons and descriptions for the filter primitives available at the filter effects dialog")); + { + Glib::ustring dockbarstyleLabels[] = {_("Icons only"), _("Text only"), _("Icons and text")}; + int dockbarstyleValues[] = {0, 1, 2}; + + /* dockbar style */ + _dockbar_style.init( "/options/dock/dockbarstyle", dockbarstyleLabels, dockbarstyleValues, G_N_ELEMENTS(dockbarstyleLabels), 0); + _page_ui.add_line(false, _("Dockbar style (requires restart):"), _dockbar_style, "", + _("Selects whether the vertical bars on the dockbar will show text labels, icons, or both"), false); + + Glib::ustring switcherstyleLabels[] = {_("Text only"), _("Icons only"), _("Icons and text")}; /* see bug #1098437 */ + int switcherstyleValues[] = {0, 1, 2}; + + /* switcher style */ + _switcher_style.init( "/options/dock/switcherstyle", switcherstyleLabels, switcherstyleValues, G_N_ELEMENTS(switcherstyleLabels), 0); + _page_ui.add_line(false, _("Switcher style (requires restart):"), _switcher_style, "", + _("Selects whether the dockbar switcher will show text labels, icons, or both"), false); + } + // Windows _win_save_geom.init ( _("Save and restore window geometry for each document"), "/options/savewindowgeometry/value", 1, true, 0); _win_save_geom_prefs.init ( _("Remember and use last window's geometry"), "/options/savewindowgeometry/value", 2, false, &_win_save_geom); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 690016556..b21ab0128 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -274,6 +274,8 @@ protected: UI::Widget::PrefRadioButton _filter_quality_worse; UI::Widget::PrefRadioButton _filter_quality_worst; UI::Widget::PrefCheckButton _show_filters_info_box; + UI::Widget::PrefCombo _dockbar_style; + UI::Widget::PrefCombo _switcher_style; UI::Widget::PrefSpinButton _rendering_cache_size; UI::Widget::PrefSpinButton _filter_multi_threaded; -- cgit v1.2.3 From cb07768f46fef63b0e0f48e3b12be97467d46a9c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 11 Feb 2013 16:35:47 +0100 Subject: Move cell_data_func and separator_func from text-toolbar to font-lister. Use functions with font-selector (in Text dialog). (bzr r12116) --- src/ink-comboboxentry-action.cpp | 4 +- src/libnrtype/font-lister.cpp | 73 +++++++++++++++++++++++++++++- src/libnrtype/font-lister.h | 15 +++++++ src/widgets/font-selector.cpp | 13 ++++++ src/widgets/text-toolbar.cpp | 95 +--------------------------------------- 5 files changed, 104 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp index 5adc3e73a..fd146926f 100644 --- a/src/ink-comboboxentry-action.cpp +++ b/src/ink-comboboxentry-action.cpp @@ -497,8 +497,8 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink // Show or hide warning -- this might be better moved to text-toolbox.cpp bool clear = true; - if( ink_comboboxentry_action->active == -1 && - ink_comboboxentry_action->warning != NULL ) { + + if( ink_comboboxentry_action->warning != NULL ) { Glib::ustring missing = check_comma_separated_text( ink_comboboxentry_action ); if( !missing.empty() ) { diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 647bbc056..04859185c 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -18,6 +18,7 @@ #include "sp-root.h" #include "document.h" #include "xml/repr.h" +#include "preferences.h" namespace Inkscape { @@ -106,7 +107,6 @@ namespace Inkscape default_styles = g_list_append( default_styles, g_strdup("Italic") ); default_styles = g_list_append( default_styles, g_strdup("Bold") ); default_styles = g_list_append( default_styles, g_strdup("Bold Italic") ); - default_styles = g_list_append( default_styles, g_strdup("Loopy") ); } /* Get "font-family"s used in document. */ @@ -222,6 +222,77 @@ namespace Inkscape } } +// Helper functions +void font_lister_cell_data_func(GtkCellLayout */*cell_layout*/, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer /*data*/) +{ + gchar *family; + gboolean onSystem = false; + gtk_tree_model_get(model, iter, 0, &family, 2, &onSystem, -1); + Glib::ustring family_escaped = g_markup_escape_text(family, -1); + //g_free(family); + Glib::ustring markup; + + if( !onSystem ) { + markup = ""; + + /* See if font-family on system */ + std::vector tokens = Glib::Regex::split_simple("\\s*,\\s*", family_escaped ); + for( size_t i=0; i < tokens.size(); ++i ) { + + Glib::ustring token = tokens[i]; + + GtkTreeIter iter; + gboolean valid; + gchar *family = 0; + gboolean onSystem = true; + gboolean found = false; + for( valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter ); + valid; + valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ) ) { + + gtk_tree_model_get(model, &iter, 0, &family, 2, &onSystem, -1); + if( onSystem && token.compare( family ) == 0 ) { + found = true; + break; + } + } + if( found ) { + markup += g_markup_escape_text(token.c_str(), -1); + markup += ", "; + } else { + markup += ""; + markup += g_markup_escape_text(token.c_str(), -1); + markup += ""; + markup += ", "; + } + } + // Remove extra comma and space from end. + if( markup.size() >= 2 ) { + markup.resize( markup.size()-2 ); + } + markup += ""; + // std::cout << markup << std::endl; + } else { + markup = family_escaped; + } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1); + if (show_sample) { + Glib::ustring sample = prefs->getString("/tools/text/font_sample"); + Glib::ustring sample_escaped = g_markup_escape_text(sample.data(), -1); + markup += " "; + markup += sample_escaped; + markup += ""; + } + + g_object_set (G_OBJECT (cell), "markup", markup.c_str(), NULL); +} diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h index d4c48dd52..751350407 100644 --- a/src/libnrtype/font-lister.h +++ b/src/libnrtype/font-lister.h @@ -120,6 +120,21 @@ namespace Inkscape }; } +// Helper functions +// Separator function (if true, a separator will be drawn) +static gboolean font_lister_separator_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer /*data*/) +{ + gchar* text = 0; + gtk_tree_model_get(model, iter, 0, &text, -1 ); // Column 0: FontList.font + return (text && strcmp(text,"#") == 0); +} + +void font_lister_cell_data_func(GtkCellLayout */*cell_layout*/, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer /*data*/); + #endif /* diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index b0b4b5504..013ad9e94 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -162,8 +162,21 @@ static void sp_font_selector_init(SPFontSelector *fsel) GtkCellRenderer *cell = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, cell, FALSE); gtk_tree_view_column_set_attributes (column, cell, "text", 0, NULL); + gtk_tree_view_column_set_cell_data_func (column, cell, + GtkTreeCellDataFunc (font_lister_cell_data_func), + NULL, NULL ); gtk_tree_view_append_column (GTK_TREE_VIEW(fsel->family_treeview), column); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(fsel->family_treeview), FALSE); + gtk_tree_view_set_row_separator_func( GTK_TREE_VIEW(fsel->family_treeview), + GtkTreeViewRowSeparatorFunc ((gpointer)font_lister_separator_func), + NULL, NULL ); + + /* Muck with style, see text-toolbar.cpp */ + gtk_widget_set_name( GTK_WIDGET(fsel->family_treeview), "font_selector_family" ); + gtk_rc_parse_string ( + "widget \"*font_selector_family\" style \"fontfamily-separator-style\""); + + Glib::RefPtr store = fontlister->get_font_list(); gtk_tree_view_set_model (GTK_TREE_VIEW(fsel->family_treeview), GTK_TREE_MODEL (Glib::unwrap (store))); gtk_container_add(GTK_CONTAINER(sw), fsel->family_treeview); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 5ba2065b9..a01f950a6 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -133,97 +133,6 @@ static void sp_print_fontstyle( SPStyle *query ) { } #endif -// Format family drop-down menu. -static void cell_data_func(GtkCellLayout * /*cell_layout*/, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer /*data*/) -{ - gchar *family; - gboolean onSystem = false; - gtk_tree_model_get(model, iter, 0, &family, 2, &onSystem, -1); - Glib::ustring family_escaped = g_markup_escape_text(family, -1); - g_free(family); - Glib::ustring markup; - - if( !onSystem ) { - markup = ""; - - /* See if font-family on system */ - std::vector tokens = Glib::Regex::split_simple("\\s*,\\s*", family_escaped ); - for( size_t i=0; i < tokens.size(); ++i ) { - - Glib::ustring token = tokens[i]; - - GtkTreeIter iter; - gboolean valid; - gchar *family = 0; - gboolean onSystem = true; - gboolean found = false; - for( valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(model), &iter ); - valid; - valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ) ) { - - gtk_tree_model_get(model, &iter, 0, &family, 2, &onSystem, -1); - if( onSystem && token.compare( family ) == 0 ) { - found = true; - break; - } - } - if( found ) { - markup += g_markup_escape_text(token.c_str(), -1); - markup += ", "; - } else { - markup += ""; - markup += g_markup_escape_text(token.c_str(), -1); - markup += ""; - markup += ", "; - } - } - // Remove extra comma and space from end. - if( markup.size() >= 2 ) { - markup.resize( markup.size()-2 ); - } - markup += ""; - // std::cout << markup << std::endl; - } else { - markup = family_escaped; - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1); - if (show_sample) { - - Glib::ustring sample = prefs->getString("/tools/text/font_sample"); - Glib::ustring sample_escaped = g_markup_escape_text(sample.data(), -1); - - markup += " "; - markup += sample_escaped; - markup += ""; - } - - g_object_set (G_OBJECT (cell), "markup", markup.c_str(), NULL); - - // This doesn't work for two reasons... it set both selected and not selected backgrounds - // to white.. which means that white foreground text is invisible. It also only effects - // the text region, leaving the padding untouched. - // g_object_set (G_OBJECT (cell), "cell-background", "white", "cell-background-set", true, NULL); - -} - -// Separator function (if true, a separator will be drawn) -static gboolean separator_func(GtkTreeModel *model, - GtkTreeIter *iter, - gpointer /*data*/) -{ - gchar* text = 0; - gtk_tree_model_get(model, iter, 0, &text, -1 ); // Column 0 - return (text && strcmp(text,"#") == 0); -} - /* * Fill the font style combobox with the available font styles for the selected font family * Set the selected style to that in font @@ -1613,8 +1522,8 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje GTK_TREE_MODEL(model), -1, // Entry width 50, // Extra list width - (gpointer)cell_data_func, // Cell layout - (gpointer)separator_func, + (gpointer)font_lister_cell_data_func, // Cell layout + (gpointer)font_lister_separator_func, GTK_WIDGET(desktop->canvas)); // Focus widget ink_comboboxentry_action_popup_enable( act ); // Enable entry completion gchar *const warning = _("Font not found on system"); -- cgit v1.2.3 From e8377a78c88424dd76f8fc47c61f436efd5470e7 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 11 Feb 2013 18:57:49 +0100 Subject: cppcheck (bzr r12117) --- src/dom/xpathparser.cpp | 2 +- src/dom/xpathtoken.cpp | 20 +++++++------------- src/dom/xpathtoken.h | 6 +----- src/extension/internal/filter/bumps.h | 3 --- src/extension/internal/image-resolution.cpp | 8 +------- src/extension/internal/pdfinput/svg-builder.cpp | 4 ++-- 6 files changed, 12 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/dom/xpathparser.cpp b/src/dom/xpathparser.cpp index 393c12cda..b19975966 100644 --- a/src/dom/xpathparser.cpp +++ b/src/dom/xpathparser.cpp @@ -131,7 +131,7 @@ void XPathParser::lexicalTokenDump() printf("####### LEXICAL TOKENS #######\n"); for (unsigned int i=0 ; igetType() == 2 ) { // Shading pattern GfxShadingPattern *shading_pattern = static_cast(pattern); double *ptm; - double ittm[6]; // invert ttm double m[6] = {1, 0, 0, 1, 0, 0}; double det; @@ -638,6 +637,7 @@ gchar *SvgBuilder::_createPattern(GfxPattern *pattern, GfxState *state, bool is_ ptm = shading_pattern->getMatrix(); det = ttm[0] * ttm[3] - ttm[1] * ttm[2]; if (det) { + double ittm[6]; // invert ttm ittm[0] = ttm[3] / det; ittm[1] = -ttm[1] / det; ittm[2] = -ttm[2] / det; @@ -1208,7 +1208,7 @@ void SvgBuilder::updateTextMatrix(GfxState *state) { */ void SvgBuilder::_flushText() { // Ignore empty strings - if ( _glyphs.size() < 1 ) { + if ( _glyphs.empty()) { _glyphs.clear(); return; } -- cgit v1.2.3 From 5723519be38287501aa4dd273a7ff907128b3407 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 11 Feb 2013 19:32:33 +0100 Subject: Dropped duplicate code for dom/io and io/ (Bug #1120585 ) (bzr r12118) --- src/dom/CMakeLists.txt | 4 - src/dom/Makefile_insert | 6 - src/dom/io/base64stream.cpp | 341 -------------------------------------------- src/dom/io/base64stream.h | 148 ------------------- src/dom/io/gzipstream.cpp | 245 ------------------------------- src/dom/io/gzipstream.h | 126 ---------------- src/io/base64stream.cpp | 23 ++- src/io/gzipstream.cpp | 17 ++- 8 files changed, 35 insertions(+), 875 deletions(-) delete mode 100644 src/dom/io/base64stream.cpp delete mode 100644 src/dom/io/base64stream.h delete mode 100644 src/dom/io/gzipstream.cpp delete mode 100644 src/dom/io/gzipstream.h (limited to 'src') diff --git a/src/dom/CMakeLists.txt b/src/dom/CMakeLists.txt index 15b4ba74d..5d761e649 100644 --- a/src/dom/CMakeLists.txt +++ b/src/dom/CMakeLists.txt @@ -19,10 +19,8 @@ set(dom_SRC xpathparser.cpp xpathtoken.cpp - io/base64stream.cpp io/bufferstream.cpp io/domstream.cpp - io/gzipstream.cpp io/stringstream.cpp io/uristream.cpp @@ -61,10 +59,8 @@ set(dom_SRC xpathparser.h xpathtoken.h - io/base64stream.h io/bufferstream.h io/domstream.h - io/gzipstream.h io/stringstream.h io/uristream.h diff --git a/src/dom/Makefile_insert b/src/dom/Makefile_insert index 17bab94ac..91c91eeac 100644 --- a/src/dom/Makefile_insert +++ b/src/dom/Makefile_insert @@ -50,16 +50,10 @@ dom_libdom_a_SOURCES = \ dom/xpathparser.h \ dom/xpathtoken.h \ dom/xpathtoken.cpp \ - dom/io/base64stream.cpp \ - dom/io/base64stream.h \ dom/io/bufferstream.cpp \ dom/io/bufferstream.h \ dom/io/domstream.cpp \ dom/io/domstream.h \ - dom/io/gzipstream.cpp \ - dom/io/gzipstream.h \ - dom/io/gzipstream.cpp \ - dom/io/gzipstream.h \ dom/io/stringstream.cpp \ dom/io/stringstream.h \ dom/io/uristream.cpp \ diff --git a/src/dom/io/base64stream.cpp b/src/dom/io/base64stream.cpp deleted file mode 100644 index 433675e18..000000000 --- a/src/dom/io/base64stream.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Phoebe DOM Implementation. - * - * Base64-enabled input and output streams - * - * This class allows easy encoding and decoding - * of Base64 data with a stream interface, hiding - * the implementation from the user. - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "base64stream.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - -//######################################################################### -//# B A S E 6 4 I N P U T S T R E A M -//######################################################################### - -static int base64decode[] = -{ -/*00*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*08*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*10*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*18*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*20*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*28*/ -1, -1, -1, 62, -1, -1, -1, 63, -/*30*/ 52, 53, 54, 55, 56, 57, 58, 59, -/*38*/ 60, 61, -1, -1, -1, -1, -1, -1, -/*40*/ -1, 0, 1, 2, 3, 4, 5, 6, -/*48*/ 7, 8, 9, 10, 11, 12, 13, 14, -/*50*/ 15, 16, 17, 18, 19, 20, 21, 22, -/*58*/ 23, 24, 25, -1, -1, -1, -1, -1, -/*60*/ -1, 26, 27, 28, 29, 30, 31, 32, -/*68*/ 33, 34, 35, 36, 37, 38, 39, 40, -/*70*/ 41, 42, 43, 44, 45, 46, 47, 48, -/*78*/ 49, 50, 51, -1, -1, -1, -1, -1 -}; - - -/** - * - */ -Base64InputStream::Base64InputStream(InputStream &sourceStream) - : BasicInputStream(sourceStream) -{ - outCount = 0; - padCount = 0; - closed = false; - done = false; -} - -/** - * - */ -Base64InputStream::~Base64InputStream() -{ - close(); -} - -/** - * Returns the number of bytes that can be read (or skipped over) from - * this input stream without blocking by the next caller of a method for - * this input stream. - */ -int Base64InputStream::available() -{ - if (closed ) - return 0; - int len = source.available() * 2 / 3; - return len; -} - - -/** - * Closes this input stream and releases any system resources - * associated with the stream. - */ -void Base64InputStream::close() -{ - if (closed) - return; - source.close(); - closed = true; -} - -/** - * Reads the next byte of data from the input stream. -1 if EOF - */ -int Base64InputStream::get() -{ - if (closed) - return -1; - - if (outCount - padCount > 0) - { - return outBytes[3-(outCount--)]; - } - - if (done) - return -1; - - int inBytes[4]; - int inCount = 0; - while (inCount < 4) - { - int ch = source.get(); - if (ch < 0) - { - while (inCount < 4) //pad if needed - { - inBytes[inCount++] = 0; - padCount++; - } - done = true; - break; - } - if (isspace(ch)) //ascii whitespace - { - //nothing - } - else if (ch == '=') //padding - { - inBytes[inCount++] = 0; - padCount++; - } - else - { - int byteVal = base64decode[ch & 0x7f]; - //printf("char:%c %d\n", ch, byteVal); - if (byteVal < 0) - { - //Bad lookup value - } - inBytes[inCount++] = byteVal; - } - } - - outBytes[0] = ((inBytes[0]<<2) & 0xfc) | ((inBytes[1]>>4) & 0x03); - outBytes[1] = ((inBytes[1]<<4) & 0xf0) | ((inBytes[2]>>2) & 0x0f); - outBytes[2] = ((inBytes[2]<<6) & 0xc0) | ((inBytes[3] ) & 0x3f); - - outCount = 3; - - //try again - if (outCount - padCount > 0) - { - return outBytes[3-(outCount--)]; - } - - return -1; - -} - - -//######################################################################### -//# B A S E 6 4 O U T P U T S T R E A M -//######################################################################### - -static char const *base64encode = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -/** - * - */ -Base64OutputStream::Base64OutputStream(OutputStream &destinationStream) - : BasicOutputStream(destinationStream) -{ - column = 0; - columnWidth = 72; - outBuf = 0L; - bitCount = 0; -} - -/** - * - */ -Base64OutputStream::~Base64OutputStream() -{ - close(); -} - -/** - * Closes this output stream and releases any system resources - * associated with this stream. - */ -void Base64OutputStream::close() -{ - if (closed) - return; - - //get any last bytes (1 or 2) out of the buffer - if (bitCount == 16) - { - outBuf <<= 2; //pad to make 18 bits - - int indx = (int)((outBuf & 0x0003f000L) >> 12); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x00000fc0L) >> 6); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - putCh('='); - } - else if (bitCount == 8) - { - outBuf <<= 4; //pad to make 12 bits - - int indx = (int)((outBuf & 0x00000fc0L) >> 6); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - putCh('='); - putCh('='); - } - - if (columnWidth > 0) //if <=0, no newlines - destination.put('\n'); - - destination.close(); - closed = true; -} - -/** - * Flushes this output stream and forces any buffered output - * bytes to be written out. - */ -void Base64OutputStream::flush() -{ - if (closed) - return; - //dont flush here. do it on close() - destination.flush(); -} - -/** - * Private. Put a char to the output stream, checking for line length - */ -void Base64OutputStream::putCh(int ch) -{ - destination.put(ch); - column++; - if (columnWidth > 0 && column >= columnWidth) - { - destination.put('\n'); - column = 0; - } -} - - -/** - * Writes the specified byte to this output stream. - */ -int Base64OutputStream::put(XMLCh ch) -{ - if (closed) - { - //probably throw an exception here - return -1; - } - - outBuf <<= 8; - outBuf |= (ch & 0xff); - bitCount += 8; - if (bitCount >= 24) - { - int indx = (int)((outBuf & 0x00fc0000L) >> 18); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0003f000L) >> 12); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x00000fc0L) >> 6); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - bitCount = 0; - outBuf = 0L; - } - - return 1; -} - - - -} //namespace io -} //namespace dom -} //namespace w3c -} //namespace org - - -//######################################################################### -//# E N D O F F I L E -//######################################################################### diff --git a/src/dom/io/base64stream.h b/src/dom/io/base64stream.h deleted file mode 100644 index 93bb5c7e5..000000000 --- a/src/dom/io/base64stream.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef SEEN_DOM_IO_BASE64STREAM_H -#define SEEN_DOM_IO_BASE64STREAM_H - -/** - * @file - * Phoebe DOM Implementation. - * - * Base64-enabled input and output streams - * - * This class allows easy encoding and decoding - * of Base64 data with a stream interface, hiding - * the implementation from the user. - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "domstream.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - - -//######################################################################### -//# B A S E 6 4 I N P U T S T R E A M -//######################################################################### - -/** - * This class is for decoding a Base-64 encoded InputStream source - * - */ -class Base64InputStream : public BasicInputStream -{ - -public: - - Base64InputStream(InputStream &sourceStream); - - virtual ~Base64InputStream(); - - virtual int available(); - - virtual void close(); - - virtual int get(); - -private: - - int outBytes[3]; - - int outCount; - - int padCount; - - bool done; - -}; // class Base64InputStream - - - - -//######################################################################### -//# B A S E 6 4 O U T P U T S T R E A M -//######################################################################### - -/** - * This class is for Base-64 encoding data going to the - * destination OutputStream - * - */ -class Base64OutputStream : public BasicOutputStream -{ - -public: - - Base64OutputStream(OutputStream &destinationStream); - - virtual ~Base64OutputStream(); - - virtual void close(); - - virtual void flush(); - - virtual int put(XMLCh ch); - - /** - * Sets the maximum line length for base64 output. If - * set to <=0, then there will be no line breaks; - */ - virtual void setColumnWidth(int val) - { columnWidth = val; } - -private: - - void putCh(int ch); - - int column; - - int columnWidth; - - unsigned long outBuf; - - int bitCount; - -}; // class Base64OutputStream - - - - - - - -} //namespace io -} //namespace dom -} //namespace w3c -} //namespace org - - -#endif // SEEN_DOM_IO_BASE64STREAM_H diff --git a/src/dom/io/gzipstream.cpp b/src/dom/io/gzipstream.cpp deleted file mode 100644 index 2a2f8a5b5..000000000 --- a/src/dom/io/gzipstream.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Zlib-enabled input and output streams - * - * This is a thin wrapper of libz calls, in order - * to provide a simple interface to our developers - * for gzip input and output. - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "gzipstream.h" - -#include "dom/util/ziptool.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - -//######################################################################### -//# G Z I P I N P U T S T R E A M -//######################################################################### - -/** - * - */ -GzipInputStream::GzipInputStream(InputStream &sourceStream) - : BasicInputStream(sourceStream) -{ - loaded = false; - bufPos = 0; -} - -/** - * - */ -GzipInputStream::~GzipInputStream() -{ - close(); -} - -/** - * Returns the number of bytes that can be read (or skipped over) from - * this input stream without blocking by the next caller of a method for - * this input stream. - */ -int GzipInputStream::available() -{ - if (closed) - return 0; - if (!loaded) - if (!load()) - return 0; - return (int) buffer.size(); -} - - -/** - * Closes this input stream and releases any system resources - * associated with the stream. - */ -void GzipInputStream::close() -{ - if (closed) - return; - - closed = true; -} - -/** - * Reads the next byte of data from the input stream. -1 if EOF - */ -int GzipInputStream::get() -{ - if (closed) - return -1; - - if (!loaded) - if (!load()) - return -1; - - if (bufPos >= buffer.size()) - return -1; - int ch = (int) buffer[bufPos++]; - - return ch; -} - -/** - * Processes input. Fills read buffer. - */ -bool GzipInputStream::load() -{ - if (closed) - return false; - - if (loaded) - return true; - - std::vector compBuf; - while (true) - { - int ch = source.get(); - if (ch < 0) - break; - compBuf.push_back(ch); - } - GzipFile gz; - if (!gz.readBuffer(compBuf)) - { - return -1; - } - buffer = gz.getData(); - bufPos = 0; - loaded = true; - return true; -} - - - - - - -//######################################################################### -//# G Z I P O U T P U T S T R E A M -//######################################################################### - -/** - * - */ -GzipOutputStream::GzipOutputStream(OutputStream &destinationStream) - : BasicOutputStream(destinationStream) -{ - - closed = false; -} - -/** - * - */ -GzipOutputStream::~GzipOutputStream() -{ - close(); -} - -/** - * Closes this output stream and releases any system resources - * associated with this stream. - */ -void GzipOutputStream::close() -{ - if (closed) - return; - - flush(); - - closed = true; -} - -/** - * Flushes this output stream and forces any buffered output - * bytes to be written out. - */ -void GzipOutputStream::flush() -{ - if (closed || buffer.empty()) - return; - - std::vector compBuf; - GzipFile gz; - - gz.writeBuffer(buffer); - - std::vector::iterator iter; - for (iter=compBuf.begin() ; iter!=compBuf.end() ; ++iter) - { - int ch = (int) *iter; - destination.put(ch); - } - - buffer.clear(); - - //printf("done\n"); - -} - - - -/** - * Writes the specified byte to this output stream. - */ -int GzipOutputStream::put(XMLCh ch) -{ - if (closed) - { - //probably throw an exception here - return -1; - } - - //Add char to buffer - buffer.push_back(ch); - return 1; -} - - - -} // namespace io -} // namespace dom -} // namespace w3c -} // namespace org - - - - -//######################################################################### -//# E N D O F F I L E -//######################################################################### - - - diff --git a/src/dom/io/gzipstream.h b/src/dom/io/gzipstream.h deleted file mode 100644 index 6e82c3531..000000000 --- a/src/dom/io/gzipstream.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef SEEN_GZIPSTREAM_H -#define SEEN_GZIPSTREAM_H -/** - * Zlib-enabled input and output streams - * - * This provides a simple mechanism for reading and - * writing Gzip files. We use our own 'ZipTool' class - * to accomplish this, avoiding a zlib dependency. - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - - -#include "domstream.h" - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - -//######################################################################### -//# G Z I P I N P U T S T R E A M -//######################################################################### - -/** - * This class is for deflating a gzip-compressed InputStream source - * - */ -class GzipInputStream : public BasicInputStream -{ - -public: - - GzipInputStream(InputStream &sourceStream); - - virtual ~GzipInputStream(); - - virtual int available(); - - virtual void close(); - - virtual int get(); - -private: - - bool load(); - - bool loaded; - - std::vector buffer; - unsigned int bufPos; - - -}; // class GzipInputStream - - - - -//######################################################################### -//# G Z I P O U T P U T S T R E A M -//######################################################################### - -/** - * This class is for gzip-compressing data going to the - * destination OutputStream - * - */ -class GzipOutputStream : public BasicOutputStream -{ - -public: - - GzipOutputStream(OutputStream &destinationStream); - - virtual ~GzipOutputStream(); - - virtual void close(); - - virtual void flush(); - - virtual int put(XMLCh ch); - -private: - - std::vector buffer; - - -}; // class GzipOutputStream - - - - - - - -} // namespace io -} // namespace dom -} // namespace w3c -} // namespace org - - -#endif // SEEN_GZIPSTREAM_H diff --git a/src/io/base64stream.cpp b/src/io/base64stream.cpp index 0a28a8cc3..667487c35 100644 --- a/src/io/base64stream.cpp +++ b/src/io/base64stream.cpp @@ -5,18 +5,35 @@ * of Base64 data with a stream interface, hiding * the implementation from the user. * + * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html + * * Authors: - * Bob Jamison + + * Bob Jamison + * + * Copyright (C) 2006 Bob Jamison * - * Copyright (C) 2004 Inkscape.org + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * Released under GNU GPL, read the file 'COPYING' for more information + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "base64stream.h" + namespace Inkscape { namespace IO diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index cbe29a41e..91b51140b 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -8,9 +8,22 @@ * Authors: * Bob Jamison * - * Copyright (C) 2004 Inkscape.org + * Copyright (C) 2004 * - * Released under GNU GPL, read the file 'COPYING' for more information + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "gzipstream.h" -- cgit v1.2.3 From c8a761256b40300761c7ff6a0d642ac75b6f541a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 11 Feb 2013 23:34:59 +0000 Subject: A couple of forward declarations (bzr r12119) --- src/desktop-style.cpp | 1 + src/extension/dependency.cpp | 2 ++ src/extension/extension.h | 1 + src/extension/internal/filter/filter-file.cpp | 1 + src/extension/internal/javafx-out.cpp | 2 ++ src/extension/timer.cpp | 2 +- src/file.cpp | 1 + src/gradient-drag.cpp | 1 + src/io/gzipstream.cpp | 1 + src/io/gzipstream.h | 2 +- src/io/inkscapestream.cpp | 2 +- src/io/inkscapestream.h | 3 +-- src/io/sys.cpp | 1 + src/preferences.cpp | 1 + src/sp-filter.cpp | 1 + src/sp-font-face.h | 2 ++ src/text-editing.cpp | 1 + src/ui/widget/style-swatch.cpp | 1 + src/xml/repr-css.cpp | 1 + src/xml/repr.h | 19 +++++++++++++------ 20 files changed, 35 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 410e71730..2ea3c876b 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -39,6 +39,7 @@ #include "sp-tref.h" #include "sp-tspan.h" #include "xml/repr.h" +#include "xml/sp-css-attr.h" #include "libnrtype/font-style-to-pos.h" #include "sp-path.h" #include "event-context.h" diff --git a/src/extension/dependency.cpp b/src/extension/dependency.cpp index f53dc93b4..7c358d871 100644 --- a/src/extension/dependency.cpp +++ b/src/extension/dependency.cpp @@ -13,6 +13,8 @@ #endif #include +#include +#include #include "config.h" #include "path-prefix.h" #include "dependency.h" diff --git a/src/extension/extension.h b/src/extension/extension.h index e0b643b6d..78999631a 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -19,6 +19,7 @@ #include #include #include "xml/repr.h" +#include namespace Gtk { class Table; diff --git a/src/extension/internal/filter/filter-file.cpp b/src/extension/internal/filter/filter-file.cpp index d129f590c..d569c6438 100644 --- a/src/extension/internal/filter/filter-file.cpp +++ b/src/extension/internal/filter/filter-file.cpp @@ -20,6 +20,7 @@ /* System includes */ #include +#include namespace Inkscape { namespace Extension { diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp index 67c0fae66..035a6f0aa 100644 --- a/src/extension/internal/javafx-out.cpp +++ b/src/extension/internal/javafx-out.cpp @@ -20,6 +20,8 @@ #ifdef HAVE_CONFIG_H # include #endif + +#include #include "javafx-out.h" #include #include diff --git a/src/extension/timer.cpp b/src/extension/timer.cpp index 3941ddcfc..e4e8632d2 100644 --- a/src/extension/timer.cpp +++ b/src/extension/timer.cpp @@ -10,7 +10,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "extension.h" #include "timer.h" diff --git a/src/file.cpp b/src/file.cpp index 14f70fc8c..468d02eba 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -62,6 +62,7 @@ #include "ui/view/view-widget.h" #include "uri.h" #include "xml/rebase-hrefs.h" +#include "xml/sp-css-attr.h" #include "verbs.h" #include "event-log.h" #include "ui/dialog/font-substitution.h" diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 904c3b349..65b26937b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -34,6 +34,7 @@ #include "display/sp-ctrlcurve.h" #include "display/sp-canvas-util.h" #include "xml/repr.h" +#include "xml/sp-css-attr.h" #include "svg/css-ostringstream.h" #include "svg/svg.h" #include "preferences.h" diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index 91b51140b..f9e30de91 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -28,6 +28,7 @@ #include "gzipstream.h" #include +#include #include #include diff --git a/src/io/gzipstream.h b/src/io/gzipstream.h index 4debbfca9..89c5f64f3 100644 --- a/src/io/gzipstream.h +++ b/src/io/gzipstream.h @@ -17,7 +17,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "inkscapestream.h" #include diff --git a/src/io/inkscapestream.cpp b/src/io/inkscapestream.cpp index da7870add..65f24cf59 100644 --- a/src/io/inkscapestream.cpp +++ b/src/io/inkscapestream.cpp @@ -11,7 +11,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "inkscapestream.h" namespace Inkscape diff --git a/src/io/inkscapestream.h b/src/io/inkscapestream.h index a766e16e0..37c41552f 100644 --- a/src/io/inkscapestream.h +++ b/src/io/inkscapestream.h @@ -9,9 +9,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - #include -#include +#include namespace Inkscape { diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 26c1993a7..60e850c96 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -15,6 +15,7 @@ # include "config.h" #endif +#include #include #include #include diff --git a/src/preferences.cpp b/src/preferences.cpp index 3f12c4f64..1d7009a99 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index e3a44d8bb..bce86c465 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -22,6 +22,7 @@ using std::map; using std::pair; +#include #include "attributes.h" #include "document.h" #include "sp-filter.h" diff --git a/src/sp-font-face.h b/src/sp-font-face.h index 691c1f883..57702b683 100644 --- a/src/sp-font-face.h +++ b/src/sp-font-face.h @@ -6,6 +6,8 @@ #ifndef __SP_FONTFACE_H__ #define __SP_FONTFACE_H__ +#include + /* * SVG element implementation * diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 44b323989..47b4d35ac 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -29,6 +29,7 @@ #include "document.h" #include "xml/repr.h" #include "xml/attribute-record.h" +#include "xml/sp-css-attr.h" #include "sp-textpath.h" #include "sp-flowtext.h" diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 60d5f6ecc..44bceb826 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -28,6 +28,7 @@ #include "sp-radial-gradient-fns.h" #include "sp-pattern.h" #include "xml/repr.h" +#include "xml/sp-css-attr.h" #include "widgets/widget-sizes.h" #include "helper/units.h" #include "helper/action.h" diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 4c339ad5a..24e2db9e1 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -27,6 +27,7 @@ #include "xml/repr.h" #include "xml/simple-document.h" #include "xml/simple-node.h" +#include "xml/sp-css-attr.h" #include "style.h" #include "libcroco/cr-sel-eng.h" diff --git a/src/xml/repr.h b/src/xml/repr.h index debd0f489..52f07d11f 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -14,16 +14,11 @@ #ifndef SEEN_SP_REPR_H #define SEEN_SP_REPR_H -#include #include -#include "gc-anchored.h" +#include #include "xml/node.h" #include "xml/document.h" -#include "xml/sp-css-attr.h" -#include "io/inkscapestream.h" - -#include <2geom/forward.h> #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" @@ -35,6 +30,18 @@ #define SP_OLD_CC_NS_URI "http://web.resource.org/cc/" #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/" +class SPCSSAttr; + +namespace Inkscape { +namespace IO { +class Writer; +} // namespace IO +} // namespace Inkscape + +namespace Geom { +class Point; +} + /* SPXMLNs */ char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested); char const *sp_xml_ns_prefix_uri(gchar const *prefix); -- cgit v1.2.3 From d9386b2f8af03b8dc5a512008750f50aabce14e9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 13 Feb 2013 13:03:17 +0100 Subject: Build. Adding unistd header (fixes compilation on Win32 with OpenSuse cross-compiled libs.) (bzr r12122) --- src/extension/system.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 7fb6e1591..60cd21d71 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -21,6 +21,7 @@ #endif #include +#include #include "system.h" #include "preferences.h" -- cgit v1.2.3