13#include <com/sun/star/beans/XPropertySet.hpp>
14#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
15#include <com/sun/star/drawing/LineStyle.hpp>
16#include <com/sun/star/lang/XMultiServiceFactory.hpp>
17#include <com/sun/star/graphic/XGraphic.hpp>
18#include <com/sun/star/frame/XLayoutManager.hpp>
21#include <com/sun/star/style/XStyle.hpp>
22#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23#include <com/sun/star/text/XPageCursor.hpp>
24#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
25#include <com/sun/star/sheet/XSpreadsheetView.hpp>
29#include <com/sun/star/util/SearchAlgorithms.hpp>
30#include <com/sun/star/util/SearchAlgorithms2.hpp>
31#include <com/sun/star/util/SearchFlags.hpp>
38#include <sfx2/sfxsids.hrc>
70 if (pIsRedactMode && pIsRedactMode->
GetValue())
79 OUString sStringParam;
89 sStringParam = pStringArg->
GetValue();
115void setPageMargins(
const uno::Reference<beans::XPropertySet>& xPageProperySet,
118 if (aPageMargins.
nTop < 0 || aPageMargins.
nBottom < 0 || aPageMargins.
nLeft < 0
119 || aPageMargins.
nRight < 0)
122 xPageProperySet->setPropertyValue(
"BorderTop", css::uno::Any(aPageMargins.
nTop));
123 xPageProperySet->setPropertyValue(
"BorderBottom", css::uno::Any(aPageMargins.
nBottom));
124 xPageProperySet->setPropertyValue(
"BorderLeft", css::uno::Any(aPageMargins.
nLeft));
125 xPageProperySet->setPropertyValue(
"BorderRight", css::uno::Any(aPageMargins.
nRight));
130 sal_Int32 nStrStartPos, sal_Int32 nStrEndPos)
136 case MetaActionType::TEXTARRAY:
141 if (!aString.isEmpty())
144 std::unique_ptr<SalLayout> pSalLayout1 = rOut.
ImplLayout(
146 std::unique_ptr<SalLayout> pSalLayout2 = rOut.
ImplLayout(
153 if (pSalLayout1 && nStrStartPos > 0)
172 return aActionBounds;
175 return aActionBounds;
181 std::vector<::Size>& aPageSizes, sal_Int32 nPages,
184 for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage)
189 ::Size aCalcPageContentSize;
191 &aCalcPageContentSize);
193 aPageSizes.push_back(aLogic);
204 rGDIMetaFile.SetPrefMapMode(aMapMode);
205 rGDIMetaFile.SetPrefSize(aLogic);
207 fixMetaFile(rGDIMetaFile);
209 aMetaFiles.push_back(rGDIMetaFile);
214 const uno::Reference<XComponent>& xComponent, sal_Int32 nPages,
215 const std::vector<GDIMetaFile>& aMetaFiles,
const std::vector<::Size>& aPageSizes,
217 const std::vector<std::pair<RedactionTarget, OUString>>& r_aTableTargets,
bool bIsAutoRedact)
220 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
221 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
223 uno::Reference<css::lang::XMultiServiceFactory>
xFactory(xComponent, uno::UNO_QUERY);
225 for (sal_Int32 nPage = 0; nPage < nPages; ++nPage)
228 Graphic aGraphic(rGDIMetaFile);
230 sal_Int32 nPageHeight(aPageSizes[nPage].
Height());
231 sal_Int32 nPageWidth(aPageSizes[nPage].
Width());
233 uno::Reference<graphic::XGraphic> xGraph = aGraphic.
GetXGraphic();
234 uno::Reference<drawing::XDrawPage> xPage = xDrawPages->insertNewByIndex(nPage);
237 uno::Reference<beans::XPropertySet> xPageProperySet(xPage, uno::UNO_QUERY);
238 xPageProperySet->setPropertyValue(
"Height", css::uno::Any(nPageHeight));
239 xPageProperySet->setPropertyValue(
"Width", css::uno::Any(nPageWidth));
241 setPageMargins(xPageProperySet, aPageMargins);
244 uno::Reference<drawing::XShape> xShape(
245 xFactory->createInstance(
"com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
246 uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
247 xShapeProperySet->setPropertyValue(
"Graphic",
uno::Any(xGraph));
248 xShapeProperySet->setPropertyValue(
"MoveProtect",
uno::Any(
true));
249 xShapeProperySet->setPropertyValue(
"SizeProtect",
uno::Any(
true));
257 if (bIsAutoRedact && !r_aTableTargets.empty())
259 for (
const auto& targetPair : r_aTableTargets)
261 autoRedactPage(targetPair.first, rGDIMetaFile, xPage, xComponent);
267 uno::Reference<drawing::XDrawPage> xPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW);
268 xDrawPages->remove(xPage);
277 Reference<css::beans::XPropertySet> xPropSet(
xFrame, UNO_QUERY);
278 Reference<css::frame::XLayoutManager> xLayoutManager;
285 Any aValue = xPropSet->getPropertyValue(
"LayoutManager");
286 aValue >>= xLayoutManager;
287 xLayoutManager->createElement(
"private:resource/toolbar/redactionbar");
288 xLayoutManager->showElement(
"private:resource/toolbar/redactionbar");
290 catch (
const css::uno::RuntimeException&)
294 catch (css::uno::Exception&)
305 Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
xModel->getCurrentController(),
307 if (!xTextViewCursorSupplier.is())
309 SAL_WARN(
"sfx.doc",
"Ref to xTextViewCursorSupplier is null in setPageMargins().");
313 Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), UNO_QUERY);
315 uno::Reference<beans::XPropertySet> xPageProperySet(xCursor, UNO_QUERY);
316 OUString sPageStyleName;
317 Any aValue = xPageProperySet->getPropertyValue(
"PageStyleName");
318 aValue >>= sPageStyleName;
320 Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, UNO_QUERY);
321 if (!xStyleFamiliesSupplier.is())
323 SAL_WARN(
"sfx.doc",
"Ref to xStyleFamiliesSupplier is null in setPageMargins().");
326 uno::Reference<container::XNameAccess> xStyleFamilies
327 = xStyleFamiliesSupplier->getStyleFamilies();
329 if (!xStyleFamilies.is())
332 uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName(
"PageStyles"),
335 if (!xPageStyles.is())
338 uno::Reference<css::style::XStyle> xPageStyle(xPageStyles->getByName(sPageStyleName),
341 if (!xPageStyle.is())
344 uno::Reference<beans::XPropertySet> xPageProperties(xPageStyle, uno::UNO_QUERY);
346 if (!xPageProperties.is())
349 xPageProperties->getPropertyValue(
"LeftMargin") >>= aPageMargins.
nLeft;
350 xPageProperties->getPropertyValue(
"RightMargin") >>= aPageMargins.
nRight;
351 xPageProperties->getPropertyValue(
"TopMargin") >>= aPageMargins.
nTop;
352 xPageProperties->getPropertyValue(
"BottomMargin") >>= aPageMargins.
nBottom;
361 OUString sPageStyleName(
"Default");
363 css::uno::Reference<css::sheet::XSpreadsheetView> xSpreadsheetView(
364 xModel->getCurrentController(), UNO_QUERY);
366 if (!xSpreadsheetView.is())
368 SAL_WARN(
"sfx.doc",
"Ref to xSpreadsheetView is null in getPageMarginsForCalc().");
372 uno::Reference<beans::XPropertySet> xSheetProperties(xSpreadsheetView->getActiveSheet(),
375 xSheetProperties->getPropertyValue(
"PageStyle") >>= sPageStyleName;
377 Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, UNO_QUERY);
378 if (!xStyleFamiliesSupplier.is())
380 SAL_WARN(
"sfx.doc",
"Ref to xStyleFamiliesSupplier is null in getPageMarginsForCalc().");
383 uno::Reference<container::XNameAccess> xStyleFamilies
384 = xStyleFamiliesSupplier->getStyleFamilies();
386 if (!xStyleFamilies.is())
389 uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName(
"PageStyles"),
392 if (!xPageStyles.is())
395 uno::Reference<css::style::XStyle> xPageStyle(xPageStyles->getByName(sPageStyleName),
398 if (!xPageStyle.is())
401 uno::Reference<beans::XPropertySet> xPageProperties(xPageStyle, uno::UNO_QUERY);
403 if (!xPageProperties.is())
406 xPageProperties->getPropertyValue(
"LeftMargin") >>= aPageMargins.
nLeft;
407 xPageProperties->getPropertyValue(
"RightMargin") >>= aPageMargins.
nRight;
408 xPageProperties->getPropertyValue(
"TopMargin") >>= aPageMargins.
nTop;
409 xPageProperties->getPropertyValue(
"BottomMargin") >>= aPageMargins.
nBottom;
416 std::vector<::tools::Rectangle>& aRedactionRectangles,
417 const uno::Reference<XComponent>& xComponent)
428 for (pCurrAct =
const_cast<GDIMetaFile&
>(rMtf).FirstAction(); pCurrAct;
429 pCurrAct =
const_cast<GDIMetaFile&
>(rMtf).NextAction())
433 if (pCurrAct->
GetType() == MetaActionType::TEXTARRAY)
438 OUString sText = pMetaTextArrayAction->
GetText();
439 sal_Int32 nStart = 0;
440 sal_Int32 nEnd = sText.getLength();
442 bool bFound = textSearch.
SearchForward(sText, &nStart, &nEnd);
450 ImplCalcActionBounds(*pMetaTextArrayAction, *pOutputDevice, nStart, nEnd));
457 aNewRect.
SetTop(aNewRect.
Bottom() - aLastFontHeight - aLastFontHeight / 10);
458 aRedactionRectangles.push_back(aNewRect);
463 nEnd = sText.getLength();
467 else if (pCurrAct->
GetType() == MetaActionType::FONT)
476 const uno::Reference<XComponent>& xComponent,
const uno::Reference<drawing::XDrawPage>& xPage,
477 const std::vector<::tools::Rectangle>& aNewRectangles)
479 if (!xComponent.is() || !xPage.is())
482 if (aNewRectangles.empty())
485 uno::Reference<css::lang::XMultiServiceFactory>
xFactory(xComponent, uno::UNO_QUERY);
487 for (
auto const& aNewRectangle : aNewRectangles)
489 uno::Reference<drawing::XShape> xRectShape(
490 xFactory->createInstance(
"com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
491 uno::Reference<beans::XPropertySet> xRectShapeProperySet(xRectShape, uno::UNO_QUERY);
493 xRectShapeProperySet->setPropertyValue(
"Name",
494 uno::Any(OUString(
"RectangleRedactionShape")));
495 xRectShapeProperySet->setPropertyValue(
"FillTransparence",
496 css::uno::Any(
static_cast<sal_Int16
>(50)));
497 xRectShapeProperySet->setPropertyValue(
"FillColor", css::uno::Any(
COL_GRAY7));
498 xRectShapeProperySet->setPropertyValue(
499 "LineStyle", css::uno::Any(css::drawing::LineStyle::LineStyle_NONE));
501 xRectShape->setSize(awt::Size(aNewRectangle.GetWidth(), aNewRectangle.GetHeight()));
502 xRectShape->setPosition(awt::Point(aNewRectangle.Left(), aNewRectangle.Top()));
504 xPage->add(xRectShape);
510 const uno::Reference<drawing::XDrawPage>& xPage,
511 const uno::Reference<XComponent>& xComponent)
513 if (rRedactionTarget.
sContent.isEmpty())
517 std::vector<::tools::Rectangle> aRedactionRectangles;
518 searchInMetaFile(rRedactionTarget, rGDIMetaFile, aRedactionRectangles, xComponent);
557 rSearchOpt.
searchFlag |= util::SearchFlags::NORM_WORD_ONLY;
@ REDACTION_TARGET_PREDEFINED
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
const OUString & GetValue() const
Size getDocumentSizeIn100mm(sal_Int32 nCurrentPage, Point *pDocumentPosition=nullptr, Point *pCalcPagePosition=nullptr, Size *pCalcPageSize=nullptr)
Graphic renderToGraphic(sal_Int32 nCurrentPage, Size aDocumentSizePixel, Size aTargetSizePixel, Color aPageColor, bool bExtOutDevData)
Size getDocumentSizeInPixels(sal_Int32 nCurrentPage)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
const GDIMetaFile & GetGDIMetaFile() const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
void SetMapUnit(MapUnit eUnit)
sal_Int32 GetIndex() const
const KernArray & GetDXArray() const
const OUString & GetText() const
const Point & GetPoint() const
vcl::Region GetClipRegion() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
bool IsClipRegion() const
tools::Rectangle ImplGetTextBoundRect(const SalLayout &) const
std::unique_ptr< SalLayout > ImplLayout(const OUString &, sal_Int32 nIndex, sal_Int32 nLen, const Point &rLogicPos=Point(0, 0), tools::Long nLogicWidth=0, KernArraySpan aKernArray=KernArraySpan(), o3tl::span< const sal_Bool > pKashidaArray={}, SalLayoutFlags flags=SalLayoutFlags::NONE, vcl::text::TextLayoutCache const *=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
virtual OutputDevice * GetDocumentRefDev()
static SfxObjectShell * GetShellFromComponent(const css::uno::Reference< css::uno::XInterface > &xComp)
static void addPagesToDraw(const uno::Reference< XComponent > &xComponent, sal_Int32 nPages, const std::vector< GDIMetaFile > &aMetaFiles, const std::vector<::Size > &aPageSizes, const PageMargins &aPageMargins, const std::vector< std::pair< RedactionTarget, OUString > > &r_aTableTargets, bool bIsAutoRedact)
static void fillSearchOptions(i18nutil::SearchOptions2 &rSearchOpt, const RedactionTarget &rTarget)
Fill the search options based on the given redaction target.
static void autoRedactPage(const RedactionTarget &rRedactionTarget, const GDIMetaFile &rGDIMetaFile, const uno::Reference< drawing::XDrawPage > &xPage, const uno::Reference< XComponent > &xComponent)
static constexpr std::u16string_view m_aPredefinedTargets[6]
static void addRedactionRectToPage(const uno::Reference< XComponent > &xComponent, const uno::Reference< drawing::XDrawPage > &xPage, const std::vector< tools::Rectangle > &aNewRectangles)
static PageMargins getPageMarginsForCalc(const css::uno::Reference< css::frame::XModel > &xModel)
static OUString getStringParam(const SfxRequest &rReq, sal_uInt16 nParamId)
static PageMargins getPageMarginsForWriter(const css::uno::Reference< css::frame::XModel > &xModel)
static void showRedactionToolbar(const SfxViewFrame *pViewFrame)
static void searchInMetaFile(const RedactionTarget &rRedactionTarget, const GDIMetaFile &rMtf, std::vector< tools::Rectangle > &aRedactionRectangles, const uno::Reference< XComponent > &xComponent)
static bool isRedactMode(const SfxRequest &rReq)
Checks to see if the request has a parameter of IsRedactMode:bool=true.
static void getPageMetaFilesFromDoc(std::vector< GDIMetaFile > &aMetaFiles, std::vector<::Size > &aPageSizes, sal_Int32 nPages, DocumentToGraphicRenderer &aRenderer)
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
Templatized access to the individual parameters of the SfxRequest.
SfxFrame & GetFrame() const
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
const Size & GetFontSize() const
tools::Rectangle GetBoundRect() const
constexpr ::Color COL_GRAY7(0x66, 0x66, 0x66)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
Keeps information for a single redaction target.
TransliterationFlags transliterateFlags
Reference< XFrame > xFrame
Reference< XModel > xModel
SW_DLLPUBLIC const LanguageTag & GetAppLanguageTag()
VCL_DLLPUBLIC bool ReadWindowMetafile(SvStream &rStream, GDIMetaFile &rMTF)
VCL_DLLPUBLIC bool ConvertGDIMetaFileToWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable=true)