desktop-style.cpp revision f8663560deb57dfd332026dbc1f25ae8b9904863
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#define __SP_DESKTOP_STYLE_C__
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/** \file
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Desktop style management
c533a883a71cff9ff32df1c53c31201e1cbf371fhx *
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Authors:
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * bulia byak
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * verbalshadow
c533a883a71cff9ff32df1c53c31201e1cbf371fhx *
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Copyright (C) 2004, 2006 authors
c533a883a71cff9ff32df1c53c31201e1cbf371fhx *
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Released under GNU GPL, read the file 'COPYING' for more information
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include <string>
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include <cstring>
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "desktop.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "color-rgba.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "svg/css-ostringstream.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "svg/svg.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "svg/svg-color.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "selection.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "inkscape.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "style.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "preferences.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-use.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "filters/blend.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-filter.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-filter-reference.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-gaussian-blur.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-flowtext.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-flowregion.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-flowdiv.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-linear-gradient.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-pattern.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-radial-gradient.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-textpath.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-tref.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-tspan.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "xml/repr.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "libnrtype/font-style-to-pos.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "sp-path.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "desktop-style.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "svg/svg-icc-color.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx#include "box3d-side.h"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Set color on selection on desktop.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxvoid
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_set_color(SPDesktop *desktop, ColorRGBA const &color, bool is_relative, bool fill)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /// \todo relative color setting
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (is_relative) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx g_warning("FIXME: relative color setting not yet implemented");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx guint32 rgba = SP_RGBA32_F_COMPOSE(color[0], color[1], color[2], color[3]);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gchar b[64];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_svg_write_color(b, sizeof(b), rgba);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css = sp_repr_css_attr_new();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (fill) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set_property(css, "fill", b);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::CSSOStringStream osalpha;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx osalpha << color[3];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set_property(css, "fill-opacity", osalpha.str().c_str());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set_property(css, "stroke", b);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::CSSOStringStream osalpha;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx osalpha << color[3];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set_property(css, "stroke-opacity", osalpha.str().c_str());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_desktop_set_style(desktop, css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css);
43439c96b8398c01c375889c79bed72d78fb4c39hx}
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Apply style on object and children, recursively.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxvoid
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_apply_css_recursive(SPObject *o, SPCSSAttr *css, bool skip_lines)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // non-items should not have style
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_ITEM(o))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // 1. tspans with role=line are not regular objects in that they are not supposed to have style of their own,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // but must always inherit from the parent text. Same for textPath.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // However, if the line tspan or textPath contains some style (old file?), we reluctantly set our style to it too.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // 2. Generally we allow setting style on clones, but when it's inside flowRegion, do not touch
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // it, be it clone or not; it's just styleless shape (because that's how Inkscape does
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // flowtext).
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!(skip_lines
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && ((SP_IS_TSPAN(o) && SP_TSPAN(o)->role == SP_TSPAN_ROLE_LINE)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx || SP_IS_FLOWDIV(o)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx || SP_IS_FLOWPARA(o)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx || SP_IS_TEXTPATH(o))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_OBJECT_REPR(o)->attribute("style"))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx !(SP_IS_FLOWREGION(o) ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SP_IS_FLOWREGIONEXCLUDE(o) ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx (SP_IS_USE(o) &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SP_OBJECT_PARENT(o) &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx (SP_IS_FLOWREGION(SP_OBJECT_PARENT(o)) ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SP_IS_FLOWREGIONEXCLUDE(SP_OBJECT_PARENT(o))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx )
c533a883a71cff9ff32df1c53c31201e1cbf371fhx )
c533a883a71cff9ff32df1c53c31201e1cbf371fhx )
c533a883a71cff9ff32df1c53c31201e1cbf371fhx ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css_set = sp_repr_css_attr_new();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_merge(css_set, css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // Scale the style by the inverse of the accumulated parent transform in the paste context.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Geom::Matrix const local(sp_item_i2doc_affine(SP_ITEM(o)));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx double const ex(local.descrim());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( ( ex != 0. )
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && ( ex != 1. ) ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_css_attr_scale(css_set, 1/ex);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_change(SP_OBJECT_REPR(o), css_set, "style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css_set);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // setting style on child of clone spills into the clone original (via shared repr), don't do it!
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (SP_IS_USE(o))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (SPObject *child = sp_object_first_child(SP_OBJECT(o)) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (sp_repr_css_property(css, "opacity", NULL) != NULL) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // Unset properties which are accumulating and thus should not be set recursively.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // For example, setting opacity 0.5 on a group recursively would result in the visible opacity of 0.25 for an item in the group.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css_recurse = sp_repr_css_attr_new();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_merge(css_recurse, css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set_property(css_recurse, "opacity", NULL);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_desktop_apply_css_recursive(child, css_recurse, skip_lines);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css_recurse);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_desktop_apply_css_recursive(child, css, skip_lines);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Apply style on selection on desktop.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxvoid
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write_current)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (write_current) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // 1. Set internal value
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_merge(desktop->current, css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // 1a. Write to prefs; make a copy and unset any URIs first
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css_write = sp_repr_css_attr_new();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_merge(css_write, css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_css_attr_unset_uris(css_write);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prefs->mergeStyle("/desktop/style", css_write);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* last used styles for 3D box faces are stored separately */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (SP_IS_BOX3D_SIDE (i->data)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx const char * descr = box3d_side_axes_string(SP_BOX3D_SIDE(i->data));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (descr != NULL) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prefs->mergeStyle(Glib::ustring("/desktop/") + descr + "/style", css_write);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css_write);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!change)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx// 2. Emit signal
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool intercepted = desktop->_set_style_signal.emit(css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/** \todo
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * FIXME: in set_style, compensate pattern and gradient fills, stroke width,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * rect corners, font size for the object's own transform so that pasting
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * fills does not depend on preserve/optimize.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx// 3. If nobody has intercepted the signal, apply the style to the selection
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!intercepted) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /// \todo if the style is text-only, apply only to texts?
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_desktop_apply_css_recursive(SP_OBJECT(i->data), css, true);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Return the desktop's current style.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxSPCSSAttr *
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_get_style(SPDesktop *desktop, bool with_text)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css = sp_repr_css_attr_new();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_merge(css, desktop->current);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!css->attributeList()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!with_text) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx css = sp_css_attr_unset_text(css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return css;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China/**
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China * Return the desktop's current color.
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China */
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing Chinaguint32
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing Chinasp_desktop_get_color(SPDesktop *desktop, bool is_fill)
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China{
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China guint32 r = 0; // if there's no color, return black
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gchar const *property = sp_repr_css_property(desktop->current,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx is_fill ? "fill" : "stroke",
c533a883a71cff9ff32df1c53c31201e1cbf371fhx "#000");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (desktop->current && property) { // if there is style and the property in it,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (strncmp(property, "url", 3)) { // and if it's not url,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // read it
c533a883a71cff9ff32df1c53c31201e1cbf371fhx r = sp_svg_read_color(property, r);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return r;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhxdouble
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_get_master_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool *has_opacity)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gfloat value = 1.0; // default if nothing else found
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (has_opacity)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx *has_opacity = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prefs->getBool(tool + "/usecurrent")) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx css = sp_desktop_get_style(desktop, true);
43439c96b8398c01c375889c79bed72d78fb4c39hx } else {
43439c96b8398c01c375889c79bed72d78fb4c39hx css = prefs->getStyle(tool + "/style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (css) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gchar const *property = css ? sp_repr_css_property(css, "opacity", "1.000") : 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (desktop->current && property) { // if there is style and the property in it,
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( !sp_svg_number_read_f(property, &value) ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx value = 1.0; // things failed. set back to the default
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (has_opacity)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx *has_opacity = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhxdouble
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing Chinasp_desktop_get_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gfloat value = 1.0; // default if nothing else found
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prefs->getBool(tool + "/usecurrent")) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx css = sp_desktop_get_style(desktop, true);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx css = prefs->getStyle(tool + "/style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (css) {
43439c96b8398c01c375889c79bed72d78fb4c39hx gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
43439c96b8398c01c375889c79bed72d78fb4c39hx
43439c96b8398c01c375889c79bed72d78fb4c39hx if (desktop->current && property) { // if there is style and the property in it,
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if ( !sp_svg_number_read_f(property, &value) ) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China value = 1.0; // things failed. set back to the default
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China sp_repr_css_attr_unref(css);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return value;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China}
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing Chinaguint32
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing Chinasp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill, bool *has_color)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China{
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China Inkscape::Preferences *prefs = Inkscape::Preferences::get();
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China SPCSSAttr *css = NULL;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China guint32 r = 0; // if there's no color, return black
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (has_color)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China *has_color = false;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (prefs->getBool(tool + "/usecurrent")) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China css = sp_desktop_get_style(desktop, true);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China } else {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China css = prefs->getStyle(tool + "/style");
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (css) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China gchar const *property = sp_repr_css_property(css, is_fill ? "fill" : "stroke", "#000");
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China if (desktop->current && property) { // if there is style and the property in it,
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (strncmp(property, "url", 3) && strncmp(property, "none", 4)) { // and if it's not url or none,
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China // read it
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China r = sp_svg_read_color(property, r);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (has_color)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China *has_color = true;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_attr_unref(css);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return r | 0xff;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Apply the desktop's current style or the tool style to repr.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing Chinavoid
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool_path, bool with_text)
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan{
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan SPCSSAttr *css_current = sp_desktop_get_style(desktop, with_text);
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan Inkscape::Preferences *prefs = Inkscape::Preferences::get();
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer if (prefs->getBool(tool_path + "/usecurrent") && css_current) {
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer sp_repr_css_set(repr, css_current, "style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPCSSAttr *css = prefs->getStyle(tool_path + "/style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_repr_css_set(repr, css, "style");
f3c4902c7f91725a7b538a3d82f1993bff02944fpengcheng chen - Sun Microsystems - Beijing China sp_repr_css_attr_unref(css);
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China }
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China if (css_current) {
6f12def440a1ce798ab128210a43414d173669f0pengcheng chen - Sun Microsystems - Beijing China sp_repr_css_attr_unref(css_current);
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China }
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China}
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Returns the font size (in SVG pixels) of the text tool style (if text
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * tool uses its own style) or desktop style (otherwise).
c533a883a71cff9ff32df1c53c31201e1cbf371fhx*/
c533a883a71cff9ff32df1c53c31201e1cbf371fhxdouble
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_get_font_size_tool(SPDesktop *desktop)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx (void)desktop; // TODO cleanup
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Glib::ustring desktop_style = prefs->getString("/desktop/style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Glib::ustring style_str;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ((prefs->getBool("/tools/text/usecurrent")) && !desktop_style.empty()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_str = desktop_style;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_str = prefs->getString("/tools/text/style");
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx double ret = 12;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style_str.empty()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_style_merge_from_style_string(style, style_str.data());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx ret = style->font_size.computed;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China sp_style_unref(style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return ret;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/** Determine average stroke width, simple method */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx// see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually
c533a883a71cff9ff32df1c53c31201e1cbf371fhxgdouble
c533a883a71cff9ff32df1c53c31201e1cbf371fhxstroke_average_width (GSList const *objects)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length ((GSList *) objects) == 0)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return NR_HUGE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble avgwidth = 0.0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool notstroked = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int n_notstroked = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *l = objects; l != NULL; l = l->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_ITEM (l->data))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(l->data));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *object = SP_OBJECT(l->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( object->style->stroke.isNone() ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx ++n_notstroked; // do not count nonstroked objects
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx notstroked = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx avgwidth += SP_OBJECT_STYLE (object)->stroke_width.computed * i2d.descrim();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (notstroked)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return NR_HUGE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return avgwidth / (g_slist_length ((GSList *) objects) - n_notstroked);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average fill or stroke of list of objects, if applicable.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPIPaint *paint_res = isfill? &style_res->fill : &style_res->stroke;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool paintImpossible = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint_res->set = TRUE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SVGICCColor* iccColor = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool iccSeen = false;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer gfloat c[4];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c[0] = c[1] = c[2] = c[3] = 0.0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gint num = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gfloat prev[3];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev[0] = prev[1] = prev[2] = 0.0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_color = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer for (GSList const *i = objects; i != NULL; i = i->next) {
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan SPObject *obj = SP_OBJECT (i->data);
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan SPStyle *style = SP_OBJECT_STYLE (obj);
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan if (!style) continue;
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan SPIPaint *paint = isfill? &style->fill : &style->stroke;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer // We consider paint "effectively set" for anything within text hierarchy
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *parent = SP_OBJECT_PARENT (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool paint_effectively_set =
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint->set || (SP_IS_TEXT(parent) || SP_IS_TEXTPATH(parent) || SP_IS_TSPAN(parent)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx || SP_IS_FLOWTEXT(parent) || SP_IS_FLOWDIV(parent) || SP_IS_FLOWPARA(parent)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx || SP_IS_FLOWTSPAN(parent) || SP_IS_FLOWLINE(parent));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // 1. Bail out with QUERY_STYLE_MULTIPLE_DIFFERENT if necessary
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ((!paintImpossible) && (!paint->isSameType(*paint_res) || (paint_res->set != paint_effectively_set))) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT; // different types of paint
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (paint_res->set && paint->set && paint_res->isPaintserver()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // both previous paint and this paint were a server, see if the servers are compatible
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPPaintServer *server_res = isfill? SP_STYLE_FILL_SERVER (style_res) : SP_STYLE_STROKE_SERVER (style_res);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER (style) : SP_STYLE_STROKE_SERVER (style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (SP_IS_LINEARGRADIENT (server_res)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_LINEARGRADIENT(server))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE );
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE );
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (vector_res != vector)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (SP_IS_RADIALGRADIENT (server_res)) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (!SP_IS_RADIALGRADIENT(server))
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
d62cb7fff63265824a8e6725a3bcef698f6134c9hx SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE );
d62cb7fff63265824a8e6725a3bcef698f6134c9hx SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE );
d62cb7fff63265824a8e6725a3bcef698f6134c9hx if (vector_res != vector)
d62cb7fff63265824a8e6725a3bcef698f6134c9hx return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
d62cb7fff63265824a8e6725a3bcef698f6134c9hx
d62cb7fff63265824a8e6725a3bcef698f6134c9hx } else if (SP_IS_PATTERN (server_res)) {
d62cb7fff63265824a8e6725a3bcef698f6134c9hx
09539a3c2da6fef054f5306232ef0480de261eabpengcheng chen - Sun Microsystems - Beijing China if (!SP_IS_PATTERN(server))
09539a3c2da6fef054f5306232ef0480de261eabpengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
09539a3c2da6fef054f5306232ef0480de261eabpengcheng chen - Sun Microsystems - Beijing China
09539a3c2da6fef054f5306232ef0480de261eabpengcheng chen - Sun Microsystems - Beijing China SPPattern *pat = pattern_getroot (SP_PATTERN (server));
09539a3c2da6fef054f5306232ef0480de261eabpengcheng chen - Sun Microsystems - Beijing China SPPattern *pat_res = pattern_getroot (SP_PATTERN (server_res));
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China if (pat_res != pat)
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China }
d62cb7fff63265824a8e6725a3bcef698f6134c9hx }
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China
d62cb7fff63265824a8e6725a3bcef698f6134c9hx // 2. Sum color, copy server from paint to paint_res
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China
d62cb7fff63265824a8e6725a3bcef698f6134c9hx if (paint_res->set && paint_effectively_set && paint->isColor()) {
d62cb7fff63265824a8e6725a3bcef698f6134c9hx gfloat d[3];
d62cb7fff63265824a8e6725a3bcef698f6134c9hx sp_color_get_rgb_floatv (&paint->value.color, d);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // Check if this color is the same as previous
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (paintImpossible) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev[0] = d[0];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev[1] = d[1];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev[2] = d[2];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint_res->setColor(d[0], d[1], d[2]);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx iccColor = paint->value.color.icc;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx iccSeen = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (same_color && (prev[0] != d[0] || prev[1] != d[1] || prev[2] != d[2]))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_color = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( iccSeen ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(paint->value.color.icc) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // TODO fix this
c533a883a71cff9ff32df1c53c31201e1cbf371fhx iccColor = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // average color
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c[0] += d[0];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c[1] += d[1];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c[2] += d[2];
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c[3] += SP_SCALE24_TO_FLOAT (isfill? style->fill_opacity.value : style->stroke_opacity.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx num ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paintImpossible = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint_res->colorSet = paint->colorSet;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint_res->currentcolor = paint->currentcolor;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (paint_res->set && paint_effectively_set && paint->isPaintserver()) { // copy the server
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (isfill) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_style_set_to_uri_string (style_res, true, style->getFillURI());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx sp_style_set_to_uri_string (style_res, false, style->getStrokeURI());
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx paint_res->set = paint_effectively_set;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->fill_rule.computed = style->fill_rule.computed; // no averaging on this, just use the last one
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // After all objects processed, divide the color if necessary and return
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (paint_res->set && paint_res->isColor()) { // set the color
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China g_assert (num >= 1);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China c[0] /= num;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China c[1] /= num;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China c[2] /= num;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China c[3] /= num;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China paint_res->setColor(c[0], c[1], c[2]);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (isfill) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China style_res->fill_opacity.value = SP_SCALE24_FROM_FLOAT (c[3]);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China } else {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China style_res->stroke_opacity.value = SP_SCALE24_FROM_FLOAT (c[3]);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if ( iccSeen && iccColor ) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China // TODO check for existing
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China SVGICCColor* tmp = new SVGICCColor(*iccColor);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China paint_res->value.color.icc = tmp;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (num > 1) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (same_color)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China else
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_AVERAGED;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_SINGLE;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China // Not color
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (g_slist_length(objects) > 1) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China } else {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_SINGLE;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China}
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China/**
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China * Write to style_res the average opacity of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_opacity (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble opacity_sum = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble opacity_prev = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_opacity = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx guint opacity_items = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China for (GSList const *i = objects; i != NULL; i = i->next) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx double opacity = SP_SCALE24_TO_FLOAT(style->opacity.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx opacity_sum += opacity;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (opacity_prev != -1 && opacity != opacity_prev)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_opacity = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx opacity_prev = opacity;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China opacity_items ++;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (opacity_items > 1)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx opacity_sum /= opacity_items;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->opacity.value = SP_SCALE24_FROM_FLOAT(opacity_sum);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (opacity_items == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (opacity_items == 1) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_SINGLE;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (same_opacity)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_AVERAGED;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average stroke width of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing Chinaint
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing Chinaobjects_query_strokewidth (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble avgwidth = 0.0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble prev_sw = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_sw = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool noneSet = true; // is stroke set to none?
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int n_stroked = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_ITEM(obj)) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( style->stroke.isNone() && !(
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style->marker[SP_MARKER_LOC].set || // stroke width affects markers, so if there's no stroke but only markers then we should
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style->marker[SP_MARKER_LOC_START].set || // still calculate the stroke width
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style->marker[SP_MARKER_LOC_MID].set ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style->marker[SP_MARKER_LOC_END].set))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx n_stroked ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx noneSet &= style->stroke.isNone();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx double sw = style->stroke_width.computed * i2d.descrim();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prev_sw != -1 && fabs(sw - prev_sw) > 1e-3)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_sw = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev_sw = sw;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China avgwidth += sw;
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China }
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China if (n_stroked > 1)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China avgwidth /= (n_stroked);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_width.computed = avgwidth;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_width.set = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke.noneSet = noneSet; // Will only be true if none of the selected objects has it's stroke set.
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China if (n_stroked == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (n_stroked == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China if (same_sw)
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_AVERAGED;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average miter limit of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_miterlimit (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble avgml = 0.0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int n_stroked = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble prev_ml = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_ml = true;
f3c4902c7f91725a7b538a3d82f1993bff02944fpengcheng chen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China for (GSList const *i = objects; i != NULL; i = i->next) {
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China SPObject *obj = SP_OBJECT (i->data);
43439c96b8398c01c375889c79bed72d78fb4c39hx if (!SP_IS_ITEM(obj)) continue;
43439c96b8398c01c375889c79bed72d78fb4c39hx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( style->stroke.isNone() ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China n_stroked ++;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prev_ml != -1 && fabs(style->stroke_miterlimit.value - prev_ml) > 1e-3)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China same_ml = false;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China prev_ml = style->stroke_miterlimit.value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx avgml += style->stroke_miterlimit.value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (n_stroked > 1)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx avgml /= (n_stroked);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China style_res->stroke_miterlimit.value = avgml;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_miterlimit.set = true;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (n_stroked == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (n_stroked == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China } else {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (same_ml)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China else
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_AVERAGED;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the stroke cap of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_strokecap (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int cap = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx gdouble prev_cap = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_cap = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int n_stroked = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_ITEM(obj)) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( style->stroke.isNone() ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx n_stroked ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prev_cap != -1 && style->stroke_linecap.value != prev_cap)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_cap = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev_cap = style->stroke_linecap.value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx cap = style->stroke_linecap.value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_linecap.value = cap;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_linecap.set = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (n_stroked == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (n_stroked == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (same_cap)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the stroke join of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_strokejoin (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int join = -1;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China gdouble prev_join = -1;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China bool same_join = true;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China int n_stroked = 0;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China SPObject *obj = SP_OBJECT (i->data);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (!SP_IS_ITEM(obj)) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if ( style->stroke.isNone() ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx n_stroked ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (prev_join != -1 && style->stroke_linejoin.value != prev_join)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_join = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx prev_join = style->stroke_linejoin.value;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China join = style->stroke_linejoin.value;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China style_res->stroke_linejoin.value = join;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->stroke_linejoin.set = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (n_stroked == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (n_stroked == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (same_join)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average font size and spacing of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
d62cb7fff63265824a8e6725a3bcef698f6134c9hxobjects_query_fontnumbers (GSList *objects, SPStyle *style_res)
d62cb7fff63265824a8e6725a3bcef698f6134c9hx{
d62cb7fff63265824a8e6725a3bcef698f6134c9hx bool different = false;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx
d62cb7fff63265824a8e6725a3bcef698f6134c9hx double size = 0;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx double letterspacing = 0;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx double linespacing = 0;
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China bool linespacing_normal = false;
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China bool letterspacing_normal = false;
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China
d40f4da491abdcae192eb797766f5f44772a832fpengcheng chen - Sun Microsystems - Beijing China double size_prev = 0;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx double letterspacing_prev = 0;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx double linespacing_prev = 0;
d62cb7fff63265824a8e6725a3bcef698f6134c9hx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /// \todo FIXME: add word spacing, kerns? rotates?
d62cb7fff63265824a8e6725a3bcef698f6134c9hx
43439c96b8398c01c375889c79bed72d78fb4c39hx int texts = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx texts ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx size += style->font_size.computed * Geom::Matrix(sp_item_i2d_affine(SP_ITEM(obj))).descrim(); /// \todo FIXME: we assume non-% units here
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style->letter_spacing.normal) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx letterspacing_normal = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx letterspacing += style->letter_spacing.computed; /// \todo FIXME: we assume non-% units here
c533a883a71cff9ff32df1c53c31201e1cbf371fhx letterspacing_normal = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx double linespacing_current;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if (style->line_height.normal) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!different && (linespacing_prev == 0 || linespacing_prev == linespacing_current))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_normal = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (style->line_height.unit == SP_CSS_UNIT_PERCENT || style->font_size.computed == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_current = style->line_height.value;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_normal = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else { // we need % here
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_current = style->line_height.computed / style->font_size.computed;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China linespacing_normal = false;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China }
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China linespacing += linespacing_current;
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China if ((size_prev != 0 && style->font_size.computed != size_prev) ||
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China (letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) ||
cdc64593cc1046229f4ac4daf5ead688b5efe6ebxinghua wen - Sun Microsystems - Beijing China (linespacing_prev != 0 && linespacing_current != linespacing_prev)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx different = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx size_prev = style->font_size.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx letterspacing_prev = style->letter_spacing.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx linespacing_prev = linespacing_current;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // FIXME: we must detect MULTIPLE_DIFFERENT for these too
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text_anchor.computed = style->text_anchor.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->writing_mode.computed = style->writing_mode.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts == 0)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts > 1) {
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China size /= texts;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China letterspacing /= texts;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China linespacing /= texts;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China }
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->font_size.computed = size;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->font_size.type = SP_FONT_SIZE_LENGTH;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->letter_spacing.normal = letterspacing_normal;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->letter_spacing.computed = letterspacing;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->line_height.normal = linespacing_normal;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->line_height.computed = linespacing;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->line_height.value = linespacing;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China if (texts > 1) {
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China if (different) {
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_AVERAGED;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China } else {
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China }
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China } else {
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_SINGLE;
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China }
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China}
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China/**
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China * Write to style_res the average font style of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_fontstyle (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool different = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool set = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int texts = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx texts ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (set &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx font_style_to_pos(*style_res).signature() != font_style_to_pos(*style).signature() ) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx different = true; // different styles
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx set = TRUE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->font_weight.value = style_res->font_weight.computed = style->font_weight.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->font_style.value = style_res->font_style.computed = style->font_style.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->font_stretch.value = style_res->font_stretch.computed = style->font_stretch.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->font_variant.value = style_res->font_variant.computed = style->font_variant.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text_align.value = style_res->text_align.computed = style->text_align.computed;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts == 0 || !set)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts > 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (different) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average font family of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_fontfamily (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool different = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int texts = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_family.value) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx g_free(style_res->text->font_family.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_family.value = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_family.set = FALSE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx texts ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_family.value && style->text->font_family.value &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx strcmp (style_res->text->font_family.value, style->text->font_family.value)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx different = true; // different fonts
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_family.value) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx g_free(style_res->text->font_family.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_family.value = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_family.set = TRUE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_family.value = g_strdup(style->text->font_family.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts == 0 || !style_res->text->font_family.set)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts > 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (different) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_fontspecification (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool different = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int texts = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_specification.value) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx g_free(style_res->text->font_specification.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_specification.value = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_specification.set = FALSE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_TEXT(obj) && !SP_IS_FLOWTEXT(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_TSPAN(obj) && !SP_IS_TREF(obj) && !SP_IS_TEXTPATH(obj)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx && !SP_IS_FLOWDIV(obj) && !SP_IS_FLOWPARA(obj) && !SP_IS_FLOWTSPAN(obj))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx texts ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_specification.value && style_res->text->font_specification.set &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style->text->font_specification.value && style->text->font_specification.set &&
c533a883a71cff9ff32df1c53c31201e1cbf371fhx strcmp (style_res->text->font_specification.value, style->text->font_specification.value)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx different = true; // different fonts
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style->text->font_specification.set) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style_res->text->font_specification.value) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx g_free(style_res->text->font_specification.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_specification.value = NULL;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_specification.set = TRUE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->text->font_specification.value = g_strdup(style->text->font_specification.value);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts == 0)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (texts > 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (different) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_blend (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx const int empty_prev = -2;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx const int complex_filter = 5;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int blend = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx float blend_prev = empty_prev;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_blend = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx guint items = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(!style || !SP_IS_ITEM(obj)) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx items++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx //if object has a filter
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style->filter.set && style->getFilter()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int blurcount = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int blendcount = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // determine whether filter is simple (blend and/or blur) or complex
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for(SPObject *primitive_obj = style->getFilter()->children;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx primitive_obj && SP_IS_FILTER_PRIMITIVE(primitive_obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx primitive_obj = primitive_obj->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(SP_IS_FEBLEND(primitive))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx ++blendcount;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else if(SP_IS_GAUSSIANBLUR(primitive))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx ++blurcount;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blurcount = complex_filter;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx break;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // simple filter
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(blurcount == 1 || blendcount == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for(SPObject *primitive_obj = style->getFilter()->children;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx primitive_obj && SP_IS_FILTER_PRIMITIVE(primitive_obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx primitive_obj = primitive_obj->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(SP_IS_FEBLEND(primitive_obj)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPFeBlend *spblend = SP_FEBLEND(primitive_obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blend = spblend->blend_mode;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else {
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China blend = complex_filter;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // defaults to blend mode = "normal"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blend = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(blend_prev != empty_prev && blend_prev != blend)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx same_blend = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blend_prev = blend;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (items > 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->filter_blend_mode.value = blend;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (items == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (items == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(same_blend)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_SAME;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx else
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_DIFFERENT;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Write to style_res the average blurring of a list of objects.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxobjects_query_blur (GSList *objects, SPStyle *style_res)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (g_slist_length(objects) == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx /* No objects, set empty */
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx float blur_sum = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx float blur_prev = -1;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx bool same_blur = true;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx guint blur_items = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx guint items = 0;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx for (GSList const *i = objects; i != NULL; i = i->next) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *obj = SP_OBJECT (i->data);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPStyle *style = SP_OBJECT_STYLE (obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!style) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (!SP_IS_ITEM(obj)) continue;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Geom::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx items ++;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx //if object has a filter
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (style->filter.set && style->getFilter()) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx //cycle through filter primitives
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPObject *primitive_obj = style->getFilter()->children;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx while (primitive_obj) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx //if primitive is gaussianblur
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if(SP_IS_GAUSSIANBLUR(primitive)) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx float num = spblur->stdDeviation.getNumber();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blur_sum += num * i2d.descrim();
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (blur_prev != -1 && fabs (num - blur_prev) > 1e-2) // rather low tolerance because difference in blur radii is much harder to notice than e.g. difference in sizes
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China same_blur = false;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blur_prev = num;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx //TODO: deal with opt number, for the moment it's not necessary to the ui.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blur_items ++;
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx primitive_obj = primitive_obj->next;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (items > 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (blur_items > 0)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx blur_sum /= blur_items;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx style_res->filter_gaussianBlur_deviation.value = blur_sum;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (items == 0) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (items == 1) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_SINGLE;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (same_blur)
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China return QUERY_STYLE_MULTIPLE_SAME;
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China else
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_MULTIPLE_AVERAGED;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Query the given list of objects for the given property, write
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China * the result to style, return appropriate flag.
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_query_style_from_list (GSList *list, SPStyle *style, int property)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (property == QUERY_STYLE_PROPERTY_FILL) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fillstroke (list, style, true);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_STROKE) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fillstroke (list, style, false);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_STROKEWIDTH) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_strokewidth (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_STROKEMITERLIMIT) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_miterlimit (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_STROKECAP) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_strokecap (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_STROKEJOIN) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_strokejoin (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_opacity (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_FONT_SPECIFICATION) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fontspecification (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_FONTFAMILY) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fontfamily (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_FONTSTYLE) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fontstyle (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_fontnumbers (list, style);
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China
c533a883a71cff9ff32df1c53c31201e1cbf371fhx } else if (property == QUERY_STYLE_PROPERTY_BLEND) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_blend (list, style);
d2a61391af480de12cf4264080d7254a6de96e2apengcheng chen - Sun Microsystems - Beijing China } else if (property == QUERY_STYLE_PROPERTY_BLUR) {
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return objects_query_blur (list, style);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx }
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return QUERY_STYLE_NOTHING;
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Query the subselection (if any) or selection on the given desktop for the given property, write
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * the result to style, return appropriate flag.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxint
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int ret = desktop->_query_style_signal.emit(style, property);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx if (ret != QUERY_STYLE_NOTHING)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return ret; // subselection returned a style, pass it on
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx // otherwise, do querying and averaging over selection
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/**
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * Do the same as sp_desktop_query_style for all (defined) style properties, return true if at
c533a883a71cff9ff32df1c53c31201e1cbf371fhx * least one of the properties did not return QUERY_STYLE_NOTHING.
c533a883a71cff9ff32df1c53c31201e1cbf371fhx */
c533a883a71cff9ff32df1c53c31201e1cbf371fhxbool
c533a883a71cff9ff32df1c53c31201e1cbf371fhxsp_desktop_query_style_all (SPDesktop *desktop, SPStyle *query)
c533a883a71cff9ff32df1c53c31201e1cbf371fhx{
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_family = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_fstyle = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_fnumbers = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_fill = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_FILL);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_stroke = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKE);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_strokewidth = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_strokemiterlimit = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_strokecap = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKECAP);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_strokejoin = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_opacity = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx int result_blur = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx return (result_family != QUERY_STYLE_NOTHING ||
b510adae7e8895b2bf58eda3537fd56df35302e4fei feng - Sun Microsystems - Beijing China result_fstyle != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_fnumbers != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_fill != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_stroke != QUERY_STYLE_NOTHING ||
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China result_opacity != QUERY_STYLE_NOTHING ||
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China result_strokewidth != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_strokemiterlimit != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_strokecap != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_strokejoin != QUERY_STYLE_NOTHING ||
c533a883a71cff9ff32df1c53c31201e1cbf371fhx result_blur != QUERY_STYLE_NOTHING);
c533a883a71cff9ff32df1c53c31201e1cbf371fhx}
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx
c533a883a71cff9ff32df1c53c31201e1cbf371fhx/*
c533a883a71cff9ff32df1c53c31201e1cbf371fhx Local Variables:
c533a883a71cff9ff32df1c53c31201e1cbf371fhx mode:c++
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c-file-style:"stroustrup"
c533a883a71cff9ff32df1c53c31201e1cbf371fhx c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
c533a883a71cff9ff32df1c53c31201e1cbf371fhx indent-tabs-mode:nil
c533a883a71cff9ff32df1c53c31201e1cbf371fhx fill-column:99
c533a883a71cff9ff32df1c53c31201e1cbf371fhx End:
c533a883a71cff9ff32df1c53c31201e1cbf371fhx*/
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
c50ced99bb75273dc8c4c36876d2e8f59a64f4b1pengcheng chen - Sun Microsystems - Beijing China