From a3f684fa5156f66fdcd3d15cc469d84258807201 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 7 Mar 2016 22:10:20 +0100 Subject: Add GUI for 'paint-order' property. (bzr r14693) --- src/desktop-style.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 10 deletions(-) (limited to 'src/desktop-style.cpp') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index a81cbdd1f..c36bcee44 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -881,8 +881,7 @@ objects_query_strokecap (const std::vector &objects, SPStyle *style_res return QUERY_STYLE_NOTHING; } - int cap = -1; - gdouble prev_cap = -1; + int prev_cap = -1; bool same_cap = true; int n_stroked = 0; @@ -905,11 +904,9 @@ objects_query_strokecap (const std::vector &objects, SPStyle *style_res if (prev_cap != -1 && style->stroke_linecap.value != prev_cap) same_cap = false; prev_cap = style->stroke_linecap.value; - - cap = style->stroke_linecap.value; } - style_res->stroke_linecap.value = cap; + style_res->stroke_linecap.value = prev_cap; style_res->stroke_linecap.set = true; if (n_stroked == 0) { @@ -935,8 +932,7 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re return QUERY_STYLE_NOTHING; } - int join = -1; - gdouble prev_join = -1; + int prev_join = -1; bool same_join = true; int n_stroked = 0; @@ -960,11 +956,9 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re same_join = false; } prev_join = style->stroke_linejoin.value; - - join = style->stroke_linejoin.value; } - style_res->stroke_linejoin.value = join; + style_res->stroke_linejoin.value = prev_join; style_res->stroke_linejoin.set = true; if (n_stroked == 0) { @@ -979,6 +973,62 @@ objects_query_strokejoin (const std::vector &objects, SPStyle *style_re } } +/** + * Write to style_res the paint order of a list of objects. + */ +int +objects_query_paintorder (const std::vector &objects, SPStyle *style_res) +{ + if (objects.empty()) { + /* No objects, set empty */ + return QUERY_STYLE_NOTHING; + } + + std::string prev_order; + bool same_order = true; + int n_order = 0; + + for (std::vector::const_iterator i = objects.begin(); i != objects.end(); ++i) { + SPObject *obj = *i; + if (!dynamic_cast(obj)) { + continue; + } + SPStyle *style = obj->style; + if (!style) { + continue; + } + + if ( style->stroke.isNone() ) { + continue; + } + + n_order ++; + + if (!prev_order.empty() && prev_order.compare( style->paint_order.value ) != 0) { + same_order = false; + } + if (style->paint_order.set) { + prev_order = style->paint_order.value; + } + } + + + g_free( style_res->paint_order.value ); + style_res->paint_order.value= g_strdup( prev_order.c_str() ); + style_res->paint_order.set = true; + + if (n_order == 0) { + return QUERY_STYLE_NOTHING; + } else if (n_order == 1) { + return QUERY_STYLE_SINGLE; + } else { + if (same_order) + return QUERY_STYLE_MULTIPLE_SAME; + else + return QUERY_STYLE_MULTIPLE_DIFFERENT; + } +} + /** * Write to style_res the average font size and spacing of objects. */ @@ -1763,6 +1813,8 @@ sp_desktop_query_style_from_list (const std::vector &list, SPStyle *sty } else if (property == QUERY_STYLE_PROPERTY_STROKEJOIN) { return objects_query_strokejoin (list, style); + } else if (property == QUERY_STYLE_PROPERTY_PAINTORDER) { + return objects_query_paintorder (list, style); } else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) { return objects_query_opacity (list, style); @@ -1829,6 +1881,9 @@ sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query) int result_strokemiterlimit = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT); int result_strokecap = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKECAP); int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN); + + int result_paintorder = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_PAINTORDER); + int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY); int result_blur = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR); @@ -1842,6 +1897,7 @@ sp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query) result_strokemiterlimit != QUERY_STYLE_NOTHING || result_strokecap != QUERY_STYLE_NOTHING || result_strokejoin != QUERY_STYLE_NOTHING || + result_paintorder != QUERY_STYLE_NOTHING || result_blur != QUERY_STYLE_NOTHING); } -- cgit v1.2.3 From 1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 12 Mar 2016 18:50:04 -0500 Subject: Add a units box to line height and wire in the style units, plus some cleanup (bzr r14701) --- src/desktop-style.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/desktop-style.cpp') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index c36bcee44..c28302d22 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1049,6 +1049,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r double letterspacing_prev = 0; double wordspacing_prev = 0; double linespacing_prev = 0; + int linespacing_unit = 0; int texts = 0; int no_size = 0; @@ -1105,6 +1106,11 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r linespacing_current = style->line_height.computed; linespacing_normal = false; } + if (linespacing_unit == 0) { + linespacing_unit = style->line_height.unit; + } else if (linespacing_unit != style->line_height.unit) { + linespacing_unit = SP_CSS_UNIT_PERCENT; + } linespacing += linespacing_current; if ((size_prev != 0 && style->font_size.computed != size_prev) || @@ -1148,7 +1154,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r 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.unit = linespacing_unit; if (texts > 1) { if (different) { -- cgit v1.2.3 From c1a9b9773542b5a5de771a06a20834f38bb2da90 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 15 Mar 2016 22:38:20 +0100 Subject: fix-bug-1557192. paint-order crash with multiple items Fixed bugs: - https://launchpad.net/bugs/1557192 (bzr r14708) --- src/desktop-style.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/desktop-style.cpp') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index c28302d22..d10c75cd8 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1004,10 +1004,10 @@ objects_query_paintorder (const std::vector &objects, SPStyle *style_re n_order ++; - if (!prev_order.empty() && prev_order.compare( style->paint_order.value ) != 0) { - same_order = false; - } if (style->paint_order.set) { + if (!prev_order.empty() && prev_order.compare( style->paint_order.value ) != 0) { + same_order = false; + } prev_order = style->paint_order.value; } } -- cgit v1.2.3 From a714c688d60a3a62114591984f57f26cd41dbed9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 18 Mar 2016 11:23:29 +0100 Subject: Reverting 14701. (bzr r14716.1.2) --- src/desktop-style.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/desktop-style.cpp') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index d10c75cd8..7f9670af3 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1049,7 +1049,6 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r double letterspacing_prev = 0; double wordspacing_prev = 0; double linespacing_prev = 0; - int linespacing_unit = 0; int texts = 0; int no_size = 0; @@ -1106,11 +1105,6 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r linespacing_current = style->line_height.computed; linespacing_normal = false; } - if (linespacing_unit == 0) { - linespacing_unit = style->line_height.unit; - } else if (linespacing_unit != style->line_height.unit) { - linespacing_unit = SP_CSS_UNIT_PERCENT; - } linespacing += linespacing_current; if ((size_prev != 0 && style->font_size.computed != size_prev) || @@ -1154,7 +1148,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r style_res->line_height.normal = linespacing_normal; style_res->line_height.computed = linespacing; style_res->line_height.value = linespacing; - style_res->line_height.unit = linespacing_unit; + style_res->line_height.unit = SP_CSS_UNIT_PERCENT; if (texts > 1) { if (different) { -- cgit v1.2.3 From 4cce40a79ab973a3609cd5ee7666673bc2337fef Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 22 Mar 2016 14:56:36 +0100 Subject: Add line-height unit selector to text toolbar. Remove 'm' and 'ft' non-CSS lengths. (bzr r14716.1.3) --- src/desktop-style.cpp | 96 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 22 deletions(-) (limited to 'src/desktop-style.cpp') 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 &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 &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 &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 &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; -- cgit v1.2.3 From a18efaedfcc01ec5bd1b9c60ca55b8be4445c5cb Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 30 Mar 2016 19:26:19 +0200 Subject: Partial fix for bug 156221 ('line-height' with non-pixel scaled drawing). (bzr r14752) --- src/desktop-style.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/desktop-style.cpp') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 5f6441aa7..7f9b46c7d 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1073,7 +1073,12 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r texts ++; SPItem *item = dynamic_cast(obj); g_assert(item != NULL); - double dummy = style->font_size.computed * Geom::Affine(item->i2dt_affine()).descrim(); + + // Quick way of getting document scale. Should be same as: + // item->document->getDocumentScale().Affine().descrim() + double doc_scale = Geom::Affine(item->i2dt_affine()).descrim(); + + double dummy = style->font_size.computed * doc_scale; if (!IS_NAN(dummy)) { size += dummy; /// \todo FIXME: we assume non-% units here } else { @@ -1085,7 +1090,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r letterspacing_normal = true; } } else { - letterspacing += style->letter_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here + letterspacing += style->letter_spacing.computed * doc_scale;; /// \todo FIXME: we assume non-% units here letterspacing_normal = false; } @@ -1094,7 +1099,7 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r wordspacing_normal = true; } } else { - wordspacing += style->word_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here + wordspacing += style->word_spacing.computed * doc_scale; /// \todo FIXME: we assume non-% units here wordspacing_normal = false; } @@ -1119,14 +1124,15 @@ objects_query_fontnumbers (const std::vector &objects, SPStyle *style_r lineheight_unit_current = style->line_height.unit; lineheight_unit_proportional = true; lineheight_normal = false; + lineheight += lineheight_current; } else { // Always 'px' internally lineheight_current = style->line_height.computed; lineheight_unit_current = style->line_height.unit; lineheight_unit_absolute = true; lineheight_normal = false; + lineheight += lineheight_current * doc_scale; } - lineheight += lineheight_current; if ((size_prev != 0 && style->font_size.computed != size_prev) || (letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) || -- cgit v1.2.3