Skip to content

Commit 62adc55

Browse files
committed
clean up module
1 parent 134cbed commit 62adc55

6 files changed

Lines changed: 342 additions & 343 deletions

File tree

ControlR/console_graphics_device.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
293379
SEXP CreateConsoleDevice(void *device_pointer, const std::string &type) {
294380

295381
pDevDesc dd = (pDevDesc)device_pointer;

ControlR/console_graphics_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <string>
3333

3434
SEXP CreateConsoleDevice(void *p, const std::string &type);
35+
SEXP CreateConsoleDevice2(const std::string &background, double width, double height, double pointsize, const std::string &type, void * pointer);
3536

3637
#endif // #ifndef __CONSOLE_GRAPHICS_DEVICE_H
3738

ControlR/rinterface_common.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,19 +754,33 @@ SEXP RCallback(SEXP command, SEXP data) {
754754

755755
// some commands are handled here. others are sent to BERT as callbacks.
756756

757-
/*
758757
if (!string_command.compare("console-device")) {
759-
return CreateConsoleDevice(data);
758+
759+
// validate args?
760+
if (TYPEOF(data) != VECSXP) return Rf_ScalarLogical(0);
761+
if (Rf_length(data) != 6) return Rf_ScalarLogical(0);
762+
763+
std::string background, type;
764+
double width, height, pointsize;
765+
void *pointer;
766+
767+
background = CHAR(Rf_asChar(VECTOR_ELT(data, 0)));
768+
width = Rf_asReal(VECTOR_ELT(data, 1));
769+
height = Rf_asReal(VECTOR_ELT(data, 2));
770+
pointsize = Rf_asReal(VECTOR_ELT(data, 3));
771+
type = CHAR(Rf_asChar(VECTOR_ELT(data, 4)));
772+
pointer = R_ExternalPtrAddr(VECTOR_ELT(data, 5));
773+
774+
return CreateConsoleDevice2(background, width, height, pointsize, type, pointer);
760775
}
761-
*/
762-
if (!string_command.compare("console-device-png")) {
776+
else if (!string_command.compare("console-device-png")) {
763777
if (TYPEOF(data) == EXTPTRSXP) {
764778
return CreateConsoleDevice(R_ExternalPtrAddr(data), "png");
765779
}
766780
std::cerr << "invalid argument" << std::endl;
767781
return Rf_ScalarLogical(0);
768782
}
769-
if (!string_command.compare("console-device-svg")) {
783+
else if (!string_command.compare("console-device-svg")) {
770784
if (TYPEOF(data) == EXTPTRSXP) {
771785
return CreateConsoleDevice(R_ExternalPtrAddr(data), "svg");
772786
}

Module/DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: BERTModule
22
Type: Package
33
Title: Utilities for BERT
4-
Version: 1.5.7
5-
Date: 2018-02-09
4+
Version: 2.0.3
5+
Date: 2018-02-18
66
Author: Duncan Werner
77
Maintainer: Duncan Werner <dwerner@riskamp.com>
88
Description: Utilities for BERT

0 commit comments

Comments
 (0)