@@ -113,9 +113,72 @@ glyphJust.numeric <- function(just, which=NULL, ...) {
113113
114114# ###############################################################################
115115# # glyph font
116+ 
117+ standardAxes  <-  c(" wght" " wdth" " ital" " slnt" " opsz" 
118+ standardAxisMin  <-  c(wght = 1 , wdth = 0 , ital = 0 , slnt = - 90 , opsz = 0 )
119+ standardAxisMax  <-  c(wght = 1000 , wdth = Inf , ital = 1 , slnt = 90 , opsz = Inf )
120+ 
121+ checkAxisCase  <-  function (axis , registered ) {
122+     if  (any(registered ) && 
123+         (! all(tolower(axis [registered ]) ==  axis [registered ]))) {
124+         warning(" Registered axis names must be lower case" 
125+     }
126+     if  (any(! registered ) && 
127+         (! all(toupper(axis [! registered ]) ==  axis [! registered ]))) {
128+         warning(" Custom axis names must be upper case" 
129+     }
130+ }
131+ 
132+ checkAxisRange  <-  function (axis , value ) {
133+     low  <-  value  <  standardAxisMin [axis ]
134+     high  <-  value  >  standardAxisMax [axis ] 
135+     if  (any(low ) ||  any(high )) {
136+         warning(" Axis value(s) out of range: " 
137+                 paste(paste0(axis [low | high ], " =" value [low | high ]),
138+                       collapse = " ; " 
139+     }
140+ }
141+ 
142+ fontVariation  <-  function (axis , value ) {
143+     if  (! length(axis )) {
144+         stop(" No axes specified" 
145+     }
146+     if  (! is.character(axis ) ||  any(is.na(axis )) ||  any(nchar(axis ) !=  4 )|| 
147+         any(grepl(" [^a-zA-Z]" axis ))) {
148+         stop(" Axis names must 4 ASCII letters long" 
149+     }
150+     if  (! is.numeric(value ) ||  any(is.na(value ))) {
151+         stop(" Axis values must be numeric" 
152+     }
153+     registered  <-  tolower(axis ) %in%  standardAxes 
154+     checkAxisCase(axis , registered )
155+     if  (any(registered )) {
156+         checkAxisRange(tolower(axis [registered ]), value [registered ])
157+     }
158+     variant  <-  value 
159+     names(variant ) <-  axis 
160+     attr(variant , " formatted" <-  paste(axis , value , sep = " =" 
161+     attr(variant , " registered" <-  registered 
162+     class(variant ) <-  " FontVariation" 
163+     variant 
164+ }
165+ 
166+ glyphFontVariation  <-  function (... ) {
167+     values  <-  c(... )
168+     axes  <-  names(values )
169+     fontVariation(axes , values )
170+ }
171+ 
172+ print.FontVariation  <-  function (x , ... ) {
173+     names  <-  names(x )
174+     attributes(x ) <-  NULL 
175+     names(x ) <-  names 
176+     print(unclass(x ))
177+ }
178+ 
116179glyphFont  <-  function (file , index ,
117180                      family , weight , style ,
118-                       PSname = NA ) {
181+                       PSname = NA ,  variations = NULL ) {
119182    file  <-  as.character(file )
120183    nafile  <-  is.na(file )
121184    if  (any(nchar(file [! nafile ], " bytes" >  500 ))
@@ -151,17 +214,31 @@ glyphFont <- function(file, index,
151214    names  <-  rle(PSname )$ lengths 
152215    if  (! (all(families  ==  files ) &&  all(files  ==  names )))
153216        stop(" Font information is inconsistent" 
154-     
217+     if  (! is.null(variations )) {
218+         if  (! inherits(variations , " FontVariation" 
219+             variations  <-  do.call(glyphFontVariation , as.list(variations ))
220+         }
221+     }
222+ 
155223    font  <-  list (file = file , index = index ,
156224                 family = family , weight = weight , style = style ,
157-                  PSname = PSname )
225+                  PSname = PSname ,  variations = variations )
158226    class(font ) <-  " RGlyphFont" 
159227    font 
160228}
161229
162230print.RGlyphFont  <-  function (x , ... ) {
163-     cat(paste0(x $ family , "  wgt: " x $ weight , "  style: " x $ style ),
164-                " \n   (" x $ file , "  [" x $ index , " ])\n " 
231+     format  <-  paste0(x $ family , "  wgt: " x $ weight ,
232+                      "  style: " x $ style ),
233+                      " \n   (" x $ file , "  [" x $ index , " ]" 
234+     if  (! is.null(x $ variations )) {
235+         format  <-  paste0(format ,
236+                         "  [" 
237+                         paste(paste0(names(x $ variations ), " =" x $ variations ),
238+                               collapse = " ; " 
239+                         " ]" 
240+     }
241+     cat(format , " )\n " 
165242}
166243
167244glyphFontList  <-  function (... ) {
0 commit comments