Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <graphics/shapeimpl.h>
25 #include <graphics/shaperparams.h>
26 #include "linkedfonts.h"
27 #include "linkedfontsprivate.h"
28 #include "openfontsprivate.h"
30 #include <openfontlinkedtypefaceelementspec.h>
31 #include <graphics/openfontlinkedtypefacespecification.h>
33 EXPORT_C CLinkedTypefaceSpecification* CLinkedTypefaceSpecification::NewLC(const TDesC& aTypefaceName)
35 CLinkedTypefaceSpecification* self = new (ELeave) CLinkedTypefaceSpecification();
36 CleanupStack::PushL(self);
37 self->ConstructL(aTypefaceName);
41 CLinkedTypefaceSpecification::CLinkedTypefaceSpecification()
45 void CLinkedTypefaceSpecification::ConstructL(const TDesC &aTypefaceName)
47 iBody = new (ELeave) CLinkedTypefaceSpecificationBody();
49 TInt length = aTypefaceName.Length();
50 if ((length > KMaxTypefaceNameLength) || (length == 0))
51 User::Leave(KErrArgument);
53 iBody->iLinkedTypefaceName = aTypefaceName.AllocL();
56 EXPORT_C void CLinkedTypefaceSpecification::AddTypefaceAtIndexL(CLinkedTypefaceElementSpec& aElementSpec, TInt aIndex)
58 DoAddTypefaceL(aElementSpec, aIndex);
61 EXPORT_C void CLinkedTypefaceSpecification::AddTypefaceAtBackL(CLinkedTypefaceElementSpec& aElementSpec)
63 DoAddTypefaceL(aElementSpec, iBody->iTypefaces.Count());
66 EXPORT_C TInt CLinkedTypefaceSpecification::RemoveTypeface(TInt aIndex)
68 if ( (aIndex < iBody->iTypefaces.Count()) && (aIndex >= 0) )
70 CLinkedTypefaceElementSpec* elementSpec = iBody->iTypefaces[aIndex];
71 iBody->iTypefaces.Remove(aIndex);
79 EXPORT_C void CLinkedTypefaceSpecification::RegisterLinkedTypefaceL(CFbsTypefaceStore& aStore)
81 //Leave if there is no canonical element, or there are multiples.
82 //The remaining validation must be performed in fntstore.
83 User::LeaveIfError(CanonicalIndex());
84 User::LeaveIfError(aStore.RegisterLinkedTypeface(*this));
87 EXPORT_C void CLinkedTypefaceSpecification::FetchLinkedTypefaceSpecificationL(CFbsTypefaceStore& aStore)
89 aStore.GetLinkedTypefaceL(*this);
92 EXPORT_C TInt CLinkedTypefaceSpecification::TypefaceCount() const
94 return iBody->iTypefaces.Count();
97 EXPORT_C TPtrC CLinkedTypefaceSpecification::Name() const
99 return *iBody->iLinkedTypefaceName;
102 EXPORT_C CLinkedTypefaceSpecification::~CLinkedTypefaceSpecification()
107 EXPORT_C TInt CLinkedTypefaceSpecification::CanonicalIndex()
109 TInt index = KErrNotFound;
110 for (TInt i = iBody->iTypefaces.Count()-1 ; i >= 0; i--)
112 if (iBody->iTypefaces[i]->Canonical())
114 if (index == KErrNotFound)
123 EXPORT_C CLinkedTypefaceElementSpec* CLinkedTypefaceSpecification::Typeface(TInt aIndex) const
125 if ((aIndex >= iBody->iTypefaces.Count()) || (aIndex < 0))
131 return iBody->iTypefaces[aIndex];
135 void CLinkedTypefaceSpecification::DoAddTypefaceL(CLinkedTypefaceElementSpec& aElementSpec, TInt aPos)
137 if (iBody->iTypefaces.Count() == KMaxLinkedTypefaces)
138 User::Leave(KErrOverflow);
140 TInt err = iBody->iTypefaces.Find(&aElementSpec);
142 if (err != KErrNotFound)
143 User::Leave(KErrAlreadyExists);
145 if (aElementSpec.Canonical() && CanonicalIndex() != KErrNotFound)
146 User::Leave(KErrArgument);
148 if (GroupById(aElementSpec.GroupId()) == NULL)
149 User::Leave(KErrArgument);
151 err = iBody->iTypefaces.Insert(&aElementSpec, aPos);
153 User::LeaveIfError(err);
156 EXPORT_C void CLinkedTypefaceSpecification::AddLinkedTypefaceGroupL(CLinkedTypefaceGroup& aGroup)
158 if (iBody->iGroups.Count() == KMaxLinkedTypefaceGroups)
159 User::Leave(KErrOverflow);
161 for (TInt i = iBody->iGroups.Count()-1 ; i >= 0 ; i--)
163 if (iBody->iGroups[i]->GroupId() == aGroup.GroupId())
164 User::Leave(KErrAlreadyExists);
166 iBody->iGroups.AppendL(&aGroup);
169 EXPORT_C TInt CLinkedTypefaceSpecification::RemoveLinkedTypefaceGroup(TInt aGroupId)
171 //Search for & remove the group if it exists
172 CLinkedTypefaceGroup* remove = GroupById(aGroupId);
173 //If the group has been found & removed remove all associated typefaces
176 CLinkedTypefaceElementSpec* elementSpec;
177 for (TInt i = iBody->iTypefaces.Count()-1 ; i >= 0 ; i--)
179 elementSpec = iBody->iTypefaces[i];
180 if (elementSpec->GroupId() == aGroupId)
183 iBody->iGroups.Remove(iBody->iGroups.Find(remove));
190 EXPORT_C CLinkedTypefaceGroup* CLinkedTypefaceSpecification::GroupById(TInt aGroupId) const
193 TBool found = EFalse;
194 for (index = iBody->iGroups.Count()-1; index != -1 ; index--)
196 if (iBody->iGroups[index]->GroupId() == aGroupId)
204 return iBody->iGroups[index];
209 EXPORT_C CLinkedTypefaceGroup* CLinkedTypefaceSpecification::Group(TInt aGroupIndex) const
211 if ( (aGroupIndex >= 0) && (aGroupIndex < iBody->iGroups.Count()) )
212 return iBody->iGroups[aGroupIndex];
217 EXPORT_C TInt CLinkedTypefaceSpecification::GroupCount() const
219 return iBody->iGroups.Count();
222 EXPORT_C void CLinkedTypefaceSpecification::Clear()
224 iBody->iGroups.ResetAndDestroy();
225 iBody->iTypefaces.ResetAndDestroy();
228 EXPORT_C void CLinkedTypefaceSpecification::UpdateLinkedTypefaceL(CFbsTypefaceStore& aStore)
230 User::LeaveIfError(aStore.UpdateLinkedTypeface(*this));
233 CLinkedTypefaceSpecificationBody::CLinkedTypefaceSpecificationBody()
237 CLinkedTypefaceSpecificationBody::~CLinkedTypefaceSpecificationBody()
239 delete iLinkedTypefaceName;
240 iTypefaces.ResetAndDestroy();
241 iGroups.ResetAndDestroy();
244 EXPORT_C CLinkedTypefaceElementSpec* CLinkedTypefaceElementSpec::NewLC(const TDesC& aElementName, TInt aGroupId)
246 CLinkedTypefaceElementSpec* self = new(ELeave)CLinkedTypefaceElementSpec(aGroupId);
247 CleanupStack::PushL(self);
248 self->ConstructL(aElementName);
252 EXPORT_C CLinkedTypefaceElementSpec::~CLinkedTypefaceElementSpec()
257 EXPORT_C TPtrC CLinkedTypefaceElementSpec::ElementName() const
259 return *iElementName;
262 EXPORT_C void CLinkedTypefaceElementSpec::SetCanonical(TBool aIsCanonical)
264 iIsCanonical = aIsCanonical;
267 EXPORT_C TBool CLinkedTypefaceElementSpec::Canonical() const
272 CLinkedTypefaceElementSpec::CLinkedTypefaceElementSpec(TInt aGroupId)
275 iIsCanonical = EFalse;
278 EXPORT_C TInt CLinkedTypefaceElementSpec::GroupId() const
283 EXPORT_C COpenFontLinkedTypefaceSpecification* COpenFontLinkedTypefaceSpecification::NewLC(const TDesC& aTypefaceName)
285 COpenFontLinkedTypefaceSpecification* self = new (ELeave) COpenFontLinkedTypefaceSpecification();
286 CleanupStack::PushL(self);
287 self->ConstructL(aTypefaceName);
291 EXPORT_C COpenFontLinkedTypefaceSpecification* COpenFontLinkedTypefaceSpecification::NewLC(const TLinkedTypefaceSpecificationArgs& aSpecArgs)
293 COpenFontLinkedTypefaceSpecification* self = new (ELeave) COpenFontLinkedTypefaceSpecification();
294 CleanupStack::PushL(self);
295 self->ConstructL(aSpecArgs);
299 COpenFontLinkedTypefaceSpecification::COpenFontLinkedTypefaceSpecification()
303 void COpenFontLinkedTypefaceSpecification::ConstructL(const TDesC &aTypefaceName)
305 TInt length = aTypefaceName.Length();
306 if ((length > KMaxTypefaceNameLength) || (length == 0))
307 User::Leave(KErrArgument);
309 iLinkedTypefaceName = aTypefaceName.AllocL();
312 void COpenFontLinkedTypefaceSpecification::ConstructL(const TLinkedTypefaceSpecificationArgs& aSpecArgs)
314 iLinkedTypefaceName = aSpecArgs.iName.AllocL();
318 for (i = 0; i != aSpecArgs.iGroupSize ; i++)
320 CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(aSpecArgs.iGroups[i].iGroupId);
321 grp->SetBaselineShift(aSpecArgs.iGroups[i].iBaselineShift);
322 grp->SetBoldnessPercentage(aSpecArgs.iGroups[i].iBoldnessPercentage);
323 grp->SetItalicAngle(aSpecArgs.iGroups[i].iItalicAngle);
324 grp->SetScalingOption(aSpecArgs.iGroups[i].iScalingOption);
325 AddLinkedTypefaceGroupL(*grp);
326 CleanupStack::Pop(grp);
329 for (i = 0 ; i != aSpecArgs.iSize ; i++)
331 COpenFontLinkedTypefaceElementSpec* es = COpenFontLinkedTypefaceElementSpec::NewLC(aSpecArgs.iTypefaces[i].iName, aSpecArgs.iTypefaces[i].iGroupId);
332 es->SetCanonical(aSpecArgs.iTypefaces[i].iIsCanonical);
333 AddTypefaceAtBackL(*es);
334 CleanupStack::Pop(es);
337 //ASSERT Can. Indexs match.
340 EXPORT_C COpenFontLinkedTypefaceSpecification::~COpenFontLinkedTypefaceSpecification()
342 delete iLinkedTypefaceName;
343 iTypefaces.ResetAndDestroy();
345 iGroups.ResetAndDestroy();
349 EXPORT_C void COpenFontLinkedTypefaceSpecification::AddTypefaceAtIndexL(COpenFontLinkedTypefaceElementSpec& aElementSpec, TInt aIndex)
351 DoAddTypefaceL(aElementSpec, aIndex);
354 EXPORT_C void COpenFontLinkedTypefaceSpecification::AddTypefaceAtBackL(COpenFontLinkedTypefaceElementSpec& aElementSpec)
356 DoAddTypefaceL(aElementSpec, iTypefaces.Count());
359 EXPORT_C TInt COpenFontLinkedTypefaceSpecification::RemoveTypeface(TInt aIndex)
361 if ( (aIndex < iTypefaces.Count()) && (aIndex >= 0) )
363 COpenFontLinkedTypefaceElementSpec* elementSpec = iTypefaces[aIndex];
364 iTypefaces.Remove(aIndex);
373 EXPORT_C TInt COpenFontLinkedTypefaceSpecification::TypefaceCount() const
375 return iTypefaces.Count();
378 EXPORT_C TPtrC COpenFontLinkedTypefaceSpecification::Name() const
380 return *iLinkedTypefaceName;
383 EXPORT_C TInt COpenFontLinkedTypefaceSpecification::CanonicalIndex() const
385 TInt index = KErrNotFound;
386 for (TInt i = iTypefaces.Count()-1 ; i >= 0; i--)
388 if (iTypefaces[i]->Canonical())
390 if (index == KErrNotFound)
399 EXPORT_C COpenFontLinkedTypefaceElementSpec* COpenFontLinkedTypefaceSpecification::Typeface(TInt aIndex) const
401 if ((aIndex >= iTypefaces.Count()) || (aIndex < 0))
407 return iTypefaces[aIndex];
411 void COpenFontLinkedTypefaceSpecification::DoAddTypefaceL(COpenFontLinkedTypefaceElementSpec& aElementSpec, TInt aPos)
413 if (iTypefaces.Count() == KMaxLinkedTypefaces)
414 User::Leave(KErrOverflow);
416 TInt err = iTypefaces.Find(&aElementSpec);
418 if (err != KErrNotFound)
419 User::Leave(KErrAlreadyExists);
421 if (aElementSpec.Canonical() && CanonicalIndex() >= 0)
422 User::Leave(KErrArgument);
424 if (GroupById(aElementSpec.GroupId()) == NULL)
425 User::Leave(KErrArgument);
427 err = iTypefaces.Insert(&aElementSpec, aPos);
429 User::LeaveIfError(err);
432 EXPORT_C void COpenFontLinkedTypefaceSpecification::AddLinkedTypefaceGroupL(CLinkedTypefaceGroup& aGroup)
434 if (iGroups.Count() == KMaxLinkedTypefaceGroups)
435 User::Leave(KErrOverflow);
437 for (TInt i = iGroups.Count()-1 ; i >= 0 ; i--)
439 if (iGroups[i]->GroupId() == aGroup.GroupId())
440 User::Leave(KErrAlreadyExists);
442 iGroups.AppendL(&aGroup);
445 EXPORT_C TInt COpenFontLinkedTypefaceSpecification::RemoveLinkedTypefaceGroup(TInt aGroupId)
447 //Search for & remove the group if it exists
448 CLinkedTypefaceGroup* remove = GroupById(aGroupId);
449 //If the group has been found & removed remove all associated typefaces
452 COpenFontLinkedTypefaceElementSpec* elementSpec;
453 for (TInt i = iTypefaces.Count()-1 ; i >= 0 ; i--)
455 elementSpec = iTypefaces[i];
456 if (elementSpec->GroupId() == aGroupId)
459 iGroups.Remove(iGroups.Find(remove));
466 EXPORT_C CLinkedTypefaceGroup* COpenFontLinkedTypefaceSpecification::GroupById(TInt aGroupId) const
469 TBool found = EFalse;
470 for (index = iGroups.Count()-1; index != -1 ; index--)
472 if (iGroups[index]->GroupId() == aGroupId)
480 return iGroups[index];
485 EXPORT_C const CLinkedTypefaceGroup* COpenFontLinkedTypefaceSpecification::Group(TInt aGroupIndex) const
487 if ( (aGroupIndex >= 0) && (aGroupIndex < iGroups.Count()) )
488 return iGroups[aGroupIndex];
493 EXPORT_C TInt COpenFontLinkedTypefaceSpecification::GroupCount() const
495 return iGroups.Count();
498 COpenFontLinkedTypefaceSpecificationBody::COpenFontLinkedTypefaceSpecificationBody()
503 COpenFontLinkedTypefaceSpecificationBody::~COpenFontLinkedTypefaceSpecificationBody()
505 delete iLinkedTypefaceName;
509 EXPORT_C COpenFontLinkedTypefaceElementSpec* COpenFontLinkedTypefaceElementSpec::NewLC(const TDesC& aElementName, TInt aGroupId)
511 COpenFontLinkedTypefaceElementSpec* self = new(ELeave)COpenFontLinkedTypefaceElementSpec(aGroupId);
512 CleanupStack::PushL(self);
513 self->ConstructL(aElementName);
517 EXPORT_C COpenFontLinkedTypefaceElementSpec::~COpenFontLinkedTypefaceElementSpec()
523 EXPORT_C TPtrC COpenFontLinkedTypefaceElementSpec::ElementName() const
525 return *iElementName;
528 EXPORT_C void COpenFontLinkedTypefaceElementSpec::SetCanonical(TBool aIsCanonical)
530 iIsCanonical = aIsCanonical;
533 EXPORT_C TBool COpenFontLinkedTypefaceElementSpec::Canonical() const
538 EXPORT_C TInt COpenFontLinkedTypefaceElementSpec::GroupId() const
543 EXPORT_C TPtrC COpenFontLinkedTypefaceElementSpec::FileName() const
548 EXPORT_C void COpenFontLinkedTypefaceElementSpec::SetFileNameL(const TDesC& aFileName)
550 iFileName = aFileName.AllocL();
553 COpenFontLinkedTypefaceElementSpec::COpenFontLinkedTypefaceElementSpec(TInt aGroupId)
558 void COpenFontLinkedTypefaceElementSpec::ConstructL(const TDesC& aName)
560 TInt length = aName.Length();
561 if ((length == 0) || (length > KMaxTypefaceNameLength))
562 User::Leave(KErrArgument);
563 iElementName = aName.AllocL();
566 void CLinkedTypefaceElementSpec::ConstructL(const TDesC& aName)
568 TInt length = aName.Length();
569 if ((length == 0) || (length > KMaxTypefaceNameLength))
570 User::Leave(KErrArgument);
571 iElementName = aName.AllocL();
574 EXPORT_C CLinkedTypefaceGroup* CLinkedTypefaceGroup::NewLC(TInt aGroupId)
576 CLinkedTypefaceGroup* self = new (ELeave) CLinkedTypefaceGroup(aGroupId);
577 CleanupStack::PushL(self);
581 CLinkedTypefaceGroup::CLinkedTypefaceGroup(TInt aGroupId)
584 iScalingOption = EScalingNone;
585 iBaselineShift = ENoBaselineShift;
586 iBoldnessPercentage = -1;
590 CLinkedTypefaceGroup::~CLinkedTypefaceGroup()
594 EXPORT_C void CLinkedTypefaceGroup::SetScalingOption(CLinkedTypefaceGroup::TScalingOption aOption)
596 iScalingOption = aOption;
599 EXPORT_C CLinkedTypefaceGroup::TScalingOption CLinkedTypefaceGroup::ScalingOption() const
601 return iScalingOption;
604 EXPORT_C void CLinkedTypefaceGroup::SetBaselineShift(CLinkedTypefaceGroup::TBaselineShift aShift)
606 iBaselineShift = aShift;
609 EXPORT_C CLinkedTypefaceGroup::TBaselineShift CLinkedTypefaceGroup::BaselineShift() const
611 return iBaselineShift;
614 EXPORT_C void CLinkedTypefaceGroup::SetBoldnessPercentage(TInt aPercentage)
616 iBoldnessPercentage = aPercentage;
619 EXPORT_C TInt CLinkedTypefaceGroup::BoldnessPercentage() const
621 return iBoldnessPercentage;
624 EXPORT_C TInt CLinkedTypefaceGroup::GroupId() const
629 EXPORT_C TInt CLinkedTypefaceGroup::ItalicAngle() const
634 EXPORT_C void CLinkedTypefaceGroup::SetItalicAngle(TInt aAngle)
636 iItalicAngle = aAngle;
639 EXPORT_C void TLinkedTypefaceSpecificationArgs::operator =(const CLinkedTypefaceSpecification& aRhs)
641 iSize = aRhs.TypefaceCount();
642 iGroupSize = aRhs.GroupCount();
646 for (i = 0 ; i != iSize ; i++)
647 iTypefaces[i] = aRhs.Typeface(i);
649 for (i = 0 ; i != iGroupSize ; i++)
650 iGroups[i] = aRhs.Group(i);
653 EXPORT_C void TLinkedTypefaceSpecificationArgs::operator =(const COpenFontLinkedTypefaceSpecification &aRhs)
655 iSize = aRhs.TypefaceCount();
656 iGroupSize = aRhs.GroupCount();
660 for (i = 0 ; i != iSize ; i++)
661 iTypefaces[i] = aRhs.Typeface(i);
663 for (i = 0 ; i != iGroupSize ; i++)
664 iGroups[i] = aRhs.Group(i);
667 void TLinkedTypefaceElementSpecArgs::operator = (const CLinkedTypefaceElementSpec* aRhs)
669 iIsCanonical = aRhs->Canonical();
670 iGroupId = aRhs->GroupId();
671 iName = aRhs->ElementName();
674 void TLinkedTypefaceElementSpecArgs::operator = (const COpenFontLinkedTypefaceElementSpec* aRhs)
676 iIsCanonical = aRhs->Canonical();
677 iGroupId = aRhs->GroupId();
678 iName = aRhs->ElementName();
681 void TLinkedTypefaceGroupArgs::operator =(const CLinkedTypefaceGroup* aRhs)
683 iGroupId = aRhs->GroupId();
684 iScalingOption = aRhs->ScalingOption();
685 iBaselineShift = aRhs->BaselineShift();
686 iBoldnessPercentage = aRhs->BoldnessPercentage();
687 iItalicAngle = aRhs->ItalicAngle();