Exemple #1
0
EXPORT BOOL WINAPI t_getWidth(float *p1, char *string, int p3, int p4)
{
#ifdef JAMING
	unsigned char *out;
	lstrcpy(funcname, "t_getWidth");
	out = toutf8(string);
	*p1 = SWFText_getStringWidth(mhsp_text, (char *)out);
	free(out);
#else
	lstrcpy(funcname, "t_getWidth");
	*p1 = SWFText_getStringWidth(mhsp_text, (unsigned char *)string);
#endif
	return 0;
}
Exemple #2
0
 	/*
     * device_MetricInfo should return height, depth, and
     * width information for the given character in DEVICE
     * units.
     * Note: in an 8-bit locale, c is 'char'.
     * In an mbcslocale, it is wchar_t, and at least some
     * of code assumes that is UCS-2 (Windows, true) or UCS-4.
     * This is used for formatting mathematical expressions
     * and for exact centering of text (see GText)
     * If the device cannot provide metric information then
     * it MUST return 0.0 for ascent, descent, and width.
     *
     * R_GE_gcontext parameters that should be honoured (if possible):
     *   font, cex, ps
     */
static void SWF_MetricInfo( int c, const pGEcontext plotParams,
		double *ascent, double *descent, double *width, pDevDesc deviceInfo ){

	/* Shortcut pointers to variables of interest. */
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;

	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"SWF_MetricInfo:");
		fflush(swfInfo->logFile);
	}

	SWFText text_object = newSWFText();
	//char *s;
	//sprintf(s, "%c", c);

	// Tell the text object to use the font previously loaded
	SWFText_setFont(text_object, swfInfo->ss);

	// Set the height of the text
	SWFText_setHeight(text_object, plotParams->ps * plotParams->cex);

	// Add a string to the text object
	//FIXME!!! pass real character.
	SWFText_addString(text_object, "a", NULL);

	double a = SWFText_getAscent(text_object);
	double d = SWFText_getDescent(text_object);
	double w = SWFText_getStringWidth(text_object, "a");
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"Calculated Ascent=%5.2f, Decent=%5.2f, Width=%5.2f\n", 
				a, d, w);
		fflush(swfInfo->logFile);
	}
	
	*ascent = a;
	*descent = d;
	*width = w;
	
	destroySWFText(text_object);
	
		
}
Exemple #3
0
 /*
     * device_StrWidth should return the width of the given
     * string in DEVICE units.
     * An example is ...
     *
     * static double X11_StrWidth(const char *str,
     *                            const pGEcontext gc,
     *                            pDevDesc dd)
     *
     * R_GE_gcontext parameters that should be honoured (if possible):
     *   font, cex, ps
     */
static double SWF_StrWidth( const char *str,
		const pGEcontext plotParams, pDevDesc deviceInfo )
{
	/* Shortcut pointers to variables of interest. */
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"SWF_StrWidth: ");
		fflush(swfInfo->logFile);
	}
	
	SWFText text_object = newSWFText();
	
	// Tell the text object to use the font previously loaded
	SWFText_setFont(text_object,
		selectFont(plotParams->fontface, plotParams->fontfamily, swfInfo));
	
	// Set the height of the text
	SWFText_setHeight(text_object, plotParams->ps * plotParams->cex);
	
	if( swfInfo->debug == TRUE )
		fprintf(swfInfo->logFile, "Honoring ps=%7.2f, cex=%7.2f\n",
			plotParams->ps, plotParams->cex);
	
	float width = SWFText_getStringWidth(text_object, str);
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"\tCalculated Width of \"%s\" as %7.2f\n", str, width);
		fflush(swfInfo->logFile);
	}
	
	destroySWFText(text_object);
	
	return width;
}