Skip to content

Commit

Permalink
Cairo: playing with Quartz backend. Not ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Jan 30, 2025
1 parent eefb8e7 commit be7e03e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/Alexandrie-Cairo-Tests/AeCairoMigratedRenderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,32 @@ AeCairoMigratedRenderTest >> surfaceWithOutsideClipping [

^ aSurface
]

{ #category : #tests }
AeCairoMigratedRenderTest >> surfaceWithQuartzAppleColorEmoji [
"Test showing a color font in a Quartz surface (only in Mac).
Based on: quartz-color-font.c"

| string extent aSurface aContext |
Smalltalk os isMacOSX ifFalse: [ ^ AeCairoImageSurface extent: 0@0 ].

string := WideString with: (Character value: 16r1F642). "smily face"
extent := 100@50.
aSurface := AeCairoQuartzSurface
extent: extent
format: AeCairoSurfaceFormat argb32.
aContext := aSurface newContext.

"Draw outlined text with toy font selection"
aContext
selectFont: 'Apple Color Emoji'
slant: AeCairoFontSlant normal
weight: AeCairoFontWeight normal;
fontSize: extent y // 2;
moveToX: extent x // 5 y: (2 * extent y) // 3;
showText: string;
showText: string.

^ aSurface
]
12 changes: 8 additions & 4 deletions src/Alexandrie-Cairo-Tests/AeCairoQuartzSurfaceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ Class {
}

{ #category : #tests }
AeCairoQuartzSurfaceTest >> testItIsNotCurrentlySupported [
AeCairoQuartzSurfaceTest >> testExportPNG [

| aSurface |
| aSurface filename |
Smalltalk os isMacOSX ifFalse: [ ^ self skip ].

aSurface := AeCairoQuartzSurface
extent: 100 @ 100
format: AeCairoSurfaceFormat rgb24.

self assert: aSurface status isSuccess. "Confusingly: it says it was a success".
self assert: aSurface extent equals: 0 @ 0 "But the width and height is zero."
self assert: aSurface status isSuccess.

filename := (Time microsecondClockValue asString, '.png') asFileReference.
self deny: filename exists.
aSurface writePngTo: filename.
self assert: filename exists.
]
35 changes: 33 additions & 2 deletions src/Alexandrie-Cairo/AeCairoQuartzSurface.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ I am a Cairo FFI binding for a `cairo_surface_t` for Quartz.
The Quartz surface is used to render cairo graphics targeting the Apple OS X Quartz rendering system.
It is not currently supported by our bindings.
See: https://www.cairographics.org/manual/cairo-Quartz-Surfaces.html
"
Class {
Expand All @@ -13,6 +11,18 @@ Class {
#category : #'Alexandrie-Cairo-Surfaces'
}

{ #category : #'instance creation' }
AeCairoQuartzSurface class >> newWrapping: aCairoImageSurface [
"Return a newly created Quartz surface backed by a CGBitmapContext that references the received surface.
The resulting surface can be rendered quickly when used as a source when rendering to a cairo_quartz_surface.
See: https://www.cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-image-surface-create"

^ (self unownedNewWrapping: aCairoImageSurface)
autoRelease;
yourself
]

{ #category : #'instance creation' }
AeCairoQuartzSurface class >> unownedNewWithFormat: aFormat width: aWidth height: aHeight [
"See: https://www.cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-surface-create"
Expand All @@ -24,3 +34,24 @@ AeCairoQuartzSurface class >> unownedNewWithFormat: aFormat width: aWidth height
int aWidth,
int aHeight ) )
]

{ #category : #'instance creation' }
AeCairoQuartzSurface class >> unownedNewWrapping: aCairoImageSurface [
"Return a newly created Quartz surface backed by a CGBitmapContext that references the received surface.
The resulting surface can be rendered quickly when used as a source when rendering to a cairo_quartz_surface.
See: https://www.cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-image-surface-create"

^ self ffiCall: #(
AeCairoImageSurface cairo_quartz_image_surface_create ( aCairoImageSurface ) )
]

{ #category : #accessing }
AeCairoQuartzSurface >> image [
"Returns a cairo_surface_t (owned by the quartz cairo_surface_t), or NULL if the quartz surface is not an image surface.
See: https://www.cairographics.org/manual/cairo-Quartz-Surfaces.html#cairo-quartz-image-surface-get-image"

^ self ffiCall: #(
AeCairoImageSurface cairo_quartz_image_surface_get_image ( self ) )
]
6 changes: 6 additions & 0 deletions src/Alexandrie-Cairo/AeCairoSurfaceFormat.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ AeCairoSurfaceFormat class >> enumDecl [
)
]

{ #category : #'accessing enum' }
AeCairoSurfaceFormat class >> invalid [

^ CAIRO_FORMAT_INVALID
]

{ #category : #'accessing enum' }
AeCairoSurfaceFormat class >> rgb24 [

Expand Down

0 comments on commit be7e03e

Please sign in to comment.