From 146b9af96c87c0e7fd2d1d7212fa617fb770ad3d Mon Sep 17 00:00:00 2001 From: maxmattone Date: Tue, 17 Aug 2021 16:16:04 +0100 Subject: [PATCH 1/4] Rendering ellipses as ellipses --- src/Athens-SVG/ASEllipse.class.st | 45 ++++++++++++++++++++++--------- src/Athens-SVG/ASPath.class.st | 2 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/Athens-SVG/ASEllipse.class.st b/src/Athens-SVG/ASEllipse.class.st index c58e2c5..a32b766 100644 --- a/src/Athens-SVG/ASEllipse.class.st +++ b/src/Athens-SVG/ASEllipse.class.st @@ -29,6 +29,33 @@ If the attribute is not specified, the effect is as if a value of 0 were specifi cy := self translateLength: aString ] +{ #category : #'as yet unclassified' } +ASEllipse >> ellipseToPhath [ +| kappa ox oy conv stream | +"Please refer to https://stackoverflow.com/questions/59011294/ellipse-to-path-convertion-using-javascript for implementation details" +kappa := 0.5522847498. +ox := rx * kappa. "x offset for the control point" +oy := ry * kappa. "y offset for the control point" +stream := ReadWriteStream on: (String new: 10). +stream << 'M' << (cx - rx) asString << $, << cy asString + <<'C' << (cx - rx) asString << ', ' << (cy - oy) asString + << ', ' << (cx - ox) asString << ', ' << (cy - ry) asString + << ', ' << cx asString << ', ' << (cy - ry) asString + << ',C' << (cx + ox) asString << ', ' << (cy - ry) asString + << ', ' << (cx + rx) asString << ', ' << (cy - oy) asString + << ', ' << (cx + rx) asString << ', ' << cy asString + << ',C' << (cx + rx) asString << ', ' << (cy + oy) asString + << ', ' << (cx + ox) asString << ', ' << (cy + ry) asString + << ', ' << cx asString << ', ' << (cy + ry) asString + << ',C' << (cx - ox) asString << ', ' << (cy + ry) asString + << ', ' << (cx - rx) asString << ', ' << (cy + oy) asString + << ', ' << (cx - rx) asString << ', ' << cy asString + << ',z'. +Transcript show: stream contents; cr. +conv := ASPathConverter new stream: stream contents readStream. +^ conv convertPathData +] + { #category : #'as yet unclassified' } ASEllipse >> rx: aString [ @@ -47,17 +74,11 @@ ASEllipse >> ry: aString [ { #category : #'as yet unclassified' } ASEllipse >> setShapeOn: aCanvas [ - | circle | - - - circle := aCanvas createPath: [:builder | - builder - absolute; - moveTo: (cx - rx @ cy); - cwArcTo: (cx + rx @ cy ) angle: 180 degreesToRadians; - cwArcTo: (cx - rx @ cy) angle: 180 degreesToRadians + | ellipse | + ellipse := aCanvas createPath: [:builder | + self ellipseToPhath do: [:each | + builder perform: each first withArguments: each second + ] ]. - - aCanvas setShape: circle. - + aCanvas setShape: ellipse. ] diff --git a/src/Athens-SVG/ASPath.class.st b/src/Athens-SVG/ASPath.class.st index 3d34eaa..891d94a 100644 --- a/src/Athens-SVG/ASPath.class.st +++ b/src/Athens-SVG/ASPath.class.st @@ -40,7 +40,7 @@ ASPath >> d: aString [ | conv | conv := ASPathConverter new stream: aString readStream. - + Transcript show: aString; cr. pathData := conv convertPathData. bbox := conv bbox. ] From 0d1b35c61b7ea46067ef5234cbb281f52b0d859f Mon Sep 17 00:00:00 2001 From: maxmattone Date: Tue, 17 Aug 2021 16:17:43 +0100 Subject: [PATCH 2/4] remove debugging logs --- src/Athens-SVG/ASEllipse.class.st | 1 - src/Athens-SVG/ASPath.class.st | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Athens-SVG/ASEllipse.class.st b/src/Athens-SVG/ASEllipse.class.st index a32b766..4920cd3 100644 --- a/src/Athens-SVG/ASEllipse.class.st +++ b/src/Athens-SVG/ASEllipse.class.st @@ -51,7 +51,6 @@ stream << 'M' << (cx - rx) asString << $, << cy asString << ', ' << (cx - rx) asString << ', ' << (cy + oy) asString << ', ' << (cx - rx) asString << ', ' << cy asString << ',z'. -Transcript show: stream contents; cr. conv := ASPathConverter new stream: stream contents readStream. ^ conv convertPathData ] diff --git a/src/Athens-SVG/ASPath.class.st b/src/Athens-SVG/ASPath.class.st index 891d94a..e73023c 100644 --- a/src/Athens-SVG/ASPath.class.st +++ b/src/Athens-SVG/ASPath.class.st @@ -40,7 +40,6 @@ ASPath >> d: aString [ | conv | conv := ASPathConverter new stream: aString readStream. - Transcript show: aString; cr. pathData := conv convertPathData. bbox := conv bbox. ] From 69ceb78e42d0e157c3425b35f3a3bb5892c0b0f2 Mon Sep 17 00:00:00 2001 From: maxmattone Date: Tue, 17 Aug 2021 16:18:10 +0100 Subject: [PATCH 3/4] typo --- src/Athens-SVG/ASPath.class.st | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Athens-SVG/ASPath.class.st b/src/Athens-SVG/ASPath.class.st index e73023c..c65c0e8 100644 --- a/src/Athens-SVG/ASPath.class.st +++ b/src/Athens-SVG/ASPath.class.st @@ -40,6 +40,7 @@ ASPath >> d: aString [ | conv | conv := ASPathConverter new stream: aString readStream. + pathData := conv convertPathData. bbox := conv bbox. ] From c51509818745f1425dad9fff4aac2f1f3b7fb6ff Mon Sep 17 00:00:00 2001 From: maxmattone Date: Tue, 17 Aug 2021 16:19:01 +0100 Subject: [PATCH 4/4] formatting whitespaces --- src/Athens-SVG/ASPath.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Athens-SVG/ASPath.class.st b/src/Athens-SVG/ASPath.class.st index c65c0e8..3d34eaa 100644 --- a/src/Athens-SVG/ASPath.class.st +++ b/src/Athens-SVG/ASPath.class.st @@ -40,7 +40,7 @@ ASPath >> d: aString [ | conv | conv := ASPathConverter new stream: aString readStream. - + pathData := conv convertPathData. bbox := conv bbox. ]