summaryrefslogtreecommitdiff
path: root/src/cairo.c
diff options
context:
space:
mode:
authorRick Yorgason <rick@firefang.com>2021-08-15 06:58:54 +0000
committerAdrian Johnson <ajohnson@redneon.com>2021-08-15 06:58:54 +0000
commitecec0419f8e178d71e449b52acfdfe9ac03aed37 (patch)
treee6ede3cdc9a0ae02a6f56dfec38ff8b05cdcf9bb /src/cairo.c
parent4dd48f0979f693dfc515eb3eff266ec6429f8b33 (diff)
downloadcairo-ecec0419f8e178d71e449b52acfdfe9ac03aed37.tar.gz
Added hairline support to cairo
Diffstat (limited to 'src/cairo.c')
-rw-r--r--src/cairo.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/cairo.c b/src/cairo.c
index b2bda657d..d141b56d2 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -1185,6 +1185,47 @@ cairo_set_line_width (cairo_t *cr, double width)
slim_hidden_def (cairo_set_line_width);
/**
+ * cairo_set_hairline:
+ * @cr: a #cairo_t
+ * @set_hairline: whether or not to set hairline mode
+ *
+ * Sets lines within the cairo context to be hairlines.
+ * Hairlines are logically zero-width lines that are drawn at the
+ * thinnest renderable width possible in the current context.
+ *
+ * On surfaces with native hairline support, the native hairline
+ * functionality will be used. Surfaces that support hairlines include:
+ * - pdf/ps: Encoded as 0-width line.
+ * - win32_printing: Rendered with PS_COSMETIC pen.
+ * - svg: Encoded as 1px non-scaling-stroke.
+ * - script: Encoded with set-hairline function.
+ *
+ * Cairo will always render hairlines at 1 device unit wide, even if
+ * an anisotropic scaling was applied to the stroke width. In the wild,
+ * handling of this situation is not well-defined. Some PDF, PS, and SVG
+ * renderers match Cairo's output, but some very popular implementations
+ * (Acrobat, Chrome, rsvg) will scale the hairline unevenly.
+ * As such, best practice is to reset any anisotropic scaling before calling
+ * cairo_stroke(). See https://cairographics.org/cookbook/ellipses/
+ * for an example.
+ *
+ * Since: 1.18
+ **/
+void
+cairo_set_hairline (cairo_t *cr, cairo_bool_t set_hairline)
+{
+ cairo_status_t status;
+
+ if (unlikely (cr->status))
+ return;
+
+ status = cr->backend->set_hairline (cr, set_hairline);
+ if (unlikely (status))
+ _cairo_set_error (cr, status);
+}
+slim_hidden_def (cairo_set_hairline);
+
+/**
* cairo_set_line_cap:
* @cr: a cairo context
* @line_cap: a line cap style
@@ -4058,6 +4099,26 @@ cairo_get_line_width (cairo_t *cr)
slim_hidden_def (cairo_get_line_width);
/**
+ * cairo_get_hairline:
+ * @cr: a cairo context
+ *
+ * Returns whether or not hairline mode is set, as set by cairo_set_hairline().
+ *
+ * Return value: whether hairline mode is set.
+ *
+ * Since: 1.18
+ **/
+cairo_bool_t
+cairo_get_hairline (cairo_t *cr)
+{
+ if (unlikely (cr->status))
+ return FALSE;
+
+ return cr->backend->get_hairline (cr);
+}
+slim_hidden_def (cairo_get_hairline);
+
+/**
* cairo_get_line_cap:
* @cr: a cairo context
*