Code

Add a zoom correction option to preferences (used when zooming to 1:1 etc. to display...
[inkscape.git] / src / ui / dialog / svg-fonts-dialog.cpp
index 3e356119066520bbca3e593112266ef006bf20f0..fa81e84ca7e754aa68028be49c0efc037229ae61 100644 (file)
 
 #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 = "";
@@ -57,6 +60,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(){
@@ -172,35 +245,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);
-
-//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));
+Gtk::VBox* SvgFontsDialog::global_settings_tab(){
+    Gtk::VBox* global_vbox = Gtk::manage(new Gtk::VBox());
 
-    this->update_fonts();
+    AttrEntry* familyname;
+    familyname = new AttrEntry(this, (gchar*) "Family Name", SP_PROP_FONT_FAMILY);
 
-//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:"))));
@@ -224,6 +305,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);