1 /*
2  *  R : A Computer Language for Statistical Data Analysis
3  *  Copyright (C) 2011-2014     The R Core Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, a copy is available at
17  *  https://www.R-project.org/Licenses/
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include <Defn.h>
25 
26 
27 #include <R_ext/Rdynload.h>
28 int R_cairoCdynload(int local, int now);
29 
30 typedef SEXP (*R_cairo)(SEXP args);
31 typedef SEXP (*R_cairoVersion_t)(void);
32 typedef SEXP (*R_pangoVersion_t)(void);
33 typedef SEXP (*R_cairoFT_t)(void);
34 
35 static R_cairo R_devCairo;
36 static R_cairoVersion_t R_cairoVersion;
37 static R_pangoVersion_t R_pangoVersion;
38 static R_cairoFT_t R_cairoFT;
39 
Load_Rcairo_Dll(void)40 static int Load_Rcairo_Dll(void)
41 {
42     static int initialized = 0;
43 
44     if (initialized) return initialized;
45     initialized = -1;
46 
47     int res = R_cairoCdynload(1, 1);
48     if(!res) return initialized;
49     R_devCairo = (R_cairo) R_FindSymbol("in_Cairo", "cairo", NULL);
50     if (!R_devCairo) error("failed to load cairo DLL");
51     R_cairoVersion = (R_cairoVersion_t) R_FindSymbol("in_CairoVersion", "cairo", NULL);
52     R_pangoVersion = (R_pangoVersion_t) R_FindSymbol("in_PangoVersion", "cairo", NULL);
53     R_cairoFT = (R_cairoFT_t) R_FindSymbol("in_CairoFT", "cairo", NULL);
54     initialized = 1;
55     return initialized;
56 }
57 
58 
devCairo(SEXP args)59 SEXP devCairo(SEXP args)
60 {
61     if (Load_Rcairo_Dll() < 0) warning("failed to load cairo DLL");
62     else (R_devCairo)(args);
63     return R_NilValue;
64 }
65 
cairoVersion(void)66 SEXP cairoVersion(void)
67 {
68 #ifdef HAVE_WORKING_CAIRO
69     if (Load_Rcairo_Dll() < 0) return mkString("");
70     else return (R_cairoVersion)();
71 #else
72     return mkString("");
73 #endif
74 }
75 
pangoVersion(void)76 SEXP pangoVersion(void)
77 {
78 #ifdef HAVE_WORKING_CAIRO
79     if (Load_Rcairo_Dll() < 0) return mkString("");
80     else return (R_pangoVersion)();
81 #else
82     return mkString("");
83 #endif
84 }
85 
cairoFT(void)86 SEXP cairoFT(void)
87 {
88 #ifdef HAVE_WORKING_CAIRO
89     if (Load_Rcairo_Dll() < 0) return mkString("");
90     else return (R_cairoFT)();
91 #else
92     return mkString("");
93 #endif
94 }
95