From 8a7cfe972c4a3305b5a8e8f45691a17e48125d40 Mon Sep 17 00:00:00 2001 From: David Warring Date: Mon, 9 Dec 2024 06:41:36 +1300 Subject: [PATCH] Tweak current-point() method #26 --- docs/PDF/Content/Ops.md | 4 ++-- lib/PDF/Content/Ops.rakumod | 6 +++--- t/current-point.t | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/PDF/Content/Ops.md b/docs/PDF/Content/Ops.md index 112b115..836f8c6 100644 --- a/docs/PDF/Content/Ops.md +++ b/docs/PDF/Content/Ops.md @@ -87,12 +87,12 @@ return all current graphics state variables ### method current-point ```raku -method current-point() returns PDF::Content::Ops::Vector +method current-point() returns List ``` return current point -This method is only valid in a path context +This method returns the x,y position of current point in a path context, or an empty list otherwise ### multi method op diff --git a/lib/PDF/Content/Ops.rakumod b/lib/PDF/Content/Ops.rakumod index 733df23..207c2c6 100644 --- a/lib/PDF/Content/Ops.rakumod +++ b/lib/PDF/Content/Ops.rakumod @@ -881,11 +881,11 @@ method is-graphics-op($op-name) { my subset Vector of List is export(:Vector) where {.elems == 2 && .&are ~~ Numeric} #| return current point -method current-point is rw returns Vector { +method current-point is rw returns List { sub FETCH($) { $!context == Path ?? ($!cur-x, $!cur-y) - !! (Numeric, Numeric) + !! () } sub STORE($, Vector \v) { unless $!context == Path && $!cur-x =~= v[0] && $!cur-x =~= v[1] { @@ -894,7 +894,7 @@ method current-point is rw returns Vector { } Proxy.new: :&FETCH, :&STORE; } -=para This method is only valid in a path context +=para This method returns the x,y position of current point in a path context, or an empty list otherwise #| process operator quarantined by PDF::Grammar::Content / PDF::Native::COS as either an #| unknown operator or having an incorrect argument list diff --git a/t/current-point.t b/t/current-point.t index f989fae..ab95b16 100644 --- a/t/current-point.t +++ b/t/current-point.t @@ -1,6 +1,6 @@ use Test; use PDF::Grammar::Test :&is-json-equiv; -plan 8; +plan 10; use lib 't'; use PDFTiny; @@ -26,9 +26,11 @@ given $pdf.add-page.gfx { .ClosePath; is-deeply .current-point, (40, 42); + ok .current-point; .Stroke; - is-deeply .current-point, (Numeric, Numeric); + is-deeply .current-point, List; + nok .current-point; } done-testing;