Update contrib.
1 // Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 EXPORT_C CFbsDrvDevice::CFbsDrvDevice()
25 __DECLARE_NAME(_S("CFbsDrvDevice"));
28 EXPORT_C CFbsDrvDevice::~CFbsDrvDevice()
30 delete iFbsTypefaceStore;
31 delete iGenTypefaceFontsList;
32 delete iGenTypefaceFontsType;
35 /** Creates a font from those available in the printer device's
36 typeface store that most closely matches a font specification.
38 When the font is no longer needed, call ReleaseFont().
40 This function is replaced by GetNearestFontToDesignHeightInTwips()
42 @param aFont On return, points to the font which most closely matches the
44 @param aFontSpec An absolute font specification. Its iHeight member is
45 interpreted as being in twips.
46 @return KErrNone if successful; otherwise, another one of the system-wide error
49 EXPORT_C TInt CFbsDrvDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
51 return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
54 /** Creates a font from those available in the printer device's
55 typeface store that most closely matches a font specification.
57 When the font is no longer needed, call ReleaseFont().
59 This function replaces GetNearestFontInTwips()
61 @param aFont On return, points to the font which most closely matches the
63 @param aFontSpec An absolute font specification. Its iHeight member is
64 interpreted as being in twips.
65 @return KErrNone if successful; otherwise, another one of the system-wide error
67 EXPORT_C TInt CFbsDrvDevice::GetNearestFontToDesignHeightInTwips(CFont *&aFont, const TFontSpec &aFontSpec)
69 TRAPD(errCode, LoadTypeFaceListL());
70 if(errCode != KErrNone)
74 TInt count = iGenTypefaceFontsList->Count();
76 TTypefaceSupport support ; // holds typeface from iGenTypefaceFontsList
77 TTypeface typeface = aFontSpec.iTypeface; // holds typeface from aFontSpec
78 TBuf<KMaxTypefaceNameLength> support_name;
79 TBuf<KMaxTypefaceNameLength> typeface_name;
80 TBuf<KMaxTypefaceNameLength> aname;
81 typeface_name.Copy(typeface.iName);
85 TTypefaceSupport lsupport;
86 // Try to match specified font name with name from typeface font list
87 for (loop = 0; (loop < count) && (typeface.iName.CompareF(support.iTypeface.iName)); loop++)
89 TInt index = iGenTypefaceFontsList->At(loop);
90 TInt type = iGenTypefaceFontsType->At(loop);
93 iTypefaceStore->TypefaceSupport(support,index);
94 support_name.Copy(support.iTypeface.iName);
98 iFbsTypefaceStore->TypefaceSupport(support,index);
99 if(support.iIsScalable)
102 support_name.Copy(support.iTypeface.iName);
105 if (!typeface.iName.CompareF(support.iTypeface.iName))
107 typeface_name.Copy(support.iTypeface.iName);
114 if (loop <= iFbsTypefaceCount)
116 TFontSpec fontspec(aFontSpec);
117 fontspec.iTypeface=support.iTypeface;
118 return iFbsTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, fontspec);
120 else if (loop <= count)
122 TFontSpec fontspec(aFontSpec);
123 fontspec.iTypeface=support.iTypeface;
124 return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, fontspec);
129 if (!typeface.IsSymbol())
130 { // To match first non-symbol, serif, proportional
131 TypefaceSupport(lsupport, 0);
132 while ((listindex < count) && ((lsupport.iTypeface.IsSymbol() ||
133 (typeface.IsProportional() != lsupport.iTypeface.IsProportional()) ||
134 (typeface.IsSerif() != lsupport.iTypeface.IsSerif()))))
136 TypefaceSupport(lsupport, listindex);
137 aname.Copy(lsupport.iTypeface.iName);
140 if (listindex == count)
141 { // try to match first non-symbol.proportional
145 TypefaceSupport(lsupport, listindex);
146 aname.Copy(lsupport.iTypeface.iName);
149 while ((listindex < count) && (lsupport.iTypeface.IsSymbol() ||
150 (typeface.IsProportional() != lsupport.iTypeface.IsProportional())));
152 if (listindex == count)
153 { // try to match first non-symbol
157 TypefaceSupport(lsupport, listindex);
158 aname.Copy(lsupport.iTypeface.iName);
161 while ((listindex < count) && lsupport.iTypeface.IsSymbol());
165 { // try to match first symbol typeface
167 TypefaceSupport(lsupport, 0);
169 while ((listindex < count) && !lsupport.iTypeface.IsSymbol())
171 TypefaceSupport(lsupport, listindex);
172 aname.Copy(lsupport.iTypeface.iName);
176 if (listindex == count)
179 TypefaceSupport(lsupport, listindex);
183 if (listindex <= iFbsTypefaceCount)
185 TFontSpec fontspec(aFontSpec);
186 fontspec.iTypeface = lsupport.iTypeface;
187 TBuf<KMaxTypefaceNameLength> fontspec_name;
188 fontspec_name.Copy(fontspec.iTypeface.iName);
189 return iFbsTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, fontspec);
193 TFontSpec fontspec(aFontSpec);
194 fontspec.iTypeface = lsupport.iTypeface;
195 TBuf<KMaxTypefaceNameLength> fontspec_name;
196 fontspec_name.Copy(fontspec.iTypeface.iName);
197 return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, fontspec);
201 EXPORT_C void CFbsDrvDevice::ReleaseFont(CFont* aFont)
205 if (aFont->TypeUid() != KCFbsFontUid)
207 iTypefaceStore->ReleaseFont(aFont);
211 iFbsTypefaceStore->ReleaseFont(aFont);
216 EXPORT_C TInt CFbsDrvDevice::NumTypefaces() const
218 return iGenTypefaceFontsList->Count();
222 @deprecated Interface is deprecated because it is unsafe as it may leave. It is available for backward compatibility reasons only.
223 @see CFbsDrvDevice::LoadTypeFaceListL
226 EXPORT_C void CFbsDrvDevice::LoadTypeFaceList()
228 // Trap and Ignore the ERROR code as its a non-leaving method.
229 TRAP_IGNORE(LoadTypeFaceListL());
233 New Updated LoadTypeFaceList() method
237 EXPORT_C void CFbsDrvDevice::LoadTypeFaceListL()
239 iFbsTypefaceCount = 0;
240 iPdrTypefaceCount = 0;
241 if (iGenTypefaceFontsList)
242 iGenTypefaceFontsList->Reset();
244 iGenTypefaceFontsList = new (ELeave) CArrayFixFlat<TInt>(1);
246 if (iGenTypefaceFontsType)
247 iGenTypefaceFontsType->Reset();
249 iGenTypefaceFontsType = new (ELeave) CArrayFixFlat<TInt>(1);
252 for(loop = 0; loop < iFbsTypefaceStore->NumTypefaces(); loop++)
254 TTypefaceSupport support;
255 iFbsTypefaceStore->TypefaceSupport(support, loop);
257 if (support.iIsScalable)
259 iGenTypefaceFontsList->AppendL(loop);
260 iGenTypefaceFontsType->AppendL(1);
266 for (loop = 0; loop < iTypefaceStore->NumTypefaces(); loop++)
268 TTypefaceSupport support;
269 iTypefaceStore->TypefaceSupport(support, loop);
271 TBuf<KMaxTypefaceNameLength> name;
272 name.Copy(support.iTypeface.iName);
274 iGenTypefaceFontsList->AppendL(loop);
275 iGenTypefaceFontsType->AppendL(0);
280 EXPORT_C void CFbsDrvDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const
282 TInt index = iGenTypefaceFontsList->At(aTypefaceIndex);
283 TInt type = iGenTypefaceFontsType->At(aTypefaceIndex);
286 iTypefaceStore->TypefaceSupport(aTypefaceSupport, index);
288 iFbsTypefaceStore->TypefaceSupport(aTypefaceSupport, index);
291 EXPORT_C TInt CFbsDrvDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
293 TInt index = iGenTypefaceFontsList->At(aTypefaceIndex);
294 TInt type = iGenTypefaceFontsType->At(aTypefaceIndex);
297 return iTypefaceStore->FontHeightInTwips(index, aHeightIndex);
299 return iFbsTypefaceStore->FontHeightInTwips(index, aHeightIndex);
302 EXPORT_C TInt CFbsDrvDevice::CreateContext(CGraphicsContext*& aGc)
304 __ASSERT_DEBUG(iControl, Panic(EPdrControlDoesNotExist));
305 CPdrControl* control = (CPdrControl*)iControl;
306 return control->CreateContext(aGc);
309 EXPORT_C void CFbsDrvDevice::CreateControlL(CPrinterPort* aPrinterPort)
311 __ASSERT_ALWAYS(aPrinterPort, Panic(EPdrRequiresPrinterPort));
312 __ASSERT_ALWAYS(!iControl, Panic(EPdrControlAlreadyExists));
313 __ASSERT_DEBUG(iCurrentPageSpecInTwips.iPortraitPageSize.iWidth && iCurrentPageSpecInTwips.iPortraitPageSize.iHeight, Panic(EPdrPageSpecNotSet));
314 iControl = CFbsDrvControl::NewL(this, aPrinterPort, *iStore, iModelInfo->iResourcesStreamId);
318 @deprecated Interface is deprecated because it is unsafe as it may leave. It is available for backward compatibility reasons only.
319 @see CFbsDrvDevice::SetModelL
321 EXPORT_C TInt CFbsDrvDevice::SetModel(const TPrinterModelHeader& aModel, CStreamStore& aStore)
324 TRAPD(errCode, ret=SetModelL(aModel, aStore));
325 if(errCode != KErrNone)
332 EXPORT_C TInt CFbsDrvDevice::SetModelL(const TPrinterModelHeader& aModel, CStreamStore& aStore)
334 TInt ret = CPdrDevice::SetModel(aModel, aStore);
337 iFbsTypefaceStore = CFbsTypefaceStore::NewL(this);
343 EXPORT_C TSize CFbsDrvDevice::KPixelSizeInTwips() const
345 return TSize(iModelInfo->iKPixelWidthInTwips, iModelInfo->iKPixelHeightInTwips);
348 EXPORT_C void CFbsDrvDevice::Reserved_1()
352 EXPORT_C CFbsDrvControl* CFbsDrvControl::NewL(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort, CStreamStore& aStore, TStreamId aResourcesStreamId)
354 CFbsDrvControl* control = new(ELeave) CFbsDrvControl(aPdrDevice, aPrinterPort);
355 CleanupStack::PushL(control);
356 control->ConstructL(aStore, aResourcesStreamId);
361 EXPORT_C CFbsDrvControl::~CFbsDrvControl()
364 delete iCompressedScanLine;
367 EXPORT_C CFbsDrvControl::CFbsDrvControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort):
368 CPdrControl(aPdrDevice, aPrinterPort),
370 iCompressedScanLine(NULL)
372 __DECLARE_NAME(_S("CFbsDrvControl"));
375 EXPORT_C void CFbsDrvControl::ConstructL(CStreamStore& aStore, TStreamId aResourcesStreamId)
377 CPdrControl::ConstructL(aStore, aResourcesStreamId);
380 EXPORT_C void CFbsDrvControl::SetPageSizeL()
383 des.Format(iResources->ResourceString(EPdrSetPageSize), iPdrDevice->CurrentPageSpecInTwips().iPortraitPageSize.iHeight / KTwipsPerInch);
384 iPageBuffer->AddBytesL(des);
388 @return ETrue if there are non-blank bytes in scanline.
390 EXPORT_C TBool CFbsDrvControl::TransformBuffer()
393 for (i = iScanLine->Length() - 1; (i >= 0) && (iScanLine->Des()[i] == 0xFF); i--)
397 iScanLine->Des().SetLength(length);
398 TUint8* p = (TUint8*)iScanLine->Des().Ptr();
399 TUint8* pEnd = p + length;
400 for (; p < pEnd; p++)
404 for (TInt j = 0; j < 8; j++)
407 byte2 |= (byte1 & 1);
412 return (length > 0); // returns ETrue if there are non-blank bytes in scanline
416 @return ETrue if the scanline is compressed successfully.
418 EXPORT_C TBool CFbsDrvControl::CompressBuffer()
420 TInt length1 = iScanLine->Des().Length();
422 TUint8* p1 = (TUint8*)iScanLine->Des().Ptr();
423 TUint8* p2 = (TUint8*)iCompressedScanLine->Des().Ptr();
425 for (TInt i = 0; (i < length1) && (length2 < length1); i += repeat + 1)
427 TUint8 byte = *(p1++);
428 for (repeat = 0; ((i + repeat + 1) < length1) && (byte == *p1) && (repeat < 255);)
434 if (length2 < length1)
438 if (length2 < length1)
442 iCompressedScanLine->Des().SetLength(length2);
443 return (length2 < length1); // returns ETrue if the scanline is compressed successfully
447 This function is intentionally a dummy. It has to be implemented because
448 of an inherited pure virtual but it should always be overload by any class
449 that derives from it.
451 EXPORT_C void CFbsDrvControl::OutputBandL()
453 // I should probably put an assert in here.
454 if (IsGraphicsBand())
456 TRect bandrect = iBandedDevice->BandRect();
457 TSize size = bandrect.Size();
459 TBool datainband = EFalse;
460 TInt numscanlines = size.iHeight;
461 if (iBandedDevice->BandingDirection() == EBandingRightToLeft)
462 numscanlines = size.iWidth;
463 for (TInt i = 0; i < numscanlines; i++)
465 TInt x = bandrect.iTl.iX;
466 TInt y = bandrect.iTl.iY + i;
467 TPtr8 ptr = iScanLine->Des();
468 if (iBandedDevice->BandingDirection() == EBandingTopToBottom)
469 iBandedDevice->BandBitmap()->GetScanLine(ptr, TPoint(0, i), size.iWidth, iPdrDevice->DisplayMode());
472 iBandedDevice->BandBitmap()->GetVerticalScanLine(ptr, numscanlines - (i + 1), iPdrDevice->DisplayMode());
473 x = bandrect.iBr.iX - i;
476 if (TransformBuffer() && !datainband)
478 MoveToL(TPoint(x, y));
479 if (iBandedDevice->BandingDirection() == EBandingLeftToRight)
480 des.Format(iResources->ResourceString(EPdrBitmapStart), EFbsPhysicalPageOrientation);
482 des.Format(iResources->ResourceString(EPdrBitmapStart), EFbsLogicalPageOrientation);
483 iPageBuffer->AddBytesL(des);
488 TCommandString buf = iResources->ResourceString(EPdrScanLine);
489 if (CompressBuffer())
491 des.Format(buf, EFbsRunLength, iCompressedScanLine->Des().Length());
492 iPageBuffer->AddBytesL(des);
493 iPageBuffer->AddBytesL(iCompressedScanLine->Des());
497 des.Format(buf, EFbsNone, iScanLine->Des().Length());
498 iPageBuffer->AddBytesL(des);
499 iPageBuffer->AddBytesL(iScanLine->Des());
503 iPageBuffer->AddBytesL(iResources->ResourceString(EPdrBitmapEnd));
505 iPosition.iX = iPdrDevice->OffsetInPixels().iX;
506 TInt numentries = iPageText->NumEntries();
509 CPageTextEntry* entry;
510 for(TInt y = bandrect.iTl.iY; y <= bandrect.iBr.iY; y++)
512 for(TInt index = 0; (index < numentries); index++)
514 entry = (*iPageText)[index];
515 TPoint drawPos = entry->iDrawPos;
517 OutputTextL(drawPos, entry->iTextWidthInPixels, *(entry->iTextFormat), *(entry->iText)); //!!
524 EXPORT_C void CFbsDrvControl::Reserved_1()