26#include <com/sun/star/container/XEnumerationAccess.hpp>
27#include <com/sun/star/container/XContentEnumerationAccess.hpp>
28#include <com/sun/star/document/XActionLockable.hpp>
29#include <com/sun/star/document/XDocumentProperties.hpp>
30#include <com/sun/star/drawing/FillStyle.hpp>
31#include <com/sun/star/drawing/HomogenMatrix3.hpp>
32#include <com/sun/star/drawing/LineStyle.hpp>
33#include <com/sun/star/drawing/XShape.hpp>
34#include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
35#include <com/sun/star/lang/XMultiServiceFactory.hpp>
36#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38#include <com/sun/star/text/RelOrientation.hpp>
39#include <com/sun/star/text/TextContentAnchorType.hpp>
40#include <com/sun/star/text/VertOrientation.hpp>
41#include <com/sun/star/text/WrapTextMode.hpp>
42#include <com/sun/star/text/XTextContent.hpp>
43#include <com/sun/star/text/XTextDocument.hpp>
44#include <com/sun/star/text/XTextField.hpp>
45#include <com/sun/star/text/XTextRange.hpp>
46#include <com/sun/star/text/XParagraphAppend.hpp>
47#include <com/sun/star/text/XParagraphCursor.hpp>
48#include <com/sun/star/awt/FontWeight.hpp>
49#include <com/sun/star/rdf/XMetadatable.hpp>
50#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
51#include <com/sun/star/security/XCertificate.hpp>
105#define WATERMARK_AUTO_SIZE sal_uInt32(1)
109constexpr OUStringLiteral MetaFilename(
u"tscp/bails.rdf");
110constexpr OUStringLiteral MetaNS(
u"urn:bails");
111constexpr OUStringLiteral ParagraphSignatureRDFNamespace =
u"urn:bails:loext:paragraph:signature:";
112constexpr OUStringLiteral ParagraphSignatureIdRDFName =
u"urn:bails:loext:paragraph:signature:id";
113constexpr OUStringLiteral ParagraphSignatureDigestRDFName =
u":digest";
114constexpr OUStringLiteral ParagraphSignatureDateRDFName =
u":date";
115constexpr OUStringLiteral ParagraphSignatureUsageRDFName =
u":usage";
116constexpr OUStringLiteral ParagraphSignatureLastIdRDFName =
u"urn:bails:loext:paragraph:signature:lastid";
117constexpr OUStringLiteral ParagraphClassificationNameRDFName =
u"urn:bails:loext:paragraph:classification:name";
118constexpr OUStringLiteral ParagraphClassificationValueRDFName =
u"urn:bails:loext:paragraph:classification:value";
119constexpr OUStringLiteral ParagraphClassificationAbbrRDFName =
u"urn:bails:loext:paragraph:classification:abbreviation";
120constexpr OUStringLiteral ParagraphClassificationFieldNamesRDFName =
u"urn:bails:loext:paragraph:classification:fields";
121constexpr OUStringLiteral MetadataFieldServiceName =
u"com.sun.star.text.textfield.MetadataField";
122constexpr OUStringLiteral DocInfoServiceName =
u"com.sun.star.text.TextField.DocInfo.Custom";
125std::vector<OUString> lcl_getUsedPageStyles(
SwViewShell const * pShell)
127 std::vector<OUString> aReturn;
134 aReturn.push_back(pDesc->GetName());
141uno::Reference<text::XTextField> lcl_findField(
const uno::Reference<text::XText>& xText,
const OUString& rServiceName, std::u16string_view rFieldName)
143 uno::Reference<text::XTextField> xField;
144 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
145 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
146 while (xParagraphs->hasMoreElements())
148 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
149 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
150 while (xTextPortions->hasMoreElements())
152 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
153 OUString aTextPortionType;
158 uno::Reference<lang::XServiceInfo> xTextField;
160 if (!xTextField->supportsService(rServiceName))
164 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
166 if (
aName == rFieldName)
168 xField = uno::Reference<text::XTextField>(xTextField, uno::UNO_QUERY);
178bool lcl_hasField(
const uno::Reference<text::XText>& xText,
const OUString& rServiceName, std::u16string_view rFieldName)
180 return lcl_findField(xText, rServiceName, rFieldName).is();
184uno::Reference<drawing::XShape> lcl_getWatermark(
const uno::Reference<text::XText>& xText,
185 const OUString& rServiceName, OUString& rShapeName,
bool& bSuccess)
188 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
189 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
190 while (xParagraphs->hasMoreElements())
192 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
193 if (!xTextPortionEnumerationAccess.is())
198 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
199 while (xTextPortions->hasMoreElements())
201 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
202 OUString aTextPortionType;
204 if (aTextPortionType !=
"Frame")
207 uno::Reference<container::XContentEnumerationAccess> xContentEnumerationAccess(xTextPortion, uno::UNO_QUERY);
208 if (!xContentEnumerationAccess.is())
211 uno::Reference<container::XEnumeration> xEnumeration = xContentEnumerationAccess->createContentEnumeration(
"com.sun.star.text.TextContent");
212 if (!xEnumeration->hasMoreElements())
215 uno::Reference<lang::XServiceInfo> xWatermark(xEnumeration->nextElement(), uno::UNO_QUERY);
216 if (!xWatermark->supportsService(rServiceName))
219 uno::Reference<container::XNamed> xNamed(xWatermark, uno::UNO_QUERY);
224 rShapeName = xNamed->getName();
226 uno::Reference<drawing::XShape> xShape(xWatermark, uno::UNO_QUERY);
231 return uno::Reference<drawing::XShape>();
236OString lcl_getParagraphBodyText(
const uno::Reference<text::XTextContent>& xText)
238 OUStringBuffer strBuf;
239 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xText, uno::UNO_QUERY);
240 if (!xTextPortionEnumerationAccess.is())
243 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
244 while (xTextPortions->hasMoreElements())
246 uno::Any elem = xTextPortions->nextElement();
249 OUString aTextPortionType;
250 uno::Reference<beans::XPropertySet> xPropertySet(elem, uno::UNO_QUERY);
252 if (aTextPortionType ==
"Text")
254 uno::Reference<text::XTextRange> xTextRange(elem, uno::UNO_QUERY);
256 strBuf.append(xTextRange->getString());
265 return strBuf.makeStringAndClear().trim().toUtf8();
269std::map<OUString, OUString> lcl_getRDFStatements(
const uno::Reference<frame::XModel>&
xModel,
274 const css::uno::Reference<css::rdf::XResource> xSubject(xRef, uno::UNO_QUERY);
277 catch (const ::css::uno::Exception&)
281 return std::map<OUString, OUString>();
285std::pair<OUString, OUString> lcl_getFieldRDFByPrefix(
const uno::Reference<frame::XModel>&
xModel,
286 const uno::Reference<css::text::XTextField>& xField,
289 for (
const auto& pair : lcl_getRDFStatements(
xModel, xField))
291 if (pair.first.startsWith(
sPrefix))
295 return std::make_pair(OUString(), OUString());
300std::pair<OUString, OUString> lcl_getRDF(
const uno::Reference<frame::XModel>&
xModel,
302 const OUString& sRDFName)
304 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(
xModel, xRef);
305 const auto it = aStatements.find(sRDFName);
306 return (it != aStatements.end()) ? std::make_pair(it->first, it->second) : std::make_pair(OUString(), OUString());
311bool lcl_IsParagraphSignatureField(
const uno::Reference<frame::XModel>&
xModel,
312 const uno::Reference<css::text::XTextField>& xField)
314 return (lcl_getRDF(
xModel, xField, ParagraphSignatureIdRDFName).
first == ParagraphSignatureIdRDFName);
317uno::Reference<text::XTextField> lcl_findFieldByRDF(
const uno::Reference<frame::XModel>&
xModel,
318 const uno::Reference<text::XTextContent>& xParagraph,
319 const OUString& sRDFName,
320 std::u16string_view sRDFValue)
322 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
323 if (!xTextPortionEnumerationAccess.is())
324 return uno::Reference<text::XTextField>();
326 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
327 if (!xTextPortions.is())
328 return uno::Reference<text::XTextField>();
330 while (xTextPortions->hasMoreElements())
332 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
333 OUString aTextPortionType;
338 uno::Reference<lang::XServiceInfo> xTextField;
340 if (!xTextField->supportsService(MetadataFieldServiceName))
343 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
344 const std::pair<OUString, OUString> pair = lcl_getRDF(
xModel, xField, sRDFName);
345 if (pair.first == sRDFName && (sRDFValue.empty() || sRDFValue == pair.second))
349 return uno::Reference<text::XTextField>();
354 OUString msSignature;
358 bool isValid()
const {
return !msSignature.isEmpty(); }
361SignatureDescr lcl_getSignatureDescr(
const uno::Reference<frame::XModel>&
xModel,
362 const uno::Reference<css::text::XTextContent>& xParagraph,
363 std::u16string_view sFieldId)
365 SignatureDescr aDescr;
367 const OUString
prefix = ParagraphSignatureRDFNamespace + sFieldId;
368 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(
xModel, xParagraph);
370 const auto itSig = aStatements.find(
prefix + ParagraphSignatureDigestRDFName);
371 aDescr.msSignature = (itSig != aStatements.end() ? itSig->second : OUString());
373 const auto itDate = aStatements.find(
prefix + ParagraphSignatureDateRDFName);
374 aDescr.msDate = (itDate != aStatements.end() ? itDate->second : OUString());
376 const auto itUsage = aStatements.find(
prefix + ParagraphSignatureUsageRDFName);
377 aDescr.msUsage = (itUsage != aStatements.end() ? itUsage->second : OUString());
382SignatureDescr lcl_getSignatureDescr(
const uno::Reference<frame::XModel>&
xModel,
383 const uno::Reference<css::text::XTextContent>& xParagraph,
384 const uno::Reference<css::text::XTextField>& xField)
386 const OUString sFieldId = lcl_getRDF(
xModel, xField, ParagraphSignatureIdRDFName).second;
387 if (!sFieldId.isEmpty())
388 return lcl_getSignatureDescr(
xModel, xParagraph, sFieldId);
390 return SignatureDescr();
394std::pair<bool, OUString> lcl_MakeParagraphSignatureFieldText(
const SignatureDescr& aDescr,
395 const OString& utf8Text)
397 OUString msg =
SwResId(STR_INVALID_SIGNATURE);
400 if (aDescr.isValid())
402 const char*
pData = utf8Text.getStr();
403 const std::vector<unsigned char> data(
pData,
pData + utf8Text.getLength());
405 OString encSignature;
406 if (aDescr.msSignature.convertToString(&encSignature, RTL_TEXTENCODING_UTF8, 0))
412 && aInfo.
nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED;
417 msg += (!aDescr.msUsage.isEmpty() ? (
" (" + aDescr.msUsage +
"): ") : OUString(
": "));
422 return std::make_pair(valid, msg);
426std::pair<bool, OUString>
427lcl_MakeParagraphSignatureFieldText(
const uno::Reference<frame::XModel>&
xModel,
428 const uno::Reference<css::text::XTextContent>& xParagraph,
429 const uno::Reference<css::text::XTextField>& xField,
430 const OString& utf8Text)
432 const SignatureDescr aDescr = lcl_getSignatureDescr(
xModel, xParagraph, xField);
433 return lcl_MakeParagraphSignatureFieldText(aDescr, utf8Text);
437OUString lcl_getNextSignatureId(
const uno::Reference<frame::XModel>&
xModel,
438 const uno::Reference<text::XTextContent>& xParagraph)
440 const OUString sFieldId = lcl_getRDF(
xModel, xParagraph, ParagraphSignatureLastIdRDFName).second;
441 return OUString::number(!sFieldId.isEmpty() ? sFieldId.toInt32() + 1 : 1);
445uno::Reference<text::XTextField> lcl_InsertParagraphSignature(
const uno::Reference<frame::XModel>&
xModel,
446 const uno::Reference<text::XTextContent>& xParagraph,
447 const OUString& signature,
448 const OUString& usage)
450 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
451 auto xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
454 xField->attach(xParagraph->getAnchor()->getEnd());
456 const OUString
sId = lcl_getNextSignatureId(
xModel, xParagraph);
458 const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
464 OUStringBuffer rBuffer;
465 rBuffer.append(
static_cast<sal_Int32
>(aDateTime.
GetYear()));
469 rBuffer.append(
static_cast<sal_Int32
>(aDateTime.
GetMonth()));
471 if (aDateTime.
GetDay() < 10)
473 rBuffer.append(
static_cast<sal_Int32
>(aDateTime.
GetDay()));
476 const css::uno::Reference<css::rdf::XResource> xParaSubject(xParagraph, uno::UNO_QUERY);
477 const OUString
prefix = ParagraphSignatureRDFNamespace +
sId;
487bool lcl_DoUpdateParagraphSignatureField(
SwDoc& rDoc,
488 const uno::Reference<css::text::XTextField>& xField,
489 const OUString& sDisplayText)
500 uno::Reference<css::text::XTextRange> xText(xField, uno::UNO_QUERY);
501 const OUString curText = xText->getString();
502 if (curText != sDisplayText)
504 xText->setString(sDisplayText);
508 catch (
const uno::Exception&)
518bool lcl_UpdateParagraphSignatureField(
SwDoc& rDoc,
519 const uno::Reference<frame::XModel>&
xModel,
520 const uno::Reference<css::text::XTextContent>& xParagraph,
521 const uno::Reference<css::text::XTextField>& xField,
522 const OString& utf8Text)
524 const OUString sDisplayText
525 = lcl_MakeParagraphSignatureFieldText(
xModel, xParagraph, xField, utf8Text).second;
526 return lcl_DoUpdateParagraphSignatureField(rDoc, xField, sDisplayText);
529void lcl_RemoveParagraphMetadataField(
const uno::Reference<css::text::XTextField>& xField)
531 uno::Reference<css::text::XTextRange> xParagraph(xField->getAnchor());
532 xParagraph->getText()->removeTextContent(xField);
537bool lcl_IsParagraphClassificationField(
const uno::Reference<frame::XModel>&
xModel,
538 const uno::Reference<css::text::XTextField>& xField,
539 std::u16string_view sKey)
541 const std::pair<OUString, OUString> rdfPair = lcl_getRDF(
xModel, xField, ParagraphClassificationNameRDFName);
542 return rdfPair.first == ParagraphClassificationNameRDFName && (sKey.empty() || rdfPair.second == sKey);
545uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(
const uno::Reference<frame::XModel>&
xModel,
547 std::u16string_view sKey =
u"")
549 uno::Reference<text::XTextField> xTextField;
551 if (!xParagraph.is())
556 while (xTextPortions->hasMoreElements())
558 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
559 OUString aTextPortionType;
564 uno::Reference<lang::XServiceInfo> xServiceInfo;
566 if (!xServiceInfo->supportsService(MetadataFieldServiceName))
569 uno::Reference<text::XTextField> xField(xServiceInfo, uno::UNO_QUERY);
570 if (lcl_IsParagraphClassificationField(
xModel, xField, sKey))
581uno::Reference<text::XTextField> lcl_InsertParagraphClassification(
const uno::Reference<frame::XModel>&
xModel,
582 const uno::Reference<text::XTextContent>& xParent)
584 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
585 auto xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
588 xField->attach(xParent->getAnchor()->getStart());
593bool lcl_UpdateParagraphClassificationField(
SwDoc* pDoc,
594 const uno::Reference<frame::XModel>&
xModel,
595 const uno::Reference<css::text::XTextContent>& xTextNode,
596 const OUString& sKey,
597 const OUString& sValue,
598 const OUString& sDisplayText)
607 uno::Reference<text::XTextField> xField = lcl_InsertParagraphClassification(
xModel, xTextNode);
609 css::uno::Reference<css::rdf::XResource> xFieldSubject(xField, uno::UNO_QUERY);
614 css::uno::Reference<css::rdf::XResource> xNodeSubject(xTextNode, uno::UNO_QUERY);
617 return lcl_DoUpdateParagraphSignatureField(*pDoc, xField, sDisplayText);
620void lcl_ValidateParagraphSignatures(
SwDoc& rDoc,
const uno::Reference<text::XTextContent>& xParagraph,
const bool updateDontRemove)
631 const std::pair<OUString, OUString> pair = lcl_getRDF(
xModel, xParagraph, ParagraphSignatureLastIdRDFName);
632 if (pair.second.isEmpty())
635 catch (const ::css::uno::Exception&)
640 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
641 if (!xTextPortionEnumerationAccess.is())
644 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
645 if (!xTextPortions.is())
649 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
650 if (utf8Text.isEmpty())
653 while (xTextPortions->hasMoreElements())
655 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
656 OUString aTextPortionType;
661 uno::Reference<lang::XServiceInfo> xTextField;
663 if (!xTextField->supportsService(MetadataFieldServiceName))
666 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
667 if (!lcl_IsParagraphSignatureField(
xModel, xField))
672 if (updateDontRemove)
674 lcl_UpdateParagraphSignatureField(rDoc,
xModel, xParagraph, xField, utf8Text);
676 else if (!lcl_MakeParagraphSignatureFieldText(
xModel, xParagraph, xField, utf8Text).
first)
680 std::make_unique<SwUndoParagraphSigning>(rDoc, xField, xParagraph,
false));
681 lcl_RemoveParagraphMetadataField(xField);
705 uno::Reference<text::XText>
const & rxText, uno::Reference<text::XParagraphCursor>
const & rxParagraphCursor,
706 OUString
const & rsKey)
708 uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
710 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
712 rxText->insertTextContent(rxParagraphCursor, xTextContent,
false);
717 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(rxText, uno::UNO_QUERY);
718 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
719 while (xParagraphs->hasMoreElements())
721 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
722 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
723 while (xTextPortions->hasMoreElements())
725 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
726 OUString aTextPortionType;
731 uno::Reference<lang::XServiceInfo> xTextField;
733 if (!xTextField->supportsService(DocInfoServiceName))
737 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
739 if (
aName.startsWith(rPolicy))
741 uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY);
742 rxText->removeTextContent(xField);
750 uno::Reference<container::XEnumerationAccess> xParagraphEnumAccess(xText, uno::UNO_QUERY);
751 uno::Reference<container::XEnumeration> xParagraphEnum = xParagraphEnumAccess->createEnumeration();
752 sal_Int32 nResult = 0;
753 while (xParagraphEnum->hasMoreElements())
755 xParagraphEnum->nextElement();
761static void equaliseNumberOfParagraph(std::vector<svx::ClassificationResult>
const & rResults, uno::Reference<text::XText>
const & xText)
763 sal_Int32 nNumberOfParagraphs = 0;
767 nNumberOfParagraphs++;
772 uno::Reference<text::XParagraphAppend> xParagraphAppend(xText, uno::UNO_QUERY);
773 xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>());
788 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, uno::UNO_QUERY);
789 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
790 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY);
792 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
794 uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->
getDocProperties();
797 const std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(
this);
798 for (
const OUString& rPageStyleName : aUsedPageStyles)
800 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
803 bool bHeaderIsOn =
false;
805 uno::Reference<text::XText> xHeaderText;
808 if (xHeaderText.is())
812 bool bFooterIsOn =
false;
814 uno::Reference<text::XText> xFooterText;
817 if (xFooterText.is())
822 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
844 for (
const OUString& rPageStyleName : aUsedPageStyles)
846 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
849 bool bHeaderIsOn =
false;
853 uno::Reference<text::XText> xHeaderText;
858 bool bFooterIsOn =
false;
862 uno::Reference<text::XText> xFooterText;
871 uno::Reference<text::XParagraphCursor> xHeaderParagraphCursor(xHeaderText->createTextCursor(), uno::UNO_QUERY);
872 uno::Reference<text::XParagraphCursor> xFooterParagraphCursor(xFooterText->createTextCursor(), uno::UNO_QUERY);
874 sal_Int32 nParagraph = -1;
878 switch(rResult.meType)
922 xHeaderParagraphCursor->gotoNextParagraph(
false);
923 xFooterParagraphCursor->gotoNextParagraph(
false);
926 xHeaderParagraphCursor->gotoStartOfParagraph(
false);
927 xFooterParagraphCursor->gotoStartOfParagraph(
false);
929 uno::Reference<beans::XPropertySet> xHeaderPropertySet(xHeaderParagraphCursor, uno::UNO_QUERY_THROW);
930 uno::Reference<beans::XPropertySet> xFooterPropertySet(xFooterParagraphCursor, uno::UNO_QUERY_THROW);
931 if (rResult.msName ==
"BOLD")
933 xHeaderPropertySet->setPropertyValue(
"CharWeight",
uno::Any(awt::FontWeight::BOLD));
934 xFooterPropertySet->setPropertyValue(
"CharWeight",
uno::Any(awt::FontWeight::BOLD));
938 xHeaderPropertySet->setPropertyValue(
"CharWeight",
uno::Any(awt::FontWeight::NORMAL));
939 xFooterPropertySet->setPropertyValue(
"CharWeight",
uno::Any(awt::FontWeight::NORMAL));
953 std::vector<svx::ClassificationResult> aResult;
963 const OUString sBlank;
965 uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->
getDocProperties();
966 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
970 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, uno::UNO_QUERY);
971 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
972 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY);
974 std::vector<OUString> aPageStyles = lcl_getUsedPageStyles(
this);
975 OUString aPageStyleString = aPageStyles.back();
976 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(aPageStyleString), uno::UNO_QUERY);
978 bool bHeaderIsOn =
false;
983 if (!aValue.isEmpty())
989 uno::Reference<text::XText> xHeaderText;
992 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xHeaderText, uno::UNO_QUERY);
993 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
996 bool bFoundClassificationCategory =
false;
998 while (xParagraphs->hasMoreElements())
1000 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
1001 if (!xTextPortionEnumerationAccess.is())
1003 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
1006 uno::Reference<beans::XPropertySet> xParagraphPropertySet(xTextPortionEnumerationAccess, uno::UNO_QUERY_THROW);
1007 uno::Any aAny = xParagraphPropertySet->getPropertyValue(
"CharWeight");
1009 OUString sWeight = (aAny.get<
float>() >= awt::FontWeight::BOLD) ? OUString(
"BOLD") : OUString(
"NORMAL");
1014 while (xTextPortions->hasMoreElements())
1016 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
1017 OUString aTextPortionType;
1022 uno::Reference<lang::XServiceInfo> xTextField;
1024 if (!xTextField->supportsService(DocInfoServiceName))
1028 uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
1034 if (!aValue.isEmpty())
1040 if (!aValue.isEmpty())
1042 bFoundClassificationCategory =
true;
1047 if (!aValue.isEmpty())
1049 bFoundClassificationCategory =
true;
1054 if (!aValue.isEmpty())
1060 if (!aValue.isEmpty())
1066 if (!bFoundClassificationCategory)
1069 if (!aValue.isEmpty())
1084 const bool bHadWatermark = !
aHelper.GetDocumentWatermark().isEmpty();
1090 uno::Reference<beans::XPropertyContainer> xPropertyContainer = pDocShell->
getDocProperties()->getUserDefinedProperties();
1094 bool bHeaderIsNeeded =
aHelper.HasDocumentHeader();
1095 bool bFooterIsNeeded =
aHelper.HasDocumentFooter();
1096 OUString aWatermark =
aHelper.GetDocumentWatermark();
1097 bool bWatermarkIsNeeded = !aWatermark.isEmpty();
1099 if (!bHeaderIsNeeded && !bFooterIsNeeded && !bWatermarkIsNeeded && !bHadWatermark)
1103 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, uno::UNO_QUERY);
1104 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1105 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY);
1106 const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
1108 for (
const OUString& rPageStyleName : aStyles)
1110 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1111 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
1113 if (bHeaderIsNeeded || bWatermarkIsNeeded || bHadWatermark)
1116 bool bHeaderIsOn =
false;
1122 uno::Reference<text::XText> xHeaderText;
1125 if (bHeaderIsNeeded)
1130 uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
1132 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
1133 xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent,
false);
1138 aWatermarkItem.
SetText(aWatermark);
1142 if (bFooterIsNeeded)
1145 bool bFooterIsOn =
false;
1151 uno::Reference<text::XText> xFooterText;
1154 if (!lcl_hasField(xFooterText, DocInfoServiceName, sFooter))
1157 uno::Reference<beans::XPropertySet> xField(xMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY);
1159 uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
1160 xFooterText->insertTextContent(xFooterText->getEnd(), xTextContent,
false);
1169 const uno::Reference<frame::XModel>& xModel,
1171 const css::uno::Reference<css::rdf::XResource>& xNodeSubject,
1172 std::vector<svx::ClassificationResult> aResults)
1174 if (!xNodeSubject.is())
1180 uno::Reference<text::XTextField> xTextField = lcl_FindParagraphClassificationField(
xModel, xParent);
1181 if (!xTextField.is())
1183 lcl_RemoveParagraphMetadataField(xTextField);
1186 if (aResults.empty())
1191 std::reverse(aResults.begin(), aResults.end());
1193 aResults.erase(std::remove_if(aResults.begin(),
1196 { return rResult.meType == svx::ClassificationType::PARAGRAPH; }),
1205 const bool isLast =
nIndex == 0;
1206 const bool isFirst = (
nIndex == aResults.size() - 1);
1208 OUString sValue = rResult.
msName;
1250 sDisplayText +=
")";
1251 lcl_UpdateParagraphClassificationField(pDoc,
xModel, xParent, sKey, sValue, sDisplayText);
1257 OUStringBuffer sFieldNames;
1262 sFieldNames.append(
"/");
1263 sFieldNames.append(rFieldName);
1267 const OUString sOldFieldNames = lcl_getRDF(
xModel, xNodeSubject, ParagraphClassificationFieldNamesRDFName).second;
1279 if (pNode ==
nullptr)
1295 std::vector<svx::ClassificationResult> aResult;
1297 uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
1298 if (!xTextPortionEnumerationAccess.is())
1301 uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
1305 while (xTextPortions->hasMoreElements())
1307 uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
1308 OUString aTextPortionType;
1313 uno::Reference<lang::XServiceInfo> xField;
1315 if (!xField->supportsService(MetadataFieldServiceName))
1318 uno::Reference<text::XTextField> xTextField(xField, uno::UNO_QUERY);
1320 const std::pair<OUString, OUString> rdfNamePair = lcl_getFieldRDFByPrefix(
xModel, xTextField, sPolicy);
1322 uno::Reference<text::XTextRange> xTextRange(xField, uno::UNO_QUERY);
1323 const OUString
aName = rdfNamePair.first;
1324 const OUString aValue = rdfNamePair.second;
1325 static constexpr OUStringLiteral sBlank(
u"");
1353 std::vector<svx::ClassificationResult> aResult;
1360 if (pNode ==
nullptr)
1376 aTransformation.
set(0, 0, rMatrix.Line1.Column1);
1377 aTransformation.
set(0, 1, rMatrix.Line1.Column2);
1378 aTransformation.
set(0, 2, rMatrix.Line1.Column3);
1379 aTransformation.
set(1, 0, rMatrix.Line2.Column1);
1380 aTransformation.
set(1, 1, rMatrix.Line2.Column2);
1381 aTransformation.
set(1, 2, rMatrix.Line2.Column3);
1383 assert( rMatrix.Line3.Column1 == 0 );
1384 assert( rMatrix.Line3.Column2 == 0 );
1385 assert( rMatrix.Line3.Column3 == 1 );
1387 aTransformation.
decompose(aScale, aTranslate, fRotate, fShear);
1389 return nDeg < 0 ?
round(nDeg) * -1 :
round(360.0 - nDeg);
1399 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, uno::UNO_QUERY);
1400 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1401 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY);
1402 std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(
this);
1403 for (
const OUString& rPageStyleName : aUsedPageStyles)
1405 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1407 bool bHeaderIsOn =
false;
1412 uno::Reference<text::XText> xHeaderText;
1415 OUString sWatermark =
"";
1416 bool bSuccess =
false;
1417 uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText,
"com.sun.star.drawing.CustomShape", sWatermark, bSuccess);
1419 if (xWatermark.is())
1422 uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
1423 uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
1425 sal_Int16 nTransparency;
1427 drawing::HomogenMatrix3 aMatrix;
1429 aItem.
SetText(xTextRange->getString());
1435 if (xPropertySet->getPropertyValue(
"Transformation") >>= aMatrix)
1447 const uno::Reference<frame::XModel>& xModel,
1448 const uno::Reference<beans::XPropertySet>& xPageStyle,
1449 const uno::Reference<text::XText>& xHeaderText)
1451 if (!xHeaderText.is())
1454 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
1455 OUString aShapeServiceName =
"com.sun.star.drawing.CustomShape";
1457 bool bSuccess =
false;
1458 uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess);
1460 bool bDeleteWatermark = rWatermark.
GetText().isEmpty();
1461 if (xWatermark.is())
1463 drawing::HomogenMatrix3 aMatrix;
1464 Color nColor = 0xc0c0c0;
1465 sal_Int16 nTransparency = 50;
1466 sal_Int16 nAngle = 45;
1467 OUString aFont =
"";
1469 uno::Reference<beans::XPropertySet> xPropertySet(xWatermark, uno::UNO_QUERY);
1473 xPropertySet->getPropertyValue(
"Transformation") >>= aMatrix;
1477 uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
1478 if (xTextRange->getString() != rWatermark.
GetText()
1479 || aFont != rWatermark.
GetFont()
1483 || bDeleteWatermark)
1486 uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY);
1487 xComponent->dispose();
1492 if (!bSuccess || xWatermark.is() || bDeleteWatermark)
1495 const OUString& sFont = rWatermark.
GetFont();
1496 sal_Int16 nAngle = rWatermark.
GetAngle();
1507 pDevice->SetFont(aFont);
1509 auto nTextWidth = pDevice->GetTextWidth(rWatermark.
GetText());
1512 fRatio = pDevice->GetTextHeight();
1513 fRatio /= nTextWidth;
1517 sal_Int32 nWidth = 0;
1520 if (aSize.Width < aSize.Height)
1538 sal_Int32 nHeight = fRatio * nWidth;
1541 uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY);
1543 uno::Reference<container::XNamed> xNamed(xShape, uno::UNO_QUERY);
1544 xNamed->setName(sWatermark);
1548 aTransformation.
scale(nWidth, nHeight);
1550 drawing::HomogenMatrix3 aMatrix;
1551 aMatrix.Line1.Column1 = aTransformation.
get(0, 0);
1552 aMatrix.Line1.Column2 = aTransformation.
get(0, 1);
1553 aMatrix.Line1.Column3 = aTransformation.
get(0, 2);
1554 aMatrix.Line2.Column1 = aTransformation.
get(1, 0);
1555 aMatrix.Line2.Column2 = aTransformation.
get(1, 1);
1556 aMatrix.Line2.Column3 = aTransformation.
get(1, 2);
1557 aMatrix.Line3.Column1 = 0;
1558 aMatrix.Line3.Column2 = 0;
1559 aMatrix.Line3.Column3 = 1;
1560 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
1562 uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY);
1563 xHeaderText->insertTextContent(xHeaderText->getEnd(), xTextContent,
false);
1566 uno::Reference<document::XActionLockable> xLockable(xShape, uno::UNO_QUERY);
1567 xLockable->addActionLock();
1584 xPropertySet->setPropertyValue(
"Transformation",
uno::Any(aMatrix));
1586 uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY);
1587 xTextRange->setString(rWatermark.
GetText());
1589 uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
1590 xDefaulter->createCustomShapeDefaults(
"fontwork-plain-text");
1592 auto aGeomPropSeq = xPropertySet->getPropertyValue(
"CustomShapeGeometry").get< uno::Sequence<beans::PropertyValue> >();
1593 auto aGeomPropVec = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aGeomPropSeq);
1598 auto it = std::find_if(aGeomPropVec.begin(), aGeomPropVec.end(), [](
const beans::PropertyValue& rValue)
1600 return rValue.Name ==
"TextPath";
1602 if (it == aGeomPropVec.end())
1610 xPropertySet->getPropertyValue(
"Transformation") >>= aMatrix;
1611 xPropertySet->setPropertyValue(
"Transformation",
uno::Any(aMatrix));
1616 xLockable->removeActionLock();
1624 const bool bNoWatermark = rWatermark.
GetText().isEmpty();
1627 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
xModel, uno::UNO_QUERY);
1628 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
1629 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY);
1630 const uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
1632 for (
const OUString& rPageStyleName : aStyles)
1634 uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
1637 bool bHeaderIsOn =
false;
1648 bool bDynamicHeight =
true;
1649 sal_Int32 nOldValue;
1655 uno::Reference<text::XText> xHeaderText;
1656 uno::Reference<text::XText> xHeaderTextFirst;
1657 uno::Reference<text::XText> xHeaderTextLeft;
1658 uno::Reference<text::XText> xHeaderTextRight;
1681 uno::Reference<text::XTextField> xField,
1682 uno::Reference<text::XTextContent> xParent,
1686 m_xField(
std::move(xField)),
1687 m_xParent(
std::move(xParent)),
1692 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(
xModel,
m_xField);
1693 const auto it = aStatements.find(ParagraphSignatureIdRDFName);
1694 if (it != aStatements.end())
1697 const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName);
1698 if (it2 != aStatements.end())
1701 uno::Reference<css::text::XTextRange> xText(
m_xField, uno::UNO_QUERY);
1761 lcl_RemoveParagraphMetadataField(
m_xField);
1783 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
1784 if (utf8Text.isEmpty())
1788 uno::Reference<security::XDocumentDigitalSignatures> xSigner(
1790 security::DocumentDigitalSignatures::createDefault(
1793 uno::Sequence<css::beans::PropertyValue>
aProperties;
1794 uno::Reference<security::XCertificate> xCertificate = xSigner->chooseCertificateWithProps(
aProperties);
1795 if (!xCertificate.is())
1800 signing.
AddDataRange(utf8Text.getStr(), utf8Text.getLength());
1801 OStringBuffer sigBuf;
1802 if (!signing.
Sign(sigBuf))
1805 const OUString signature = OStringToOUString(sigBuf, RTL_TEXTENCODING_UTF8, 0);
1809 return rValue.Name ==
"Usage";
1814 it->Value >>= aUsage;
1827 uno::Reference<css::text::XTextField> xField = lcl_InsertParagraphSignature(
xModel, xParagraph, signature, aUsage);
1829 lcl_UpdateParagraphSignatureField(*
GetDoc(),
xModel, xParagraph, xField, utf8Text);
1832 std::make_unique<SwUndoParagraphSigning>(rDoc, xField, xParagraph,
true));
1853 lcl_ValidateParagraphSignatures(*
GetDoc(), xParentText, updateDontRemove);
1881 const uno::Reference<text::XTextDocument> xDoc(
xModel, uno::UNO_QUERY);
1882 uno::Reference<text::XText> xParent = xDoc->getText();
1883 uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xParent, uno::UNO_QUERY);
1884 if (!xParagraphEnumerationAccess.is())
1886 uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
1887 if (!xParagraphs.is())
1889 while (xParagraphs->hasMoreElements())
1891 uno::Reference<text::XTextContent> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
1892 lcl_ValidateParagraphSignatures(*
GetDoc(), xParagraph, updateDontRemove);
1898 uno::Reference<text::XTextField> xTextField;
1899 if (pNode !=
nullptr && pDocSh !=
nullptr)
1902 SwTextMeta* pTextMeta = static_txtattr_cast<SwTextMeta*>(pAttr);
1903 if (pTextMeta !=
nullptr)
1908 const css::uno::Reference<css::rdf::XResource> xSubject = pMeta->MakeUnoObject();
1910 const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(
xModel, xSubject);
1911 if (aStatements.find(ParagraphSignatureIdRDFName) != aStatements.end() ||
1912 aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end())
1914 xTextField = uno::Reference<text::XTextField>(xSubject, uno::UNO_QUERY);
1938 if (!xBodyText.is())
1942 static constexpr OUStringLiteral sBlank(
u"");
1946 while (xParagraphs->hasMoreElements())
1948 uno::Reference<text::XTextContent> xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY);
1953 const css::uno::Reference<css::rdf::XResource> xSubject(xParagraph);
1956 const auto it = aStatements.find(ParagraphClassificationFieldNamesRDFName);
1957 const OUString sFieldNames = (it != aStatements.end() ? it->second : sBlank);
1958 std::vector<svx::ClassificationResult> aResults;
1959 if (!sFieldNames.isEmpty())
1961 assert(it != aStatements.end() &&
"can only be non-empty if it was valid");
1966 const OUString sCurFieldName = sFieldNames.getToken(0,
'/',
nIndex);
1967 if (sCurFieldName.isEmpty())
1970 const auto it2 = aStatements.find(sCurFieldName);
1971 bool bStatementFound = it2 != aStatements.end();
1972 const OUString
sName = bStatementFound ? it->first : sBlank;
1973 const OUString sValue = bStatementFound ? it->second : sBlank;
1981 const auto it3 = aStatements.find(ParagraphClassificationAbbrRDFName);
1982 const OUString sAbbreviatedName = (it3 != aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
1987 const auto it3 = aStatements.find(ParagraphClassificationAbbrRDFName);
1988 const OUString sAbbreviatedName = (it3 != aStatements.end() && !it3->second.isEmpty() ? it3->second : sValue);
2007 std::map<OUString, SignatureDescr> aSignatures;
2008 for (
const auto& pair : lcl_getRDFStatements(
xModel, uno::Reference<css::text::XTextContent>(xParagraph)))
2010 const OUString&
sName = pair.first;
2011 if (
sName.startsWith(ParagraphSignatureRDFNamespace))
2013 const OUString
sSuffix =
sName.copy(ParagraphSignatureRDFNamespace.getLength());
2019 const OUString& sValue = pair.second;
2020 if (
type == ParagraphSignatureDateRDFName)
2021 aSignatures[id].msDate = sValue;
2022 else if (
type == ParagraphSignatureUsageRDFName)
2023 aSignatures[id].msUsage = sValue;
2024 else if (
type == ParagraphSignatureDigestRDFName)
2025 aSignatures[id].msSignature = sValue;
2030 for (
const auto& pair : aSignatures)
2032 uno::Reference<text::XTextField> xField = lcl_findFieldByRDF(
xModel, xParagraph, ParagraphSignatureIdRDFName, pair.first);
2035 uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(
xModel, uno::UNO_QUERY);
2036 xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
2039 xField->attach(xParagraph->getAnchor()->getEnd());
2041 const css::uno::Reference<css::rdf::XResource> xFieldSubject(xField, uno::UNO_QUERY);
2044 const OString utf8Text = lcl_getParagraphBodyText(xParagraph);
2045 lcl_UpdateParagraphSignatureField(*
GetDoc(),
xModel, xParagraph, xField, utf8Text);
2049 lcl_ValidateParagraphSignatures(*
GetDoc(), xParagraph,
true);
2051 catch (
const std::exception&)
2088 lcl_RemoveParagraphMetadataField(xField);
2099 uno::Reference<text::XTextField> xTextField;
2101 if (xTextField.is())
2103 const std::pair<OUString, OUString> rdfValuePair = lcl_getRDF(
xModel, xTextField, ParagraphClassificationValueRDFName);
2108 if (xTextField.is())
2110 return lcl_getRDF(
xModel, xTextField, ParagraphClassificationNameRDFName).second;
2118 OUString sHighestClass;
2121 if (pNode ==
nullptr)
2122 return sHighestClass;
2126 return sHighestClass;
2136 while (xParagraphs->hasMoreElements())
2138 uno::Reference<text::XTextContent> xParaOrTable(xParagraphs->nextElement(), uno::UNO_QUERY);
2141 sHighestClass =
aHelper.GetHigherClass(sHighestClass, sCurrentClass);
2144 return sHighestClass;
2157 uno::Reference<document::XDocumentProperties> xDocumentProperties = pDocShell->
getDocProperties();
2158 uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
2167 if (!aClassificationCategory.isEmpty())
2169 sHighestClass =
aHelper.GetHigherClass(sHighestClass, aClassificationCategory);
2172 if (aClassificationCategory != sHighestClass)
2175 VclMessageType::Question, VclButtonsType::Ok,
2176 SwResId(STR_CLASSIFICATION_LEVEL_CHANGED)));
2192 aHelper.SetBACName(sHighestClass, eHighestClassType);
2203 const bool bResetListAttrs)
2218 OUString sParaStyleName;
2219 sal_uInt16 nPoolId = USHRT_MAX;
2227 nPoolId = nStylePoolId;
2229 sParaStyleName = pTextFormatColl->
GetName();
2236 SwPaM aPaM(*rPaM.Start(), *rPaM.End());
2240 aPaM.
End()->
SetContent(pEndTextNode->GetText().getLength());
2258 std::unique_ptr<SwRedlineExtraData_FormatColl> xExtra;
2275 if ( pParent ==
nullptr )
2278 if ( pColl ==
nullptr )
2280 OSL_FAIL(
"MakeTextFormatColl failed" );
2308 &&
nullptr != (pRule =
GetDoc()->FindNumRulePtr(pItem->
GetValue()))
2317 &&
nullptr != (pRule =
GetDoc()->FindNumRulePtr(pItem->
GetValue()))
PropertyValueVector_t aPropertyValues
PropertiesInfo aProperties
const char *const aFieldNames[]
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const OUString & GetValue() const
static DateTime CreateFromUnixTime(const double fSecondsSinceEpoch)
void ConvertToLocalTime()
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_uInt16 GetMonth() const
static const OUString & PROP_DOCFOOTER()
static SfxClassificationPolicyType getPolicyType()
OUString GetBACNameForIdentifier(std::u16string_view sIdentifier)
static const OUString & PROP_DOCHEADER()
static SfxClassificationPolicyType stringToPolicyType(std::u16string_view rType)
static const OUString & policyTypeToString(SfxClassificationPolicyType eType)
static const OUString & PROP_PREFIX_INTELLECTUALPROPERTY()
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
void SetFont(const OUString &aFont)
sal_Int16 GetTransparency() const
OUString const & GetFont() const
void SetAngle(const sal_Int16 nAngle)
OUString const & GetText() const
void SetTransparency(const sal_Int16 nTransparency)
void SetColor(Color nColor)
void SetText(const OUString &aText)
sal_Int16 GetAngle() const
const SwAttrSet * GetpSwAttrSet() const
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
void RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark=false, bool bExactRange=false, SwRootFrame const *pLayout=nullptr)
void ChgFormat(SwFormat &rFormat, const SfxItemSet &rSet)
IDocumentUndoRedo & GetIDocumentUndoRedo()
SwEditShell const * GetEditShell() const
const SwTextFormatColls * GetTextFormatColls() const
const SwTextFormatColl * GetDfltTextFormatColl() const
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatName, SwTextFormatColl *pDerivedFrom, bool bBroadcast=false)
Create the FormatCollections.
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter <bResetListAttrs>.
SwDocShell * GetDocShell()
std::vector< svx::ClassificationResult > CollectAdvancedClassification()
void ApplyParagraphClassification(std::vector< svx::ClassificationResult > aResult)
Apply the classification to the paragraph at cursor.
void StartAllAction()
For all views of this document.
void SetWatermark(const SfxWatermarkItem &rText)
void SignParagraph()
Sign the paragraph at the cursor.
bool RemoveParagraphMetadataFieldAtCursor()
Removes the paragraph metadata field at the current cursor, if any.
void ValidateAllParagraphSignatures(bool updateDontRemove)
Validate all paragraph signatures.
bool IsCursorInParagraphMetadataField() const
Returns true iff the cursor is within a paragraph metadata field.
SwTextFormatColl & GetTextFormatColl(sal_uInt16 nTextFormatColl) const
sal_uInt16 GetTextFormatCollCount() const
bool SetParagraphSignatureValidation(const bool bEnable)
Enable/Disable paragraph signature validation and return the previous value.
void RestoreMetadataFieldsAndValidateParagraphSignatures()
Restore the metadata fields, if missing, from the RDF metadata and validate the signatures and update...
void SetTextFormatColl(SwTextFormatColl *, const bool bResetListAttrs=false)
Add 2nd optional parameter <bResetListAttrs> - see also <SwDoc::SetTextFormatColl(....
std::vector< svx::ClassificationResult > CollectParagraphClassification()
void ValidateCurrentParagraphSignatures(bool updateDontRemove)
Validate the current paragraph signatures, if any, at the cursor start.
void SetClassification(const OUString &rName, SfxClassificationPolicyType eType)
SwTextFormatColl & GetDfltTextFormatColl() const
void ApplyAdvancedClassification(std::vector< svx::ClassificationResult > const &rResult)
void ClassifyDocPerHighestParagraphClass()
Ensure that the classification of the doc is never lower than the paragraph with the highest classifi...
bool IsParagraphSignatureValidationEnabled() const
Returns true iff paragraph signature validation is enabled.
SfxWatermarkItem GetWatermark() const
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom=nullptr)
void FillByEx(SwCharFormat *)
void ValidateParagraphSignatures(SwTextNode *pNode, bool updateDontRemove)
Validate the paragraph signatures, if any, of the current text node.
Base class of the Writer layout elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwTableNode * FindTableNode()
Search table node, in which it is.
SwContentNode * GetContentNode()
PaM is Point and Mark: a selection of the document model.
SwContentNode * GetPointContentNode() const
const SwPosition * End() const
const SwPosition * GetPoint() const
const SwPosition * Start() const
A page of the document layout.
SwPageDesc * FindPageDesc()
static void removeStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Remove an (XResource, key, value) statement in the graph of type rType, if it exists.
static std::map< OUString, OUString > getStatements(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > &rGraphNames, const css::uno::Reference< css::rdf::XResource > &xSubject)
Gets all (XResource, key, value) statements in RDF graphs given the graph-names.
static void addStatement(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType, const OUString &rPath, const css::uno::Reference< css::rdf::XResource > &xSubject, const OUString &rKey, const OUString &rValue)
Add an (XResource, key, value) statement in the graph of type rType – or if it does not exist,...
static css::uno::Sequence< css::uno::Reference< css::rdf::XURI > > getGraphNames(const css::uno::Reference< css::rdf::XDocumentMetadataAccess > &xDocumentMetadataAccess, const css::uno::Reference< css::rdf::XURI > &xType)
Gets all graph-names in RDF of a given type.
static bool hasMetadataGraph(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rType)
Check if a graph of type rType exists.
void SetExtraData(const SwRedlineExtraData *pData)
ExtraData gets copied, the pointer is therefore not taken over by the RedLineObject.
void AddRule(SwUndoArg eWhat, const OUString &rWith)
The root element of a Writer document layout.
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
const SfxPoolItem & GetAttr() const
Represents the style of a paragraph.
SwTextNode is a paragraph in the document model.
SwTextAttr * GetTextAttrAt(sal_Int32 const nIndex, sal_uInt16 const nWhich, ::sw::GetTextAttrMode const eMode=::sw::GetTextAttrMode::Default) const
get the innermost text attribute covering position nIndex.
SwTextFormatColl * GetTextColl() const
virtual void UndoImpl(::sw::UndoRedoContext &) override
virtual void RedoImpl(::sw::UndoRedoContext &) override
SwUndoParagraphSigning(SwDoc &rDoc, css::uno::Reference< css::text::XTextField > xField, css::uno::Reference< css::text::XTextContent > xParent, const bool bRemove)
css::uno::Reference< css::text::XTextField > m_xField
virtual void RepeatImpl(::sw::RepeatContext &) override
css::uno::Reference< css::text::XTextContent > m_xParent
const SwViewOption * GetViewOptions() const
SwRootFrame * GetLayout() const
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
static rtl::Reference< SwXParagraph > CreateXParagraph(SwDoc &rDoc, SwTextNode *pTextNode, css::uno::Reference< css::text::XText > const &xParentText=nullptr, const sal_Int32 nSelStart=-1, const sal_Int32 nSelEnd=- 1)
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void rotate(double fRadiant)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
void scale(double fX, double fY)
SfxClassificationPolicyType
bool isMarkingKey(std::u16string_view aKey) const
OUString makeNumberedMarkingKey()
bool isMarkingTextKey(std::u16string_view aKey) const
OUString makeNumberedIntellectualPropertyPartKey()
bool isCategoryIdentifierKey(std::u16string_view aKey) const
bool isCategoryNameKey(std::u16string_view aKey) const
OUString makeCategoryNameKey() const
OUString makeCategoryIdentifierKey() const
OUString makeNumberedTextKey()
bool isIntellectualPropertyPartKey(std::u16string_view aKey) const
void AddDataRange(const void *pData, sal_Int32 size)
bool Sign(OStringBuffer &rCMSHexBuffer)
static bool Verify(const std::vector< unsigned char > &aData, const bool bNonDetached, const std::vector< unsigned char > &aSignature, SignatureInformation &rInformation)
ClassificationType meType
OUString msAbbreviatedName
ring_container GetRingContainer()
void SetFontSize(const Size &)
void SetFamilyName(const OUString &rFamilyName)
#define DBG_UNHANDLED_EXCEPTION(...)
static void lcl_placeWatermarkInHeader(const SfxWatermarkItem &rWatermark, const uno::Reference< frame::XModel > &xModel, const uno::Reference< beans::XPropertySet > &xPageStyle, const uno::Reference< text::XText > &xHeaderText)
static void insertFieldToDocument(uno::Reference< lang::XMultiServiceFactory > const &rxMultiServiceFactory, uno::Reference< text::XText > const &rxText, uno::Reference< text::XParagraphCursor > const &rxParagraphCursor, OUString const &rsKey)
static void lcl_ApplyParagraphClassification(SwDoc *pDoc, const uno::Reference< frame::XModel > &xModel, const rtl::Reference< SwXParagraph > &xParent, const css::uno::Reference< css::rdf::XResource > &xNodeSubject, std::vector< svx::ClassificationResult > aResults)
static OUString lcl_GetParagraphClassification(SfxClassificationHelper &rHelper, sfx::ClassificationKeyCreator const &rKeyCreator, const uno::Reference< frame::XModel > &xModel, const rtl::Reference< SwXParagraph > &xParagraph)
static OUString lcl_GetHighestClassificationParagraphClass(SwPaM *pCursor)
static void equaliseNumberOfParagraph(std::vector< svx::ClassificationResult > const &rResults, uno::Reference< text::XText > const &xText)
static sal_Int16 lcl_GetAngle(const drawing::HomogenMatrix3 &rMatrix)
static std::vector< svx::ClassificationResult > lcl_CollectParagraphClassification(const uno::Reference< frame::XModel > &xModel, const uno::Reference< text::XTextContent > &xParagraph)
static void removeAllClassificationFields(std::u16string_view rPolicy, uno::Reference< text::XText > const &rxText)
static uno::Reference< text::XTextField > lcl_GetParagraphMetadataFieldAtIndex(const SwDocShell *pDocSh, SwTextNode const *pNode, const sal_uLong index)
constexpr OUStringLiteral WATERMARK_NAME
static sal_Int32 getNumberOfParagraphs(uno::Reference< text::XText > const &xText)
#define WATERMARK_AUTO_SIZE
#define CH_TXT_ATR_INPUTFIELDSTART
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SwNumRuleItem > RES_PARATR_NUMRULE(72)
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(100)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
#define CH_TXT_ATR_INPUTFIELDEND
#define CH_TXTATR_BREAKWORD
std::unique_ptr< sal_Int32[]> pData
tools::Long const nRightMargin
tools::Long const nBottomMargin
tools::Long const nTopMargin
tools::Long const nLeftMargin
constexpr double rad2deg(double v)
constexpr double deg2rad(double v)
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral first
enumrange< T >::Iterator begin(enumrange< T >)
sfx::ClassificationCreationOrigin getCreationOriginProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator)
std::vector< unsigned char > DecodeHexString(std::string_view rHex)
OUString getProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
void insertFullTextualRepresentationAsDocumentProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator, std::vector< svx::ClassificationResult > const &rResults)
void insertCreationOrigin(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, sfx::ClassificationKeyCreator const &rKeyCreator, sfx::ClassificationCreationOrigin eOrigin)
bool addOrInsertDocumentProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rsKey, OUString const &rsValue)
void removeAllProperties(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer)
@ INTELLECTUAL_PROPERTY_PART
SwTextNode * GetParaPropsNode(SwRootFrame const &rLayout, SwNode const &rNode)
@ RES_POOLCOLL_STANDARD
Standard.
Marks a position in the document model.
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
sal_Int32 GetContentIndex() const
Reference< XModel > xModel
OUString SwResId(TranslateId aId)
constexpr OUStringLiteral UNO_NAME_FILL_TRANSPARENCE
constexpr OUStringLiteral UNO_NAME_TEXT_FIELD
constexpr OUStringLiteral UNO_NAME_FILLCOLOR
constexpr OUStringLiteral UNO_NAME_SIZE
constexpr OUStringLiteral UNO_NAME_HEADER_HEIGHT
constexpr OUStringLiteral UNO_NAME_ANCHOR_TYPE
constexpr OUStringLiteral UNO_NAME_RIGHT_MARGIN
constexpr OUStringLiteral UNO_NAME_FOOTER_TEXT
constexpr OUStringLiteral UNO_NAME_TEXT_WRAP
constexpr OUStringLiteral UNO_NAME_TEXT_MINFRAMEHEIGHT
constexpr OUStringLiteral UNO_NAME_LINESTYLE
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT
constexpr OUStringLiteral UNO_NAME_HEADER_IS_ON
constexpr OUStringLiteral UNO_NAME_LEFT_MARGIN
constexpr OUStringLiteral UNO_NAME_HORI_ORIENT
constexpr OUStringLiteral UNO_NAME_CHAR_FONT_NAME_ASIAN
constexpr OUStringLiteral UNO_NAME_VERT_ORIENT
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_LEFT
constexpr OUStringLiteral UNO_NAME_NAME
constexpr OUStringLiteral UNO_NAME_HORI_ORIENT_RELATION
constexpr OUStringLiteral UNO_NAME_TOP_MARGIN
constexpr OUStringLiteral UNO_NAME_FILLSTYLE
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_RIGHT
constexpr OUStringLiteral UNO_NAME_TEXT_PORTION_TYPE
constexpr OUStringLiteral UNO_NAME_FOOTER_IS_ON
constexpr OUStringLiteral UNO_NAME_OPAQUE
constexpr OUStringLiteral UNO_NAME_TEXT_AUTOGROWHEIGHT
constexpr OUStringLiteral UNO_NAME_HEADER_IS_DYNAMIC_HEIGHT
constexpr OUStringLiteral UNO_NAME_VERT_ORIENT_RELATION
constexpr OUStringLiteral UNO_NAME_TEXT_AUTOGROWWIDTH
constexpr OUStringLiteral UNO_NAME_BOTTOM_MARGIN
constexpr OUStringLiteral UNO_NAME_CHAR_HEIGHT
constexpr OUStringLiteral UNO_NAME_TEXT_MINFRAMEWIDTH
constexpr OUStringLiteral UNO_NAME_CHAR_FONT_NAME
constexpr OUStringLiteral UNO_NAME_HEADER_TEXT_FIRST
constexpr OUStringLiteral UNO_NAME_CHAR_FONT_NAME_COMPLEX