style.h revision 5834db43b21308e958a2fdbbec082b1a4f019a38
#ifndef __SP_STYLE_H__
#define __SP_STYLE_H__
/** \file
* SPStyle - a style object for SPItem objects
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "color.h"
#include "forward.h"
#include "sp-marker-loc.h"
#include "sp-filter.h"
#include "sp-filter-reference.h"
#include "uri-references.h"
#include "uri.h"
#include "sp-paint-server.h"
#include <sigc++/connection.h>
}
}
/// Float type internal to SPStyle.
struct SPIFloat {
unsigned set : 1;
unsigned inherit : 1;
unsigned data : 30;
float value;
};
/*
* One might think that the best value for SP_SCALE24_MAX would be ((1<<24)-1), which allows the
* greatest possible precision for fitting [0, 1] fractions into 24 bits.
*
* However, in practice, that gives a problem with 0.5, which falls half way between two fractions
* of ((1<<24)-1). What's worse is that casting double(1<<23) / ((1<<24)-1) to float on x86
* produces wrong rounding behaviour, resulting in a fraction of ((1<<23)+2.0f) / (1<<24) rather
* than ((1<<23)+1.0f) / (1<<24) as one would expect, let alone ((1<<23)+0.0f) / (1<<24) as one
* would ideally like for this example.
*
* The value (1<<23) is thus best if one considers float conversions alone.
*
* The value 0xff0000 can exactly represent all 8-bit alpha channel values,
* and can exactly represent all multiples of 0.1. I haven't yet tested whether
* rounding bugs still get in the way of conversions to & from float, but my instinct is that
* it's fairly safe because 0xff fits three times inside float's significand.
*
* though that might need to be accompanied by greater use of double instead of float for
* colours and opacities, to be safe from rounding bugs.
*/
#define SP_SCALE24_MAX (0xff0000)
#define SP_SCALE24_TO_FLOAT(v) ((double) (v) / SP_SCALE24_MAX)
/** Returns a scale24 for the product of two scale24 values. */
/// 24 bit data type internal to SPStyle.
struct SPIScale24 {
unsigned set : 1;
unsigned inherit : 1;
unsigned value : 24;
};
/// Int type internal to SPStyle.
struct SPIInt {
unsigned set : 1;
unsigned inherit : 1;
unsigned data : 30;
int value;
};
/// Short type internal to SPStyle.
struct SPIShort {
unsigned set : 1;
unsigned inherit : 1;
unsigned data : 14;
int value : 16;
};
/// Enum type internal to SPStyle.
struct SPIEnum {
unsigned set : 1;
unsigned inherit : 1;
unsigned value : 8;
unsigned computed : 8;
};
/// String type internal to SPStyle.
struct SPIString {
unsigned set : 1;
unsigned inherit : 1;
unsigned data : 30;
};
enum {
};
/// Length type internal to SPStyle.
struct SPILength {
unsigned set : 1;
unsigned inherit : 1;
unsigned unit : 4;
float value;
float computed;
};
/// Paint type internal to SPStyle.
struct SPIPaint {
unsigned set : 1;
unsigned inherit : 1;
unsigned currentcolor : 1;
unsigned int colorSet : 1;
unsigned int noneSet : 1;
struct {
} value;
bool isSet() const { return true; /* set || colorSet*/}
bool isSameType( SPIPaint const & other ) const {return (isPaintserver() == other.isPaintserver()) && (colorSet == other.colorSet) && (currentcolor == other.currentcolor);}
void clear();
};
/// Filter type internal to SPStyle
struct SPIFilter {
unsigned set : 1;
unsigned inherit : 1;
};
enum {
};
#define SP_STYLE_FLAG_IFSET (1 << 0)
/// Fontsize type internal to SPStyle.
struct SPIFontSize {
unsigned set : 1;
unsigned inherit : 1;
unsigned type : 2;
unsigned value : 24;
float computed;
};
/// Text decoration type internal to SPStyle.
struct SPITextDecoration {
unsigned set : 1;
unsigned inherit : 1;
unsigned underline : 1;
unsigned overline : 1;
unsigned line_through : 1;
};
/// Extended length type internal to SPStyle.
struct SPILengthOrNormal {
unsigned set : 1;
unsigned inherit : 1;
unsigned normal : 1;
unsigned unit : 4;
float value;
float computed;
};
/// Stroke dash details.
double offset;
int n_dash;
double *dash;
};
/// An SVG style object.
struct SPStyle {
int refcount;
/** Object we are attached to */
/** Document we are associated with */
/** Our text style component */
unsigned text_private : 1;
/* CSS2 */
/* Font */
/** Size of the font */
/** Style of the font */
/** Which substyle of the font */
/** Weight of the font */
/** Stretch of the font */
/** First line indent of paragraphs (css2 16.1) */
/** text alignment (css2 16.2) (not to be confused with text-anchor) */
/** text decoration (css2 16.3.1) */
// 16.3.2 is text-shadow. That's complicated.
/** Line spacing (css2 10.8.1) */
/** letter spacing (css2 16.4) */
/** word spacing (also css2 16.4) */
/** capitalization (css2 16.5) */
/* CSS3 Text */
/** text direction (css3 text 3.2) */
/** block progression (css3 text 3.2) */
/** Writing mode (css3 text 3.2 and svg1.1 10.7.2) */
/* SVG */
/** Anchor of the text (svg1.1 10.9.1) */
/* Misc attributes */
unsigned clip_set : 1;
unsigned color_set : 1;
unsigned cursor_set : 1;
unsigned overflow_set : 1;
unsigned clip_path_set : 1;
unsigned clip_rule_set : 1;
unsigned mask_set : 1;
/** display */
/** overflow */
/** visibility */
/** opacity */
/** color */
/** fill */
/** fill-opacity */
/** fill-rule: 0 nonzero, 1 evenodd */
/** stroke */
/** stroke-width */
/** stroke-linecap */
/** stroke-linejoin */
/** stroke-miterlimit */
/** stroke-dash* */
unsigned stroke_dasharray_set : 1;
unsigned stroke_dasharray_inherit : 1;
unsigned stroke_dashoffset_set : 1;
/** stroke-opacity */
/** Marker list */
/** Filter effect */
/** normally not used, but duplicates the Gaussian blur deviation (if any) from the attached
filter when the style is used for querying */
/** enable-background, used for defining where filter effects get
* their background image */
/// style belongs to a cloned object
bool cloned;
const gchar *getFilterURI() {if (filter.href) return filter.href->getURI()->toString(); else return NULL;}
SPPaintServer *getFillPaintServer() {if (fill.value.href) return fill.value.href->getObject(); else return NULL;}
const gchar *getFillURI() {if (fill.value.href) return fill.value.href->getURI()->toString(); else return NULL;}
SPPaintServer *getStrokePaintServer() {if (stroke.value.href) return stroke.value.href->getObject(); else return NULL;}
const gchar *getStrokeURI() {if (stroke.value.href) return stroke.value.href->getURI()->toString(); else return NULL;}
};
/* SPTextStyle */
enum SPCSSFontSize {
};
enum SPCSSFontStyle {
};
enum SPCSSFontVariant {
};
enum SPCSSFontWeight {
};
enum SPCSSFontStretch {
};
enum SPCSSTextAlign {
// also <string> is allowed, but only within table calls
};
enum SPCSSTextTransform {
};
enum SPCSSDirection {
};
enum SPCSSBlockProgression {
};
enum SPCSSWritingMode {
};
enum SPTextAnchor {
};
enum SPVisibility {
};
enum SPOverflow {
};
/// \todo more display types
enum SPCSSDisplay {
};
enum SPEnableBackground {
};
/// An SPTextStyle has a refcount, a font family, and a font name.
struct SPTextStyle {
int refcount;
/* CSS font properties */
/* Full font name, as font_factory::ConstructFontSpecification would give */
/** \todo fixme: The 'font' property is ugly, and not working (lauris) */
};
void sp_style_unset_property_attrs(SPObject *o);
void sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *linked, bool recursive);
#endif
/*
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:encoding=utf-8:textwidth=99 :