Code

Modified filter rendering area handling to better accommodate upcoming feOffset
[inkscape.git] / src / dialogs / text-edit.cpp
index 85237c7cb6cd681507d6236ec64b44e3e47830b0..b0ba2c2f00d4e172ca6e973fc9b2dcc502cbc28f 100644 (file)
@@ -3,11 +3,12 @@
 /**
  * \brief Text editing dialog
  *
- * Author:
+ * Authors:
  *   Lauris Kaplinski <lauris@ximian.com>
  *   bulia byak <buliabyak@users.sf.net>
+ *   Johan Engelen <goejendaagh@zonnet.nl>
  *
- * Copyright (C) 1999-2002 Lauris Kaplinski
+ * Copyright (C) 1999-2007 Authors
  * Copyright (C) 2000-2001 Ximian, Inc.
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
@@ -52,6 +53,7 @@ extern "C" {
 #include <xml/repr.h>
 
 #define VB_MARGIN 4
+#define MIN_ONSCREEN_DISTANCE 50
 
 static void sp_text_edit_dialog_selection_modified (Inkscape::Application *inkscape, Inkscape::Selection *sel, guint flags, GtkWidget *dlg);
 static void sp_text_edit_dialog_selection_changed (Inkscape::Application *inkscape, Inkscape::Selection *sel, GtkWidget *dlg);
@@ -143,8 +145,8 @@ sp_text_edit_dialog (void)
 
         dlg = sp_window_new (title, TRUE);
         if (x == -1000 || y == -1000) {
-            x = prefs_get_int_attribute (prefs_path, "x", 0);
-            y = prefs_get_int_attribute (prefs_path, "y", 0);
+            x = prefs_get_int_attribute (prefs_path, "x", -1000);
+            y = prefs_get_int_attribute (prefs_path, "y", -1000);
         }
 
         if (w ==0 || h == 0) {
@@ -152,17 +154,17 @@ sp_text_edit_dialog (void)
             h = prefs_get_int_attribute (prefs_path, "h", 0);
         }
 
-        if (x<0) x=0;
-        if (y<0) y=0;
+//        if (x<0) x=0;
+//        if (y<0) y=0;
 
-        if (x != 0 || y != 0) {
+        if (w && h)
+            gtk_window_resize ((GtkWindow *) dlg, w, h);
+        if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
             gtk_window_move ((GtkWindow *) dlg, x, y);
         } else {
             gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
         }
 
-        if (w && h)
-            gtk_window_resize ((GtkWindow *) dlg, w, h);
 
         sp_transientize (dlg);
         wd.win = dlg;
@@ -269,6 +271,20 @@ sp_text_edit_dialog (void)
                         gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0);
                         g_object_set_data (G_OBJECT (dlg), "text_anchor_end", b);
                     }
+                    
+                    // align justify
+                    {
+                        // TODO - replace with Inkscape-specific call
+                        GtkWidget *px = gtk_image_new_from_stock ( GTK_STOCK_JUSTIFY_FILL, GTK_ICON_SIZE_LARGE_TOOLBAR );
+                        GtkWidget *b = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
+                        gtk_tooltips_set_tip (tt, b, _("Justify lines"), NULL);
+                        gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE);
+                        g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg );
+                        gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE);
+                        gtk_container_add (GTK_CONTAINER (b), px);
+                        gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0);
+                        g_object_set_data (G_OBJECT (dlg), "text_anchor_justify", b);
+                    }
 
                     gtk_box_pack_start (GTK_BOX (l_vb), row, FALSE, FALSE, 0);
                 }
@@ -528,7 +544,7 @@ sp_get_text_dialog_style ()
                                        sp_repr_css_set_property (css, "font-variant", c);
                                        
                                        Inkscape::CSSOStringStream os;
-                                       os << sp_font_selector_get_size (SP_FONT_SELECTOR (fontsel));
+                                       os << sp_font_selector_get_size (SP_FONT_SELECTOR (fontsel)) << "px"; // must specify px, see inkscape bug 1221626 and 1610103
                                        sp_repr_css_set_property (css, "font-size", os.str().c_str());
                                        
                                        font->Unref();
@@ -538,18 +554,29 @@ sp_get_text_dialog_style ()
         /* Layout */
         GtkWidget *b = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "text_anchor_start");
         
+        // Align Left
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) {
             sp_repr_css_set_property (css, "text-anchor", "start");
             sp_repr_css_set_property (css, "text-align", "start");
         } else {
+            // Align Center
             b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), 
                                                 "text_anchor_middle");
             if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) {
                 sp_repr_css_set_property (css, "text-anchor", "middle");
                 sp_repr_css_set_property (css, "text-align", "center");
             } else {
-                sp_repr_css_set_property (css, "text-anchor", "end");
-                sp_repr_css_set_property (css, "text-align", "end");
+                // Align Right
+               b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), 
+                                                    "text_anchor_end");
+                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) {
+                    sp_repr_css_set_property (css, "text-anchor", "end");
+                    sp_repr_css_set_property (css, "text-align", "end");
+                } else {
+                    // Align Justify
+                    sp_repr_css_set_property (css, "text-anchor", "start");
+                    sp_repr_css_set_property (css, "text-align", "justify");
+                }
             }
         }
 
@@ -736,7 +763,11 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
 
         GtkWidget *b;
         if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) {
-            b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_start" );
+            if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) {
+                b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_justify" );
+            } else {
+                b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_start" );
+            }
         } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) {
             b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_middle" );
         } else {