summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
Diffstat (limited to 'src/display')
-rw-r--r--src/display/cairo-utils.cpp91
-rw-r--r--src/display/drawing-item.cpp14
-rw-r--r--src/display/drawing-item.h2
-rw-r--r--src/display/drawing-text.cpp23
4 files changed, 91 insertions, 39 deletions
diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp
index 5b358ade7..d6ff7b2f0 100644
--- a/src/display/cairo-utils.cpp
+++ b/src/display/cairo-utils.cpp
@@ -19,6 +19,7 @@
#include <glibmm/fileutils.h>
#include <2geom/pathvector.h>
#include <2geom/bezier-curve.h>
+#include <2geom/elliptical-arc.h>
#include <2geom/hvlinesegment.h>
#include <2geom/affine.h>
#include <2geom/point.h>
@@ -502,7 +503,17 @@ void Pixbuf::ensurePixelFormat(PixelFormat fmt)
static void
feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Affine const & trans, Geom::Rect view, bool optimize_stroke)
{
- if( is_straight_curve(c) )
+ using Geom::X;
+ using Geom::Y;
+
+ unsigned order = 0;
+ if (Geom::BezierCurve const* b = dynamic_cast<Geom::BezierCurve const*>(&c)) {
+ order = b->order();
+ }
+
+ // handle the three typical curve cases
+ switch (order) {
+ case 1:
{
Geom::Point end_tr = c.finalPoint() * trans;
if (!optimize_stroke) {
@@ -516,57 +527,97 @@ feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Affine const & tran
}
}
}
- else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast<Geom::QuadraticBezier const*>(&c)) {
+ break;
+ case 2:
+ {
+ Geom::QuadraticBezier const *quadratic_bezier = static_cast<Geom::QuadraticBezier const*>(&c);
std::vector<Geom::Point> points = quadratic_bezier->points();
points[0] *= trans;
points[1] *= trans;
points[2] *= trans;
+ // degree-elevate to cubic Bezier, since Cairo doesn't do quadratic Beziers
Geom::Point b1 = points[0] + (2./3) * (points[1] - points[0]);
Geom::Point b2 = b1 + (1./3) * (points[2] - points[0]);
if (!optimize_stroke) {
- cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]);
+ cairo_curve_to(cr, b1[X], b1[Y], b2[X], b2[Y], points[2][X], points[2][Y]);
} else {
Geom::Rect swept(points[0], points[2]);
swept.expandTo(points[1]);
if (swept.intersects(view)) {
- cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]);
+ cairo_curve_to(cr, b1[X], b1[Y], b2[X], b2[Y], points[2][X], points[2][Y]);
} else {
- cairo_move_to(cr, points[2][0], points[2][1]);
+ cairo_move_to(cr, points[2][X], points[2][Y]);
}
}
}
- else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast<Geom::CubicBezier const*>(&c)) {
+ break;
+ case 3:
+ {
+ Geom::CubicBezier const *cubic_bezier = static_cast<Geom::CubicBezier const*>(&c);
std::vector<Geom::Point> points = cubic_bezier->points();
//points[0] *= trans; // don't do this one here for fun: it is only needed for optimized strokes
points[1] *= trans;
points[2] *= trans;
points[3] *= trans;
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]);
+ cairo_curve_to(cr, points[1][X], points[1][Y], points[2][X], points[2][Y], points[3][X], points[3][Y]);
} else {
points[0] *= trans; // didn't transform this point yet
Geom::Rect swept(points[0], points[3]);
swept.expandTo(points[1]);
swept.expandTo(points[2]);
if (swept.intersects(view)) {
- cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]);
+ cairo_curve_to(cr, points[1][X], points[1][Y], points[2][X], points[2][Y], points[3][X], points[3][Y]);
} else {
- cairo_move_to(cr, points[3][0], points[3][1]);
+ cairo_move_to(cr, points[3][X], points[3][Y]);
}
}
}
-// 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
- Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1);
-
- //recurse to convert the new path resulting from the sbasis to svgd
- for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) {
- feed_curve_to_cairo(cr, *iter, trans, view, optimize_stroke);
+ break;
+ default:
+ {
+ if (Geom::EllipticalArc const *a = dynamic_cast<Geom::EllipticalArc const*>(&c)) {
+ //if (!optimize_stroke || a->boundsFast().intersects(view)) {
+ Geom::Affine xform = a->unitCircleTransform() * trans;
+ Geom::Point ang(a->initialAngle().radians(), a->finalAngle().radians());
+
+ // Apply the transformation to the current context
+ cairo_matrix_t cm;
+ cm.xx = xform[0];
+ cm.xy = xform[2];
+ cm.x0 = xform[4];
+ cm.yx = xform[1];
+ cm.yy = xform[3];
+ cm.y0 = xform[5];
+
+ cairo_save(cr);
+ cairo_transform(cr, &cm);
+
+ // Draw the circle
+ if (a->sweep()) {
+ cairo_arc(cr, 0, 0, 1, ang[0], ang[1]);
+ } else {
+ cairo_arc_negative(cr, 0, 0, 1, ang[0], ang[1]);
+ }
+ // Revert the current context
+ cairo_restore(cr);
+ //} else {
+ // Geom::Point f = a->finalPoint() * trans;
+ // cairo_move_to(cr, f[X], f[Y]);
+ //}
+ } else {
+ // handles sbasis as well as all other curve types
+ // this is very slow
+ Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1);
+
+ // recurse to convert the new path resulting from the sbasis to svgd
+ for (Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) {
+ feed_curve_to_cairo(cr, *iter, trans, view, optimize_stroke);
+ }
}
}
+ break;
+ }
}
@@ -579,7 +630,7 @@ feed_path_to_cairo (cairo_t *ct, Geom::Path const &path)
cairo_move_to(ct, path.initialPoint()[0], path.initialPoint()[1] );
- for(Geom::Path::const_iterator cit = path.begin(); cit != path.end_open(); ++cit) {
+ for (Geom::Path::const_iterator cit = path.begin(); cit != path.end_open(); ++cit) {
feed_curve_to_cairo(ct, *cit, Geom::identity(), Geom::Rect(), false); // optimize_stroke is false, so the view rect is not used
}
diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp
index 0bfb00b62..80eb69546 100644
--- a/src/display/drawing-item.cpp
+++ b/src/display/drawing-item.cpp
@@ -127,7 +127,7 @@ DrawingItem::DrawingItem(Drawing &drawing)
, _pick_children(0)
, _antialias(1)
, _isolation(SP_CSS_ISOLATION_AUTO)
- , _blend_mode(SP_CSS_BLEND_NORMAL)
+ , _mix_blend_mode(SP_CSS_BLEND_NORMAL)
{}
DrawingItem::~DrawingItem()
@@ -291,10 +291,10 @@ DrawingItem::setIsolation(unsigned isolation)
}
void
-DrawingItem::setBlendMode(unsigned blend_mode)
+DrawingItem::setBlendMode(unsigned mix_blend_mode)
{
- _blend_mode = blend_mode;
- //if( blend_mode != 0 ) std::cout << "setBlendMode: " << blend_mode << std::endl;
+ _mix_blend_mode = mix_blend_mode;
+ //if( mix_blend_mode != 0 ) std::cout << "setBlendMode: " << mix_blend_mode << std::endl;
_markForRendering();
}
@@ -592,7 +592,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag
if (_cached) {
if (_cache) {
_cache->prepare();
- set_cairo_blend_operator( dc, _blend_mode );
+ set_cairo_blend_operator( dc, _mix_blend_mode );
_cache->paintFromCache(dc, carea);
if (!carea) return RENDER_OK;
@@ -622,7 +622,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag
nir |= (_filter != NULL && render_filters); // 3. it has a filter
nir |= needs_opacity; // 4. it is non-opaque
nir |= (_cache != NULL); // 5. it is cached
- nir |= (_blend_mode != SP_CSS_BLEND_NORMAL); // 6. Blend mode not normal
+ nir |= (_mix_blend_mode != SP_CSS_BLEND_NORMAL); // 6. Blend mode not normal
nir |= (_isolation == SP_CSS_ISOLATION_ISOLATE); // 7. Explicit isolatiom
/* How the rendering is done.
@@ -735,7 +735,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag
}
dc.rectangle(*carea);
dc.setSource(&intermediate);
- set_cairo_blend_operator( dc, _blend_mode );
+ set_cairo_blend_operator( dc, _mix_blend_mode );
dc.fill();
dc.setSource(0,0,0,0);
// the call above is to clear a ref on the intermediate surface held by dc
diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h
index d89299eeb..925bcbddb 100644
--- a/src/display/drawing-item.h
+++ b/src/display/drawing-item.h
@@ -209,7 +209,7 @@ protected:
unsigned _antialias : 1; ///< Whether to use antialiasing
unsigned _isolation : 1;
- unsigned _blend_mode : 4;
+ unsigned _mix_blend_mode : 4;
friend class Drawing;
};
diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp
index 05a2c3c2a..9f3b447df 100644
--- a/src/display/drawing-text.cpp
+++ b/src/display/drawing-text.cpp
@@ -150,25 +150,26 @@ unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext
return STATE_ALL;
}
-DrawingItem *
-DrawingGlyphs::_pickItem(Geom::Point const &p, double delta, unsigned /*flags*/)
+DrawingItem *DrawingGlyphs::_pickItem(Geom::Point const &p, double /*delta*/, unsigned /*flags*/)
{
DrawingText *ggroup = dynamic_cast<DrawingText *>(_parent);
if (!ggroup) {
throw InvalidItemException();
}
+ DrawingItem *result = NULL;
bool invisible = (ggroup->_nrstyle.fill.type == NRStyle::PAINT_NONE) &&
(ggroup->_nrstyle.stroke.type == NRStyle::PAINT_NONE);
- if (!_font || !_bbox || (!_drawing.outline() && invisible) ) {
- return NULL;
- }
- // With text we take a simple approach: pick if the point is in a character bbox
- Geom::Rect expanded(_pick_bbox);
- // FIXME, why expand by delta? When is the next line needed?
- // expanded.expandBy(delta);
- if (expanded.contains(p)) return this;
- return NULL;
+ if (_font && _bbox && (_drawing.outline() || !invisible) ) {
+ // With text we take a simple approach: pick if the point is in a character bbox
+ Geom::Rect expanded(_pick_bbox);
+ // FIXME, why expand by delta? When is the next line needed?
+ // expanded.expandBy(delta);
+ if (expanded.contains(p)) {
+ result = this;
+ }
+ }
+ return result;
}