summaryrefslogtreecommitdiffstats
path: root/src/desktop-style.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-03-22 13:56:36 +0000
committertavmjong-free <tavmjong@free.fr>2016-03-22 13:56:36 +0000
commit4cce40a79ab973a3609cd5ee7666673bc2337fef (patch)
treeb2f2ccbc21c94eb5d0d0c5e377473dd4ec04106d /src/desktop-style.cpp
parentReverting 14701. (diff)
downloadinkscape-4cce40a79ab973a3609cd5ee7666673bc2337fef.tar.gz
inkscape-4cce40a79ab973a3609cd5ee7666673bc2337fef.zip
Add line-height unit selector to text toolbar.
Remove 'm' and 'ft' non-CSS lengths. (bzr r14716.1.3)
Diffstat (limited to 'src/desktop-style.cpp')
-rw-r--r--src/desktop-style.cpp96
1 files changed, 74 insertions, 22 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index 7f9670af3..5f6441aa7 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -1036,19 +1036,24 @@ int
objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
+ bool different_lineheight = false;
+ bool different_lineheight_unit = false;
double size = 0;
double letterspacing = 0;
double wordspacing = 0;
- double linespacing = 0;
+ double lineheight = 0;
bool letterspacing_normal = false;
bool wordspacing_normal = false;
- bool linespacing_normal = false;
+ bool lineheight_normal = false;
+ bool lineheight_unit_proportional = false;
+ bool lineheight_unit_absolute = false;
double size_prev = 0;
double letterspacing_prev = 0;
double wordspacing_prev = 0;
- double linespacing_prev = 0;
+ double lineheight_prev = 0;
+ int lineheight_unit_prev = -1;
int texts = 0;
int no_size = 0;
@@ -1093,31 +1098,55 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
wordspacing_normal = false;
}
- double linespacing_current;
+ // If all line spacing units the same, use that (average line spacing).
+ // Else if all line spacings absolute, use 'px' (average line spacing).
+ // Else if all line spacings proportional, use % (average line spacing).
+ // Else use default.
+ double lineheight_current;
+ int lineheight_unit_current;
if (style->line_height.normal) {
- linespacing_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
- if (!different && (linespacing_prev == 0 || linespacing_prev == linespacing_current))
- linespacing_normal = true;
- } else if (style->line_height.unit == SP_CSS_UNIT_PERCENT || style->font_size.computed == 0) {
- linespacing_current = style->line_height.value;
- linespacing_normal = false;
+ lineheight_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ lineheight_unit_current = SP_CSS_UNIT_NONE;
+ if (!different_lineheight &&
+ (lineheight_prev == 0 || lineheight_prev == lineheight_current))
+ lineheight_normal = true;
+ } else if (style->line_height.unit == SP_CSS_UNIT_NONE ||
+ style->line_height.unit == SP_CSS_UNIT_PERCENT ||
+ style->line_height.unit == SP_CSS_UNIT_EM ||
+ style->line_height.unit == SP_CSS_UNIT_EX ||
+ style->font_size.computed == 0) {
+ lineheight_current = style->line_height.value;
+ lineheight_unit_current = style->line_height.unit;
+ lineheight_unit_proportional = true;
+ lineheight_normal = false;
} else {
- linespacing_current = style->line_height.computed;
- linespacing_normal = false;
+ // Always 'px' internally
+ lineheight_current = style->line_height.computed;
+ lineheight_unit_current = style->line_height.unit;
+ lineheight_unit_absolute = true;
+ lineheight_normal = false;
}
- linespacing += linespacing_current;
+ lineheight += lineheight_current;
if ((size_prev != 0 && style->font_size.computed != size_prev) ||
(letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) ||
- (wordspacing_prev != 0 && style->word_spacing.computed != wordspacing_prev) ||
- (linespacing_prev != 0 && linespacing_current != linespacing_prev)) {
+ (wordspacing_prev != 0 && style->word_spacing.computed != wordspacing_prev)) {
different = true;
}
+ if (lineheight_prev != 0 && lineheight_current != lineheight_prev) {
+ different_lineheight = true;
+ }
+
+ if (lineheight_unit_prev != -1 && lineheight_unit_current != lineheight_unit_prev) {
+ different_lineheight_unit = true;
+ }
+
size_prev = style->font_size.computed;
letterspacing_prev = style->letter_spacing.computed;
wordspacing_prev = style->word_spacing.computed;
- linespacing_prev = linespacing_current;
+ lineheight_prev = lineheight_current;
+ lineheight_unit_prev = lineheight_unit_current;
// FIXME: we must detect MULTIPLE_DIFFERENT for these too
style_res->text_anchor.computed = style->text_anchor.computed;
@@ -1133,7 +1162,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
}
letterspacing /= texts;
wordspacing /= texts;
- linespacing /= texts;
+ lineheight /= texts;
}
style_res->font_size.computed = size;
@@ -1145,13 +1174,36 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
style_res->word_spacing.normal = wordspacing_normal;
style_res->word_spacing.computed = wordspacing;
- style_res->line_height.normal = linespacing_normal;
- style_res->line_height.computed = linespacing;
- style_res->line_height.value = linespacing;
- style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
+ style_res->line_height.normal = lineheight_normal;
+ style_res->line_height.computed = lineheight;
+ style_res->line_height.value = lineheight;
+ if (different_lineheight_unit) {
+ if (lineheight_unit_absolute && !lineheight_unit_proportional) {
+ // Mixture of absolute units
+ style_res->line_height.unit = SP_CSS_UNIT_PX;
+ } else {
+ // Mixture of relative units
+ style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
+ }
+ if (lineheight_unit_absolute && lineheight_unit_proportional) {
+ // Mixed types of units, fallback to default
+ style_res->line_height.computed = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * 100.0;
+ style_res->line_height.value = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * 100.0;
+ }
+ } else {
+ // Same units.
+ if (lineheight_unit_prev != -1) {
+ style_res->line_height.unit = lineheight_unit_prev;
+ } else {
+ // No text object... use default.
+ style_res->line_height.unit = SP_CSS_UNIT_NONE;
+ style_res->line_height.computed = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ style_res->line_height.value = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ }
+ }
if (texts > 1) {
- if (different) {
+ if (different || different_lineheight) {
return QUERY_STYLE_MULTIPLE_AVERAGED;
} else {
return QUERY_STYLE_MULTIPLE_SAME;