@@ -53,28 +53,28 @@ pub const SurfaceType = enum {
5353};
5454
5555pub const Surface = struct {
56- surface : * c.struct__cairo_surface ,
56+ c_ptr : * c.struct__cairo_surface ,
5757
5858 const Self = @This ();
5959
6060 pub fn getType (self : * Self ) SurfaceType {
61- const c_enum = c .cairo_surface_get_type (self .surface );
61+ const c_enum = c .cairo_surface_get_type (self .c_ptr );
6262 const c_integer = @enumToInt (c_enum );
6363 return @intToEnum (SurfaceType , @intCast (u5 , c_integer ));
6464 }
6565
6666 /// https://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-create
6767 pub fn image (width : u16 , height : u16 ) ! Surface {
68- var surface = try image_surface .create (Format .Argb32 , width , height );
69- try checkStatus (surface );
70- return Self { .surface = surface };
68+ var c_ptr = try image_surface .create (Format .Argb32 , width , height );
69+ try checkStatus (c_ptr );
70+ return Self { .c_ptr = c_ptr };
7171 }
7272
7373 pub fn setSize (self : * Self , width : f64 , height : f64 ) void {
7474 const st = self .getType ();
7575 switch (st ) {
76- SurfaceType .Xcb = > xcb_surface .setSize (self .surface , @floatToInt (u16 , width ), @floatToInt (u16 , height )),
77- SurfaceType .Pdf = > pdf_surface .setSize (self .surface , width , height ),
76+ SurfaceType .Xcb = > xcb_surface .setSize (self .c_ptr , @floatToInt (u16 , width ), @floatToInt (u16 , height )),
77+ SurfaceType .Pdf = > pdf_surface .setSize (self .c_ptr , width , height ),
7878 else = > std .debug .print ("`setSize` not implemented for {}\n " , .{st }),
7979 }
8080 }
@@ -85,20 +85,20 @@ pub const Surface = struct {
8585 if (st != SurfaceType .Svg ) {
8686 return Error .SurfaceTypeMismatch ;
8787 } else {
88- return svg_surface .getDocumentUnit (self .surface );
88+ return svg_surface .getDocumentUnit (self .c_ptr );
8989 }
9090 }
9191
9292 pub fn pdf (comptime filename : [* ]const u8 , width_pt : f64 , height_pt : f64 ) ! Surface {
93- var surface = try pdf_surface .create (filename , width_pt , height_pt );
94- try checkStatus (surface );
95- return Self { .surface = surface };
93+ var c_ptr = try pdf_surface .create (filename , width_pt , height_pt );
94+ try checkStatus (c_ptr );
95+ return Self { .c_ptr = c_ptr };
9696 }
9797
9898 pub fn createFromPng (filename : [* ]const u8 ) ! Surface {
99- var surface = try png_surface .create (filename );
100- try checkStatus (surface );
101- return Self { .surface = surface };
99+ var c_ptr = try png_surface .create (filename );
100+ try checkStatus (c_ptr );
101+ return Self { .c_ptr = c_ptr };
102102 }
103103
104104 /// https://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-get-width
@@ -108,7 +108,7 @@ pub const Surface = struct {
108108 std .debug .print ("`getWidth` not implemented for {}\n " , .{st });
109109 return Error .SurfaceTypeMismatch ;
110110 } else {
111- return @intCast (u16 , c .cairo_image_surface_get_width (self .surface ));
111+ return @intCast (u16 , c .cairo_image_surface_get_width (self .c_ptr ));
112112 }
113113 }
114114
@@ -119,15 +119,14 @@ pub const Surface = struct {
119119 std .debug .print ("`getHeight` not implemented for {}\n " , .{st });
120120 return Error .SurfaceTypeMismatch ;
121121 } else {
122- return @intCast (u16 , c .cairo_image_surface_get_height (self .surface ));
122+ return @intCast (u16 , c .cairo_image_surface_get_height (self .c_ptr ));
123123 }
124124 }
125125
126126 pub fn svg (comptime filename : [* ]const u8 , width_pt : f64 , height_pt : f64 ) ! Surface {
127- var surface = try svg_surface .create (filename , width_pt , height_pt );
128- try checkStatus (surface );
129- // std.debug.assert(SurfaceStatus.Success == surfaceStatusAsEnum(surface));
130- return Self { .surface = surface };
127+ var c_ptr = try svg_surface .create (filename , width_pt , height_pt );
128+ try checkStatus (c_ptr );
129+ return Self { .c_ptr = c_ptr };
131130 }
132131
133132 /// https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-get-device
@@ -139,35 +138,34 @@ pub const Surface = struct {
139138 }
140139
141140 pub fn xcb (conn : ? * c.struct_xcb_connection_t , drawable : u32 , visual : ? * c.struct_xcb_visualtype_t , width : u16 , height : u16 ) ! Surface {
142- var surface = try xcb_surface .create (conn , drawable , visual , width , height );
143- try checkStatus (surface );
144- var device = try Surface .getDevice (surface );
145- return Self { .surface = surface };
141+ var c_ptr = try xcb_surface .create (conn , drawable , visual , width , height );
142+ try checkStatus (c_ptr );
143+ var device = try Surface .getDevice (c_ptr );
144+ return Self { .c_ptr = c_ptr };
146145 }
147146
148147 /// Decrease the reference count on surface by one.
149148 /// https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-destroy
150149 pub fn destroy (self : * Self ) void {
151- c .cairo_surface_destroy (self .surface );
152- // std.debug.print("cairo.Surface {} destroyed\n", .{self});
150+ c .cairo_surface_destroy (self .c_ptr );
153151 }
154152
155153 /// Do any pending drawing for the surface and also restore any temporary modifications cairo has made to the surface's state.
156154 /// https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-flush/
157155 pub fn flush (self : * Self ) void {
158- c .cairo_surface_flush (self .surface );
156+ c .cairo_surface_flush (self .c_ptr );
159157 }
160158
161159 /// https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-mark-dirty
162160 pub fn markDirty (self : * Self ) void {
163- c .cairo_surface_mark_dirty (self .surface );
161+ c .cairo_surface_mark_dirty (self .c_ptr );
164162 }
165163
166164 /// Write the contents of surface to a new file filename as a PNG image.
167165 /// https://cairographics.org/manual/cairo-PNG-Support.html#cairo-surface-write-to-png
168166 /// TODO: cast C string
169167 pub fn writeToPng (self : * Self , filename : [* ]const u8 ) c.enum__cairo_status {
170- const s = c .cairo_surface_write_to_png (self .surface , filename );
168+ const s = c .cairo_surface_write_to_png (self .c_ptr , filename );
171169 return s ;
172170 }
173171};
@@ -221,7 +219,7 @@ test "checkStatus() returns no error" {
221219 var surface_image = try Surface .image (320 , 240 );
222220 defer surface_image .destroy ();
223221 var errored = false ;
224- _ = checkStatus (surface_image .surface ) catch | err | {
222+ _ = checkStatus (surface_image .c_ptr ) catch | err | {
225223 errored = true ;
226224 };
227225 expectEqual (false , errored );
@@ -246,7 +244,7 @@ test "Surface.getDevice() returns NullPointer when the surface does not have an
246244 var surface_image = try Surface .image (320 , 240 );
247245 defer surface_image .destroy ();
248246 var caught = false ;
249- _ = Surface .getDevice (surface_image .surface ) catch | err | {
247+ _ = Surface .getDevice (surface_image .c_ptr ) catch | err | {
250248 expectEqual (Error .NullPointer , err );
251249 caught = true ;
252250 };
0 commit comments