Code

From trunk
[inkscape.git] / src / ui / dialog / svg-fonts-dialog.cpp
index 22d03998676056d2955a74deacec105c36f3f9c3..6a27f6048aebf58f9e03b7631c8223af978d9b34 100644 (file)
@@ -1,11 +1,10 @@
-/**
- * \brief SVG Fonts dialog
- *
- * Authors:
+/** @file
+ * @brief SVG Fonts dialog - implementation
+ */
+/* Authors:
  *   Felipe C. da S. Sanches <felipe.sanches@gmail.com>
  *
  * Copyright (C) 2008 Authors
- *
  * Released under GNU GPLv2 (or later).  Read the file 'COPYING' for more information.
  */
 
 
 #ifdef ENABLE_SVG_FONTS
 
+#include <gtkmm/notebook.h>
 #include "svg-fonts-dialog.h"
 #include <glibmm/i18n.h>
 #include <string.h>
+#include "xml/node.h"
 
 SvgFontDrawingArea::SvgFontDrawingArea(){
        this->text = "";
@@ -58,6 +59,76 @@ namespace Inkscape {
 namespace UI {
 namespace Dialog {
 
+/*
+Gtk::HBox* SvgFontsDialog::AttrEntry(gchar* lbl, const SPAttributeEnum attr){
+    Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox());
+    hbox->add(* Gtk::manage(new Gtk::Label(lbl)) );
+    Gtk::Entry* entry = Gtk::manage(new Gtk::Entry());
+    hbox->add(* entry );
+    hbox->show_all();
+
+    entry->signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_attr_changed));
+    return hbox;
+}
+*/
+
+SvgFontsDialog::AttrEntry::AttrEntry(SvgFontsDialog* d, gchar* lbl, const SPAttributeEnum attr){
+    this->dialog = d;
+    this->attr = attr;
+    this->add(* Gtk::manage(new Gtk::Label(lbl)) );
+    this->add(entry);
+    this->show_all();
+
+    entry.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::AttrEntry::on_attr_changed));
+}
+
+void SvgFontsDialog::AttrEntry::on_attr_changed(){
+       g_warning("attr entry changed: %s", this->entry.get_text().c_str());
+
+       SPObject* o = NULL;
+        for(SPObject* node = this->dialog->get_selected_spfont()->children; node; node=node->next){
+            switch(this->attr){
+               case SP_PROP_FONT_FAMILY:
+                       if (SP_IS_FONTFACE(node)){
+                               o = node;
+                               continue;
+                       }
+                       break;
+               default:
+                       o = NULL;
+           }
+        }
+
+       const gchar* name = (const gchar*)sp_attribute_name(this->attr);
+        if(name && o) {
+            SP_OBJECT_REPR(o)->setAttribute((const gchar*) name, this->entry.get_text().c_str());
+            o->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
+
+            Glib::ustring undokey = "svgfonts:";
+            undokey += name;
+            sp_document_maybe_done(o->document, undokey.c_str(), SP_VERB_DIALOG_SVG_FONTS,
+                                   _("Set SVG Font attribute"));
+        }
+
+}
+
+Gtk::HBox* SvgFontsDialog::AttrCombo(gchar* lbl, const SPAttributeEnum attr){
+    Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox());
+    hbox->add(* Gtk::manage(new Gtk::Label(lbl)) );
+    hbox->add(* Gtk::manage(new Gtk::ComboBox()) );
+    hbox->show_all();
+    return hbox;
+}
+
+/*
+Gtk::HBox* SvgFontsDialog::AttrSpin(gchar* lbl){
+    Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox());
+    hbox->add(* Gtk::manage(new Gtk::Label(lbl)) );
+    hbox->add(* Gtk::manage(new Gtk::SpinBox()) );
+    hbox->show_all();
+    return hbox;
+}*/
+
 /*** SvgFontsDialog ***/
 
 GlyphComboBox::GlyphComboBox(){
@@ -173,35 +244,43 @@ SPFont* SvgFontsDialog::get_selected_spfont()
     return NULL;
 }
 
-SvgFontsDialog::SvgFontsDialog()
- : UI::Widget::Panel("", "dialogs.svgfonts", SP_VERB_DIALOG_SVG_FONTS)
-{
-    Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox());
-    hbox->add(_font_list);
-    hbox->add(_font_settings);
-    _getContents()->add(*hbox);
+Gtk::VBox* SvgFontsDialog::global_settings_tab(){
+    Gtk::VBox* global_vbox = Gtk::manage(new Gtk::VBox());
 
-//List of SVGFonts declared in a document:
-    _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));
+    AttrEntry* familyname;
+    familyname = new AttrEntry(this, (gchar*) _("Family Name:"), SP_PROP_FONT_FAMILY);
 
-    this->update_fonts();
-
-//kerning setup:
-    Gtk::VBox* kernvbox = Gtk::manage(new Gtk::VBox());
-    _font_settings.add(*kernvbox);
+    global_vbox->add(*familyname);
+    global_vbox->add(*AttrCombo((gchar*) _("Style:"), SP_PROP_FONT_STYLE));
+    global_vbox->add(*AttrCombo((gchar*) _("Variant:"), SP_PROP_FONT_VARIANT));
+    global_vbox->add(*AttrCombo((gchar*) _("Weight:"), SP_PROP_FONT_WEIGHT));
 
 //Set Width (horiz_adv_x):
     Gtk::HBox* setwidth_hbox = Gtk::manage(new Gtk::HBox());
-    setwidth_hbox->add(*Gtk::manage(new Gtk::Label(_("Set width (not working yet):"))));
+    setwidth_hbox->add(*Gtk::manage(new Gtk::Label(_("Set width:"))));
     setwidth_hbox->add(setwidth_spin);
 
     setwidth_spin.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_setwidth_changed));
     setwidth_spin.set_range(0, 4096);
     setwidth_spin.set_increments(10, 100);
-    _font_settings.add(*setwidth_hbox);
+    global_vbox->add(*setwidth_hbox);
+
+    return global_vbox;
+}
+
+Gtk::VBox* SvgFontsDialog::glyphs_tab(){
+    Gtk::VBox* glyphs_vbox = Gtk::manage(new Gtk::VBox());
+    glyphs_vbox->add(*new SvgFontsDialog::AttrEntry(this, (gchar*) _("Glyph Name:"), SP_ATTR_GLYPH_NAME));
+    glyphs_vbox->add(*new SvgFontsDialog::AttrEntry(this, (gchar*) _("Unicode:"), SP_ATTR_UNICODE));
+    //glyphs_vbox->add(*AttrSpin((gchar*) "Horizontal Advance"), SP_ATTR_HORIZ_ADV_X);
+    //glyphs_vbox->add(*AttrCombo((gchar*) "Missing Glyph"), SP_ATTR_); ?
+    return glyphs_vbox;
+}
+
+Gtk::VBox* SvgFontsDialog::kerning_tab(){
+
+//kerning setup:
+    Gtk::VBox* kernvbox = Gtk::manage(new Gtk::VBox());
 
 //Kerning Setup:
     kernvbox->add(*Gtk::manage(new Gtk::Label(_("Kerning Setup:"))));
@@ -225,6 +304,34 @@ SvgFontsDialog::SvgFontsDialog()
     kerning_preview.set_size(300 + 20, 150 + 20);
     _font_da.set_size(150 + 20, 50 + 20);
 
+    return kernvbox;
+}
+
+SvgFontsDialog::SvgFontsDialog()
+ : UI::Widget::Panel("", "/dialogs/svgfonts", SP_VERB_DIALOG_SVG_FONTS)
+{
+    Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox());
+    hbox->add(_font_list);
+    hbox->add(_font_settings);
+    _getContents()->add(*hbox);
+
+//List of SVGFonts declared in a document:
+    _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();
+
+    Gtk::Notebook *tabs = Gtk::manage(new Gtk::Notebook());
+    tabs->set_scrollable();
+
+    tabs->append_page(*global_settings_tab(), _("_Global Settings"), true);
+    tabs->append_page(*glyphs_tab(), _("_Glyphs"), true);
+    tabs->append_page(*kerning_tab(), _("_Kerning"), true);
+
+    _font_settings.add(*tabs);
+
 //Text Preview:
     _preview_entry.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_preview_text_changed));
     _getContents()->add((Gtk::Widget&) _font_da);