[med-svn] [r-cran-cairo] 04/06: New upstream version 1.5-9

Andreas Tille tille at debian.org
Thu Oct 19 07:34:16 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-cairo.

commit 4d318b464bf82303704ee07c55ee21bf48e8891f
Author: Andreas Tille <tille at debian.org>
Date:   Thu Oct 19 09:29:15 2017 +0200

    New upstream version 1.5-9
---
 DESCRIPTION               |   19 +
 MD5                       |   42 +
 NAMESPACE                 |    3 +
 NEWS                      |  283 +++
 R/Cairo.R                 |  156 ++
 R/imgtools.R              |   16 +
 R/zzz.R                   |   10 +
 configure                 | 5155 +++++++++++++++++++++++++++++++++++++++++++++
 configure.ac              |  273 +++
 configure.win             |   49 +
 debian/changelog          |   11 -
 debian/compat             |    1 -
 debian/control            |   36 -
 debian/copyright          |   32 -
 debian/rules              |    3 -
 debian/source/format      |    1 -
 debian/watch              |    2 -
 man/Cairo.Rd              |  199 ++
 man/Cairo.capabilities.Rd |   26 +
 man/Cairo.capture.Rd      |   38 +
 man/Cairo.onSave.Rd       |   54 +
 man/Cairo.serial.Rd       |   34 +
 man/CairoFontMatch.Rd     |   89 +
 man/CairoFonts.Rd         |   62 +
 src/Makevars.in           |    3 +
 src/Makevars.win          |   13 +
 src/backend.h             |   94 +
 src/cairobem.c            |   60 +
 src/cairobem.h            |    8 +
 src/cairogd.c             |  567 +++++
 src/cairogd.h             |   84 +
 src/cairotalk.c           | 1168 ++++++++++
 src/cairotalk.h           |   18 +
 src/cconfig.h.in          |   68 +
 src/img-backend.c         |  259 +++
 src/img-backend.h         |   24 +
 src/img-jpeg.c            |   73 +
 src/img-jpeg.h            |    6 +
 src/img-tiff.c            |   68 +
 src/img-tiff.h            |   15 +
 src/pdf-backend.c         |  107 +
 src/pdf-backend.h         |   14 +
 src/ps-backend.c          |  107 +
 src/ps-backend.h          |   14 +
 src/svg-backend.c         |  107 +
 src/svg-backend.h         |   14 +
 src/w32-backend.c         |  486 +++++
 src/w32-backend.h         |   14 +
 src/xlib-backend.c        |  404 ++++
 src/xlib-backend.h        |   14 +
 50 files changed, 10317 insertions(+), 86 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..d0c2a22
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,19 @@
+Package: Cairo
+Version: 1.5-9
+Title: R graphics device using cairo graphics library for creating
+        high-quality bitmap (PNG, JPEG, TIFF), vector (PDF, SVG,
+        PostScript) and display (X11 and Win32) output
+Author: Simon Urbanek <Simon.Urbanek at r-project.org>, Jeffrey Horner <jeff.horner at vanderbilt.edu>
+Maintainer: Simon Urbanek <Simon.Urbanek at r-project.org>
+Depends: R (>= 2.4.0)
+Imports: grDevices, graphics
+Suggests: png
+Enhances: FastRWeb
+Description: Cairo graphics device that can be use to create high-quality vector (PDF, PostScript and SVG) and bitmap output (PNG,JPEG,TIFF), and high-quality rendering in displays (X11 and Win32). Since it uses the same back-end for all output, copying across formats is WYSIWYG. Files are created without the dependence on X11 or other external programs. This device supports alpha channel (semi-transparent drawing) and resulting images can contain transparent and semi-transparent regions [...]
+License: GPL-2
+SystemRequirements: cairo (>= 1.2 http://www.cairographics.org/)
+URL: http://www.rforge.net/Cairo/
+NeedsCompilation: yes
+Packaged: 2015-09-25 17:49:11 UTC; svnuser
+Repository: CRAN
+Date/Publication: 2015-09-26 09:05:40
diff --git a/MD5 b/MD5
new file mode 100644
index 0000000..09cad77
--- /dev/null
+++ b/MD5
@@ -0,0 +1,42 @@
+c120a9cbee1a22ec1555ea032f9c278d *DESCRIPTION
+4349f93fca74b0151a9435bfbeec5673 *NAMESPACE
+bbc8e777b8c57addac39b73b6724060e *NEWS
+652a130cdb89035bd21add505f09ff6c *R/Cairo.R
+45f780dde83799bfd5ec2d67659fded4 *R/imgtools.R
+a9008f9a9abd726e834484d834008b47 *R/zzz.R
+c5196eb2ad5615b9198965124fbbc2f7 *configure
+938f465e81a73126bac6eabfdfce8ea0 *configure.ac
+9ab259fe324885b6524858aa98ab51ef *configure.win
+9b9c0bd04bd4f6444182d8a4b8e209b5 *man/Cairo.Rd
+08dffecb11001a3d8d781c6834100cac *man/Cairo.capabilities.Rd
+828f9d2b515a62d1e7ba8aadb582b01f *man/Cairo.capture.Rd
+021c456c904c3400f5a8cebe93e9b8bb *man/Cairo.onSave.Rd
+f15d68f877a128ae9727519c64b21dd0 *man/Cairo.serial.Rd
+4a9f52de93602ecc31b5c61682351bba *man/CairoFontMatch.Rd
+db2888837293dbf144e4605d794e8379 *man/CairoFonts.Rd
+0a452df871ff02cc77b07df796e20739 *src/Makevars.in
+72c5f27149e19f5b0663a9908caacdb1 *src/Makevars.win
+b57465d1220ef2db48ada0ea4d699df4 *src/backend.h
+4c2d98472fa7190b86538d0f9d880a68 *src/cairobem.c
+4839a2d606ecaa9e9a000e38cb075fc7 *src/cairobem.h
+d41639330befbe7cfb4a71b6fcc33014 *src/cairogd.c
+fad889d6ff126cc92fe5b415eb48ebaa *src/cairogd.h
+e6c0d7b56e54f2b1543ffe8b7bfe9312 *src/cairotalk.c
+bc2e6aeed51a7bf7c9f6c08c043a308a *src/cairotalk.h
+24d698d7aad1fb7f5b629be5b457e319 *src/cconfig.h.in
+9793089f6917df1f2e9bda616930da65 *src/img-backend.c
+64361f5aefcef67513607eb825a58e98 *src/img-backend.h
+ed89d57a5afef289936a7bdb4b385edf *src/img-jpeg.c
+8d58fa8f009a29a0394d1bbdfe828807 *src/img-jpeg.h
+a32eb19736e255aef13b85d475e99382 *src/img-tiff.c
+8c4ef00c7ecd978ce7836c6592b181ed *src/img-tiff.h
+132ce72bf4993f07c7d22dd3e1f3b43a *src/pdf-backend.c
+07e27ba75d13a5b12ffa8431657758c7 *src/pdf-backend.h
+dd35702593437c20ff5503d7ad323840 *src/ps-backend.c
+ad3d54689163db0667e5e5b8f672dd38 *src/ps-backend.h
+b929392615feec6f4424410c993f60ed *src/svg-backend.c
+2508ee0d495026cde2c59009af983f7f *src/svg-backend.h
+579964ffb8474b0a0b60aad763f02fe3 *src/w32-backend.c
+68f9a9c2fdb49f778bb0638f67fb54ae *src/w32-backend.h
+13ad14453af19e54be73051ef0ae4d51 *src/xlib-backend.c
+f978a2861b85129a9955aa7b4677a1d4 *src/xlib-backend.h
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..f20b034
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,3 @@
+exportPattern("^Cairo")
+importFrom("grDevices", "dev.cur")
+importFrom("graphics", "par")
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..40db1df
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,283 @@
+NEWS/Changelog
+
+1.5-9	(2015-09-25)
+    o	work around bug #45376 in freetype 2.6.0 causing compilation
+	failure
+
+
+1.5-8	(2015-07-29)
+    o	fix a premature memory release in locator handling for
+	raster back-ends.
+
+
+1.5-7	(2015-07-27)
+    o	fix a segfault in CairoFontMatch() in case FcNameParse()
+	fails (closes #10)
+
+    o	image back-end can now provide custom locator if
+	a `locator` argument is passed to `Cairo()` with the desired
+	callback function. The callback function accepts `dev` argument
+	and should return either a numeric vector of length 2 (x, y)
+	or `NULL`. This is mainly useful for `type='raster'` passed to
+	external UI where that UI can provide locator capability.
+
+    o   add Cairo.snapshot() which is similar to recordPlot() but
+	also allows the retrieval of the last snapshot.
+
+
+1.5-6	(2014-06-26)
+    o	scale line width by the same amount as fonts such that
+	resolution changes are consistent even in that respect
+
+
+1.5-5	(2013-12-23)
+    o	fix onSave reporting incorrect page number for the last page
+	(introduced in 1.5-4, closes #6)
+
+    o	scale fonts unconditionally according to the dpi adjustment
+	(fixes issues with grid graphics and dpi changes)
+
+
+1.5-4	(2013-12-12)
+    o	fix invalid pointsize scaling if dpi auto-detection is used
+	(closes #1)
+
+    o	fix failure to emit final page in some multi-page settings
+	(closes #4)
+
+    o	the `res' parameter in CairoPNG(), CairoTIFF() and CairoJPEG()
+	it now passed down to Cairo() which now accepts `res' to
+	override the value of `dpi' if `res' is set to anyhting other
+	than NA or NULL. (closes #3)
+
+    o	release onSave callback function on close (closes #2)
+
+
+1.5-3	(2013-12-03)
+    o	remove compatibility layers to make R 3.x happy
+
+    o	adjust pointsize according to the dpi setting
+
+
+1.5-2	(2012-11-05)
+    o	added Cairo.onSave() callback which allows R code to be run
+	when Cairo finishes a page
+
+    o	added Cairo.serial() function which allows user code to check
+	whether the graphics have been updated
+
+    o	bugfix/update in Cairo connection patch (by Karl Millar)
+
+
+1.5-1	(2011-12-10)
+    o	add support for dev.hold()/dev.flush()
+
+    o	use new R 2.14.0 device capabilities advertizing feature
+
+    o	fix memory leak when setting fonts via CairoFonts()
+
+    o	explicitly request font anti-aliasing even if it is not the
+	surface default - in particular Windows has disabled font
+	anti-aliasing by default
+
+
+1.5-0	(2011-09-30)
+    o	fix swapped bold vs italic traits if freetype is not available
+
+    o	use Times font for symbols on Windows because Symbol font
+	doesn't seem to support Unicode
+
+    o	add support for poly-paths
+
+    o	add support for dev.capture()/grid.cap()
+
+    o	added new type "raster" that creates an image back-end without
+	any output file. It can be used in conjunction with
+	dev.capture() to create in-memory image representations, e.g.:
+	Cairo(type='raster')
+	plot(1:10, col=2)
+	p = writePNG(dev.capture(native=TRUE), raw())
+	will create a raw vector containg a PNG image.
+
+
+1.4-9	(2011-04-06)
+    o	force static built-in libraries on Windows to prevent Cairo
+	from picking up broken system libraries
+
+1.4-8	(2011-03-07)
+    o	spurious character in the 1.4-7 w32-backed source has made it
+	unusable on Windows. This is a re-packaging of 1.4-7 without
+	that spurious character.
+
+1.4-7	(2011-03-07)
+    o	fix a bug in raster support causing raster to be usable only
+	once
+
+    o	win backend: release and re-get DC on resize -- fixes resizing
+	issues in CairoWin() for some Windows versions
+
+1.4-6	(2011-02-10)
+    o	adds raster image support (courtesy of R core)
+
+    o	update Windows libcairo binary to cairo 1.10.2, use static
+	build to avoid DLL issues and add 64-bit binary
+
+1.4-5	(2009-07-16)
+    o	minor Windows configuration change
+
+    o	fix SET_VECTOR_ELT issue for R 2.9.0+
+
+1.4-4	(2008-10-17)
+    o	adapt to changes in R-devel (2.9.0-to-be), clean up warnings
+
+1.4-3	(2008-07-21)
+    o	make the use of an invalid font non-fatal
+
+    o	allow Cairo to compile on some older systems that don't have
+	trunc()
+
+    o	updated libcairo binary for Windows to 1.6.4 (from GTK+)
+
+1.4-2	(2008-04-03)
+    o	adapt to even more changes in R 2.7
+
+1.4-1	(2008-03-14)
+    o	adapt to R 2.7 changes
+
+1.4-0
+    o	fix DPI detection in X11 back-end and use 90dpi as a fallback
+
+    o	fix cra settings to be closer to what other devices use
+
+    o	CairoX11 no longer fixes DPI to 72, "auto" is now the default.
+	In addition, CairoWin and CairoX11 allow additional arguments
+	to ba passed to Cairo.
+
+1.3-5	(2007-08-27)
+    o	adapt to const char* CHARs in R-devel
+
+    o	fix a bug in CairoSVG (wrong argument name)
+
+    o	fix a bug in CairoPS (units were not set to "in" and
+	width/height had no defaults)
+
+    o	fix unintentional doubling of the .ps suffix
+
+1.3-4	(2007-05-10)
+    o	more fixes in flag-guessing
+
+    o	some vector backends (e.g. PDF, SVG) were falling back to
+	bitamp rasterization, we try to prevent this 
+
+    o	address expose issues with some X11 servers
+
+    o	add CairoSVG wrapper
+
+    o	add an unified way to register back-ends and get a list of all
+	supported types.
+
+    o	add Cairo.capabilities() function
+
+1.3-3	2007-04-25
+    o	improve detection of cairo and its dependencies
+
+    o	work around missing API such that cairo 1.0 can be used.
+	However, it is strongly encouraged to use cairo 1.2 or
+	possibly 1.4 as they contain important bugfixes.
+
+    o	fix page numbering to start at 1 (was 0) and update
+	documentation correspondingly
+
+1.3-2	2007-04-18
+    o	added format autodetection for tiff and png. The 32-bit
+	version of either format is used if the background
+	is not opaque.
+
+    o	fixed bug in the value returned by Cairo
+
+    o	added type and file attributes to the Cairo object
+
+    o	added (hidden, experimental) functions that allow direct
+	modification of image content in Cairo (.image, .ptr.to.raw
+	and .raw.to.ptr)
+
+1.3-1
+    o	change semantics of canvas and bg to match other devices:
+	canvas is used by devices that don't support any kind
+	of transparency in case bg is translucent
+
+    o	fixed data ordering issues in TIFF and JPEG output
+
+    o	added "compression" parameter to TIFF back-end which
+	now defaults to LZW compression
+
+1.3-0
+    o	add support for canvas and dpi specification
+
+    o	allow backends to detect native resolution
+
+    o	add support for custom parameters (e.g. quality for jpeg)
+
+1.2-1
+    o	improve rendering on bitmap devices by aligning straight lines
+	to the pixel grid and adding bleed to such fills.
+
+    o	added wrappers that take exactly the same parameters as
+	existing devices such as png, jpeg, pdf, postscript, X11 or
+	windows and map them to calls to Cairo. They can be used to
+	replace native devices by Cairo without the need to change
+	existing code.
+
+    o	added namespace
+
+1.2-0
+    o	additional interactive back ends: X11 (XLib) and win (Win32)
+
+    o	enhanced back-end API to support interactive back-ends
+
+    o	change default backgroud color to "white", because
+	alpha-blending doesn't work properly in cairo when painting on
+	purely transparent background.
+
+    o	change the way filenames are interpreted, use multi-file
+	printf convention as other devices do.
+
+    o	added support for jpeg and tiff image formats
+
+1.1-0
+    o	additional file/stream back-ends: svg, ps
+
+    o	enhanced back-end API
+
+1.0-0
+    o	fixed function names to not conflict with GDD
+
+0.1-5
+    o   added R connections patch support at config time.
+        see 
+	http://wiki.r-project.org/rwiki/doku.php?id=developers:r_connections_api
+
+0.1-4	(2006-12-07)
+    o	add pdf backend (Jeff Horner)
+
+    o	fix up backend infrastructure (Jeff Horner)
+
+0.1-3	(2006-12-06)
+    o	add freetype and fontconfig support (Jeff Horner)
+
+    o	fix memory leaks (Jeff Horner)
+
+    o	make transparent background default with bg="transparent"
+
+0.1-2	(2006-12-05)
+    o	add support for caps/joints (patch by Jeff Horner)
+
+    o	make rectangels to snap to grid (patch by Jeff Horner)
+
+    o	use transparent image background by default
+
+
+0.1-1	(2005-12-23)
+    o	first official release, image backend works, others are
+	waiting to be implemented by volunteers
+
diff --git a/R/Cairo.R b/R/Cairo.R
new file mode 100644
index 0000000..41803e3
--- /dev/null
+++ b/R/Cairo.R
@@ -0,0 +1,156 @@
+### Copyright (C) 2004-2007 Simon Urbanek
+### License: GPL v2
+
+### mapping of supported type names to canonical type names
+### as of 1.3-2 png/png24/png32 are the same (we don't support png8 anyway)
+.supported.types <- c(png="png",png24="png",png32="png",jpeg="jpeg",jpg="jpeg",tiff="tiff",tif="tiff",
+					  pdf="pdf",svg="svg",ps="ps",postscript="ps",x11="x11",xlib="x11",
+					  win="win",win32="win",window="win",windows="win",w32="win",raster="raster")
+
+Cairo <- function(width=640, height=480, file="", type="png", pointsize=12, bg="transparent", canvas="white", units="px", dpi="auto", ...) {
+	ctype <- tolower(type)
+	if (!ctype %in% names(.supported.types))
+		stop("Unknown output type `",type,"'.")
+	ctype <- .supported.types[ctype==names(.supported.types)]
+	if (is.null(file) || !nchar(file))
+		file <- if (ctype != 'x11') paste("plot.",ctype,sep='') else Sys.getenv("DISPLAY")
+
+	if (typeof(file) == "character" && length(file) != 1)
+		stop("file must be a character vector of length 1 or a connection")
+	else if (inherits(file,"connection") && (summary(file)$opened != "opened" || summary(file)$"can write" != "yes"))
+		stop("connection must be open and writeable")
+	if (length(units)!=1 || ! units %in% c("px","pt","in","cm","mm"))
+		stop("invalid unit (supported are px, pt, in, cm and mm)")
+        ## res is used in bitmap wrappers to set dpi
+        ## the default is NA so we only honor it if it's set to a non-default value
+        res <- list(...)$res
+        if (!is.null(res) && all(!is.na(res))) dpi <- res
+	if (any(dpi=="auto" || dpi=="")) dpi <- 0
+	if (length(dpi)!=1 || !is.numeric(dpi) || dpi<0)
+		stop("invalid dpi specification (must be 'auto' or a positive number)")
+	dpi <- as.double(dpi)
+	## unit multiplier: >0 mpl to get inches, <0 mpl to get device pixels
+	umpl <- as.double(c(-1, 1/72, 1, 1/2.54, 1/25.4)[units==c("px","pt","in","cm","mm")])
+	gdn<-.External("cairo_create_new_device", as.character(ctype), file, width, height, pointsize, bg, canvas, umpl, dpi, ..., PACKAGE="Cairo")
+	par(bg=bg)
+	invisible(structure(gdn,class=c("Cairo",paste("Cairo",toupper(ctype),sep='')),type=as.character(ctype),file=file))
+}
+
+Cairo.capabilities <- function() {
+    ust <- unique(.supported.types)
+    cap <- !is.na(match(ust, .Call("Rcairo_supported_types", PACKAGE="Cairo")))
+    names(cap) <- ust
+    cap
+}
+
+###-------------- supporting functions -----------------
+
+CairoFontMatch <- function(fontpattern="Helvetica",sort=FALSE,verbose=FALSE) {
+	if (typeof(fontpattern) != "character")
+		stop("fontname must be a character vector of length 1")
+
+	if (typeof(sort) != "logical")
+		stop("sort option must be a logical")
+
+	if (typeof(verbose) != "logical")
+		stop("verbose option must be a logical")
+
+	invisible(.External("cairo_font_match",fontpattern,sort,verbose,PACKAGE="Cairo"))
+}
+
+CairoFonts <- function(regular="Helvetica:style=Regular",bold="Helvetica:style=Bold",italic="Helvetica:style=Italic",bolditalic="Helvetica:style=Bold Italic,BoldItalic",symbol="Symbol"){
+	if (!is.null(regular) && typeof(regular) != "character")
+		stop("regular option must be a character vector of length 1")
+	if (!is.null(bold) && typeof(bold) != "character")
+		stop("bold option must be a character vector of length 1")
+	if (!is.null(italic) && typeof(italic) != "character")
+		stop("italic option must be a character vector of length 1")
+	if (!is.null(bolditalic) && typeof(bolditalic) != "character")
+		stop("bolditalic option must be a character vector of length 1")
+	if (!is.null(symbol) && typeof(symbol) != "character")
+		stop("symbol option must be a character vector of length 1")
+	invisible(.External("cairo_font_set",regular,bold,italic,bolditalic,symbol,PACKAGE="Cairo"))
+}
+
+
+###-------------- convenience wrapper functions -----------------
+
+CairoX11 <- function(display=Sys.getenv("DISPLAY"), width = 7, height = 7, pointsize = 12,
+					 gamma = getOption("gamma"), bg = "transparent", canvas = "white",
+					 xpos = NA, ypos = NA, ...) {
+	Cairo(width, height, file=display, type='x11', pointsize=pointsize, bg=bg, units="in", ...)
+}
+
+CairoPNG <- function(filename = "Rplot%03d.png", width = 480, height = 480,
+					 pointsize = 12, bg = "white",  res = NA, ...) {
+	Cairo(width, height, type='png', file=filename, pointsize=pointsize, bg=bg, res=res, ...)
+}
+
+CairoTIFF <- function(filename = "Rplot%03d.tiff", width = 480, height = 480,
+					  pointsize = 12, bg = "white",  res = NA, ...) {
+	Cairo(width, height, type='tiff', file=filename, pointsize=pointsize, bg=bg, res=res, ...)
+}
+
+CairoJPEG <- function(filename = "Rplot%03d.jpeg", width = 480, height = 480,
+					  pointsize = 12, quality = 75, bg = "white", res = NA, ...) {
+	Cairo(width, height, type='jpeg', file=filename, pointsize=pointsize, bg=bg, quality=quality, res=res, ...)
+}
+
+CairoPDF <- function(file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),
+					 width = 6, height = 6, onefile = TRUE, family = "Helvetica",
+					 title = "R Graphics Output", fonts = NULL, version = "1.1",
+					 paper = "special", encoding, bg, fg, pointsize, pagecentre) {
+	if (!onefile) stop("Sorry, PDF backend of Cairo supports onefile=TRUE only")
+    if (missing(pointsize)) pointsize <- 12
+    if (missing(bg)) bg <- "white"
+	Cairo(width, height, file, "pdf", pointsize=pointsize, bg=bg, units="in")
+}
+
+CairoSVG <- function(file = ifelse(onefile, "Rplots.svg", "Rplot%03d.svg"),
+                     width = 6, height = 6, onefile = TRUE, bg = "transparent",
+                     pointsize = 12, ...) {
+    if (!onefile) stop("Sorry, SVG backend of Cairo supports onefile=TRUE only")
+    Cairo(width, height, type='svg', file=file, pointsize=pointsize, bg=bg, units='in', ...)
+}
+
+CairoPS <- function(file = ifelse(onefile, "Rplots.ps", "Rplot%03d.ps"),
+                    onefile = TRUE, family,
+                    title = "R Graphics Output", fonts = NULL,
+                    encoding, bg, fg,
+                    width, height, horizontal, pointsize,
+                    paper, pagecentre, print.it, command, colormodel) {
+	if (!onefile) stop("Sorry, PostScript backend of Cairo supports onefile=TRUE only")
+    if (missing(pointsize)) pointsize <- 12
+    if (missing(bg)) bg <- "white"
+    # the following are different from R's postscript defaults!
+    # the PS device uses page dimensions, we don't
+    if (missing(width)) width <- 8
+    if (missing(height)) height <- 6
+    Cairo(width, height, file, "ps", pointsize=pointsize, bg=bg, units="in")
+}
+
+CairoWin <- function(width = 7, height = 7, pointsize = 12,
+					 record = getOption("graphics.record"),
+					 rescale = c("R", "fit", "fixed"), xpinch, ypinch,
+					 bg = "transparent", canvas = "white",
+					 gamma = getOption("gamma"), xpos = NA, ypos = NA,
+					 buffered = getOption("windowsBuffered"),
+					 restoreConsole = FALSE, ...) {
+	Cairo(width, height, '', 'win', pointsize=pointsize, bg=bg, units="in", ...)
+}
+
+Cairo.serial <- function(device = dev.cur()) .Call("Cairo_get_serial", device, PACKAGE="Cairo")
+
+Cairo.onSave <- function(device = dev.cur(), onSave) .Call("Cairo_set_onSave", device, onSave, PACKAGE="Cairo")
+
+Cairo.capture <- function(device = dev.cur()) .Call("Rcairo_capture", device, PACKAGE="Cairo")
+
+Cairo.snapshot <- function(device = dev.cur(), last=FALSE) {
+    res <- if (is.na(last)) {
+        res <- .Call("Rcairo_snapshot", device, FALSE, PACKAGE="Cairo")
+        if (is.null(res[[1]])) .Call("Rcairo_snapshot", device, TRUE, PACKAGE="Cairo") else res
+    } else .Call("Rcairo_snapshot", device, last, PACKAGE="Cairo")
+    attr(res, "pid") <- Sys.getpid()
+    class(res) <- "recordedplot"
+    res
+}
diff --git a/R/imgtools.R b/R/imgtools.R
new file mode 100644
index 0000000..92352c8
--- /dev/null
+++ b/R/imgtools.R
@@ -0,0 +1,16 @@
+.image <- function(device) {
+    a <- .Call("get_img_backplane", device, PACKAGE="Cairo")
+    names(a) <- c('ref', 'info')
+    a$width <- a[[2]][1]
+    a$height <- a[[2]][2]
+    a$format <- c("ARGB","RGB","A8","A1","dep","RGB16")[a[[2]][3]+1]
+    class(a) <- "CairoImageRef"
+    a
+}
+
+.ptr.to.raw <- function(ptr, begin, length)
+    .Call("ptr_to_raw", ptr, begin, length, PACKAGE="Cairo")
+
+.raw.to.ptr <- function(ptr, offset=0, raw, begin=0, length=length(raw))
+    invisible(.Call("raw_to_ptr", ptr, offset, raw, begin, length, PACKAGE="Cairo"))
+
diff --git a/R/zzz.R b/R/zzz.R
new file mode 100644
index 0000000..36723a8
--- /dev/null
+++ b/R/zzz.R
@@ -0,0 +1,10 @@
+.onLoad <- function(libname, pkgname) {
+    ## add our libs to the PATH
+    if (.Platform$OS.type=="windows") {
+        lp<-gsub("/","\\\\",paste(libname,pkgname,"libs",sep="/"))
+        cp<-strsplit(Sys.getenv("PATH"),";")
+        if (! lp %in% cp) Sys.setenv(PATH=paste(lp,Sys.getenv("PATH"),sep=";"))
+    }
+    library.dynam("Cairo", pkgname, libname)
+    .Call("Rcairo_initialize", PACKAGE="Cairo")
+}
diff --git a/configure b/configure
new file mode 100755
index 0000000..282cbd7
--- /dev/null
+++ b/configure
@@ -0,0 +1,5155 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.69 for Cairo 1.3.
+#
+# Report bugs to <Simon.Urbanek at r-project.org>.
+#
+#
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     # Try only shells that exist, to save several forks.
+	     as_shell=$as_dir/$as_base
+	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+	   done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf at gnu.org and
+$0: Simon.Urbanek at r-project.org about your system,
+$0: including any error possibly output before this
+$0: message. Then install a modern shell, or manually run
+$0: the script under such a shell if you do have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='Cairo'
+PACKAGE_TARNAME='cairo'
+PACKAGE_VERSION='1.3'
+PACKAGE_STRING='Cairo 1.3'
+PACKAGE_BUGREPORT='Simon.Urbanek at r-project.org'
+PACKAGE_URL=''
+
+ac_unique_file="src/cairogd.c"
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+PKGCONF
+EGREP
+GREP
+CPP
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+R_HOME
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *=)   ac_optarg= ;;
+  *)    ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures Cairo 1.3 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking ...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/cairo]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of Cairo 1.3:";;
+   esac
+  cat <<\_ACEOF
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CPP         C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <Simon.Urbanek at r-project.org>.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+Cairo configure 1.3
+generated by GNU Autoconf 2.69
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } > conftest.i && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval \${$3+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( $as_echo "## ------------------------------------------ ##
+## Report this to Simon.Urbanek at r-project.org ##
+## ------------------------------------------ ##"
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 test -x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by Cairo $as_me 1.3, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	$as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  # We do not want a PATH search for config.site.
+  case $CONFIG_SITE in #((
+    -*)  ac_site_file1=./$CONFIG_SITE;;
+    */*) ac_site_file1=$CONFIG_SITE;;
+    *)   ac_site_file1=./$CONFIG_SITE;;
+  esac
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file" \
+      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+ac_config_headers="$ac_config_headers src/cconfig.h"
+
+
+# find R home and set CC/CFLAGS
+: ${R_HOME=`R RHOME`}
+if test -z "${R_HOME}"; then
+  echo "could not determine R_HOME"
+  exit 1
+fi
+RBIN="${R_HOME}/bin/R"
+CC=`"${RBIN}" CMD config CC`;
+CFLAGS=`"${RBIN}" CMD config CFLAGS`
+CPP=`"${RBIN}" CMD config CPP`;
+
+
+# platform check
+#AC_CANONICAL_HOST
+
+# Checks for programs.
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
+	break;;
+    * )
+	break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+if test -z "$ac_file"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if ${ac_cv_objext+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if ${ac_cv_c_compiler_gnu+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if ${ac_cv_prog_cc_g+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if ${ac_cv_prog_cc_c89+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+struct stat;
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Checks for libraries.
+
+# Checks for header files.
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if ${ac_cv_prog_CPP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if ${ac_cv_path_GREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_GREP" || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if ${ac_cv_header_stdc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5
+$as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; }
+if ${ac_cv_header_sys_wait_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/wait.h>
+#ifndef WEXITSTATUS
+# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif
+
+int
+main ()
+{
+  int s;
+  wait (&s);
+  s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_sys_wait_h=yes
+else
+  ac_cv_header_sys_wait_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_wait_h" >&5
+$as_echo "$ac_cv_header_sys_wait_h" >&6; }
+if test $ac_cv_header_sys_wait_h = yes; then
+
+$as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+for ac_header in string.h sys/time.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+# Checks for typedefs, structures, and compiler characteristics.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
+$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
+if ${ac_cv_c_const+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this sort of thing.  */
+  typedef int charset[2];
+  const charset cs = { 0, 0 };
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *pcpcc;
+  char **ppc;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  pcpcc = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++pcpcc;
+  ppc = (char**) pcpcc;
+  pcpcc = (char const *const *) ppc;
+  { /* SCO 3.2v4 cc rejects this sort of thing.  */
+    char tx;
+    char *t = &tx;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+    if (s) return 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; } bx;
+    struct s *b = &bx; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+    if (!foo) return 0;
+  }
+  return !cs[0] && !zero.x;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_const=yes
+else
+  ac_cv_c_const=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
+$as_echo "$ac_cv_c_const" >&6; }
+if test $ac_cv_c_const = no; then
+
+$as_echo "#define const /**/" >>confdefs.h
+
+fi
+
+#AC_HEADER_TIME
+
+# Checks for library functions.
+#AC_FUNC_MALLOC
+#AC_TYPE_SIGNAL
+
+# Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PKGCONF+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKGCONF in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKGCONF="$PKGCONF" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/usr/local/bin:ext/bin:ext:/sw/bin:/opt/bin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PKGCONF="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKGCONF=$ac_cv_path_PKGCONF
+if test -n "$PKGCONF"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONF" >&5
+$as_echo "$PKGCONF" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+have_cairo=no
+if test "xx$CAIRO_LIBS" == "xx"; then
+   if test "xx$PKGCONF" != "xx"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether pkg-config knows about cairo" >&5
+$as_echo_n "checking whether pkg-config knows about cairo... " >&6; }
+      if "${PKGCONF}" --exists cairo; then
+         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for configurable backends" >&5
+$as_echo_n "checking for configurable backends... " >&6; }
+	 modlist="cairo"
+	 for module in cairo-ft cairo-pdf cairo-png cairo-ps cairo-svn cairo-xlib cairo-xlib-xrender cairo-win32; do
+	    if "${PKGCONF}" --exists ${module}; then
+		modlist="${modlist} ${module}"
+	    fi
+	 done
+	 { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${modlist}" >&5
+$as_echo "${modlist}" >&6; }
+	 CAIRO_CFLAGS=`"${PKGCONF}" --cflags ${modlist}`
+	 CAIRO_LIBS=`"${PKGCONF}" --libs ${modlist}`
+      else
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+      fi
+   fi
+fi
+if test -z "${CAIRO_LIBS}"; then
+   { $as_echo "$as_me:${as_lineno-$LINENO}: CAIRO_LIBS is unset, attempting to guess it." >&5
+$as_echo "$as_me: CAIRO_LIBS is unset, attempting to guess it." >&6;}
+   cpre=''
+   for pre in /usr /usr/local /usr/X11 /usr/X11R6 /opt /sw; do
+      if test -e "${pre}/include/cairo/cairo.h"; then
+         cpre=${pre}; break
+      fi
+   done
+   if test -n "${cpre}"; then
+      CAIRO_CFLAGS="-I${cpre}/include/cairo"
+      if test "${cpre}" = /usr; then
+         CAIRO_LIBS="-lcairo"
+      else
+         CAIRO_LIBS="-L${cpre}/lib -lcairo"
+      fi
+   fi
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: CAIRO_CFLAGS=${CAIRO_CFLAGS}" >&5
+$as_echo "$as_me: CAIRO_CFLAGS=${CAIRO_CFLAGS}" >&6;}
+
+# Check for Rconn patch
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if R was compiled with the RConn patch" >&5
+$as_echo_n "checking if R was compiled with the RConn patch... " >&6; }
+if test -f "${R_HOME}/include/R_ext/RConn.h"; then
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	HAVE_RCONN_H="-DHAVE_RCONN_H"
+else
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	HAVE_RCONN_H=""
+fi
+
+CPPFLAGS="$CPPFLAGS ${CAIRO_CFLAGS} ${HAVE_RCONN_H}"
+
+ac_fn_c_check_header_mongrel "$LINENO" "cairo.h" "ac_cv_header_cairo_h" "$ac_includes_default"
+if test "x$ac_cv_header_cairo_h" = xyes; then :
+
+else
+  as_fn_error $? "Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly." "$LINENO" 5
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PNG support in Cairo" >&5
+$as_echo_n "checking for PNG support in Cairo... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include "cairo.h"
+int main(void) {
+#ifndef CAIRO_HAS_PNG_FUNCTIONS
+#error no PNG support
+#endif
+    return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+as_fn_error $? "Cairo library has no PNG support." "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+uses_ats=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ATS font support in Cairo" >&5
+$as_echo_n "checking for ATS font support in Cairo... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include "cairo.h"
+int main(void) {
+#ifndef CAIRO_HAS_ATSUI_FONT
+#error no PNG support
+#endif
+    return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+uses_ats=yes
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+if test "xx${CAIRO_LIBS}" == "xx"; then
+   if test $uses_ats == "yes"; then
+      CAIRO_LIBS="-lcairo -lpng -lz -framework ApplicationServices"
+   else
+      CAIRO_LIBs="-lcairo -lpng -lz"
+   fi
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: CAIRO_LIBS=${CAIRO_LIBS}" >&5
+$as_echo "$as_me: CAIRO_LIBS=${CAIRO_LIBS}" >&6;}
+
+LIBS="$LIBS ${CAIRO_LIBS}"
+
+#AC_CHECK_LIB(cairo, cairo_create,,
+#[AC_MSG_ERROR([Cannot link to cairo library. Please check config.log for details and set CAIRO_LIBS accordingly.])])
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing deflate" >&5
+$as_echo_n "checking for library containing deflate... " >&6; }
+if ${ac_cv_search_deflate+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char deflate ();
+int
+main ()
+{
+return deflate ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' z; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_deflate=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_deflate+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_deflate+:} false; then :
+
+else
+  ac_cv_search_deflate=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_deflate" >&5
+$as_echo "$ac_cv_search_deflate" >&6; }
+ac_res=$ac_cv_search_deflate
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether Cairo programs can be compiled" >&5
+$as_echo_n "checking whether Cairo programs can be compiled... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <cairo.h>
+int main(void) {
+  cairo_surface_t *cs = 0;
+  cairo_t *cr;
+  cr = cairo_create(cs);
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  as_fn_error $? "Cannot compile a simple Cairo program. See config.log for details." "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+
+ac_fn_c_check_decl "$LINENO" "cairo_image_surface_get_format" "ac_cv_have_decl_cairo_image_surface_get_format" "$ac_includes_default"
+if test "x$ac_cv_have_decl_cairo_image_surface_get_format" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_CAIRO_IMAGE_SURFACE_GET_FORMAT $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+  #include <cairo.h>
+fi
+
+
+has_cairo_ft=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for FreeType support in cairo" >&5
+$as_echo_n "checking for FreeType support in cairo... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <cairo.h>
+#ifndef CAIRO_HAS_FT_FONT
+#error nope, no ft
+#endif
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  has_cairo_ft=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${has_cairo_ft}" >&5
+$as_echo "${has_cairo_ft}" >&6; }
+
+need_xtra_ft_flags=no
+if test "${has_cairo_ft}" = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether FreeType needs additional flags" >&5
+$as_echo_n "checking whether FreeType needs additional flags... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <cairo.h>
+#include <cairo-ft.h>
+int main(void) {
+   cairo_ft_font_face_create_for_pattern(0);
+   return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  need_xtra_ft_flags=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${need_xtra_ft_flags}" >&5
+$as_echo "${need_xtra_ft_flags}" >&6; }
+fi
+
+if test "${need_xtra_ft_flags}" = yes; then
+ if test -n "${PKGCONF}"; then
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether pkg-config knows about fontconfig or freetype2" >&5
+$as_echo_n "checking whether pkg-config knows about fontconfig or freetype2... " >&6; }
+   ftmod=''
+   for module in fontconfig freetype2; do
+      if "${PKGCONF}" --exists ${module}; then ftmod="${ftmod} ${module}"; fi
+   done
+   if test -n "${ftmod}"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+      FT_CPPFLAGS=`"${PKGCONF}" --cflags ${ftmod}`
+      FT_LIBS=`"${PKGCONF}" --libs ${ftmod}`
+   else
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+   fi
+ fi
+ if test -z "${FT_LIBS}"; then
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether fontconfig/freetype2 location can be guessed" >&5
+$as_echo_n "checking whether fontconfig/freetype2 location can be guessed... " >&6; }
+   FCI=''; FTI=''; FCL=''; FTL=''
+   for pre in /usr /usr/X11 /usr/X11R6 /usr/local /opt /sw; do
+     if test -z "${FCI}" -a -e "${pre}/include/fontconfig/fontconfig.h"; then
+        FCI="-I${pre}/include"
+	FCL="-L${pre}/lib"
+     fi
+     if test -z "{FTI}" -a -e "${pre}/include/freetype2/freetype/freetype.h"; then
+        FTI="-I${pre}/include/freetype2"
+	FTL="-L${pre}/lib"
+     fi
+   done
+   if test "${FCI}" = -I/usr/include; then FCI=''; fi
+   if test "${FCL}" = "-L/usr/lib"; then FCL=''; fi
+   if test "${FTL}" = "-L/usr/lib"; then FTL=''; fi
+   if test "${FTL}" = "${FCL}"; then FTL=''; fi
+   if test -z "${FCI}" -a -z "${FTI}"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+      as_fn_error $? "Cannot find fontconfig/freetype2 although cairo claims to support it. Please check your cairo installation and/or update cairo if necessary or set CAIRO_CFLAGS/CAIRO_LIBS accordingly." "$LINENO" 5
+   fi
+   FT_CPPFLAGS="${FCI} ${FTI}"
+   FT_LIBS="${FCL} ${FTL} -lfontconfig -lfreetype -lz"
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: possibly" >&5
+$as_echo "possibly" >&6; }
+ fi
+ zLIBS="${LIBS}"
+ LIBS="${LIBS} ${FT_LIBS}"
+ zCPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${CPPFLAGS} ${FT_CPPFLAGS}"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether additional flags work" >&5
+$as_echo_n "checking whether additional flags work... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <cairo.h>
+#include <cairo-ft.h>
+int main(void) {
+   cairo_ft_font_face_create_for_pattern(0);
+   return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ CAIRO_LIBS="${CAIRO_LIBS} ${FT_LIBS}"
+ CAIRO_CFLAGS="${CAIRO_CFLAGS} ${FT_CPPFLAGS}"
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ as_fn_error $? "Cannot use cairo-ft backend, although cairo claims it is working. Please check your caito installation and/or update cairo if necessary or set CAIRO_CFLAGS/CAIRO_LIBS accordingly." "$LINENO" 5
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+# --- check for JPEG support ---
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wheter libjpeg works" >&5
+$as_echo_n "checking wheter libjpeg works... " >&6; }
+zLIBS="${LIBS}"
+LIBS="${LIBS} -ljpeg"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdio.h>
+#include <jpeglib.h>
+int main(void) {
+  struct jpeg_compress_struct cinfo;
+  jpeg_create_compress(&cinfo);
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define SUPPORTS_JPEG 1" >>confdefs.h
+
+else
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    LIBS="${zLIBS}"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+# --- check for TIFF support
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking wheter libtiff works" >&5
+$as_echo_n "checking wheter libtiff works... " >&6; }
+zLIBS="${LIBS}"
+LIBS="${LIBS} -ltiff"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <tiffio.h>
+int main(void) {
+  TIFF *out = TIFFOpen("new.tif", "w");
+  TIFFSetField (out, TIFFTAG_IMAGEWIDTH, 100);
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+$as_echo "#define SUPPORTS_TIFF 1" >>confdefs.h
+
+else
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    LIBS="${zLIBS}"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+ac_config_files="$ac_config_files src/Makevars"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    if test "x$cache_file" != "x/dev/null"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+	cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+	  mv -f confcache "$cache_file"$$ &&
+	  mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+	  mv -f confcache "$cache_file" ;;
+	esac
+      fi
+    fi
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: "${CONFIG_STATUS=./config.status}"
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by Cairo $as_me 1.3, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Report bugs to <Simon.Urbanek at r-project.org>."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+Cairo config.status 1.3
+configured by $0, generated by GNU Autoconf 2.69,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=?*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  --*=)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    '') as_fn_error $? "missing file argument" ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    as_fn_error $? "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "src/cconfig.h") CONFIG_HEADERS="$CONFIG_HEADERS src/cconfig.h" ;;
+    "src/Makevars") CONFIG_FILES="$CONFIG_FILES src/Makevars" ;;
+
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp= ac_tmp=
+  trap 'exit_status=$?
+  : "${ac_tmp:=$tmp}"
+  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
+h
+s///
+s/^/:/
+s/[	 ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[	 ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_tt"; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[	 ]*#[	 ]*define[	 ][	 ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    "
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$ac_tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$ac_tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
+      "$ac_tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&2;}
+
+  rm -f "$ac_tmp/stdin"
+  case $ac_file in
+  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+  if test x"$ac_file" != x-; then
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
+    } >"$ac_tmp/config.h" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      rm -f "$ac_file"
+      mv "$ac_tmp/config.h" "$ac_file" \
+	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    fi
+  else
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
+      || as_fn_error $? "could not create -" "$LINENO" 5
+  fi
+ ;;
+
+
+  esac
+
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..a9fe730
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,273 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT(Cairo, 1.3, Simon.Urbanek at r-project.org)
+AC_CONFIG_SRCDIR([src/cairogd.c])
+AC_CONFIG_HEADER([src/cconfig.h])
+
+# find R home and set CC/CFLAGS
+: ${R_HOME=`R RHOME`}
+if test -z "${R_HOME}"; then
+  echo "could not determine R_HOME"
+  exit 1
+fi
+RBIN="${R_HOME}/bin/R"
+CC=`"${RBIN}" CMD config CC`;
+CFLAGS=`"${RBIN}" CMD config CFLAGS`
+CPP=`"${RBIN}" CMD config CPP`;
+AC_SUBST(R_HOME)
+
+# platform check
+#AC_CANONICAL_HOST
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_HEADER_SYS_WAIT
+AC_CHECK_HEADERS([string.h sys/time.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+#AC_HEADER_TIME
+
+# Checks for library functions.
+#AC_FUNC_MALLOC
+#AC_TYPE_SIGNAL
+
+AC_PATH_PROG([PKGCONF],[pkg-config],[],[$PATH:/usr/local/bin:ext/bin:ext:/sw/bin:/opt/bin])
+
+have_cairo=no
+if test "xx$CAIRO_LIBS" == "xx"; then
+   if test "xx$PKGCONF" != "xx"; then
+      AC_MSG_CHECKING([whether pkg-config knows about cairo])
+      if "${PKGCONF}" --exists cairo; then
+         AC_MSG_RESULT([yes])
+	 AC_MSG_CHECKING([for configurable backends])
+	 modlist="cairo"
+	 for module in cairo-ft cairo-pdf cairo-png cairo-ps cairo-svn cairo-xlib cairo-xlib-xrender cairo-win32; do
+	    if "${PKGCONF}" --exists ${module}; then
+		modlist="${modlist} ${module}"
+	    fi
+	 done
+	 AC_MSG_RESULT(${modlist})
+	 CAIRO_CFLAGS=`"${PKGCONF}" --cflags ${modlist}`
+	 CAIRO_LIBS=`"${PKGCONF}" --libs ${modlist}`
+      else
+	AC_MSG_RESULT([no])
+      fi
+   fi
+fi
+if test -z "${CAIRO_LIBS}"; then
+   AC_MSG_NOTICE([CAIRO_LIBS is unset, attempting to guess it.])
+   cpre=''
+   for pre in /usr /usr/local /usr/X11 /usr/X11R6 /opt /sw; do
+      if test -e "${pre}/include/cairo/cairo.h"; then
+         cpre=${pre}; break
+      fi
+   done
+   if test -n "${cpre}"; then
+      CAIRO_CFLAGS="-I${cpre}/include/cairo"
+      if test "${cpre}" = /usr; then
+         CAIRO_LIBS="-lcairo"
+      else
+         CAIRO_LIBS="-L${cpre}/lib -lcairo"
+      fi
+   fi
+fi
+
+AC_MSG_NOTICE([CAIRO_CFLAGS=${CAIRO_CFLAGS}])
+
+# Check for Rconn patch
+AC_MSG_CHECKING([if R was compiled with the RConn patch])
+if test -f "${R_HOME}/include/R_ext/RConn.h"; then
+	AC_MSG_RESULT([yes])
+	HAVE_RCONN_H="-DHAVE_RCONN_H"
+else
+	AC_MSG_RESULT([no])
+	HAVE_RCONN_H=""
+fi
+
+CPPFLAGS="$CPPFLAGS ${CAIRO_CFLAGS} ${HAVE_RCONN_H}"
+
+AC_CHECK_HEADER(cairo.h,,AC_MSG_ERROR([Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.]))
+
+AC_MSG_CHECKING([for PNG support in Cairo])
+AC_LINK_IFELSE([
+#include "cairo.h"
+int main(void) {
+#ifndef CAIRO_HAS_PNG_FUNCTIONS
+#error no PNG support
+#endif
+    return 0;
+}],[AC_MSG_RESULT([yes])] ,[AC_MSG_RESULT([no])
+AC_MSG_ERROR([Cairo library has no PNG support.])])
+
+uses_ats=no
+AC_MSG_CHECKING([for ATS font support in Cairo])
+AC_LINK_IFELSE([
+#include "cairo.h"
+int main(void) {
+#ifndef CAIRO_HAS_ATSUI_FONT
+#error no PNG support
+#endif
+    return 0;
+}],[AC_MSG_RESULT([yes])
+uses_ats=yes],[AC_MSG_RESULT([no])])
+
+if test "xx${CAIRO_LIBS}" == "xx"; then
+   if test $uses_ats == "yes"; then
+      CAIRO_LIBS="-lcairo -lpng -lz -framework ApplicationServices"
+   else
+      CAIRO_LIBs="-lcairo -lpng -lz"
+   fi
+fi
+
+AC_MSG_NOTICE([CAIRO_LIBS=${CAIRO_LIBS}])
+
+LIBS="$LIBS ${CAIRO_LIBS}"
+
+#AC_CHECK_LIB(cairo, cairo_create,,
+#[AC_MSG_ERROR([Cannot link to cairo library. Please check config.log for details and set CAIRO_LIBS accordingly.])])
+
+AC_SEARCH_LIBS(deflate, z)
+
+AC_MSG_CHECKING([whether Cairo programs can be compiled])
+AC_LINK_IFELSE([
+#include <cairo.h>
+int main(void) {
+  cairo_surface_t *cs = 0;
+  cairo_t *cr;
+  cr = cairo_create(cs);
+  return 0;
+}
+],[AC_MSG_RESULT(yes)],[AC_MSG_ERROR([Cannot compile a simple Cairo program. See config.log for details.])])
+
+
+dnl AC_CHECK_LIB(cairo, cairo_image_surface_get_format)
+dnl if test "$ac_cv_lib_cairo_cairo_image_surface_get_format" != "yes"; then
+dnl   AC_MSG_ERROR([Cairo is too old: >= 1.2 is needed.])
+dnl fi
+AC_CHECK_DECLS([cairo_image_surface_get_format], [#include <cairo.h>])
+
+has_cairo_ft=no
+AC_MSG_CHECKING([for FreeType support in cairo])
+AC_COMPILE_IFELSE([
+#include <cairo.h>
+#ifndef CAIRO_HAS_FT_FONT
+#error nope, no ft
+#endif
+],[has_cairo_ft=yes])
+AC_MSG_RESULT(${has_cairo_ft})
+
+need_xtra_ft_flags=no
+if test "${has_cairo_ft}" = yes; then
+ AC_MSG_CHECKING([whether FreeType needs additional flags])
+ AC_LINK_IFELSE([
+#include <cairo.h>
+#include <cairo-ft.h>
+int main(void) {
+   cairo_ft_font_face_create_for_pattern(0);
+   return 0;
+}
+],[],[need_xtra_ft_flags=yes])
+ AC_MSG_RESULT(${need_xtra_ft_flags})
+fi
+
+if test "${need_xtra_ft_flags}" = yes; then
+ if test -n "${PKGCONF}"; then
+   AC_MSG_CHECKING([whether pkg-config knows about fontconfig or freetype2])
+   ftmod=''
+   for module in fontconfig freetype2; do
+      if "${PKGCONF}" --exists ${module}; then ftmod="${ftmod} ${module}"; fi
+   done
+   if test -n "${ftmod}"; then
+      AC_MSG_RESULT(yes)
+      FT_CPPFLAGS=`"${PKGCONF}" --cflags ${ftmod}`
+      FT_LIBS=`"${PKGCONF}" --libs ${ftmod}`
+   else
+      AC_MSG_RESULT(no)
+   fi
+ fi
+ if test -z "${FT_LIBS}"; then
+   AC_MSG_CHECKING([whether fontconfig/freetype2 location can be guessed])
+   FCI=''; FTI=''; FCL=''; FTL=''
+   for pre in /usr /usr/X11 /usr/X11R6 /usr/local /opt /sw; do
+     if test -z "${FCI}" -a -e "${pre}/include/fontconfig/fontconfig.h"; then
+        FCI="-I${pre}/include"
+	FCL="-L${pre}/lib"
+     fi
+     if test -z "{FTI}" -a -e "${pre}/include/freetype2/freetype/freetype.h"; then
+        FTI="-I${pre}/include/freetype2"
+	FTL="-L${pre}/lib"
+     fi
+   done
+   if test "${FCI}" = -I/usr/include; then FCI=''; fi
+   if test "${FCL}" = "-L/usr/lib"; then FCL=''; fi
+   if test "${FTL}" = "-L/usr/lib"; then FTL=''; fi
+   if test "${FTL}" = "${FCL}"; then FTL=''; fi
+   if test -z "${FCI}" -a -z "${FTI}"; then
+      AC_MSG_RESULT(no)
+      AC_MSG_ERROR([Cannot find fontconfig/freetype2 although cairo claims to support it. Please check your cairo installation and/or update cairo if necessary or set CAIRO_CFLAGS/CAIRO_LIBS accordingly.])
+   fi
+   FT_CPPFLAGS="${FCI} ${FTI}"
+   FT_LIBS="${FCL} ${FTL} -lfontconfig -lfreetype -lz"
+   AC_MSG_RESULT([possibly])
+ fi
+ zLIBS="${LIBS}"
+ LIBS="${LIBS} ${FT_LIBS}"
+ zCPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${CPPFLAGS} ${FT_CPPFLAGS}"
+ AC_MSG_CHECKING([whether additional flags work])
+ AC_LINK_IFELSE([
+#include <cairo.h>
+#include <cairo-ft.h>
+int main(void) {
+   cairo_ft_font_face_create_for_pattern(0);
+   return 0;
+}
+ ],[AC_MSG_RESULT(yes)
+ CAIRO_LIBS="${CAIRO_LIBS} ${FT_LIBS}"
+ CAIRO_CFLAGS="${CAIRO_CFLAGS} ${FT_CPPFLAGS}"
+ ],[
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([Cannot use cairo-ft backend, although cairo claims it is working. Please check your caito installation and/or update cairo if necessary or set CAIRO_CFLAGS/CAIRO_LIBS accordingly.])
+ ])
+fi
+
+# --- check for JPEG support ---
+AC_MSG_CHECKING([wheter libjpeg works])
+zLIBS="${LIBS}"
+LIBS="${LIBS} -ljpeg"
+AC_LINK_IFELSE([
+#include <stdio.h>
+#include <jpeglib.h>
+int main(void) {
+  struct jpeg_compress_struct cinfo;
+  jpeg_create_compress(&cinfo);
+  return 0;
+}
+],[ AC_MSG_RESULT([yes])
+    AC_DEFINE(SUPPORTS_JPEG, 1, [Define to 1 if libjpeg is present and working])],
+  [ AC_MSG_RESULT(no)
+    LIBS="${zLIBS}"])
+
+# --- check for TIFF support
+AC_MSG_CHECKING([wheter libtiff works])
+zLIBS="${LIBS}"
+LIBS="${LIBS} -ltiff"
+AC_LINK_IFELSE([
+#include <tiffio.h>
+int main(void) {
+  TIFF *out = TIFFOpen("new.tif", "w");
+  TIFFSetField (out, TIFFTAG_IMAGEWIDTH, 100);
+  return 0;
+}
+],[ AC_MSG_RESULT([yes])
+    AC_DEFINE(SUPPORTS_TIFF, 1, [Define to 1 if libtiff is present and working])],
+  [ AC_MSG_RESULT(no)
+    LIBS="${zLIBS}"])
+
+AC_CONFIG_FILES([src/Makevars])
+AC_OUTPUT
diff --git a/configure.win b/configure.win
new file mode 100644
index 0000000..2a655d9
--- /dev/null
+++ b/configure.win
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+echo "  checking cairo headers and libraries"
+allok=yes
+
+if [ ! -e src/win64/libcairo.a ]; then
+    if [ ! -e src/cairo-current-win.tar.gz ]; then
+	echo "  cannot find current cairograhics files"
+	echo "  attempting to download them"
+	echo 'download.file("http://www.rforge.net/Cairo/files/cairo-current-win.tar.gz","src/cairo-current-win.tar.gz",mode="wb")'|${R_HOME}/bin/R --vanilla --slave
+    fi
+    if [ ! -e src/cairo-current-win.tar.gz ]; then
+	allok=no
+    else
+	echo "  unpacking current cairo"
+	tar fxz src/cairo-current-win.tar.gz
+	if [ ! -e src/win64/libcairo.a ]; then
+	    allok=no
+	fi
+    fi
+fi
+
+if [ ! -e src/win64/libcairo.a ]; then
+    allok=no
+fi
+
+if [ ! -e src/win64/cconfig.h ]; then
+    echo '/* no extra features */' > src/win64/cconfig.h
+fi
+if [ ! -e src/win32/cconfig.h ]; then
+    echo '/* no extra features */' > src/win32/cconfig.h
+fi
+
+if [ ${allok} != yes ]; then
+    echo ""
+    echo " *** ERROR: unable to find cairographics files"
+    echo ""
+    echo " They must be either in src/win32 and src/win64 or in a tar-ball"
+    echo " src/cairo-current-win.tar.gz"
+    echo ""
+    echo " You can get the latest binary ball from"
+    echo " http://www.rforge.net/Cairo/files/"
+    echo ""
+    exit 1
+fi
+
+echo "  seems ok, ready to go"
+
+exit 0
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644
index 0790c6b..0000000
--- a/debian/changelog
+++ /dev/null
@@ -1,11 +0,0 @@
-r-cran-cairo (1.5-9-2) UNRELEASED; urgency=medium
-
-  * add missing copyright
-
- -- Andreas Tille <tille at debian.org>  Wed, 24 Aug 2016 06:35:45 +0200
-
-r-cran-cairo (1.5-9-1) unstable; urgency=medium
-
-  * Initial upload (Closes: #835087)
-
- -- Andreas Tille <tille at debian.org>  Mon, 22 Aug 2016 12:29:08 +0200
diff --git a/debian/compat b/debian/compat
deleted file mode 100644
index ec63514..0000000
--- a/debian/compat
+++ /dev/null
@@ -1 +0,0 @@
-9
diff --git a/debian/control b/debian/control
deleted file mode 100644
index 8f18e6b..0000000
--- a/debian/control
+++ /dev/null
@@ -1,36 +0,0 @@
-Source: r-cran-cairo
-Maintainer: Debian Med Packaging Team <debian-med-packaging at lists.alioth.debian.org>
-Uploaders: Andreas Tille <tille at debian.org>
-Section: gnu-r
-Priority: optional
-Build-Depends: debhelper (>= 9),
-               cdbs,
-               libcairo2-dev,
-               libxt-dev,
-               r-base-dev
-Standards-Version: 3.9.8
-Vcs-Browser: https://anonscm.debian.org/viewvc/debian-med/trunk/packages/R/r-cran-cairo/
-Vcs-Svn: svn://anonscm.debian.org/debian-med/trunk/packages/R/r-cran-cairo/
-Homepage: http://cran.r-project.org/web/packages/Cairo
-
-Package: r-cran-cairo
-Architecture: any
-Depends: ${shlibs:Depends},
-         ${misc:Depends},
-         ${R:Depends}
-Description: GNU R graphics device using cairo graphics library
- GNUR R graphics device using cairo graphics library for creating high-
- quality bitmap (PNG, JPEG, TIFF), vector (PDF, SVG, PostScript) and
- display (X11 and Win32) output
- .
- Cairo graphics device that can be use to create high-quality vector
- (PDF, PostScript and SVG) and bitmap output (PNG,JPEG,TIFF), and high-
- quality rendering in displays (X11 and Win32). Since it uses the same
- back-end for all output, copying across formats is WYSIWYG. Files are
- created without the dependence on X11 or other external programs. This
- device supports alpha channel (semi-transparent drawing) and resulting
- images can contain transparent and semi-transparent regions. It is ideal
- for use in server environments (file output) and as a replacement for
- other devices that don't have Cairo's capabilities such as alpha support
- or anti-aliasing. Backends are modular such that any subset of backends
- is supported.
diff --git a/debian/copyright b/debian/copyright
deleted file mode 100644
index 6cfdae5..0000000
--- a/debian/copyright
+++ /dev/null
@@ -1,32 +0,0 @@
-Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
-Upstream-Contact: Simon Urbanek <Simon.Urbanek at r-project.org>
-Upstream-Name: Cairo
-Source: http://cran.r-project.org/web/packages/Cairo
-
-Files: *
-Copyright: 2013-2016 Simon Urbanek <Simon.Urbanek at r-project.org>
-License: GPL-2
-
-Files: src/xlib-backend.c
-Copyright: 2007 Simon Urbanek
-           1995, 1996  Robert Gentleman and Ross Ihaka
-           1997--2005  Robert Gentleman, Ross Ihaka and the R Development Core Team
-License: GPL-2
-Comment: X11 window handling is based on src/modules/devX11.c from the R sources
-
-Files: debian/*
-Copyright: 2016 Andreas Tille <tille at debian.org>
-License: GPL-2
-
-License: GPL-2
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License.
- .
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
- .
- On Debian systems, the complete text of the GNU General Public License
- version 2 can be found in ‘/usr/share/common-licenses/GPL-2’.
diff --git a/debian/rules b/debian/rules
deleted file mode 100755
index 2fbba2d..0000000
--- a/debian/rules
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/make -f
-
-include /usr/share/R/debian/r-cran.mk
diff --git a/debian/source/format b/debian/source/format
deleted file mode 100644
index 163aaf8..0000000
--- a/debian/source/format
+++ /dev/null
@@ -1 +0,0 @@
-3.0 (quilt)
diff --git a/debian/watch b/debian/watch
deleted file mode 100644
index eeb3076..0000000
--- a/debian/watch
+++ /dev/null
@@ -1,2 +0,0 @@
-version=3
-http://cran.r-project.org/src/contrib/Cairo_([\d.-]*)\.tar.gz
diff --git a/man/Cairo.Rd b/man/Cairo.Rd
new file mode 100644
index 0000000..25b0108
--- /dev/null
+++ b/man/Cairo.Rd
@@ -0,0 +1,199 @@
+\name{Cairo}
+\alias{Cairo}
+\alias{CairoX11}
+\alias{CairoPNG}
+\alias{CairoPDF}
+\alias{CairoSVG}
+\alias{CairoPS}
+\alias{CairoWin}
+\alias{CairoJPEG}
+\alias{CairoTIFF}
+\title{
+  Create a new Cairo-based graphics device
+}
+\description{
+  \code{Cairo} initializes a new graphics device that uses the cairo
+  graphics library for rendering. The current implementation produces
+  high-quality PNG, JPEG, TIFF bitmap files, high resolution PDF files
+  with embedded fonts, SVG graphics and PostScript files. It also
+  provides X11 and Windows interactive graphics devices. Unlike other
+  devices it supports all graphics features including alpha blending,
+  anti-aliasing etc.
+
+  \code{CairoX11}, \code{CairoPNG}, \code{CairoPDF}, \code{CairoPS} and
+  \code{CairoSVG} are convenience wrappers of \code{Cairo} that take the
+  same arguments as the corresponding device it replaces such as
+  \code{X11}, \code{png}, \code{pdf}, etc. Use of the \code{Cairo}
+  function is encouraged as it is more flexible than the wrappers.
+}
+\usage{
+Cairo(width = 640, height = 480, file="", type="png", pointsize=12, 
+      bg = "transparent", canvas = "white", units = "px", dpi = "auto",
+      ...)
+
+CairoX11(display=Sys.getenv("DISPLAY"), width = 7, height = 7,
+         pointsize = 12, gamma = getOption("gamma"), bg = "transparent",
+         canvas = "white", xpos = NA, ypos = NA, ...)
+CairoPNG(filename = "Rplot\%03d.png", width = 480, height = 480,
+         pointsize = 12, bg = "white",  res = NA, ...)
+CairoJPEG(filename = "Rplot\%03d.jpeg", width = 480, height = 480,
+         pointsize = 12, quality = 75, bg = "white", res = NA, ...)
+CairoTIFF(filename = "Rplot\%03d.tiff", width = 480, height = 480,
+         pointsize = 12, bg = "white", res = NA, ...)
+CairoPDF(file = ifelse(onefile, "Rplots.pdf","Rplot\%03d.pdf"),
+         width = 6, height = 6, onefile = TRUE, family = "Helvetica",
+         title = "R Graphics Output", fonts = NULL, version = "1.1",
+         paper = "special", encoding, bg, fg, pointsize, pagecentre)
+CairoSVG(file = ifelse(onefile, "Rplots.svg", "Rplot\%03d.svg"),
+         width = 6, height = 6, onefile = TRUE, bg = "transparent",
+         pointsize = 12, ...)
+CairoWin(width = 7, height = 7, pointsize = 12,
+         record = getOption("graphics.record"),
+         rescale = c("R", "fit", "fixed"), xpinch, ypinch, bg =
+         "transparent", canvas = "white", gamma = getOption("gamma"),
+         xpos = NA, ypos = NA, buffered = getOption("windowsBuffered"),
+         restoreConsole = FALSE, ...)
+CairoPS(file = ifelse(onefile, "Rplots.ps", "Rplot\%03d.ps"),
+        onefile = TRUE, family, title = "R Graphics Output", fonts = NULL,
+        encoding, bg, fg, width, height, horizontal, pointsize, paper,
+        pagecentre, print.it, command, colormodel)
+}
+\arguments{
+  \item{width}{width of the plot area (also see \code{units}).}
+  \item{height}{height of the plot area (also see \code{units}).}
+  \item{file}{name of the file to be created or connection to write
+         to. Only PDF, PS and PNG types support connections. For X11
+	 type \code{file} specifies the display name. If \code{NULL} or
+	 \code{""} a reasonable default will be chosen which is
+         \code{"plot.type"} for file-oriented types and value of the
+         \code{DISPLAY} environment variable for X11. For image types
+	 the file name can contain printf-style formatting expecting
+	 one integer parameter which is the page number, such as
+	 \code{"Rplot\%03d.png"}. The page numbers start at one.}
+  \item{type}{output type. This version of Cario supports "png", "jpeg"
+  and "tiff" bitmaps (png/tiff with transparent background), "pdf"
+  PDF-file with embedded fonts, "svg" SVG-file, "ps" PostScript-file,
+  "x11" X11 interactive window and "win" Windows graphics.
+  A special type "raster" creates an image back-end that produces no
+  actual output file but can be used in conjunction with any of
+  \code{dev.capture()}, \code{grid.cap()} or \code{Cairo:::.image()}
+  to create in-memory images.
+  Depending on the support of various backends in cairo graphics some
+  of the options may not be available for your system. See
+  \code{\link{Cairo.capabilities}} function.}
+  \item{pointsize}{initial text size (in points).}
+  \item{canvas}{canvas color (must be opaque). The canvas is only used
+    by devices that display graphics on a screen and the canvas is only
+    visible only if bg is transparent.}
+  \item{bg}{plot background color (can include alpha-component or be
+  transparent alltogether).}
+  \item{units}{units for of the \code{width} and \code{height}
+         specifications. It can be any of \code{"px"} (pixels),
+         \code{"in"} (inches), \code{"pt"} (points), \code{"cm"}
+         (centimeters) or \code{"mm"} (millimeters).}
+  \item{dpi}{DPI used for the conversion of units to pixels. If set to
+    \code{"auto"} the DPI resolution will be determined by the
+    back-end.}
+  \item{...}{additional backend specific parameters (e.g. \code{quality}
+         setting for JPEG (0..100), \code{compression} for TIFF
+         (0,1=none, 5=LZW (default), 7=JPEG, 8=Adobe Deflate),
+	 \code{locator} for a custom locator function in image back-ends)
+
+    All parameters
+         listed below are defined by the other devices are are used by
+         the wrappers to make it easier replace other devices by
+         \code{Cairo}. They are described in detail in the documentation
+         corresponding to the device that is being replaced.}
+       \item{display}{X11 display, see \code{\link{X11}}}
+       \item{gamma}{gamma correction}
+       \item{xpos}{see \code{\link{X11}}}
+       \item{ypos}{see \code{\link{X11}}}
+       \item{filename}{same as \code{file} in \code{Cairo}}
+       \item{res}{resolution in ppi, see \code{\link{png}}, will
+         override \code{dpi} in \code{Cairo} if set to anything other
+         than \code{NA} or \code{NULL}. Note that cairographics does not
+         support tagging PNG output files with DPI so the raster image will
+         be produced with the dpi setting, but readers may render it at
+         some default dpi setting.}
+       \item{quality}{quality of the jpeg, see \code{\link{jpeg}}}
+       \item{onefile}{logical: if true (the default) allow multiple
+         figures in one file (see \code{\link{pdf}}). false is currently
+         not supported by vector devices}
+       \item{family}{font family, see \code{\link{pdf}}}
+       \item{title}{see \code{\link{pdf}} (ignored)}
+       \item{fonts}{see \code{\link{pdf}}, ignored, \code{Cairo}
+         automatically detects and embeds fonts}
+       \item{version}{PDF version, see \code{\link{pdf}} (ignored)}
+       \item{paper}{see \code{\link{pdf}} (ignored, \code{Cairo} uses device dimensions)}
+       \item{encoding}{see \code{\link{pdf}} (ignored, \code{Cairo} uses
+         native enconding except for symbols)}
+       \item{fg}{see \code{\link{pdf}} (ignored)}
+       \item{pagecentre}{see \code{\link{pdf}} (ignored, \code{Cairo}
+         uses device dimensions and thus it is irrelevant)}
+#ifdef windows
+       \item{record}{see \code{\link{windows}} (ignored)}
+       \item{rescale}{see \code{\link{windows}} (ignored)}
+       \item{xpinch}{see \code{\link{windows}} (ignored)}
+       \item{ypinch}{see \code{\link{windows}} (ignored)}
+       \item{buffered}{see \code{\link{windows}} (ignored, \code{Cairo}
+         always uses cache buffer)}
+       \item{restoreConsole}{see \code{\link{windows}} (ignored)}
+#endif
+#ifndef windows
+       \item{record}{Windows-specific, ignored on unix}
+       \item{rescale}{Windows-specific, ignored on unix}
+       \item{xpinch}{Windows-specific, ignored on unix}
+       \item{ypinch}{Windows-specific, ignored on unix}
+       \item{buffered}{Windows-specific, ignored on unix}
+       \item{restoreConsole}{Windows-specific, ignored on unix}
+#endif
+       \item{horizontal}{see \code{\link{postscript}} (ignored)}
+       \item{print.it}{see \code{\link{postscript}} (ignored)}
+       \item{command}{see \code{\link{postscript}} (ignored)}
+       \item{colormodel}{see \code{\link{postscript}} (ignored,
+         \code{Cairo} always uses \code{RGB} or \code{ARGB})}
+}
+\value{
+  The (invisible) return value is NULL if the device couldn't be created
+  or a \code{Cairo} object if successful. The vaule of the object is the
+  device number.
+}
+\section{Known issues}{
+  \itemize{
+    \item The X11 backend is quite slow. The reason is the cairographics
+         implementation of the backend, so we can't do much about
+         it. It should be possible to drop cairographics' Xlib
+         backend entirely and use image backend copied into an X11
+         window instead. We may try that in future releases.
+   \item TrueType (and OpenType) fonts are supported when this package is compiled
+	against a cairo graphics library configured with FreeType and
+         Fontconfig support. Therefore make sure have a cairo graphics
+         library with all bells and whistles to get a good result.
+   \item R math symbols are supported, but require a TrueType "Symbol" font accessible
+	to Cairo under that name.
+  }
+} 
+\seealso{
+  \code{\link{CairoFonts}}
+}
+\examples{
+# very simple KDE
+Cairo(600, 600, file="plot.png", type="png", bg="white")
+plot(rnorm(4000),rnorm(4000),col="#ff000018",pch=19,cex=2) # semi-transparent red
+dev.off() # creates a file "plot.png" with the above plot
+
+# you can use any Cairo backend and get the same result
+# vector, bitmap or on-screen
+CairoPDF("plot.pdf", 6, 6, bg="transparent")
+data(iris)
+attach(iris)
+plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
+     ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
+     pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
+     bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
+for (i in 1:3)
+  polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),
+    col=c("#ff000040","#00ff0040","#0000ff40")[i])
+dev.off()
+}
+\keyword{device}
diff --git a/man/Cairo.capabilities.Rd b/man/Cairo.capabilities.Rd
new file mode 100644
index 0000000..4ba97db
--- /dev/null
+++ b/man/Cairo.capabilities.Rd
@@ -0,0 +1,26 @@
+\name{Cairo.capabilities}
+\alias{Cairo.capabilities}
+\title{
+  Reports which output types are supported by this Cairo build
+}
+\description{
+  \code{Cairo.capabilities} returns a logical vector describing the
+  capabilities of this particular Cairo build.
+}
+\usage{
+Cairo.capabilities()
+}
+\details{
+  The \code{Cairo} package provides multiple back-ends, such as images
+  (PNG, JPEG, TIFF), vector graphics (PDF, PostScript, SVG) or displays
+  (X11, Windows). However, not all systems support all back-ends. The
+  \code{Cairo.capabilities} function returns a logical vector showing
+  which capabilities are supported in this particular Cairo build.
+
+  Note that the capabilities depend both on the libraries available in
+  the system as well as the compiled-in modules in cairo graphics.
+}
+\seealso{
+  \code{\link{Cairo}}
+}
+\keyword{device}
diff --git a/man/Cairo.capture.Rd b/man/Cairo.capture.Rd
new file mode 100644
index 0000000..4371ef1
--- /dev/null
+++ b/man/Cairo.capture.Rd
@@ -0,0 +1,38 @@
+\name{Cairo.capture}
+\alias{Cairo.capture}
+\alias{Cairo.snapshot}
+\title{
+  Capture contents of an image backend or a display list snapshot.
+}
+\description{
+  \code{Cairo.capture} is essentially the same as
+  \code{dev.capture(native=TRUE)} with the exception that it works where
+  \code{dev.capture} doesn't such as \code{onSave} callbacks.
+
+  \code{Cairo.snapshot} is very similar to \code{recordPlot} except it
+  also allows to retrieve the last snapshot.
+}
+\usage{
+Cairo.capture(device = dev.cur())
+Cairo.snapshot(device = dev.cur(), last=FALSE)
+}
+\arguments{
+  \item{device}{device number or an object of the class \code{Cairo} (as
+    obtained from the \code{\link{Cairo}} function).}
+  \item{last}{logical, if \code{FALSE} then a new snapshot is created
+    (exactly the same as \code{recordPlot()}), if \code{TRUE} then the last
+    known snapshot is retrieved, if \code{NA} then a snapshot is created
+    first, but if the display list is empty last snapshot is retrieved
+    instead.}
+}
+\value{
+  \code{Cairo.capture}: object of the class \code{nativeRaster}.
+
+  \code{Cairo.snapshot}: object of the class \code{recordedplot}.
+}
+\author{
+  Simon Urbanek
+}
+%\examples{
+%}
+\keyword{device}
diff --git a/man/Cairo.onSave.Rd b/man/Cairo.onSave.Rd
new file mode 100644
index 0000000..52e594c
--- /dev/null
+++ b/man/Cairo.onSave.Rd
@@ -0,0 +1,54 @@
+\name{Cairo.onSave}
+\alias{Cairo.onSave}
+\title{
+  Cairo callbacks
+}
+\description{
+  \code{Cairo.onSave} set the \code{onSave} callback which allows R code
+  to be run when Cairo finalizes a page (either due to a new page being
+  created or by the device being closed). The callback expects
+  \code{function(device, page)} where \code{device} will be the device
+  number and \code{page} is the currently finished page number (starting
+  at 1).
+}
+\usage{
+Cairo.onSave(device = dev.cur(), onSave)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{device}{device number or \code{Cairo} object (as returned by the
+    \code{\link{Cairo}} function)}
+  \item{onSave}{function that will replace the current callback or
+    \code{NULL} to remove the current callback}
+}
+%\details{
+%}
+\value{
+  The old callback being replaced or \code{NULL} if there was none.
+}
+%\references{
+%}
+\author{
+Simon Urbanek
+}
+\note{
+  The function \code{onSave} will be evaluated in the global environment
+  and no error checking is done, so you must make sure to catch errors,
+  otherwise the behavior is undefined (and may included crashing R or
+  other bad things).
+}
+\seealso{
+  \code{\link{Cairo}}
+}
+\examples{
+if (require(png, quietly=TRUE)) {
+  dev <- Cairo(800, 600, type='raster')
+  Cairo.onSave(dev, function(dev, page)
+    .GlobalEnv$png <- writePNG(Cairo.capture(dev))
+  )
+  plot(1:10, col=2)
+  dev.off()
+  str(png)
+}
+}
+\keyword{device}
diff --git a/man/Cairo.serial.Rd b/man/Cairo.serial.Rd
new file mode 100644
index 0000000..db73084
--- /dev/null
+++ b/man/Cairo.serial.Rd
@@ -0,0 +1,34 @@
+\name{Cairo.serial}
+\alias{Cairo.serial}
+\title{
+  Check for changes in the graphics state of Cairo devices.
+}
+\description{
+  \code{Cairo.serial} returns an integer that is increased with every
+  plotting operation on the device. This allows user code to determine
+  whether any new content has been added to the device since it was last
+  checked.
+}
+\usage{
+Cairo.serial(device = dev.cur())
+}
+\arguments{
+  \item{device}{device number or an object of the class \code{Cairo} (as
+    obtained from the \code{\link{Cairo}} function).}
+}
+%\details{
+%}
+\value{
+  Integer value.
+}
+\author{
+  Simon Urbanek
+}
+\note{
+  The integer value overflows to 0 at 2^31. Typically only equality
+  should be checked and for such it is extremely unlikely that the state
+  has changed yet the serial value is the same due to overflow.
+}
+%\examples{
+%}
+\keyword{device}
diff --git a/man/CairoFontMatch.Rd b/man/CairoFontMatch.Rd
new file mode 100644
index 0000000..6dfb8ac
--- /dev/null
+++ b/man/CairoFontMatch.Rd
@@ -0,0 +1,89 @@
+\name{CairoFonMatch}
+\alias{CairoFontMatch}
+\title{
+  Find installed fonts with a fontconfig pattern
+}
+\description{
+  \code{CairoFontMatch} searches for fonts based on a fontconfig pattern.
+}
+\usage{
+CairoFontMatch(fontpattern="Helvetica",sort=FALSE,verbose=FALSE)
+}
+\arguments{
+  \item{fontpattern}{character; a fontconfig pattern.}
+  \item{sort}{logical; if 'FALSE', display only the best matching font for the pattern. If 'TRUE', display a sorted list of best matching fonts.}
+  \item{verbose}{logical; if 'FALSE', display the family, style, and file property for the pattern. if 'TRUE', display the canonical font pattern for each match.}
+}
+\details{
+
+This function displays a list of one or more fonts matching the supplied
+fontconfig pattern. sort='FALSE' displays the font that Cairo will use
+for the supplied pattern, while sort='TRUE' displays a sorted list of
+best matching fonts. The simplest fontconfig pattern matching all installed fonts
+is ":". Here's what CairoFontMatch(":") displays on this system:
+
+\preformatted{
+1. family: "Bitstream Vera Sans", style: "Roman", file: "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf"
+}
+
+verbose='FALSE' displays the font properties 'family', 'style', and 'file', while
+verbose='TRUE' will display the canonical font pattern, displaying all properties known
+for the font (output of CairoFontMatch(":",verbose=TRUE)):
+
+\preformatted{
+1. family: "Bitstream Vera Sans", style: "Roman", file: "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf"
+   "Bitstream Vera Sans-12:familylang=en:style=Roman:stylelang=en:slant=0:weight=80:width=100:pixelsize=12.5:foundry=bitstream:hintstyle=3:hinting=True:verticallayout=False:autohint=False:globaladvance=True:index=0:outline=True:scalable=True:dpi=75:rgba=1:scale=1:fontversion=131072:fontformat=TrueType:embeddedbitmap=True:decorative=False"
+}
+
+A simple approach to selecting a font starts with calling CairoFontMatch(":",sort=TRUE) to
+list all available fonts. Next, the user will choose a font from the list and call
+CairoFontMatch("FamilyName:style=PreferredStyle",sort=TRUE) substituting "FamilyName"
+and "PreferredStyle" with the desired values. If only one font is found, then the user
+has found the fontconfig pattern that will select the desired font. Otherwise, the user
+will call CairoFontMatch with verbose=TRUE to determine other properties to add to
+the pattern to attain the desired font, for instance the fontformat.
+
+The following excerpt is from the fontconfig user's manual (http://fontconfig.org/) and
+better describes the fontconfig pattern definition:
+
+"Fontconfig provides a textual representation for patterns that
+the library can both accept and generate. The representation is
+in three parts, first a list of family names, second a list of
+point sizes and finally a list of additional properties:
+
+<families>-<point sizes>:<name1>=<values1>:<name2>=<values2>...
+	
+Values in a list are separated with commas. The name needn't
+include either families or point sizes; they can be elided. In
+addition, there are symbolic constants that simultaneously
+indicate both a name and a value. Here are some examples:
+
+\preformatted{
+Font Pattern                    Meaning
+----------------------------------------------------------
+Times-12                        12 point Times Roman
+Times-12:bold                   12 point Times Bold
+Courier:italic                  Courier Italic in the default size
+Monospace:matrix=1 .1 0 1       The users preferred monospace font
+                                with artificial obliquing
+}
+
+The '\', '-', ':' and ',' characters in family names
+must be preceeded by a '\' character to avoid having them
+misinterpreted. Similarly, values containing '\', '=', '\_', ':'
+and ',' must also have them preceeded by a '\' character. The
+'\' characters are stripped out of the family name and values
+as the font name is read."
+}
+
+\section{Known issues}{
+  \itemize{
+  	\item This function is only available when the Cairo graphics library is configured
+	with FreeType and Fontcofig support.
+  }
+}
+\seealso{
+  \code{\link{CairoFonts}},
+  \code{\link{Cairo}}
+}
+\keyword{device}
diff --git a/man/CairoFonts.Rd b/man/CairoFonts.Rd
new file mode 100644
index 0000000..54b9cb8
--- /dev/null
+++ b/man/CairoFonts.Rd
@@ -0,0 +1,62 @@
+\name{CairoFonts}
+\alias{CairoFonts}
+\title{
+  Set the fonts used for all Cairo graphics devices.
+}
+\description{
+  \code{CairoFonts} initializes the fonts used for Cairo graphics devices.
+}
+\usage{
+CairoFonts(
+	regular="Helvetica:style=Regular",
+	bold="Helvetica:style=Bold",
+	italic="Helvetica:style=Italic",
+	bolditalic="Helvetica:style=Bold Italic,BoldItalic",
+	symbol="Symbol"
+)
+}
+\arguments{
+  \item{regular}{character; fontconfig pattern for the 'plain text' font.}
+  \item{bold}{character; fontconfig pattern for the 'bold face' font.}
+  \item{italic}{character; fontconfig pattern for the 'italic' font.}
+  \item{bolditalic}{character; fontconfig pattern for the 'bold italic' font.}
+  \item{symbol}{character; fontconfig pattern for the 'symbol' font.}
+}
+\details{
+	This function sets the fonts for Cairo graphics devices globally; previously opened
+	Cairo graphics devices will also use these fonts. The argument names correspond to 
+	the five values of the graphical parameter 'font', i.e. regular is 1, bold is 2, italic 
+	is 3, etc.
+
+	For an explanation of fontconfig patterns, see \code{\link{CairoFontMatch}}.
+}
+\section{Known issues}{
+  \itemize{
+  	\item This function is only available when the cairo graphics library is configured
+	with FreeType and Fontcofig support.
+    \item R math symbols are supported,but require a
+    "Symbol" font with the Adobe symbol encoding. At the time of this release
+	the authors are unaware of a free version of this font, however they do exist on Windows
+	and Mac OS X.
+  }
+}
+\seealso{
+  \code{\link{CairoFontMatch}},
+  \code{\link{Cairo}},
+  \code{\link{par}},
+}
+\examples{
+\dontrun{
+#
+# The following fontconfig patterns define the free truetype fonts 
+# available in the debian package 'ttf-freefont'.
+# 
+# Freesans is very similar to Helvetica
+CairoFonts(
+	regular="FreeSans:style=Medium",
+	bold="FreeSans:style=Bold",
+	italic="FreeSans:style=Oblique",
+	bolditalic="FreeSans:style=BoldOblique"
+)
+}}
+\keyword{device}
diff --git a/src/Makevars.in b/src/Makevars.in
new file mode 100644
index 0000000..08e9dc9
--- /dev/null
+++ b/src/Makevars.in
@@ -0,0 +1,3 @@
+PKG_CFLAGS=@CFLAGS@
+PKG_CPPFLAGS=@CPPFLAGS@ -I. -Iinclude
+PKG_LIBS=@LDFLAGS@ @LIBS@
diff --git a/src/Makevars.win b/src/Makevars.win
new file mode 100644
index 0000000..66a024d
--- /dev/null
+++ b/src/Makevars.win
@@ -0,0 +1,13 @@
+ifdef DEBUG
+  XTRA_PKG_CPPFLAGS=-DJGD_DEBUG
+endif
+
+ifeq "$(WIN)" "64"
+BITS=64
+else
+BITS=32
+endif
+
+PKG_CPPFLAGS=-I. -Iwin$(BITS) $(XTRA_PKG_CPPFLAGS)
+PKG_LIBS=win$(BITS)/libcairo.a win$(BITS)/libpixman-1.a win$(BITS)/libpng.a win$(BITS)/libz.a -lgdi32 -lmsimg32 $(GRAPHAPP_LIB)
+
diff --git a/src/backend.h b/src/backend.h
new file mode 100644
index 0000000..c6661c5
--- /dev/null
+++ b/src/backend.h
@@ -0,0 +1,94 @@
+#ifndef __CAIRO_BACKEND_H__
+#define __CAIRO_BACKEND_H__
+
+/* Cario config from configure */
+#include "cconfig.h"
+
+#include <cairo.h>
+#include <R.h>
+#include <Rversion.h>
+#include <Rinternals.h>
+#include <R_ext/GraphicsEngine.h>
+#include <R_ext/GraphicsDevice.h>
+
+#if R_VERSION >= R_Version(2,8,0)
+#ifndef NewDevDesc
+#define NewDevDesc DevDesc
+#endif
+#endif
+
+#define CDF_HAS_UI    0x0001  /* backend has UI (e.g. window) */
+#define CDF_FAKE_BG   0x0002  /* fake transparent background */
+#define CDF_OPAQUE    0x0004  /* device doesn't support any kind of alpha, not even fake */
+#define CDF_NOZERO    0x0008  /* if set pages don't need to be zeroed */
+
+#define CBDF_FILE      0x0001  /* can output to file(s) */
+#define CBDF_CONN      0x0002  /* can output to a connection */
+#define CBDF_VISUAL    0x0004  /* can produce visual output (window/screen) */
+#define CBDF_MULTIPAGE 0x0008  /* supports multiple pages in one document (relevant to file/conn only) */
+
+#define fake_bg_color (0xfffefefe)
+
+/* known cairo back-ends (as of cairographics 1.4.2) */
+#define BET_IMAGE   1
+#define BET_PDF     2
+#define BET_PS      3
+#define BET_SVG     4
+#define BET_XLIB    5
+#define BET_W32     6
+#define BET_QUARTZ  7
+#define BET_USER   64
+
+typedef struct st_Rcairo_backend_def {
+    int backend_type;      /* see BET_xxx constants */
+    char **types;          /* supported types (0-terminated list) */
+    char *name;            /* human-readable back-end name */
+    int  flags;            /* see CBDF_xxx constants */
+    /*----- creation call-back -----*/
+    void *create;          /* not used yet, should be set to 0 */
+} Rcairo_backend_def;
+
+typedef struct st_Rcairo_backend {
+    int backend_type;      /* see BET_xxx constants */
+    /*----- instance variables -----*/
+    void *backendSpecific; /* private data for backend use */
+    cairo_t          *cc;  /* cairo context */
+    cairo_surface_t  *cs;  /* cairo surface */
+    NewDevDesc       *dd;  /* device descriptor */
+    double width, height;  /* size in native units (pixels or pts) */
+    int               in_replay; /* set to 1 if it is known where the painting stops
+				    and thus the backend doesn't need to perform
+				    any synchronization until we're done.
+				    if mode is set, it is called ater replay
+				    with mode=-1
+				 */
+    int               truncate_rect; /* set to 1 to truncate rectangle coordinates
+					to integers. Useful with bitmap back-ends. */
+    int               serial; /* this variable is increased with each operation
+				 so it can be used to track whether the content
+				 has potentially changed since last poll */
+    SEXP              onSave; /* optional R callback to call after the page
+				 has been saved */
+    /*----- back-end global variables (capabilities etc.) -----*/
+    int  flags; /* see CDF_xxx above */
+    double dpix, dpiy;
+    
+    /*----- back-end global callbacks (=methods) -----*/
+    /* cairo_surface_t *(*create_surface)(struct st_Rcairo_backend *be, int width, int height); */
+    void (*save_page)(struct st_Rcairo_backend *be, int pageno);
+    void (*destroy_backend)(struct st_Rcairo_backend *be);
+    
+    /* optional callbacks - must be set to 0 if unsupported */
+    int  (*locator)(struct st_Rcairo_backend *be, double *x, double *y);
+    void (*activation)(struct st_Rcairo_backend *be, int activate);  /* maps both Activate/Deactivate */
+    void (*mode)(struct st_Rcairo_backend *be, int mode); /* in addition it is called after internal replay with mode -1 */
+    void (*resize)(struct st_Rcairo_backend *be, double width, double height);
+    void (*sync)(struct st_Rcairo_backend *be); /* force sync for devices that do asynchronous drawing */
+} Rcairo_backend;
+
+/* implemented in cairotalk but can be used by any back-end to talk to the GD system */
+void Rcairo_backend_resize(Rcairo_backend *be, double width, double height); /* won't do anything if resize is not implemented in the back-end */
+void Rcairo_backend_repaint(Rcairo_backend *be); /* re-plays the display list */
+void Rcairo_backend_kill(Rcairo_backend *be); /* kills the devide */
+void Rcairo_backend_init_surface(Rcairo_backend *be); /* initialize a new surface */
+#endif
diff --git a/src/cairobem.c b/src/cairobem.c
new file mode 100644
index 0000000..fc01145
--- /dev/null
+++ b/src/cairobem.c
@@ -0,0 +1,60 @@
+/* Cairo back-end management */
+#include <R.h>
+#include <Rinternals.h>
+
+#include "backend.h"
+
+static char *types[64];
+
+static struct bed_list_st {
+  Rcairo_backend_def* bed;
+  struct bed_list_st* next;
+} root;
+
+void Rcairo_register_backend(Rcairo_backend_def* def) {
+  struct bed_list_st *l=&root;
+  while (l->bed && l->next) {
+    if (l->bed == def) return; /* nothing to do if we have this be alreay */
+    l = l->next;
+  }
+  if (l->bed) {
+    l->next = (struct bed_list_st*) malloc(sizeof(struct bed_list_st));
+    l = l->next;
+    l->next = 0;
+  }
+  l->bed = def;
+  { /* collect types list */
+    char **c = types;
+    char **d = def->types;
+    while (*c) c++;
+    while (*d) {
+      *c=*d; c++; d++;
+      if (c-types > 48) break;
+    }
+  }
+}
+
+int Rcairo_type_supported(char *type) {
+  char **c = types;
+  if (!type) return 0;
+  while (*c) {
+    if (!strcmp(type, *c)) return 1;
+    c++;
+  }
+  return 0;
+}
+
+SEXP Rcairo_supported_types() {
+  char **c = types;
+  int i = 0;
+  SEXP res;
+  while (*c) { c++; i++; }
+  PROTECT(res=allocVector(STRSXP, i));
+  i = 0; c = types;
+  while (*c) {
+    SET_STRING_ELT(res, i, mkChar(*c));
+    c++; i++;
+  }
+  UNPROTECT(1);
+  return res;
+}
diff --git a/src/cairobem.h b/src/cairobem.h
new file mode 100644
index 0000000..958461a
--- /dev/null
+++ b/src/cairobem.h
@@ -0,0 +1,8 @@
+#ifndef RCAIRO_BEM_H
+#define RCAIRO_BEM_H
+
+#include "backend.h"
+
+void Rcairo_register_backend(Rcairo_backend_def* def);
+
+#endif
diff --git a/src/cairogd.c b/src/cairogd.c
new file mode 100644
index 0000000..d3870fd
--- /dev/null
+++ b/src/cairogd.c
@@ -0,0 +1,567 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+ *  Cairo-based gd   (C)2004,5,7 Simon Urbanek (simon.urbanek at r-project.org)
+ *
+ *  Parts of this code are based on the X11 device skeleton from the R project
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define R_CairoGD 1
+#include "cairogd.h"
+#include "cairotalk.h"
+#include "img-backend.h"
+
+double jGDdpiX = 100.0;
+double jGDdpiY = 100.0;
+double jGDasp  = 1.0;
+
+#ifdef USE_GAMMA
+/* actually we use it in cairotalk as well - we may want to do soemthing about it ... */
+static SEXP findArg(char *name, SEXP list) {
+    SEXP ns = install(name);
+    while (list && list!=R_NilValue) {
+        if (TAG(list)==ns) return CAR(list);
+        list=CDR(list);
+    }
+    return 0;
+}
+#endif
+
+/* type: png[24]
+   file: file to write to
+   width/heigth
+   initps: initial PS
+   bgcolor: currently only -1 (transparent) and 0xffffff (white) are really supported
+   -
+   gamma: 0.6
+*/
+Rboolean Rcairo_new_device_driver(NewDevDesc *dd, const char *type, int conn, const char *file,
+								  double width, double height, double initps,
+								  int bgcolor, int canvas, double umul, double *dpi, SEXP aux)
+{
+	CairoGDDesc *xd;
+	double dpi_exX = 1.0, dpi_exY = 1.0;
+	
+#ifdef JGD_DEBUG
+	Rprintf("Rcairo_new_device_driver(\"%s\", \"%s\", %f, %f, %f)\n",type,file,width,height,initps);
+#endif
+	
+	
+    /* allocate new device description */
+    if (!(xd = (CairoGDDesc*)calloc(1, sizeof(CairoGDDesc))))
+		return FALSE;
+	
+#ifdef USE_MAGIC
+	xd->magic = CAIROGD_MAGIC
+#endif
+    xd->fontface = -1;
+    xd->fontsize = -1;
+    xd->basefontface = 1;
+    xd->basefontsize = initps;
+	xd->canvas = canvas;
+	xd->bg = bgcolor;
+	xd->gamma = 1.0;
+#ifdef USE_GAMMA
+	{
+		SEXP g = findArg("gamma", aux);
+		if (g ** g!=R_NilValue) xd->gamma = asReal(g);
+	}
+#endif
+	xd->asp = 1.0;
+	if (dpi) {
+		xd->dpix = dpi[0];
+		xd->dpiy = dpi[1];
+		/* FIXME: Pango uses 96dpi - do we care or are we always
+		   going through FT such that 72dpi is correct? */
+		dpi_exX = dpi[0] / 72.0;
+		dpi_exY = dpi[1] / 72.0;
+		if (dpi_exX == 0.0) dpi_exX = 1.0;
+		if (dpi_exY == 0.0) dpi_exY = 1.0;
+		if (xd->dpix > 0.0 && xd->dpiy > 0.0)
+			xd->asp = xd->dpix / xd->dpiy;
+	} else
+		xd->dpix = xd->dpiy = 0.0;
+
+	/* ---- fill dd ----- */
+
+    /*	Set up Data Structures. */
+    Rcairo_setup_gd_functions(dd);
+
+    dd->left = dd->clipLeft = 0;			/* left */
+    dd->top = dd->clipTop = 0;			/* top */
+
+    /* Nominal Character Sizes in Pixels */
+
+    dd->cra[0] = 0.9 * initps * dpi_exX; /* FIXME: we should use font metric for this */
+    dd->cra[1] = 1.2 * initps * dpi_exY;
+
+	/* adjust font size according to the DPI scalig.
+	   FIXME: we have no way of supporting non-square pixels? */
+	xd->fontscale = dpi_exX;
+
+    /* Character Addressing Offsets */
+    /* These are used to plot a single plotting character */
+    /* so that it is exactly over the plotting point */
+
+    dd->xCharOffset = 0.4900;
+    dd->yCharOffset = 0.3333;
+    dd->yLineBias = 0.1;
+
+    /* Device capabilities */
+
+#if R_GE_version < 4
+    dd->canResizePlot = TRUE; /* opt */
+    dd->canChangeFont = TRUE;
+    dd->canRotateText = TRUE;
+    dd->canResizeText = TRUE;
+#endif
+    dd->canClip = TRUE;
+    dd->canHAdj = 2;
+    dd->canChangeGamma = FALSE;
+
+    dd->startlty   = LTY_SOLID;
+    dd->startfont  = 1;
+
+	/* set default behavior - backends should change it where they diverge from the default */
+#if R_GE_version >= 9
+	dd->haveRaster = 2;       /* yes */
+	dd->haveTransparency = 2; /* yes */
+	dd->haveTransparentBg = 3;/* yes, full alpha range */
+	dd->haveCapture = 2;      /* yes */
+	dd->haveLocator = 2;      /* yes */
+#endif
+
+    dd->deviceSpecific = (void *) xd;
+
+#ifdef JGD_DEBUG
+	Rprintf("Cairo-Open, dimensions: %f x %f, umul=%f, dpi=%f/%f\n", width, height, umul, xd->dpix, xd->dpiy);
+#endif
+	/* open the device */
+    if (!CairoGD_Open(dd, xd, type, conn, file, width, height, umul, aux) || !xd->cb) {
+		free(xd);
+		dd->deviceSpecific = 0;
+		return FALSE;
+	}
+
+#if R_GE_version < 5
+	if (!xd->cb->resize)
+		dd->canResizePlot = FALSE;
+#endif
+
+	/* those were deferred, because they depend on xd and Open may have modified them */
+    dd->right   = dd->clipRight = xd->cb->width;	/* right */
+    dd->bottom  = dd->clipBottom = xd->cb->height;	/* bottom */
+    dd->startps    = xd->basefontsize; /* = initps */
+    dd->startcol   = xd->col;
+    dd->startfill  = xd->fill;
+    dd->startgamma = xd->gamma;
+
+    /* Inches per raster unit */
+	if (xd->dpix > 0 && xd->dpiy <= 0) xd->dpiy = xd->dpix;
+   	dd->ipr[0] = (xd->dpix > 0)?(1/xd->dpix):(1.0/72.0);
+   	dd->ipr[1] = (xd->dpiy > 0)?(1/xd->dpiy):(1.0/72.0);
+
+#if R_GE_version < 4
+    dd->asp = (xd->asp > 0)?xd->asp:1.0;
+#endif
+
+#ifdef JGD_DEBUG
+	Rprintf("Cairo-Open, returned: %f x %f, dpi=%f/%f\n", xd->cb->width, xd->cb->height, xd->dpix, xd->dpiy);
+	Rprintf("  ipr=%f/%f (1/ipr)=%f/%f\n", dd->ipr[0], dd->ipr[1], 1/dd->ipr[0], 1/dd->ipr[1]);
+#endif
+
+    dd->displayListOn = TRUE;
+
+    return(TRUE);
+}
+
+SEXP cairo_create_new_device(SEXP args)
+{
+    NewDevDesc *dev = NULL;
+    GEDevDesc *dd;
+    
+    const char *devname="Cairo";
+	const char *type, *file = NULL;
+	double width, height, initps, umul, dpi[2];
+	int bgcolor = -1, canvas = -1;
+	int conn = -1;
+
+	SEXP v;
+	args=CDR(args);
+	v=CAR(args); args=CDR(args);
+	if (!isString(v) || LENGTH(v)<1) error("output type must be a string");
+	PROTECT(v);
+	type=CHAR(STRING_ELT(v,0));
+	UNPROTECT(1);
+
+	v=CAR(args); args=CDR(args);
+	if (isString(v)){
+		PROTECT(v);
+		file=CHAR(STRING_ELT(v,0));
+		UNPROTECT(1);
+	} else if (isInteger(v)){
+#ifdef HAVE_RCONN_H
+		conn = asInteger(v);
+#else
+		error("file must be a filename. to support writing to a connection, recompile R and Cairo with the R Connection Patch. ");
+#endif
+	} else {
+		error("file must be a filename");
+	}
+
+
+	v=CAR(args); args=CDR(args);
+	if (!isNumeric(v)) error("`width' must be a number");
+	width=asReal(v);
+	v=CAR(args); args=CDR(args);
+	if (!isNumeric(v)) error("`height' must be a number");
+	height=asReal(v);
+	v=CAR(args); args=CDR(args);
+	if (!isNumeric(v)) error("initial point size must be a number");
+	initps=asReal(v);
+	v=CAR(args); args=CDR(args);
+	if (!isString(v) && !isInteger(v) && !isLogical(v) && !isReal(v))
+		error("invalid color specification for `bg'");
+	bgcolor = RGBpar(v, 0);
+	v=CAR(args); args=CDR(args);
+	if (!isString(v) && !isInteger(v) && !isLogical(v) && !isReal(v))
+		error("invalid color specification for `canvas'");
+	canvas = RGBpar(v, 0);
+	v=CAR(args); args=CDR(args);
+	if (!isNumeric(v)) error("unit multiplier must be a number");
+	umul = asReal(v);
+	v=CAR(args); args=CDR(args);
+	if (!isNumeric(v)) error("dpi must be a number");
+	dpi[0] = dpi[1] = asReal(v);	
+#ifdef JGD_DEBUG
+	Rprintf("type=%s, file=%s, bgcolor=0x%08x, canvas=0x%08x, umul=%f, dpi=%f\n", type, file, bgcolor, canvas, umul, dpi[0]);
+#endif
+	
+    R_CheckDeviceAvailable();
+    BEGIN_SUSPEND_INTERRUPTS {
+	if (!(dev = (NewDevDesc*)calloc(1, sizeof(NewDevDesc))))
+	    return R_NilValue;
+
+#if R_GE_version < 4
+	dev->newDevStruct = 1;
+#endif
+#if R_GE_version < 5
+	dev->displayList = R_NilValue;
+	dev->savedSnapshot = R_NilValue;
+#endif
+
+	if (!Rcairo_new_device_driver(dev, type, conn, file, width, height, initps,
+								 bgcolor, canvas, umul, dpi, args))
+	{
+	    free(dev);
+	    error("unable to start device %s", devname);
+	}
+	
+	gsetVar(install(".Device"), mkString(devname), R_NilValue);
+	dd = GEcreateDevDesc(dev);
+	GEaddDevice(dd);
+	GEinitDisplayList(dd);
+    } END_SUSPEND_INTERRUPTS;
+#ifdef JGD_DEBUG
+	Rprintf("CairoGD> devNum=%d, dd=%x\n", 1 + GEdeviceNumber(dd), dd);
+#endif
+	v = ScalarInteger(1 + GEdeviceNumber(dd));
+    return v;
+}
+
+void cairo_set_display_param(double *par) {
+	jGDdpiX = par[0];
+	jGDdpiY = par[1];
+	jGDasp  = par[2];
+}
+
+void cairo_get_display_param(double *par) {
+	par[0] = jGDdpiX;
+	par[1] = jGDdpiY;
+	par[2] = jGDasp;
+}
+
+void gdd_get_version(int *ver) {
+	*ver=CAIROGD_VER;
+}
+
+SEXP cairo_font_match(SEXP args){
+#if CAIRO_HAS_FT_FONT
+	SEXP v;
+	const char *fcname;
+	int sort;
+	int verbose;
+
+	args = CDR(args);
+
+	/* Get fontname */
+	v = CAR(args); args = CDR(args);
+	if (!isString(v) || LENGTH(v)<1){
+		warning("fontname must be a character vector of length 1\n");
+		return R_NilValue;
+	}
+
+	fcname = CHAR(STRING_ELT(v,0));
+
+	/* Get sort option */
+	v=CAR(args); args=CDR(args);
+	if (!isLogical(v) || LENGTH(v)<1){
+		warning("sort options must be a logical\n");
+		return R_NilValue;
+	}
+	
+	sort = LOGICAL(v)[0];
+
+	/* Get verbose option */
+	v=CAR(args); args=CDR(args);
+	if (!isLogical(v) || LENGTH(v)<1){
+		warning("verbose options must be a logical\n");
+		return R_NilValue;
+	}
+
+	verbose = LOGICAL(v)[0];
+
+	/* Now search for fonts */
+	{
+		FcFontSet	*fs;
+		FcPattern   *pat;
+		FcResult	result;
+
+		if (!FcInit ()) {
+			warning ("Can't init font config library\n");
+			return R_NilValue;
+		}
+		pat = FcNameParse ((FcChar8 *)fcname);
+
+		if (!pat){
+			warning ("Problem with font config library in FcNameparse\n");
+			return R_NilValue;
+		}
+
+		FcConfigSubstitute (0, pat, FcMatchPattern);
+		FcDefaultSubstitute (pat);
+		if (sort) {
+			fs = FcFontSort (0, pat, FcTrue, 0, &result);
+		} else {
+			FcPattern   *match;
+			fs = FcFontSetCreate ();
+			match = FcFontMatch (0, pat, &result);
+			if (match) FcFontSetAdd (fs, match);
+		}
+		FcPatternDestroy (pat);
+
+		if (fs) {
+			int	j;
+
+			for (j = 0; j < fs->nfont; j++) {
+				FcChar8	*family;
+				FcChar8	*style;
+				FcChar8	*file;
+
+				if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) != FcResultMatch)
+					file = (FcChar8 *) "<unknown filename>";
+				/* else
+				   {
+				   FcChar8 *slash = (FcChar8 *) strrchr ((char *) file, '/');
+				   if (slash)
+				   file = slash+1;
+				   } */
+				if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch)
+					family = (FcChar8 *) "<unknown family>";
+				if (FcPatternGetString (fs->fonts[j], FC_STYLE, 0, &style) != FcResultMatch)
+					file = (FcChar8 *) "<unknown style>";
+
+				Rprintf ("%d. family: \"%s\", style: \"%s\", file: \"%s\"\n", j+1, family, style, file);
+				if (verbose) {
+					FcPattern   *vpat;
+					FcChar8 *fname;
+
+					fname = FcNameUnparse(fs->fonts[j]);
+					if (fname) {
+						if ((vpat = FcNameParse(fname))) {
+							FcPatternDel(vpat,FC_CHARSET);
+							FcPatternDel(vpat,FC_LANG);
+							free(fname);
+							fname = FcNameUnparse(vpat);
+						}
+						Rprintf("   \"%s\"\n",fname);
+						free(fname);
+						FcPatternDestroy(vpat);
+					}
+				}
+			}
+			FcFontSetDestroy (fs);
+		}
+	}
+#else 
+	warning("the R Cairo package was not installed with font matching capability. Please consider installing the cairo graphics engine (www.cairographics.org) with freetype and fontconfig support");
+#endif
+	return R_NilValue;
+}
+
+SEXP cairo_font_set(SEXP args){
+#if CAIRO_HAS_FT_FONT
+	SEXP v;
+	int i;
+	const char *font;
+
+	args = CDR(args);
+
+	/* regular font */
+	for (i = 0; i < 5; i++){
+		v = CAR(args); args = CDR(args);
+		if (!isNull(v) && isString(v) && LENGTH(v)==1){
+			font = CHAR(STRING_ELT(v,0));
+			Rcairo_set_font(i,font);
+		}
+	}
+#else
+#ifdef WIN32
+	warning("CairoFonts() has no effect on Windows. Please use par(family=\"...\") to specify the desired font - see ?par.");
+#else
+	warning("The R Cairo package was not installed with fontconfig. Please consider installing the cairo graphics engine (www.cairographics.org) with freetype and fontconfig support");
+#endif
+#endif
+	return R_NilValue;
+}
+
+/* experimental */
+SEXP get_img_backplane(SEXP dev) {
+	int devNr = asInteger(dev)-1;
+	GEDevDesc *gd = GEgetDevice(devNr);
+	if (gd) {
+		NewDevDesc *dd=gd->dev;
+		if (dd) {
+			CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+#ifdef USE_MAGIC
+			if (xd->magic != CAIROGD_MAGIC)
+				error("Not a Cairo device");
+#endif
+			if(xd && xd->cb) {
+				int bet = xd->cb->backend_type;
+				switch (bet) {
+				case BET_IMAGE:
+					{
+						Rcairo_image_backend *image = (Rcairo_image_backend*) xd->cb->backendSpecific;
+						SEXP l = allocVector(VECSXP, 2);
+						unsigned char *data = image->buf;
+						cairo_format_t dformat = image->format;
+						int width = cairo_image_surface_get_width(xd->cb->cs);
+						int height = cairo_image_surface_get_height(xd->cb->cs);
+						PROTECT(l);
+						{
+							SEXP info = allocVector(INTSXP, 3);
+							int *iv = INTEGER(info);
+							iv[0] = width;
+							iv[1] = height;
+							iv[2] = dformat;
+							SET_VECTOR_ELT(l, 1, info);
+						}
+						{
+							SEXP ref = R_MakeExternalPtr(data, R_NilValue, R_NilValue);
+							SET_VECTOR_ELT(l, 0, ref);
+						}
+						UNPROTECT(1);
+						return l;
+					}
+				}
+				error("unsupported backend");
+			}
+		}
+	}
+	error("invalid device number");
+	return R_NilValue;
+}
+
+SEXP ptr_to_raw(SEXP ptr, SEXP off, SEXP len) {
+	int o = asInteger(off);
+	int l = asInteger(len);
+	if (TYPEOF(ptr) != EXTPTRSXP)
+		error("ptr argument must be an external pointer");
+	{
+		unsigned char *data = (unsigned char*) EXTPTR_PTR(ptr);
+		if (data) {
+			SEXP v = allocVector(RAWSXP, l);
+			Rbyte *rc = RAW(v);
+			memcpy(rc, data+o, l);
+			return v;
+		}
+	}
+	return R_NilValue;
+}
+
+SEXP raw_to_ptr(SEXP ptr, SEXP woff, SEXP raw, SEXP roff, SEXP len) {
+	int o1 = asInteger(woff);
+	int o2 = asInteger(roff);
+	int l = asInteger(len);
+	if (TYPEOF(ptr) != EXTPTRSXP)
+		error("ptr argument must be an external pointer");
+	if (TYPEOF(raw) != RAWSXP)
+		error("raw argument must be a raw vector");
+	{
+		unsigned char *data = (unsigned char*) EXTPTR_PTR(ptr);
+		Rbyte *rc = RAW(raw);
+		memcpy(data+o1, rc+o2, l);
+		return ptr;
+	}
+	return R_NilValue;
+}
+
+SEXP Cairo_get_serial(SEXP dev) {
+	int devNr = asInteger(dev) - 1;
+	GEDevDesc *gd = GEgetDevice(devNr);
+	if (gd) {
+		NewDevDesc *dd = gd->dev;
+		if (dd) {
+			CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+#ifdef USE_MAGIC
+			if (xd->magic != CAIROGD_MAGIC)
+				error("Not a Cairo device");
+#endif
+			if(xd && xd->cb)
+				return ScalarInteger(xd->cb->serial & 0x7ffffff); /* return 31-bit so it is easier to handle in R */
+		}
+	}
+	Rf_error("Not a valid Cairo device");
+	return R_NilValue;
+}
+
+SEXP Cairo_set_onSave(SEXP dev, SEXP fn) {
+	int devNr = asInteger(dev) - 1;
+	GEDevDesc *gd = GEgetDevice(devNr);
+	if (gd) {
+		NewDevDesc *dd = gd->dev;
+		if (dd) {
+			CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+#ifdef USE_MAGIC
+			if (xd->magic != CAIROGD_MAGIC)
+				error("Not a Cairo device");
+#endif
+			if (xd && xd->cb) {
+				SEXP old = xd->cb->onSave;
+				if (!old) old = R_NilValue;
+				if (fn != R_NilValue) {
+					R_PreserveObject(fn);
+					xd->cb->onSave = fn;
+				} else xd->cb->onSave = 0;
+				if (old != R_NilValue)
+					R_ReleaseObject(old);
+				return old;
+			}
+		}
+	}
+	Rf_error("Not a valid Cairo device");	
+	return R_NilValue;
+}
diff --git a/src/cairogd.h b/src/cairogd.h
new file mode 100644
index 0000000..032ed7d
--- /dev/null
+++ b/src/cairogd.h
@@ -0,0 +1,84 @@
+#ifndef _DEV_GD_H
+#define _DEV_GD_H
+
+#define CAIROGD_VER 0x010509 /* Cairo v1.5-9 */
+
+/* cairo R package config */
+#include "cconfig.h"
+
+#include <cairo.h>
+#if CAIRO_HAS_FT_FONT
+#include <cairo-ft.h>
+#include FT_TRUETYPE_IDS_H
+#include <fontconfig/fontconfig.h>
+#endif
+
+/* work around bug #45376 in freetype 2.6.0 */
+#ifdef TYPEOF
+#undef TYPEOF
+#endif
+
+#include "backend.h"
+#include <R_ext/Print.h>
+#if R_GE_version < 4
+#include <Rgraphics.h>
+#include <Rdevices.h>
+#define BEGIN_SUSPEND_INTERRUPTS
+#define END_SUSPEND_INTERRUPTS
+#endif
+
+/* the internal representation of a color in this (R) API is RGBa with a=0 meaning transparent and a=255 meaning opaque (hence a means 'opacity'). previous implementation was different (inverse meaning and 0x80 as NA), so watch out. */
+#if R_VERSION < 0x20000
+#define CONVERT_COLOR(C) ((((C)==0x80000000) || ((C)==-1))?0:(((C)&0xFFFFFF)|((0xFF000000-((C)&0xFF000000)))))
+#else
+#define CONVERT_COLOR(C) (C)
+#endif
+
+#define CAIROGD_MAGIC (0x43614744)
+
+/* for compatibility with older R versions */
+#if R_GE_version < 4
+#define GEaddDevice(X) addDevice((DevDesc*)(X))
+#define GEdeviceNumber(X) devNumber((DevDesc*)(X))
+#define GEgetDevice(X) ((GEDevDesc*) GetDevice(X))
+#define ndevNumber(X) devNumber((DevDesc*)(X))
+#define GEkillDevice(X) KillDevice(X)
+#define desc2GEDesc(X) ((DevDesc*) GetDevice(devNumber((DevDesc*) (X))))
+#endif
+
+typedef struct {
+#ifdef USE_MAGIC
+    int magic; /* magic number such that we recognize Cairo */
+#endif
+    double cex;				/* Character expansion */
+    int lty;				/* Line type */
+    double lwd;
+    int col;				/* Color */
+    int fill;
+    int canvas;				/* Canvas */
+    int fontface;			/* Typeface */
+    int fontsize;			/* Size in points */
+    int basefontface;	    /* Typeface */
+    int basefontsize;		/* Size in points */
+
+    /* --- custom fields --- */
+    Rcairo_backend   *cb; /* cairo backend */
+
+    /* those are set before Open is invoked such that we can pass
+       any number of initial parameters without modifying the code */
+    int bg;  /* bg */
+    double gamma; /* gamma */
+    double dpix, dpiy, asp;
+    double fontscale; /* scaling of fonts due to DPI change */
+    
+    int gd_fill, gd_draw; /* current GD colors */
+    double gd_ftsize, gd_ftm_ascent, gd_ftm_descent, gd_ftm_width;
+    int gd_ftm_char; /*gd_ftm_xxx are font-metric cached values - char specifying the last query */
+    
+    int npages; /* sequence # in case multiple pages are requested */
+    
+    int holdlevel;
+} CairoGDDesc;
+
+#endif
+
diff --git a/src/cairotalk.c b/src/cairotalk.c
new file mode 100644
index 0000000..bc441a6
--- /dev/null
+++ b/src/cairotalk.c
@@ -0,0 +1,1168 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*- */
+#include "backend.h"
+#include "cairogd.h"
+#include "cairotalk.h"
+#include "cairobem.h"
+#include "img-backend.h"
+#include "pdf-backend.h"
+#include "svg-backend.h"
+#include "ps-backend.h"
+#include "xlib-backend.h"
+#include "w32-backend.h"
+#include "img-tiff.h" /* for TIFF_COMPR_LZW */
+#include <Rversion.h>
+#define USE_RINTERNALS 1
+#include <Rinternals.h>
+
+/* Device Driver Actions */
+
+#if R_VERSION < 0x10900
+#error This device needs at least R version 1.9.0
+#endif
+
+#define CREDC(C) (((unsigned int)(C))&0xff)
+#define CGREENC(C) ((((unsigned int)(C))&0xff00)>>8)
+#define CBLUEC(C) ((((unsigned int)(C))&0xff0000)>>16)
+#define CALPHA(C) ((((unsigned int)(C))&0xff000000)>>24)
+
+#if R_VERSION < R_Version(2,7,0)
+#define constxt
+#else
+#define constxt const
+#endif
+
+static void CairoGD_Activate(NewDevDesc *dd);
+static void CairoGD_Circle(double x, double y, double r,
+			  R_GE_gcontext *gc,
+			  NewDevDesc *dd);
+static void CairoGD_Clip(double x0, double x1, double y0, double y1,
+			NewDevDesc *dd);
+static void CairoGD_Close(NewDevDesc *dd);
+static void CairoGD_Deactivate(NewDevDesc *dd);
+static Rboolean CairoGD_Locator(double *x, double *y, NewDevDesc *dd);
+static void CairoGD_Line(double x1, double y1, double x2, double y2,
+			R_GE_gcontext *gc,
+			NewDevDesc *dd);
+static void CairoGD_MetricInfo(int c, 
+			      R_GE_gcontext *gc,
+			      double* ascent, double* descent,
+			      double* width, NewDevDesc *dd);
+static void CairoGD_Mode(int mode, NewDevDesc *dd);
+static void CairoGD_NewPage(R_GE_gcontext *gc, NewDevDesc *dd);
+static void CairoGD_Path(double *x, double *y, int npoly, int *nper, Rboolean winding,
+                       R_GE_gcontext *gc, NewDevDesc *dd);
+static void CairoGD_Polygon(int n, double *x, double *y,
+			   R_GE_gcontext *gc,
+			   NewDevDesc *dd);
+static void CairoGD_Polyline(int n, double *x, double *y,
+			     R_GE_gcontext *gc,
+			     NewDevDesc *dd);
+static void CairoGD_Rect(double x0, double y0, double x1, double y1,
+			 R_GE_gcontext *gc,
+			 NewDevDesc *dd);
+static void CairoGD_Size(double *left, double *right,
+			 double *bottom, double *top,
+			 NewDevDesc *dd);
+static double CairoGD_StrWidth(constxt char *str, 
+			       R_GE_gcontext *gc,
+			       NewDevDesc *dd);
+static void CairoGD_Text(double x, double y, constxt char *str,
+			 double rot, double hadj,
+			 R_GE_gcontext *gc,
+			 NewDevDesc *dd);
+static void CairoGD_Raster(unsigned int *raster, int w, int h,
+                       double x, double y, double width, double height,
+                       double rot, Rboolean interpolate,
+                       R_GE_gcontext *gc, NewDevDesc *dd);
+static SEXP CairoGD_Cap(NewDevDesc *dd);
+static int  CairoGD_HoldFlush(NewDevDesc *dd, int level);
+
+/* fake mbcs support for old R versions */
+#if R_GE_version < 4
+#define mbcslocale 0
+#define Rf_ucstoutf8(X,Y)
+#define AdobeSymbol2utf8(A,B,W) { A[0]=s[0]; A[1]=0; }
+#endif
+
+#ifdef JGD_DEBUG
+#define Rcairo_set_source_rgb(C,R,G,B) { Rprintf("S:RGB> %f %f %f\n", R, G, B); cairo_set_source_rgb(C,R,G,B); }
+#define Rcairo_set_source_rgba(C,R,G,B,A) { Rprintf("S:RGBA> %f %f %f (%f)\n", R, G, B, A); cairo_set_source_rgba(C,R,G,B,A); }
+#define Rcairo_set_color(cc, col) { if (CALPHA(col)==255) { Rcairo_set_source_rgb (cc, ((double)CREDC(col))/255., ((double)CGREENC(col))/255., ((double)CBLUEC(col))/255.); } else { Rcairo_set_source_rgba (cc, ((double)CREDC(col))/255., ((double)CGREENC(col))/255., ((double)CBLUEC(col))/255., ((double)CALPHA(col))/255.); }; }
+#else
+#define Rcairo_set_color(cc, col) { if (CALPHA(col)==255) { cairo_set_source_rgb (cc, ((double)CREDC(col))/255., ((double)CGREENC(col))/255., ((double)CBLUEC(col))/255.); } else { cairo_set_source_rgba (cc, ((double)CREDC(col))/255., ((double)CGREENC(col))/255., ((double)CBLUEC(col))/255., ((double)CALPHA(col))/255.); }; }
+#endif
+
+#ifdef CAIRO_HAS_FT_FONT
+FT_Library Rcairo_ft_library = NULL;
+
+typedef struct {
+	cairo_font_face_t *face;
+	int updated;
+} Rcairo_font_face;
+
+Rcairo_font_face Rcairo_fonts[5] = {
+	{ NULL, 0 },
+	{ NULL, 0 },
+	{ NULL, 0 },
+	{ NULL, 0 },
+	{ NULL, 0 }
+};
+
+static const cairo_user_data_key_t key;
+
+cairo_font_face_t *Rcairo_set_font_face(int i, const char *file){
+	cairo_font_face_t *c_face;
+	cairo_status_t status;
+	FT_Face face;
+	FT_Error er;
+	FT_CharMap found = 0; 
+	FT_CharMap charmap; 
+	int n; 
+
+	/* Ensure that freetype library is ready */
+	if (!Rcairo_ft_library){
+		if (FT_Init_FreeType(&Rcairo_ft_library)){
+			error("Failed to initialize freetype library in Rcairo_set_font_face!\n");
+			return FALSE;
+		}
+	}
+
+	er = FT_New_Face(Rcairo_ft_library, file, 0, &face);
+	if ( er == FT_Err_Unknown_File_Format ) { 
+		error("Unsupported font file format\n");
+		return NULL;
+	} else if ( er ) {
+		error("Unknown font problem\n");
+		return NULL;
+	}
+	for ( n = 0; n < face->num_charmaps; n++ ) { 
+		charmap = face->charmaps[n]; 
+		if ( charmap->platform_id == TT_PLATFORM_MACINTOSH) { 
+			found = charmap; 
+			break; 
+		} 
+	}
+
+	/* Only do this for symbol font */
+	if (found && i == 4){
+		er = FT_Set_Charmap( face, found );
+	} 
+
+	c_face = cairo_ft_font_face_create_for_ft_face(face,FT_LOAD_DEFAULT);
+	status = cairo_font_face_set_user_data (c_face, &key,
+		face, (cairo_destroy_func_t) FT_Done_Face);
+	if (status) {
+	    cairo_font_face_destroy (c_face);
+	    FT_Done_Face (face);
+	    return NULL;
+	}
+	return c_face;
+}
+
+void Rcairo_set_font(int i, const char *fcname){
+	FcFontSet	*fs;
+	FcPattern   *pat, *match;
+	FcResult	result;
+	FcChar8	*file;
+	int j;
+
+	if (Rcairo_fonts[i].face != NULL){
+		cairo_font_face_destroy(Rcairo_fonts[i].face);
+		Rcairo_fonts[i].face = NULL;
+	}
+
+	pat = FcNameParse((FcChar8 *)fcname);
+	if (!pat){
+		error("Problem with font config library in Rcairo_set_font\n");
+		return;
+	}
+	FcConfigSubstitute (0, pat, FcMatchPattern);
+	FcDefaultSubstitute (pat);
+
+	fs = FcFontSetCreate ();
+	match = FcFontMatch (0, pat, &result);
+	FcPatternDestroy (pat);
+	if (match) {
+		FcFontSetAdd (fs, match);
+	} else {
+		error("No font found in Rcairo_set_font");
+		FcFontSetDestroy (fs);
+		return;
+	}
+
+	/* should be at least one font face in fontset */
+	if (fs) {
+
+		for (j = 0; j < fs->nfont; j++) {
+
+			/* Need to make sure a real font file exists */
+			if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch){
+				Rcairo_fonts[i].face = Rcairo_set_font_face(i,(const char *)file);
+				break;
+			}
+		}
+		FcFontSetDestroy (fs);
+		Rcairo_fonts[i].updated = 1;
+	} else {
+		error("No font found Rcairo_set_font");
+	}
+
+}
+#endif
+
+static void set_cf_antialias(cairo_t *cc) {
+	cairo_font_options_t *fo = cairo_font_options_create();
+	cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL);
+	cairo_set_font_options(cc, fo);
+	cairo_font_options_destroy(fo);
+}
+
+static void Rcairo_setup_font(CairoGDDesc* xd, R_GE_gcontext *gc) {
+	cairo_t *cc = xd->cb->cc;
+
+#ifdef CAIRO_HAS_FT_FONT
+	int i = gc->fontface - 1;
+
+	if (i < 0 || i >= 5) i = 0;
+
+	if (Rcairo_fonts[i].updated || (xd->fontface != gc->fontface)){
+		cairo_set_font_face(cc,Rcairo_fonts[i].face);
+		set_cf_antialias(cc);
+		Rcairo_fonts[i].updated = 0;
+#ifdef JGD_DEBUG
+		  Rprintf("  font face changed to \"%d\" %fpt\n", gc->fontface, gc->cex*gc->ps + 0.5);
+#endif
+	} 
+
+	xd->fontface = gc->fontface;
+
+#else
+  char *Cfontface="Helvetica";
+  int slant = CAIRO_FONT_SLANT_NORMAL;
+  int wght  = CAIRO_FONT_WEIGHT_NORMAL;
+#ifdef WIN32
+  if (gc->fontface==5) Cfontface="Times";
+#else
+  if (gc->fontface==5) Cfontface="Symbol";
+#endif
+  if (gc->fontfamily[0]) Cfontface=gc->fontfamily;
+  if (gc->fontface==3 || gc->fontface==4) slant=CAIRO_FONT_SLANT_ITALIC;
+  if (gc->fontface==2 || gc->fontface==4) wght=CAIRO_FONT_WEIGHT_BOLD;
+  
+  cairo_select_font_face (cc, Cfontface, slant, wght);
+  set_cf_antialias(cc);
+#ifdef JGD_DEBUG
+  Rprintf("  font \"%s\" %fpt (slant:%d, weight:%d)\n", Cfontface, gc->cex*gc->ps + 0.5, slant, wght);
+#endif
+#endif
+
+  /* Add 0.5 per devX11.c in R src. We want to match it's png output as close
+   * as possible. */
+  cairo_set_font_size (cc, gc->cex * gc->ps * xd->fontscale + 0.5);
+}
+
+static void Rcairo_set_line(CairoGDDesc* xd, R_GE_gcontext *gc) {
+	cairo_t *cc = xd->cb->cc;
+	R_GE_lineend lend = CAIRO_LINE_CAP_SQUARE;
+	R_GE_linejoin ljoin = CAIRO_LINE_JOIN_ROUND;
+	
+	/* Line width: par lwd  */
+	cairo_set_line_width(cc, gc->lwd * xd->fontscale); /* use fontscale to match the DPI setting */
+
+	/* Line end: par lend  */
+	switch(gc->lend){
+		case GE_ROUND_CAP: lend = CAIRO_LINE_CAP_ROUND; break;
+		case GE_BUTT_CAP: lend = CAIRO_LINE_CAP_BUTT; break;
+		case GE_SQUARE_CAP: lend = CAIRO_LINE_CAP_SQUARE; break;
+	}
+	cairo_set_line_cap(cc,lend);
+
+	/* Line join: par ljoin */
+	switch(gc->ljoin){
+		case GE_ROUND_JOIN: ljoin = CAIRO_LINE_JOIN_ROUND; break;
+		case GE_MITRE_JOIN: ljoin = CAIRO_LINE_JOIN_MITER; break;
+		case GE_BEVEL_JOIN: ljoin = CAIRO_LINE_JOIN_BEVEL; break;
+	} 
+	cairo_set_line_join(cc,ljoin);
+
+	if (gc->lty==0 || gc->lty==-1)
+		cairo_set_dash(cc,0,0,0);
+	else {
+		double ls[16]; /* max 16x4=64 bit */
+		int l=0, dt=gc->lty;
+		while (dt>0) {
+			ls[l]=(double)(dt&15);
+			dt>>=4;
+			l++;
+		}
+		cairo_set_dash(cc, ls, l, 0);
+	}
+}
+
+/*------- the R callbacks begin here ... ------------------------*/
+
+#define c_trunc(X) ((double)((int)(X)))  /* some Suns don't have trunc(), so we use the cast-way to truncate */
+
+static void CairoGD_Activate(NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb) return;
+	if (xd->cb->activation) xd->cb->activation(xd->cb, 1);
+}
+
+static SEXP CairoGD_Cap(NewDevDesc *dd)
+{
+	SEXP raster = R_NilValue, dim;	
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	cairo_surface_t *s;
+	if(!xd || !xd->cb || !(s = xd->cb->cs)) return raster;
+
+	cairo_surface_flush(s);
+	/* we have defined way of getting the contents only from image back-ends */
+	if (cairo_surface_get_type(s) == CAIRO_SURFACE_TYPE_IMAGE) {
+		int w = cairo_image_surface_get_width(s);
+		int h = cairo_image_surface_get_height(s);
+		unsigned int *dst, size = w * h, i;
+		unsigned int *img = (unsigned int*) cairo_image_surface_get_data(s);
+		cairo_format_t fmt = cairo_image_surface_get_format(s);
+		
+		/* we only support RGB or ARGB */
+		if (fmt != CAIRO_FORMAT_RGB24 && fmt != CAIRO_FORMAT_ARGB32)
+			return raster;
+		
+		raster = PROTECT(allocVector(INTSXP, size));
+		dst = (unsigned int*) INTEGER(raster);
+
+#ifdef JGD_DEBUG
+		Rprintf("format = %s (%d x %d)\n", (fmt == CAIRO_FORMAT_ARGB32) ? "ARGB" : "RGB", w, h);
+#endif
+
+		if (fmt == CAIRO_FORMAT_ARGB32) /* ARGB is the default we use in most cases */
+			/* annoyingly Cairo uses pre-multiplied storage so we have to reverse that */
+			for (i = 0; i < size; i++) {
+				unsigned int v = *(img++), a = v >> 24;
+				dst[i] =
+					(a == 0) ? 0 : /* special cases for alpha = 0.0 and 1.0 */
+					((a == 255) ? R_RGB((v >> 16) & 255, (v >> 8) & 255, v & 255) : 
+					 R_RGBA(((v >> 16) & 255) * 255 / a, ((v >> 8) & 255) * 255 / a, (v & 255) * 255 / a, a));
+			}
+		else
+			for (i = 0; i < size; i++)
+				dst[i] = R_RGB((img[i] >> 16) & 255, (img[i] >> 8) & 255, img[i] & 255);
+		
+		dim = allocVector(INTSXP, 2);
+		INTEGER(dim)[0] = h;
+		INTEGER(dim)[1] = w;
+		setAttrib(raster, R_DimSymbol, dim);
+		
+		UNPROTECT(1);
+	}
+	return raster;
+}
+
+static void CairoGD_Circle(double x, double y, double r,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb) return;
+	{
+		cairo_t *cc = xd->cb->cc;
+
+#ifdef JGD_DEBUG
+		Rprintf("circle %x %f/%f %f [%08x/%08x]\n",cc, x, y, r, gc->col, gc->fill);
+#endif
+
+		cairo_new_path(cc);
+		cairo_arc(cc, x, y, r + 0.5 , 0., 2 * M_PI); /* Add 0.5 like devX11 */
+		if (CALPHA(gc->fill)) {
+			Rcairo_set_color(cc, gc->fill);
+			cairo_fill_preserve(cc);
+		}
+		if (CALPHA(gc->col) && gc->lty!=-1) {
+			Rcairo_set_color(cc, gc->col);
+			Rcairo_set_line(xd, gc);
+			cairo_stroke(cc);
+		} else cairo_new_path(cc);
+		xd->cb->serial++;
+	}
+}
+
+static void CairoGD_Clip(double x0, double x1, double y0, double y1,  NewDevDesc *dd)
+{
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	cairo_t *cc;
+    if(!xd || !xd->cb) return;
+
+	cc = xd->cb->cc;
+    if (x1<x0) { double h=x1; x1=x0; x0=h; };
+    if (y1<y0) { double h=y1; y1=y0; y0=h; };
+
+    cairo_reset_clip(cc);
+    cairo_new_path(cc);
+    cairo_rectangle(cc, x0, y0, x1-x0 + 1, y1-y0 + 1); /* Add 1 per newX11_Clip */
+    cairo_clip(cc);
+
+#ifdef JGD_DEBUG
+    Rprintf("clipping %f/%f %f/%f\n", x0, y0, x1, y1);
+#endif
+}
+
+static void CairoGD_Close(NewDevDesc *dd)
+{
+  CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+  if(!xd || !xd->cb) return;
+  
+  xd->npages++;
+  xd->cb->save_page(xd->cb,xd->npages);
+  if (xd->cb->onSave && xd->cb->onSave != R_NilValue) {
+	  SEXP devNr = PROTECT(ScalarInteger(ndevNumber(dd) + 1));
+	  SEXP pageNr = PROTECT(ScalarInteger(xd->npages));
+	  eval(lang3(xd->cb->onSave, devNr, pageNr), R_GlobalEnv);
+	  UNPROTECT(2);
+	  R_ReleaseObject(xd->cb->onSave);
+	  xd->cb->onSave = 0;
+  }
+  xd->cb->destroy_backend(xd->cb);
+
+  free(xd);
+  dd->deviceSpecific=NULL;
+}
+
+static void CairoGD_Deactivate(NewDevDesc *dd)
+{
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+    if(!xd || !xd->cb) return;
+	if (xd->cb->activation) xd->cb->activation(xd->cb, 0);
+}
+
+static int  CairoGD_HoldFlush(NewDevDesc *dd, int level)
+{
+	int ol;
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+    if (!xd) return 0;
+	ol = xd->holdlevel;
+    xd->holdlevel += level;
+    if (xd->holdlevel < 0)
+		xd->holdlevel = 0;
+    if (xd->holdlevel == 0) { /* flush */
+		if (xd->cb && xd->cb->sync) /* if a back-end provides sync, we just pass on */
+			xd->cb->sync(xd->cb);
+		else /* otherwise just do cairo-side flush */
+			if (xd->cb && xd->cb->cs) cairo_surface_flush(xd->cb->cs);
+	} else if (ol == 0) { /* first hold */
+        /* could display a wait cursor or something ... */
+    }
+    return xd->holdlevel;
+}
+
+static Rboolean CairoGD_Locator(double *x, double *y, NewDevDesc *dd)
+{
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+    if(!xd || !xd->cb) return FALSE;
+    if (xd->cb && xd->cb->locator) return xd->cb->locator(xd->cb, x, y);
+    return FALSE;
+}
+
+static void CairoGD_Line(double x1, double y1, double x2, double y2,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+    if(!xd || !xd->cb) return;
+    
+#ifdef JGD_DEBUG
+    Rprintf("line %f/%f %f/%f [%08x/%08x]\n", x1, y1, x2, y2, gc->col, gc->fill);
+#endif
+
+    if (CALPHA(gc->col) && gc->lty!=-1) {
+      cairo_t *cc = xd->cb->cc;
+      cairo_new_path(cc);
+	  if ((x1==x2 || y1==y2) &&xd->cb->truncate_rect) {
+		  /* if we are snapping rectangles to grid, we also need to snap straight
+			 lines to make sure they match - e.g. tickmarks, baselines etc. */
+		  x1=c_trunc(x1)+0.5; x2=c_trunc(x2)+0.5;
+		  y1=c_trunc(y1)+0.5; y2=c_trunc(y2)+0.5;
+	  }
+      cairo_move_to(cc, x1, y1);
+      cairo_line_to(cc, x2, y2);
+      Rcairo_set_color(cc, gc->col);
+      Rcairo_set_line(xd, gc);
+      cairo_stroke(cc);
+	  xd->cb->serial++;
+    }
+}
+
+static void CairoGD_MetricInfo(int c,  R_GE_gcontext *gc,  double* ascent, double* descent,  double* width, NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	cairo_t *cc;
+	cairo_text_extents_t te = {0, 0, 0, 0, 0, 0};
+	char str[16];
+	int Unicode = mbcslocale;
+
+	if(!xd || !xd->cb) return;
+	if(c < 0) {c = -c; Unicode = 1;}
+
+	cc = xd->cb->cc;
+
+	Rcairo_setup_font(xd, gc);
+
+	if (!c) { 
+		str[0]='M'; str[1]='g'; str[2]=0;
+		/* this should give us a reasonably decent (g) and almost max width (M) */
+	} else if (gc->fontface == 5) {
+		char s[2];
+		s[0] = c; s[1] = '\0';
+		AdobeSymbol2utf8(str, s, 16);		
+	} else if(Unicode) {
+		Rf_ucstoutf8(str, (unsigned int) c);
+	} else {
+		str[0] = c; str[1] = 0;
+		/* Here, we assume that c < 256 */
+	}
+
+	cairo_text_extents(cc, str, &te);
+
+#ifdef JGD_DEBUG
+	Rprintf("metric %x [%c]: bearing %f:%f, size %f:%f, advance %f:%f\n",c, (char)c, te.x_bearing, te.y_bearing,
+			te.width, te.height, te.x_advance, te.y_advance);
+#endif
+
+	*ascent  = -te.y_bearing; 
+	*descent = te.height+te.y_bearing;
+	/* cairo doesn't report width of whitespace, so use x_advance */
+	*width = te.x_advance;
+
+#ifdef JGD_DEBUG
+	Rprintf("FM> ascent=%f, descent=%f, width=%f\n", *ascent, *descent, *width);
+#endif
+}
+
+static void CairoGD_Mode(int mode, NewDevDesc *dd)
+{
+    CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+    if(!xd || !xd->cb) return;
+	if (xd->cb->mode) xd->cb->mode(xd->cb, mode);
+}
+
+static void CairoGD_NewPage(R_GE_gcontext *gc, NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	cairo_t *cc;
+	if(!xd || !xd->cb) return;
+
+	cc = xd->cb->cc;
+
+	xd->npages++;
+	if (xd->npages > 0) { /* first request is not saved as this is part of the init */
+		xd->cb->save_page(xd->cb,xd->npages);
+		if (xd->cb->onSave) {
+			SEXP devNr = PROTECT(ScalarInteger(ndevNumber(dd) + 1));
+			SEXP pageNr = PROTECT(ScalarInteger(xd->npages));
+			eval(lang3(xd->cb->onSave, devNr, pageNr), R_GlobalEnv);
+			UNPROTECT(2);
+		}
+	}
+
+	cairo_reset_clip(cc);
+	/* we don't need to fill if the back-end sets nozero and bg is transparent */
+	if (! (R_TRANSPARENT(xd->bg) && (xd->cb->flags & CDF_NOZERO)) ) {
+		/* we are assuming that the operator is reasonable enough
+		   to clear the page. Setting CAIRO_OPERATOR_SOURCE seemed
+		   to trigger rasterization for PDF and SVG backends, so we
+		   leave the operator alone. Make sure the back-end sets
+		   an operator that is optimal for the back-end */
+		Rcairo_set_color(cc, xd->bg);
+		if (xd->cb->flags & CDF_OPAQUE) {
+			/* Opaque devices use canvas if bg is transparent */
+			if (R_TRANSPARENT(xd->bg))
+				Rcairo_set_color(cc, xd->canvas);
+		} else {
+			if (xd->cb->flags & CDF_FAKE_BG) {
+				if (R_TRANSPARENT(xd->bg))
+					Rcairo_set_color(cc, fake_bg_color);
+			}
+		}
+		cairo_new_path(cc);
+		cairo_paint(cc);
+		xd->cb->serial++;
+	}
+}
+
+static SEXP findArg(const char *name, SEXP list) {
+	SEXP ns = install(name);
+	while (list && list!=R_NilValue) {
+		if (TAG(list)==ns) return CAR(list);
+		list=CDR(list);
+	}
+	return 0;
+}
+
+Rboolean CairoGD_Open(NewDevDesc *dd, CairoGDDesc *xd,  const char *type, int conn, const char *file, double w, double h,
+					  double umpl, SEXP aux)
+{
+	if (umpl==0) error("unit multiplier cannot be zero");
+
+	xd->fill   = 0xffffffff; /* transparent, was R_RGB(255, 255, 255); */
+	xd->col    = R_RGB(0, 0, 0);
+
+	xd->npages=-1;	
+	xd->cb = (Rcairo_backend*) calloc(1,sizeof(Rcairo_backend));
+	if (!xd->cb) return FALSE;
+
+	xd->cb->dd = dd;
+	xd->cb->dpix = xd->dpix;	
+	xd->cb->dpiy = xd->dpiy;	
+
+	/* Select Cairo backend */
+	/* Cairo 1.2-0: jpeg and tiff are created via external libraries (libjpeg/libtiff) by our code */
+	if (!strcmp(type,"png") || !strcmp(type,"png24")  || !strcmp(type,"jpeg") || !strcmp(type,"jpg") ||
+		!strcmp(type,"tif")  || !strcmp(type,"tiff") || !strcmp(type, "raster")) {
+		int alpha_plane = 0;
+		int quality = 0; /* find out if we have quality setting */
+		SEXP loc_cb = R_NilValue;
+#if R_GE_version >= 9
+		loc_cb = findArg("locator", aux);
+		if (loc_cb && TYPEOF(loc_cb) == CLOSXP) {
+			dd->haveLocator = 2; /* yes, custom supplied locator callback */
+		} else {
+			dd->haveLocator = 1; /* no locator on image back-ends */
+			loc_cb = R_NilValue;
+		}
+#endif
+		if (R_ALPHA(xd->bg) < 255) alpha_plane=1;
+		if (!strcmp(type,"jpeg") || !strcmp(type,"jpg")) {
+			SEXP arg = findArg("quality", aux);
+			if (arg && arg!=R_NilValue)
+				quality = asInteger(arg);
+			if (quality<0) quality=0;
+			if (quality>100) quality=100;
+			alpha_plane=0;
+#if R_GE_version >= 9
+			/* JPEG has no tbg */
+			dd->haveTransparentBg = 1;
+#endif
+		}
+		if (!strcmp(type,"tif")  || !strcmp(type,"tiff")) {
+			SEXP arg = findArg("compression", aux);
+			if (arg && arg!=R_NilValue)
+				quality = asInteger(arg);
+			else
+				quality = TIFF_COMPR_LZW; /* default */
+		}
+		if (umpl>=0) {
+			if (xd->dpix <= 0)
+				error("images cannot be created with other units than 'px' if dpi is not specified");
+			if (xd->dpiy <= 0) xd->dpiy=xd->dpix;
+			w = w*umpl*xd->dpix;
+			h = h*umpl*xd->dpiy;
+		} else {
+			if (umpl != -1) {
+				w = (-umpl)*w;
+				h = (-umpl)*h;
+			}
+		}
+		xd->cb->width = w; xd->cb->height = h;
+		xd->cb = Rcairo_new_image_backend(xd->cb, conn, file, type, (int)(w+0.5), (int)(h+0.5), quality, alpha_plane, loc_cb);
+	}
+	else if (!strcmp(type,"pdf") || !strcmp(type,"ps") || !strcmp(type,"postscript") || !strcmp(type,"svg")) {
+#if R_GE_version >= 9
+		/* no locator, no capture */
+		dd->haveLocator = 1;
+		dd->haveCapture = 1;
+#endif
+		/* devices using native units, covert those to points */
+		if (umpl<0) {
+			if (xd->dpix <= 0)
+				error("dpi must be specified when creating vector devices with units='px'");
+			if (xd->dpiy <= 0) xd->dpiy=xd->dpix;
+			w = w/xd->dpix;
+			h = h/xd->dpiy;
+			umpl=1;
+		}
+		w = w * umpl * 72; /* inches * 72 = pt */
+		h = h * umpl * 72;
+		xd->cb->width = w; xd->cb->height = h;
+		xd->cb->flags|=CDF_NOZERO;
+		if (!strcmp(type,"pdf"))
+			xd->cb = Rcairo_new_pdf_backend(xd->cb, conn, file, w, h);
+		else if (!strcmp(type,"ps") || !strcmp(type,"postscript"))
+			xd->cb = Rcairo_new_ps_backend(xd->cb, conn, file, w, h);
+		else if (!strcmp(type,"svg"))
+			xd->cb = Rcairo_new_svg_backend(xd->cb, conn, file, w, h);
+	} else {
+		/* following devices are pixel-based yet supporting umpl */
+		if (umpl>0 && xd->dpix>0) { /* convert if we can */
+			if (xd->dpiy <= 0) xd->dpiy=xd->dpix;
+			w = w * umpl * xd->dpix;
+			h = h * umpl * xd->dpiy;
+			umpl = -1;
+		} /* otherwise device's dpi will be used */
+		xd->cb->width = w; xd->cb->height = h;
+		/* also following devices are opaque UI-devices */
+		xd->cb->flags |= CDF_HAS_UI|CDF_OPAQUE;
+		if (!strcmp(type,"x11") || !strcmp(type,"X11") || !strcmp(type,"xlib"))
+			xd->cb = Rcairo_new_xlib_backend(xd->cb, file, w, h, umpl);
+		else if (!strncmp(type,"win",3))
+			xd->cb = Rcairo_new_w32_backend(xd->cb, file, w, h, umpl);
+		else {
+			error("Unsupported output type \"%s\" - choose from png, png24, jpeg, tiff, pdf, ps, svg, win and x11.", type);
+			return FALSE;
+		}
+	}
+	if (!xd->cb) {
+		error("Failed to create Cairo backend!");
+		return FALSE;
+	}
+
+	/* get modified dpi in case the backend has set it */
+	xd->dpix = xd->cb->dpix;
+	xd->dpiy = xd->cb->dpiy;
+	if (xd->dpix>0 && xd->dpiy>0) xd->asp = xd->dpix / xd->dpiy;
+
+	Rcairo_backend_init_surface(xd->cb);
+	/*
+	  cc = xd->cb->cc;
+	  cairo_save(cc);
+	*/
+
+#ifdef JGD_DEBUG
+	Rprintf("open [type='%s'] %d x %d (flags %04x)\n", type, (int)w, (int)h, xd->cb->flags);
+#endif
+
+	return TRUE;
+}
+
+static void CairoGD_Path(double *x, double *y, int npoly, int *nper, Rboolean winding,
+                       R_GE_gcontext *gc, NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb || !nper || npoly < 1) return;
+	{
+		int i, j, n;
+		cairo_t *cc = xd->cb->cc;
+		
+		Rcairo_set_line(xd, gc);
+
+#ifdef JGD_DEBUG
+		Rprintf("path %d polygons [%08x/%08x]\n", npoly, gc->col, gc->fill);
+#endif
+		
+		cairo_new_path(cc);
+		n = 0;
+		for (i = 0; i < npoly; i++) {
+			cairo_move_to(cc, x[n], y[n]);
+			n++;
+			for(j = 1; j < nper[i]; j++) {
+				cairo_line_to(cc, x[n], y[n]);
+				n++;
+			}
+			cairo_close_path(cc);
+		}
+
+		if (CALPHA(gc->fill)) {
+			if (winding) 
+				cairo_set_fill_rule(cc, CAIRO_FILL_RULE_WINDING);
+			else 
+				cairo_set_fill_rule(cc, CAIRO_FILL_RULE_EVEN_ODD);
+			Rcairo_set_color(cc, gc->fill);
+			cairo_fill_preserve(cc);
+		}
+		if (CALPHA(gc->col) && gc->lty != -1) {
+			Rcairo_set_color(cc, gc->col);
+			cairo_stroke(cc);
+		} else cairo_new_path(cc);
+		xd->cb->serial++;
+    }
+}
+
+static void CairoGD_Polygon(int n, double *x, double *y,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb || n<2) return;
+	{
+		int i=1;
+		cairo_t *cc = xd->cb->cc;
+
+		Rcairo_set_line(xd, gc);
+
+#ifdef JGD_DEBUG
+		Rprintf("polygon %d points [%08x/%08x]\n", n, gc->col, gc->fill);
+#endif
+		cairo_new_path(cc);
+		cairo_move_to(cc, x[0], y[0]);
+		while (i<n) { cairo_line_to(cc, x[i], y[i]); i++; }
+		cairo_close_path(cc);
+		if (CALPHA(gc->fill)) {
+			Rcairo_set_color(cc, gc->fill);
+			cairo_fill_preserve(cc);
+		}
+		if (CALPHA(gc->col) && gc->lty!=-1) {
+			Rcairo_set_color(cc, gc->col);
+			cairo_stroke(cc);
+		} else cairo_new_path(cc);
+		xd->cb->serial++;
+	}
+}
+
+static void CairoGD_Polyline(int n, double *x, double *y,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb || n<2) return;
+	{
+		int i=1;
+		cairo_t *cc = xd->cb->cc;
+
+#ifdef JGD_DEBUG
+		Rprintf("poly-line %d points [%08x]\n", n, gc->col);
+#endif
+		if (CALPHA(gc->col) && gc->lty!=-1) {
+			cairo_new_path(cc);
+			cairo_move_to(cc, x[0], y[0]);
+			while (i<n) { cairo_line_to(cc, x[i], y[i]); i++; }
+			Rcairo_set_color(cc, gc->col);
+			Rcairo_set_line(xd, gc);
+			cairo_stroke(cc);
+			xd->cb->serial++;
+		}
+	}
+}
+
+static void CairoGD_Rect(double x0, double y0, double x1, double y1,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb) return;
+	{
+		cairo_t *cc = xd->cb->cc;
+		double snap_add = 0.0;
+		if (x1<x0) { double h=x1; x1=x0; x0=h; }
+		if (y1<y0) { double h=y1; y1=y0; y0=h; }
+		/* if (x0<0) x0=0; if (y0<0) y0=0; */
+
+		Rcairo_set_line(xd, gc);
+
+#ifdef JGD_DEBUG
+		Rprintf("rect: %x %f/%f %f/%f [%08x/%08x]\n", cc, x0, y0, x1, y1, gc->col, gc->fill);
+#endif
+
+		/* Snap to grid so that image() plots and rectangles look nicer, but only if the backend wishes so */
+		if (xd->cb->truncate_rect) {
+			cairo_user_to_device(cc,&x0,&y0);
+			cairo_user_to_device(cc,&x1,&y1);
+			x0 = trunc(x0); x1 = trunc(x1);
+			y0 = trunc(y0); y1 = trunc(y1);
+			cairo_device_to_user(cc,&x0,&y0);
+			cairo_device_to_user(cc,&x1,&y1);
+			snap_add=1;
+		}
+
+		cairo_new_path(cc);
+		cairo_rectangle(cc, x0, y0, x1-x0+snap_add, y1-y0+snap_add);
+		if (CALPHA(gc->fill)) {
+			Rcairo_set_color(cc, gc->fill);
+			cairo_fill_preserve(cc);
+		}
+		if (CALPHA(gc->col) && gc->lty!=-1) {
+			/* if we are snapping, note that lines must be in 0.5 offset to fills in order
+			   hit the same pixels, because lines extend to both sides */
+			if (xd->cb->truncate_rect) {
+				cairo_new_path(cc);
+				cairo_rectangle(cc, x0+0.5, y0+0.5, x1-x0, y1-y0);
+			}
+			Rcairo_set_color(cc, gc->col);
+			cairo_stroke(cc);
+		} else cairo_new_path(cc);
+		xd->cb->serial++;
+	}
+}
+
+static void CairoGD_Raster(unsigned int *raster, int w, int h,
+                       double x, double y, double width, double height,
+                       double rot, Rboolean interpolate,
+                       R_GE_gcontext *gc, NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb) return;
+	{   /* the code in this block has been adapted from R 2.12.1, src/modules/X11/cairoX11.c
+		   (c) 2010 R Development Core Team under GPL 2+ */
+		cairo_t *cc = xd->cb->cc;
+		cairo_surface_t *image;
+		unsigned char *imageData;
+		int i;
+
+		cairo_save(cc);
+		cairo_translate(cc, x, y);
+		if (rot != 0.0)
+			cairo_rotate(cc, -rot * M_PI/180);
+		if (w != width || h != height)
+			cairo_scale(cc, width / w, height / h);
+		
+		/* Flip vertical first */
+		cairo_translate(cc, 0, h / 2.0);
+		cairo_scale(cc, 1, -1);
+		cairo_translate(cc, 0, -h / 2.0);
+
+
+		/* allocate data and transform to pre-mpl alpha */
+		imageData = (unsigned char *) malloc(4*w*h);
+		for (i = 0; i < w * h; i++) {
+			int alpha = R_ALPHA(raster[i]);
+			imageData[i*4 + 3] = alpha;
+			if (alpha < 255) {
+				imageData[i*4 + 2] = R_RED(raster[i]) * alpha / 255;
+				imageData[i*4 + 1] = R_GREEN(raster[i]) * alpha / 255;
+				imageData[i*4 + 0] = R_BLUE(raster[i]) * alpha / 255;
+			} else {
+				imageData[i*4 + 2] = R_RED(raster[i]);
+				imageData[i*4 + 1] = R_GREEN(raster[i]);
+				imageData[i*4 + 0] = R_BLUE(raster[i]);
+			}
+		}
+		
+		image = cairo_image_surface_create_for_data(imageData, 
+													CAIRO_FORMAT_ARGB32,
+													w, h, 4 * w);
+		
+		cairo_set_source_surface(cc, image, 0, 0);
+		if (interpolate) {
+            cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_BILINEAR);
+            cairo_pattern_set_extend(cairo_get_source(cc), CAIRO_EXTEND_PAD);
+		} else
+			cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_NEAREST);
+
+		cairo_new_path(cc);
+		cairo_rectangle(cc, 0, 0, w, h);
+		cairo_clip(cc);
+		cairo_paint(cc); 
+		
+		cairo_restore(cc);
+		cairo_surface_destroy(image);
+		free(imageData);
+		xd->cb->serial++;
+	}
+}
+
+static void CairoGD_Size(double *left, double *right,  double *bottom, double *top,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	if(!xd || !xd->cb) return;	
+	*left=*top=0.0;
+	*right=xd->cb->width;
+	*bottom=xd->cb->height;
+}
+
+static double CairoGD_StrWidth(constxt char *str,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	int slen = strlen(str);
+	if (!str) return 0;
+	if(!xd || !xd->cb) return slen*8;
+
+	Rcairo_setup_font(xd, gc);
+
+	{
+		cairo_t *cc = xd->cb->cc;
+		cairo_text_extents_t te;
+		cairo_text_extents(cc, str, &te);
+		/* Cairo doesn't take into account whitespace char widths, 
+		 * but the x_advance does */
+		return te.x_advance;
+	}
+}
+
+static void CairoGD_Text(double x, double y, constxt char *str,  double rot, double hadj,  R_GE_gcontext *gc,  NewDevDesc *dd)
+{
+	CairoGDDesc *xd = (CairoGDDesc *) dd->deviceSpecific;
+	cairo_t *cc;
+
+	if(!xd || !xd->cb) return;
+
+	cc = xd->cb->cc;
+		
+	Rcairo_setup_font(xd,gc);
+
+#ifdef JGD_DEBUG
+	Rprintf("text \"%s\" (%d) face %d  %f:%f rot=%f hadj=%f [%08x:%08x]\n", str, len, gc->fontface, x, y, rot, hadj, gc->col, gc->fill);
+#endif
+
+	cairo_save(cc);
+	cairo_move_to(cc, x, y);
+	if (hadj!=0. || rot!=0.) {
+		cairo_text_extents_t te;
+		cairo_text_extents(cc, str, &te);
+		if (rot!=0.)
+			cairo_rotate(cc, -rot/180.*M_PI);
+		if (hadj!=0.)
+			cairo_rel_move_to(cc, -te.x_advance*hadj, 0);
+
+		/* Rcairo_set_color(cc, 0xff80ff); */
+	}
+	Rcairo_set_color(cc, gc->col);
+	cairo_show_text(cc, str);
+	xd->cb->serial++;
+
+#ifdef JGD_DEBUG
+	{
+		cairo_text_extents_t te;
+		cairo_text_extents(cc, str, &te);
+
+		if (hadj!=0.) x = x - (te.x_advance*hadj);
+
+		/* debug - mark the origin of the text */
+		Rcairo_set_color(cc, 0x8080ff);
+		cairo_new_path(cc); cairo_move_to(cc,x-3.,y); cairo_line_to(cc,x+3.,y); cairo_stroke(cc);
+		cairo_new_path(cc); cairo_move_to(cc,x,y-3.); cairo_line_to(cc,x,y+3.); cairo_stroke(cc);
+
+		x = x + te.x_advance;
+		cairo_new_path(cc); cairo_move_to(cc,x-3.,y); cairo_line_to(cc,x+3.,y); cairo_stroke(cc);
+		cairo_new_path(cc); cairo_move_to(cc,x,y-3.); cairo_line_to(cc,x,y+3.); cairo_stroke(cc);
+
+	}
+#endif
+
+	cairo_restore(cc);
+}
+
+/** fill the R device structure with callback functions */
+void Rcairo_setup_gd_functions(NewDevDesc *dd) {
+    dd->close = CairoGD_Close;
+    dd->activate = CairoGD_Activate;
+    dd->deactivate = CairoGD_Deactivate;
+    dd->size = CairoGD_Size;
+    dd->newPage = CairoGD_NewPage;
+    dd->clip = CairoGD_Clip;
+    dd->strWidth = CairoGD_StrWidth;
+    dd->text = CairoGD_Text;
+    dd->rect = CairoGD_Rect;
+    dd->circle = CairoGD_Circle;
+    dd->line = CairoGD_Line;
+    dd->polyline = CairoGD_Polyline;
+    dd->polygon = CairoGD_Polygon;
+    dd->locator = CairoGD_Locator;
+    dd->mode = CairoGD_Mode;
+    dd->metricInfo = CairoGD_MetricInfo;
+#if R_GE_version >= 4
+	dd->hasTextUTF8 = TRUE;
+    dd->strWidthUTF8 = CairoGD_StrWidth;
+    dd->textUTF8 = CairoGD_Text;
+	dd->wantSymbolUTF8 = TRUE;
+#if R_GE_version >= 6
+	dd->raster = CairoGD_Raster;
+	dd->cap = CairoGD_Cap;
+#if R_GE_version >= 8
+	dd->path = CairoGD_Path;
+#if R_GE_version >= 9
+	dd->holdflush = CairoGD_HoldFlush;
+#endif
+#endif
+#endif
+#endif
+}
+
+void Rcairo_backend_resize(Rcairo_backend *be, double width, double height) {
+	if (!be || !be->dd) return;
+	if (be->resize) {
+		CairoGDDesc *xd = (CairoGDDesc *) be->dd->deviceSpecific;
+		if(!xd) return;
+		/* Rprintf("cairotalk.resize(%d,%d) %d:%d %dx%d\n", width, height, be->dd->top, be->dd->left, be->dd->right, be->dd->bottom); */
+		
+		be->width=width;
+		be->height=height;
+		be->dd->size(&(be->dd->left), &(be->dd->right), &(be->dd->bottom), &(be->dd->top), be->dd);
+		be->resize(be, width, height);
+	}
+}
+
+void Rcairo_backend_repaint(Rcairo_backend *be) {
+	if (!be || !be->dd) return;
+	{
+		int devNum = ndevNumber(be->dd);
+		if (devNum > 0) {
+			be->in_replay = 1;
+			GEplayDisplayList(GEgetDevice(devNum));
+			be->in_replay = 0;
+			if (be->mode) be->mode(be, -1);
+		}
+	}
+}
+
+void Rcairo_backend_kill(Rcairo_backend *be) {
+	if (!be || !be->dd) return;
+	GEkillDevice(desc2GEDesc(be->dd));
+}
+
+static int has_initd_fc = 0;
+
+void Rcairo_backend_init_surface(Rcairo_backend *be) {
+	cairo_t *cc = be->cc;
+	/* clearing of the surface is done directly in NewPage */
+	/* CairoGDDesc *cd = (CairoGDDesc *) be->dd->deviceSpecific; */
+
+	cairo_reset_clip(cc);
+
+#ifdef CAIRO_HAS_FT_FONT
+	/* Ensure that fontconfig library is ready */
+	if (!has_initd_fc && !FcInit ())
+		error ("Can't init font config library\n");
+	has_initd_fc = 1;
+
+	/* Ensure that freetype library is ready */
+	if (!Rcairo_ft_library &&
+		FT_Init_FreeType(&Rcairo_ft_library))
+		error("Failed to initialize freetype library in CairoGD_Open!\n");
+
+	if (Rcairo_fonts[0].face == NULL) Rcairo_set_font(0,"Helvetica:style=Regular");
+	if (Rcairo_fonts[1].face == NULL) Rcairo_set_font(1,"Helvetica:style=Bold");
+	if (Rcairo_fonts[2].face == NULL) Rcairo_set_font(2,"Helvetica:style=Italic");
+	if (Rcairo_fonts[3].face == NULL) Rcairo_set_font(3,"Helvetica:style=Bold Italic,BoldItalic");
+	if (Rcairo_fonts[4].face == NULL) Rcairo_set_font(4,"Symbol");
+#else
+	cairo_select_font_face (cc, "Helvetica",
+			CAIRO_FONT_SLANT_NORMAL,
+			CAIRO_FONT_WEIGHT_NORMAL);
+	set_cf_antialias(cc);
+	cairo_set_font_size (cc, 14);
+#endif
+}
+
+/* add any new back-ends to this list */
+void Rcairo_register_builtin_backends() {
+	if (RcairoBackendDef_image) Rcairo_register_backend(RcairoBackendDef_image);
+	if (RcairoBackendDef_pdf) Rcairo_register_backend(RcairoBackendDef_pdf);
+	if (RcairoBackendDef_ps) Rcairo_register_backend(RcairoBackendDef_ps);
+	if (RcairoBackendDef_svg) Rcairo_register_backend(RcairoBackendDef_svg);
+	if (RcairoBackendDef_xlib) Rcairo_register_backend(RcairoBackendDef_xlib);
+	if (RcairoBackendDef_w32) Rcairo_register_backend(RcairoBackendDef_w32);
+}
+
+/* called on load */
+SEXP Rcairo_initialize() {
+	Rcairo_register_builtin_backends();
+	return R_NilValue;
+}
+
+/* this is a shortcut for dev.capture(native=TRUE) that also works in onSave
+   (R disables the device before calling Close so you can't use dev.capture) */
+SEXP Rcairo_capture(SEXP dev) {
+	int devNr = asInteger(dev) - 1;
+	GEDevDesc *gd = GEgetDevice(devNr);
+	if (gd) {
+		NewDevDesc *dd = gd->dev;
+		if (dd) {
+			SEXP res = CairoGD_Cap(dd);
+			if (res != R_NilValue) {
+				PROTECT(res);
+				setAttrib(res, R_ClassSymbol, mkString("nativeRaster"));
+				UNPROTECT(1);
+				return res;
+			}
+		}
+	}
+	Rf_error("Unable to capture content - not a valid image backend Cairo device");
+	return R_NilValue;
+}
+
+SEXP Rcairo_snapshot(SEXP dev, SEXP sLast) {
+    int last = asInteger(sLast);
+    int devNr = asInteger(dev) - 1;
+    GEDevDesc *gd = GEgetDevice(devNr);
+    if (!gd) Rf_error("invalid device");
+    return last ? gd->savedSnapshot : GEcreateSnapshot(gd);
+}
diff --git a/src/cairotalk.h b/src/cairotalk.h
new file mode 100644
index 0000000..08ad6a0
--- /dev/null
+++ b/src/cairotalk.h
@@ -0,0 +1,18 @@
+#ifndef __JGD_TALK_H__
+#define __JGD_TALK_H__
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "cairo.h"
+
+void Rcairo_setup_gd_functions(NewDevDesc *dd);
+Rboolean CairoGD_Open(NewDevDesc *dd, CairoGDDesc *xd, const char *type, int conn, const char *file,
+		      double w, double h, double umpl, SEXP aux);
+
+#ifdef CAIRO_HAS_FT_FONT
+void Rcairo_set_font(int i, const char *fcname);
+#endif
+
+#endif
diff --git a/src/cconfig.h.in b/src/cconfig.h.in
new file mode 100644
index 0000000..851e147
--- /dev/null
+++ b/src/cconfig.h.in
@@ -0,0 +1,68 @@
+/* src/cconfig.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the declaration of
+   `cairo_image_surface_get_format', and to 0 if you don't. */
+#undef HAVE_DECL_CAIRO_IMAGE_SURFACE_GET_FORMAT
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#undef HAVE_SYS_WAIT_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if libjpeg is present and working */
+#undef SUPPORTS_JPEG
+
+/* Define to 1 if libtiff is present and working */
+#undef SUPPORTS_TIFF
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
diff --git a/src/img-backend.c b/src/img-backend.c
new file mode 100644
index 0000000..d774305
--- /dev/null
+++ b/src/img-backend.c
@@ -0,0 +1,259 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+   Copyright (C) 2004-2007   Simon Urbanek
+   Copyright (C) 2006        Jeffrey Horner
+   License: GPL v2 */
+
+#ifdef HAVE_RCONN_H
+#include <R.h>
+#include <Rinternals.h>
+#include <Rdefines.h>
+#define R_INTERFACE_PTRS
+#include <Rinterface.h>
+#include <Rembedded.h>
+#include <R_ext/Print.h>
+#include <R_ext/RConn.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <cairo.h>
+#include "img-backend.h"
+#include "img-jpeg.h"
+#include "img-tiff.h"
+
+#define default_jpeg_quality 75
+
+static char* img_types[] = {
+	"png",
+#ifdef SUPPORTS_JPEG
+	"jpeg",
+#endif
+#ifdef SUPPORTS_TIFF
+	"tiff",
+#endif
+	"raster",
+	0 };
+
+static Rcairo_backend_def RcairoBackendDef_image_ = {
+	BET_IMAGE,
+	img_types,
+	"image",
+	CBDF_FILE|CBDF_CONN,
+	0
+};
+
+Rcairo_backend_def *RcairoBackendDef_image = &RcairoBackendDef_image_;
+
+static int cairo_op = -1;
+SEXP Rcso(SEXP v) {
+	cairo_op = asInteger(v);
+	return v;
+}
+
+static void image_backend_destroy(Rcairo_backend* be)
+{
+	if (be->backendSpecific){
+		Rcairo_image_backend *image = (Rcairo_image_backend *)be->backendSpecific;
+		if (image->buf) free(image->buf);
+		if (image->filename) free(image->filename);
+		if (image->locator_call && image->locator_call != R_NilValue)
+			R_ReleaseObject(image->locator_call);
+		free(be->backendSpecific);
+	}
+
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);
+	free(be);
+}
+
+/* utility function: create a filename based on the original specification and the pageno
+   result must be freed by the caller */
+static char *image_filename(Rcairo_backend* be, int pageno) {
+	Rcairo_image_backend *image = (Rcairo_image_backend *)be->backendSpecific;
+	char *fn;
+	int l = strlen(image->filename)+16;
+
+	fn=(char*) malloc(l);
+	fn[l-1] = 0;
+	snprintf(fn, l-1, image->filename, pageno);
+	return fn;
+}
+
+static void image_save_page_jpg(Rcairo_backend* be, int pageno){
+	Rcairo_image_backend *image = (Rcairo_image_backend *)be->backendSpecific;
+	char *fn = image_filename(be, pageno);
+	int width = cairo_image_surface_get_width(be->cs);
+	int height = cairo_image_surface_get_height(be->cs);
+	/* although we don't use alpha, cairo still aligns on 4 so we have to set channels=4 */
+	int res = save_jpeg_file(image->buf, width, height, fn, image->quality?image->quality:default_jpeg_quality, 4);
+	free(fn);
+	if (res == -2)
+		error("Sorry, this Cairo was compiled without jpeg support.");
+	if (res)
+		error("Unable to write jpeg file.");
+}
+
+static void image_save_page_tiff(Rcairo_backend* be, int pageno){
+	Rcairo_image_backend *image = (Rcairo_image_backend *)be->backendSpecific;
+	char *fn = image_filename(be, pageno);
+	int width = cairo_image_surface_get_width(be->cs);
+	int height = cairo_image_surface_get_height(be->cs);
+	cairo_format_t cf = image->format;
+	int res = save_tiff_file(image->buf, width, height, fn, (cf==CAIRO_FORMAT_RGB24)?3:4, image->quality);
+	free(fn);
+	if (res == -2)
+		error("Sorry, this Cairo was compiled without tiff support.");
+	if (res)
+		error("Unable to write tiff file.");
+}
+
+static void image_save_page_png(Rcairo_backend* be, int pageno){
+	/* Rcairo_image_backend *image = (Rcairo_image_backend *)be->backendSpecific; */
+	char *fn;
+
+	fn=image_filename(be, pageno);
+	cairo_surface_write_to_png(be->cs, fn);
+	free(fn);
+}
+
+static void image_save_page_null(Rcairo_backend* be, int pageno) {
+}
+
+#ifdef HAVE_RCONN_H
+static cairo_status_t send_image_data(void *closure, const unsigned char *data, unsigned int length)
+{
+	Rcairo_backend *be = (Rcairo_backend *)closure;
+	Rcairo_image_backend *image;
+	image = (Rcairo_image_backend *)be->backendSpecific;
+
+	if (R_WriteConnection(image->conn, data, length, 1))
+		return CAIRO_STATUS_SUCCESS;
+	else
+		return CAIRO_STATUS_WRITE_ERROR;
+}
+static void image_send_page(Rcairo_backend* be, int pageno){
+			cairo_surface_write_to_png_stream (be->cs, send_image_data , (void *)be);
+}
+#endif
+
+int  image_locator(struct st_Rcairo_backend *be, double *x, double *y) {
+	Rcairo_image_backend *image;
+	image = (Rcairo_image_backend *)be->backendSpecific;
+	if (image->locator_call && image->locator_call != R_NilValue) {
+		SEXP res;
+		INTEGER(image->locator_dev)[0] = ndevNumber(be->dd) + 1;
+		res = eval(image->locator_call, R_GlobalEnv);
+		if (TYPEOF(res) == INTSXP && LENGTH(res) == 2) {
+			*x = INTEGER(res)[0];
+			*y = INTEGER(res)[1];
+			return 1;
+		}
+		if (TYPEOF(res) == REALSXP && LENGTH(res) == 2) {
+			*x = REAL(res)[0];
+			*y = REAL(res)[1];
+			return 1;
+		}
+	}
+	return 0;
+}
+
+
+Rcairo_backend *Rcairo_new_image_backend(Rcairo_backend *be, int conn, const char *filename, const char *type,
+										 int width, int height, int quality, int alpha_plane, SEXP locator_cb)
+{
+	Rcairo_image_backend *image;
+	int stride = 4 * width;
+
+	if ( ! (image = (Rcairo_image_backend *)calloc(1,sizeof(Rcairo_image_backend)))){
+		free(be); return NULL;
+	}
+
+	/* filename will be irrelevan for raster output */
+	if (type && !strcmp(type, "raster")) filename = 0;
+
+	if (filename){
+		if ( !(image->filename = malloc(strlen(filename)+1))){
+			free(be); free(image); return NULL;
+		}
+
+		strcpy(image->filename,filename);
+	} else {
+#ifdef HAVE_RCONN_H
+		image->conn = conn;
+		be->save_page = image_send_page;
+#else
+		be->save_page = image_save_page_null;
+#endif
+	}
+
+	be->backend_type = BET_IMAGE;
+	be->destroy_backend = image_backend_destroy;
+	be->locator = image_locator;
+	be->backendSpecific = (void *)image;
+	be->truncate_rect = 1;
+	be->width = width;
+	be->height = height;
+
+	if (!strcmp(type,"jpg")) alpha_plane=0; /* forge jpeg to never have alpha */
+	if ( ! (image->buf = calloc (stride * height, 1))){
+		free(be); free(image->filename); free(image);
+		return NULL;
+	}
+	image->format = alpha_plane ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
+	be->cs = cairo_image_surface_create_for_data (image->buf, image->format,
+												  width, height, stride);
+
+	if (cairo_surface_status(be->cs) != CAIRO_STATUS_SUCCESS){
+		if (image->buf) free(image->buf); free(be); free(image->filename); free(image);
+		return NULL;
+	}
+
+	if (locator_cb != R_NilValue)
+		R_PreserveObject((image->locator_call =
+						  lang2(locator_cb,
+								(image->locator_dev = allocVector(INTSXP, 1))
+								)));
+	else
+		image->locator_call = R_NilValue;
+
+	if (!strcmp(type,"png") ||!strcmp(type,"png24") ||!strcmp(type,"png32")) {
+		if (!alpha_plane)
+			be->flags|=CDF_FAKE_BG;
+		if (!be->save_page) be->save_page = image_save_page_png;
+	} else if (!strcmp(type,"jpg") || !strcmp(type,"jpeg")) {
+#ifdef SUPPORTS_JPEG
+		image->quality = quality;
+		if (!be->save_page) be->save_page = image_save_page_jpg;
+		be->flags|=CDF_OPAQUE; /* no transparency at all */
+#else
+		cairo_surface_destroy(be->cs);
+		free(image->buf);
+		error("Sorry, this Cairo was compiled without jpeg support.");
+#endif
+	} else if (!strcmp(type,"tif") || !strcmp(type,"tiff")) {
+#ifdef SUPPORTS_TIFF
+		image->quality = quality;
+		if (!alpha_plane)
+			be->flags|=CDF_OPAQUE;
+		if (!be->save_page) be->save_page = image_save_page_tiff;
+#else
+		cairo_surface_destroy(be->cs);
+		free(image->buf);
+		error("Sorry, this Cairo was compiled without tiff support.");
+#endif
+	} /* etc. */
+
+	be->cc = cairo_create(be->cs);
+
+	if (cairo_status(be->cc) != CAIRO_STATUS_SUCCESS){
+		if (image->buf) free(image->buf); free(be); free(image->filename); free(image);
+		return NULL;
+	}
+
+	/* Note: back-ends with alpha-plane don't work with ATOP, because cairo doesn't increase
+	   the opacity and thus the resulting picture will be fully transparent. */
+	cairo_set_operator(be->cc,alpha_plane?CAIRO_OPERATOR_OVER:CAIRO_OPERATOR_ATOP);
+	/* debug */
+	if (cairo_op != -1) cairo_set_operator(be->cc,cairo_op);
+	return be;
+}
diff --git a/src/img-backend.h b/src/img-backend.h
new file mode 100644
index 0000000..132d60a
--- /dev/null
+++ b/src/img-backend.h
@@ -0,0 +1,24 @@
+#ifndef __IMAGE_BACKEND_H__
+#define __IMAGE_BACKEND_H__
+
+#include "backend.h"
+
+/* usually we don't expose this, but the experimental
+   image backplane API needs this so that we don't have
+   to use cairo 1.2 API */
+typedef struct st_Rcairo_image_backend {
+  void *buf;
+  char *filename;
+  int  conn;
+  int  quality;
+  cairo_format_t format;
+  SEXP locator_call, locator_dev;
+} Rcairo_image_backend;
+
+
+extern Rcairo_backend_def *RcairoBackendDef_image;
+
+Rcairo_backend *Rcairo_new_image_backend(Rcairo_backend *be, int conn, const char *filename, const char *type,
+					 int width, int height, int quality, int alpha_plane, SEXP locator_cb);
+
+#endif
diff --git a/src/img-jpeg.c b/src/img-jpeg.c
new file mode 100644
index 0000000..89e7dfb
--- /dev/null
+++ b/src/img-jpeg.c
@@ -0,0 +1,73 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+   Copyright (C) 2007  Simon Urbanek
+   License: GPL v2 */
+
+#include "cconfig.h"
+
+#ifdef SUPPORTS_JPEG
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <jpeglib.h>
+
+int save_jpeg_file(void *buf, int w, int h, char *fn, int quality, int channels) {
+	struct jpeg_compress_struct cinfo;
+	struct jpeg_error_mgr jerr;
+	FILE *output_file = fopen(fn, "wb");
+	JSAMPROW slr;
+
+	if (!output_file) return -1;
+	if (channels!=3 && channels!=4) return -1;
+	cinfo.err = jpeg_std_error(&jerr);
+	jpeg_create_compress(&cinfo);
+	cinfo.in_color_space = JCS_RGB;
+	cinfo.input_components = 3;
+	cinfo.image_width=w;
+	cinfo.image_height=h;
+	jpeg_set_defaults(&cinfo);
+	jpeg_set_quality(&cinfo, quality, (quality<25)?0:1);
+	jpeg_stdio_dest(&cinfo, output_file);
+	jpeg_start_compress(&cinfo, TRUE);
+	if (channels == 3) {
+		unsigned char *src = (unsigned char*) buf;
+		int sl = 0;
+		while (sl<h) {
+			slr=src;
+			jpeg_write_scanlines(&cinfo, &slr, 1);
+			src+=w*3;
+			h++;
+		}
+	} else {
+		unsigned char *dst;
+		unsigned int *src = (unsigned int*)buf;
+		int sl = 0;
+		dst = (unsigned char*) malloc(w*3);
+		while (sl<h) {
+			unsigned char *dp = dst;
+			int x = 0;
+			while (x < w) {
+				dp[0] = (*src >> 16) & 255;
+				dp[1] = (*src >> 8) & 255;
+				dp[2] = *src & 255;
+				src++; dp+=3;
+				x++;
+			}
+			slr=dst;
+			jpeg_write_scanlines(&cinfo, &slr, 1);
+			sl++;
+		}
+		free(dst);
+	}
+	jpeg_finish_compress(&cinfo);
+	jpeg_destroy_compress(&cinfo);
+	fclose(output_file);
+	return 0;
+}
+
+#else
+
+	int save_jpeg_file(void *buf, int w, int h, char *fn, int quality, int channels) {
+	return -2;
+}
+
+#endif
diff --git a/src/img-jpeg.h b/src/img-jpeg.h
new file mode 100644
index 0000000..8499de1
--- /dev/null
+++ b/src/img-jpeg.h
@@ -0,0 +1,6 @@
+#ifndef __IMG_JPEG_H__
+#define __IMG_JPEG_H__
+
+int save_jpeg_file(void *buf, int w, int h, char *fn, int quality, int channels);
+
+#endif
diff --git a/src/img-tiff.c b/src/img-tiff.c
new file mode 100644
index 0000000..67684d6
--- /dev/null
+++ b/src/img-tiff.c
@@ -0,0 +1,68 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+   Copyright (C) 2007  Simon Urbanek
+   License: GPL v2 */
+
+#include "cconfig.h"
+
+#ifdef SUPPORTS_TIFF
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tiffio.h>
+
+int save_tiff_file(void *buf, int w, int h, char *fn, int channels, int compression) {
+	tsize_t linebytes = channels * w;
+	unsigned char *tbuf = NULL; 
+	TIFF *out= TIFFOpen(fn, "w");
+	unsigned int row =  0;
+	unsigned short extra[1] = { EXTRASAMPLE_ASSOCALPHA };
+	if (!out) return -1;
+	TIFFSetField (out, TIFFTAG_IMAGEWIDTH, w);
+	TIFFSetField(out, TIFFTAG_IMAGELENGTH, h);
+	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, channels);
+	TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
+	TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+	TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+	if (channels>3) 
+		TIFFSetField(out, TIFFTAG_EXTRASAMPLES, (unsigned short) 1, extra);
+	if (compression) TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
+
+	/* Rprintf(" %d x %d, %d chs, scanls=%d, strips=%d, compr=%d\n", w, h, channels, TIFFScanlineSize(out), TIFFDefaultStripSize(out, w * channels), compression); */
+
+	if (TIFFScanlineSize(out) < linebytes)
+		tbuf = (unsigned char *)_TIFFmalloc(linebytes);
+	else
+		tbuf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
+
+	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, w * channels));
+	while (row < h)	{
+		unsigned int *src = (unsigned int*)(&((unsigned char*)buf)[row*w*4]);
+		unsigned char *dst = tbuf;
+		int x = 0;
+		while (x < w) {
+			*dst = (*src >> 16) & 255; dst++;
+			*dst = (*src >> 8) & 255; dst++;
+			*dst = *src & 255; dst++;
+			if (channels>3) {
+				*dst = *src >> 24; dst++;
+			}
+			src++; x++;
+		}
+		if (TIFFWriteScanline(out, tbuf, row, 0) < 0) break;
+		row++;
+	}
+	TIFFClose(out);
+	if (tbuf)
+		_TIFFfree(tbuf);
+	return 0;
+}
+
+#else
+
+int save_tiff_file(void *buf, int w, int h, char *fn, int channels) {
+	return -2;
+}
+
+#endif
diff --git a/src/img-tiff.h b/src/img-tiff.h
new file mode 100644
index 0000000..0a320f1
--- /dev/null
+++ b/src/img-tiff.h
@@ -0,0 +1,15 @@
+#ifndef __IMG_TIFF_H__
+#define __IMG_TIFF_H__
+
+/* compression values: */
+#define TIFF_COMPR_NONE 1
+#define TIFF_COMPR_RLE  2
+#define TIFF_COMPR_LZW  5
+#define TIFF_COMPR_JPEG 7
+
+/* the source is assumed to be 32-bit aligned pixels plane (even if channels=3) in
+   native endianness format. really supported are only channels values 3 (RGB Tiff)
+   and 4 (RGBA Tiff). compression value of 0 means that no flag will be set */
+int save_tiff_file(void *buf, int w, int h, char *fn, int channels, int compression);
+
+#endif
diff --git a/src/pdf-backend.c b/src/pdf-backend.c
new file mode 100644
index 0000000..ed8975a
--- /dev/null
+++ b/src/pdf-backend.c
@@ -0,0 +1,107 @@
+#include <stdlib.h>
+#include <string.h>
+#include "pdf-backend.h"
+#ifdef HAVE_RCONN_H
+#include <R.h>
+#include <Rinternals.h>
+#include <Rdefines.h>
+#define R_INTERFACE_PTRS
+#include <Rinterface.h>
+#include <Rembedded.h>
+#include <R_ext/Print.h>
+#include <R_ext/RConn.h>
+#endif
+
+#if CAIRO_HAS_PDF_SURFACE
+
+static char *types_list[] = { "pdf", 0 };
+static Rcairo_backend_def RcairoBackendDef_ = {
+  BET_PDF,
+  types_list,
+  "PDF",
+  CBDF_FILE|CBDF_CONN|CBDF_MULTIPAGE,
+  0
+};
+Rcairo_backend_def *RcairoBackendDef_pdf = &RcairoBackendDef_;
+
+static void pdf_save_page(Rcairo_backend* be, int pageno){
+	cairo_show_page(be->cc);
+}
+
+#ifdef HAVE_RCONN_H
+static cairo_status_t send_image_data(void *closure, const unsigned char *data, unsigned int length)
+{
+	Rcairo_backend *be = (Rcairo_backend *)closure;
+	int conn;
+	conn = *(int *)be->backendSpecific;
+
+	if (R_WriteConnection(conn, data, length, 1))
+		return CAIRO_STATUS_SUCCESS;
+	else
+		return CAIRO_STATUS_WRITE_ERROR;
+}
+#endif
+
+static void pdf_backend_destroy(Rcairo_backend* be)
+{
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);
+	free(be);
+}
+
+Rcairo_backend *Rcairo_new_pdf_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+	be->backend_type = BET_PDF;
+	be->destroy_backend = pdf_backend_destroy;
+	be->save_page = pdf_save_page;
+	if (filename){
+		char *fn = NULL;
+		int len = strlen(filename);
+
+		/* Add .pdf extension if necessary */
+		if (len>3 && strcmp(filename+len-4,".pdf")){
+			fn = malloc(len + 5);
+			if (!fn) { free(be); return NULL; }
+			strcpy(fn,filename);
+			strcat(fn,".pdf");
+			filename = fn;
+		}
+		be->cs = cairo_pdf_surface_create(filename,(double)width,(double)height);
+		if (fn) free(fn);
+	} else {
+#ifdef HAVE_RCONN_H
+		if ( ! (be->backendSpecific =  calloc(1,sizeof(int)))){
+			free(be); return NULL;
+		}
+		*(int *)be->backendSpecific = conn;
+		be->cs = cairo_pdf_surface_create_for_stream(send_image_data,(void *)be,(double)width,(double)height);
+#else
+		free(be); return NULL;
+#endif
+	}
+
+	if (cairo_surface_status(be->cs) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	be->cc = cairo_create(be->cs);
+
+	if (cairo_status(be->cc) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	cairo_set_operator(be->cc,CAIRO_OPERATOR_OVER);
+
+	return be;
+}
+#else
+Rcairo_backend_def *RcairoBackendDef_pdf = 0;
+
+Rcairo_backend *Rcairo_new_pdf_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+	error("cairo library was compiled without PDF back-end.");
+	return NULL;
+}
+#endif
diff --git a/src/pdf-backend.h b/src/pdf-backend.h
new file mode 100644
index 0000000..1bd250a
--- /dev/null
+++ b/src/pdf-backend.h
@@ -0,0 +1,14 @@
+#ifndef __CAIRO_PDF_BACKEND_H__
+#define __CAIRO_PDF_BACKEND_H__
+
+#include "backend.h"
+
+extern Rcairo_backend_def *RcairoBackendDef_pdf;
+
+#if CAIRO_HAS_PDF_SURFACE
+#include <cairo-pdf.h>
+#endif
+
+Rcairo_backend *Rcairo_new_pdf_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height);
+
+#endif
diff --git a/src/ps-backend.c b/src/ps-backend.c
new file mode 100644
index 0000000..6953fff
--- /dev/null
+++ b/src/ps-backend.c
@@ -0,0 +1,107 @@
+#include <stdlib.h>
+#include <string.h>
+#include "ps-backend.h"
+#ifdef HAVE_RCONN_H
+#include <R.h>
+#include <Rinternals.h>
+#include <Rdefines.h>
+#define R_INTERFACE_PTRS
+#include <Rinterface.h>
+#include <Rembedded.h>
+#include <R_ext/Print.h>
+#include <R_ext/RConn.h>
+#endif
+
+#if CAIRO_HAS_PDF_SURFACE
+
+static char *types_list[] = { "ps", 0 };
+static Rcairo_backend_def RcairoBackendDef_ = {
+  BET_PS,
+  types_list,
+  "PostScript",
+  CBDF_FILE|CBDF_CONN|CBDF_MULTIPAGE,
+  0
+};
+Rcairo_backend_def *RcairoBackendDef_ps = &RcairoBackendDef_;
+
+static void ps_save_page(Rcairo_backend* be, int pageno){
+	cairo_show_page(be->cc);
+}
+
+#ifdef HAVE_RCONN_H
+static cairo_status_t send_image_data(void *closure, const unsigned char *data, unsigned int length)
+{
+	Rcairo_backend *be = (Rcairo_backend *)closure;
+	int conn;
+	conn = *(int *)be->backendSpecific;
+
+	if (R_WriteConnection(conn, data, length, 1))
+		return CAIRO_STATUS_SUCCESS;
+	else
+		return CAIRO_STATUS_WRITE_ERROR;
+}
+#endif
+
+static void ps_backend_destroy(Rcairo_backend* be)
+{
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);
+	free(be);
+}
+
+Rcairo_backend *Rcairo_new_ps_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+	be->backend_type = BET_PS;
+	be->destroy_backend = ps_backend_destroy;
+	be->save_page = ps_save_page;
+	if (filename){
+		char *fn = NULL;
+		int len = strlen(filename);
+
+		/* Add .ps extension if necessary */
+		if (len>3 && strcmp(filename+len-3,".ps")){
+			fn = malloc(len + 5);
+			if (!fn) { free(be); return NULL; }
+			strcpy(fn,filename);
+			strcat(fn,".ps");
+			filename = fn;
+		}
+		be->cs = cairo_ps_surface_create(filename,(double)width,(double)height);
+		if (fn) free(fn);
+	} else {
+#ifdef HAVE_RCONN_H
+		if ( ! (be->backendSpecific =  calloc(1,sizeof(int)))){
+			free(be); return NULL;
+		}
+		*(int *)be->backendSpecific = conn;
+		be->cs = cairo_ps_surface_create_for_stream(send_image_data,(void *)be,(double)width,(double)height);
+#else
+		free(be); return NULL;
+#endif
+	}
+
+	if (cairo_surface_status(be->cs) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	be->cc = cairo_create(be->cs);
+
+	if (cairo_status(be->cc) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	cairo_set_operator(be->cc,CAIRO_OPERATOR_OVER);
+
+	return be;
+}
+#else
+Rcairo_backend_def *RcairoBackendDef_ps = 0;
+
+Rcairo_backend *Rcairo_new_ps_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+        error("cairo library was compiled without PostScript back-end.");
+	return NULL;
+}
+#endif
diff --git a/src/ps-backend.h b/src/ps-backend.h
new file mode 100644
index 0000000..c1cce60
--- /dev/null
+++ b/src/ps-backend.h
@@ -0,0 +1,14 @@
+#ifndef __CAIRO_PS_BACKEND_H__
+#define __CAIRO_PS_BACKEND_H__
+
+#include "backend.h"
+
+#if CAIRO_HAS_PS_SURFACE
+#include <cairo-ps.h>
+#endif
+
+extern Rcairo_backend_def *RcairoBackendDef_ps;
+
+Rcairo_backend *Rcairo_new_ps_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height);
+
+#endif
diff --git a/src/svg-backend.c b/src/svg-backend.c
new file mode 100644
index 0000000..a17f5f3
--- /dev/null
+++ b/src/svg-backend.c
@@ -0,0 +1,107 @@
+#include <stdlib.h>
+#include <string.h>
+#include "svg-backend.h"
+#ifdef HAVE_RCONN_H
+#include <R.h>
+#include <Rinternals.h>
+#include <Rdefines.h>
+#define R_INTERFACE_PTRS
+#include <Rinterface.h>
+#include <Rembedded.h>
+#include <R_ext/Print.h>
+#include <R_ext/RConn.h>
+#endif
+
+#if CAIRO_HAS_SVG_SURFACE
+
+static char *types_list[] = { "svg", 0 };
+static Rcairo_backend_def RcairoBackendDef_ = {
+  BET_SVG,
+  types_list,
+  "SVG",
+  CBDF_FILE|CBDF_CONN|CBDF_MULTIPAGE, /* we can't really do multi-page, but we can't do multifiles, either */
+  0
+};
+Rcairo_backend_def *RcairoBackendDef_svg = &RcairoBackendDef_;
+
+static void svg_save_page(Rcairo_backend* be, int pageno){
+	cairo_show_page(be->cc);
+}
+
+#ifdef HAVE_RCONN_H
+static cairo_status_t send_image_data(void *closure, const unsigned char *data, unsigned int length)
+{
+	Rcairo_backend *be = (Rcairo_backend *)closure;
+	int conn;
+	conn = *(int *)be->backendSpecific;
+
+	if (R_WriteConnection(conn, data, length, 1))
+		return CAIRO_STATUS_SUCCESS;
+	else
+		return CAIRO_STATUS_WRITE_ERROR;
+}
+#endif
+
+static void svg_backend_destroy(Rcairo_backend* be)
+{
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);
+	free(be);
+}
+
+Rcairo_backend *Rcairo_new_svg_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+	be->backend_type = BET_SVG;
+	be->destroy_backend = svg_backend_destroy;
+	be->save_page = svg_save_page;
+	if (filename){
+		char *fn = NULL;
+		int len = strlen(filename);
+
+		/* Add .svg extension if necessary */
+		if (len>3 && strcmp(filename+len-4,".svg")){
+			fn = malloc(len + 5);
+			if (!fn) { free(be); return NULL; }
+			strcpy(fn,filename);
+			strcat(fn,".svg");
+			filename = fn;
+		}
+		be->cs = cairo_svg_surface_create(filename,(double)width,(double)height);
+		if (fn) free(fn);
+	} else {
+#ifdef HAVE_RCONN_H
+		if ( ! (be->backendSpecific =  calloc(1,sizeof(int)))){
+			free(be); return NULL;
+		}
+		*(int *)be->backendSpecific = conn;
+		be->cs = cairo_svg_surface_create_for_stream(send_image_data,(void *)be,(double)width,(double)height);
+#else
+		free(be); return NULL;
+#endif
+	}
+
+	if (cairo_surface_status(be->cs) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	be->cc = cairo_create(be->cs);
+
+	if (cairo_status(be->cc) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	cairo_set_operator(be->cc,CAIRO_OPERATOR_OVER);
+
+	return be;
+}
+#else
+Rcairo_backend_def *RcairoBackendDef_svg = 0;
+
+Rcairo_backend *Rcairo_new_svg_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height)
+{
+	error("cairo library was compiled without SVG support.");
+	return NULL;
+}
+#endif
diff --git a/src/svg-backend.h b/src/svg-backend.h
new file mode 100644
index 0000000..ef2dfff
--- /dev/null
+++ b/src/svg-backend.h
@@ -0,0 +1,14 @@
+#ifndef __CAIRO_SVG_BACKEND_H__
+#define __CAIRO_SVG_BACKEND_H__
+
+#include "backend.h"
+
+#if CAIRO_HAS_SVG_SURFACE
+#include <cairo-svg.h>
+#endif
+
+extern Rcairo_backend_def *RcairoBackendDef_svg;
+
+Rcairo_backend *Rcairo_new_svg_backend(Rcairo_backend *be, int conn, const char *filename, double width, double height);
+
+#endif
diff --git a/src/w32-backend.c b/src/w32-backend.c
new file mode 100644
index 0000000..3e9b919
--- /dev/null
+++ b/src/w32-backend.c
@@ -0,0 +1,486 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+   Created 4/11/2007 by Simon Urbanek
+   Copyright (C) 2007        Simon Urbanek
+
+   GA interface is partially based on devWindows.c from R
+
+   License: GPL v2
+
+   Conditionals:
+   NATIVE_UI - if set, we use plain Win32 API (works for stand-alone
+               or SDI apps), otherwise we use GraphApp from R.
+			   The latter is the default.
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "w32-backend.h"
+
+#if CAIRO_HAS_WIN32_SURFACE
+
+static const char *types_list[] = { "win", 0 };
+static Rcairo_backend_def RcairoBackendDef_ = {
+    BET_W32,
+    types_list,
+	"Windows",
+    CBDF_VISUAL,
+    0
+};
+Rcairo_backend_def *RcairoBackendDef_w32 = &RcairoBackendDef_;
+
+/* --- GraphApp support --- we use GA from R headers --- */
+#ifndef NATIVE_UI
+#include <ga.h>
+#undef resize
+
+/* this is an excerpt from internal.h objinfo structure
+   we need it to get the window handle for native GDI */
+typedef struct ga_objinfo {
+	int kind;
+	int refcount;
+	HANDLE handle;
+} ga_object;
+#endif
+
+typedef struct {
+	Rcairo_backend *be; /* back-link */
+	HWND    wh;         /* window handle */
+	HDC     cdc;        /* cache device context */
+	HDC     hdc;        /* window device context */
+	HBITMAP cb;         /* cache bitmap */
+	int     width;
+	int     height;
+#ifndef NATIVE_UI
+	window  gawin;      /* GA window if we use graphapp */
+#endif
+} Rcairo_w32_data;
+
+
+/*---- save page ----*/
+static void w32_save_page(Rcairo_backend* be, int pageno){
+	cairo_show_page(be->cc);
+	cairo_set_source_rgba(be->cc,1,1,1,1);
+	cairo_reset_clip(be->cc);
+	cairo_new_path(be->cc);
+	cairo_paint(be->cc);
+}
+
+/*---- resize ----*/
+static void w32_resize(Rcairo_backend* be, double width, double height){
+	Rcairo_w32_data *xd = (Rcairo_w32_data *) be->backendSpecific;
+	RECT r;
+	HBITMAP ob;
+	HDC hdc;
+	if (!xd) return;
+	if (xd->cdc) {
+		DeleteDC(xd->cdc);
+		DeleteObject(xd->cb);
+	}
+
+	if (be->cs) {
+		cairo_destroy(be->cc); be->cc=0;
+		cairo_surface_destroy(be->cs); be->cs=0;
+	}
+
+	be->width=xd->width=width;
+	be->height=xd->height=height;
+
+	/* manage HDC -- we have to re-get it after resize due to clipping issues */
+	if (!xd->hdc)
+		xd->hdc = GetDC( xd->wh );
+	else {
+		ReleaseDC(xd->wh, xd->hdc);
+		xd->hdc = GetDC( xd->wh );
+	}
+	hdc=xd->hdc;
+	/* first re-paint the window */
+	GetClientRect( xd->wh, &r );
+	/* Rprintf("w32_resize(%g,%g); rect=(%d,%d)-(%d,%d)\n", width, height, r.left, r.bottom, r.right, r.top); */
+	be->cs = cairo_win32_surface_create( hdc );
+	be->cc = cairo_create( be->cs );
+	Rcairo_backend_repaint(be);
+	cairo_copy_page(be->cc);
+	cairo_surface_flush(be->cs);
+
+	/* then create a cached copy */
+	xd->cdc = CreateCompatibleDC( hdc );
+	xd->cb = CreateCompatibleBitmap( hdc, r.right, r.bottom );
+	ob = SelectObject(xd->cdc, xd->cb);
+	BitBlt(xd->cdc, 0, 0, r.right, r.bottom, hdc, 0, 0, SRCCOPY);
+}
+
+/*---- mode ---- (-1=replay finished, 0=done, 1=busy, 2=locator) */
+static void w32_mode(Rcairo_backend* be, int which){
+	Rcairo_w32_data *xd = (Rcairo_w32_data *) be->backendSpecific;
+	if (be->in_replay) return;
+	if (which < 1) {
+		cairo_copy_page(be->cc);
+		cairo_surface_flush(be->cs);
+
+		/* upate cache */
+		if (xd->cdc) {
+			DeleteDC(xd->cdc);
+			DeleteObject(xd->cb);
+		}
+		xd->cdc = CreateCompatibleDC( xd->hdc );
+		xd->cb = CreateCompatibleBitmap( xd->hdc, xd->width, xd->height );
+		SelectObject(xd->cdc, xd->cb);
+		BitBlt(xd->cdc, 0, 0, xd->width, xd->height, xd->hdc, 0, 0, SRCCOPY);
+	}
+}
+
+/*---- locator ----*/
+int  w32_locator(struct st_Rcairo_backend *be, double *x, double *y) {
+	Rcairo_w32_data *cd = (Rcairo_w32_data *) be->backendSpecific;
+	return 0;
+}
+
+/*---- destroy ----*/
+static void w32_backend_destroy(Rcairo_backend* be)
+{
+	Rcairo_w32_data *xd = (Rcairo_w32_data *) be->backendSpecific;
+
+	if (xd->cdc) {
+		DeleteDC(xd->cdc); xd->cdc=0;
+		DeleteObject(xd->cb); xd->cb=0;
+	}
+	if (xd->gawin) {
+		del(xd->gawin);
+		doevent();
+		xd->gawin=0;
+	} else if (xd->wh) {
+		DestroyWindow(xd->wh);
+	}
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);	
+	free(be);
+}
+
+/*-----------------*/
+
+#ifdef NATIVE_UI
+
+static int inited_w32 = 0;
+
+typedef struct w32chain_s {
+	HWND w;
+	window gawin;
+	Rcairo_backend *be;
+	struct w32chain_s *next;
+} w32chain_t;
+
+static w32chain_t wchain;
+
+static HWND      parent;   /* parent of all windows - i.e. the Rgui Workspace or similar */
+static HINSTANCE instance; /* instance handle for the current process */
+static int       isMDI;    /* set to 1 if we are hooked into Rgui's MDI, 0 otherwise */
+static char*     appname;  /* name of the application we hook into (e.g. "Rgui") */
+
+LRESULT CALLBACK WindowProc(HWND hwnd,  UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	Rcairo_backend *be = 0;
+	Rcairo_w32_data *xd = 0;
+	w32chain_t *l = &wchain;
+	while (l && l->be) {
+		if (l->w == hwnd) {
+			be = l->be;
+			break;
+		}
+		l = l -> next;
+	}
+	if (!be) be=wchain.be; /*HACK: DEBUG: FIXME! */
+	if (!be) {
+		{ FILE *f=fopen("c:\\debug.txt","a"); fprintf(f,"Window: %x: be is NULL!\n", hwnd); fclose(f); }
+		return
+			isMDI?DefMDIChildProc(hwnd, uMsg, wParam, lParam):DefWindowProc(hwnd, uMsg, wParam, lParam);
+	}
+
+	xd = (Rcairo_w32_data*) be->backendSpecific;
+
+	{ FILE *f=fopen("c:\\debug.txt","a"); fprintf(f,"Window: %x, msg: %x, [%x, %x]\n", (unsigned int)hwnd, (unsigned int)uMsg, (unsigned int)wParam, (unsigned int)lParam); fclose(f); }
+	
+
+	switch (uMsg) {
+		/*
+		  case WM_DESTROY:
+		  PostQuitMessage(0);
+		  break; 
+
+		  case WM_QUERYENDSESSION:
+		  return((long) TRUE);  // we agree to end session.                                                                            
+		*/
+
+	case WM_CLOSE:
+		DestroyWindow(hwnd);
+		break;
+
+	case WM_SIZE:
+		{
+			RECT r;
+			GetClientRect( hwnd, &r );
+			{ FILE *f=fopen("c:\\debug.txt","a"); fprintf(f," - WM_SIZE: %d x %d\n", r.right, r.bottom); fclose(f); }
+			Rcairo_backend_resize(be, r.right, r.bottom);
+		}
+		return 0;
+
+	case WM_PAINT:
+		{
+			RECT r, ur;
+
+			{ FILE *f=fopen("c:\\debug.txt","a"); fprintf(f," - WM_PAINT: %d\n", (int)GetUpdateRect(hwnd,&ur,1)); fclose(f); }
+			if (GetUpdateRect(hwnd,&ur,1)) {
+				PAINTSTRUCT ps;
+				HDC wdc=BeginPaint(hwnd,&ps);
+				GetClientRect( hwnd, &r );
+				BitBlt(wdc, 0, 0, r.right, r.bottom, xd->cdc, 0, 0, SRCCOPY);
+				ValidateRect(hwnd, NULL);
+				EndPaint(hwnd,&ps);
+			}
+			return 0;
+		}
+
+	default:
+		return
+			isMDI?DefMDIChildProc(hwnd, uMsg, wParam, lParam):DefWindowProc(hwnd, uMsg, wParam, lParam);
+	}
+	return 0;
+}
+
+BOOL CALLBACK EnumWin( HWND hwnd, LPARAM lParam) {
+	char buf[128];
+	*buf=0;
+	GetClassName(hwnd, buf, 127);
+	Rprintf("win> %08x (%s)\n", hwnd, buf);
+	return 1;
+}
+/* just for fun - an easter egg - never really used in Cairo */
+void list_all_windows() {
+	EnumWindows(&EnumWin,0);
+}
+
+static void get_R_window() {
+	char mname[127];
+	char fn[64];
+	char *c = mname, *d = mname;
+	instance = GetModuleHandle(0);
+	GetModuleFileName(instance, mname, sizeof(mname));
+	Rprintf(" Module name: '%s'\n", mname);
+	/* GetFileTitle(mname, fn, sizeof(fn));  we do this manually so we don't need -lcomdlg32 */
+	for (;*c;c++) if (*c=='/' || *c=='\\') d=c+1;
+	c=d; while (*c) c++; c--; while (c>d && *c!='.') c--;
+	if (*c=='.') *c=0;
+	appname=strdup(d);
+	strcpy(fn, d);
+	strcat(fn, " Workspace");
+	parent=FindWindow(fn, 0);
+	if (parent)
+		isMDI = 1;
+	else
+		parent = FindWindow(appname, 0);
+}
+
+#else
+
+static void HelpClose(window w)
+{
+	Rcairo_backend *be = (Rcairo_backend *) getdata(w);
+	Rcairo_backend_kill(be);
+}
+
+static void HelpExpose(window w, rect r)
+{
+	Rcairo_backend *be = (Rcairo_backend *) getdata(w);
+	Rcairo_w32_data *xd = (Rcairo_w32_data *) be->backendSpecific;
+	HWND hwnd = (HWND) ((ga_object*)(xd->gawin))->handle;
+	RECT cr;
+	
+	HDC wdc=GetDC(hwnd);
+	GetClientRect( hwnd, &cr );
+
+	/*
+	if (cr.right != xd->width || cr.bottom != xd->height) {
+		ReleaseDC(hwnd, wdc);
+		Rprintf("HelpExpose: size mismatch, calling resize\n");
+		Rcairo_backend_resize(be, cr.right, cr.bottom);
+		return;
+		}*/
+
+	BitBlt(wdc, 0, 0, cr.right, cr.bottom, xd->cdc, 0, 0, SRCCOPY);
+	ValidateRect(hwnd, NULL);
+	ReleaseDC(hwnd, wdc);
+}
+
+static void HelpResize(window w, rect r)
+{
+	Rcairo_backend *be = (Rcairo_backend *) getdata(w);
+	Rcairo_backend_resize(be, r.width, r.height);
+}
+
+#endif
+
+Rcairo_backend *Rcairo_new_w32_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl)
+{
+	Rcairo_w32_data *xd;
+#ifdef NATIVE_UI
+	w32chain_t *l = &wchain;
+#endif
+
+	if ( ! (xd = (Rcairo_w32_data*) calloc(1,sizeof(Rcairo_w32_data)))) {
+		free(be);
+		return NULL;
+	}
+
+	be->backend_type = BET_W32;
+	be->backendSpecific = xd;
+	xd->be = be;
+	be->destroy_backend = w32_backend_destroy;
+	be->save_page = w32_save_page;
+	be->resize = w32_resize;
+	be->mode = w32_mode;
+	be->locator = w32_locator;
+	be->truncate_rect = 1;
+
+	if (be->dpix<=0) { /* try to find out the DPI setting */
+		HWND dw = GetDesktopWindow();
+		if (dw) {
+			HDC  dc = GetDC(dw);
+			if (dc) {
+				int dpix = GetDeviceCaps(dc, LOGPIXELSX);
+				int dpiy = GetDeviceCaps(dc, LOGPIXELSY);
+				ReleaseDC(dw, dc);
+				if (dpix>0) be->dpix=(double)dpix;
+				if (dpiy>0) be->dpiy=(double)dpiy;
+			}
+		}
+	}
+	/* adjust width and height to be in pixels */
+	if (umpl>0 && be->dpix<=0) {
+		be->dpix = 96; be->dpiy = 96;
+	}
+	if (be->dpiy==0 && be->dpix>0) be->dpiy=be->dpix;
+	if (umpl>0) {
+		width = width * umpl * be->dpix;
+		height = height * umpl * be->dpiy;
+		umpl=-1;
+	}
+	if (umpl!=-1) {
+		width *= (-umpl);
+		height *= (-umpl);
+	}
+
+	be->width = width;
+	be->height = height;
+
+#ifdef NATIVE_UI
+	if (!inited_w32) {
+		WNDCLASS wc;
+
+		get_R_window();
+
+		{ FILE *f=fopen("c:\\debug.txt","w"); fprintf(f,"init W32; isMDI=%d, parent=%x\n", isMDI, (unsigned int) parent); fclose(f); }
+
+		wc.style=0; wc.lpfnWndProc=WindowProc;
+		wc.cbClsExtra=0; wc.cbWndExtra=0;
+		wc.hInstance=instance;
+		wc.hIcon=0;
+		wc.hCursor=LoadCursor(NULL, IDC_ARROW);
+		wc.hbrBackground=GetSysColorBrush(COLOR_WINDOW);
+		wc.lpszMenuName=NULL;
+		wc.lpszClassName="RCairoWindow";
+
+		RegisterClass(&wc);
+
+		wc.cbWndExtra=/* CBWNDEXTRA */ 1024;
+		wc.lpszClassName="RCairoDoc";
+
+		RegisterClass(&wc);
+
+		inited_w32 = 1;
+	}
+
+	while (l->be && l->next) l=l->next;
+	if (l->be) { l->next = (w32chain_t*) calloc(1,sizeof(w32chain_t)); l = l->next; }
+
+	l->be = be;	
+#else
+	{
+		window gawin = newwindow("Cairo Graphics", rect(20,20,width,height),
+								 Document|StandardWindow);
+		xd->gawin = gawin;
+		xd->wh = (HWND) ((ga_object*)gawin)->handle;
+		addto(gawin);
+		gsetcursor(gawin, ArrowCursor);
+		if (ismdi()) {
+			int btsize = 24;
+			control tb;
+
+			tb = newtoolbar(btsize + 4);
+			gsetcursor(tb, ArrowCursor);
+			addto(tb);
+		}
+		addto(gawin);
+		newmenubar(NULL);
+		newmdimenu();
+		show(gawin); /* twice, for a Windows bug */
+		show(gawin);
+		BringToTop(gawin, 0);
+		setresize(gawin, HelpResize);
+		setredraw(gawin, HelpExpose);
+		setclose(gawin, HelpClose);
+		setdata(gawin, (void *) be);
+		w32_resize(be, width, height);
+	}
+#endif
+
+#ifdef NATIVE_UI
+	if (isMDI) {
+		HWND mdiClient;
+		CLIENTCREATESTRUCT ccs;
+		HMENU rm = GetMenu(parent);
+		HMENU wm = GetSubMenu(rm, 4);
+		ccs.hWindowMenu = wm;
+		ccs.idFirstChild = 512+0xE000; /* from graphapp/internal.h -> MinDocID */
+		Rprintf("Menu = %x, Windows = %x, ID = %x\n", rm, wm, ccs.idFirstChild);
+
+		mdiClient = CreateWindow("MDICLIENT","Cairo",WS_CHILD|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,width,height,
+								 parent,NULL,instance,&ccs);
+		ShowWindow(mdiClient, SW_SHOW);
+
+		Rprintf("mdiClient: %x\n", mdiClient);
+		{
+			MDICREATESTRUCT mcs;
+			mcs.szTitle = "Cairo device";
+			mcs.szClass = "RCairoDoc";
+			mcs.hOwner  = instance;
+			mcs.x = CW_USEDEFAULT; mcs.cx = width;
+			mcs.y = CW_USEDEFAULT; mcs.cy = height;
+			mcs.style = WS_MAXIMIZE|WS_MINIMIZE|WS_CHILD|WS_VISIBLE;
+			xd->wh = l->w = (HWND) SendMessage (mdiClient, WM_MDICREATE, 0, 
+												(LONG) (LPMDICREATESTRUCT) &mcs);
+			Rprintf("MDICREATE result: %x\n", l->w);
+		}
+		{ FILE *f=fopen("c:\\debug.txt","a"); fprintf(f,"parent: %x\nMDIclient: %x\ndoc: %x\n", parent, mdiClient, l->w); fclose(f); }
+	} else {
+		l->w = xd->wh = CreateWindow("RCairoWindow","Cairo",WS_OVERLAPPEDWINDOW,
+									 100,100,width,height,
+									 parent,NULL,instance,NULL);
+	}
+
+	ShowWindow(xd->wh, SW_SHOWNORMAL);
+
+	w32_resize(be, width, height);
+
+	UpdateWindow(xd->wh);
+#endif
+
+	return be;
+}
+#else
+Rcairo_backend_def *RcairoBackendDef_w32 = 0;
+
+Rcairo_backend *Rcairo_new_w32_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl)
+{
+	error("cairo library was compiled without win32 back-end.");
+	return NULL;
+}
+#endif
diff --git a/src/w32-backend.h b/src/w32-backend.h
new file mode 100644
index 0000000..4cae215
--- /dev/null
+++ b/src/w32-backend.h
@@ -0,0 +1,14 @@
+#ifndef __CAIRO_W32_BACKEND_H__
+#define __CAIRO_W32_BACKEND_H__
+
+#include "backend.h"
+
+#if CAIRO_HAS_WIN32_SURFACE
+#include <cairo-win32.h>
+#endif
+
+extern Rcairo_backend_def *RcairoBackendDef_w32;
+
+Rcairo_backend *Rcairo_new_w32_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl);
+
+#endif
diff --git a/src/xlib-backend.c b/src/xlib-backend.c
new file mode 100644
index 0000000..41de1a6
--- /dev/null
+++ b/src/xlib-backend.c
@@ -0,0 +1,404 @@
+/* -*- mode: C; tab-width: 4; c-basic-offset: 4 -*-
+   Created 4/6/2007 by Simon Urbanek
+   Copyright (C) 2007        Simon Urbanek
+   X11 window handling is based on src/modules/devX11.c from the R sources:
+   Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
+   Copyright (C) 1997--2005  Robert Gentleman, Ross Ihaka and the R Development Core Team
+
+   License: GPL v2
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "xlib-backend.h"
+
+#if CAIRO_HAS_XLIB_SURFACE
+
+static char *types_list[] = { "x11", 0 };
+static Rcairo_backend_def RcairoBackendDef_ = {
+	BET_XLIB,
+	types_list,
+	"X11",
+	CBDF_VISUAL,
+	0
+};
+Rcairo_backend_def *RcairoBackendDef_xlib = &RcairoBackendDef_;
+
+#include <R_ext/eventloop.h>
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <X11/Intrinsic.h>      /*->    Xlib.h  Xutil.h Xresource.h .. */
+
+typedef struct {
+	Rcairo_backend *be; /* back-link */
+	Display *display;
+	Visual  *visual;
+	Window  rootwin;
+	Window  window;
+	Cursor  gcursor;
+	int     screen;
+	int     width;
+	int     height;
+} Rcairo_xlib_data;
+
+static int inclose = 0;
+static XContext devPtrContext;
+
+static void ProcessX11Events(void *);
+static void handleDisplayEvent(Display *display, XEvent event);
+
+#define X_BELL_VOLUME 0 /* integer between -100 and 100 for the volume
+						   of the bell in locator. */
+
+/*---- save page ----*/
+static void xlib_save_page(Rcairo_backend* be, int pageno){
+	cairo_show_page(be->cc);
+
+	cairo_set_source_rgba(be->cc,1,1,1,1);
+	cairo_reset_clip(be->cc);
+	cairo_new_path(be->cc);
+	cairo_paint(be->cc);
+}
+
+/*---- resize ----*/
+static void xlib_resize(Rcairo_backend* be, double width, double height){
+	Rcairo_xlib_data *xd = (Rcairo_xlib_data *) be->backendSpecific;
+	if (xd) {
+		xd->width=width;
+		xd->height=height;
+	}
+	be->width=width;
+	be->height=height;
+	if (be->cs) cairo_xlib_surface_set_size(be->cs, width, height);
+	Rcairo_backend_repaint(be);
+	if (xd->display) XSync(xd->display, 0);
+}
+
+/*---- mode ---- (0=done, 1=busy, 2=locator) */
+static void xlib_mode(Rcairo_backend* be, int which){
+	if (be->in_replay) return;
+	if (which < 1)	{
+		Rcairo_xlib_data *xd = (Rcairo_xlib_data *) be->backendSpecific;
+		if (xd->display) XSync(xd->display, 0);
+	}
+}
+
+/*---- locator ----*/
+int  xlib_locator(struct st_Rcairo_backend *be, double *x, double *y) {
+	XEvent event;
+	Rcairo_xlib_data *cd = (Rcairo_xlib_data *) be->backendSpecific;
+	Rcairo_xlib_data *cdEvent = NULL;
+	caddr_t temp;
+	int done = 0;
+	Display *display = cd->display;
+
+    ProcessX11Events((void*)NULL);    /* discard pending events */
+    XSync(display, 1);
+    /* handle X events as normal until get a button click in the desired device */
+	while (!done /* && displayOpen FIXME! */) {
+		XNextEvent(display, &event);
+		/* possibly later R_CheckUserInterrupt(); */
+		if (event.type == ButtonPress) {
+			XFindContext(display, event.xbutton.window,
+						 devPtrContext, &temp);
+			cdEvent = (Rcairo_xlib_data *) temp;
+			if (cdEvent == cd) {
+				if (event.xbutton.button == Button1) {
+					int useBeep = asLogical(GetOption(install("locatorBell"),
+													  R_BaseEnv));
+					*x = event.xbutton.x;
+					*y = event.xbutton.y;
+					/* Make a beep! Was print "\07", but that
+					   messes up some terminals. */
+                    if(useBeep) XBell(display, X_BELL_VOLUME);
+                    XSync(display, 0);
+                    done = 1;
+                }
+                else
+                    done = 2;
+            }
+        }
+        else
+            handleDisplayEvent(display, event);
+    }
+    /* if it was a Button1 succeed, otherwise fail */
+    return (done == 1);
+}
+
+/*---- destroy ----*/
+static void xlib_backend_destroy(Rcairo_backend* be)
+{
+	Rcairo_xlib_data *xd = (Rcairo_xlib_data *) be->backendSpecific;
+
+	cairo_surface_destroy(be->cs);
+	cairo_destroy(be->cc);
+	
+	inclose = 1;
+	ProcessX11Events((void*) NULL);
+	
+	if (xd) {
+		XFreeCursor(xd->display, xd->gcursor);
+		XDestroyWindow(xd->display, xd->window);
+		XSync(xd->display, 0);
+	}
+
+	free(be);
+}
+
+/*-----------------*/
+
+static int firstInit = 1;
+
+static void Rcairo_init_xlib() {
+	if (!firstInit) return;
+	devPtrContext = XUniqueContext();
+}
+
+typedef struct Rcairo_display_list_s {
+	Display *display;
+	struct Rcairo_display_list_s *next;
+} Rcairo_display_list;
+
+static Rcairo_display_list display_list = { 0, 0 };
+
+/* FIXME: this is bad - we need to associate it with a display */
+static Atom _XA_WM_PROTOCOLS, protocol;
+
+static void ProcessX11DisplayEvents(Display *display)
+{
+	XEvent event;
+	
+	while (display && XPending(display)) {
+		XNextEvent(display, &event);
+		handleDisplayEvent(display, event);
+	}
+}
+
+static void handleDisplayEvent(Display *display, XEvent event) {
+	caddr_t temp;
+	Rcairo_xlib_data *xd = NULL;
+		
+	if (event.xany.type == Expose) {
+		/* printf(" - expose\n"); */
+		while(XCheckTypedEvent(display, Expose, &event))
+			;
+		XFindContext(display, event.xexpose.window,
+					 devPtrContext, &temp);
+		xd = (Rcairo_xlib_data *) temp;
+		if (event.xexpose.count == 0) /* sync - some X11 implementations seem to need this */
+			XSync(xd->display, 0);
+	} else if (event.type == ConfigureNotify) {
+		while(XCheckTypedEvent(display, ConfigureNotify, &event))
+			;
+		XFindContext(display, event.xconfigure.window,
+					 devPtrContext, &temp);
+		xd = (Rcairo_xlib_data *) temp;
+		if (xd->width != event.xconfigure.width ||
+			xd->height != event.xconfigure.height) {
+			/* printf(" - configure %d x %d (vs %d x %d)\n", event.xconfigure.width, event.xconfigure.height, xd->width, xd->height); */
+			Rcairo_backend_resize(xd->be, event.xconfigure.width, event.xconfigure.height);
+			/* Gobble Expose events; we'll redraw anyway */
+			while(XCheckTypedEvent(display, Expose, &event))
+				;
+		}
+	} else if ((event.type == ClientMessage) &&
+			   (event.xclient.message_type == _XA_WM_PROTOCOLS))
+		if (!inclose && event.xclient.data.l[0] == protocol) {
+			XFindContext(display, event.xclient.window,
+						 devPtrContext, &temp);
+			xd = (Rcairo_xlib_data *) temp;
+			Rcairo_backend_kill(xd->be);
+		}
+}
+
+static void ProcessX11Events(void *foo)
+{
+	Rcairo_display_list *l = &display_list;
+	while (l && l->display) {
+		ProcessX11DisplayEvents(l->display);
+		l = l->next;
+	}
+}
+
+Rcairo_backend *Rcairo_new_xlib_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl)
+{
+	Rcairo_xlib_data *xd;
+
+	if ( ! (xd = (Rcairo_xlib_data*) calloc(1,sizeof(Rcairo_xlib_data)))) {
+		free(be);
+		return NULL;
+	}
+
+	be->backend_type = BET_XLIB;
+	be->backendSpecific = xd;
+	xd->be = be;
+	be->destroy_backend = xlib_backend_destroy;
+	be->save_page = xlib_save_page;
+	be->resize = xlib_resize;
+	be->mode = xlib_mode;
+	be->locator = xlib_locator;
+	be->truncate_rect = 1;
+
+	{
+		int depth;
+		int blackpixel = 0;
+		int whitepixel = 0;
+		static XSetWindowAttributes attributes;    /* Window attributes */
+		XSizeHints *hint;
+		XEvent event;
+		char *title = "Cairo display";
+		
+		if (!display) {
+			display=getenv("DISPLAY");
+			if (!display) display=":0.0";
+		}
+	
+		xd->display = XOpenDisplay(display);
+		if (!xd->display)
+			error("Update to open X11 display %s", display);
+	
+		{ /* we maintain a list of displays we used so far.
+			 let's see if we encountered this display already.
+			 if not, setup the event handler etc.
+		  */
+			Rcairo_display_list *l = &display_list;
+			while (l->display != xd->display && l->next) l=l->next;
+			if (l->display)
+				l = l->next = (Rcairo_display_list *)calloc(1, sizeof(Rcairo_display_list));
+			if (l->display != xd->display) { /* new display */
+				l->display = xd->display;
+				addInputHandler(R_InputHandlers, ConnectionNumber(xd->display),
+								ProcessX11Events, 71);
+				Rcairo_init_xlib();
+			}
+		}
+
+		xd->screen = DefaultScreen(xd->display);
+		{ /* adjust width and height to be in pixels */
+			if (be->dpix<=0) { /* is DPI set to auto? then find it out */
+				int dwp = DisplayWidth(xd->display,xd->screen);
+				int dwr = DisplayWidthMM(xd->display,xd->screen);
+				int dhp = DisplayHeight(xd->display,xd->screen);
+				int dhr = DisplayHeightMM(xd->display,xd->screen);
+				if (dwp && dwr && dhp && dhr) {
+					be->dpix = ((double)dwp)/((double)dwr)*25.4;
+					be->dpiy = ((double)dhp)/((double)dhr)*25.4;
+				}
+			}
+			if (umpl>0 && be->dpix<=0) {
+				warning("cannot determine DPI from the screen, assuming 90dpi");
+				be->dpix = 90; be->dpiy = 90;
+			}
+			if (be->dpiy==0 && be->dpix>0) be->dpiy=be->dpix;
+			if (umpl>0) {
+				width = width * umpl * be->dpix;
+				height = height * umpl * be->dpiy;
+				umpl=-1;
+			}
+			if (umpl!=-1) {
+				width *= (-umpl);
+				height *= (-umpl);
+			}
+		}
+
+		xd->rootwin = DefaultRootWindow(xd->display);
+		depth = DefaultDepth(xd->display, xd->screen);    
+		xd->visual = DefaultVisual(xd->display, xd->screen);
+		if (!xd->visual)
+			error("Unable to get visual from X11 display %s", display);
+		if (xd->visual->class != TrueColor)
+			error("Sorry, Cairo Xlib back-end supports true-color displays only.");
+	
+		{ int d=depth; for (;d;d--) whitepixel=(whitepixel << 1)|1; }
+	
+		devPtrContext = XUniqueContext();
+	
+		memset(&attributes, 0, sizeof(attributes));
+		attributes.background_pixel = whitepixel;
+		attributes.border_pixel = blackpixel;
+		attributes.backing_store = Always;
+		attributes.event_mask = ButtonPressMask
+			| ExposureMask
+			| StructureNotifyMask;
+		
+		hint = XAllocSizeHints();
+		hint->x = 10;
+		hint->y = 10;
+		
+		xd->width = hint->width = be->width = width;
+		xd->height = hint->height = be->height = height;
+		hint->flags  = PPosition | PSize;
+	
+		xd->window = XCreateSimpleWindow(xd->display,
+										 xd->rootwin,
+										 hint->x,hint->y,
+										 hint->width, hint->height,
+										 1,
+										 blackpixel,
+										 whitepixel);
+		if (!xd->window) {
+			XFree(hint);
+			error("Unable to create X11 window on display %s", display);
+		}
+		
+		XSetWMNormalHints(xd->display, xd->window, hint);
+		XFree(hint);
+		XChangeWindowAttributes(xd->display, xd->window,
+								CWEventMask | CWBackPixel |
+								CWBorderPixel | CWBackingStore,
+								&attributes);
+		
+		XStoreName(xd->display, xd->window, title);
+		
+		xd->gcursor = XCreateFontCursor(xd->display, XC_crosshair);
+		XDefineCursor(xd->display, xd->window, xd->gcursor);
+		
+		{ /* FIXME: this is really display-dependent */
+			_XA_WM_PROTOCOLS = XInternAtom(xd->display, "WM_PROTOCOLS", 0);
+			protocol = XInternAtom(xd->display, "WM_DELETE_WINDOW", 0);
+			XSetWMProtocols(xd->display, xd->window, &protocol, 1);
+		}
+		
+		XSaveContext(xd->display, xd->window, devPtrContext, (caddr_t) xd);
+		
+		XSelectInput(xd->display, xd->window,
+					 ExposureMask | ButtonPressMask | StructureNotifyMask);
+		XMapWindow(xd->display, xd->window);
+		XSync(xd->display, 0);
+		while ( XPeekEvent(xd->display, &event),
+				!XCheckTypedEvent(xd->display, Expose, &event))
+			;
+	}
+
+	be->cs = cairo_xlib_surface_create(xd->display, xd->window, xd->visual,
+									   (double)width,(double)height);
+	
+	if (cairo_surface_status(be->cs) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+	
+	be->cc = cairo_create(be->cs);
+	
+	if (cairo_status(be->cc) != CAIRO_STATUS_SUCCESS){
+		free(be);
+		return NULL;
+	}
+
+	cairo_set_operator(be->cc,CAIRO_OPERATOR_ATOP);
+
+	return be;
+}
+#else
+Rcairo_backend_def *RcairoBackendDef_xlib = 0;
+
+Rcairo_backend *Rcairo_new_xlib_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl)
+{
+	error("cairo library was compiled without XLIB back-end.");
+	return NULL;
+}
+#endif
diff --git a/src/xlib-backend.h b/src/xlib-backend.h
new file mode 100644
index 0000000..add4183
--- /dev/null
+++ b/src/xlib-backend.h
@@ -0,0 +1,14 @@
+#ifndef __CAIRO_XLIB_BACKEND_H__
+#define __CAIRO_XLIB_BACKEND_H__
+
+#include "backend.h"
+
+#if CAIRO_HAS_XLIB_SURFACE
+#include <cairo-xlib.h>
+#endif
+
+extern Rcairo_backend_def *RcairoBackendDef_xlib;
+
+Rcairo_backend *Rcairo_new_xlib_backend(Rcairo_backend *be, const char *display, double width, double height, double umpl);
+
+#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-cairo.git



More information about the debian-med-commit mailing list