Commit 8d5b6e7c authored by Paul Asmuth's avatar Paul Asmuth
Browse files

switch to using a coordinate system where positive y extends upwards

parent 450f0481
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ ReturnCode font_get_glyph_path(
    assert(c.points.size() == c.tags.size());

    // translate the resolved contour to the path object representation
    path->moveTo(c.points[0].x, c.points[0].y);
    path->moveTo(c.points[0].x, -c.points[0].y);

    for (size_t i = 0; i < c.points.size() - 1; ) {
      const auto& p = c.points[i];
@@ -188,7 +188,7 @@ ReturnCode font_get_glyph_path(
      if (i + 1 < c.points.size() &&
          c.tags[i + 0] == GlyphPointType::ON &&
          c.tags[i + 1] == GlyphPointType::ON) {
        path->lineTo(c.points[i + 1].x, c.points[i + 1].y);
        path->lineTo(c.points[i + 1].x, -c.points[i + 1].y);
        i += 1;
        continue;
      }
@@ -201,11 +201,11 @@ ReturnCode font_get_glyph_path(
          c.tags[i + 3] == GlyphPointType::ON) {
        path->cubicCurveTo(
            c.points[i + 1].x,
            c.points[i + 1].y,
            -c.points[i + 1].y,
            c.points[i + 2].x,
            c.points[i + 2].y,
            -c.points[i + 2].y,
            c.points[i + 3].x,
            c.points[i + 3].y);
            -c.points[i + 3].y);

        i += 3;
        continue;
@@ -218,9 +218,9 @@ ReturnCode font_get_glyph_path(
          c.tags[i + 2] == GlyphPointType::ON) {
        path->quadraticCurveTo(
            c.points[i + 1].x,
            c.points[i + 1].y,
            -c.points[i + 1].y,
            c.points[i + 2].x,
            c.points[i + 2].y);
            -c.points[i + 2].y);

        i += 2;
        continue;
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ Rectangle layout_margin_box(
    double margin_left) {
  Rectangle box;
  box.x = parent.x + margin_left;
  box.y = parent.y + margin_top;
  box.y = parent.y + margin_bottom;
  box.w = std::max(parent.w - (margin_left + margin_right), 0.0);
  box.h = std::max(parent.h - (margin_top + margin_bottom), 0.0);
  return box;
@@ -59,10 +59,10 @@ Point layout_align(

  switch (align_y) {
    case VAlign::TOP:
      target.y += bbox.h / 2;
      target.y -= bbox.h / 2;
      break;
    case VAlign::BOTTOM:
      target.y -= bbox.h / 2;
      target.y += bbox.h / 2;
      break;
    case VAlign::CENTER:
      break;
+2 −2
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ void convert_unit_relative(
  switch (measure->unit) {
    case Unit::REL:
      measure->unit = Unit::UNIT;
      measure->value = std::clamp(measure->value, 0.0, 1.0) * range;
      measure->value = measure->value * range;
      break;
  }
}
@@ -167,7 +167,7 @@ void convert_unit_user(
  switch (measure->unit) {
    case Unit::USER:
      measure->unit = Unit::REL;
      measure->value = std::clamp(converter(measure->value), 0.0, 1.0);
      measure->value = converter(measure->value);
      break;
  }
}
+4 −2
Original line number Diff line number Diff line
@@ -28,12 +28,14 @@ namespace fviz {
struct PageTextElement {
  std::string text;
  std::vector<text::GlyphPlacementGroup> glyphs;

  // The `origin` refers to the start of the baseline
  Point origin;
  double rotate;
  Point rotate_pivot;

  TextStyle style;
  std::optional<uint32_t> zindex;
  Rectangle clip;
  std::optional<mat3> transform;
};

struct PageShapeElement {
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ ReturnCode page_export_png(
  std::vector<DrawOp> ops;
  for (const auto& e : page.text_elements) {
    DrawOp op;
    op.draw_fn = bind(&Rasterizer::drawText, _1, e.glyphs, e.style);
    op.draw_fn = bind(&Rasterizer::drawText, _1, e.glyphs, e.style, e.transform);
    op.draw_idx = e.zindex.value_or(0);
    ops.push_back(op);
  }
Loading