// calculate an offset for the rectangle of the n-th page to // move the start point of the output operation to a position // such that in the output device all pages will be painted // at the same position
aPt.setX( -aPt.X() ); aPt.setY( -aPt.Y() );
void SwViewShell::InitPrt( OutputDevice *pOutDev )
{ // For printing we use a negative offset (exactly the offset of OutputSize). // This is necessary because the origin is in the upper left corner of the // physical page while the output uses OutputOffset as origin. if ( pOutDev )
{
maPrtOffset = Point();
// use given printer //! Make a copy of it since it gets destroyed with the temporary document //! used for PDF export if (pPrt)
rPrtDoc.getIDocumentDeviceAccess().setPrinter( VclPtr<SfxPrinter>::Create(*pPrt), true, true );
// get page descriptor - fall back to the first one if pPage could not be found const SwPageDesc* pPageDesc = pPage ? rPrtDoc.FindPageDesc(
pPage->GetPageDesc()->GetName() ) : &rPrtDoc.GetPageDesc( 0 );
if( !pFESh->IsTableMode() && pActCursor && pActCursor->HasMark() )
{ // Tweak paragraph attributes of last paragraph
SwNodeIndex aNodeIdx( *rPrtDoc.GetNodes().GetEndOfContent().StartOfSectionNode() );
SwTextNode* pTextNd = SwNodes::GoNext(&aNodeIdx)->GetTextNode();
SwContentNode *pLastNd =
(*pActCursor->GetMark()) <= (*pActCursor->GetPoint())
? pActCursor->GetPointContentNode()
: pActCursor->GetMarkContentNode(); // copy the paragraph attributes of the first paragraph if( pLastNd && pLastNd->IsTextNode() ) static_cast<SwTextNode*>(pLastNd)->CopyCollFormat( *pTextNd );
}
// fill it with the selected content
pFESh->Copy(rPrtDoc);
// set the page style at the first paragraph
{
SwNodeIndex aNodeIdx( *rPrtDoc.GetNodes().GetEndOfContent().StartOfSectionNode() );
SwContentNode* pCNd = SwNodes::GoNext(&aNodeIdx); // go to 1st ContentNode if( pFESh->IsTableMode() )
{
SwTableNode* pTNd = pCNd->FindTableNode(); if( pTNd )
pTNd->GetTable().GetFrameFormat()->SetFormatAttr( SwFormatPageDesc( pPageDesc ) );
} else
{
pCNd->SetAttr( SwFormatPageDesc( pPageDesc ) ); if( pFirstCursor && pFirstCursor->HasMark() )
{
SwTextNode *pTextNd = pCNd->GetTextNode(); if( pTextNd )
{
SwContentNode *pFirstNd =
(*pFirstCursor->GetMark()) > (*pFirstCursor->GetPoint())
? pFirstCursor->GetPointContentNode()
: pFirstCursor->GetMarkContentNode(); // copy paragraph attributes of the first paragraph if( pFirstNd && pFirstNd->IsTextNode() ) static_cast<SwTextNode*>(pFirstNd)->CopyCollFormat( *pTextNd );
}
}
}
}
}
// TODO: there is already a GetPageByPageNum, but it checks some physical page // number; unsure if we want that here, should find out what that is...
SwPageFrame const*
sw_getPage(SwRootFrame const& rLayout, sal_Int32 const nPage)
{ // yes this is O(n^2) but at least it does not crash...
SwPageFrame const* pPage = dynamic_cast<const SwPageFrame*>(rLayout.Lower()); for (sal_Int32 i = nPage; pPage && (i > 0); --i)
{ if (1 == i) { // note: nPage is 1-based, i.e. 0 is invalid! return pPage;
}
pPage = dynamic_cast<SwPageFrame const*>(pPage->GetNext());
}
OSL_ENSURE(pPage, "ERROR: SwPageFrame expected");
OSL_FAIL("non-existent page requested"); return nullptr;
}
namespace sw
{ // tdf#91680 Reserve space in margin for comments only if there are comments bool IsShrinkPageForPostIts(SwViewShell const& rShell, SwPrintData const& rPrintData)
{
SwPostItMode const nPostItMode(rPrintData.GetPrintPostIts()); return nPostItMode == SwPostItMode::InMargins
&& sw_GetPostIts(rShell.GetDoc()->getIDocumentFieldsAccess(), nullptr);
}
}
bool SwViewShell::PrintOrPDFExport(
OutputDevice *pOutDev,
SwPrintData const& rPrintData,
sal_Int32 nRenderer, /* the index in the vector of pages to be printed */ bool bIsPDFExport )
{ // CAUTION: Do also always update the printing routines in viewpg.cxx (PrintProspect)!
// Print/PDF export for (multi-)selection has already generated a // temporary document with the selected text. // (see XRenderable implementation in unotxdoc.cxx) // It is implemented this way because PDF export calls this Prt function // once per page and we do not like to always have the temporary document // to be created that often here.
std::unique_ptr<SwViewShell> pShell(new SwViewShell(*this, nullptr, pOutDev));
if (pPostItManager)
{
pPostItManager->CalcRects();
pPostItManager->LayoutPostIts();
pPostItManager->DrawNotesForPage(pOutDev, nPage-1);
oOrigHeight.emplace(pStPage->getFrameArea().Height());
}
}
pShell.reset();
// restore settings of OutputDevice (should be done always now since the // output device is now provided by a call from outside the Writer)
pOutDev->Pop();
// avoid a warning about unbalanced Push/Pop by doing this last: if (oOrigHeight)
{ // fdo#36815 Now scale the recorded page down so the comments in // margins will fit in the final page double fScale = 0.75;
tools::Long nNewHeight = *oOrigHeight*fScale;
tools::Long nShiftY = (*oOrigHeight-nNewHeight)/2;
GDIMetaFile *const pMetaFile = pOutDev->GetConnectMetaFile();
pMetaFile->ScaleActions(fScale, fScale); //Move the scaled page down to center it //the other variant of Move does not map pixels //back to the logical units correctly
pMetaFile->Move(0, convertTwipToMm100(nShiftY), pOutDev->GetDPIX(), pOutDev->GetDPIY());
}
returntrue;
}
void SwViewShell::PrtOle2( SwDoc *pDoc, const SwViewOption *pOpt, const SwPrintData& rOptions,
vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, bool bOutputForScreen )
{ // For printing a shell is needed. Either the Doc already has one, then we // create a new view, or it has none, then we create the first view.
std::unique_ptr<SwViewShell> pSh; if( pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
pSh.reset(new SwViewShell( *pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(), nullptr, &rRenderContext,VSHELLFLAG_SHARELAYOUT )); else
pSh.reset(new SwViewShell( *pDoc, nullptr, pOpt, &rRenderContext));
// CalcPagesForPrint() should not be necessary here. The pages in the // visible area will be formatted in SwRootFrame::PaintSwFrame(). // Removing this gives us a performance gain during saving the // document because the thumbnail creation will not trigger a complete // formatting of the document.
// OD 09.01.2003 #i6467# - method also called for page preview void SwViewShell::PrepareForPrint( const SwPrintData &rOptions, bool bIsPDFExport )
{
mpOpt->SetGraphic ( rOptions.m_bPrintGraphic );
mpOpt->SetDraw ( rOptions.m_bPrintGraphic );
mpOpt->SetControl ( rOptions.m_bPrintControl );
mpOpt->SetPageBack ( rOptions.m_bPrintPageBackground ); // Font should not be black if it's a PDF Export
mpOpt->SetBlackFont( rOptions.m_bPrintBlackFont && !bIsPDFExport );
if ( !HasDrawView() ) return;
SdrView *pDrawView = GetDrawView(); // OD 09.01.2003 #i6467# - consider, if view shell belongs to page preview if ( !IsPreview() )
{
pDrawView->SetLayerPrintable( u"Controls"_ustr, rOptions.m_bPrintControl );
} else
{
pDrawView->SetLayerVisible( u"Controls"_ustr, rOptions.m_bPrintControl );
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.