Skip to content

Commit

Permalink
Add AeCairoContext>>sourceSurface: for convenience, as 0@0 is a usual…
Browse files Browse the repository at this point in the history
… translation

And replace some occurrences to use this new method
  • Loading branch information
tinchodias committed Nov 6, 2024
1 parent dac70fd commit bfc8262
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ AeCairoExamplesRenderTest >> surfaceWithFlippedText [
extent: extent * 2
format: AeCairoSurfaceFormat argb32.
mainContext := mainSurface newContext.
mainContext sourceSurface: textSurface x: 0.0 y: 0.0.
mainContext sourceSurface: textSurface.
mainContext paint.

m := AeCairoMatrix newIdentity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ AeCairoPatternSourceConvertedTest >> testSurface [
context := surface newContext.

tmpSurface := AeCairoImageSurface extent: 100 @ 100.
context sourceSurface: tmpSurface x: 0 y: 0.
context sourceSurface: tmpSurface x: 7 y: 11.

self
assert: context sourceConverted class
equals: AeCairoSurfacePattern.


self assert: context sourceConverted matrix x equals: -7.
self assert: context sourceConverted matrix y equals: -11.
]
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ AeCairoRecordingSurfaceRenderTest >> surfaceWithBounds [
paint;

"Draw a rectangle with the recorded surface"
sourceSurface: aRecordingSurface
x: 0
y: 0;
sourceSurface: aRecordingSurface;
rectangle: aRectangle;
fill;

Expand Down Expand Up @@ -101,9 +99,7 @@ AeCairoRecordingSurfaceRenderTest >> surfaceWithNoBounds [

"Draw a rectangle with the recorded surface.
The fill operation clips the source by the path."
sourceSurface: aRecordingSurface
x: 0
y: 0;
sourceSurface: aRecordingSurface;
rectangle: aRectangle;
fill;

Expand Down
10 changes: 8 additions & 2 deletions src/Alexandrie-Cairo/AeCairoContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,13 @@ AeCairoContext >> sourceConverted [
^ result
]

{ #category : #'API - source' }
AeCairoContext >> sourceSurface: aCairoSurface [
"Set a surface as the current pattern source, at 0@0."

self sourceSurface: aCairoSurface x: 0.0 y: 0.0
]

{ #category : #'API - source' }
AeCairoContext >> sourceSurface: aCairoSurface x: aX y: aY [
"This is a convenience function for creating a pattern from surface and setting it as the source.
Expand All @@ -1768,8 +1775,7 @@ AeCairoContext >> sourceSurface: aCairoSurface x: aX y: aY [
(The surface origin is its upper-left corner before any transformation has been applied.)
The x and y parameters are negated and then set as translation values in the pattern matrix.
Other than the initial translation pattern matrix, as described above, all other pattern attributes, such as its extend mode,
are set to the default values.
Other than the initial translation pattern matrix, as described above, all other pattern attributes, such as its extend mode, are set to the default values.
See: https://www.cairographics.org/manual/cairo-cairo-t.html#cairo-set-source-surface"

Expand Down
4 changes: 1 addition & 3 deletions src/Alexandrie-Cairo/AeCairoImageSurface.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ AeCairoImageSurface >> asARGB32ImageSurface [
aSurface deviceScale: self deviceScale.

aSurface newContext
sourceSurface: self
x: 0.0
y: 0.0;
sourceSurface: self;
paint.

^ aSurface
Expand Down
4 changes: 2 additions & 2 deletions src/Alexandrie-Canvas/AeCanvas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ AeCanvas >> setBackgroundWithForm: aForm alpha: aDouble [
setBackgroundWith: [
| aCairoSurface |
aCairoSurface := formToCairoSurfaceCache at: aForm.
cairoContext sourceSurface: aCairoSurface x: 0.0 y: 0.0 ]
cairoContext sourceSurface: aCairoSurface ]
alpha: aDouble

]
Expand All @@ -724,7 +724,7 @@ AeCanvas >> setBackgroundWithFormSet: aFormSet alpha: aDouble [
setBackgroundWith: [
| aCairoSurface |
aCairoSurface := formSetToCairoSurfaceCache at: aFormSet.
cairoContext sourceSurface: aCairoSurface x: 0.0 y: 0.0 ]
cairoContext sourceSurface: aCairoSurface ]
alpha: aDouble
]

Expand Down

0 comments on commit bfc8262

Please sign in to comment.