Skip to content
This repository has been archived by the owner on Sep 23, 2018. It is now read-only.

Commit

Permalink
Pass package arguments from C functions
Browse files Browse the repository at this point in the history
Pass `documentDeclaration` and `packages` when `getLatexStrWidth` and
`getLatexCharMetrics` are called from the C level. This ensures these arguments
are honored if passed to `tikz` when the device is created.

Fixes #59.
  • Loading branch information
Sharpie committed Feb 5, 2012
1 parent bc80cc9 commit d28d965
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ Latest Changes
- Calls to the Filehash package have been protected from user interruptions.
This should prevent rogue lockfiles and corrupted metrics dictionaries.

- The `documentDeclaration` and `packages` arguments to the `tikz` function
are now used in metric calculations. Previously, only global options were
consulted.

#### Behind the Scenes

- The tikzDevice now requires R 2.12.0 or later.
Expand Down
16 changes: 14 additions & 2 deletions src/tikzDevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ static void TikZ_MetricInfo(int c, const pGEcontext plotParams,
SEXP metricFun = findFun(install("getLatexCharMetrics"), namespace);

SEXP RCallBack;
PROTECT( RCallBack = allocVector(LANGSXP,5) );
PROTECT( RCallBack = allocVector(LANGSXP,7) );

// Place the function into the first slot of the SEXP.
SETCAR( RCallBack, metricFun );
Expand Down Expand Up @@ -749,6 +749,12 @@ static void TikZ_MetricInfo(int c, const pGEcontext plotParams,
}
SET_TAG(CDDR(CDDR(RCallBack)), install("engine"));

SETCAD4R(CDR(RCallBack), mkString(tikzInfo->documentDeclaration));
SET_TAG(CDR(CDDR(CDDR(RCallBack))), install("documentDeclaration"));

SETCAD4R(CDDR(RCallBack), mkString(tikzInfo->packages));
SET_TAG(CDDR(CDDR(CDDR(RCallBack))), install("packages"));

SEXP RMetrics;
PROTECT( RMetrics = eval(RCallBack, namespace) );

Expand Down Expand Up @@ -859,7 +865,7 @@ static double TikZ_StrWidth( const char *str,
* so I guess I will nuke it."
*/
SEXP RCallBack;
PROTECT( RCallBack = allocVector(LANGSXP, 5) );
PROTECT( RCallBack = allocVector(LANGSXP, 7) );

// Place the function into the first slot of the SEXP.
SETCAR( RCallBack, widthFun );
Expand Down Expand Up @@ -903,6 +909,12 @@ static double TikZ_StrWidth( const char *str,
}
SET_TAG(CDDR(CDDR(RCallBack)), install("engine"));

SETCAD4R(CDR(RCallBack), mkString(tikzInfo->documentDeclaration));
SET_TAG(CDR(CDDR(CDDR(RCallBack))), install("documentDeclaration"));

SETCAD4R(CDDR(RCallBack), mkString(tikzInfo->packages));
SET_TAG(CDDR(CDDR(CDDR(RCallBack))), install("packages"));

/*
* Call the R function, capture the result.
* PROTECT may not be necessary here, but I'm doing
Expand Down

0 comments on commit d28d965

Please sign in to comment.