--- a/CairoGraphicsContext.st Sun Feb 14 00:15:15 2016 +0000
+++ b/CairoGraphicsContext.st Tue Feb 16 07:46:52 2016 +0000
@@ -22,6 +22,26 @@
"Modified: / 09-01-2015 / 15:08:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!CairoGraphicsContext class methodsFor:'instance creation'!
+
+onDeviceGraphicsContext: dGC
+ | cGC |
+
+ cGC := self onDevice: dGC device.
+ 1 to: DeviceGraphicsContext instSize do:[:i |
+ cGC instVarAt: i put: (dGC instVarAt: i).
+ ].
+ dGC gcId notNil ifTrue:[
+ cGC createCR.
+ ].
+ cGC lineWidth: dGC lineWidth.
+ cGC font: dGC font.
+ ^ cGC
+
+ "Created: / 15-02-2016 / 21:20:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-02-2016 / 10:44:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!CairoGraphicsContext class methodsFor:'accessing'!
dllPath
@@ -102,27 +122,32 @@
!CairoGraphicsContext methodsFor:'accessing'!
-font:aFont
- | dfont family slant psize weight |
+clippingBounds:aRectangleOrNil
+ "set the clipping rectangle for drawing (in logical coordinates);
+ a nil argument turn off clipping (i.e. whole view is drawable)"
+
+ ^ super clippingBounds:aRectangleOrNil
+
+ "Created: / 15-02-2016 / 21:38:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
- dfont := aFont onDevice: device.
+font:aFont
+ | family slant psize weight |
+
+ super font: aFont.
- family := dfont family.
- slant := SymbolicFontSlantToCairoFontSlantMap at: (dfont style ? 'roman').
- weight := SymbolicFontFaceToCairoFontWeightMap at: (dfont face ? 'regular').
+ family := font family.
+ slant := SymbolicFontSlantToCairoFontSlantMap at: (font style ? 'roman').
+ weight := SymbolicFontFaceToCairoFontWeightMap at: (font face ? 'regular').
+ psize := font pixelSize.
+ psize isNil ifTrue:[
+ psize := (self device verticalPixelPerInch / 72) * font size.
+ ].
cr font: family slant: slant weight: weight.
-
- psize := dfont pixelSize.
- psize isNil ifTrue:[
- psize := (self device verticalPixelPerInch / 72) * dfont size.
- ].
cr fontSize: psize .
- font := ScaledFont family: dfont family face: dfont face style: dfont style size: dfont size.
- font handle: (CPrimitives cairo_get_scaled_font: crId).
-
- "Modified: / 13-02-2016 / 21:17:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-02-2016 / 10:55:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
function:aFunctionSymbol
@@ -133,10 +158,10 @@
lineWidth: w
super lineWidth: w.
- cr lineWidth: w.
+ cr lineWidth: (w == 0 ifTrue:[ 1 ] ifFalse:[ w ]).
"Created: / 17-06-2012 / 21:55:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 13-02-2016 / 17:38:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-02-2016 / 10:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
mask:aForm
@@ -160,13 +185,16 @@
"set the transformation"
super transformation: aTransformation.
- cr
- matrixReset;
- scale: transformation scale;
- transform: transformation translation.
+
+ cr matrixReset.
+ transformation notNil ifTrue:[
+ cr
+ scale: transformation scale;
+ transform: transformation translation.
+ ]
"Created: / 01-01-2015 / 12:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 13-02-2016 / 19:55:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-02-2016 / 10:59:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CairoGraphicsContext methodsFor:'basic drawing'!
@@ -211,12 +239,6 @@
"Modified: / 13-02-2016 / 20:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-displayOpaqueString:aString from:index1 to:index2 x:x y:y maxWitdh:maxWidth
- "draw part of a string with both fg and bg at x/y in current font"
-
- ^ self shouldImplement
-!
-
displayPolygon:points
"draw a polygon
- this could be recoded to draw using displayLine"
@@ -241,22 +263,27 @@
"Modified: / 13-02-2016 / 20:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-displayString:aString from:index1 to:index2 x:x y:y
- "draw part of a string with fg at x/y in current font"
+displayString:aStringArg from:index1Arg to:index2Arg x:x y:y opaque:opaqueArg maxWidth:maxWidth
+ "draw a substring at the coordinate x/y - draw foreground pixels in
+ paint-color and (if opaque is true), background pixels in bgPaint-color.
+ If the transformation involves scaling, the font's point-size is scaled as appropriate.
+ Assuming that device can only draw in device colors, we have to handle
+ the case where paint and/or bgPaint are dithered colors.
+ maxWidth is the maximum width of the string in pixels or nil if unknown."
cr save.
[
cr moveToX: x y: y.
- (index1 == 1 and:[ index2 == aString size ]) ifTrue:[
- cr showText: aString
+ (index1Arg == 1 and:[ index2Arg == aStringArg size ]) ifTrue:[
+ cr showText: aStringArg
] ifFalse:[
- cr showText: (aString copyFrom: index1 to: index2).
+ cr showText: (aStringArg copyFrom: index1Arg to: index2Arg).
].
] ensure:[
cr restore.
]
- "Modified: / 13-02-2016 / 20:04:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 16-02-2016 / 10:51:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CairoGraphicsContext methodsFor:'basic filling'!
@@ -318,15 +345,14 @@
cr strokeAndPreserve.
cr fill.
- "Modified: / 13-02-2016 / 20:01:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!CairoGraphicsContext methodsFor:'bit blitting'!
+"/ cr save.
+"/ cr rectangleX: x y: y width: w height: h.
+"/ cr sourceR: 1 G: 0 B: 0.
+"/ cr lineWidth: 3.
+"/ cr stroke.
+"/ cr restore.
-copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
- "copy from a drawable - maybe self"
-
- ^ self shouldImplement
+ "Modified: / 16-02-2016 / 07:58:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CairoGraphicsContext methodsFor:'drawing'!
@@ -339,23 +365,25 @@
| image width height stride data image_surface |
+ ^ super displayForm:aFormOrImage x:x y:y.
+
image := aFormOrImage asImage.
width := image width.
height := image height.
- stride := CPrimitives cairo_format_stride_for_width: CAIRO_FORMAT_ARGB32 _: width.
+ stride := Cairo::CPrimitives cairo_format_stride_for_width: CAIRO_FORMAT_ARGB32 _: width.
data := ExternalBytes basicNew allocateBytes: stride * height clear: false.
[
image bitsARGB32Into: data stride: stride fg: self paint bg: self backgroundPaint.
- image_surface := CPrimitives cairo_image_surface_create_for_data: data _: CAIRO_FORMAT_ARGB32 _: width _: height _: stride.
- CPrimitives cairo_set_source_surface: crId _: image_surface _: x asFloat _: y asFloat.
- CPrimitives cairo_paint: crId.
+ image_surface := Cairo::CPrimitives cairo_image_surface_create_for_data: data _: CAIRO_FORMAT_ARGB32 _: width _: height _: stride.
+ Cairo::CPrimitives cairo_set_source_surface: crId _: image_surface _: x asFloat _: y asFloat.
+ Cairo::CPrimitives cairo_paint: crId.
] ensure:[
data finalize.
image_surface release.
].
"Created: / 31-12-2014 / 12:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 01-01-2015 / 02:48:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-02-2016 / 21:32:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn