| 906 |
urbaneks |
1 |
/*
|
|
|
2 |
* For compatibility with 2.1.0 - implements stuff formerly present in devQuartz.c in libR
|
|
|
3 |
*
|
|
|
4 |
* Created by Simon Urbanek on 1/13/05 (based on devQuartz in 2.0.1 by Stefano Iacus)
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
#include "devQuartz.h"
|
|
|
9 |
|
|
|
10 |
#include <Rversion.h>
|
|
|
11 |
#include <R.h>
|
|
|
12 |
#include <Rdefines.h>
|
|
|
13 |
#include <Rinternals.h>
|
|
|
14 |
|
|
|
15 |
/* since 2.1.0 devQuartz is no longer in libR, so we need to duplicate it here */
|
|
|
16 |
#if (R_VERSION >= R_Version(2,1,0))
|
|
|
17 |
|
|
|
18 |
static char *SaveFontSpec(SEXP sxp, int offset) {
|
|
|
19 |
char *s;
|
|
|
20 |
if(!isString(sxp) || length(sxp) <= offset)
|
|
|
21 |
error("Invalid font specification");
|
|
|
22 |
s = R_alloc(strlen(CHAR(STRING_ELT(sxp, offset)))+1, sizeof(char));
|
|
|
23 |
strcpy(s, CHAR(STRING_ELT(sxp, offset)));
|
|
|
24 |
return s;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
char* RGUI_Quartz_TranslateFontFamily(char* family, int face, char *devfamily) {
|
|
|
28 |
SEXP graphicsNS, quartzenv, fontdb, fontnames;
|
|
|
29 |
int i, nfonts;
|
|
|
30 |
char* result = devfamily;
|
|
|
31 |
PROTECT_INDEX xpi;
|
|
|
32 |
|
|
|
33 |
PROTECT(graphicsNS = R_FindNamespace(ScalarString(mkChar("grDevices"))));
|
|
|
34 |
PROTECT_WITH_INDEX(quartzenv = findVar(install(".Quartzenv"),
|
|
|
35 |
graphicsNS), &xpi);
|
|
|
36 |
if(TYPEOF(quartzenv) == PROMSXP)
|
|
|
37 |
REPROTECT(quartzenv = eval(quartzenv, graphicsNS), xpi);
|
|
|
38 |
PROTECT(fontdb = findVar(install(".Quartz.Fonts"), quartzenv));
|
|
|
39 |
PROTECT(fontnames = getAttrib(fontdb, R_NamesSymbol));
|
|
|
40 |
nfonts = LENGTH(fontdb);
|
|
|
41 |
if (strlen(family) > 0) {
|
|
|
42 |
int found = 0;
|
|
|
43 |
for (i=0; i<nfonts && !found; i++) {
|
|
|
44 |
char* fontFamily = CHAR(STRING_ELT(fontnames, i));
|
|
|
45 |
if (strcmp(family, fontFamily) == 0) {
|
|
|
46 |
found = 1;
|
|
|
47 |
result = SaveFontSpec(VECTOR_ELT(fontdb, i), face-1);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
if (!found)
|
|
|
51 |
warning("Font family not found in Quartz font database");
|
|
|
52 |
}
|
|
|
53 |
UNPROTECT(4);
|
|
|
54 |
return result;
|
|
|
55 |
}
|
|
|
56 |
#endif
|