Commit 47999da2 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improved layer setup, run test suite on both .svg and .png outputs

parent de69aae0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -90,3 +90,13 @@ foreach(spec_test_path ${spec_test_files})
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_runner.sh ${CMAKE_CURRENT_BINARY_DIR}/plotfx ${spec_test_path} ${CMAKE_CURRENT_BINARY_DIR}/${spec_test_name}.svg ${spec_test_srcdir}/${spec_test_name}.svg)
endforeach()

file(GLOB spec_test_files "tests/**/test_*.plot")
foreach(spec_test_path ${spec_test_files})
  get_filename_component(spec_test_name ${spec_test_path} NAME_WE)
  get_filename_component(spec_test_srcdir ${spec_test_path} DIRECTORY)
  add_test(
      NAME ${spec_test_name}_png
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_runner.sh ${CMAKE_CURRENT_BINARY_DIR}/plotfx ${spec_test_path} ${CMAKE_CURRENT_BINARY_DIR}/${spec_test_name}.png ${spec_test_srcdir}/${spec_test_name}.png)
endforeach()
+1 −10
Original line number Diff line number Diff line
@@ -34,16 +34,7 @@

namespace plotfx {

Layer::Layer(
    double w,
    double h,
    const MeasureTable& m /* = MeasureTable{} */) :
    width(w),
    height(h),
    measures(m),
    text_shaper(m.dpi) {}

Layer::~Layer() {}
//Layer::Layer() : width(0), height(0) {}

} // namespace plotfx
+10 −16
Original line number Diff line number Diff line
@@ -43,23 +43,17 @@
namespace plotfx {

struct Layer {
  Layer();
  Layer(double width, double height, const MeasureTable& measures = MeasureTable{});
  ~Layer();
  Layer(const Layer&) = delete;
  Layer& operator=(const Layer&) = delete;

  double width;
  double height;
  MeasureTable measures;
  Colour background_colour;

  std::function<Status (const BrushStrokeOp&)> op_brush_stroke;
  std::function<Status (const BrushFillOp&)> op_brush_fill;
  std::function<Status (const TextSpanOp&)> op_text_span;

  text::TextShaper text_shaper;
  const double width;
  const double height;
  const MeasureTable measures;
  const std::shared_ptr<text::TextShaper> text_shaper;
  const std::function<Status (const BrushStrokeOp&)> op_brush_stroke;
  const std::function<Status (const BrushFillOp&)> op_brush_fill;
  const std::function<Status (const TextSpanOp&)> op_text_span;
  const std::function<std::string ()> data;
};

using LayerRef = std::unique_ptr<Layer>;

} // namespace plotfx
+28 −16
Original line number Diff line number Diff line
@@ -31,23 +31,35 @@

namespace plotfx {

ReturnCode layer_new_pixmap(Layer* layer, Rasterizer* raster) {
  raster->clear(layer->background_colour);
ReturnCode layer_bind_png(
    double width,
    double height,
    const MeasureTable& measures,
    const Colour& background_colour,
    LayerRef* layer) {
  auto text_shaper = std::make_shared<text::TextShaper>();
  auto raster = std::make_shared<Rasterizer>(width, height, measures, text_shaper);
  raster->clear(background_colour);

  layer->op_brush_stroke = std::bind(
  layer->reset(new Layer {
    .width = width,
    .height = height,
    .measures = measures,
    .text_shaper = text_shaper,
    .op_brush_stroke = std::bind(
        &Rasterizer::strokePath,
      raster,
      std::placeholders::_1);

  layer->op_brush_fill = std::bind(
        raster.get(), // safe
        std::placeholders::_1),
    .op_brush_fill = std::bind(
        &Rasterizer::fillPath,
      raster,
      std::placeholders::_1);

  layer->op_text_span = std::bind(
        raster.get(), // safe
        std::placeholders::_1),
    .op_text_span = std::bind(
        &Rasterizer::drawText,
      raster,
      std::placeholders::_1);
        raster.get(), // safe
        std::placeholders::_1),
    .data = [raster] { return raster->to_png(); },
  });

  return OK;
}
+6 −1
Original line number Diff line number Diff line
@@ -33,7 +33,12 @@
namespace plotfx {
class Rasterizer;

ReturnCode layer_new_pixmap(Layer* layer, Rasterizer* raster);
ReturnCode layer_bind_png(
    double width,
    double height,
    const MeasureTable& measures,
    const Colour& background_colour,
    LayerRef* layer);

} // namespace plotfx
Loading