More work for using CairoGrahicsContext for rendering views
* Added GraphicsMedium>>cairoify to change from device rendering
to Cairo rendering.
* Handle lineWidth: 0 specially as it actually means lineWidth = 1.
* Small cleanup / fixes in text displaying (this would need more work, though)
"{ Package: 'stx:goodies/libcairo' }"
"{ NameSpace: Cairo }"
CObject subclass:#Surface
instanceVariableNames:'view drawable'
classVariableNames:''
poolDictionaries:'Cairo::SurfaceType Cairo::Format'
category:'Cairo-Objects'
!
!Surface class methodsFor:'instance creation'!
forView: aView
^ self onView: aView
"Created: / 10-07-2008 / 10:15:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 14-02-2016 / 00:01:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
newImageWithFormat:format width:width height:height
^ CPrimitives
cairo_image_surface_create:format
_:width
_:height
"Created: / 24-12-2014 / 23:43:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:03:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
newImageWithFormatARGB32width:width height:height
^ self
newImageWithFormat:CAIRO_FORMAT_ARGB32
width:width
height:height
"Created: / 24-12-2014 / 23:44:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:04:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
newPDFWithFile:aStringOrFilename width:w height:h
^ CPrimitives
cairo_pdf_surface_create:aStringOrFilename asFilename asString
_:w asDouble
_:h asDouble
"Created: / 10-07-2008 / 09:35:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:05:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
newXlibWithDisplay:dpy drawable:drawable visual:visual width:width height:height
^ CPrimitives
cairo_xlib_surface_create:dpy
_:drawable
_:visual
_:width
_:height
"Created: / 10-07-2008 / 11:06:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
onView: aView
aView device platformName == #X11 ifTrue:[
| surface |
surface := self newXlibWithDisplay:aView device displayId
drawable:aView drawableId address
visual:aView device queryDefaultVisual
width:aView width
height:aView height.
surface setView: aView.
^ surface.
].
self error: 'Unsupported plarform'
"Created: / 13-02-2016 / 23:47:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!Surface class methodsFor:'accessing'!
dllPath
OperatingSystem isMSWINDOWSlike ifTrue:[
^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
].
OperatingSystem isUNIXlike ifTrue:[
OperatingSystem getSystemType == #linux ifTrue:[
| path |
path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
(OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
"If the machine is 64bit, prepend standard path for 32bit libs.
Leave standard paths at the end, as the system might be completely
32bit but running on 64bit-capable CPU.
CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
not installed byt 64bit sqlite libs are, then 64bit libs are found
and when a function is called, segfault will occur!!
Q: Is there a way how to figure out if the OS itself is 32bit,
regardles on CPU?"
path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
].
^path
].
].
self error:'Unsupported operating system'
"
SqliteLibrary dllPath
"
"Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
libraryName
OperatingSystem isUNIXlike ifTrue:[^'libcairo.so.2'].
OperatingSystem isMSWINDOWSlike ifTrue:[^'cairo.dll'].
self error:'Library name for host OS is not known'
!
sizeof
"Returns size of undelaying structure in bytes"
^0
! !
!Surface methodsFor:'accessing'!
referenceCount
"Return value or reference counter"
^ CPrimitives cairo_surface_get_reference_count: self
"Created: / 28-12-2014 / 22:09:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
type
^CPrimitives cairo_surface_get_type: self
"Created: / 10-07-2008 / 10:34:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 21:46:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!Surface methodsFor:'initialization & release'!
destroy
"Tell Cairo library to destroy the corresponding C object.
Remember that object is physically destroyed only if internal
refcounter goes to zero. However, after calling destroy,
this instance should be treated as invalid."
CPrimitives cairo_surface_destroy: self.
self setAddress: nil.
"Created: / 28-12-2014 / 22:10:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 13-02-2016 / 16:10:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
finish
^CPrimitives cairo_surface_finish: self
"Created: / 17-06-2012 / 08:49:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 21:48:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
flush
^CPrimitives cairo_surface_flush: self
"Created: / 10-07-2008 / 10:32:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 21:48:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!Surface methodsFor:'queries'!
isViewSurface
"Return true, if this sufrace if for a kind of a View"
^self isXLibSurface or:[ self isWin32Surface ]
"Created: / 17-06-2012 / 15:02:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isWin32Surface
^self type == CAIRO_SURFACE_TYPE_WIN32
"Created: / 17-06-2012 / 15:01:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 21:46:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isXLibSurface
^self type == CAIRO_SURFACE_TYPE_XLIB
"Created: / 17-06-2012 / 14:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 21:46:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!Surface class methodsFor:'documentation'!
version
^'$Id$'
!
version_HG
^ '$Changeset: <not expanded> $'
! !