include/svx/ClassificationField.hxx | 4 sd/source/ui/view/drviews2.cxx | 55 +++++- svx/source/dialog/ClassificationDialog.cxx | 48 +++++ svx/source/dialog/ClassificationEditView.cxx | 24 +- sw/source/core/edit/edfcol.cxx | 221 +++++++++++++++++---------- 5 files changed, 255 insertions(+), 97 deletions(-)
New commits: commit 73f57984110a3c5bb19168dd0789c0c3c809b24e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Fri Oct 27 16:03:52 2017 +0900 TSCP: proper collecting and applying of paragraph and text weight Change-Id: I22edc4adb87706a176c3afa3500963c4a5b46ee7 Reviewed-on: https://gerrit.libreoffice.org/44015 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/ClassificationField.hxx b/include/svx/ClassificationField.hxx index 559ed66511d8..b57f29cbafbe 100644 --- a/include/svx/ClassificationField.hxx +++ b/include/svx/ClassificationField.hxx @@ -22,7 +22,8 @@ enum class ClassificationType CATEGORY, MARKING, TEXT, - INTELLECTUAL_PROPERTY_PART + INTELLECTUAL_PROPERTY_PART, + PARAGRAPH, }; class SVX_DLLPUBLIC ClassificationField : public SvxFieldData @@ -61,7 +62,6 @@ struct SVX_DLLPUBLIC ClassificationResult ClassificationType meType; OUString msString; OUString msAbbreviatedString; - sal_Int32 mnParagraph; }; } // end svx namespace diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 49706a9cdd0d..e96a69db7c60 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -299,7 +299,6 @@ public: const sal_uInt16 nCount = m_rDrawViewShell.GetDoc()->GetMasterSdPageCount(PageKind::Standard); - sal_Int32 nParagraph = 1; bool bFound = false; for (sal_uInt16 nPageIndex = 0; nPageIndex < nCount; ++nPageIndex) @@ -323,8 +322,34 @@ public: bFound = true; m_pRectObject = pRectObject; const OUString sBlank(""); + sal_Int32 nCurrentParagraph = -1; + for (editeng::Section const & rSection : aSections) { + // Insert new paragraph if needed + while (nCurrentParagraph < rSection.mnParagraph) + { + nCurrentParagraph++; + + // Get Weight of current paragraph + FontWeight eFontWeight = WEIGHT_NORMAL; + SfxItemSet aItemSet(rEditText.GetParaAttribs(nCurrentParagraph)); + if (const SfxPoolItem* pItem = aItemSet.GetItem(EE_CHAR_WEIGHT, false)) + { + const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem); + if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD) + eFontWeight = WEIGHT_BOLD; + } + + // Font weight to string + OUString sWeightProperty = "NORMAL"; + if (eFontWeight == WEIGHT_BOLD) + sWeightProperty = "BOLD"; + + // Insert into collection + m_aResults.push_back({ svx::ClassificationType::PARAGRAPH, sWeightProperty, sBlank }); + } + const SvxFieldItem* pFieldItem = findField(rSection); const editeng::CustomPropertyField* pCustomPropertyField = pFieldItem ? dynamic_cast<const editeng::CustomPropertyField*>(pFieldItem->GetField()) : nullptr; if (pCustomPropertyField) @@ -333,22 +358,22 @@ public: if (aKey.startsWith(sPolicy + "Marking:Text:")) { OUString aValue = lcl_getProperty(xPropertyContainer, aKey); - m_aResults.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, nParagraph }); + m_aResults.push_back({ svx::ClassificationType::TEXT, aValue, sBlank }); } else if (aKey.startsWith(sPolicy + "BusinessAuthorizationCategory:Name")) { OUString aValue = lcl_getProperty(xPropertyContainer, aKey); - m_aResults.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, nParagraph }); + m_aResults.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank }); } else if (aKey.startsWith(sPolicy + "Extension:Marking")) { OUString aValue = lcl_getProperty(xPropertyContainer, aKey); - m_aResults.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, nParagraph }); + m_aResults.push_back({ svx::ClassificationType::MARKING, aValue, sBlank }); } else if (aKey.startsWith(sPolicy + "Extension:IntellectualPropertyPart")) { OUString aValue = lcl_getProperty(xPropertyContainer, aKey); - m_aResults.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank, nParagraph }); + m_aResults.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank }); } } } @@ -415,9 +440,11 @@ public: pOutliner = pView->GetTextEditOutliner(); } + sal_Int32 nParagraph = -1; for (svx::ClassificationResult const & rResult : rResults) { - ESelection aPosition(EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT, EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT); + + ESelection aPosition(nParagraph, EE_TEXTPOS_MAX_COUNT, nParagraph, EE_TEXTPOS_MAX_COUNT); switch(rResult.meType) { @@ -453,6 +480,22 @@ public: } break; + case svx::ClassificationType::PARAGRAPH: + { + nParagraph++; + pOutliner->Insert(""); + + SfxItemSet aItemSet(m_rDrawViewShell.GetDoc()->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{}); + + if (rResult.msString == "BOLD") + aItemSet.Put(SvxWeightItem(WEIGHT_BOLD, EE_CHAR_WEIGHT)); + else + aItemSet.Put(SvxWeightItem(WEIGHT_NORMAL, EE_CHAR_WEIGHT)); + + pOutliner->SetParaAttribs(nParagraph, aItemSet); + } + break; + default: break; } diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx index d9b2ec868235..f99d4f97bd0c 100644 --- a/svx/source/dialog/ClassificationDialog.cxx +++ b/svx/source/dialog/ClassificationDialog.cxx @@ -13,6 +13,7 @@ #include <editeng/eeitem.hxx> #include <editeng/section.hxx> #include <editeng/editobj.hxx> +#include <editeng/wghtitem.hxx> #include <svl/itemset.hxx> namespace svx { @@ -21,7 +22,7 @@ namespace { const SvxFieldItem* findField(editeng::Section const & rSection) { - for (SfxPoolItem const * pPool: rSection.maAttributes) + for (SfxPoolItem const * pPool : rSection.maAttributes) { if (pPool->Which() == EE_FEATURE_FIELD) return static_cast<const SvxFieldItem*>(pPool); @@ -110,6 +111,7 @@ void ClassificationDialog::insertField(ClassificationType eType, OUString const void ClassificationDialog::setupValues(std::vector<ClassificationResult> const & rInput) { + sal_Int32 nParagraph = -1; for (ClassificationResult const & rClassificationResult : rInput) { OUString msAbbreviatedString = rClassificationResult.msAbbreviatedString; @@ -145,6 +147,21 @@ void ClassificationDialog::setupValues(std::vector<ClassificationResult> const & } break; + case svx::ClassificationType::PARAGRAPH: + { + nParagraph++; + + if (nParagraph != 0) + m_pEditWindow->pEdView->InsertParaBreak(); + + // Set paragraph font weight + FontWeight eWeight = (rClassificationResult.msString == "BOLD") ? WEIGHT_BOLD : WEIGHT_NORMAL; + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(m_pEditWindow->pEdEngine->GetParaAttribs(nParagraph))); + pSet->Put(SvxWeightItem(eWeight, EE_CHAR_WEIGHT)); + m_pEditWindow->pEdEngine->SetParaAttribs(nParagraph, *pSet); + } + break; + default: break; } @@ -157,11 +174,34 @@ std::vector<ClassificationResult> ClassificationDialog::getResult() std::unique_ptr<EditTextObject> pEditText(m_pEditWindow->pEdEngine->CreateTextObject()); + sal_Int32 nCurrentParagraph = -1; + std::vector<editeng::Section> aSections; pEditText->GetAllSections(aSections); - for (editeng::Section const & rSection : aSections) { + while (nCurrentParagraph < rSection.mnParagraph) + { + nCurrentParagraph++; + + // Get Weight of current paragraph + FontWeight eFontWeight = WEIGHT_NORMAL; + SfxItemSet aItemSet(m_pEditWindow->pEdEngine->GetParaAttribs(nCurrentParagraph)); + if (const SfxPoolItem* pItem = aItemSet.GetItem(EE_CHAR_WEIGHT, false)) + { + const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem); + if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD) + eFontWeight = WEIGHT_BOLD; + } + // Font weight to string + OUString sWeightProperty = "NORMAL"; + if (eFontWeight == WEIGHT_BOLD) + sWeightProperty = "BOLD"; + // Insert into collection + OUString sBlank; + aClassificationResults.push_back({ ClassificationType::PARAGRAPH, sWeightProperty, sBlank }); + } + const SvxFieldItem* pFieldItem = findField(rSection); ESelection aSelection(rSection.mnParagraph, rSection.mnStart, rSection.mnParagraph, rSection.mnEnd); @@ -172,11 +212,11 @@ std::vector<ClassificationResult> ClassificationDialog::getResult() if (pClassificationField) { - aClassificationResults.push_back({ pClassificationField->meType, pClassificationField->msFullClassName, sDisplayString, rSection.mnParagraph }); + aClassificationResults.push_back({ pClassificationField->meType, pClassificationField->msFullClassName, sDisplayString }); } else { - aClassificationResults.push_back({ ClassificationType::TEXT, sDisplayString, sDisplayString, rSection.mnParagraph }); + aClassificationResults.push_back({ ClassificationType::TEXT, sDisplayString, sDisplayString }); } } } diff --git a/svx/source/dialog/ClassificationEditView.cxx b/svx/source/dialog/ClassificationEditView.cxx index 1c602a2f2343..a992dc0aedf2 100644 --- a/svx/source/dialog/ClassificationEditView.cxx +++ b/svx/source/dialog/ClassificationEditView.cxx @@ -91,18 +91,24 @@ void ClassificationEditView::InsertField(const SvxFieldItem& rFieldItem) void ClassificationEditView::InvertSelectionWeight() { - std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(pEdEngine->GetAttribs(pEdView->GetSelection()))); - FontWeight eFontWeight = WEIGHT_BOLD; - if (const SfxPoolItem* pItem = pSet->GetItem(EE_CHAR_WEIGHT, true)) + ESelection aSelection = pEdView->GetSelection(); + + for (sal_Int32 nParagraph = aSelection.nStartPara; nParagraph <= aSelection.nEndPara; ++nParagraph) { - const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem); - if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD) - eFontWeight = WEIGHT_NORMAL; + FontWeight eFontWeight = WEIGHT_BOLD; + + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(pEdEngine->GetParaAttribs(nParagraph))); + if (const SfxPoolItem* pItem = pSet->GetItem(EE_CHAR_WEIGHT, false)) + { + const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem); + if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD) + eFontWeight = WEIGHT_NORMAL; + } + SvxWeightItem aWeight(eFontWeight, EE_CHAR_WEIGHT); + pSet->Put(aWeight); + pEdEngine->SetParaAttribs(nParagraph, *pSet); } - SvxWeightItem aWeight(eFontWeight, EE_CHAR_WEIGHT); - pSet->Put(aWeight); - pEdEngine->QuickSetAttribs(*pSet, pEdView->GetSelection()); pEdView->Invalidate(); } diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 21b9461c0f15..457fb80a01b8 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -36,6 +36,9 @@ #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XParagraphAppend.hpp> +#include <com/sun/star/text/XParagraphCursor.hpp> +#include <com/sun/star/awt/FontWeight.hpp> #include <com/sun/star/xml/crypto/SEInitializer.hpp> #include <com/sun/star/rdf/XMetadatable.hpp> #include <com/sun/star/security/DocumentDigitalSignatures.hpp> @@ -525,14 +528,76 @@ bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const return true; } -void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory, uno::Reference<text::XText> const & rxText, OUString const & rsKey) +void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory, + uno::Reference<text::XText> const & rxText, uno::Reference<text::XParagraphCursor> const & rxParagraphCursor, + OUString const & rsKey) { - if (!lcl_hasField(rxText, DocInfoServiceName, rsKey)) + uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY); + xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(rsKey)); + uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); + + rxText->insertTextContent(rxParagraphCursor, xTextContent, false); +} + +void removeAllClassificationFields(OUString const & rPolicy, uno::Reference<text::XText> const & rxText) +{ + uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(rxText, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration(); + while (xParagraphs->hasMoreElements()) + { + uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); + while (xTextPortions->hasMoreElements()) + { + uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY); + OUString aTextPortionType; + xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType; + if (aTextPortionType != UNO_NAME_TEXT_FIELD) + continue; + + uno::Reference<lang::XServiceInfo> xTextField; + xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField; + if (!xTextField->supportsService(DocInfoServiceName)) + continue; + + OUString aName; + uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY); + xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName; + if (aName.startsWith(rPolicy)) + { + uno::Reference<text::XTextField> xField(xTextField, uno::UNO_QUERY); + rxText->removeTextContent(xField); + } + } + } +} + +sal_Int32 getNumberOfParagraphs(uno::Reference<text::XText> const & xText) +{ + uno::Reference<container::XEnumerationAccess> xParagraphEnumAccess(xText, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphEnum = xParagraphEnumAccess->createEnumeration(); + sal_Int32 nResult = 0; + while (xParagraphEnum->hasMoreElements()) { - uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(DocInfoServiceName), uno::UNO_QUERY); - xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(rsKey)); - uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY); - rxText->insertTextContent(rxText->getEnd(), xTextContent, false); + xParagraphEnum->nextElement(); + nResult++; + } + return nResult; +} + +void equaliseNumberOfParagraph(std::vector<svx::ClassificationResult> const & rResults, uno::Reference<text::XText> const & xText) +{ + sal_Int32 nNumberOfParagraphs = 0; + for (svx::ClassificationResult const & rResult : rResults) + { + if (rResult.meType == svx::ClassificationType::PARAGRAPH) + nNumberOfParagraphs++; + } + + while (getNumberOfParagraphs(xText) < nNumberOfParagraphs) + { + uno::Reference<text::XParagraphAppend> xParagraphAppend(xText, uno::UNO_QUERY); + xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>()); } } @@ -551,8 +616,6 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties(); - // First, we need to remove the old ones. - //TODO: we should get this as a param, since we pass it to the dialog. const OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType()); const std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this); for (const OUString& rPageStyleName : aUsedPageStyles) @@ -565,6 +628,10 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes uno::Reference<text::XText> xHeaderText; if (bHeaderIsOn) xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText; + if (xHeaderText.is()) + removeAllClassificationFields(sPolicy, xHeaderText); + + equaliseNumberOfParagraph(rResults, xHeaderText); // FOOTER bool bFooterIsOn = false; @@ -572,55 +639,10 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes uno::Reference<text::XText> xFooterText; if (bFooterIsOn) xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText; + if (xFooterText.is()) + removeAllClassificationFields(sPolicy, xFooterText); - sal_Int32 nTextNumber = 1; - OUString sKey; - for (svx::ClassificationResult const & rResult : CollectAdvancedClassification()) - { - sKey = ""; - switch(rResult.meType) - { - case svx::ClassificationType::TEXT: - { - sKey = sPolicy + "Marking:Text:" + OUString::number(nTextNumber++); - } - break; - - case svx::ClassificationType::CATEGORY: - { - sKey = sPolicy + "BusinessAuthorizationCategory:Name"; - } - break; - - case svx::ClassificationType::MARKING: - { - sKey = sPolicy + "Extension:Marking"; - } - break; - - case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: - { - sKey = sPolicy + "Extension:IntellectualPropertyPart"; - } - break; - - default: - break; - } - - if (!sKey.isEmpty()) - { - uno::Reference<css::text::XTextField> xField = lcl_findClassificationField(xHeaderText, DocInfoServiceName, sKey); - if (xField.is()) - { - if (xHeaderText.is()) - xHeaderText->removeTextContent(xField); - - if (xFooterText.is()) - xFooterText->removeTextContent(xField); - } - } - } + equaliseNumberOfParagraph(rResults, xFooterText); } // Clear properties @@ -660,6 +682,11 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes sal_Int32 nTextNumber = 1; + uno::Reference<text::XParagraphCursor> xHeaderParagraphCursor(xHeaderText->createTextCursor(), uno::UNO_QUERY); + uno::Reference<text::XParagraphCursor> xFooterParagraphCursor(xFooterText->createTextCursor(), uno::UNO_QUERY); + + sal_Int32 nParagraph = -1; + for (svx::ClassificationResult const & rResult : rResults) { switch(rResult.meType) @@ -670,16 +697,16 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes nTextNumber++; addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString); - insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey); - insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey); + insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey); + insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey); } break; case svx::ClassificationType::CATEGORY: { OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name"; - insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey); - insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey); + insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey); + insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey); } break; @@ -687,8 +714,8 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes { OUString sKey = sPolicy + "Extension:Marking"; addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString); - insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey); - insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey); + insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey); + insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey); } break; @@ -696,8 +723,36 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes { OUString sKey = sPolicy + "Extension:IntellectualPropertyPart"; addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString); - insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey); - insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey); + insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey); + insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey); + } + break; + + case svx::ClassificationType::PARAGRAPH: + { + nParagraph++; + + if (nParagraph != 0) // only jump to next paragraph, if we aren't at the first paragraph + { + xHeaderParagraphCursor->gotoNextParagraph(false); + xFooterParagraphCursor->gotoNextParagraph(false); + } + + xHeaderParagraphCursor->gotoStartOfParagraph(false); + xFooterParagraphCursor->gotoStartOfParagraph(false); + + uno::Reference<beans::XPropertySet> xHeaderPropertySet(xHeaderParagraphCursor, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xFooterPropertySet(xFooterParagraphCursor, uno::UNO_QUERY_THROW); + if (rResult.msString == "BOLD") + { + xHeaderPropertySet->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::BOLD)); + xFooterPropertySet->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::BOLD)); + } + else + { + xHeaderPropertySet->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::NORMAL)); + xFooterPropertySet->setPropertyValue("CharWeight", uno::makeAny(awt::FontWeight::NORMAL)); + } } break; @@ -740,12 +795,23 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties(); OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType()); - sal_Int32 nParagraph = 1; + + const OUString sBlank(""); while (xParagraphs->hasMoreElements()) { uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY); uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); + + // Check font weitght + uno::Reference<beans::XPropertySet> xParagraphPropertySet(xTextPortionEnumerationAccess, uno::UNO_QUERY_THROW); + uno::Any aAny = xParagraphPropertySet->getPropertyValue("CharWeight"); + + OUString sWeight = (aAny.get<float>() >= awt::FontWeight::BOLD) ? OUString("BOLD") : OUString("NORMAL"); + + aResult.push_back({ svx::ClassificationType::PARAGRAPH, sWeight, sBlank }); + + // Process portions.. while (xTextPortions->hasMoreElements()) { uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY); @@ -762,33 +828,32 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio OUString aName; uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY); xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName; - const OUString sBlank(""); + if (aName.startsWith(sPolicy + "Marking:Text:")) { const OUString aValue = lcl_getProperty(xPropertyContainer, aName); if (!aValue.isEmpty()) - aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name")) { const OUString aValue = lcl_getProperty(xPropertyContainer, aName); if (!aValue.isEmpty()) - aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "Extension:Marking")) { const OUString aValue = lcl_getProperty(xPropertyContainer, aName); if (!aValue.isEmpty()) - aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart")) { const OUString aValue = lcl_getProperty(xPropertyContainer, aName); if (!aValue.isEmpty()) - aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank }); } } - ++nParagraph; } return aResult; @@ -917,6 +982,11 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe for (size_t nIndex = 0; nIndex < aResults.size(); ++nIndex) { const svx::ClassificationResult& rResult = aResults[nIndex]; + + // Ignore "PARAGRAPH" types + if (rResult.meType == svx::ClassificationType::PARAGRAPH) + continue; + const bool isLast = nIndex == 0; const bool isFirst = nIndex == aResults.size() - 1; OUString sKey; @@ -981,7 +1051,6 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassificati uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); const OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType()); - const sal_Int32 nParagraph = 1; while (xTextPortions->hasMoreElements()) { @@ -1006,19 +1075,19 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassificati const OUString sBlank(""); if (aName.startsWith(sPolicy + "Marking:Text:")) { - aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name")) { - aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "Extension:Marking")) { - aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank }); } else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart")) { - aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), sBlank, nParagraph }); + aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), sBlank }); } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits