Exemple #1
0
void KPR_canvasRenderingContext2D_measureText(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsStringValue text = xsToString(xsArg(0));
	UInt16* buffer;
	if (kFskErrNone == FskTextUTF8ToUnicode16NE((unsigned char*)text, FskStrLen(text), &buffer, NULL)) {
		xsNumberValue width = FskCanvas2dMeasureText(ctx, buffer);
		FskMemPtrDispose(buffer);
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("textMetrics")));
		xsSet(xsResult, xsID("width"), xsNumber(width));
	}
}
Exemple #2
0
void xs_pwm_read(xsMachine* the)
{
	FskErr err;
	double value;
    FskPinPWM pwm = xsGetHostData(xsThis);
    if (!pwm) return;

	err = FskPinPWMGetDutyCycle(pwm, &value);
	xsThrowDiagnosticIfFskErr(err, "PWM read of pin %d failed with error %d.", (int)-1, FskInstrumentationGetErrorString(err));

	xsResult = xsNumber(value);
}
Exemple #3
0
void xs_a2d_read(xsMachine* the)
{
	FskErr err;
    FskPinAnalog a2d = xsGetHostData(xsThis);
	double value;

	xsThrowIfNULL(a2d);

	err = FskPinAnalogRead(a2d, &value);
	xsThrowDiagnosticIfFskErr(err, "Analog pin read %d error.", -1);

	xsResult = xsNumber(value);
}
Exemple #4
0
void KPR_canvasRenderingContext2D_getLineDash(xsMachine *the)
{
	FskCanvas2dContext	ctx = xsGetHostData(xsThis);
	double				*dash	= NULL;
	FskErr				err;
	UInt32				len, i;

	bailIfError(FskCanvas2dGetLineDash(ctx, &len, &dash));
	len *= 2;																	/* Convert from cycles to length */
	xsResult = xsNew1(xsGlobal, xsID("Array"), xsInteger(len));
	for (i = 0; i < len; i++)
		xsSetAt(xsResult, xsInteger(i), xsNumber(dash[i]));
bail:
	(void)FskMemPtrDispose(dash);
	return;
}
Exemple #5
0
void KprFILEServiceInvoke(KprService service UNUSED, KprMessage message)
{
	FskErr err = kFskErrNone;
	char* path = NULL;
	FskFileInfo info;
	FskDirectoryIterator iterator = NULL;
	char* pathName = NULL;
	char* sniff = NULL;
	FskFile fref = NULL;
	char *name = NULL;
	if (KprMessageContinue(message)) {
		if (!message->method || FskStrCompare(message->method, "GET")) {
			bailIfError(KprURLToPath(message->url, &path));
			bailIfError(FskFileGetFileInfo(path, &info));
			if (kFskDirectoryItemIsDirectory == info.filetype) {
				unsigned char buffer[4096];
				UInt32 itemType;
				double date;
				UInt32 size;
				xsBeginHostSandboxCode(gFILEService.machine, NULL);
				{
					xsVars(3);
					{
						xsTry {
							xsVar(0) = xsGet(xsGlobal, xsID("Files"));
							xsResult = xsNewInstanceOf(xsArrayPrototype);
							bailIfError(FskDirectoryIteratorNew(path, &iterator, 0));
							while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &itemType)) {
								if (name[0] == '.') {
									FskMemPtrDisposeAt(&name);
									continue;
								}
								if (kFskDirectoryItemIsFile == itemType) {
									pathName = FskStrDoCat(path, name);
									bailIfError(FskFileGetFileInfo(pathName, &info));
									bailIfError(FskFileOpen(pathName, kFskFilePermissionReadOnly, &fref));
									bailIfError(FskFileRead(fref, sizeof(buffer), buffer, &size));
									FskFileClose(fref);
									fref = NULL;
									if (kFskErrNone == FskMediaPlayerSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									else if (kFskErrNone == FskImageDecompressSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									FskMemPtrDispose(pathName);
									pathName = NULL;
								}
								xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
								xsNewHostProperty(xsVar(1), xsID("name"), xsString(name), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("path"), xsString(name), xsDefault, xsDontScript);
								FskStrCopy((char*)buffer, message->url);
								FskStrCat((char*)buffer, name);
								if (kFskDirectoryItemIsDirectory == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("directoryType"));
									FskStrCat((char*)buffer, "/");
								}
								else if (kFskDirectoryItemIsFile == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("fileType"));
									if (info.fileModificationDate > info.fileCreationDate)
										date = info.fileModificationDate * 1000.0;	
									else
										date = info.fileCreationDate * 1000.0;
									xsNewHostProperty(xsVar(1), xsID("date"), xsNumber(date), xsDefault, xsDontScript);
									xsNewHostProperty(xsVar(1), xsID("size"), xsNumber(info.filesize), xsDefault, xsDontScript);
									if (sniff) {
										xsNewHostProperty(xsVar(1), xsID("mime"), xsString(sniff), xsDefault, xsDontScript);
										FskMemPtrDispose(sniff);
										sniff = NULL;
									}
								}
								else
									xsVar(2) = xsGet(xsVar(0), xsID("linkType"));
								xsNewHostProperty(xsVar(1), xsID("type"), xsVar(2), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("url"), xsString((char*)buffer), xsDefault, xsDontScript);
								(void)xsCall1(xsResult, xsID("push"), xsVar(1));
								FskMemPtrDisposeAt(&name);
							}
							xsResult = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("stringify"), xsResult);
							message->response.body = FskStrDoCopy(xsToString(xsResult));
							message->response.size = FskStrLen(message->response.body);
							KprMessageTransform(message, gFILEService.machine);
						}
						xsCatch {
						}
					}
				}
				xsEndHostSandboxCode();
			}
			else if (kFskDirectoryItemIsFile == info.filetype) {
Exemple #6
0
void KPR_message_get_priority(xsMachine *the)
{
	KprMessage self = xsGetHostData(xsThis);
	xsResult = xsNumber((double)KprMessageGetPriority(self) / 4096);
}
Exemple #7
0
void KPR_canvasRenderingContext2D_get_shadowBlur(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsResult = xsNumber(FskCanvas2dGetShadowBlur(ctx));
}
Exemple #8
0
void KPR_canvasRenderingContext2D_get_miterLimit(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsResult = xsNumber(FskCanvas2dGetMiterLimit(ctx));
}
Exemple #9
0
// line caps/joins
void KPR_canvasRenderingContext2D_get_lineWidth(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsResult = xsNumber(FskCanvas2dGetLineWidth(ctx));
}
Exemple #10
0
static void KPR_canvasRenderingContext2D_getStyle(xsMachine *the, xsBooleanValue stroke)
{
	FskCanvas2dContext ctx;
	const FskColorSourceUnion* csu;
	UInt32 c, i;
	FskGradientStop *stop;
	xsVars(3);
	ctx = xsGetHostData(xsThis);
	if (stroke)
		csu = (const FskColorSourceUnion *)FskCanvas2dGetStrokeStyle(ctx);
	else
		csu = (const FskColorSourceUnion *)FskCanvas2dGetFillStyle(ctx);
	switch (csu->so.type) {
	case kFskColorSourceTypeConstant:
		KprSerializeColor(the, &csu->cn.color, &xsResult);
		break;
	case kFskColorSourceTypeLinearGradient:
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasLinearGradient")));
		xsSet(xsResult, xsID("x0"), xsNumber(FskFixedToFloat(csu->lg.gradientVector[0].x)));
		xsSet(xsResult, xsID("y0"), xsNumber(FskFixedToFloat(csu->lg.gradientVector[0].y)));
		xsSet(xsResult, xsID("x1"), xsNumber(FskFixedToFloat(csu->lg.gradientVector[1].x)));
		xsSet(xsResult, xsID("y1"), xsNumber(FskFixedToFloat(csu->lg.gradientVector[1].y)));
		c = csu->lg.numStops;
		stop = csu->lg.gradientStops;
		goto getStops;
	case kFskColorSourceTypeRadialGradient:
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasRadialGradient")));
		xsSet(xsResult, xsID("x0"), xsNumber(FskFixedToFloat(csu->rg.focus.x)));
		xsSet(xsResult, xsID("y0"), xsNumber(FskFixedToFloat(csu->rg.focus.y)));
		xsSet(xsResult, xsID("r0"), xsNumber(0));
		xsSet(xsResult, xsID("x1"), xsNumber(FskFixedToFloat(csu->rg.center.x)));
		xsSet(xsResult, xsID("y1"), xsNumber(FskFixedToFloat(csu->rg.center.y)));
		xsSet(xsResult, xsID("r1"), xsNumber(FskFixedToFloat(csu->rg.radius)));
		c = csu->rg.numStops;
		stop = csu->rg.gradientStops;
getStops:
		xsVar(0) = xsNew1(xsGlobal, xsID("Array"), xsInteger(c));
		for (i = 0; i < c; i++) {
			xsVar(1) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasGradientStop")));
			xsSet(xsVar(1), xsID("offset"), xsNumber(FskFractToFloat(stop->offset)));
			KprSerializeColor(the, &stop->color, &xsVar(2));
			xsSet(xsVar(1), xsID("color"), xsVar(2));
			xsSetAt(xsVar(0), xsInteger(i), xsVar(1));
			stop++;
		}
		xsSet(xsResult, xsID("stops"), xsVar(0));
		break;
	case kFskColorSourceTypeTexture:
		xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasPattern")));
		// @@ fskBitmapToXSBitmap(the, (FskBitmap)csu->tx.texture, false, &xsVar(0));
		xsSet(xsResult, xsID("image"), xsVar(0));
		c = csu->tx.spreadMethod & kFskCanvas2dPatternRepeatX;
		i = csu->tx.spreadMethod & kFskCanvas2dPatternRepeatY;
		if (c && i)
			xsSet(xsResult, xsID("repetition"), xsString("repeat"));
		else if (c)
			xsSet(xsResult, xsID("repetition"), xsString("repeat-x"));
		else if (i)
			xsSet(xsResult, xsID("repetition"), xsString("repeat-y"));
		else
			xsSet(xsResult, xsID("repetition"), xsString("no-repeat"));
		break;
	}
}
Exemple #11
0
// compositing
void KPR_canvasRenderingContext2D_get_globalAlpha(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsResult = xsNumber(FskCanvas2dGetGlobalAlpha(ctx));
}