desktop-style.cpp revision fa6673a4a7cb29244706d94d967858c3c8cae2ea
/*
* Desktop style management
*
* Authors:
* bulia byak
* verbalshadow
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2004, 2006 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <string>
#include <cstring>
#include <glibmm.h>
#include "desktop.h"
#include "color-rgba.h"
#include "svg/css-ostringstream.h"
#include "svg/svg-color.h"
#include "selection.h"
#include "inkscape.h"
#include "style.h"
#include "preferences.h"
#include "sp-use.h"
#include "sp-filter.h"
#include "sp-filter-reference.h"
#include "filters/gaussian-blur.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-flowdiv.h"
#include "sp-linear-gradient.h"
#include "sp-pattern.h"
#include "sp-radial-gradient.h"
#include "sp-textpath.h"
#include "sp-tref.h"
#include "sp-tspan.h"
#include "xml/sp-css-attr.h"
#include "sp-path.h"
#include "ui/tools/tool-base.h"
#include "desktop-style.h"
#include "svg/svg-icc-color.h"
#include "box3d-side.h"
namespace {
{
|| dynamic_cast<SPFlowtspan const *>(obj);
return isTextual;
}
} // namespace
/**
* Set color on selection on desktop.
*/
void
{
/// \todo relative color setting
if (is_relative) {
g_warning("FIXME: relative color setting not yet implemented");
return;
}
gchar b[64];
sp_svg_write_color(b, sizeof(b), rgba);
if (fill) {
} else {
}
}
/**
* Apply style on object and children, recursively.
*/
void
{
// non-items should not have style
if (!item) {
return;
}
// 1. tspans with role=line are not regular objects in that they are not supposed to have style of their own,
// but must always inherit from the parent text. Same for textPath.
// However, if the line tspan or textPath contains some style (old file?), we reluctantly set our style to it too.
// 2. Generally we allow setting style on clones, but when it's inside flowRegion, do not touch
// it, be it clone or not; it's just styleless shape (because that's how Inkscape does
// flowtext).
if (!(skip_lines
|| dynamic_cast<SPFlowdiv *>(o)
|| dynamic_cast<SPFlowpara *>(o)
|| dynamic_cast<SPTextPath *>(o))
&& !o->getAttribute("style"))
&&
!(dynamic_cast<SPFlowregionbreak *>(o) ||
dynamic_cast<SPFlowregionExclude *>(o) ||
(dynamic_cast<SPUse *>(o) &&
o->parent &&
(dynamic_cast<SPFlowregion *>(o->parent) ||
dynamic_cast<SPFlowregionExclude *>(o->parent)
)
)
)
) {
// Scale the style by the inverse of the accumulated parent transform in the paste context.
{
if ( ( ex != 0. )
&& ( ex != 1. ) ) {
}
}
}
// setting style on child of clone spills into the clone original (via shared repr), don't do it!
if (dynamic_cast<SPUse *>(o)) {
return;
}
// Unset properties which are accumulating and thus should not be set recursively.
// 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.
} else {
}
}
}
/**
* Apply style on selection on desktop.
*/
void
{
if (write_current) {
// 1. Set internal value
// 1a. Write to prefs; make a copy and unset any URIs first
/* last used styles for 3D box faces are stored separately */
SPObject *obj = reinterpret_cast<SPObject *>(i->data); // TODO unsafe until Selection is refactored.
if (side) {
}
}
}
}
if (!change)
return;
// 2. Emit signal
/** \todo
* FIXME: in set_style, compensate pattern and gradient fills, stroke width,
* rect corners, font size for the object's own transform so that pasting
*/
// 3. If nobody has intercepted the signal, apply the style to the selection
if (!intercepted) {
// If we have an event context, update its cursor (TODO: it could be neater to do this with the signal sent above, but what if the signal gets intercepted?)
if (desktop->event_context) {
}
// Remove text attributes if not text...
// Do this once in case a zillion objects are selected.
// If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME)
if (isTextualItem(item)) {
// If any font property has changed, then we have written out the font
// properties in longhand and we need to remove the 'font' shorthand.
}
} else {
}
}
}
}
/**
* Return the desktop's current style.
*/
{
if (!css->attributeList()) {
return NULL;
} else {
if (!with_text) {
}
return css;
}
}
/**
* Return the desktop's current color.
*/
{
guint32 r = 0; // if there's no color, return black
"#000");
// read it
r = sp_svg_read_color(property, r);
}
}
return r;
}
double
sp_desktop_get_master_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool *has_opacity)
{
if (has_opacity)
*has_opacity = false;
} else {
}
if (css) {
} else {
if (has_opacity)
*has_opacity = true;
}
}
}
return value;
}
double
{
} else {
}
if (css) {
gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
}
}
}
return value;
}
sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is_fill, bool *has_color)
{
guint32 r = 0; // if there's no color, return black
if (has_color)
*has_color = false;
} else {
}
if (css) {
// read it
r = sp_svg_read_color(property, r);
if (has_color)
*has_color = true;
}
}
}
return r | 0xff;
}
/**
* Apply the desktop's current style or the tool style to repr.
*/
void
sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib::ustring const &tool_path, bool with_text)
{
} else {
}
if (css_current) {
}
}
/**
* Returns the font size (in SVG pixels) of the text tool style (if text
* tool uses its own style) or desktop style (otherwise).
*/
double
{
(void)desktop; // TODO cleanup
} else {
}
double ret = 12;
}
return ret;
}
/** Determine average stroke width, simple method */
// see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually
{
bool notstroked = true;
int n_notstroked = 0;
if (!item) {
continue;
}
++n_notstroked; // do not count nonstroked objects
continue;
} else {
notstroked = false;
}
}
if (notstroked)
}
{
bool isClose = false;
static double epsilon = 1e-6;
isClose = true;
}
}
return isClose;
}
/**
* Write to style_res the average fill or stroke of list of objects, if applicable.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
bool paintImpossible = true;
SVGICCColor* iccColor = 0;
bool iccSeen = false;
gfloat c[4];
c[0] = c[1] = c[2] = c[3] = 0.0;
bool same_color = true;
if (!obj) {
continue;
}
if (!style) {
continue;
}
// We consider paint "effectively set" for anything within text hierarchy
bool paint_effectively_set =
paint->set || (dynamic_cast<SPText *>(parent) || dynamic_cast<SPTextPath *>(parent) || dynamic_cast<SPTSpan *>(parent)
|| dynamic_cast<SPFlowtext *>(parent) || dynamic_cast<SPFlowdiv *>(parent) || dynamic_cast<SPFlowpara *>(parent)
// 1. Bail out with QUERY_STYLE_MULTIPLE_DIFFERENT if necessary
// cppcheck-suppress comparisonOfBoolWithInt
if ((!paintImpossible) && (!paint->isSameType(*paint_res) || (paint_res->set != paint_effectively_set))) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different types of paint
}
// both previous paint and this paint were a server, see if the servers are compatible
SPPaintServer *server_res = isfill ? style_res->getFillPaintServer() : style_res->getStrokePaintServer();
if (linear_res) {
if (!linear) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
}
if (vector_res != vector) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
}
} else if (radial_res) {
if (!radial) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
}
if (vector_res != vector) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
}
} else if (pattern_res) {
if (!pattern) {
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
}
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots
}
}
}
// 2. Sum color, copy server from paint to paint_res
gfloat d[3];
// Check if this color is the same as previous
if (paintImpossible) {
prev[0] = d[0];
iccSeen = true;
} else {
same_color = false;
iccColor = 0;
}
same_color = false;
iccColor = 0;
}
}
}
// average color
c[0] += d[0];
c[1] += d[1];
c[2] += d[2];
num ++;
}
paintImpossible = false;
gchar const *string = NULL; // memory leak results if style->get* called inside sp_style_set_to_uri_string.
if (isfill) {
} else {
}
}
style_res->fill_rule.computed = style->fill_rule.computed; // no averaging on this, just use the last one
}
// After all objects processed, divide the color if necessary and return
c[0] /= num;
c[1] /= num;
c[2] /= num;
c[3] /= num;
if (isfill) {
} else {
}
// TODO check for existing
}
if (num > 1) {
if (same_color)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_AVERAGED;
} else {
return QUERY_STYLE_SINGLE;
}
}
// Not color
return QUERY_STYLE_MULTIPLE_SAME;
} else {
return QUERY_STYLE_SINGLE;
}
}
/**
* Write to style_res the average opacity of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
gdouble opacity_sum = 0;
bool same_opacity = true;
guint opacity_items = 0;
if (!obj) {
continue;
}
if (!style) {
continue;
}
opacity_sum += opacity;
same_opacity = false;
}
opacity_items ++;
}
if (opacity_items > 1) {
}
if (opacity_items == 0) {
return QUERY_STYLE_NOTHING;
} else if (opacity_items == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_opacity) {
return QUERY_STYLE_MULTIPLE_SAME;
} else {
return QUERY_STYLE_MULTIPLE_AVERAGED;
}
}
}
/**
* Write to style_res the average stroke width of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
bool same_sw = true;
bool noneSet = true; // is stroke set to none?
int n_stroked = 0;
if (!obj) {
continue;
}
if (!item) {
continue;
}
if (!style) {
continue;
}
{
continue;
}
same_sw = false;
n_stroked ++;
}
}
if (n_stroked > 1)
style_res->stroke.noneSet = noneSet; // Will only be true if none of the selected objects has it's stroke set.
if (n_stroked == 0) {
return QUERY_STYLE_NOTHING;
} else if (n_stroked == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_sw)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_AVERAGED;
}
}
/**
* Write to style_res the average miter limit of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
int n_stroked = 0;
bool same_ml = true;
continue;
}
if (!style) {
continue;
}
continue;
}
n_stroked ++;
same_ml = false;
}
}
if (n_stroked > 1) {
}
if (n_stroked == 0) {
return QUERY_STYLE_NOTHING;
} else if (n_stroked == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_ml)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_AVERAGED;
}
}
/**
* Write to style_res the stroke cap of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
int cap = -1;
bool same_cap = true;
int n_stroked = 0;
continue;
}
if (!style) {
continue;
}
continue;
}
n_stroked ++;
same_cap = false;
}
if (n_stroked == 0) {
return QUERY_STYLE_NOTHING;
} else if (n_stroked == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_cap)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_DIFFERENT;
}
}
/**
* Write to style_res the stroke join of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
int join = -1;
bool same_join = true;
int n_stroked = 0;
continue;
}
if (!style) {
continue;
}
continue;
}
n_stroked ++;
same_join = false;
}
}
if (n_stroked == 0) {
return QUERY_STYLE_NOTHING;
} else if (n_stroked == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_join)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_DIFFERENT;
}
}
/**
* Write to style_res the average font size and spacing of objects.
*/
int
{
bool different = false;
double size = 0;
double letterspacing = 0;
double wordspacing = 0;
double linespacing = 0;
bool letterspacing_normal = false;
bool wordspacing_normal = false;
bool linespacing_normal = false;
double size_prev = 0;
double letterspacing_prev = 0;
double wordspacing_prev = 0;
double linespacing_prev = 0;
int texts = 0;
int no_size = 0;
if (!isTextualItem(obj)) {
continue;
}
if (!style) {
continue;
}
texts ++;
} else {
no_size++;
}
letterspacing_normal = true;
}
} else {
letterspacing += style->letter_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here
letterspacing_normal = false;
}
wordspacing_normal = true;
}
} else {
wordspacing += style->word_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here
wordspacing_normal = false;
}
double linespacing_current;
linespacing_normal = true;
linespacing_normal = false;
} else {
linespacing_normal = false;
}
different = true;
}
// FIXME: we must detect MULTIPLE_DIFFERENT for these too
}
if (texts == 0)
return QUERY_STYLE_NOTHING;
if (texts > 1) {
}
letterspacing /= texts;
wordspacing /= texts;
linespacing /= texts;
}
if (texts > 1) {
if (different) {
return QUERY_STYLE_MULTIPLE_AVERAGED;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
}
} else {
return QUERY_STYLE_SINGLE;
}
}
/**
* Write to style_res the average font style of objects.
*/
int
{
bool different = false;
bool set = false;
int texts = 0;
if (!isTextualItem(obj)) {
continue;
}
if (!style) {
continue;
}
texts ++;
if (set &&
different = true; // different styles
}
}
return QUERY_STYLE_NOTHING;
if (texts > 1) {
if (different) {
return QUERY_STYLE_MULTIPLE_DIFFERENT;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
}
} else {
return QUERY_STYLE_SINGLE;
}
}
/**
* Write to style_res the baseline numbers.
*/
static int
{
bool different = false;
// Only baseline-shift at the moment
// We will return:
// If baseline-shift is same for all objects:
// The full baseline-shift data (used for subscripts and superscripts)
// If baseline-shift is different:
// The average baseline-shift (not implemented at the moment as this is complicated June 2010)
// double baselineshift = 0.0;
bool set = false;
int texts = 0;
if (!isTextualItem(obj)) {
continue;
}
if (!style) {
continue;
}
texts ++;
if( set ) {
// Maybe this needs to be better thought out.
different = true;
}
}
set = true;
}
}
} else {
}
return QUERY_STYLE_NOTHING;
if (texts > 1) {
if (different) {
return QUERY_STYLE_MULTIPLE_DIFFERENT;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
}
} else {
return QUERY_STYLE_SINGLE;
}
}
/**
* Write to style_res the average font family of objects.
*/
int
{
bool different = false;
int texts = 0;
}
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
continue;
}
if (!style) {
continue;
}
texts ++;
different = true; // different fonts
}
}
}
return QUERY_STYLE_NOTHING;
}
if (texts > 1) {
if (different) {
return QUERY_STYLE_MULTIPLE_DIFFERENT;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
}
} else {
return QUERY_STYLE_SINGLE;
}
}
static int
{
bool different = false;
int texts = 0;
}
// std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl;
if (!isTextualItem(obj)) {
continue;
}
if (!style) {
continue;
}
texts ++;
different = true; // different fonts
}
}
}
}
if (texts == 0) {
return QUERY_STYLE_NOTHING;
}
if (texts > 1) {
if (different) {
return QUERY_STYLE_MULTIPLE_DIFFERENT;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
}
} else {
return QUERY_STYLE_SINGLE;
}
}
static int
{
const int empty_prev = -2;
const int complex_filter = 5;
int blend = 0;
float blend_prev = empty_prev;
bool same_blend = true;
if (!obj) {
continue;
}
continue;
}
items++;
//if object has a filter
int blurcount = 0;
int blendcount = 0;
++blendcount;
} else if (dynamic_cast<SPGaussianBlur *>(primitive)) {
++blurcount;
} else {
break;
}
}
// simple filter
if (spblend) {
}
}
}
else {
}
}
// defaults to blend mode = "normal"
else {
blend = 0;
}
same_blend = false;
blend_prev = blend;
}
if (items > 0) {
}
if (items == 0) {
return QUERY_STYLE_NOTHING;
} else if (items == 1) {
return QUERY_STYLE_SINGLE;
} else {
if(same_blend)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_DIFFERENT;
}
}
/**
* Write to style_res the average blurring of a list of objects.
*/
int
{
if (g_slist_length(objects) == 0) {
/* No objects, set empty */
return QUERY_STYLE_NOTHING;
}
float blur_sum = 0;
float blur_prev = -1;
bool same_blur = true;
guint blur_items = 0;
if (!obj) {
continue;
}
if (!style) {
continue;
}
if (!item) {
continue;
}
items ++;
//if object has a filter
//cycle through filter primitives
while (primitive_obj) {
if (primitive) {
//if primitive is gaussianblur
if (spblur) {
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
same_blur = false;
//TODO: deal with opt number, for the moment it's not necessary to the ui.
blur_items ++;
}
}
}
}
}
}
if (items > 0) {
if (blur_items > 0)
blur_sum /= blur_items;
}
if (items == 0) {
return QUERY_STYLE_NOTHING;
} else if (items == 1) {
return QUERY_STYLE_SINGLE;
} else {
if (same_blur)
return QUERY_STYLE_MULTIPLE_SAME;
else
return QUERY_STYLE_MULTIPLE_AVERAGED;
}
}
/**
* Query the given list of objects for the given property, write
* the result to style, return appropriate flag.
*/
int
{
if (property == QUERY_STYLE_PROPERTY_FILL) {
} else if (property == QUERY_STYLE_PROPERTY_STROKE) {
} else if (property == QUERY_STYLE_PROPERTY_STROKEWIDTH) {
} else if (property == QUERY_STYLE_PROPERTY_STROKEMITERLIMIT) {
} else if (property == QUERY_STYLE_PROPERTY_STROKECAP) {
} else if (property == QUERY_STYLE_PROPERTY_STROKEJOIN) {
} else if (property == QUERY_STYLE_PROPERTY_MASTEROPACITY) {
} else if (property == QUERY_STYLE_PROPERTY_FONT_SPECIFICATION) {
} else if (property == QUERY_STYLE_PROPERTY_FONTFAMILY) {
} else if (property == QUERY_STYLE_PROPERTY_FONTSTYLE) {
} else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
} else if (property == QUERY_STYLE_PROPERTY_BASELINES) {
} else if (property == QUERY_STYLE_PROPERTY_BLEND) {
} else if (property == QUERY_STYLE_PROPERTY_BLUR) {
}
return QUERY_STYLE_NOTHING;
}
/**
* Query the subselection (if any) or selection on the given desktop for the given property, write
* the result to style, return appropriate flag.
*/
int
{
if (ret != QUERY_STYLE_NOTHING)
return ret; // subselection returned a style, pass it on
// otherwise, do querying and averaging over selection
return sp_desktop_query_style_from_list ((GSList *) desktop->selection->itemList(), style, property);
}
return QUERY_STYLE_NOTHING;
}
/**
* Do the same as sp_desktop_query_style for all (defined) style properties, return true if at
* least one of the properties did not return QUERY_STYLE_NOTHING.
*/
bool
{
int result_strokemiterlimit = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
return (result_family != QUERY_STYLE_NOTHING ||
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :