int main() { SWFMovie m = newSWFMovie(); SWFText text = newSWFText(); SWFTextField textfield = newSWFTextField(); SWFDisplayItem it; SWFFont font = newSWFFont_fromFile(MEDIADIR "/font01.fdb"); if(font == NULL) { perror(MEDIADIR "/font01.fdb"); exit(EXIT_FAILURE); } SWFText_setFont(text, font); SWFText_setColor(text, 0, 0, 0xff, 0xff); SWFText_setHeight(text, 20); SWFText_moveTo(text, 100, 100); SWFText_addString(text, "1234567890", NULL); SWFTextField_setFont(textfield, font); SWFTextField_addString(textfield, "1234567890"); SWFTextField_setColor(textfield, 0xff, 0, 0, 0xff); SWFTextField_setHeight(textfield, 20); SWFMovie_add(m, text); it = SWFMovie_add(m, textfield); SWFDisplayItem_moveTo(it, 100, 120); SWFMovie_nextFrame(m); SWFMovie_save(m, "test04.swf"); return 0; }
static void ming_textpara(GVJ_t * job, pointf p, textpara_t * para) { SWFMovie movie = (SWFMovie)(job->context); SWFTextField textfield; SWFDisplayItem item; obj_state_t *obj = job->obj; gvcolor_t pencolor = obj->pencolor; pointf offset; char *font_file_name; char *libdir; static SWFFont font; /* FIXME - hardcoded to a Times-like font */ if (font == NULL) { libdir=gvconfig_libdir(); font_file_name = malloc(strlen(libdir)+strlen(FONT)+2); strcpy(font_file_name, libdir); strcat(font_file_name, "/"); strcat(font_file_name, FONT); font = newSWFFont_fromFile(font_file_name); free(font_file_name); } textfield = newSWFTextField(); SWFTextField_setFont(textfield, (SWFBlock)font); SWFTextField_addChars(textfield, para->str); SWFTextField_addUTF8String(textfield, para->str); SWFTextField_setColor(textfield, pencolor.u.rgba[0], pencolor.u.rgba[1], pencolor.u.rgba[2], pencolor.u.rgba[3]); SWFTextField_setHeight(textfield, para->fontsize); switch (para->just) { case 'r': offset.x = 0.; break; case 'l': offset.x = -para->width; break; case 'n': default: offset.x = -para->width/2.; break; } /* offset to baseline */ offset.y = -para->height + para->fontsize*.4; /* empirically determined */ item = SWFMovie_add(movie, (SWFBlock)textfield); SWFDisplayItem_moveTo(item, p.x + offset.x, p.y + offset.y); }
/*Called on startup to loaddefault font, can also be called from R to * load a user provided font. */ static void SWF_LoadFont(const char *fontFile){ //Get the device info by pointer since this can be called from R pDevDesc deviceInfo = GEcurrentDevice()->dev; // Shortcut pointers to variables of interest. swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific; //Load a fdb or ttf font //XXX - can this work with ttc fonts? //warning(fontFile); swfInfo->ss = newSWFFont_fromFile(fontFile); }
int main() { SWFMovie m = newSWFMovie(); SWFTextField text = newSWFTextField(); SWFFont font = newSWFFont_fromFile(MEDIADIR "/test.ttf"); if(font == NULL) { perror(MEDIADIR "/test.tff"); exit(EXIT_FAILURE); } SWFTextField_setFont(text, font); SWFTextField_setColor(text, 0, 0, 0, 0xff); SWFTextField_setHeight(text, 20); SWFMovie_add(m, text); SWFMovie_nextFrame(m); SWFMovie_save(m, "test02.swf"); return 0; }
int main() { SWFMovie m = newSWFMovie(); SWFTextField text = newSWFTextField(); SWFFont font = newSWFFont_fromFile(MEDIADIR "/test.ttf"); if(font == NULL) { perror(MEDIADIR "/test.tff"); exit(EXIT_FAILURE); } SWFTextField_setFont(text, font); SWFTextField_setColor(text, 0, 0, 0, 0xff); SWFTextField_setHeight(text, 20); SWFTextField_setFlags(text, SWFTEXTFIELD_NOEDIT); SWFTextField_addString(text, "The quick brown fox jumps over the lazy dog. 1234567890"); SWFMovie_add(m, text); SWFMovie_nextFrame(m); SWFMovie_save(m, "test01.swf"); return 0; }
static Rboolean SWF_Setup( pDevDesc deviceInfo, const char *fileName, double width, double height, const char *bg, const char *fg, double frameRate, SEXP fontFileList, const char *logFileName ){ /* * Create swfInfo, this variable contains information which is * unique to the implementation of the SWF Device. The deviceInfo * variable contains a slot into which swfInfo can be placed so that * this information persists and is retrievable during the lifespan * of this device. * * More information on the components of the deviceInfo structure, * which is a pointer to a DevDesc variable, can be found under * struct _DevDesc in the R header file GraphicsDevice.h * * swfInfo is a structure which is defined in the file swfDevice.h * */ swfDevDesc *swfInfo; pGEcontext plotParams; /* * pGEcontext is actually a *pointer* to a structure of type * R_GE_gcontext. If we don't allocate it, it will be passed * into the initialization routine without actually pointing * to anything. This causes nasty crashes- for some reason * only on Windows and Linux... */ if( !( plotParams = (pGEcontext) malloc(sizeof(pGEcontext)) ) ) return FALSE; /* * Initialize swfInfo, return false if this fails. A false return * value will cause the whole device initialization routine to fail. */ if( !( swfInfo = (swfDevDesc *) malloc(sizeof(swfDevDesc)) ) ) return FALSE; /* Copy SWF-specific information to the swfInfo variable. */ strcpy( swfInfo->outFileName, fileName); strcpy( swfInfo->logFileName, logFileName); swfInfo->debug = DEBUG; swfInfo->nFrames = 0; swfInfo->frameRate = frameRate; swfInfo->haveControls = FALSE; /*Initilize the SWF movie version 8 so more line styles can be used*/ swfInfo->m = newSWFMovieWithVersion(8); //const char *ss = CHAR(asChar(getListElement(fontFileList,"ss"))); //Rprintf("%s\n",ss); swfInfo->ss = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"ss")))); swfInfo->ss_b = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"ss_b")))); swfInfo->ss_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"ss_i")))); swfInfo->ss_b_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"ss_b_i")))); swfInfo->mo = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"mo")))); swfInfo->mo_b = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"mo_b")))); swfInfo->mo_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"mo_i")))); swfInfo->mo_b_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"mo_b_i")))); swfInfo->se = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"se")))); swfInfo->se_b = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"se_b")))); swfInfo->se_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"se_i")))); swfInfo->se_b_i = newSWFFont_fromFile(CHAR(asChar(getListElement(fontFileList,"se_b_i")))); swfInfo->displayListHead = NULL; swfInfo->displayListTail = NULL; /* Incorporate swfInfo into deviceInfo. */ deviceInfo->deviceSpecific = (void *) swfInfo; /* * These next statements define the capabilities of the device. * These capabilities include: * -Device/user interaction * -Gamma correction * -Clipping abilities * -UTF8 support * -Text justification/alignment abilities */ /* * Define the gamma factor- used to adjust the luminosity of an image. * Set to 1 since there is no gamma correction in the SWF device. Also, * canChangeGamma is set to FALSE to disallow user adjustment of this * default */ deviceInfo->startgamma = 1; deviceInfo->canChangeGamma = FALSE; /* * canHAdj is an integer specifying the level of horizontal adjustment * or justification provided by this device. Currently set to 0 as this * is not implemented. */ deviceInfo->canHAdj = 0; /* * useRotatedTextInContour specifies if the text function along with * rotation parameters should be used over Hershey fonts when printing * contour plot labels. */ deviceInfo->useRotatedTextInContour = TRUE; /* * canClip specifies whether the device implements routines for filtering * plotting input such that it falls within a rectangular clipping area. * Implementing this leads to an interesting design choice- to implement * clipping here in the C code or hand it off to the SWF clipping * routines. Clipping at the C level may reduce and simplify the final * output file by not printing objects that fall outside the plot * boundaries. */ deviceInfo->canClip = FALSE; /* * These next parameters speficy if the device reacts to keyboard and * mouse events. Since this device outputs to a file, not a screen window, * these actions are disabled. */ deviceInfo->canGenMouseDown = FALSE; deviceInfo->canGenMouseMove = FALSE; deviceInfo->canGenMouseUp = FALSE; deviceInfo->canGenKeybd = FALSE; /* * This parameter specifies whether the device is set up to handle UTF8 * characters. This makes a difference in the complexity of the text * handling functions that must be built into the device. If set to true * both hook functions textUTF8 and strWidthUTF8 must be implemented. * Compared to ASCII, which only has 128 character values, UTF8 has * thousends. This will require a fairly sophisticated function for * calculating string widths. * * UTF8 support would be a great feature to include as it would make * this device useful for an international audience. For now only * the ASCII character set will be used as it is easy to implement. * * wantSymbolUTF8 indicates if mathematical symbols should be treated * as UTF8 characters. */ deviceInfo->hasTextUTF8 = FALSE; deviceInfo->wantSymbolUTF8 = FALSE; /* * Initialize device parameters. These concern properties such as the * plotting canvas size, the initial foreground and background colors and * the initial clipping area. Other parameters related to fonts and text * output are also included. */ /* * Set canvas size. The bottom left corner is considered the origin and * assigned the value of 0pt, 0pt. The upper right corner is assigned by * converting the specified height and width of the device to points. */ deviceInfo->bottom = 0; deviceInfo->left = 0; deviceInfo->top = dim2dev( height ); deviceInfo->right = dim2dev( width ); /* Set default character size in pixels. */ deviceInfo->cra[0] = 9; deviceInfo->cra[1] = 12; /* Set initial font. */ deviceInfo->startfont = 1; /* Set initial font size. */ deviceInfo->startps = 10; /* * Apparently these are supposed to center text strings over the points at * which they are plotted. SWF does this automagically. * * I hope. * */ deviceInfo->xCharOffset = 0; deviceInfo->yCharOffset = 0; deviceInfo->yLineBias = 0; /* Specify the number of inches per pixel in the x and y directions. */ deviceInfo->ipr[0] = 1/dim2dev(1); deviceInfo->ipr[1] = 1/dim2dev(1); /* Set initial foreground and background colors. */ deviceInfo->startfill = R_GE_str2col( bg ); deviceInfo->startcol = R_GE_str2col( fg ); /* Set initial line type. */ deviceInfo->startlty = 0; /* * Connect R graphic function hooks to SWF Routines implemented in this * file. Each routine performs a specific function such as adding text, * drawing a line or reporting/adjusting the status of the device. */ /* Utility routines. */ deviceInfo->close = SWF_Close; deviceInfo->newPage = SWF_NewPage; deviceInfo->clip = SWF_Clip; deviceInfo->size = SWF_Size; /* Text routines. */ deviceInfo->metricInfo = SWF_MetricInfo; deviceInfo->strWidth = SWF_StrWidth; deviceInfo->text = SWF_Text; /* Drawing routines. */ deviceInfo->line = SWF_Line; deviceInfo->circle = SWF_Circle; deviceInfo->rect = SWF_Rectangle; deviceInfo->polyline = SWF_Polyline; deviceInfo->polygon = SWF_Polygon; /* Dummy routines. These are mainly used by GUI graphics devices. */ deviceInfo->activate = SWF_Activate; deviceInfo->deactivate = SWF_Deactivate; deviceInfo->locator = SWF_Locator; deviceInfo->mode = SWF_Mode; /* Call SWF_Open to create and initialize the output file. */ if( !SWF_Open( deviceInfo ) ) return FALSE; return TRUE; }
int main(void) { // Create local variables int i; SWFDisplayItem image_display_item; SWFFont font_object; SWFMovie test_movie; SWFText text_object; // Initialise the movie structure in memory Ming_init(); test_movie = newSWFMovieWithVersion(7); // Set the desired compression level // for the output (9 = maximum compression) Ming_setSWFCompression(9); // Set the background color for the movie SWFMovie_setBackground(test_movie, 0x00, 0x00, 0x00); // Adjust the dimensions of the movie SWFMovie_setDimension(test_movie, 800, 600); // Set the frame rate for the movie to 24 frames per second SWFMovie_setRate(test_movie, 24.0); // Load a font from disk font_object = newSWFFont_fromFile("../../fonts/vera/Vera.ttf"); if (NULL == font_object) { // Something went wrong, so exit printf("Unable to load font from file.\n"); return EXIT_FAILURE; } // Create a new, empty text object text_object = newSWFText(); // Tell the text object to use the font previously loaded SWFText_setFont(text_object, font_object); // Set the height of the text SWFText_setHeight(text_object, 18.0); // Set the color of the text SWFText_setColor(text_object, 0x00, 0x00, 0xff, 0xff); // Add a string to the text object SWFText_addString(text_object, "This is some example text", NULL); // Add the text object to the movie (at 0,0) image_display_item = SWFMovie_add(test_movie, (SWFBlock) text_object); // Move to 100, 100 SWFDisplayItem_moveTo(image_display_item, 100.00, 100.0); // Progressively move the text down and to the right for (i = 0; i <= 250; i++) { SWFMovie_nextFrame(test_movie); SWFDisplayItem_move(image_display_item, 2, 2); } // Save the swf movie file to disk SWFMovie_save(test_movie, "ming-test-text.swf"); // Free the swf movie in memory destroySWFMovie(test_movie); // Free the swf text object destroySWFText(text_object); return EXIT_SUCCESS; }
static VALUE font_open(VALUE klass, VALUE filename) { SWFFont font = newSWFFont_fromFile(StringValuePtr(filename)); if(font == NULL) rb_raise(rb_eRuntimeError, "could not read file"); return Data_Wrap_Struct(klass, NULL, deallocate, font); }