Commit 9055a9eb authored by Jabier Arraiza's avatar Jabier Arraiza
Browse files

Add line height UX improvements

parent 0fe4e04e
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg1"
width="28"
height="28"
>
version="1.1"
sodipodi:docname="text_outer_style-symbolic.svg"
inkscape:version="1.0alpha2 (7029881c03, 2019-06-24, custom)">
<metadata
id="metadata94">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
id="base"
showgrid="true"
gridspacingy="1pt"
gridspacingx="1pt"
gridoriginy="0pt"
gridoriginx="0pt"
/>
<defs id="defs3">
</defs>
<g id="text_outer_style" transform="translate(0,0)">
<rect height="28" id="text_outer_style_rect" style="fill:none" width="28" x="0" y="0"/>
<g aria-label="T" style="font-weight:bold;font-size:20px;font-family:sans-serif;text-anchor:middle;fill:#4d4d4d;stroke:#000000;stroke-width:0.75">
<path d="m 2.28125,2.4199219 h 13.4375 V 5.2617187 H 10.884766 V 17 H 7.125 V 5.2617187 H 2.28125 Z" id="BigT"/>
inkscape:document-rotation="0"
inkscape:zoom="5.6"
inkscape:cx="7.046511"
inkscape:cy="44.985506"
inkscape:window-width="1360"
inkscape:window-height="704"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg1">
<inkscape:grid
id="GridFromPre046Settings"
type="xygrid"
originx="0pt"
originy="0pt"
spacingx="1pt"
spacingy="1pt"
color="#3f3fff"
empcolor="#3f3fff"
opacity="0.15"
empopacity="0.38"
empspacing="5" />
</sodipodi:namedview>
<defs
id="defs3" />
<g
id="text_outer_style"
transform="translate(0,0)">
<rect
height="28"
id="text_outer_style_rect"
style="opacity:0"
width="28"
x="0"
y="0" />
<g
aria-label="T"
style="font-weight:bold;font-size:20px;font-family:sans-serif;text-anchor:middle;fill:#4d4d4d;stroke:#000000;stroke-width:0.75"
id="g82" />
<g
aria-label="T"
style="font-weight:bold;font-size:12px;font-family:sans-serif;text-anchor:middle;fill:#4d4d4d;stroke:#000000;stroke-width:0.75"
id="g85" />
<path
id="path921"
d="M 20,1.25 A 0.75,0.75 0 0 0 19.25,2 0.75,0.75 0 0 0 20,2.75 h 5.25 v 22.5 H 2.75 V 10 A 0.75,0.75 0 0 0 2,9.25 0.75,0.75 0 0 0 1.25,10 V 26 A 0.750075,0.750075 0 0 0 2,26.75 H 26 A 0.750075,0.750075 0 0 0 26.75,26 V 2 A 0.750075,0.750075 0 0 0 26,1.25 Z m -6.03125,12.001953 h 8.0625 v 1.705078 H 19.130859 V 22 H 16.875 V 14.957031 H 13.96875 Z M 2.28125,2.4199219 h 13.4375 V 5.2617187 H 10.884766 V 17 H 7.125 V 5.2617187 H 2.28125 Z" />
</g>
<g aria-label="T" style="font-weight:bold;font-size:12px;font-family:sans-serif;text-anchor:middle;fill:#4d4d4d;stroke:#000000;stroke-width:0.75">
<path d="m 13.96875,13.251953 h 8.0625 v 1.705078 H 19.130859 V 22 H 16.875 v -7.042969 h -2.90625 z" id="LittleT"/>
</g>
<path d="m 20,2 h 6 V 26 H 2 V 10" id="text_outer_style_path1" style="fill:none;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round"/>
<path d="M 3,3 H 15" id="text_outer_style_path2" style="fill:none;stroke:#999999;stroke-width:0.75;stroke-linecap:round"/>
<path d="M 7.8,5.5 V 16.25" id="text_outer_style_path3" style="fill:none;stroke:#999999;stroke-width:0.75;stroke-linecap:round"/>
<path d="m 14.6,13.75 h 6.8" id="text_outer_style_path4" style="fill:#4d4d4d;stroke:#999999;stroke-width:0.5;stroke-linecap:round"/>
<path d="m 17.5,14.85 v 6.5" id="text_outer_style_path5" style="fill:#4d4d4d;stroke:#999999;stroke-width:0.5;stroke-linecap:round"/>
</g>
</svg>
......@@ -486,9 +486,6 @@ void InkscapePreferences::initPageTools()
int sizeValues[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN, SP_CSS_UNIT_EM/*, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/};
_page_text.add_group_header( _("Text units"));
_font_unit_type.init( "/options/font/unitType", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), SP_CSS_UNIT_PT );
_page_text.add_line( true, _("Text size unit type:"), _font_unit_type, "",
_("Set the type of unit used in the text toolbar and text dialogs"), false);
_font_output_px.init ( _("Always output text size in pixels (px)"), "/options/font/textOutputPx", true);
// _page_text.add_line( false, "", _font_output_px, "", _("Always convert the text size units above into pixels (px) before saving to file"));
......
......@@ -37,6 +37,7 @@ extern "C" {
#include "document-undo.h"
#include "document.h"
#include "inkscape.h"
#include "style.h"
#include "text-editing.h"
#include "verbs.h"
......@@ -48,8 +49,8 @@ extern "C" {
#include "object/sp-textpath.h"
#include "svg/css-ostringstream.h"
#include "ui/icon-names.h"
#include "ui/toolbar/text-toolbar.h"
#include "ui/widget/font-selector.h"
#include "util/units.h"
......@@ -268,7 +269,7 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
font_selector.update_size (size);
selected_fontsize = size;
// Update font features (variant) widget
//int result_features =
sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTVARIANTS);
......@@ -422,18 +423,21 @@ void TextEdit::onApply()
unsigned items = 0;
auto item_list = desktop->getSelection()->items();
SPCSSAttr *css = fillTextStyle ();
sp_desktop_set_style(desktop, css, true);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
for(auto i=item_list.begin();i!=item_list.end();++i){
// apply style to the reprs of all text objects in the selection
if (SP_IS_TEXT (*i) || (SP_IS_FLOWTEXT (*i)) ) {
++items;
}
}
if (items == 1) {
double factor = font_selector.get_fontsize() / selected_fontsize;
prefs->setDouble("/options/font/scaleLineHeightFromFontSIze", factor);
}
sp_desktop_set_style(desktop, css, true);
if (items == 0) {
// no text objects; apply style to prefs for new objects
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->mergeStyle("/tools/text/style", css);
setasdefault_button.set_sensitive ( false );
......@@ -442,6 +446,12 @@ void TextEdit::onApply()
SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem();
if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) {
updateObjectText (item);
SPStyle *item_style = item->style;
if (SP_IS_TEXT(item) && item_style->inline_size.value == 0) {
css = sp_css_attr_from_style(item_style, SP_STYLE_FLAG_IFSET);
sp_repr_css_unset_property(css, "inline-size");
item->changeCSS(css, "style");
}
}
}
......
......@@ -188,6 +188,7 @@ private:
sigc::connection fontFeaturesChangedConn;
// Other
double selected_fontsize;
bool blocked;
const Glib::ustring samplephrase;
......
This diff is collapsed.
......@@ -28,9 +28,14 @@
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "object/sp-item.h"
#include "object/sp-object.h"
#include "toolbar.h"
#include <gtkmm/adjustment.h>
#include <gtkmm/box.h>
#include <gtkmm/popover.h>
#include <gtkmm/separatortoolitem.h>
#include <sigc++/connection.h>
class SPDesktop;
......@@ -59,24 +64,23 @@ class TextToolbar : public Toolbar {
private:
bool _freeze;
bool _text_style_from_prefs;
UI::Widget::UnitTracker *_tracker;
UI::Widget::UnitTracker *_tracker_fs;
UI::Widget::ComboBoxEntryToolItem *_font_family_item;
UI::Widget::ComboBoxEntryToolItem *_font_size_item;
UI::Widget::ComboToolItem *_font_size_units_item;
UI::Widget::ComboBoxEntryToolItem *_font_style_item;
UI::Widget::ComboToolItem *_line_height_units_item;
UI::Widget::SpinButtonToolItem *_line_height_item;
Gtk::ToggleToolButton *_superscript_item;
Gtk::ToggleToolButton *_subscript_item;
Gtk::ToggleToolButton *_outer_style_item;
Gtk::ToggleToolButton *_line_height_unset_item;
UI::Widget::ComboToolItem *_align_item;
UI::Widget::ComboToolItem *_writing_mode_item;
UI::Widget::ComboToolItem *_orientation_item;
UI::Widget::ComboToolItem *_direction_item;
UI::Widget::ComboToolItem *_line_height_units_item;
UI::Widget::ComboToolItem *_line_spacing_item;
UI::Widget::SpinButtonToolItem *_line_height_item;
UI::Widget::SpinButtonToolItem *_word_spacing_item;
UI::Widget::SpinButtonToolItem *_letter_spacing_item;
UI::Widget::SpinButtonToolItem *_dx_item;
......@@ -89,45 +93,49 @@ private:
Glib::RefPtr<Gtk::Adjustment> _dx_adj;
Glib::RefPtr<Gtk::Adjustment> _dy_adj;
Glib::RefPtr<Gtk::Adjustment> _rotation_adj;
bool _outer;
SPItem *_sub_active_item;
int _lineheight_unit;
int wrap_start;
int wrap_end;
bool _subselection;
bool _fullsubselection;
bool _updating;
double selection_fontsize;
sigc::connection c_selection_changed;
sigc::connection c_selection_modified;
sigc::connection c_selection_modified_select_tool;
sigc::connection c_subselection_changed;
void fontfamily_value_changed();
void fontsize_value_changed();
void subselection_wrap_toggle(bool start);
void fontstyle_value_changed();
void script_changed(Gtk::ToggleToolButton *btn);
void lineheight_unset_changed();
void outer_style_changed();
void align_mode_changed(int mode);
void writing_mode_changed(int mode);
void orientation_changed(int mode);
void direction_changed(int mode);
void lineheight_value_changed();
void lineheight_unit_changed(int not_used);
void line_spacing_mode_changed(int mode);
void wordspacing_value_changed();
void letterspacing_value_changed();
void dx_value_changed();
void dy_value_changed();
void rotation_value_changed();
void selection_changed(Inkscape::Selection *selection,
bool subselection = false);
void fontsize_unit_changed(int not_used);
void selection_changed(Inkscape::Selection *selection);
void selection_modified(Inkscape::Selection *selection, guint flags);
void subselection_changed(gpointer tc);
void selection_modified_select_tool(Inkscape::Selection *selection, guint flags);
void subselection_changed(gpointer texttool);
void watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec);
void set_sizes(int unit);
protected:
protected:
TextToolbar(SPDesktop *desktop);
public:
static GtkWidget * create(SPDesktop *desktop);
};
}
}
}
......
......@@ -258,13 +258,14 @@ bool TextTool::item_handler(SPItem* item, GdkEvent* event) {
SPItem *item_ungrouped;
gint ret = FALSE;
sp_text_context_validate_cursor_iterators(this);
Inkscape::Text::Layout::iterator old_start = this->text_sel_start;
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 1 && !this->space_panning) {
// this var allow too much lees subbselection queries
// reducing it to cursor iteracion, mouseup and down
// find out clicked item, disregarding groups
item_ungrouped = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE);
if (SP_IS_TEXT(item_ungrouped) || SP_IS_FLOWTEXT(item_ungrouped)) {
......@@ -318,71 +319,10 @@ bool TextTool::item_handler(SPItem* item, GdkEvent* event) {
this->dragging = 0;
sp_event_context_discard_delayed_snap_event(this);
ret = TRUE;
desktop->emitToolSubselectionChanged((gpointer)this);
}
break;
case GDK_MOTION_NOTIFY:
if ((event->motion.state & GDK_BUTTON1_MASK) && this->dragging && !this->space_panning) {
Inkscape::Text::Layout const *layout = te_get_layout(this->text);
if (!layout) break;
// find out click point in document coordinates
Geom::Point p = desktop->w2d(Geom::Point(event->button.x, event->button.y));
// set the cursor closest to that point
Inkscape::Text::Layout::iterator new_end = sp_te_get_position_by_coords(this->text, p);
if (this->dragging == 2) {
// double-click dragging: go by word
if (new_end < this->text_sel_start) {
if (!layout->isStartOfWord(new_end))
new_end.prevStartOfWord();
} else
if (!layout->isEndOfWord(new_end))
new_end.nextEndOfWord();
} else if (this->dragging == 3) {
// triple-click dragging: go by line
if (new_end < this->text_sel_start)
new_end.thisStartOfLine();
else
new_end.thisEndOfLine();
}
// update display
if (this->text_sel_end != new_end) {
this->text_sel_end = new_end;
sp_text_context_update_cursor(this);
sp_text_context_update_text_selection(this);
}
gobble_motion_events(GDK_BUTTON1_MASK);
ret = TRUE;
break;
}
// find out item under mouse, disregarding groups
item_ungrouped = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE);
if (SP_IS_TEXT(item_ungrouped) || SP_IS_FLOWTEXT(item_ungrouped)) {
Inkscape::Text::Layout const *layout = te_get_layout(item_ungrouped);
if (layout->inputTruncated()) {
SP_CTRLRECT(this->indicator)->setColor(0xff0000ff, false, 0);
} else {
SP_CTRLRECT(this->indicator)->setColor(0x0000ff7f, false, 0);
}
Geom::OptRect ibbox = item_ungrouped->desktopVisualBounds();
if (ibbox) {
SP_CTRLRECT(this->indicator)->setRectangle(*ibbox);
}
sp_canvas_item_show(this->indicator);
this->cursor_shape = cursor_text_insert_xpm;
this->sp_event_context_update_cursor();
sp_text_context_update_text_selection(this);
if (SP_IS_TEXT (item_ungrouped)) {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the text, <b>drag</b> to select part of the text."));
} else {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the flowed text, <b>drag</b> to select part of the text."));
}
this->over_text = true;
ret = TRUE;
}
break;
default:
break;
......@@ -552,7 +492,7 @@ bool TextTool::root_handler(GdkEvent* event) {
return TRUE;
}
break;
case GDK_MOTION_NOTIFY:
case GDK_MOTION_NOTIFY: {
if (this->over_text) {
this->over_text = false;
// update cursor and statusbar: we are not over a text object now
......@@ -560,7 +500,6 @@ bool TextTool::root_handler(GdkEvent* event) {
this->sp_event_context_update_cursor();
desktop->event_context->defaultMessageContext()->clear();
}
if (this->creating && (event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) {
if ( this->within_tolerance
&& ( abs( (gint) event->motion.x - this->xp ) < this->tolerance )
......@@ -598,7 +537,67 @@ bool TextTool::root_handler(GdkEvent* event) {
m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE));
m.unSetup();
}
ToolBase::root_handler(event);
if ((event->motion.state & GDK_BUTTON1_MASK) && this->dragging && !this->space_panning) {
Inkscape::Text::Layout const *layout = te_get_layout(this->text);
if (!layout) break;
// find out click point in document coordinates
Geom::Point p = desktop->w2d(Geom::Point(event->button.x, event->button.y));
// set the cursor closest to that point
Inkscape::Text::Layout::iterator new_end = sp_te_get_position_by_coords(this->text, p);
if (this->dragging == 2) {
// double-click dragging: go by word
if (new_end < this->text_sel_start) {
if (!layout->isStartOfWord(new_end))
new_end.prevStartOfWord();
} else
if (!layout->isEndOfWord(new_end))
new_end.nextEndOfWord();
} else if (this->dragging == 3) {
// triple-click dragging: go by line
if (new_end < this->text_sel_start)
new_end.thisStartOfLine();
else
new_end.thisEndOfLine();
}
// update display
if (this->text_sel_end != new_end) {
this->text_sel_end = new_end;
sp_text_context_update_cursor(this);
sp_text_context_update_text_selection(this);
}
gobble_motion_events(GDK_BUTTON1_MASK);
break;
}
// find out item under mouse, disregarding groups
SPItem *item_ungrouped = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE, nullptr);
if (SP_IS_TEXT(item_ungrouped) || SP_IS_FLOWTEXT(item_ungrouped)) {
Inkscape::Text::Layout const *layout = te_get_layout(item_ungrouped);
if (layout->inputTruncated()) {
SP_CTRLRECT(this->indicator)->setColor(0xff0000ff, false, 0);
} else {
SP_CTRLRECT(this->indicator)->setColor(0x0000ff7f, false, 0);
}
Geom::OptRect ibbox = item_ungrouped->desktopVisualBounds();
if (ibbox) {
SP_CTRLRECT(this->indicator)->setRectangle(*ibbox);
}
sp_canvas_item_show(this->indicator);
this->cursor_shape = cursor_text_insert_xpm;
this->sp_event_context_update_cursor();
sp_text_context_update_text_selection(this);
if (SP_IS_TEXT (item_ungrouped)) {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the text, <b>drag</b> to select part of the text."));
} else {
desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to edit the flowed text, <b>drag</b> to select part of the text."));
}
this->over_text = true;
}
return TRUE;
}
break;
case GDK_BUTTON_RELEASE:
if (event->button.button == 1 && !this->space_panning) {
sp_event_context_discard_delayed_snap_event(this);
......@@ -690,6 +689,7 @@ bool TextTool::root_handler(GdkEvent* event) {
}
}
this->creating = false;
desktop->emitToolSubselectionChanged((gpointer)this);
return TRUE;
}
break;
......
......@@ -68,7 +68,6 @@ public:
bool over_text; // true if cursor is over a text object
guint dragging : 2; // dragging selection over text
bool creating; // dragging rubberband to create flowtext
SPCanvasItem *grabbed; // we grab while we are creating, to get events even if the mouse goes out of the window
Geom::Point p0; // initial point if the flowtext rect
......
......@@ -85,6 +85,12 @@ Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const
return _activeUnit;
}
void UnitTracker::changeLabel(Glib::ustring new_label, gint pos)
{
ComboToolItemColumns columns;
_store->children()[pos][columns.col_label] = new_label;
}
void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit)
{
if (unit) {
......
......@@ -50,6 +50,7 @@ public:
void addAdjustment(GtkAdjustment *adj);
void prependUnit(Inkscape::Util::Unit const *u);
void setFullVal(GtkAdjustment *adj, gdouble val);
void changeLabel(Glib::ustring new_label, gint pos);
ComboToolItem *create_tool_item(Glib::ustring const &label,
Glib::ustring const &tooltip);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment