📄 prntst.cpp
字号:
// PRNTST.CPP
//
// Copyright (c) 1997-2000 Symbian Ltd. All rights reserved.
#include "PRNTST.h"
////////////////////////////////////////////////////////////////////////////////
// The class CPRNTSTOpx, which is in the format required by opx
// will access COplPrintTestEngine which will do all the actual work
//////////////////////////////////////////////////////////////////////////////
COplPrintTestEngine::COplPrintTestEngine()
{
}
COplPrintTestEngine::~COplPrintTestEngine()
{
delete iParaFormatLayer;
delete iCharFormatLayer;
delete iRichText;
delete iParaFormat;
}
COplPrintTestEngine* COplPrintTestEngine::NewL(OplAPI& aOplAPI)
{
COplPrintTestEngine* This=new(ELeave) COplPrintTestEngine();
CleanupStack::PushL(This);
This->ConstructL(aOplAPI);
CleanupStack::Pop();
return This;
}
void COplPrintTestEngine::ConstructL(OplAPI& aOplAPI)
{
iInitialised = EFalse;
iDocumentChanged =ETrue;
iPaginateDialogCalled = EFalse;
iOplAPI = &aOplAPI;
iFormatChanged = EFalse;
_LIT(KArial,"Arial");
iFontName = KArial;
iFontHeight = 178;
iParaFormat = CParaFormat::NewL();
DefaultFormatting();
iParaFormatLayer = CParaFormatLayer::NewL();
iCharFormatLayer = CCharFormatLayer::NewL(iCharFormat,iCharFormatMask);
iRichText=CRichText::NewL(iParaFormatLayer,iCharFormatLayer);
}
void COplPrintTestEngine::ResetPrinting()
// Remove all content and formatting
{
iRichText->Reset();
iFormatChanged = ETrue;
DefaultFormatting();
}
void COplPrintTestEngine::DefaultFormatting()
// Reset the formatting
{
TCharFormat defaultCharFormat(iFontName,iFontHeight);
iCharFormat = defaultCharFormat;
iCharFormatMask.ClearAll();
iCharFormatMask.SetAttrib(EAttFontTypeface);
iCharFormatMask.SetAttrib(EAttFontHeight);
CFbsScreenDevice *device = CFbsScreenDevice::NewL(_L("scdv.dll"),EGray4);
iCharFormat.iFontSpec.iTypeface.SetAttributes(FontUtils::TypefaceAttributes(*device,iFontName));
delete device;
}
void COplPrintTestEngine::InsertStringL(const TDesC& aString, const TInt aPos, TTextInsertPosition aTIP)
// Insert a string at the given position if aTIP == EInsert. Append otherwise
{
TInt pos;
pos = SetInsertPositon(aPos, aTIP);
iDocumentChanged=ETrue;
if(iFormatChanged)
{
ResetFormatL(pos);
}
iRichText->InsertL(pos, aString);
}
void COplPrintTestEngine::SetFontNameL(const TDesC& aName)
{
iDocumentChanged=ETrue;
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontTypeface);
CFbsScreenDevice *device = CFbsScreenDevice::NewL(_L("scdv.dll"),EGray4);
iCharFormat.iFontSpec.iTypeface.SetAttributes(FontUtils::TypefaceAttributes(*device,aName));
iCharFormat.iFontSpec.iTypeface.iName = aName;
delete device;
}
void COplPrintTestEngine::SetFontHeight(const TInt16 aHeight)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontHeight);
iCharFormat.iFontSpec.iHeight = aHeight;
}
void COplPrintTestEngine::SetFontPosition(const TInt16 aPosition)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontPrintPos);
iCharFormat.iFontSpec.iFontStyle.SetPrintPosition((TFontPrintPosition)aPosition);
}
void COplPrintTestEngine::SetFontWeight(const TInt16 aWeight)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight((TFontStrokeWeight)aWeight);
}
void COplPrintTestEngine::SetFontPosture(const TInt16 aPosture)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontPosture);
iCharFormat.iFontSpec.iFontStyle.SetPosture((TFontPosture)aPosture);
}
void COplPrintTestEngine::SetFontStrikethrough(const TInt16 aStrikethrough)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontStrikethrough);
iCharFormat.iFontPresentation.iStrikethrough = (TFontStrikethrough)aStrikethrough;
}
void COplPrintTestEngine::SetFontUnderline(const TInt16 aUnderline)
{
iFormatChanged = ETrue;
iCharFormatMask.SetAttrib(EAttFontUnderline);
iCharFormat.iFontPresentation.iUnderline = (TFontUnderline)aUnderline;
}
void COplPrintTestEngine::ResetFormatL(const TInt aPos)
// If the format has been changed since insert was last called
// the this member is called to enter the new format at the insert position.
{
iRichText->CancelInsertCharFormat();
if (RemoveUnnessaryCharSettings(&iCharFormat,&iCharFormatMask,aPos))
iRichText->SetInsertCharFormatL(iCharFormat, iCharFormatMask, aPos);
iFormatChanged = EFalse;
}
TInt COplPrintTestEngine::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 COplPrintTestEngine::SetAlignmentL(CParaFormat::TAlignment aAlignment)
// Alignment can also be set with InitialiseParaFormatL.
{
iFormatChanged = ETrue;
iParaFormat->iHorizontalAlignment = aAlignment;
iParaFormatMask.SetAttrib(EAttAlignment); // interested in alignment
}
void COplPrintTestEngine::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 COplPrintTestEngine::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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -