📄 printer.cpp
字号:
void COplPrintEngine::InsertBitmapL(const TInt aPos,const TInt aHandle, TTextInsertPosition aTIP, TInt aXScale, TInt aYScale)
// Insert at the position if aTIP == EInsert, append otherwise
{
TInt pos;
pos = SetInsertPositon(aPos, aTIP);
iDocumentChanged=ETrue;
CPictureSimpleBitmap* p = CPictureSimpleBitmap::NewL(aHandle,DefaultDisplayMode());
p->SetScaleFactor(aXScale, aYScale);
TPictureHeader h;
h.iPicture = p;
iRichText->InsertL(pos, h);
}
TInt COplPrintEngine::NumberOfPagesInDoc()
{
if (iDocumentChanged)
RunPaginationDialogL();
return (iCharsPerPage->Count());
}
//
// This is from MPrintPreviewObserve
//
void COplPrintEngine::HandleEdwinEventL(CEikEdwin* ,TEdwinEvent)
{
}
TInt COplPrintEngine::SetInsertPositon(const TInt aPos, const TTextInsertPosition aTIP)
// Set the insert position, called by the InsertXXX members.
{
TInt last = iRichText->DocumentLength();
if(aTIP == EInsert)
{
if(aPos >= 0 && aPos <= last)
return aPos;
User::Leave(KOplErrInvalidArgs); // OPL error code
}
return(last);
}
void COplPrintEngine::SendRichTextToPrinterL(CRichText * aRichText)
// This replaces the content and formatting.
{
iFormatChanged = ETrue;
iRichText = aRichText;
iPrint->SetDocument(iRichText);
DefaultFormatting();
}
void COplPrintEngine::SetAlignmentL(CParaFormat::TAlignment aAlignment)
// Alignment can also be set with InitialiseParaFormatL.
{
iFormatChanged = ETrue;
iParaFormat->iHorizontalAlignment = aAlignment;
iParaFormatMask.SetAttrib(EAttAlignment); // interested in alignment
}
void COplPrintEngine::InitialiseParaFormatL(TInt16 aRed,
TInt16 aGreen,
TInt16 aBlue,
TInt32 aLeftMarginInTwips,
TInt32 aRightMarginInTwips,
TInt32 aIndentInTwips,
CParaFormat::TAlignment aHorizontalAlignment,
CParaFormat::TAlignment aVerticalAlignment,
TInt32 aLineSpacingInTwips,
CParaFormat::TLineSpacingControl aLineSpacingControl,
TInt32 aSpaceBeforeInTwips,
TInt32 aSpaceAfterInTwips,
TBool aKeepTogether,
TBool aKeepWithNext,
TBool aStartNewPage,
TBool aWidowOrphan,
TBool aWrap,
TInt32 aBorderMarginInTwips,
TUint32 aDefaultTabWidthInTwips
)
// Set the pargraph format. Has no immediate effect.
// Call Set[Local|Global]ParaFormat to apply formatting
{
iFormatChanged = ETrue;
iParaFormat->iFillColor = TRgb(aRed, aGreen, aBlue);
iParaFormatMask.SetAttrib(EAttFillColor);
iParaFormat->iLeftMarginInTwips = aLeftMarginInTwips;
iParaFormatMask.SetAttrib(EAttLeftMargin);
iParaFormat->iRightMarginInTwips = aRightMarginInTwips;
iParaFormatMask.SetAttrib(EAttRightMargin);
iParaFormat->iIndentInTwips = aIndentInTwips;
iParaFormatMask.SetAttrib(EAttIndent);
iParaFormat->iHorizontalAlignment = aHorizontalAlignment;
iParaFormatMask.SetAttrib(EAttAlignment);
iParaFormat->iVerticalAlignment = aVerticalAlignment;
iParaFormatMask.SetAttrib(EAttVerticalAlignment);
iParaFormat->iLineSpacingInTwips = aLineSpacingInTwips;
iParaFormatMask.SetAttrib(EAttLineSpacing);
iParaFormat->iLineSpacingControl = aLineSpacingControl;
iParaFormatMask.SetAttrib(EAttLineSpacingControl);
iParaFormat->iSpaceBeforeInTwips = aSpaceBeforeInTwips;
iParaFormatMask.SetAttrib(EAttSpaceBefore);
iParaFormat->iSpaceAfterInTwips = aSpaceAfterInTwips;
iParaFormatMask.SetAttrib(EAttSpaceAfter);
iParaFormat->iKeepTogether = aKeepTogether;
iParaFormatMask.SetAttrib(EAttKeepTogether);
iParaFormat->iKeepWithNext = aKeepWithNext;
iParaFormatMask.SetAttrib(EAttKeepWithNext);
iParaFormat->iStartNewPage = aStartNewPage;
iParaFormatMask.SetAttrib(EAttStartNewPage);
iParaFormat->iWidowOrphan = aWidowOrphan;
iParaFormatMask.SetAttrib(EAttWidowOrphan);
iParaFormat->iWrap = aWrap;
iParaFormatMask.SetAttrib(EAttWrap);
iParaFormat->iBorderMarginInTwips = aBorderMarginInTwips;
iParaFormatMask.SetAttrib(EAttBorderMargin);
iParaFormat->iDefaultTabWidthInTwips = aDefaultTabWidthInTwips;
iParaFormatMask.SetAttrib(EAttDefaultTabWidth);
}
void COplPrintEngine::SetLocalParaFormatL()
// Set the paragraph format created by InitialiseParaFormat or SetAlignment as the local paragraph format
{
iFormatChanged = ETrue;
TInt pos = iRichText->DocumentLength();
CParaFormat* paraFormat = CParaFormat::NewL();
TParaFormatMask paraFormatMask;
iRichText->GetParaFormatL(paraFormat, paraFormatMask, pos,0);
if(!(iParaFormat->IsEqual(*paraFormat, paraFormatMask) && paraFormatMask == iParaFormatMask))
{
if (RemoveUnnessaryParaSettings(iParaFormat,&iParaFormatMask,pos))
iRichText->ApplyParaFormatL(iParaFormat, iParaFormatMask, pos, 0);
}
delete paraFormat;
}
void COplPrintEngine::SetGlobalParaFormatL()
// Set the paragraph format created by InitialiseParaFormat or SetAlignment as the global paragraph format
{
iFormatChanged = ETrue;
CParaFormat* paraFormat = CParaFormat::NewL();
TParaFormatMask paraFormatMask;
iRichText->CGlobalText::GetParaFormatL(paraFormat, paraFormatMask, 0,0);
if(!(iParaFormat->IsEqual(*paraFormat, paraFormatMask) && paraFormatMask == iParaFormatMask))
iRichText->CGlobalText::ApplyParaFormatL(iParaFormat, iParaFormatMask, 0,0);
delete paraFormat;
}
void COplPrintEngine::RemoveSpecificParaFormatL()
// Get rid of the local paragraph format, so the global takes effect
{
iRichText->RemoveSpecificParaFormatL(iRichText->DocumentLength(),0);
}
void COplPrintEngine::SetGlobalCharFormatL()
// Set the current character format to be the global default
{
TCharFormatMask mask;
mask.SetAll();
iRichText->CGlobalText::ApplyCharFormatL(iCharFormat, mask, 0,0);
}
void COplPrintEngine::RemoveSpecificCharFormatL()
// Make the character format take on global attributes
{
const CCharFormatLayer *pLay = iRichText->GlobalCharFormatLayer();
iCharFormatMask.ClearAll();
pLay->Sense(iCharFormat,iCharFormatMask);
iFormatChanged = ETrue;
}
void COplPrintEngine::InsertSpecialCharacterL(TInt16 aSpecialChar, const TInt aPos, TTextInsertPosition aTIP)
// Insert a special character (as defined by CEditableText) at aPos if aTIP == EInsert. Append otherwise
{
iFormatChanged = ETrue;
TInt pos;
pos = SetInsertPositon(aPos, aTIP);
iRichText->InsertL(pos, aSpecialChar);
}
TInt COplPrintEngine::DocumentLength()
// Return number of chars (including special chars, bitmaps count as 1).
// This is called when appending characters for example
{
return iRichText->DocumentLength();
}
//
// The following 4 functions are based on ones by Gareth Richards.
// Some changes had to be made
//
TBool COplPrintEngine::RemoveUnnessaryParaSettings(const CParaFormat *pParaFormat,TParaFormatMask *pParaMask,long pos)
{
CParaFormat ParaFormat;
TParaFormatMask Mask;
if(pos != 0 )
{ // Make sure we get the Format for the previous position, but don't go -ve.
pos--;
}
TRAPD(res,iRichText->GetParaFormatL(&ParaFormat,Mask,pos,0));
if (res!=0)
return 0;
return RemoveUnnessaryParaSettings2(&ParaFormat,pParaFormat,pParaMask);
}
TBool COplPrintEngine::RemoveUnnessaryCharSettings(const TCharFormat *pCharFormat,TCharFormatMask *pCharMask,long Pos)
{
TCharFormat CharFormat;
TCharFormatMask Mask;
iRichText->GetCharFormat(CharFormat,Mask, Pos, 0);
return RemoveUnnessaryCharSettings2(&CharFormat,pCharFormat,pCharMask);
}
TBool COplPrintEngine::RemoveUnnessaryParaSettings2(const CParaFormat *pBaseParaFormat,const CParaFormat *pParaFormat,TParaFormatMask *pParaMask)
{
TParaFormatMask Mask;
TBool SetSomething=EFalse;
for (int ii=EAttParaLanguage; ii<EAttTabStop; ii++)
{
if (pParaMask->AttribIsSet((TTextFormatAttribute)ii))
{
Mask.ClearAll();
Mask.SetAttrib((TTextFormatAttribute)ii);
if (pParaFormat->IsEqual(*pBaseParaFormat,Mask))
pParaMask->ClearAttrib((TTextFormatAttribute)ii);
else
SetSomething=ETrue;
}
}
return SetSomething;
}
TBool COplPrintEngine::RemoveUnnessaryCharSettings2(const TCharFormat *pBaseCharFormat,const TCharFormat *pCharFormat,TCharFormatMask *pCharMask)
{
TCharFormatMask Mask;
TBool SetSomething=EFalse;
for (int ii=EAttCharLanguage; ii<ETextFormatAttributeCount; ii++)
{
if (pCharMask->AttribIsSet((TTextFormatAttribute)ii))
{
Mask.ClearAll();
Mask.SetAttrib((TTextFormatAttribute)ii);
if (pCharFormat->IsEqual(*pBaseCharFormat,Mask))
pCharMask->ClearAttrib((TTextFormatAttribute)ii);
else
SetSomething=ETrue;
}
}
return SetSomething;
}
//////////////////////////////////////////////////////////////////////////////////////////
// //
// CPRINTEROpx, a proxy class to provide a opx interface to COplPrintEngine //
// //
//////////////////////////////////////////////////////////////////////////////////////////
CPRINTEROpx::CPRINTEROpx(OplAPI& aOplAPI)
:COpxBase(aOplAPI)
{
}
CPRINTEROpx* CPRINTEROpx::NewL(OplAPI& aOplAPI)
{
CPRINTEROpx* This=new(ELeave) CPRINTEROpx(aOplAPI);
CleanupStack::PushL(This);
This->ConstructL();
CleanupStack::Pop();
return This;
}
void CPRINTEROpx::ConstructL()
{
iOplPrintEngine = COplPrintEngine::NewL(iOplAPI);
}
CPRINTEROpx::~CPRINTEROpx()
{
delete iOplPrintEngine;
Dll::FreeTls(); // Required so that Tls is set to zero on unloading the OPX in UNLOADM
}
//
// Get the function by ordinal.
//
void CPRINTEROpx::RunL(TInt aProcNum)
{
switch(aProcNum)
{
case ESendStringToPrinter:
SendStringToPrinterL();
break;
case EInsertString:
InsertStringL();
break;
case ESendNewParaToPrinter:
SendNewParaToPrinterL();
break;
case EInsertNewPara:
InsertNewParaL();
break;
case ESendSpecialCharToPrinter:
SendSpecialCharToPrinterL();
break;
case EInsertSpecialChar:
InsertSpecialCharL();
break;
case ESetAlignment:
SetAlignmentL();
break;
case EInitialiseParaFormat:
InitialiseParaFormatL();
break;
case ESetLocalParaFormat:
SetLocalParaFormatL();
break;
case ESetGlobalParaFormat:
SetGlobalParaFormatL();
break;
case ERemoveSpecificParaFormat:
RemoveSpecificParaFormatL();
break;
case ESetFontName:
SetFontNameL();
break;
case ESetFontHeight:
SetFontHeight();
break;
case ESetFontPosition:
SetFontPosition();
break;
case ESetFontWeight:
SetFontWeight();
break;
case ESetFontPosture:
SetFontPosture();
break;
case ESetFontStrikethrough:
SetFontStrikethrough();
break;
case ESetFontUnderline:
SetFontUnderline();
break;
case ESetGlobalCharFormat:
SetGlobalCharFormatL();
break;
case ERemoveSpecificCharFormat:
RemoveSpecificCharFormatL();
break;
case ESendBitmapToPrinter:
SendBitmapToPrinterL();
break;
case EInsertBitmap:
InsertBitmapL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -