From: JucaBlues Date: Fri, 11 Jul 2008 06:03:47 +0000 (+0000) Subject: * removed the auxiliary GtkWindow X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a7b2d0eab58019b3222f3e9bce409d03a1d99400;p=inkscape.git * removed the auxiliary GtkWindow * added font preview to the SvgFonts dialog --- diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index 7b0b4938b..b59d0569d 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -22,29 +22,6 @@ #include "inkscape-cairo.h" #include "nr-svgfonts.h" -//***********************************// -// SvgFontDrawingArea Implementation // -//***********************************// -class SvgFontDrawingArea : Gtk::DrawingArea{ -public: -SvgFontDrawingArea(SvgFont* svgfont){ - this->svgfont = svgfont; -} -private: -SvgFont* svgfont; - -bool on_expose_event (GdkEventExpose *event){ - Glib::RefPtr window = get_window(); - Cairo::RefPtr cr = window->create_cairo_context(); - cr->set_font_face( Cairo::RefPtr(new Cairo::FontFace(this->svgfont->get_font_face(), false /* does not have reference */)) ); - cr->set_font_size (100); - cr->move_to (100, 100); - cr->show_text ("A@!A!@A"); - - return TRUE; -} -};//class SvgFontDrawingArea - //*************************// // UserFont Implementation // //*************************// @@ -98,16 +75,6 @@ SvgFont::SvgFont(SPFont* spfont){ this->font = spfont; this->missingglyph = NULL; this->userfont = NULL; - - //This is an auxiliary gtkWindow used only while we do not have proper Pango integration with cairo-user-fonts. - Gtk::Window* window; - SvgFontDrawingArea* font_da; - - window = new Gtk::Window(); - window->set_default_size (1200, 850); - font_da = new SvgFontDrawingArea(this); - window->add((Gtk::Widget&) *font_da); - window->show_all(); } cairo_status_t diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h index 58840e414..ff98f521f 100644 --- a/src/display/nr-svgfonts.h +++ b/src/display/nr-svgfonts.h @@ -14,12 +14,12 @@ */ #include "cairo.h" -#include +//#include #include -#include -#include -#include // for cairo helper functions +//#include +//#include +//#include // for cairo helper functions #include "../sp-glyph.h" #include "../sp-missing-glyph.h" diff --git a/src/sp-font.cpp b/src/sp-font.cpp index c99d5a1b6..789d3a62a 100644 --- a/src/sp-font.cpp +++ b/src/sp-font.cpp @@ -103,8 +103,6 @@ static void sp_font_build(SPObject *object, SPDocument *document, Inkscape::XML: sp_object_read_attr(object, "vert-origin-y"); sp_object_read_attr(object, "vert-adv-y"); - SvgFont* svgfont = new SvgFont(SP_FONT(object)); - sp_document_add_resource(document, "font", object); } diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index fb51da7de..38639a20d 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -17,6 +17,36 @@ #include "svg-fonts-dialog.h" +SvgFontDrawingArea::SvgFontDrawingArea(){ + this->text = (gchar*) "A@!A!@A"; + this->svgfont = NULL; + ((Gtk::Widget*) this)->set_size_request(150, 50); +} + +void SvgFontDrawingArea::set_svgfont(SvgFont* svgfont){ + this->svgfont = svgfont; +} + +void SvgFontDrawingArea::set_text(gchar* text){ + this->text = text; +} + +void SvgFontDrawingArea::redraw(){ + ((Gtk::Widget*) this)->queue_draw(); +} + +bool SvgFontDrawingArea::on_expose_event (GdkEventExpose *event){ + if (this->svgfont){ + Glib::RefPtr window = get_window(); + Cairo::RefPtr cr = window->create_cairo_context(); + cr->set_font_face( Cairo::RefPtr(new Cairo::FontFace(this->svgfont->get_font_face(), false /* does not have reference */)) ); + cr->set_font_size (20); + cr->move_to (20, 20); + cr->show_text (this->text); + } + return TRUE; +} + namespace Inkscape { namespace UI { namespace Dialog { @@ -35,12 +65,26 @@ void SvgFontsDialog::update_fonts() Gtk::TreeModel::Row row = *_model->append(); SPFont* f = (SPFont*)l->data; row[_columns.font] = f; + row[_columns.svgfont] = new SvgFont(f); const gchar* lbl = f->label(); const gchar* id = SP_OBJECT_ID(f); row[_columns.label] = lbl ? lbl : (id ? id : "font"); } } +void SvgFontsDialog::on_font_selection_changed(){ + _font_da.set_svgfont(this->get_selected_svgfont()); + _font_da.redraw(); +} + +SvgFont* SvgFontsDialog::get_selected_svgfont() +{ + Gtk::TreeModel::iterator i = _font_list.get_selection()->get_selected(); + if(i) + return (*i)[_columns.svgfont]; + return NULL; +} + SvgFontsDialog::SvgFontsDialog() : UI::Widget::Panel("", "dialogs.svgfonts", SP_VERB_DIALOG_SVG_FONTS) { @@ -53,14 +97,19 @@ SvgFontsDialog::SvgFontsDialog() _model = Gtk::ListStore::create(_columns); _font_list.set_model(_model); _font_list.append_column_editable("_Font", _columns.label); + _font_list.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_font_selection_changed)); + this->update_fonts(); + _getContents()->add((Gtk::Widget&) _font_da); + _getContents()->show_all(); + //Settings for the selected SVGFont: - _font_family.set_label("font-family"); - _font_variant.set_label("font-variant"); +// _font_family.set_label("font-family"); +// _font_variant.set_label("font-variant"); - _font_settings.add(_font_family); - _font_settings.add(_font_variant); +// _font_settings.add(_font_family); +// _font_settings.add(_font_variant); } SvgFontsDialog::~SvgFontsDialog(){} diff --git a/src/ui/dialog/svg-fonts-dialog.h b/src/ui/dialog/svg-fonts-dialog.h index 415aa8f7e..044ce5d44 100644 --- a/src/ui/dialog/svg-fonts-dialog.h +++ b/src/ui/dialog/svg-fonts-dialog.h @@ -19,11 +19,26 @@ #include "desktop.h" #include "desktop-handles.h" +#include #include #include #include #include +#include "display/nr-svgfonts.h" + +class SvgFontDrawingArea : Gtk::DrawingArea{ +public: + SvgFontDrawingArea(); + void set_text(gchar*); + void set_svgfont(SvgFont*); + void redraw(); +private: + SvgFont* svgfont; + gchar* text; + bool on_expose_event (GdkEventExpose *event); +}; + struct SPFont; namespace Inkscape { @@ -39,7 +54,8 @@ public: { return *new SvgFontsDialog(); } void update_fonts(); - + SvgFont* get_selected_svgfont(); + void on_font_selection_changed(); private: class Columns : public Gtk::TreeModel::ColumnRecord { @@ -47,18 +63,19 @@ private: Columns() { add(font); + add(svgfont); add(label); - //add(sel); } Gtk::TreeModelColumn font; + Gtk::TreeModelColumn svgfont; Gtk::TreeModelColumn label; - //Gtk::TreeModelColumn sel; }; Glib::RefPtr _model; Columns _columns; Gtk::TreeView _font_list; Gtk::VBox _font_settings; + SvgFontDrawingArea _font_da; class EntryWidget : public Gtk::HBox { public: