Code

From trunk
[inkscape.git] / src / ui / dialog / svg-fonts-dialog.cpp
index d4a2be18f55f11744eb7524aa20c2d84e9c64872..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 = "";
@@ -57,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(){
@@ -141,11 +213,21 @@ void SvgFontsDialog::on_font_selection_changed(){
 
     int steps = 50;
     double set_width = spfont->horiz_adv_x;
+    setwidth_spin.set_value(set_width);
+
     kerning_spin.set_range(0,set_width);
     kerning_spin.set_increments(int(set_width/steps),2*int(set_width/steps));
     kerning_spin.set_value(0);
 }
 
+void SvgFontsDialog::on_setwidth_changed(){
+    SPFont* spfont = this->get_selected_spfont();
+    if (spfont){
+        spfont->horiz_adv_x = setwidth_spin.get_value();
+        //TODO: tell cairo that the glyphs cache has to be invalidated
+    }
+}
+
 SvgFont* SvgFontsDialog::get_selected_svgfont()
 {
     Gtk::TreeModel::iterator i = _font_list.get_selection()->get_selected();
@@ -162,30 +244,50 @@ 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();
+    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:"))));
+    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);
+    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());
-    _font_settings.add(*kernvbox);
-    kernvbox->add(*Gtk::manage(new Gtk::Label("Kerning Setup:")));
+
+//Kerning Setup:
+    kernvbox->add(*Gtk::manage(new Gtk::Label(_("Kerning Setup:"))));
     Gtk::HBox* kerning_selector = Gtk::manage(new Gtk::HBox());
-    kerning_selector->add(*Gtk::manage(new Gtk::Label("1st Glyph:")));
+    kerning_selector->add(*Gtk::manage(new Gtk::Label(_("1st Glyph:"))));
     kerning_selector->add(first_glyph);
-    kerning_selector->add(*Gtk::manage(new Gtk::Label("2nd Glyph:")));
+    kerning_selector->add(*Gtk::manage(new Gtk::Label(_("2nd Glyph:"))));
     kerning_selector->add(second_glyph);
     first_glyph.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_glyphs_changed));
     second_glyph.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_glyphs_changed));
@@ -196,12 +298,40 @@ SvgFontsDialog::SvgFontsDialog()
 
     Gtk::HBox* kerning_amount_hbox = Gtk::manage(new Gtk::HBox());
     kernvbox->add(*kerning_amount_hbox);
-    kerning_amount_hbox->add(*Gtk::manage(new Gtk::Label("Kerning value:")));
+    kerning_amount_hbox->add(*Gtk::manage(new Gtk::Label(_("Kerning value:"))));
     kerning_amount_hbox->add(kerning_spin);
 
     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);
@@ -210,7 +340,7 @@ SvgFontsDialog::SvgFontsDialog()
 
     Gtk::HBox* preview_entry_hbox = Gtk::manage(new Gtk::HBox());
     _getContents()->add(*preview_entry_hbox);
-    preview_entry_hbox->add(*Gtk::manage(new Gtk::Label("Preview Text:")));
+    preview_entry_hbox->add(*Gtk::manage(new Gtk::Label(_("Preview Text:"))));
     preview_entry_hbox->add(_preview_entry);
 
     _getContents()->show_all();