Example #1
0
void RichQtfParser::TableFormat(bool bw)
{
	RichTable& tab = Table();
	RichTable::Format tabformat = tab.GetFormat();
	Tab& t = table.Top();
	int a, b;
	for(;;) {
		if(bw && IsDigit(*term)) {
			t.hspan = GetNumber();
		}
		else
		if(*term == '\0')
			Error("Unexpected end of text in cell format");
		else
		switch(*term++) {
		case ' ':
			tab.SetFormat(tabformat);
			return;
		case ';': break;
		case '<': tabformat.lm = ReadNumber(); break;
		case '>': tabformat.rm = ReadNumber(); break;
		case 'B': tabformat.before = ReadNumber(); break;
		case 'A': tabformat.after = ReadNumber(); break;
		case 'f': tabformat.frame = ReadNumber(); break;
		case '_':
		case 'F': tabformat.framecolor = GetColor(); break;
		case 'g': tabformat.grid = ReadNumber(); break;
		case 'G': tabformat.gridcolor = GetColor(); break;
		case 'h': tabformat.header = GetNumber(); break;
		case '~': tabformat.frame = tabformat.grid = 0; break;
		case '^': t.format.align = ALIGN_TOP; break;
		case '=': t.format.align = ALIGN_CENTER; break;
		case 'v': t.format.align = ALIGN_BOTTOM; break;
		case 'l': Number2(a, b); S(t.format.border.left, a); S(t.format.margin.left, b); break;
		case 'r': Number2(a, b); S(t.format.border.right, a); S(t.format.margin.right, b); break;
		case 't': Number2(a, b); S(t.format.border.top, a); S(t.format.margin.top, b); break;
		case 'b': Number2(a, b); S(t.format.border.bottom, a); S(t.format.margin.bottom, b); break;
		case 'H': t.format.minheight = ReadNumber(); break;
		case '@': t.format.color = GetColor(); break;
		case 'R': t.format.bordercolor = GetColor(); break;
		case '!': t.format = RichCell::Format(); break;
		case 'o': t.format.round = true; break;
		case 'k': t.format.keep = true; break;
		case 'K': tabformat.keep = true; break;
		case 'P': tabformat.newpage = true; break;
		case 'T':
			tabformat.newhdrftr = true;
			tabformat.header_qtf = GetText2('^', '^');
			tabformat.footer_qtf = GetText2('^', '^');
			break;
		case 'a':
			Number2(a, b);
			if(a >= 0)
				t.format.border.left = t.format.border.right = t.format.border.top = t.format.border.bottom = a;
			if(b >= 0)
				t.format.margin.left = t.format.margin.right = t.format.margin.top = t.format.margin.bottom = b;
			break; //!!cell all lines
		case '*':
			tabformat.frame = tabformat.grid =
			t.format.border.left = t.format.border.right = t.format.border.top = t.format.border.bottom =
			t.format.margin.left = t.format.margin.right = t.format.margin.top = t.format.margin.bottom = 0;
			break;
		case '-': t.hspan = GetNumber(); break;
		case '+':
		case '|': t.vspan = GetNumber(); break;
		default:
			Error("Invalid cell format");
		}
	}
}
Example #2
0
int CDatum::DefaultCompare (void *pCtx, const CDatum &dKey1, const CDatum &dKey2)

//	DefaultCompare
//
//	Default comparison routine used for sorting. Returns:
//
//	-1:		If dKey1 < dKey2
//	0:		If dKey1 == dKey2
//	1:		If dKey1 > dKey2
//
//	NOTES:
//
//	Nil == ""
//	Nil == {}
//	Nil == ()
//	"abc" != "ABC"

	{
	int i;

	//	If both are the same datatype, then compare

	CDatum::Types iType1 = dKey1.GetBasicType();
	CDatum::Types iType2 = dKey2.GetBasicType();

	//	If both types are equal, then compare

	if (iType1 == iType2)
		{
		switch (iType1)
			{
			case CDatum::typeNil:
			case CDatum::typeTrue:
				return 0;

			case CDatum::typeInteger32:
				if ((int)dKey1 > (int)dKey2)
					return 1;
				else if ((int)dKey1 < (int)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeInteger64:
				if ((DWORDLONG)dKey1 > (DWORDLONG)dKey2)
					return 1;
				else if ((DWORDLONG)dKey1 < (DWORDLONG)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeDouble:
				if ((double)dKey1 > (double)dKey2)
					return 1;
				else if ((double)dKey1 < (double)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeIntegerIP:
				return KeyCompare((const CIPInteger &)dKey1, (const CIPInteger &)dKey2);

			case CDatum::typeString:
				return KeyCompare((const CString &)dKey1, (const CString &)dKey2);

			case CDatum::typeDateTime:
				return ((const CDateTime &)dKey1).Compare((const CDateTime &)dKey2);

			case CDatum::typeArray:
				if (dKey1.GetCount() > dKey2.GetCount())
					return 1;
				else if (dKey1.GetCount() < dKey2.GetCount())
					return -1;
				else
					{
					for (i = 0; i < dKey1.GetCount(); i++)
						{
						CDatum dItem1 = dKey1.GetElement(i);
						CDatum dItem2 = dKey2.GetElement(i);
						int iItemCompare = CDatum::DefaultCompare(pCtx, dItem1, dItem2);
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			case CDatum::typeStruct:
				if (dKey1.GetCount() > dKey2.GetCount())
					return 1;
				else if (dKey1.GetCount() < dKey2.GetCount())
					return -1;
				else
					{
					for (i = 0; i < dKey1.GetCount(); i++)
						{
						CString sItemKey1 = dKey1.GetKey(i);
						CString sItemKey2 = dKey2.GetKey(i);
						int iKeyCompare = KeyCompare(sItemKey1, sItemKey2);
						if (iKeyCompare != 0)
							return iKeyCompare;

						CDatum dItem1 = dKey1.GetElement(i);
						CDatum dItem2 = dKey2.GetElement(i);
						int iItemCompare = CDatum::DefaultCompare(pCtx, dItem1, dItem2);
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			//	LATER: Not yet supported

			default:
				return 0;
			}
		}

	//	If one of the types is nil, then compare

	else if (iType1 == CDatum::typeNil || iType2 == CDatum::typeNil)
		{
		CDatum dNonNil;
		int iResult;
		if (iType2 == CDatum::typeNil)
			{
			dNonNil = dKey1;
			Swap(iType1, iType2);
			iResult = 1;
			}
		else
			{
			dNonNil = dKey2;
			iResult = -1;
			}

		switch (iType2)
			{
			case CDatum::typeString:
				if (((const CString &)dNonNil).IsEmpty())
					return 0;
				else
					return iResult;

			case CDatum::typeArray:
			case CDatum::typeStruct:
				if (dNonNil.GetCount() == 0)
					return 0;
				else
					return iResult;

			default:
				//	nil is always less
				return iResult;
			}
		}

	//	If one of the types is a number, then compare as numbers

	else if (dKey1.IsNumber() || dKey2.IsNumber())
		{
		CNumberValue Number1(dKey1);
		CNumberValue Number2(dKey2);

		if (Number1.IsValidNumber() && Number2.IsValidNumber())
			return Number1.Compare(Number2);
		else if (Number1.IsValidNumber())
			return 1;
		else if (Number2.IsValidNumber())
			return -1;
		else
			return 0;
		}

	//	Otherwise, cannot compare

	else
		return 0;
	}