From: Felipe C. da S. Sanches Date: Fri, 11 Dec 2009 08:37:11 +0000 (-0200) Subject: - new: Print Colors Preview Dialog and rendermode X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cd21e1bc3fdd406ffb31c1db0bb9ac984999f222;p=inkscape.git - new: Print Colors Preview Dialog and rendermode - works with shapes. I still need to make it work with gradients and imported images --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 319a0d407..0e4d4caf3 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -458,6 +458,9 @@ void SPDesktop::displayModeToggle() { _setDisplayMode(Inkscape::RENDERMODE_OUTLINE); break; case Inkscape::RENDERMODE_OUTLINE: + _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); + break; + case Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW: default: _setDisplayMode(Inkscape::RENDERMODE_NORMAL); } diff --git a/src/desktop.h b/src/desktop.h index cfb977425..a02a31034 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -201,6 +201,9 @@ struct SPDesktop : public Inkscape::UI::View::View void setDisplayModeOutline() { _setDisplayMode(Inkscape::RENDERMODE_OUTLINE); } + void setDisplayModePrintColorsPreview() { + _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); + } void displayModeToggle(); Inkscape::RenderMode _display_mode; Inkscape::RenderMode getMode() const { return _display_mode; } diff --git a/src/display/nr-arena-item.cpp b/src/display/nr-arena-item.cpp index bdab5b479..b80df7273 100644 --- a/src/display/nr-arena-item.cpp +++ b/src/display/nr-arena-item.cpp @@ -312,7 +312,9 @@ nr_arena_item_invoke_render (cairo_t *ct, NRArenaItem *item, NRRectL const *area NRPixBlock *pb, unsigned int flags) { bool outline = (item->arena->rendermode == Inkscape::RENDERMODE_OUTLINE); - bool filter = (item->arena->rendermode == Inkscape::RENDERMODE_NORMAL); + bool filter = (item->arena->rendermode != Inkscape::RENDERMODE_OUTLINE && + item->arena->rendermode != Inkscape::RENDERMODE_NO_FILTERS); + bool print_colors = (item->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); nr_return_val_if_fail (item != NULL, NR_ARENA_ITEM_STATE_INVALID); nr_return_val_if_fail (NR_IS_ARENA_ITEM (item), diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index 96ea76cbe..d5a098c39 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -35,6 +35,8 @@ #include "display/nr-filter.h" #include #include +#include "preferences.h" +#include "svg/svg-device-color.h" #include #include "svg/svg.h" @@ -844,6 +846,7 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock if (!shape->style) return item->state; bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == Inkscape::RENDERMODE_OUTLINE); + bool print_colors = (NR_ARENA_ITEM(shape)->arena->rendermode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW); if (outline) { // cairo outline rendering @@ -873,7 +876,22 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock } } + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + SPStyle const *style = shape->style; + bool render_cyan = prefs->getBool("/options/printcolorspreview/cyan", true); + bool render_magenta = prefs->getBool("/options/printcolorspreview/magenta", true); + bool render_yellow = prefs->getBool("/options/printcolorspreview/yellow", true); + bool render_black = prefs->getBool("/options/printcolorspreview/black", true); + + float rgb_v[3]; + float cmyk_v[4]; +#define FLOAT_TO_UINT8(f) (int(f*255)) +#define RGBA_R(v) ((v) >> 24) +#define RGBA_G(v) (((v) >> 16) & 0xff) +#define RGBA_B(v) (((v) >> 8) & 0xff) +#define RGBA_A(v) ((v) & 0xff) + if (shape->fill_shp) { NRPixBlock m; guint32 rgba; @@ -893,12 +911,24 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) { // do not render fill in any way } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) { + + const SPColor* fill_color = &shape->_fill.paint.color(); if ( item->render_opacity ) { - rgba = shape->_fill.paint.color().toRGBA32( shape->_fill.opacity * - SP_SCALE24_TO_FLOAT(style->opacity.value) ); + rgba = fill_color->toRGBA32( shape->_fill.opacity * + SP_SCALE24_TO_FLOAT(style->opacity.value) ); } else { - rgba = shape->_fill.paint.color().toRGBA32( shape->_fill.opacity ); + rgba = fill_color->toRGBA32( shape->_fill.opacity ); + } + + if (print_colors){ + sp_color_rgb_to_cmyk_floatv (cmyk_v, RGBA_R(rgba)/256.0, RGBA_G(rgba)/256.0, RGBA_B(rgba)/256.0); + sp_color_cmyk_to_rgb_floatv (rgb_v, render_cyan ? cmyk_v[0] : 0, + render_magenta ? cmyk_v[1] : 0, + render_yellow ? cmyk_v[2] : 0, + render_black ? cmyk_v[3] : 0); + rgba = (FLOAT_TO_UINT8(rgb_v[0])<<24) + (FLOAT_TO_UINT8(rgb_v[1])<<16) + (FLOAT_TO_UINT8(rgb_v[2])<<8) + 0xff; } + nr_blit_pixblock_mask_rgba32(pb, &m, rgba); pb->empty = FALSE; } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) { @@ -929,14 +959,25 @@ nr_arena_shape_render(cairo_t *ct, NRArenaItem *item, NRRectL *area, NRPixBlock nr_pixblock_render_shape_mask_or(m, shape->stroke_shp); m.empty = FALSE; - if ( item->render_opacity ) { - rgba = shape->_stroke.paint.color().toRGBA32( shape->_stroke.opacity * - SP_SCALE24_TO_FLOAT(style->opacity.value) ); - } else { - rgba = shape->_stroke.paint.color().toRGBA32( shape->_stroke.opacity ); - } - nr_blit_pixblock_mask_rgba32(pb, &m, rgba); - pb->empty = FALSE; + const SPColor* stroke_color = &shape->_stroke.paint.color(); + if ( item->render_opacity ) { + rgba = stroke_color->toRGBA32( shape->_stroke.opacity * + SP_SCALE24_TO_FLOAT(style->opacity.value) ); + } else { + rgba = stroke_color->toRGBA32( shape->_stroke.opacity ); + } + + if (print_colors){ + sp_color_rgb_to_cmyk_floatv (cmyk_v, RGBA_R(rgba)/256.0, RGBA_G(rgba)/256.0, RGBA_B(rgba)/256.0); + sp_color_cmyk_to_rgb_floatv (rgb_v, render_cyan ? cmyk_v[0] : 0, + render_magenta ? cmyk_v[1] : 0, + render_yellow ? cmyk_v[2] : 0, + render_black ? cmyk_v[3] : 0); + rgba = (FLOAT_TO_UINT8(rgb_v[0])<<24) + (FLOAT_TO_UINT8(rgb_v[1])<<16) + (FLOAT_TO_UINT8(rgb_v[2])<<8) + 0xff; + } + + nr_blit_pixblock_mask_rgba32(pb, &m, rgba); + pb->empty = FALSE; nr_pixblock_release(&m); diff --git a/src/display/rendermode.h b/src/display/rendermode.h index 1b59ae9bb..abcdb3db4 100644 --- a/src/display/rendermode.h +++ b/src/display/rendermode.h @@ -12,7 +12,8 @@ namespace Inkscape { enum RenderMode { RENDERMODE_NORMAL, RENDERMODE_NO_FILTERS, - RENDERMODE_OUTLINE + RENDERMODE_OUTLINE, + RENDERMODE_PRINT_COLORS_PREVIEW }; } diff --git a/src/interface.cpp b/src/interface.cpp index 415593b78..b29b91d18 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -703,6 +703,8 @@ update_view_menu(GtkWidget *widget, GdkEventExpose */*event*/, gpointer user_dat new_state = mode == Inkscape::RENDERMODE_NO_FILTERS; } else if (!strcmp(action->id, "ViewModeOutline")) { new_state = mode == Inkscape::RENDERMODE_OUTLINE; + } else if (!strcmp(action->id, "ViewModePrintColorsPreview")) { + new_state = mode == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW; } else { g_warning("update_view_menu does not handle this verb"); } diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index d7a18f211..c664d683a 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -110,6 +110,8 @@ static char const menus_skeleton[] = " \n" " \n" " \n" +" \n" +" \n" " \n" " \n" " \n" diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index fd1b07394..fac5bad80 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -71,6 +71,8 @@ ink_common_sources += \ ui/dialog/panel-dialog.h \ ui/dialog/print.cpp \ ui/dialog/print.h \ + ui/dialog/print-colors-preview-dialog.cpp \ + ui/dialog/print-colors-preview-dialog.h \ ui/dialog/scriptdialog.cpp \ ui/dialog/scriptdialog.h \ ui/dialog/spray-option.cpp \ diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 7f853bedc..2116d46c3 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -41,6 +41,7 @@ #include "ui/dialog/floating-behavior.h" #include "ui/dialog/dock-behavior.h" #include "ui/dialog/spray-option.h" +#include "ui/dialog/print-colors-preview-dialog.h" #include "preferences.h" #ifdef ENABLE_SVG_FONTS @@ -102,6 +103,7 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create); registerFactory("Memory", &create); registerFactory("Messages", &create); + registerFactory("PrintColorsPreviewDialog", &create); registerFactory("Script", &create); #ifdef ENABLE_SVG_FONTS registerFactory("SvgFontsDialog", &create); @@ -129,6 +131,7 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create); registerFactory("Memory", &create); registerFactory("Messages", &create); + registerFactory("PrintColorsPreviewDialog", &create); registerFactory("Script", &create); #ifdef ENABLE_SVG_FONTS registerFactory("SvgFontsDialog", &create); diff --git a/src/ui/dialog/print-colors-preview-dialog.cpp b/src/ui/dialog/print-colors-preview-dialog.cpp new file mode 100644 index 000000000..f4d83c271 --- /dev/null +++ b/src/ui/dialog/print-colors-preview-dialog.cpp @@ -0,0 +1,100 @@ +/** @file + * @brief Print Colors Preview dialog - implementation + */ +/* Authors: + * Felipe C. da S. Sanches + * + * Copyright (C) 2009 Authors + * Released under GNU GPLv2 (or later). Read the file 'COPYING' for more information. + */ + +#include "desktop.h" +#include "print-colors-preview-dialog.h" +#include "preferences.h" +#include + +namespace Inkscape { +namespace UI { +namespace Dialog { + +//Yes, I know we shouldn't hardcode CMYK. This class needs to be refactored +// in order to accomodate spot colors and color components defined using +// ICC colors. --Juca + +void PrintColorsPreviewDialog::toggle_cyan(){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/options/printcolorspreview/cyan", cyan->get_active()); + + SPDesktop *desktop = getDesktop(); + desktop->setDisplayModePrintColorsPreview(); +} + +void PrintColorsPreviewDialog::toggle_magenta(){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/options/printcolorspreview/magenta", magenta->get_active()); + + SPDesktop *desktop = getDesktop(); + desktop->setDisplayModePrintColorsPreview(); +} + +void PrintColorsPreviewDialog::toggle_yellow(){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/options/printcolorspreview/yellow", yellow->get_active()); + + SPDesktop *desktop = getDesktop(); + desktop->setDisplayModePrintColorsPreview(); +} + +void PrintColorsPreviewDialog::toggle_black(){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/options/printcolorspreview/black", black->get_active()); + + SPDesktop *desktop = getDesktop(); + desktop->setDisplayModePrintColorsPreview(); +} + +PrintColorsPreviewDialog::PrintColorsPreviewDialog() + : UI::Widget::Panel("", "/dialogs/printcolorspreview", SP_VERB_DIALOG_PRINT_COLORS_PREVIEW) +{ + Gtk::VBox* vbox = Gtk::manage(new Gtk::VBox()); + + cyan = new Gtk::ToggleButton(_("Cyan")); + vbox->pack_start( *cyan, false, false ); +// tips.set_tip((*cyan), _("Render cyan separation")); + cyan->signal_clicked().connect( sigc::mem_fun(*this, &PrintColorsPreviewDialog::toggle_cyan) ); + + magenta = new Gtk::ToggleButton(_("Magenta")); + vbox->pack_start( *magenta, false, false ); +// tips.set_tip((*magenta), _("Render magenta separation")); + magenta->signal_clicked().connect( sigc::mem_fun(*this, &PrintColorsPreviewDialog::toggle_magenta) ); + + yellow = new Gtk::ToggleButton(_("Yellow")); + vbox->pack_start( *yellow, false, false ); +// tips.set_tip((*yellow), _("Render yellow separation")); + yellow->signal_clicked().connect( sigc::mem_fun(*this, &PrintColorsPreviewDialog::toggle_yellow) ); + + black = new Gtk::ToggleButton(_("Black")); + vbox->pack_start( *black, false, false ); +// tips.set_tip((*black), _("Render black separation")); + black->signal_clicked().connect( sigc::mem_fun(*this, &PrintColorsPreviewDialog::toggle_black) ); + + gint val; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + val = prefs->getBool("/options/printcolorspreview/cyan"); + cyan->set_active( val != 0 ); + val = prefs->getBool("/options/printcolorspreview/magenta"); + magenta->set_active( val != 0 ); + val = prefs->getBool("/options/printcolorspreview/yellow"); + yellow->set_active( val != 0 ); + val = prefs->getBool("/options/printcolorspreview/black"); + black->set_active( val != 0 ); + + _getContents()->add(*vbox); + _getContents()->show_all(); +} + +PrintColorsPreviewDialog::~PrintColorsPreviewDialog(){} + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape diff --git a/src/ui/dialog/print-colors-preview-dialog.h b/src/ui/dialog/print-colors-preview-dialog.h new file mode 100644 index 000000000..246908556 --- /dev/null +++ b/src/ui/dialog/print-colors-preview-dialog.h @@ -0,0 +1,48 @@ +/** @file + * @brief Print Colors Preview dialog + */ +/* Authors: + * Felipe Corrêa da Silva Sanches + * + * Copyright (C) 2009 Authors + * Released under GNU GPLv2 (or later). Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_DIALOG_PRINT_COLORS_PREVIEW_H +#define INKSCAPE_UI_DIALOG_PRINT_COLORS_PREVIEW_H + +#include "ui/widget/panel.h" +#include "verbs.h" + +#include +#include + +namespace Inkscape { +namespace UI { +namespace Dialog { + +class PrintColorsPreviewDialog : public UI::Widget::Panel { +public: + PrintColorsPreviewDialog(); + ~PrintColorsPreviewDialog(); + + static PrintColorsPreviewDialog &getInstance() + { return *new PrintColorsPreviewDialog(); } + +private: + void toggle_cyan(); + void toggle_magenta(); + void toggle_yellow(); + void toggle_black(); + + Gtk::ToggleButton* cyan; + Gtk::ToggleButton* magenta; + Gtk::ToggleButton* yellow; + Gtk::ToggleButton* black; +}; + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape + +#endif //#ifndef INKSCAPE_UI_PRINT_COLORS_PREVIEW_H diff --git a/src/verbs.cpp b/src/verbs.cpp index 56b63e95e..6f86c3cce 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1749,6 +1749,9 @@ ZoomVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_VIEW_MODE_OUTLINE: dt->setDisplayModeOutline(); break; + case SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW: + dt->setDisplayModePrintColorsPreview(); + break; case SP_VERB_VIEW_MODE_TOGGLE: dt->displayModeToggle(); break; @@ -1871,6 +1874,9 @@ DialogVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_DIALOG_SVG_FONTS: dt->_dlg_mgr->showDialog("SvgFontsDialog"); break; + case SP_VERB_DIALOG_PRINT_COLORS_PREVIEW: + dt->_dlg_mgr->showDialog("PrintColorsPreviewDialog"); + break; default: break; } @@ -2626,6 +2632,8 @@ Verb *Verb::_base_verbs[] = { N_("Switch to normal display without filters"), NULL), new ZoomVerb(SP_VERB_VIEW_MODE_OUTLINE, "ViewModeOutline", N_("_Outline"), N_("Switch to outline (wireframe) display mode"), NULL), + new ZoomVerb(SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, "ViewModePrintColorsPreview", N_("_Print Colors Preview"), + N_("Switch to print colors preview mode"), NULL), new ZoomVerb(SP_VERB_VIEW_MODE_TOGGLE, "ViewModeToggle", N_("_Toggle"), N_("Toggle between normal and outline display modes"), NULL), @@ -2701,6 +2709,8 @@ Verb *Verb::_base_verbs[] = { N_("Manage, edit, and apply SVG filters"), NULL), new DialogVerb(SP_VERB_DIALOG_SVG_FONTS, "DialogSVGFonts", N_("SVG Font Editor..."), N_("Edit SVG fonts"), NULL), + new DialogVerb(SP_VERB_DIALOG_PRINT_COLORS_PREVIEW, "DialogPrintColorsPreview", N_("Print Colors..."), + N_("Select which color separations to render in Print Colors Preview rendermode"), NULL), /* Help */ new HelpVerb(SP_VERB_HELP_ABOUT_EXTENSIONS, "HelpAboutExtensions", N_("About E_xtensions"), diff --git a/src/verbs.h b/src/verbs.h index 3ea2fdee8..d0abcdca2 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -214,6 +214,7 @@ enum { SP_VERB_VIEW_MODE_NORMAL, SP_VERB_VIEW_MODE_NO_FILTERS, SP_VERB_VIEW_MODE_OUTLINE, + SP_VERB_VIEW_MODE_PRINT_COLORS_PREVIEW, SP_VERB_VIEW_MODE_TOGGLE, SP_VERB_VIEW_CMS_TOGGLE, SP_VERB_VIEW_ICON_PREVIEW, @@ -251,6 +252,7 @@ enum { SP_VERB_DIALOG_LIVE_PATH_EFFECT, SP_VERB_DIALOG_FILTER_EFFECTS, SP_VERB_DIALOG_SVG_FONTS, + SP_VERB_DIALOG_PRINT_COLORS_PREVIEW, /* Help */ SP_VERB_HELP_ABOUT_EXTENSIONS, SP_VERB_HELP_MEMORY, diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index e3bf1ae9c..b63992afe 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -613,12 +613,20 @@ SPDesktopWidget::updateTitle(gchar const* uri) if (this->desktop->number > 1) { if (this->desktop->getMode() == Inkscape::RENDERMODE_OUTLINE) { g_string_printf (name, _("%s: %d (outline) - Inkscape"), fname, this->desktop->number); + } else if (this->desktop->getMode() == Inkscape::RENDERMODE_NO_FILTERS) { + g_string_printf (name, _("%s: %d (no filters) - Inkscape"), fname, this->desktop->number); + } else if (this->desktop->getMode() == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW) { + g_string_printf (name, _("%s: %d (print colors preview) - Inkscape"), fname, this->desktop->number); } else { g_string_printf (name, _("%s: %d - Inkscape"), fname, this->desktop->number); } } else { if (this->desktop->getMode() == Inkscape::RENDERMODE_OUTLINE) { g_string_printf (name, _("%s (outline) - Inkscape"), fname); + } else if (this->desktop->getMode() == Inkscape::RENDERMODE_NO_FILTERS) { + g_string_printf (name, _("%s (no filters) - Inkscape"), fname); + } else if (this->desktop->getMode() == Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW) { + g_string_printf (name, _("%s (print colors preview) - Inkscape"), fname); } else { g_string_printf (name, _("%s - Inkscape"), fname); }