13
0

workaround/hack/fix for cairo pattern gradient space exceeding 2^16 size limit

This commit is contained in:
Paul Davis 2013-06-27 10:41:00 -04:00
parent f9936d7d3c
commit 0e656f0a13
5 changed files with 37 additions and 30 deletions

View File

@ -879,7 +879,7 @@ TimeAxisViewItem::set_frame_gradient ()
ArdourCanvas::Color darker = ArdourCanvas::hsv_to_color (h, s, v, a);
stops.push_back (std::make_pair (1.0, darker));
frame->set_gradient (stops, _height);
frame->set_gradient (stops, true);
}
/**

View File

@ -44,14 +44,16 @@ public:
typedef std::vector<std::pair<double,Color> > StopList;
void set_gradient (StopList const & stops, double height);
void set_gradient (StopList const & stops, bool is_vertical);
protected:
void setup_fill_context (Cairo::RefPtr<Cairo::Context>) const;
void setup_gradient_context (Cairo::RefPtr<Cairo::Context>, Rect const &, Duple const &) const;
Color _fill_color;
bool _fill;
Cairo::RefPtr<Cairo::LinearGradient> _gradient;
StopList _stops;
bool _vertical_gradient;
};
}

View File

@ -59,37 +59,39 @@ Fill::set_fill (bool fill)
void
Fill::setup_fill_context (Cairo::RefPtr<Cairo::Context> context) const
{
if (_gradient) {
Cairo::Matrix m;
Duple origin = item_to_window (Duple (0, 0));
context->translate (origin.x, origin.y);
context->set_source (_gradient);
context->translate (-origin.x, -origin.y);
} else {
set_source_rgba (context, _fill_color);
}
set_source_rgba (context, _fill_color);
}
void
Fill::set_gradient (StopList const & stops, double height)
Fill::setup_gradient_context (Cairo::RefPtr<Cairo::Context> context, Rect const & self, Duple const & draw_origin) const
{
Cairo::RefPtr<Cairo::LinearGradient> _gradient;
if (_vertical_gradient) {
_gradient = Cairo::LinearGradient::create (draw_origin.x, self.y0, draw_origin.x, self.y1);
} else {
_gradient = Cairo::LinearGradient::create (self.x0, draw_origin.y, self.x1, draw_origin.y);
}
for (StopList::const_iterator s = _stops.begin(); s != _stops.end(); ++s) {
double r, g, b, a;
color_to_rgba (s->second, r, g, b, a);
_gradient->add_color_stop_rgba (s->first, r, g, b, a);
}
context->set_source (_gradient);
}
void
Fill::set_gradient (StopList const & stops, bool vertical)
{
begin_visual_change ();
if (stops.empty()) {
_gradient.clear();
_stops.clear ();
} else {
double r, g, b, a;
_gradient = Cairo::LinearGradient::create (0, 0, 0, height);
for (StopList::const_iterator s = stops.begin(); s != stops.end(); ++s) {
color_to_rgba (s->second, r, g, b, a);
_gradient->add_color_stop_rgba (s->first, r, g, b, a);
}
_stops = stops;
_vertical_gradient = vertical;
}
end_visual_change ();

View File

@ -72,7 +72,11 @@ Rectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) con
Rect stroke_rect = fill_rect.expand (0.5);
if (_fill) {
setup_fill_context (context);
if (_stops.empty()) {
setup_fill_context (context);
} else {
setup_gradient_context (context, self, Duple (draw.x0, draw.y0));
}
context->rectangle (fill_rect.x0, fill_rect.y0, fill_rect.width(), fill_rect.height());
context->fill ();
}

View File

@ -151,8 +151,7 @@ Text::compute_bounding_box () const
Pango::Rectangle const r = layout->get_ink_extents ();
_bounding_box = Rect (
r.get_x() / Pango::SCALE,
r.get_y() / Pango::SCALE,
0, 0,
(r.get_x() + r.get_width()) / Pango::SCALE,
(r.get_y() + r.get_height()) / Pango::SCALE
);