Commit c3256b97 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

graphics: add clipping path argument to strokePath

parent c58e0d9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ ReturnCode drawSeries(
  StrokeStyle style;
  style.line_width = series.line_width;
  style.colour = series.line_colour;
  strokePath(layer, path, style);
  strokePath(layer, clip, path, style);

  return OK;
}
+19 −3
Original line number Diff line number Diff line
@@ -37,15 +37,29 @@ void strokePath(
    Layer* layer,
    const Path& path,
    const StrokeStyle& style) {
  strokePath(layer, path.data(), path.size(), style);
  strokePath(
      layer,
      Rectangle(0, 0, layer->width, layer->height),
      path.data(),
      path.size(),
      style);
}

void strokePath(
    Layer* layer,
    const Rectangle& clip,
    const Path& path,
    const StrokeStyle& style) {
  strokePath(layer, clip, path.data(), path.size(), style);
}

void strokePath(
    Layer* layer,
    const Rectangle& clip,
    const PathData* point_data,
    size_t point_count,
    const StrokeStyle& style) {
  layer->rasterizer.strokePath(point_data, point_count, style);
  layer->rasterizer.strokePath(clip, point_data, point_count, style);
}

void strokeLine(
@@ -60,7 +74,9 @@ void strokeLine(
  p.lineTo(x2, y2);
  p.lineTo(x2, y2);
  p.lineTo(x2, y2);
  strokePath(layer, p.data(), p.size(), style);

  Rectangle clip(0, 0, layer->width, layer->height);
  strokePath(layer, clip, p.data(), p.size(), style);
}

} // namespace plotfx
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "colour.h"
#include "path.h"
#include "measure.h"
#include "layout.h"

namespace plotfx {
class Layer;
@@ -61,6 +62,13 @@ void strokePath(

void strokePath(
    Layer* layer,
    const Rectangle& clip,
    const Path& path,
    const StrokeStyle& style);

void strokePath(
    Layer* layer,
    const Rectangle& clip,
    const PathData* path_data,
    size_t path_data_count,
    const StrokeStyle& style);
+5 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ Rasterizer::~Rasterizer() {

/* rasterize using libcairo */
Status Rasterizer::strokePath(
    const Rectangle& clip,
    const PathData* path_data,
    size_t point_count,
    const StrokeStyle& style) {
@@ -78,6 +79,10 @@ Status Rasterizer::strokePath(

  cairo_set_line_width(cr_ctx, to_px(measures, style.line_width));

  cairo_rectangle(cr_ctx, clip.x, clip.y, clip.w, clip.h);
  cairo_clip(cr_ctx);
  cairo_new_path(cr_ctx);

  for (size_t i = 0; i < point_count; ++i) {
    const auto& cmd = path_data[i];
    switch (cmd.command) {
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@

#include "text.h"
#include "brush.h"
#include "layout.h"

namespace plotfx {
class Image;
@@ -59,6 +60,7 @@ public:
  Rasterizer& operator=(const Rasterizer&) = delete;

  Status strokePath(
      const Rectangle& clip,
      const PathData* point_data,
      size_t point_count,
      const StrokeStyle& style);