@@ -290,6 +290,92 @@ void close_device(pDevDesc dd) {
290290 dd->deviceSpecific = 0 ;
291291}
292292
293+ SEXP CreateConsoleDevice2 (const std::string &background, double width, double height, double pointsize, const std::string &type, void * pointer) {
294+
295+ pGEDevDesc gd = (pGEDevDesc)pointer;
296+ pDevDesc dd = gd->dev ;
297+
298+ dd->startfill = R_GE_str2col (background.c_str ());
299+ dd->startcol = R_RGB (0 , 0 , 0 );
300+ dd->startps = pointsize;
301+ dd->startlty = 0 ;
302+ dd->startfont = 1 ;
303+ dd->startgamma = 1 ;
304+ dd->wantSymbolUTF8 = (Rboolean)1 ;
305+ dd->hasTextUTF8 = (Rboolean)1 ;
306+
307+ // size
308+
309+ dd->left = 0 ;
310+ dd->top = 0 ;
311+ dd->right = width;
312+ dd->bottom = height;
313+
314+ // straight up from [1]. these are "character size in rasters", whatever that means.
315+
316+ dd->cra [0 ] = 0.9 * pointsize;
317+ dd->cra [1 ] = 1.2 * pointsize;
318+
319+ // according to
320+ // include\R_ext\GraphicsDevice.h
321+ // xCharOffset is unused. not sure what that means for the others.
322+
323+ dd->xCharOffset = 0.4900 ;
324+ dd->yCharOffset = 0.3333 ;
325+ dd->yLineBias = 0.2 ;
326+
327+ // inches per raster; this should change for high DPI screens
328+
329+ dd->ipr [0 ] = 1.0 / 72.0 ;
330+ dd->ipr [1 ] = 1.0 / 72.0 ;
331+
332+ dd->canClip = FALSE ;
333+ dd->canHAdj = 0 ;
334+ dd->canChangeGamma = FALSE ;
335+ dd->displayListOn = TRUE ;
336+ dd->haveTransparency = 2 ;
337+ dd->haveTransparentBg = 2 ;
338+ dd->haveRaster = 3 ; // yes, except for missing values
339+
340+ // now functions, at least the ones we're implementing
341+
342+ dd->newPage = &new_page;
343+ dd->close = &close_device;
344+ dd->clip = &set_clip;
345+ dd->size = &get_size;
346+ dd->metricInfo = &get_metric_info;
347+ dd->strWidth = &get_strWidth;
348+ dd->line = &draw_line;
349+ dd->text = &draw_text;
350+ dd->rect = &draw_rect;
351+ dd->circle = &draw_circle;
352+ dd->polygon = &draw_polygon;
353+ dd->polyline = &draw_polyline;
354+ dd->path = &draw_path;
355+ dd->raster = &draw_raster;
356+ dd->textUTF8 = &draw_text;
357+ dd->strWidthUTF8 = &get_strWidth;
358+
359+ // force svg or png
360+
361+ std::string *normalized_type = new std::string (" svg" );
362+ if (!type.compare (" png" )) (*normalized_type) = " png" ;
363+
364+ std::cout << " init device (" << (*normalized_type) << " ): " << std::dec << dd->right << " , " << dd->bottom << std::endl;
365+ dd->deviceSpecific = normalized_type;
366+
367+ std::string name = " BERT Console (" ;
368+ name.append (normalized_type->c_str ());
369+ name.append (" )" );
370+
371+ GEaddDevice2 (gd, name.c_str ());
372+ GEinitDisplayList (gd);
373+ int device = GEdeviceNumber (gd) + 1 ; // to match what R says
374+
375+ return Rf_ScalarInteger (device);
376+
377+ }
378+
293379SEXP CreateConsoleDevice (void *device_pointer, const std::string &type) {
294380
295381 pDevDesc dd = (pDevDesc)device_pointer;
0 commit comments