/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
namespace { /** This incarnation of the ViewObjectContactRedirector filters away all PageObj objects, unconditionally.
*/ class ViewRedirector : public sdr::contact::ViewObjectContactRedirector
{ public:
ViewRedirector();
// Tell the view to show the given page.
SdPage* pNonConstPage = const_cast<SdPage*>(pPage); if (pPage->IsMasterPage())
{
mpView->ShowSdrPage(mpView->GetModel().GetMasterPage(pPage->GetPageNum()));
} else
{
mpView->ShowSdrPage(pNonConstPage);
}
// Make sure that a page view exists.
SdrPageView* pPageView = mpView->GetSdrPageView();
if (pPageView == nullptr) returnfalse;
// #i121224# No need to set SetApplicationBackgroundColor (which is the color // of the area 'behind' the page (formerly called 'Wiese') since the page previews // produced exactly cover the page's area, so it would never be visible. What // needs to be set is the ApplicationDocumentColor which is derived from // svtools::DOCCOLOR normally
Color aApplicationDocumentColor;
// Turn off online spelling and redlining.
SdrOutliner* pOutliner = nullptr;
EEControlBits nSavedControlWord = EEControlBits::NONE; if (mpDocShellOfView!=nullptr && mpDocShellOfView->GetDoc()!=nullptr)
{
pOutliner = &mpDocShellOfView->GetDoc()->GetDrawOutliner();
nSavedControlWord = pOutliner->GetControlWord();
pOutliner->SetControlWord(nSavedControlWord & ~EEControlBits::ONLINESPELLING);
}
// Use a special redirector to prevent PresObj shapes from being painted.
std::unique_ptr<ViewRedirector> pRedirector; if ( ! bDisplayPresentationObjects)
pRedirector.reset(new ViewRedirector());
// Restore the font.
mpPreviewDevice->SetFont (rOriginalFont);
}
void PreviewRenderer::PaintFrame()
{ if (mbHasFrame)
{ // Paint a frame around the preview.
::tools::Rectangle aPaintRectangle (
Point(0,0),
mpPreviewDevice->GetOutputSizePixel());
mpPreviewDevice->EnableMapMode(false);
mpPreviewDevice->SetLineColor(maFrameColor);
mpPreviewDevice->SetFillColor();
mpPreviewDevice->DrawRect(aPaintRectangle);
mpPreviewDevice->EnableMapMode();
}
}
void PreviewRenderer::SetupOutputSize ( const SdPage& rPage, const Size& rFramePixelSize)
{ // First set the map mode to some arbitrary scale that is numerically // stable.
MapMode aMapMode (mpPreviewDevice->GetMapMode());
aMapMode.SetMapUnit(MapUnit::MapPixel);
// Adapt it to the desired width. const Size aPageModelSize (rPage.GetSize()); if (!aPageModelSize.IsEmpty())
{ const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
aMapMode.SetScaleX(
Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width()));
aMapMode.SetScaleY(
Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height()));
aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode));
} else
{ // We should never get here.
OSL_ASSERT(false);
aMapMode.SetScaleX(Fraction(1.0));
aMapMode.SetScaleY(Fraction(1.0));
}
mpPreviewDevice->SetMapMode (aMapMode);
mpPreviewDevice->SetOutputSizePixel(rFramePixelSize);
}
void PreviewRenderer::ProvideView (DrawDocShell* pDocShell)
{ if (pDocShell != mpDocShellOfView)
{ // Destroy the view that is connected to the current doc shell.
mpView.reset();
// Switch our attention, i.e. listening for DYING events, to // the new doc shell. if (mpDocShellOfView != nullptr)
EndListening (*mpDocShellOfView);
mpDocShellOfView = pDocShell; if (mpDocShellOfView != nullptr)
StartListening (*mpDocShellOfView);
} if (mpView == nullptr)
{
mpView.reset (new DrawView (pDocShell, mpPreviewDevice.get(), nullptr));
}
mpView->SetPreviewRenderer(true);
mpView->SetPageVisible(false);
mpView->SetPageBorderVisible();
mpView->SetBordVisible(false);
mpView->SetGridVisible(false);
mpView->SetHlplVisible(false);
mpView->SetGlueVisible(false);
}
// Paint a frame around the preview.
mpPreviewDevice->SetLineColor (maFrameColor);
mpPreviewDevice->SetFillColor ();
mpPreviewDevice->DrawRect (::tools::Rectangle(Point(0,0), aFrameSize));
// Paint the bitmap scaled to the desired width.
BitmapEx aScaledBitmap(rBitmapEx);
aScaledBitmap.Scale (aPreviewSize, BmpScaleFlag::BestQuality);
mpPreviewDevice->DrawBitmapEx (
Point(1,1),
aPreviewSize,
aScaledBitmap);
// Get the resulting bitmap.
aPreview = Image(mpPreviewDevice->GetBitmapEx(Point(0,0), aFrameSize));
} while (false);
return aPreview;
}
void PreviewRenderer::Notify(SfxBroadcaster&, const SfxHint& rHint)
{ if (!mpDocShellOfView) return;
if (rHint.GetId() == SfxHintId::Dying)
{ // The doc shell is dying. Our view uses its item pool and // has to be destroyed as well. The next call to // ProvideView will create a new one (for another // doc shell, of course.)
mpView.reset();
mpDocShellOfView = nullptr;
}
}
if (pObject==nullptr || pObject->getSdrPageFromSdrObject() == nullptr)
{ // not a SdrObject visualisation (maybe e.g. page) or no page
sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
rOriginal,
rDisplayInfo,
rVisitor); return;
}
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.