summaryrefslogtreecommitdiffstats
path: root/src/desktop-style.cpp
diff options
context:
space:
mode:
authorRichard White <rwhite8282@gmail.com>2016-05-19 01:17:29 +0000
committerRichard White <rwhite8282@gmail.com>2016-05-19 01:17:29 +0000
commit1fe9c2603c33fddcd9f2688b30e843f91e1a86fa (patch)
tree13289cbe033a46a40eb829437e115b5393e2ca84 /src/desktop-style.cpp
parentCorrected frame extension stroke and fill values on 64 bit machine. (diff)
parentGTK3: Another widget named. (diff)
downloadinkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.tar.gz
inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.zip
Merge from Inkscape trunk.
(bzr r14668.1.3)
Diffstat (limited to 'src/desktop-style.cpp')
-rw-r--r--src/desktop-style.cpp184
1 files changed, 149 insertions, 35 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index a81cbdd1f..7f9b46c7d 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -881,8 +881,7 @@ objects_query_strokecap (const std::vector<SPItem*> &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<SPItem*> &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<SPItem*> &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<SPItem*> &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) {
@@ -980,25 +974,86 @@ objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_re
}
/**
+ * Write to style_res the paint order of a list of objects.
+ */
+int
+objects_query_paintorder (const std::vector<SPItem*> &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<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) {
+ SPObject *obj = *i;
+ if (!dynamic_cast<SPItem *>(obj)) {
+ continue;
+ }
+ SPStyle *style = obj->style;
+ if (!style) {
+ continue;
+ }
+
+ if ( style->stroke.isNone() ) {
+ continue;
+ }
+
+ n_order ++;
+
+ 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;
+ }
+ }
+
+
+ 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.
*/
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;
@@ -1018,7 +1073,12 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
texts ++;
SPItem *item = dynamic_cast<SPItem *>(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 {
@@ -1030,7 +1090,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &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;
}
@@ -1039,35 +1099,60 @@ objects_query_fontnumbers (const std::vector<SPItem*> &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;
}
- 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;
+ lineheight += lineheight_current;
} 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;
+ lineheight += lineheight_current * doc_scale;
}
- linespacing += linespacing_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;
@@ -1083,7 +1168,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;
@@ -1095,13 +1180,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;
@@ -1763,6 +1871,8 @@ sp_desktop_query_style_from_list (const std::vector<SPItem*> &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 +1939,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 +1955,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);
}