From 11158e5202b3421e1f370af5bf6547d219f8946c Mon Sep 17 00:00:00 2001 From: Simon Schubert <2@0x2c.org> Date: Sun, 5 Aug 2012 19:52:37 +0200 Subject: [PATCH 1/2] getDocumentPointsize: fix regexp The previous regexp would match any number that was followed by either "p" or "t" and use this as the document point size. This led to \documentclass[a4paper]{artice} being interpreted as a 4pt document. As a result, plotted figures wound up with grossly scaled font nodes (scale=3 or similar). We instead want to only match digits at the beginning of a word, followed by the string "pt". --- R/deviceUtils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/deviceUtils.R b/R/deviceUtils.R index 0b77a1e..b1af02f 100644 --- a/R/deviceUtils.R +++ b/R/deviceUtils.R @@ -15,7 +15,7 @@ getDocumentPointsize <- function( docString ){ # startps component of the pDevDesc structure. # Search the document declaration for the pointsize. - psLocation <- regexpr( '\\d+[pt]', docString, ignore.case = T, perl = T ) + psLocation <- regexpr( '\\<\\d+pt', docString, ignore.case = T, perl = T ) # If there were no matches, regexpr() returns -1 and this # function returns NA. From 41d9a26eca01434ff23843153278b9746284fb5d Mon Sep 17 00:00:00 2001 From: corecode <2@0x2c.org> Date: Thu, 4 Apr 2013 17:55:16 +0300 Subject: [PATCH 2/2] only match digits+"pt" for point size --- R/deviceUtils.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/deviceUtils.R b/R/deviceUtils.R index b1af02f..f5cd46c 100644 --- a/R/deviceUtils.R +++ b/R/deviceUtils.R @@ -15,7 +15,7 @@ getDocumentPointsize <- function( docString ){ # startps component of the pDevDesc structure. # Search the document declaration for the pointsize. - psLocation <- regexpr( '\\<\\d+pt', docString, ignore.case = T, perl = T ) + psLocation <- regexpr( '\\<\\d+pt\\>', docString, ignore.case = T, perl = T ) # If there were no matches, regexpr() returns -1 and this # function returns NA. @@ -27,7 +27,7 @@ getDocumentPointsize <- function( docString ){ # Extract and return the pointsize. pointsize <- substr( docString, psLocation, - psLocation + attr( psLocation, 'match.length') - 2 ) + psLocation + attr( psLocation, 'match.length') - 3 ) return( as.numeric( pointsize ) )