Skip to content

Commit

Permalink
AeCairoContext API: Use stroke* and *PreservingPath to better communi…
Browse files Browse the repository at this point in the history
…cate actual behavior

See #82
  • Loading branch information
tinchodias committed Dec 11, 2024
1 parent f9fa8f3 commit 26832e6
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 74 deletions.
42 changes: 21 additions & 21 deletions src/Alexandrie-Cairo-Tests/AeCairoContextTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,6 @@ AeCairoContextTest >> testGlyphExtentsOf [
self assert: aTextExtents advance closeTo: 34@0
]

{ #category : #tests }
AeCairoContextTest >> testLineWidth [

surface := AeCairoImageSurface extent: 1@1.
context := surface newContext.

"Assert on default value"
self assert: context lineWidth equals: 2.0.

context lineWidth: 7.

"Assert on new value"
self assert: context lineWidth equals: 7.0
]

{ #category : #tests }
AeCairoContextTest >> testOperator [

Expand Down Expand Up @@ -264,7 +249,7 @@ AeCairoContextTest >> testPathExtents [
scaleByX: 0.5 y: 2;
moveTo: 5 @ 10;
lineTo: 90 @ 50;
fillPreserve.
fillPreservingPath.

self
assert: context pathExtentsInUserSpace
Expand Down Expand Up @@ -354,12 +339,12 @@ AeCairoContextTest >> testStrokeExtents [
equals: (Rectangle origin: 0 asPoint extent: 0 asPoint).

context
translateBy: -1 @ -2;
translateByX: -1 y: -2;
scaleByX: 0.5 y: 2;
moveTo: 5 @ 10;
lineTo: 90 @ 50;
lineWidth: 10;
strokePreserve.
moveToX: 5 y: 10;
lineToX: 90 y: 50;
strokeSize: 10;
strokePreservingPath.

self
assert: context strokeExtentsInUserSpace
Expand All @@ -378,3 +363,18 @@ AeCairoContextTest >> testStrokeExtents [
equals: (Rectangle origin: -1 @ -2 extent: 0 asPoint).

]

{ #category : #tests }
AeCairoContextTest >> testStrokeSize [

surface := AeCairoImageSurface extent: 1@1.
context := surface newContext.

"Assert on default value"
self assert: context strokeSize equals: 2.0.

context strokeSize: 7.

"Assert on new value"
self assert: context strokeSize equals: 7.0
]
26 changes: 13 additions & 13 deletions src/Alexandrie-Cairo-Tests/AeCairoExamplesRenderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,24 @@ AeCairoExamplesRenderTest >> surfaceWithDottedCircle [
"stroke with black squared dots"
aContext
sourceColor: Color black;
lineCap: AeCairoCapStyle square;
lineWidth: lineWidth;
strokePreserve.
useLineCapSquare;
strokeSize: lineWidth;
strokePreservingPath.
self assert: aContext dashes equals: dashByteArray.
self assert: aContext hasCurrentPoint.

"stroke with green circle dots"
aContext
sourceColor: Color green;
lineWidth: lineWidth/1.5;
lineCap: AeCairoCapStyle round;
strokePreserve.
strokeSize: lineWidth/1.5;
useLineCapRound;
strokePreservingPath.
self assert: aContext dashes equals: dashByteArray.

"stroke red without dashes"
aContext
sourceColor: Color red;
lineWidth: 1;
strokeSize: 1;
dashDisable;
stroke.
self assert: aContext dashes equals: #().
Expand Down Expand Up @@ -600,7 +600,7 @@ AeCairoExamplesRenderTest >> surfaceWithRoundedRectangle [
bl: aRectangle height / 2.

aContext
lineWidth: 10;
strokeSize: 10;
sourceColor: (Color blue alpha: 0.5);
stroke.

Expand Down Expand Up @@ -772,7 +772,7 @@ AeCairoExamplesRenderTest >> surfaceWithStraightEdgesCurve [

aContext
sourceColor: Color white;
lineWidth: lineWidth;
strokeSize: lineWidth;
cubicCurveFrom: startPoint
controlPoint1: startPoint + (0 @ 35.4)
controlPoint2: startPoint + (39.4 @ 64)
Expand Down Expand Up @@ -880,7 +880,7 @@ AeCairoExamplesRenderTest >> surfaceWithTextAsPath [
aContext
sourceColor: Color blue;
dash: (AeFFIDoubleArray newFrom: { 7. 1 }) offset: 3;
lineWidth: 1.5;
strokeSize: 1.5;
stroke.

^ aSurface
Expand Down Expand Up @@ -960,10 +960,10 @@ AeCairoExamplesRenderTest >> surfaceWithToyAPISelectFontSlantWeight [
fontSize: fontSize;
translateByX: 2 y: fontSize;
appendTextPath: string;
lineWidth: 3;
strokeSize: 3;
sourceColor: Color white;
useLineJoinRound;
strokePreserve;
useStrokeJoinRound;
strokePreservingPath;
sourceColor: Color purple;
fill.

Expand Down
16 changes: 8 additions & 8 deletions src/Alexandrie-Cairo-Tests/AeCairoMigratedRenderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ AeCairoMigratedRenderTest >> surfaceWithFillAndStroke [
aContext
rectangle: (pad asPoint extent: size asPoint);
sourceColor: Color blue;
fillPreserve;
fillPreservingPath;
sourceColor: Color red;
stroke.

Expand All @@ -123,7 +123,7 @@ AeCairoMigratedRenderTest >> surfaceWithFillAndStroke [
circleCenterX: pad + (size/2)
y: pad + (size/2)
radius: size/2;
fillPreserve;
fillPreservingPath;
sourceColor: Color blue;
stroke.

Expand Down Expand Up @@ -153,7 +153,7 @@ AeCairoMigratedRenderTest >> surfaceWithFillAndStrokeAlpha [
pathBlock value.
aContext
source: fillPattern;
fillPreserve;
fillPreservingPath;
source: strokePattern;
stroke ]
alpha: 0.5 ].
Expand Down Expand Up @@ -209,13 +209,13 @@ AeCairoMigratedRenderTest >> surfaceWithFillAndStrokeAlphaAdd [
pathBlock value.
aContext
source: fillPattern;
fillPreserve.
fillPreservingPath.

"Use DEST_OUT to subtract stroke from fill."
aContext
sourceColor: Color black;
operator: AeCairoOperator destOut;
strokePreserve.
strokePreservingPath.

"Then use ADD to draw the stroke without a seam."
aContext
Expand Down Expand Up @@ -494,7 +494,7 @@ AeCairoMigratedRenderTest >> surfaceWithGroupClip [

aContext
rectangle: (25@25 extent: surfaceSize);
clipPreserve;
clipPreservingPath;
pushGroup;
sourceColor: Color blue;
fill;
Expand All @@ -504,7 +504,7 @@ AeCairoMigratedRenderTest >> surfaceWithGroupClip [

aContext
resetClip;
clipPreserve;
clipPreservingPath;
sourceColor: (Color red alpha: 0.5);
paint.

Expand Down Expand Up @@ -584,7 +584,7 @@ AeCairoMigratedRenderTest >> surfaceWithInvertedClip [
radius: 40
startAngle: 0
endAngle: Float twoPi;
clipPreserve;
clipPreservingPath;
paint.

aContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ AeCairoRecordingSurfaceRenderTest >> surfaceWithBounds [
aRecordingSurface newContext
sourceColor: (Color cyan alpha: 0.8);
rectangle: aRectangle;
lineWidth: 10;
strokeSize: 10;
stroke.

"Replay the recorded surface on a target surface"
Expand Down Expand Up @@ -85,7 +85,7 @@ AeCairoRecordingSurfaceRenderTest >> surfaceWithNoBounds [
aRecordingSurface newContext
sourceColor: (Color cyan alpha: 0.8);
rectangle: aRectangle;
lineWidth: 10;
strokeSize: 10;
stroke.

"Replay the recorded surface on a target surface"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AeCairoRecordingSurfaceTest >> testInkExtentsInBoundedSurface [
aRecordingSurface newContext
sourceColor: Color cyan;
rectangle: aRectangle;
lineWidth: 10;
strokeSize: 10;
stroke.

self
Expand All @@ -40,7 +40,7 @@ AeCairoRecordingSurfaceTest >> testInkExtentsInUnboundedSurface [
aRecordingSurface newContext
sourceColor: Color cyan;
rectangle: aRectangle;
lineWidth: 10;
strokeSize: 10;
stroke.

self
Expand Down
Loading

0 comments on commit 26832e6

Please sign in to comment.