desktop-style.cpp revision 447f436a87440c48403fb19a69aab49ee3dda2b2
#define __SP_DESKTOP_STYLE_C__
/** \file
* Desktop style management
*
* Authors:
* bulia byak
* verbalshadow
*
* Copyright (C) 2004, 2006 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "desktop.h"
#include "color-rgba.h"
#include "svg/css-ostringstream.h"
#include "svg/svg-color.h"
#include "selection.h"
#include "sp-tspan.h"
#include "sp-textpath.h"
#include "inkscape.h"
#include "style.h"
#include "prefs-utils.h"
#include "sp-use.h"
#include "sp-feblend.h"
#include "sp-filter.h"
#include "sp-filter-reference.h"
#include "sp-gaussian-blur.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-flowdiv.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-pattern.h"
#include "libnrtype/font-style-to-pos.h"
#include "desktop-style.h"
/**
* 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];
if (fill) {
} else {
}
}
/**
* Apply style on object and children, recursively.
*/
void
{
// non-items should not have style
if (!SP_IS_ITEM(o))
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
|| SP_IS_FLOWDIV(o)
|| SP_IS_FLOWPARA(o)
|| SP_IS_TEXTPATH(o))
&&
!(SP_IS_FLOWREGION(o) ||
SP_IS_FLOWREGIONEXCLUDE(o) ||
(SP_IS_USE(o) &&
SP_OBJECT_PARENT(o) &&
(SP_IS_FLOWREGION(SP_OBJECT_PARENT(o)) ||
)
)
)
) {
// 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 (SP_IS_USE(o))
return;
for (SPObject *child = sp_object_first_child(SP_OBJECT(o)) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
// 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
}
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) {
/// \todo if the style is text-only, apply only to texts?
}
}
}
/**
* 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
{
} else {
if (tool_repr) {
}
}
if (css) {
}
}
}
return value;
}
double
{
} else {
if (tool_repr) {
}
}
if (css) {
gchar const *property = css ? sp_repr_css_property(css, is_fill ? "fill-opacity": "stroke-opacity", "1.000") : 0;
}
}
}
return value;
}
{
guint32 r = 0; // if there's no color, return black
} else {
if (tool_repr) {
}
}
if (css) {
// read it
r = sp_svg_read_color(property, r);
}
}
}
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, char const *tool, bool with_text)
{
} else {
if (tool_repr) {
}
}
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
{
} else {
if (tool_repr) {
}
}
double ret = 12;
if (style_str) {
}
return ret;
}
/** Determine average stroke width, simple method */
// see TODO in dialogs/stroke-style.cpp on how to get rid of this eventually
{
return NR_HUGE;
bool notstroked = true;
int n_notstroked = 0;
if (!SP_IS_ITEM (l->data))
continue;
++n_notstroked; // do not count nonstroked objects
continue;
} else {
notstroked = false;
}
}
if (notstroked)
return NR_HUGE;
}
/**
* 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;
}
gfloat c[4];
c[0] = c[1] = c[2] = c[3] = 0.0;
bool same_color = true;
if (!style) continue;
// We consider paint "effectively set" for anything within text hierarchy
bool paint_effectively_set = paint->set || (SP_IS_TEXT(parent) || SP_IS_TEXTPATH(parent) || SP_IS_TSPAN(parent) || SP_IS_FLOWTEXT(parent) || SP_IS_FLOWDIV(parent) || SP_IS_FLOWPARA(parent) || SP_IS_FLOWTSPAN(parent) || SP_IS_FLOWLINE(parent));
// 1. Bail out with QUERY_STYLE_MULTIPLE_DIFFERENT if necessary
if ((paint_res->type != SP_PAINT_TYPE_IMPOSSIBLE) && (paint->type != paint_res->type || (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? SP_STYLE_FILL_SERVER (style_res) : SP_STYLE_STROKE_SERVER (style_res);
if (SP_IS_LINEARGRADIENT (server_res)) {
if (!SP_IS_LINEARGRADIENT(server))
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
if (vector_res != vector)
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
} else if (SP_IS_RADIALGRADIENT (server_res)) {
if (!SP_IS_RADIALGRADIENT(server))
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server
if (vector_res != vector)
return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors
} else if (SP_IS_PATTERN (server_res)) {
if (!SP_IS_PATTERN(server))
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
prev[0] = d[0];
} else {
same_color = false;
}
// average color
c[0] += d[0];
c[1] += d[1];
c[2] += d[2];
num ++;
}
if (paint_res->set && paint_effectively_set && paint->type == SP_PAINT_TYPE_PAINTSERVER) { // copy the server
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 {
}
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 (!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;
int n_stroked = 0;
if (!SP_IS_ITEM(obj)) continue;
if (!style) continue;
continue;
}
n_stroked ++;
same_sw = 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_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;
if (!SP_IS_ITEM(obj)) 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;
if (!SP_IS_ITEM(obj)) 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;
if (!SP_IS_ITEM(obj)) 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 linespacing = 0;
bool linespacing_normal = false;
bool letterspacing_normal = false;
double size_prev = 0;
double letterspacing_prev = 0;
double linespacing_prev = 0;
/// \todo FIXME: add word spacing, kerns? rotates?
int texts = 0;
continue;
if (!style) continue;
texts ++;
size += style->font_size.computed * NR::expansion(sp_item_i2d_affine(SP_ITEM(obj))); /// \todo FIXME: we assume non-% units here
letterspacing_normal = true;
} else {
letterspacing_normal = false;
}
double linespacing_current;
linespacing_normal = true;
linespacing_normal = false;
} else { // we need % here
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;
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;
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 average font family of objects.
*/
int
{
bool different = false;
int texts = 0;
}
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;
}
}
int
{
const int empty_prev = -2;
const int complex_filter = 5;
int blend = 0;
float blend_prev = empty_prev;
bool same_blend = true;
items++;
//if object has a filter
int blurcount = 0;
int blendcount = 0;
if(SP_IS_FEBLEND(primitive))
++blendcount;
else if(SP_IS_GAUSSIANBLUR(primitive))
++blurcount;
else {
break;
}
}
// simple filter
if(SP_IS_FEBLEND(primitive_obj)) {
}
}
}
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 (!style) continue;
if (!SP_IS_ITEM(obj)) continue;
items ++;
//if object has a filter
//cycle through filter primitives
while (primitive_obj) {
if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
//if primitive is gaussianblur
if(SP_IS_GAUSSIANBLUR(primitive)) {
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_FONTFAMILY) {
} else if (property == QUERY_STYLE_PROPERTY_FONTSTYLE) {
} else if (property == QUERY_STYLE_PROPERTY_FONTNUMBERS) {
} 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);
}
/**
* Do the same as sp_desktop_query_style for all (defined) style properties, return true if none of
* the properties returned QUERY_STYLE_NOTHING.
*/
bool
{
int result_strokemiterlimit = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
return (result_family != QUERY_STYLE_NOTHING && result_fstyle != QUERY_STYLE_NOTHING && result_fnumbers != QUERY_STYLE_NOTHING && result_fill != QUERY_STYLE_NOTHING && result_stroke != QUERY_STYLE_NOTHING && result_opacity != QUERY_STYLE_NOTHING && result_strokewidth != QUERY_STYLE_NOTHING && result_strokemiterlimit != QUERY_STYLE_NOTHING && result_strokecap != QUERY_STYLE_NOTHING && result_strokejoin != QUERY_STYLE_NOTHING && result_blur != 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 :