Ejemplo n.º 1
0
bool XSAppBuilder::compileBinary(const QFileInfo &source)
{
    int ret = XS_FALSE;
    QFile binary(source.filePath());
    if(!binary.open(QIODevice::ReadOnly))
    {
        return false;
    }
    QByteArray data = binary.readAll();

    xsValue val;
    val.type = XS_VALUE_BINARY;
    val.data.ptr = (void *)xsCalloc(data.size() + sizeof(size_t));
    *((size_t *)val.data.ptr) = data.size();
    memcpy((char *)val.data.ptr + sizeof(size_t), data.data(), data.size());
    qDebug()<<source.fileName()<<data.size()+sizeof(size_t);
    ret = bon->setProperty(source.fileName().toStdString().c_str(), &val);

    if(ret == XS_TRUE)
    {
        return true;
    }

    return false;
}
Ejemplo n.º 2
0
void xsBufferStream::write(const void *buff, size_t size)
{
	if(buff == NULL || buffer == NULL)
	{
		printf("NULL  pointer!");
		return;
	}

	if(this->size + size > capacity)
	{
		while(capacity < this->size + size)
		{
			capacity *= 2;
		}

		xsU8 *oldBuffer = buffer;
		buffer = (xsU8 *)xsCalloc(capacity * sizeof(xsU8));
		if(buffer == NULL)
		{
			printf("xsCalloc failed!\n");
			return;
		}
		xsMemCpy(buffer, oldBuffer, this->size);

		xsFree(oldBuffer);
		oldBuffer = NULL;
	}

	for(size_t i = 0; i < size; i++)
	{
		*(buffer + this->size++) = *((xsU8 *)buff + i);
	}
}
Ejemplo n.º 3
0
bool XSAppBuilder::compileScript(const QFileInfo &source, const QString &prefix)
{
    int ret = XS_FALSE;
    QFile js(source.filePath());
    if(!js.open(QIODevice::ReadOnly))
    {
        return false;
    }
    QByteArray data = js.readAll();
    QString name = prefix + source.fileName();

    xsValue val;
    val.type = XS_VALUE_STRING;
    val.data.s = (char *)xsCalloc(data.size() + 1);
    strncpy(val.data.s, data.data(), data.size() + 1);
    qDebug()<<name<<data.size()+1;
    ret = bon->setProperty(name.toStdString().c_str(), &val);

    if(ret == XS_TRUE)
    {
        return true;
    }

    return false;
}
Ejemplo n.º 4
0
void xsCanvasContext::createGraphics()
{
	if(NULL == graphicsGroups)
	{
		currentgraphics = (xsGraphicsGroup *)xsCalloc(sizeof(xsGraphicsGroup));
		currentgraphics ->lines = xsArrayListCreate(2);
		currentgraphics ->next = NULL;
		graphicsGroups = currentgraphics;

	}
	else
	{
		xsGraphicsGroup *newgraphics =  (xsGraphicsGroup *)xsCalloc(sizeof(xsGraphicsGroup));
		newgraphics ->lines = xsArrayListCreate(2);
		newgraphics ->next = NULL;
		currentgraphics ->next = newgraphics;
		currentgraphics = newgraphics;
	}
}
Ejemplo n.º 5
0
xsBufferStream::xsBufferStream(size_t size)
{
	buffer = (xsU8 *)xsCalloc(size * sizeof(xsU8));
	if(buffer == NULL)
	{
		printf("xsCalloc failed!\n");
		return;
	}
	capacity = size;
	pos = 0;
	this->size = 0;
}
Ejemplo n.º 6
0
xsBufferStream::xsBufferStream()
{
	buffer = (xsU8 *)xsCalloc(XS_BUFFER_SIZE * sizeof(xsU8));
	if(buffer == NULL)
	{
		printf("xsCalloc failed!\n");
		return;
	}
	capacity = XS_BUFFER_SIZE;
	pos = 0;
	size = 0;
}
Ejemplo n.º 7
0
xsAFD *xsResource::createAFD(const xsTChar *src, const xsTChar *path)
{
	xsAFD *afd;

	afd = (xsAFD *)xsCalloc(sizeof(xsAFD));
	if (afd == NULL)
		return NULL;

	if (_loadMode == xsRuntimeContext::MODE_STAGING)
	{
		afd->srcType = XS_AFD_FILENAME;
		// add path prefix
		const xsTChar *base = _context->getBasePath();
		afd->src.filename = (xsTChar *)xsMalloc((xsTcsLen(base) + xsTcsLen(src) + xsTcsLen(path) + 1) * sizeof(xsTChar));
		xsTcsCpy(afd->src.filename, base);
		xsTcsCat(afd->src.filename, path);
		xsTcsCat(afd->src.filename, src);

		return afd;
	}

	char fullpath[XS_MAX_PATH];
	// add path prefix
	size_t len = xsTcsToUtf8(fullpath, XS_MAX_PATH, path, xsTcsLen(path));
	xsTcsToUtf8(fullpath + len, XS_MAX_PATH - len, src, xsTcsLen(src));
	int ret = XS_EC_ERROR;

	if (_loadMode == xsRuntimeContext::MODE_RESOURCE)
	{
		afd->srcType = XS_AFD_RESOURCE;
		afd->src.res = _res;
		ret = xsBonLocateBinaryInRes(_res, fullpath, &afd->offset, &afd->length);
	}
	else if (_loadMode == xsRuntimeContext::MODE_FILE)
	{
		afd->srcType = XS_AFD_FILE;
		afd->src.fd = _fd;
		ret = xsBonLocateBinaryInFd(_fd, fullpath, &afd->offset, &afd->length);
	}
	
	if (ret != XS_EC_OK)
	{
		XS_ERROR("xsResource::createAFD: Locate AFD failed.");
		xsFree(afd);
		return NULL;
	}

	return afd;
}
Ejemplo n.º 8
0
void xsCanvasContext::save()
{
	xsCanvasAttribute* newStatus = (xsCanvasAttribute*)xsCalloc(sizeof(xsCanvasAttribute));
	newStatus ->fillColor = fillColor;
	newStatus ->strokeColor = strokeColor;
//	newStatus ->shadowColor = shadowColor;
//	newStatus ->shadowBlur = shadowBlur;
//	newStatus ->shadowOffsetX = shadowOffsetX;
//	newStatus ->shadowOffsetY = shadowOffsetY;
	newStatus ->lineWidth = lineWidth;
//	newStatus ->globalCompositeOperation = globalCompositeOperation;
//	newStatus ->globalAlpha = globalAlpha;
	newStatus ->font = font;
	newStatus ->textAlign = textAlign;
	newStatus ->textBaseline = textBaseline;

	addStatus(newStatus);

}
Ejemplo n.º 9
0
void xsBufferStream::write(xsU8 byte)
{
	if(buffer == NULL)
		return;

	if(size >= capacity)
	{
		xsU8 *oldBuffer = buffer;
		buffer = (xsU8 *)xsCalloc(2 * capacity * sizeof(xsU8));
		if(buffer == NULL)
		{
			printf("xsCalloc failed!\n");
			return;
		}
		xsMemCpy(buffer, oldBuffer, capacity);

		capacity *= 2;
		xsFree(oldBuffer);
		oldBuffer = NULL;
	}

	*(buffer + size) = byte;
	size++;
}
Ejemplo n.º 10
0
void xsCanvasContext::paintFill(xsGraphics *gc)
{
	xsIterator iter = NULL;
	xsArrayList lines = NULL;
	xsLine *line = NULL;
	xsRectangle *rect = NULL;
	xsArc *arc = NULL;
	xsBezierCurve* curve = NULL;

	for (;;)
	{
		arc = static_cast<xsArc *>(xsArrayListIterate(arcs, &iter));
		if (iter == NULL || arc == NULL)
			break;

		arc->fill(gc);
	}

	iter = NULL;
	for (;;)
	{
		rect = static_cast<xsRectangle *>(xsArrayListIterate(rects, &iter));
		if (iter == NULL || rect == NULL)
			break;

		rect->fill(gc);
	}

	iter = NULL;
	for (;;)
	{
		curve = static_cast<xsBezierCurve *>(xsArrayListIterate(curves, &iter));
		if (iter == NULL || curve == NULL)
			break;

		curve->fill(gc);
	}

	xsGraphicsGroup* groupTmp = graphicsGroups;
	while(groupTmp != NULL)
	{
		lines = groupTmp ->lines;
		int n = xsArrayListSize(lines);

		if(n < 2)
			return;
		line = static_cast<xsLine *>(xsArrayListGet(lines, 0));
		xsPoint *polygen = (xsPoint*)xsCalloc(sizeof(xsPoint)*(n + 1));
		polygen[0].x = line ->x1;
		polygen[0].y = line ->y1;
		int i = 1;
		iter = NULL;
		for (;;)
		{
			line = static_cast<xsLine *>(xsArrayListIterate(lines, &iter));
			if (iter == NULL || line == NULL)
				break;

			polygen[i].x = line ->x2;
			polygen[i].y = line ->y2;
			i++;
		}

		xsSetColor(gc, fillColor);
		xsFillPolygon(gc, polygen, n + 1);
		if(polygen != NULL)
		{
			xsFree(polygen);
			polygen = NULL;
		}
		groupTmp = groupTmp ->next;
	}

}