text-edit.cpp revision 3478d2cd051e123df40b5dfef79f2cb254f26f6f
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Text editing dialog.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Lauris Kaplinski <lauris@ximian.com>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * bulia byak <buliabyak@users.sf.net>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Johan Engelen <goejendaagh@zonnet.nl>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Abhishek Sharma
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * John Smith
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Tavmjong Bah
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Copyright (C) 1999-2013 Authors
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Copyright (C) 2000-2001 Ximian, Inc.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Released under GNU GPL, read the file 'COPYING' for more information
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : UI::Widget::Panel("", "/dialogs/textandfont", SP_VERB_DIALOG_TEXT),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos TRANSLATORS: Test string used in text and font dialog (when no
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * text has been entered) to get a preview of the font. Choose
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * some representative characters that users of your locale will be
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * interested in.*/
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos samplephrase(_("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Font selector */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontsel_hbox.pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Align buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_left, _("Align left"), INKSCAPE_ICON("format-justify-left"), NULL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_center, _("Align center"), INKSCAPE_ICON("format-justify-center"), &align_left);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_right, _("Align right"), INKSCAPE_ICON("format-justify-right"), &align_left);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov styleButton(&align_justify, _("Justify (only flowed text)"), INKSCAPE_ICON("format-justify-fill"), &align_left);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos align_sep.set_orientation(Gtk::ORIENTATION_VERTICAL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(align_sep, false, false, 10);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Direction buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&text_horizontal, _("Horizontal text"), INKSCAPE_ICON("format-text-direction-horizontal"), NULL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&text_vertical, _("Vertical text"), INKSCAPE_ICON("format-text-direction-vertical"), &text_horizontal);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_sep.set_orientation(Gtk::ORIENTATION_VERTICAL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(text_sep, false, false, 10);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Line Spacing */
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("text_line_spacing") );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(px)), false, false);
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce spacing_combo = gtk_combo_box_text_new_with_entry ();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_size_request (spacing_combo, 90, -1);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos const gchar *spacings[] = {"50%", "80%", "90%", "100%", "110%", "120%", "130%", "140%", "150%", "200%", "300%", NULL};
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for (int i = 0; spacings[i]; i++) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_combo_box_text_append_text((GtkComboBoxText *) spacing_combo, spacings[i]);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text (px, _("Spacing between lines (percent of font size)"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text (spacing_combo, _("Spacing between lines (percent of font size)"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(spacing_combo)), false, false);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Text start Offset
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos startOffset = gtk_combo_box_text_new_with_entry ();
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce gtk_widget_set_size_request(startOffset, 90, -1);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov const gchar *spacings[] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", NULL};
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for (int i = 0; spacings[i]; i++) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_combo_box_text_append_text(reinterpret_cast<GtkComboBoxText *>(startOffset), spacings[i]);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), "0%");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text(startOffset, _("Text path offset"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::Separator *sep = Gtk::manage(new Gtk::Separator());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::VSeparator *sep = Gtk::manage(new Gtk::VSeparator);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(startOffset)), false, false);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Font preview */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos preview_label.set_ellipsize(Pango::ELLIPSIZE_END);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_vbox.pack_start(layout_frame, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_vbox.pack_start(preview_label, true, true, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Text tab */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_view = gtk_text_view_new_with_buffer (text_buffer);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov gtk_text_view_set_wrap_mode ((GtkTextView *) text_view, GTK_WRAP_WORD);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos TODO: Use computed xml:lang attribute of relevant element, if present, to specify the
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos language (either as 2nd arg of gtkspell_new_attach, or with explicit
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtkspell_set_language call in; see advanced.c example in gtkspell docs).
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos onReadSelection looks like a suitable place.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (gtkspell_new_attach(GTK_TEXT_VIEW(text_view), NULL, &error) == NULL) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos scroller.add(*Gtk::manage(Glib::wrap(text_view)));
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov text_vbox.pack_start(scroller, true, true, 0);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_start(setasdefault_button, false, false, 0);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_end(close_button, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_end(apply_button, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos contents->pack_start(button_row, false, false, VB_MARGIN);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek /* Signal handlers */
e27c0ecef59272d4723f904a17061b4e59f0a6dbMichal Židek g_signal_connect ( G_OBJECT (fontsel), "font_set", G_CALLBACK (onFontChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect ( G_OBJECT (spacing_combo), "changed", G_CALLBACK (onLineSpacingChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect ( G_OBJECT (text_buffer), "changed", G_CALLBACK (onTextChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect(startOffset, "changed", G_CALLBACK(onStartOffsetChange), this);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek setasdefault_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onSetDefault));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek apply_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onApply));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek close_button.signal_clicked().connect(sigc::bind(_signal_response.make_slot(), GTK_RESPONSE_CLOSE));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &TextEdit::setTargetDesktop) );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::styleButton(Gtk::RadioButton *button, gchar const *tooltip, gchar const *icon_name, Gtk::RadioButton *group_button )
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov GtkWidget *icon = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, icon_name );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos icon = gtk_image_new_from_icon_name ( icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::RadioButton::Group group = group_button->get_group();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onToggle));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židekvoid TextEdit::onSelectionModified(guint flags )
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek style = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG |
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek content = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG |
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židekvoid TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive( startOffset, SP_IS_TEXT_TEXTPATH(text) );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek SPTextPath *tp = SP_TEXTPATH(text->firstChild());
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), tp->getAttribute("startOffset"));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive( startOffset, FALSE );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //if (docontent) { // When would we NOT want to show the content ?
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_text (text_buffer, str, strlen (str));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_modified (text_buffer, FALSE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov //} // end of if (docontent)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov text->getRepr(); // was being called but result ignored. Check this.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // create temporary style
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // (Ok to not get a font specification - must just rely on the family and style in that case)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // This is normally done for us by text-toolbar but only when we are in text editing context
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontlister->update_font_list(this->desktop->getDocument());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring fontspec = fontlister->get_fontspec();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_font_selector_set_fontspec(fsel, fontspec, size );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos else if (query.line_height.unit == SP_CSS_UNIT_PERCENT)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) spacing_combo), sstr);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Update font variant widget
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //int result_variants =
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTVARIANTS);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos vari_vbox.update( query.font_variant_ligatures.computed, query.font_variant_ligatures.value );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring phrase_escaped = Glib::Markup::escape_text( phrase );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos double pt_size = Inkscape::Util::Quantity::convert(sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit), "px", "pt");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Pango font size is in 1024ths of a point
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // C++11: Glib::ustring size = std::to_string( int(pt_size * PANGO_SCALE) );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos size_st << int(pt_size * PANGO_SCALE); // Markup code expects integers
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring markup = "<span font=\'" + font_spec +
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos "\' size=\'" + size_st.str() + "\'>" + phrase_escaped + "</span>";
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos unsigned int items = 0;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // write text
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (gtk_text_buffer_get_modified (text_buffer)) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_get_bounds (text_buffer, &start, &end);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gchar *str = gtk_text_buffer_get_text (text_buffer, &start, &end, TRUE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov sp_te_set_repr_text_multiline (text, str);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_modified (text_buffer, FALSE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov Glib::ustring fontspec = sp_font_selector_get_fontspec (fsel);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance();
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik // TODO, possibly move this to FontLister::set_css to be shared.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (prefs->getBool("/options/font/textOutputPx", true)) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos os << sp_style_css_size_units_to_px(sp_font_selector_get_size (fsel), unit) << sp_style_get_css_unit_string(SP_CSS_UNIT_PX);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos os << sp_font_selector_get_size (fsel) << sp_style_get_css_unit_string(unit);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "font-size", os.str().c_str());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "middle");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "center");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "end");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "end");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Align Justify
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "justify");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "writing-mode", "lr");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "writing-mode", "tb");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Note that CSS 1.1 does not support line-height; we set it for consistency, but also set
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // sodipodi:linespacing for backwards compatibility; in 1.2 we use line-height for flowtext
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos const gchar *sstr = gtk_combo_box_text_get_active_text ((GtkComboBoxText *) spacing_combo);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "line-height", sstr);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek unsigned items = 0;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek const std::vector<SPItem*> item_list = desktop->getSelection()->itemList();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // apply style to the reprs of all text objects in the selection
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // backwards compatibility:
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // no text objects; apply style to prefs for new objects
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Inkscape::Preferences *prefs = Inkscape::Preferences::get();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // exactly one text object; now set its text, too
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // Update FontLister
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Glib::ustring fontspec = sp_font_selector_get_fontspec (fsel);
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // complete the transaction
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_TEXT,
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek _("Set text style"));
blocked = false;
if (text) {
if (fontspec) {
if (text) {
const gchar *sstr = gtk_combo_box_text_get_active_text(reinterpret_cast<GtkComboBoxText *>(self->startOffset));
DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "startOffset", SP_VERB_CONTEXT_TEXT, _("Set text style"));
if (blocked)
if (text) {
if (text) {
if (this->desktop) {
selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &TextEdit::onSelectionChange)));
subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &TextEdit::onSelectionChange)));
selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &TextEdit::onSelectionModified)));