| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | ! Copyright (C) 2008 Doug Coleman. | 
					
						
							| 
									
										
										
										
											2009-02-28 02:31:51 -05:00
										 |  |  | ! Copyright (C) 2009 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-02-28 02:31:51 -05:00
										 |  |  | USING: colors fonts cairo.ffi alien alien.c-types kernel accessors | 
					
						
							|  |  |  | sequences namespaces fry continuations destructors math images | 
					
						
							| 
									
										
										
										
											2009-02-28 21:33:53 -05:00
										 |  |  | images.memory math.rectangles ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 23:51:33 -04:00
										 |  |  | IN: cairo | 
					
						
							| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 20:24:54 -04:00
										 |  |  | ERROR: cairo-error n message ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-27 00:30:02 -05:00
										 |  |  | : (check-cairo) ( cairo_status_t -- )
 | 
					
						
							|  |  |  |     dup CAIRO_STATUS_SUCCESS =
 | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |     [ drop ] [ [ ] [ cairo_status_to_string ] bi cairo-error ] if ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-27 00:30:02 -05:00
										 |  |  | : check-cairo ( cairo -- ) cairo_status (check-cairo) ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 23:41:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:51:55 -05:00
										 |  |  | : check-surface ( surface -- ) cairo_surface_status (check-cairo) ;
 | 
					
						
							| 
									
										
										
										
											2008-04-27 07:32:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 02:37:24 -05:00
										 |  |  | : width>stride ( width -- stride ) uint heap-size * ; inline
 | 
					
						
							| 
									
										
										
										
											2009-02-27 00:30:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <image-surface> ( data dim -- surface )
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:51:55 -05:00
										 |  |  |     [ CAIRO_FORMAT_ARGB32 ] dip first2 over width>stride | 
					
						
							| 
									
										
										
										
											2009-02-27 00:30:02 -05:00
										 |  |  |     cairo_image_surface_create_for_data | 
					
						
							|  |  |  |     dup check-surface ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:51:55 -05:00
										 |  |  | : <cairo> ( surface -- cairo ) cairo_create dup check-cairo ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-27 00:30:02 -05:00
										 |  |  | : make-bitmap-image ( dim quot -- image )
 | 
					
						
							| 
									
										
										
										
											2009-02-27 01:51:55 -05:00
										 |  |  |     '[ | 
					
						
							|  |  |  |         <image-surface> &cairo_surface_destroy | 
					
						
							| 
									
										
										
										
											2009-03-04 22:09:38 -05:00
										 |  |  |         <cairo> &cairo_destroy | 
					
						
							| 
									
										
										
										
											2009-02-27 01:51:55 -05:00
										 |  |  |         @ | 
					
						
							| 
									
										
										
										
											2009-02-28 02:31:51 -05:00
										 |  |  |     ] make-memory-bitmap | 
					
						
							| 
									
										
										
										
											2009-06-22 12:20:54 -04:00
										 |  |  |     BGRA >>component-order | 
					
						
							|  |  |  |     ubyte-components >>component-type ; inline
 | 
					
						
							| 
									
										
										
										
											2009-02-28 02:31:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : dummy-cairo ( -- cr )
 | 
					
						
							| 
									
										
										
										
											2015-09-08 19:15:10 -04:00
										 |  |  |     ! Sometimes we want a dummy context; eg with Pango, we want | 
					
						
							|  |  |  |     ! to measure text dimensions to create a new image context with, | 
					
						
							|  |  |  |     ! but we need an existing context to measure text dimensions | 
					
						
							|  |  |  |     ! with so we use the dummy. | 
					
						
							| 
									
										
										
										
											2009-02-28 02:31:51 -05:00
										 |  |  |     \ dummy-cairo [ | 
					
						
							|  |  |  |         CAIRO_FORMAT_ARGB32 0 0 cairo_image_surface_create | 
					
						
							|  |  |  |         cairo_create | 
					
						
							|  |  |  |     ] initialize-alien ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : set-source-color ( cr color -- )
 | 
					
						
							| 
									
										
										
										
											2009-02-28 21:33:53 -05:00
										 |  |  |     >rgba-components cairo_set_source_rgba ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : fill-rect ( cr rect -- )
 | 
					
						
							|  |  |  |     [ rect-bounds [ first2 ] bi@ cairo_rectangle ] | 
					
						
							|  |  |  |     [ drop cairo_fill ] | 
					
						
							|  |  |  |     2bi ;
 |