[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-dev] XAR file groups misunderstanding



Hello,

I have a small problem to understand the correct way to use the XAR groups.

Please find attached a small test program that outputs a XAR document
with two lines (paths) with different colours.  The two lines are
grouped into a single group.

Xara LX displays correctly the output document but when you ungroup the
two objects they lose their properties (the blue line becomes red).

What I am doing wrong?  Sorry if I'm doing something stupid (witch I'm sure)
but I don't get the point.

Regards,
Sandro

// xarlib testing scratchpad

#include "xarlib/xarlib.h"

CXarExport* pExporter;
UINT32 uiRedColourRef;
UINT32 uiBlueColourRef;

#define CM2MIL(x) ((INT32)((x)*28.34645669f*1000.0f))

void SelectStroke(INT32 iRef, INT32 width)
{
	CXaraFileRecord Rec(0);

	Rec.Reinit(TAG_LINECOLOUR, TAG_LINECOLOUR_SIZE);
	Rec.WriteReference(iRef);
	pExporter->WriteRecord(&Rec);

	Rec.Reinit(TAG_LINEWIDTH, TAG_LINEWIDTH_SIZE);
	Rec.WriteINT32(width);
	pExporter->WriteRecord(&Rec);
}

void DrawLine(INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT32 iColourRef, INT32 iWidth)
{
	CXaraFileRecord Rec(0);

	/***/ pExporter->WriteZeroSizedRecord(TAG_DOWN);

	SelectStroke(iColourRef, iWidth);

	Rec.Reinit(TAG_PATH_STROKED, TAG_PATH_SIZE);
	Rec.WriteUINT32(2);	 // two coordinates
	Rec.WriteBYTE(0x06); // moveto
	Rec.WriteBYTE(0x02); // lineno
	Rec.WriteCoord(DocCoord(x1, y1));
	Rec.WriteCoord(DocCoord(x2, y2));
	pExporter->WriteRecord(&Rec);

	/***/ pExporter->WriteZeroSizedRecord(TAG_UP);
}

void Generate()
{
	CXaraFileRecord Rec(0);

	// define red colour
	Rec.Reinit(TAG_DEFINERGBCOLOUR, TAG_DEFINERGBCOLOUR_SIZE);
	Rec.WriteBYTE(255);
	Rec.WriteBYTE(0);
	Rec.WriteBYTE(0);
	pExporter->WriteRecord(&Rec, &uiRedColourRef);

	// define blue colour
	Rec.Reinit(TAG_DEFINERGBCOLOUR, TAG_DEFINERGBCOLOUR_SIZE);
	Rec.WriteBYTE(0);
	Rec.WriteBYTE(0);
	Rec.WriteBYTE(255);
	pExporter->WriteRecord(&Rec, &uiBlueColourRef);

	pExporter->WriteZeroSizedRecord(TAG_GROUP);
	/***/ pExporter->WriteZeroSizedRecord(TAG_DOWN);

	DrawLine(CM2MIL(1.0), CM2MIL(1.0), CM2MIL(2.0), CM2MIL(3.0), uiRedColourRef, CM2MIL(0.1f));
	DrawLine(CM2MIL(1.0), CM2MIL(1.0), CM2MIL(2.0), CM2MIL(1.0), uiBlueColourRef, CM2MIL(0.1f));

	/***/ pExporter->WriteZeroSizedRecord(TAG_UP);
}

int main()
{
	pExporter = XarLibrary::CreateExporter();
	pExporter->StartExport();

	// Create a CXaraFileRecord object for the document header record
	CXaraFileRecord Rec(TAG_FILEHEADER);
	Rec.Init();
	Rec.WriteBuffer((BYTE*)"CXN", 3);
	Rec.WriteUINT32(123);			// File size
	Rec.WriteUINT32(0);				// Native/Web link ID
	Rec.WriteUINT32(0);				// Precompression flags
	Rec.WriteASCII(_T("xartest"));	// Producer
	Rec.WriteASCII(_T("0.1"));		// Producer version
	Rec.WriteASCII(_T(""));			// Producer build
	pExporter->WriteRecord(&Rec);

	// 10x10cm
	const INT32 iSize = (INT32)CM2MIL(10.0);
	pExporter->WriteZeroSizedRecord(TAG_SPREAD);
	Rec.Reinit(TAG_SPREADINFORMATION, TAG_SPREADINFORMATION_SIZE);
	Rec.WriteUINT32(iSize);       // width
	Rec.WriteUINT32(iSize);       // height
	Rec.WriteUINT32(10000);	   // margin
	Rec.WriteUINT32(0);		   // bleed
	Rec.WriteBYTE(2);			   // flags (shadow: on)
	pExporter->WriteRecord(&Rec);

	// Write a layer
	pExporter->WriteZeroSizedRecord(TAG_LAYER);
	pExporter->WriteZeroSizedRecord(TAG_DOWN);

	Rec.Reinit(TAG_LAYERDETAILS, -1);
	Rec.WriteBYTE(13);
	Rec.WriteUnicode(_T("Layer 1"));
	pExporter->WriteRecord(&Rec);

	Generate();

	// End of the layer
	pExporter->WriteZeroSizedRecord(TAG_UP);

	// Write the end of file record
	Rec.Reinit(TAG_ENDOFFILE, 0);
	pExporter->WriteZeroSizedRecord(TAG_ENDOFFILE);

	return 0;
}