diff options
| author | Martin Owens <doctormo@gmail.com> | 2013-04-21 04:20:25 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2013-04-21 04:20:25 +0000 |
| commit | bbe7c2c6760dc21615800ea0ce89c0c58608fc20 (patch) | |
| tree | 053779804cdcd82bd4277209f6bb61c8e07579f9 /src | |
| parent | Warn if we get a NULL object (diff) | |
| download | inkscape-bbe7c2c6760dc21615800ea0ce89c0c58608fc20.tar.gz inkscape-bbe7c2c6760dc21615800ea0ce89c0c58608fc20.zip | |
Clean up symbol pixmap generator and title description
(bzr r12291)
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-use.cpp | 7 | ||||
| -rw-r--r-- | src/ui/dialog/symbols.cpp | 58 | ||||
| -rw-r--r-- | src/ui/dialog/symbols.h | 5 |
3 files changed, 29 insertions, 41 deletions
diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 6fd7c6970..2220b4b47 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -299,10 +299,9 @@ sp_use_description(SPItem *item) if (use->child) { if( SP_IS_SYMBOL( use->child ) ) { - //char *symbol_desc = SP_ITEM(use->child)->description(); - //g_free(symbol_desc); - return g_strdup(_("<b>Clone of Symbol</b>")); - //return g_strdup_printf(_("<b>Clone of Symbol</b>: %s"), symbol_desc ); + char *symbol_desc = SP_ITEM(use->child)->title(); + return g_strdup_printf(_("<b>'%s' Symbol</b>"), symbol_desc ); + g_free(symbol_desc); } static unsigned recursion_depth = 0; diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 46dbcaae6..57e2e7285 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -557,32 +557,32 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen void SymbolsDialog::draw_symbols( SPDocument* symbolDocument ) { - - SymbolColumns* columns = getColumns(); - GSList* l = symbols_in_doc( symbolDocument ); for( ; l != NULL; l = l->next ) { - SPObject* symbol = SP_OBJECT(l->data); - if (!SP_IS_SYMBOL(symbol)) { - //std::cout << " Error: not symbol" << std::endl; - continue; + if (SP_IS_SYMBOL(symbol)) { + draw_symbol( symbol ); } + } +} - gchar const *id = symbol->getRepr()->attribute("id"); - gchar const *title = symbol->title(); // From title element - if( !title ) { - title = id; - } +void SymbolsDialog::draw_symbol( SPObject* symbol ) { - Glib::RefPtr<Gdk::Pixbuf> pixbuf = create_symbol_image(id, symbolDocument, &renderDrawing, key ); - if( pixbuf ) { + SymbolColumns* columns = getColumns(); - Gtk::ListStore::iterator row = store->append(); - (*row)[columns->symbol_id] = Glib::ustring( id ); - (*row)[columns->symbol_title] = Glib::ustring( title ); - (*row)[columns->symbol_image] = pixbuf; - } + gchar const *id = symbol->getRepr()->attribute("id"); + gchar const *title = symbol->title(); // From title element + if( !title ) { + title = id; + } + + Glib::RefPtr<Gdk::Pixbuf> pixbuf = create_symbol_image(id, symbol ); + + if( pixbuf ) { + Gtk::ListStore::iterator row = store->append(); + (*row)[columns->symbol_id] = Glib::ustring( id ); + (*row)[columns->symbol_title] = Glib::ustring( title ); + (*row)[columns->symbol_image] = pixbuf; } delete columns; @@ -598,18 +598,8 @@ void SymbolsDialog::draw_symbols( SPDocument* symbolDocument ) { * the temporary document is rendered. */ Glib::RefPtr<Gdk::Pixbuf> -SymbolsDialog::create_symbol_image(gchar const *symbol_id, - SPDocument *source, - Inkscape::Drawing* drawing, - unsigned /*visionkey*/) +SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) { - // Retrieve the symbol named 'symbol_id' from the source SVG document - SPObject const* symbol = source->getObjectById(symbol_id); - if (symbol == NULL) { - //std::cout << " Failed to find symbol: " << symbol_id << std::endl; - //return 0; - } - // Create a copy repr of the symbol with id="the_symbol" Inkscape::XML::Document *xml_doc = previewDocument->getReprDoc(); Inkscape::XML::Node *repr = symbol->getRepr()->duplicate(xml_doc); @@ -626,10 +616,10 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, gchar const* style = repr->attribute("inkscape:symbol-style"); if( !style ) { // If no default style in <symbol>, look in documents. - if( source == currentDocument ) { - style = style_from_use( symbol_id, source ); + if( symbol->document == currentDocument ) { + style = style_from_use( symbol_id, symbol->document ); } else { - style = source->getReprRoot()->attribute("style"); + style = symbol->document->getReprRoot()->attribute("style"); } } // Last ditch effort to provide some default styling @@ -719,7 +709,7 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, scale = atof( previewScaleString.c_str() ); } - pixbuf = Glib::wrap(render_pixbuf(*drawing, scale, *dbox, psize)); + pixbuf = Glib::wrap(render_pixbuf(renderDrawing, scale, *dbox, psize)); svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj()); } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 08221bf22..2d408386f 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -51,6 +51,7 @@ private: void get_symbols(); void draw_symbols( SPDocument* symbol_document ); + void draw_symbol( SPObject* symbol_document ); SPDocument* symbols_preview_doc(); GSList* symbols_in_doc_recursive(SPObject *r, GSList *l); @@ -60,9 +61,7 @@ private: gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr<Gdk::Pixbuf> - create_symbol_image(gchar const *symbol_name, - SPDocument *source, Inkscape::Drawing* drawing, - unsigned /*visionkey*/); + create_symbol_image(gchar const *symbol_name, SPObject *symbol); /* Keep track of all symbol template documents */ std::map<Glib::ustring, SPDocument*> symbolSets; |
