Discussion:
[cairo] Rectangle Border Widths
robertk54
2012-04-10 14:40:23 UTC
Permalink
Is it possible to render rectangles whose vertical lines are different in width from the horizontal lines? I have tried drawing separate lines for each side adjusting the line width for as needed. The result is a rectangle but there is a very slight gap where the lines meet. The gap is more noticeable as the color is made more transparent. Overlapping the lines works well for opaque colors but not for transparent. This is what I am currently doing . . .



cairo_new_sub_path (m_pCairo);
cairo_move_to (m_pCairo, m_dXPos+l_dBorderWidthV, m_dYPos+l_dBorderOffsetH);
cairo_line_to (m_pCairo, m_dXPos+m_dWidth-l_dBorderWidthV, m_dYPos+l_dBorderOffsetH);
cairo_move_to (m_pCairo, m_dXPos+l_dBorderWidthV, m_dYPos+m_dHeight-l_dBorderOffsetH);
cairo_line_to (m_pCairo, m_dXPos+m_dWidth-l_dBorderWidthV, m_dYPos+m_dHeight-l_dBorderOffsetH);
cairo_set_line_width (m_pCairo, l_dBorderWidthH);
cairo_stroke(m_pCairo);
cairo_set_line_width (m_pCairo, l_dBorderWidthV);
cairo_move_to (m_pCairo, m_dXPos+l_dBorderOffsetV, m_dYPos);
cairo_line_to (m_pCairo, m_dXPos+l_dBorderOffsetV, m_dYPos+m_dHeight);
cairo_move_to (m_pCairo, m_dXPos+m_dWidth-l_dBorderOffsetV, m_dYPos);
cairo_line_to (m_pCairo, m_dXPos+m_dWidth-l_dBorderOffsetV, m_dYPos+m_dHeight);
cairo_close_path (m_pCairo);
cairo_set_line_width (m_pCairo, l_dBorderWidthH);
cairo_stroke(m_pCairo);



Thanks,
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120410/aaed1c49/attachment.htm>
Chris Wilson
2012-04-10 14:53:55 UTC
Permalink
Post by robertk54
Is it possible to render rectangles whose vertical lines are different in width from the horizontal lines?
cairo_rectangle(cr, x, y, width, height);
cairo_save(cr);
cairo_scale(cr, stroke_width, stroke_height);
cairo_set_line_width(cr, 1);
cairo_stroke(cr);
cairo_restore(cr);

Have fun with Cairo!
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
robertk54
2012-04-10 18:29:33 UTC
Permalink
Post by Chris Wilson
Post by robertk54
Is it possible to render rectangles whose vertical lines are different in
width from the horizontal lines?
Post by Chris Wilson
cairo_rectangle(cr, x, y, width, height);
cairo_save(cr);
cairo_scale(cr, stroke_width, stroke_height);
cairo_set_line_width(cr, 1);
cairo_stroke(cr);
cairo_restore(cr);
Thanks Chris!
Given this solution, what are the resulting dimensions of the rectangles? Both the rectangle outside the line and the one within the line? I need to fill the inner rectangle with a color . I also need to use the inner rectangle for clipping other content which will be rendered on top of it.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120410/d3eed251/attachment.html>
Chris Wilson
2012-04-10 18:46:54 UTC
Permalink
Post by robertk54
Post by Chris Wilson
Post by robertk54
Is it possible to render rectangles whose vertical lines are different in
width from the horizontal lines?
Post by Chris Wilson
cairo_rectangle(cr, x, y, width, height);
cairo_save(cr);
cairo_scale(cr, stroke_width, stroke_height);
cairo_set_line_width(cr, 1);
cairo_stroke(cr);
cairo_restore(cr);
Thanks Chris!
Given this solution, what are the resulting dimensions of the rectangles? Both the rectangle outside the line and the one within the line? I need to fill the inner rectangle with a color . I also need to use the inner rectangle for clipping other content which will be rendered on top of it.
It should draw an outline between the two rectangles:
(x - stroke_width/2, y - stroke_height/2)
(x + stroke_width/2, y - stroke_height/2)
(x + stroke_width/2, y + stroke_height/2)
(x - stroke_width/2, y + stroke_height/2)
and
(x + stroke_width/2, y + stroke_height/2)
(x - stroke_width/2, y + stroke_height/2)
(x - stroke_width/2, y - stroke_height/2)
(x + stroke_width/2, y - stroke_height/2)

If you need to reuse only part of the stroked path, I'd recommend you
construct the outlines by hand (for the exercise ;).
-Chris

--
Chris Wilson, Intel Open Source Technology Centre
Travis Griggs
2012-04-10 22:25:20 UTC
Permalink
Post by robertk54
Post by Chris Wilson
Post by robertk54
Is it possible to render rectangles whose vertical lines are different in
width from the horizontal lines?
Post by Chris Wilson
cairo_rectangle(cr, x, y, width, height);
cairo_save(cr);
cairo_scale(cr, stroke_width, stroke_height);
cairo_set_line_width(cr, 1);
cairo_stroke(cr);
cairo_restore(cr);
This is a cool solution. Clever but simple.
Post by robertk54
Thanks Chris!
Given this solution, what are the resulting dimensions of the rectangles? Both the rectangle outside the line and the one within the line? I need to fill the inner rectangle with a color . I also need to use the inner rectangle for clipping other content which will be rendered on top of it.
If you're doing the above though?

Why not just do

cairo_rectangle(cr, ...outer_border_dimensions?);
cairo_set_source(cr, ?border color?);
cairo_fill(cr);
cairo_rectangle(cr, ?inner_border_dimensions?);
cairo_set_source(cr, ?fill color?);
cairo_fill_preserve(cr);
cairo_clip(cr);

?

--
Travis Griggs
Objologist
"Some of them wanted to sell me snake oil and I'm not necessarily going to dismiss all of these, as I have never found a rusty snake." --Terry Pratchett

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120410/32ad9200/attachment.htm>
Loading...