os/textandloc/fontservices/fontstore/tfs/FNTBODY_OLD.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/FNTBODY_OLD.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,347 @@
     1.4 +/*
     1.5 +* Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <s32file.h>
    1.23 +#include "FNTSTORE.H"
    1.24 +#include "FNTBODY_OLD.H"
    1.25 +#include <graphics/openfontconstants.h>
    1.26 +
    1.27 +TBitmapCodeSectionOld::TBitmapCodeSectionOld(RHeap* aHeap)
    1.28 + :	TCodeSection(),
    1.29 +	iHeap(aHeap),
    1.30 +	iOffsetsId(),
    1.31 +	iCharacterOffsetsListOffset(0),
    1.32 +	iBitmapId(),
    1.33 +	iBitmapOffset(0)
    1.34 +	{
    1.35 +	}
    1.36 +
    1.37 +void TBitmapCodeSectionOld::InternalizeL(RReadStream &aStream)
    1.38 +	{
    1.39 +	iStart = aStream.ReadUint16L();
    1.40 +	iEnd = aStream.ReadUint16L();
    1.41 +	aStream >> iOffsetsId;
    1.42 +	aStream >> iBitmapId; 
    1.43 +	}
    1.44 +
    1.45 +void TBitmapCodeSectionOld::RestoreComponentsL(const CStreamStore& aStreamStore)
    1.46 +	{
    1.47 +	if (iCharacterOffsetsListOffset == 0)
    1.48 +		{
    1.49 +		RStoreReadStream stream;
    1.50 +		stream.OpenLC(aStreamStore, iOffsetsId);
    1.51 +		InternalizeOffsetsL(stream);
    1.52 +		CleanupStack::PopAndDestroy();
    1.53 +		}
    1.54 +	if (iBitmapOffset == 0)
    1.55 +		{
    1.56 +		RStoreReadStream stream;
    1.57 +		stream.OpenLC(aStreamStore, iBitmapId);
    1.58 +		InternalizeBitmapL(stream);
    1.59 +		CleanupStack::PopAndDestroy();
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +void TBitmapCodeSectionOld::FixUpComponents(TInt aFileAddress)
    1.64 +	{
    1.65 +	TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*) (aFileAddress + sizeof(TInt) + iOffsetsId.Value());
    1.66 +	iCharacterOffsetsListOffset = TInt(characterOffsetsList);
    1.67 +	iOffsetsId = KNullStreamId;
    1.68 +	TUint8* bitmap = (TUint8*) (aFileAddress + sizeof(TInt) + iBitmapId.Value());
    1.69 +	iBitmapOffset = TInt(bitmap);
    1.70 +	}
    1.71 +
    1.72 +void TBitmapCodeSectionOld::DeleteComponents()
    1.73 +	{
    1.74 +	if (iCharacterOffsetsListOffset)
    1.75 +		{
    1.76 +		iHeap->Free(CharacterOffsetsList());
    1.77 +		iCharacterOffsetsListOffset = 0;
    1.78 +		}
    1.79 +	if (iBitmapOffset)
    1.80 +		{
    1.81 +		iHeap->Free(Bitmap());
    1.82 +		iBitmapOffset = 0;
    1.83 +		}
    1.84 +	}
    1.85 +
    1.86 +void TBitmapCodeSectionOld::operator delete(TAny *aThis)
    1.87 +	{
    1.88 +	if (((TBitmapCodeSectionOld *)aThis)->iHeap)
    1.89 +		{
    1.90 +		((TBitmapCodeSectionOld *)aThis)->iHeap->Free(aThis);
    1.91 +		}
    1.92 +	}
    1.93 +
    1.94 +void TBitmapCodeSectionOld::InternalizeOffsetsL(RReadStream &aStream)
    1.95 +	{
    1.96 +	TInt size = aStream.ReadInt32L();
    1.97 +	TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*)iHeap->AllocL(sizeof(TBitmapFontCharacterOffset) * size);
    1.98 +	iCharacterOffsetsListOffset = TInt(characterOffsetsList) - TInt(this);
    1.99 +	TBitmapFontCharacterOffset* pEnd = characterOffsetsList + size;
   1.100 +	for (TBitmapFontCharacterOffset* p = characterOffsetsList; p < pEnd; p++)
   1.101 +		{
   1.102 +		p->InternalizeL(aStream);
   1.103 +		}
   1.104 +	}
   1.105 +
   1.106 +void TBitmapCodeSectionOld::InternalizeBitmapL(RReadStream &aStream)
   1.107 +	{
   1.108 +	TInt size = aStream.ReadInt32L();
   1.109 +	TUint8* bitmap = (TUint8*)iHeap->AllocL(size);
   1.110 +	iBitmapOffset = TInt(bitmap) - TInt(this);
   1.111 +	aStream.ReadL(bitmap, size);
   1.112 +	}
   1.113 +
   1.114 +TBitmapFontCharacterOffset* TBitmapCodeSectionOld::CharacterOffsetsList() const
   1.115 +	{
   1.116 +	if (iOffsetsId == KNullStreamId)
   1.117 +		{
   1.118 +		return (TBitmapFontCharacterOffset*)iCharacterOffsetsListOffset;
   1.119 +		}
   1.120 +	TInt charOffsList = TInt(this) + iCharacterOffsetsListOffset;
   1.121 +	return (TBitmapFontCharacterOffset*)charOffsList;
   1.122 +	}
   1.123 +
   1.124 +TUint8* TBitmapCodeSectionOld::Bitmap() const
   1.125 +	{
   1.126 +	if (iOffsetsId == KNullStreamId)
   1.127 +		{
   1.128 +		return (TUint8*)iBitmapOffset;
   1.129 +		}
   1.130 +	TInt bitmap = TInt(this)+iBitmapOffset;
   1.131 +	return (TUint8*)bitmap;
   1.132 +	}
   1.133 +
   1.134 +CFontBitmapOld::CFontBitmapOld(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
   1.135 + :	iHeap(aHeap),
   1.136 +	iFontStoreFileOffset(0),
   1.137 +	iUid(KNullUid),
   1.138 +	iPosture(0),
   1.139 +	iStrokeWeight(0),
   1.140 +	iIsProportional(0),
   1.141 +	iIsInRAM(!aFontStoreFile->iFileAddress),
   1.142 +	iUsageCount(1),
   1.143 +	iCellHeightInPixels(0),
   1.144 +	iAscentInPixels(0),
   1.145 +	iMaxCharWidthInPixels(0),
   1.146 +	iMaxNormalCharWidthInPixels(0),
   1.147 +	iBitmapEncoding(0),
   1.148 +	iNumCodeSections(0),
   1.149 +	iCodeSectionListOffset(0),
   1.150 +	iCharacterMetricsTable(aHeap)
   1.151 +	{
   1.152 +	iFontStoreFileOffset = TInt(aFontStoreFile) - TInt(this);
   1.153 +	}
   1.154 +
   1.155 +void CFontBitmapOld::InternalizeL(RReadStream &aStream)
   1.156 +	{
   1.157 +	aStream >> iUid;
   1.158 +	iPosture = aStream.ReadInt8L();
   1.159 +	iStrokeWeight = aStream.ReadInt8L();
   1.160 +	iIsProportional = aStream.ReadInt8L();
   1.161 +	iCellHeightInPixels = aStream.ReadInt8L();
   1.162 +	iAscentInPixels = aStream.ReadInt8L();
   1.163 +	iMaxCharWidthInPixels = aStream.ReadInt8L();
   1.164 +	iMaxNormalCharWidthInPixels = aStream.ReadInt8L();
   1.165 +	iBitmapEncoding = aStream.ReadInt32L();
   1.166 +	iCharacterMetricsTable.InternalizeL(aStream);
   1.167 +	const TBool fixup = FontStoreFile()->iFileAddress;
   1.168 +	if (fixup)
   1.169 +		{
   1.170 +		iCharacterMetricsTable.FixUp(FontStoreFile()->iFileAddress);
   1.171 +		}
   1.172 +	iNumCodeSections = aStream.ReadInt32L();
   1.173 +	TBitmapCodeSectionOld* codesectionlist = (TBitmapCodeSectionOld*)User::LeaveIfNull(iHeap->AllocL(iNumCodeSections * sizeof(TBitmapCodeSectionOld)));
   1.174 +	iCodeSectionListOffset = TInt(codesectionlist) - TInt(this);
   1.175 +	for (TInt i = 0; i < iNumCodeSections; i++)
   1.176 +		{
   1.177 +		new(codesectionlist + i) TBitmapCodeSectionOld(iHeap);
   1.178 +		codesectionlist[i].InternalizeL(aStream);
   1.179 +		if (fixup)
   1.180 +			codesectionlist[i].FixUpComponents(FontStoreFile()->iFileAddress);
   1.181 +		}
   1.182 +	}
   1.183 +
   1.184 +void CFontBitmapOld::UseL()
   1.185 +	{
   1.186 +	iUsageCount++;
   1.187 +	if (iUsageCount == 2)
   1.188 +		RestoreComponentsL();
   1.189 +	}
   1.190 +
   1.191 +void CFontBitmapOld::Release()
   1.192 +	{
   1.193 +	iUsageCount--;
   1.194 +	if (!iUsageCount)
   1.195 +		{
   1.196 +		delete this;
   1.197 +		}
   1.198 +	}
   1.199 +
   1.200 +/*
   1.201 +Get the metrics for a given character.
   1.202 +Return aBytes as null if the character aCode doesn't exist in the font.
   1.203 +*/
   1.204 +TBitmapFontCharacterMetrics CFontBitmapOld::CharacterMetrics(TInt aCode, const TUint8*& aBytes) const
   1.205 +	{
   1.206 + 	const TBitmapCodeSectionOld* matchSection = NULL;
   1.207 +	const TBitmapCodeSectionOld* const lastSection = CodeSectionList() + iNumCodeSections - 1;
   1.208 +
   1.209 +	TBitmapFontCharacterOffset offset;
   1.210 +	aBytes = NULL;
   1.211 +
   1.212 +	TBitmapFontCharacterMetrics metrics;
   1.213 +	const TBitmapCodeSectionOld* startSearchBand = CodeSectionList();
   1.214 +	TInt numCodeSectionsRemaining = iNumCodeSections;
   1.215 +	while (numCodeSectionsRemaining >= 1)
   1.216 +		{
   1.217 +		TInt halfNumCodeSectionsRemaining = numCodeSectionsRemaining/2;
   1.218 +		const TBitmapCodeSectionOld* centralSearchBand = startSearchBand+halfNumCodeSectionsRemaining;
   1.219 +		if ((aCode >= centralSearchBand->iStart) && (aCode <= centralSearchBand->iEnd))
   1.220 +			{
   1.221 +			matchSection = centralSearchBand;
   1.222 +			break;
   1.223 +			}
   1.224 +		else if ((aCode < centralSearchBand->iStart) || (centralSearchBand == lastSection))
   1.225 +			numCodeSectionsRemaining = halfNumCodeSectionsRemaining;
   1.226 +		else
   1.227 +			{
   1.228 +			startSearchBand = centralSearchBand + 1;
   1.229 +			numCodeSectionsRemaining -= halfNumCodeSectionsRemaining + 1;
   1.230 +			}
   1.231 +		}
   1.232 +
   1.233 +	if (matchSection)
   1.234 +		{
   1.235 +		offset =* ((matchSection->CharacterOffsetsList()) + (aCode-matchSection->iStart));
   1.236 +
   1.237 +		// Fill characters within code section.
   1.238 +		// Recursive call ensures that a valid metric is always returned.
   1.239 +		if (offset.iBitmapOffset == KFillCharacterOffset)
   1.240 +			{
   1.241 +			return CharacterMetrics(KReplacementCharacter, aBytes);
   1.242 +			}
   1.243 +		
   1.244 +		aBytes = matchSection->Bitmap() + offset.iBitmapOffset;
   1.245 +		
   1.246 +		// retrieve metric index from encoded 1 or 2 bytes
   1.247 +		TInt index = 0;
   1.248 +		TUint8 byte1 = (TUint8)*aBytes;
   1.249 +		const TInt switchMask = 0x1;
   1.250 +		const TBool oneByteIndex =! (byte1 & switchMask);
   1.251 +		byte1 = TUint8(byte1 >> 1);
   1.252 +		if (oneByteIndex)
   1.253 +			{
   1.254 +			index = byte1;
   1.255 +			aBytes += 1;
   1.256 +			}
   1.257 +		else
   1.258 +			{
   1.259 +			const TUint8 byte2 = (TUint8)(*(aBytes + 1));
   1.260 +			index = byte1 + (byte2 * 128);
   1.261 +			aBytes += 2;
   1.262 +			}
   1.263 +		// Copy metric from table
   1.264 +		metrics =* iCharacterMetricsTable.Metric(index);
   1.265 +		}
   1.266 +	return metrics;
   1.267 +	}
   1.268 +
   1.269 +void CFontBitmapOld::operator delete(TAny *aThis)
   1.270 +	{
   1.271 +	if (((CFontBitmapOld *)aThis)->iHeap)
   1.272 +		{
   1.273 +		((CFontBitmapOld *)aThis)->iHeap->Free(aThis);
   1.274 +		}
   1.275 +	}
   1.276 +
   1.277 +void CFontBitmapOld::SetPosture(TFontPosture aPosture)
   1.278 +	{
   1.279 +	iPosture = (TInt8)aPosture;
   1.280 +	}
   1.281 +
   1.282 +TFontPosture CFontBitmapOld::Posture()
   1.283 +	{
   1.284 +	return (TFontPosture)iPosture;	 // iPosture is always smaller than TFontPosture
   1.285 +	}
   1.286 +
   1.287 +void CFontBitmapOld::SetStrokeWeight(TFontStrokeWeight aStrokeWeight)
   1.288 +	{
   1.289 +	iStrokeWeight = (TInt8)aStrokeWeight;
   1.290 +	}
   1.291 +
   1.292 +TFontStrokeWeight CFontBitmapOld::StrokeWeight()
   1.293 +	{
   1.294 +	return (TFontStrokeWeight)iStrokeWeight;
   1.295 +	}
   1.296 +
   1.297 +void CFontBitmapOld::SetIsProportional(TBool aIsProportional)
   1.298 +	{
   1.299 +	iIsProportional = (TInt8)aIsProportional;
   1.300 +	}
   1.301 +
   1.302 +TBool CFontBitmapOld::IsProportional()
   1.303 +	{
   1.304 +	return iIsProportional;
   1.305 +	}
   1.306 +
   1.307 +CFontStoreFile* CFontBitmapOld::FontStoreFile() const
   1.308 +	{
   1.309 +	TInt fsf = TInt(this) + iFontStoreFileOffset;
   1.310 +	return (CFontStoreFile*)fsf;
   1.311 +	}
   1.312 +
   1.313 +CFontBitmapOld::~CFontBitmapOld()
   1.314 +	{
   1.315 +	DeleteComponents();
   1.316 +	iHeap->Free(CodeSectionList());
   1.317 +	iCodeSectionListOffset = 0;
   1.318 +	}
   1.319 +
   1.320 +void CFontBitmapOld::RestoreComponentsL()
   1.321 +	{
   1.322 +	if (iIsInRAM)
   1.323 +		{
   1.324 +		CStreamStore& store =* FontStoreFile()->iFileStore;
   1.325 +		for (TInt i = 0; i < iNumCodeSections; i++)
   1.326 +			{
   1.327 +			CodeSectionList()[i].RestoreComponentsL(store);
   1.328 +			}
   1.329 +		iCharacterMetricsTable.RestoreL(store);
   1.330 +		}
   1.331 +	}
   1.332 +
   1.333 +void CFontBitmapOld::DeleteComponents()
   1.334 +	{
   1.335 +	if (iIsInRAM)
   1.336 +		{
   1.337 +		for (TInt i = 0; i < iNumCodeSections; i++)
   1.338 +			{
   1.339 +			CodeSectionList()[i].DeleteComponents();
   1.340 +			}
   1.341 +		iCharacterMetricsTable.Delete();
   1.342 +		}
   1.343 +	}
   1.344 +
   1.345 +TBitmapCodeSectionOld* CFontBitmapOld::CodeSectionList() const
   1.346 +	{
   1.347 +	TInt bcs = TInt(this) + iCodeSectionListOffset;
   1.348 +	return (TBitmapCodeSectionOld*)bcs;
   1.349 +	}
   1.350 +