summaryrefslogtreecommitdiffstats
path: root/src/widgets/text-toolbar.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-05-08 07:40:39 +0000
committerjabiertxof <info@marker.es>2016-05-08 07:40:39 +0000
commitd9c43e3d6f19a2f1102743b61d999b477bba4b9a (patch)
treee77ac36155e0813318be3b9e7641338d86dac733 /src/widgets/text-toolbar.cpp
parentFixing page transforms (diff)
parentfix-bug-734201. stroke-to-path doesn't scale stroke width used in markers (diff)
downloadinkscape-d9c43e3d6f19a2f1102743b61d999b477bba4b9a.tar.gz
inkscape-d9c43e3d6f19a2f1102743b61d999b477bba4b9a.zip
update to trunk
(bzr r13682.1.40)
Diffstat (limited to '')
-rw-r--r--src/widgets/text-toolbar.cpp107
1 files changed, 72 insertions, 35 deletions
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 8df80d2b6..23acb74af 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -508,6 +508,10 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
+static bool is_relative( Unit const *unit ) {
+ return (unit->abbr == "" || unit->abbr == "em" || unit->abbr == "ex" || unit->abbr == "%");
+}
+
static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
{
// quit if run by the _changed callbacks
@@ -524,21 +528,22 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit so
- // we can save it (allows us to adjust line height value when unit changes).
- SPILength temp_length;
- Inkscape::CSSOStringStream temp_stream;
- temp_stream << 1 << unit->abbr;
- temp_length.read(temp_stream.str().c_str());
- prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit);
- g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
-
+ // Only save if not relative unit
+ if ( !is_relative(unit) ) {
+ // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit so
+ // we can save it (allows us to adjust line height value when unit changes).
+ SPILength temp_length;
+ Inkscape::CSSOStringStream temp_stream;
+ temp_stream << 1 << unit->abbr;
+ temp_length.read(temp_stream.str().c_str());
+ prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit);
+ g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
+ }
// Set css line height.
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- // We should handle unitless values as well as 'em' and 'ex'
- if ((unit->abbr) == "em" || unit->abbr == "ex" || unit->abbr == "%") {
+ if ( is_relative(unit) ) {
osfs << gtk_adjustment_get_value(adj) << unit->abbr;
} else {
// Inside SVG file, always use "px" for absolute units.
@@ -601,13 +606,16 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
g_return_if_fail(unit != NULL);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit.
- SPILength temp_length;
- Inkscape::CSSOStringStream temp_stream;
- temp_stream << 1 << unit->abbr;
- temp_length.read(temp_stream.str().c_str());
- prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit);
- g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
+ // Only save if not relative unit
+ if ( !is_relative(unit) ) {
+ // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit.
+ SPILength temp_length;
+ Inkscape::CSSOStringStream temp_stream;
+ temp_stream << 1 << unit->abbr;
+ temp_length.read(temp_stream.str().c_str());
+ prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit);
+ g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
+ }
// Read current line height value
EgeAdjustmentAction *line_height_act =
@@ -620,25 +628,26 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
std::vector<SPItem*> itemlist=selection->itemList();
// Convert between units
- if ((unit->abbr) == "em" && old_unit == SP_CSS_UNIT_EX) {
+ if ((unit->abbr == "" || unit->abbr == "em") && old_unit == SP_CSS_UNIT_EX) {
line_height *= 0.5;
- } else if ((unit->abbr) == "ex" && old_unit == SP_CSS_UNIT_EM) {
+ } else if ((unit->abbr) == "ex" && (old_unit == SP_CSS_UNIT_EM || old_unit == SP_CSS_UNIT_NONE) ) {
line_height *= 2.0;
- } else if ((unit->abbr) == "em" && old_unit == SP_CSS_UNIT_PERCENT) {
+ } else if ((unit->abbr == "" || unit->abbr == "em") && old_unit == SP_CSS_UNIT_PERCENT) {
line_height /= 100.0;
- } else if ((unit->abbr) == "%" && old_unit == SP_CSS_UNIT_EM) {
+ } else if ((unit->abbr) == "%" && (old_unit == SP_CSS_UNIT_EM || old_unit == SP_CSS_UNIT_NONE) ) {
line_height *= 100;
} else if ((unit->abbr) == "ex" && old_unit == SP_CSS_UNIT_PERCENT) {
line_height /= 50.0;
} else if ((unit->abbr) == "%" && old_unit == SP_CSS_UNIT_EX) {
line_height *= 50;
- } else if ((unit->abbr) == "%" || (unit->abbr) == "em" || (unit->abbr) == "ex") {
+ } else if (is_relative(unit)) {
// Convert absolute to relative... for the moment use average font-size
double font_size = 0;
int count = 0;
for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
if (SP_IS_TEXT (*i)) {
- font_size += (*i)->style->font_size.computed;
+ double doc_scale = Geom::Affine((*i)->i2dt_affine()).descrim();
+ font_size += (*i)->style->font_size.computed * doc_scale;
++count;
}
}
@@ -647,7 +656,10 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
} else {
font_size = 20;
}
+
+ if (old_unit == SP_CSS_UNIT_NONE) old_unit = SP_CSS_UNIT_EM;
line_height = Quantity::convert(line_height, sp_style_get_css_unit_string(old_unit), "px");
+
if (font_size > 0) {
line_height /= font_size;
}
@@ -656,13 +668,15 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
} else if ((unit->abbr) == "ex") {
line_height *= 2;
}
- } else if (old_unit==SP_CSS_UNIT_PERCENT || old_unit==SP_CSS_UNIT_EM || old_unit==SP_CSS_UNIT_EX) {
+ } else if (old_unit==SP_CSS_UNIT_NONE || old_unit==SP_CSS_UNIT_PERCENT ||
+ old_unit==SP_CSS_UNIT_EM || old_unit==SP_CSS_UNIT_EX) {
// Convert relative to absolute... for the moment use average font-size
double font_size = 0;
int count = 0;
for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
if (SP_IS_TEXT (*i)) {
- font_size += (*i)->style->font_size.computed;
+ double doc_scale = Geom::Affine((*i)->i2dt_affine()).descrim();
+ font_size += (*i)->style->font_size.computed * doc_scale;
++count;
}
}
@@ -671,12 +685,13 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
} else {
font_size = 20;
}
- line_height *= font_size;
+
if (old_unit == SP_CSS_UNIT_PERCENT) {
line_height /= 100.0;
} else if (old_unit == SP_CSS_UNIT_EX) {
line_height /= 2.0;
}
+ line_height *= font_size;
line_height = Quantity::convert(line_height, "px", unit);
} else {
// Convert between different absolute units (only used in GUI)
@@ -686,8 +701,7 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
// Set css line height.
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- // We should handle unitless values as well as 'em' and 'ex'
- if ((unit->abbr) == "em" || unit->abbr == "ex" || unit->abbr == "%") {
+ if ( is_relative(unit) ) {
osfs << line_height << unit->abbr;
} else {
osfs << Quantity::convert(line_height, unit, "px") << "px";
@@ -1252,7 +1266,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
double height;
int line_height_unit = -1;
if (query.line_height.normal) {
- std::cout << " normal" << std::endl;
height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
line_height_unit = SP_CSS_UNIT_NONE;
} else {
@@ -1262,8 +1275,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
switch (line_height_unit) {
case SP_CSS_UNIT_NONE:
- // tracker can't show no unit... use 'em'
- line_height_unit = SP_CSS_UNIT_EM;
case SP_CSS_UNIT_EM:
case SP_CSS_UNIT_EX:
break;
@@ -1274,7 +1285,9 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// If unit is set to 'px', use the preferred display unit (if absolute).
line_height_unit =
prefs->getInt("/tools/text/lineheight/display_unit", SP_CSS_UNIT_PT);
- if (line_height_unit != SP_CSS_UNIT_EM &&
+ // But not if prefered unit is relative
+ if (line_height_unit != SP_CSS_UNIT_NONE &&
+ line_height_unit != SP_CSS_UNIT_EM &&
line_height_unit != SP_CSS_UNIT_EX &&
line_height_unit != SP_CSS_UNIT_PERCENT) {
height =
@@ -1297,7 +1310,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
gtk_adjustment_set_value( lineHeightAdjustment, height );
UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
- tracker->setActiveUnitByAbbr(sp_style_get_css_unit_string(line_height_unit));
+ if( line_height_unit == SP_CSS_UNIT_NONE ) {
+ // Function 'sp_style_get_css_unit_string' returns 'px' for unit none.
+ // We need to avoid this.
+ tracker->setActiveUnitByAbbr("");
+ } else {
+ tracker->setActiveUnitByAbbr(sp_style_get_css_unit_string(line_height_unit));
+ }
// Save unit so we can do convertions between new/old units.
g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(line_height_unit));
@@ -1543,6 +1562,23 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
g_object_set_data( holder, "TextFontFamilyAction", act );
// Change style of drop-down from menu to list
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkCssProvider *css_provider = gtk_css_provider_new();
+ gtk_css_provider_load_from_data(css_provider,
+ "#TextFontFamilyAction_combobox {\n"
+ " -GtkComboBox-appears-as-list: true;\n"
+ "}\n"
+ "combobox window.popup scrolledwindow treeview separator {\n"
+ " -GtkWidget-wide-separators: true;\n"
+ " -GtkWidget-separator-height: 6;\n"
+ "}\n",
+ -1, NULL);
+
+ GdkScreen *screen = gdk_screen_get_default();
+ gtk_style_context_add_provider_for_screen(screen,
+ GTK_STYLE_PROVIDER(css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_USER);
+#else
gtk_rc_parse_string (
"style \"dropdown-as-list-style\"\n"
"{\n"
@@ -1555,6 +1591,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
" GtkWidget::separator-height = 6\n"
"}\n"
"widget \"*gtk-combobox-popup-window.GtkScrolledWindow.GtkTreeView\" style \"fontfamily-separator-style\"");
+#endif
}
/* Font size */
@@ -1795,10 +1832,10 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
/* Line height unit tracker */
UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ tracker->prependUnit(unit_table.getUnit("")); // No unit
tracker->addUnit(unit_table.getUnit("%"));
tracker->addUnit(unit_table.getUnit("em"));
tracker->addUnit(unit_table.getUnit("ex"));
- // tracker->addUnit(unit_table.getUnit("None"));
tracker->setActiveUnit(unit_table.getUnit("%"));
g_object_set_data( holder, "tracker", tracker );