cairo-utils.cpp revision 354e9a1515ed6d7957de6b135670bfb538468351
/*
* Helper functions to use cairo with inkscape
*
* Copyright (C) 2007 bulia byak
* Copyright (C) 2008 Johan Engelen
*
* Released under GNU GPL
*
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "display/cairo-utils.h"
#include <stdexcept>
#include "color.h"
#include "helper/geom-curves.h"
namespace Inkscape {
CairoGroup::~CairoGroup() {
if (pushed) {
}
}
void CairoGroup::push() {
pushed = true;
}
pushed = true;
}
if (pushed) {
pushed = false;
return ret;
} else {
}
}
if (pushed) {
pushed = false;
return retmm;
} else {
}
}
void CairoGroup::pop_to_source() {
if (pushed) {
pushed = false;
}
}
{}
{
}
{
}
{
}
{
return ret;
}
} // namespace Inkscape
/*
* Can be called recursively.
* If optimize_stroke == false, the view Rect is not used.
*/
static void
feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix const & trans, Geom::Rect view, bool optimize_stroke)
{
if( is_straight_curve(c) )
{
if (!optimize_stroke) {
} else {
} else {
}
}
}
else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const*>(&c)) {
if (!optimize_stroke) {
} else {
} else {
}
}
}
//points[0] *= trans; // don't do this one here for fun: it is only needed for optimized strokes
if (!optimize_stroke) {
cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]);
} else {
cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]);
} else {
}
}
}
// else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast<Geom::SVGEllipticalArc *>(c)) {
// //TODO: get at the innards and spit them out to cairo
// }
else {
//this case handles sbasis as well as all other curve types
//recurse to convert the new path resulting from the sbasis to svgd
}
}
}
/** Feeds path-creating calls to the cairo context translating them from the Path */
static void
{
return;
feed_curve_to_cairo(ct, *cit, Geom::identity(), Geom::Rect(), false); // optimize_stroke is false, so the view rect is not used
}
}
}
/** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */
static void
feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, Geom::OptRect area, bool optimize_stroke, double stroke_width)
{
if (!area)
return;
return;
// Transform all coordinates to coords within "area"
// Pass transformation to feed_curve, so that we don't need to create a whole new path.
}
if (!optimize_stroke) {
} else {
/* We cannot use cairo_close_path(ct) here because some parts of the path may have been
clipped and not drawn (maybe the before last segment was outside view area), which
would result in closing the "subpath" after the last interruption, not the entire path.
However, according to cairo documentation:
The behavior of cairo_close_path() is distinct from simply calling cairo_line_to() with the equivalent coordinate
in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead,
there is a line join connecting the final and initial segments of the sub-path.
The correct fix will be possible when cairo introduces methods for moving without
see bug 168129
*/
}
}
}
/** Feeds path-creating calls to the cairo context translating them from the PathVector, with the given transform and shift
* One must have done cairo_new_path(ct); before calling this function. */
void
feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, Geom::OptRect area, bool optimize_stroke, double stroke_width)
{
if (!area)
return;
return;
}
}
/** Feeds path-creating calls to the cairo context translating them from the PathVector
* One must have done cairo_new_path(ct); before calling this function. */
void
{
return;
}
}
void
{
cairo_set_source_rgba(ct, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba), SP_RGBA32_A_F(rgba));
}
void
{
}
static void
{
}
void
{
}
void
{
}
void
{
int w = gdk_pixbuf_get_width(pb);
int h = gdk_pixbuf_get_height(pb);
}
/** @brief Create an exact copy of a surface.
* Creates a surface that has the same type, content type, dimensions and contents
* as the specified surface. */
{
if (cairo_surface_get_type(s) == CAIRO_SURFACE_TYPE_IMAGE) {
// use memory copy instead of using a Cairo context
int stride = cairo_image_surface_get_stride(s);
int h = cairo_image_surface_get_height(s);
} else {
// generic implementation
cairo_set_source_surface(ct, s, 0, 0);
}
return ns;
}
/** @brief Create a surface that differs only in pixel content.
* Creates a surface that has the same type, content type and dimensions
* as the specified surface. Pixel contents are not copied. */
{
return ns;
}
{
return ns;
}
/** @brief Extract the alpha channel into a new surface.
* Creates a surface with a content type of CAIRO_CONTENT_ALPHA that contains
* the alpha values of pixels from @a s. */
{
cairo_set_source_surface(ct, s, 0, 0);
return alpha;
}
{
} else {
}
return out;
}
void
{
{
// use memory copy instead of using a Cairo context
int h = cairo_image_surface_get_height(src);
} else {
// generic implementation
}
}
int
{
// For now only image surface is handled.
// Later add others, e.g. cairo-gl
return cairo_image_surface_get_width(surface);
}
int
{
return cairo_image_surface_get_height(surface);
}
/**
* @brief Convert pixel data from GdkPixbuf format to ARGB.
* This will convert pixel data from GdkPixbuf format to Cairo's native pixel format.
* This involves premultiplying alpha and shuffling around the channels.
* Pixbuf data must have an alpha channel, otherwise the results are undefined
* (usually a segfault).
*/
void
{
// TODO: optimize until it squeaks.
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
guint32 o = 0;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#else
guint32 a = (c & 0x000000ff);
#endif
if (a != 0) {
// extract color components
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
guint32 r = (c & 0x000000ff);
#else
#endif
// premultiply
r = premul_alpha(r, a);
b = premul_alpha(b, a);
g = premul_alpha(g, a);
// combine into output
o = (a << 24) | (r << 16) | (g << 8) | (b);
}
}
}
}
/**
* @brief Convert pixel data from ARGB to GdkPixbuf format.
* This will convert pixel data from GdkPixbuf format to Cairo's native pixel format.
* This involves premultiplying alpha and shuffling around the channels.
*/
void
{
// TODO: optimize until it squeaks.
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
guint32 o = 0;
if (a != 0) {
// extract color components
guint32 b = (c & 0x000000ff);
// unpremultiply; adding a/2 gives correct rounding
// (taken from Cairo sources)
r = (r * 255 + a/2) / a;
b = (b * 255 + a/2) / a;
g = (g * 255 + a/2) / a;
// combine into output
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
o = (r) | (g << 8) | (b << 16) | (a << 24);
#else
o = (r << 24) | (g << 16) | (b << 8) | (a);
#endif
}
}
}
}
/**
* @brief Converts GdkPixbuf's data to premultiplied ARGB.
* This function will convert a GdkPixbuf in place into Cairo's native pixel format.
* Note that this is a hack intended to save memory. When the pixbuf is Cairo's format,
* using it with GTK will result in corrupted drawings.
*/
void
{
}
/**
* @brief Converts GdkPixbuf's data back to its native format.
* Once this is done, the pixbuf can be used with GTK again.
*/
void
{
}
/*
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 :