stroke: Add miter limit
Add a miter limit to GskStroke. This will be needed to fully implement line joins. Also introduce the GSK_LINE_JOIN_MITER_CLIP value, following SVG 2.0. cairo does not have it, so translate it to plain miter when using cairo.
This commit is contained in:
@@ -225,6 +225,7 @@ typedef enum {
|
|||||||
/**
|
/**
|
||||||
* GskLineJoin:
|
* GskLineJoin:
|
||||||
* @GSK_LINE_JOIN_MITER: Use a sharp, angled corner
|
* @GSK_LINE_JOIN_MITER: Use a sharp, angled corner
|
||||||
|
* @GSK_LINE_JOIN_MITER_CLIP: Use a sharp, angled corner, at a distance
|
||||||
* @GSK_LINE_JOIN_ROUND: Use a round join, the center of the circle is
|
* @GSK_LINE_JOIN_ROUND: Use a round join, the center of the circle is
|
||||||
* the joint point
|
* the joint point
|
||||||
* @GSK_LINE_JOIN_BEVEL: Use a cut-off join, the join is cut off at half
|
* @GSK_LINE_JOIN_BEVEL: Use a cut-off join, the join is cut off at half
|
||||||
@@ -232,10 +233,14 @@ typedef enum {
|
|||||||
*
|
*
|
||||||
* Specifies how to render the junction of two lines when stroking.
|
* Specifies how to render the junction of two lines when stroking.
|
||||||
*
|
*
|
||||||
|
* See gsk_stroke_set_miter_limit() for details on the difference between
|
||||||
|
* @GSK_LINE_JOIN_MITER and @GSK_LINE_JOIN_MITER_CLIP.
|
||||||
|
*
|
||||||
* The default line join style is %GSK_LINE_JOIN_MITER.
|
* The default line join style is %GSK_LINE_JOIN_MITER.
|
||||||
**/
|
**/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GSK_LINE_JOIN_MITER,
|
GSK_LINE_JOIN_MITER,
|
||||||
|
GSK_LINE_JOIN_MITER_CLIP,
|
||||||
GSK_LINE_JOIN_ROUND,
|
GSK_LINE_JOIN_ROUND,
|
||||||
GSK_LINE_JOIN_BEVEL
|
GSK_LINE_JOIN_BEVEL
|
||||||
} GskLineJoin;
|
} GskLineJoin;
|
||||||
|
@@ -65,6 +65,9 @@ gsk_stroke_new (float line_width)
|
|||||||
self = g_new0 (GskStroke, 1);
|
self = g_new0 (GskStroke, 1);
|
||||||
|
|
||||||
self->line_width = line_width;
|
self->line_width = line_width;
|
||||||
|
self->line_cap = GSK_LINE_CAP_BUTT;
|
||||||
|
self->line_join = GSK_LINE_JOIN_MITER;
|
||||||
|
self->miter_limit = 4.f; /* following svg */
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -135,6 +138,7 @@ gsk_stroke_to_cairo (const GskStroke *self,
|
|||||||
switch (self->line_join)
|
switch (self->line_join)
|
||||||
{
|
{
|
||||||
case GSK_LINE_JOIN_MITER:
|
case GSK_LINE_JOIN_MITER:
|
||||||
|
case GSK_LINE_JOIN_MITER_CLIP:
|
||||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
|
||||||
break;
|
break;
|
||||||
case GSK_LINE_JOIN_ROUND:
|
case GSK_LINE_JOIN_ROUND:
|
||||||
@@ -147,6 +151,8 @@ gsk_stroke_to_cairo (const GskStroke *self,
|
|||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_set_miter_limit (cr, self->miter_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,3 +274,40 @@ gsk_stroke_get_line_join (const GskStroke *self)
|
|||||||
return self->line_join;
|
return self->line_join;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gsk_stroke_set_miter_limit:
|
||||||
|
* @self: a #GskStroke
|
||||||
|
* @limit: the miter limit, must be non-negative
|
||||||
|
*
|
||||||
|
* Sets the limit for the distance from the corner where sharp
|
||||||
|
* turns of joins get cut off. The miter limit is in units of
|
||||||
|
* line width.
|
||||||
|
*
|
||||||
|
* For joins of type %GSK_LINE_JOIN_MITER that exceed the miter
|
||||||
|
* limit, the join gets rendered as if it was of type
|
||||||
|
* %GSK_LINE_JOIN_BEVEL. For joins of type %GSK_LINE_JOIN_MITER_CLIP,
|
||||||
|
* the miter is clipped at a distance of half the miter limit.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gsk_stroke_set_miter_limit (GskStroke *self,
|
||||||
|
float limit)
|
||||||
|
{
|
||||||
|
g_return_if_fail (self != NULL);
|
||||||
|
g_return_if_fail (limit >= 0);
|
||||||
|
|
||||||
|
self->miter_limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gsk_stroke_get_miter_limit:
|
||||||
|
* @self: a #GskStroke
|
||||||
|
*
|
||||||
|
* Returns the miter limit of a #GskStroke.
|
||||||
|
*/
|
||||||
|
float
|
||||||
|
gsk_stroke_get_miter_limit (const GskStroke *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (self != NULL, 4.f);
|
||||||
|
|
||||||
|
return self->miter_limit;
|
||||||
|
}
|
||||||
|
@@ -60,6 +60,12 @@ void gsk_stroke_set_line_join (GskStroke
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GskLineJoin gsk_stroke_get_line_join (const GskStroke *self);
|
GskLineJoin gsk_stroke_get_line_join (const GskStroke *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
void gsk_stroke_set_miter_limit (GskStroke *self,
|
||||||
|
float limit);
|
||||||
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
float gsk_stroke_get_miter_limit (const GskStroke *self);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@ struct _GskStroke
|
|||||||
float line_width;
|
float line_width;
|
||||||
GskLineCap line_cap;
|
GskLineCap line_cap;
|
||||||
GskLineJoin line_join;
|
GskLineJoin line_join;
|
||||||
|
float miter_limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
Reference in New Issue
Block a user