graphicstools/bitmapfonttools/src/STRNG.CPP
author William Roberts <williamr@symbian.org>
Thu, 03 Jun 2010 17:39:46 +0100
branchNewGraphicsArchitecture
changeset 87 0709f76d91e5
parent 0 5d03bc08d59c
permissions -rw-r--r--
Add MMP files to build libOpenVG_sw.lib which uses LINKAS to redirect to libOpenVG.dll (and the same for libEGL_sw.lib and libOpenVGU_sw.lib). Only the libEGL_sw.lib redirection isn't activated - this can't happen until there is a merged libEGL.dll which supports the OpenWF synchronisation and also implements the graphical support functions. The overall aim is to eliminate the *_sw.dll implementations, at least as a compile-time way of choosing a software-only implementation.The correct way to choose is to put the right set of libraries into a ROM with suitable renaming, and in the emulator to use the "switching DLL" technique to pick the right set. As the Symbian Foundation doesn't have any alternative implementations, we don't need the switching DLLs and we can build directly to the correct name.

/*
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
* Header STRNG.CPP
*
*/


#include "STRNG.H"

extern bool OutputUnicode;

ostream& operator << (ostream& out, const String& aString)
	{
	for (int i = 0; i < aString.iLength; i++)
		out << aString.iText[i];
	out << '\n';
	return out;
	}

EXPORT_C void String::Externalize(ostream& out)
	{
	if (OutputUnicode)
		{
		// Convert the string to Unicode, allowing #NNNN (each N is a hex digit)
		// to represent an arbitrary Unicode character. Other values are just
		// extended, so don't use codepage 1252 values in the range 128..159.
		unsigned short* buffer = new unsigned short[iLength];
		int i = 0;
		int j = 0;
		while (i < iLength)
			{
			if (iText[i] == '#')
				{
				i++;
				char hex[5];
				hex[0] = iText[i++];
				hex[1] = iText[i++];
				hex[2] = iText[i++];
				hex[3] = iText[i++];
				hex[4] = 0;
				buffer[j++] = (unsigned short)strtoul(hex, NULL, 16);
				}
			else
				{
				buffer[j] = iText[i];
				buffer[j] &= 0xFF;
				i++;
				j++;
				}
			}
		int unicode_characters = j;
		int32 length = (unicode_characters << 1);	// 16-bit data
		if (length < 0x80)
			{
			unsigned char len = (unsigned char)(length << 1);
			out.write((char*)&len, sizeof(len));
			}
		else if (length < 0x4000)
			{
			uint16 len = (uint16)((length << 2) + 1);
			out.write((char*)&len, sizeof(len));
			}
		else
			{
			// assert len<0x20000000 ?
			uint32 len = (uint32)((length << 3) + 3);
			out.write((char*)&len, sizeof(len));
			}
		// Output Unicode characters using the Standard Compression Scheme for Unicode.
		// To save the bother of doing this properly, use a degenerate form whereby each
		// Unicode character is output as itself. 0x0F selects Unicode mode and 0xF0 quotes
		// characters that would conflict with other tags.
		out << (unsigned char)0x0F;

		for (i = 0; i < unicode_characters; i++)
			{
			unsigned char hi = (unsigned char)(buffer[i] >> 8);
			unsigned char lo = (unsigned char)buffer[i];
			if ((hi >= 0xe0) && (hi <= 0xf2))
				out << 0xf0;
			out << hi;
			out << lo;
			}

		delete [] buffer;
		}
	else
		{
		int32 length = (iLength << 1) + 1;	// 8-bit data
		if (length < 0x80)
			{
			unsigned char len = (unsigned char)(length << 1);
			out.write((char*)&len, sizeof(len));
			}
		else if (length < 0x4000)
			{
			uint16 len = (uint16)((length << 2) + 1);
			out.write((char*)&len, sizeof(len));
			}
		else
			{
			// assert len<0x20000000 ?
			uint32 len = (uint32)((length << 3) + 3);
			out.write((char*)&len, sizeof(len));
			}
		out.write(iText, iLength);
		}
	}

EXPORT_C int String::CreateText(const int aLength)
	{
	if (aLength != iLength)
		{
		char* text = new char[aLength + 1];
		if (text)
			{
			iLength = aLength;
			iText = text;
			}
		else
			{
			iLength = 0;
			delete [] iText;
			iText = NULL;
			}
		}
	return iLength;
	}

EXPORT_C void String::DeleteText(char* aText) const
	{
	if (aText != iText)
		delete [] aText;
	}

EXPORT_C String::~String()
	{
	delete [] iText;
	}