diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-10-27 16:03:52 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-10-31 09:53:48 +0100 |
commit | 73f57984110a3c5bb19168dd0789c0c3c809b24e (patch) | |
tree | 9223c3d4c5e39e203c34ce874fe41e23d28b2f57 /svx | |
parent | 13d79459e5d30b927f50885d42f7ce404124a2d0 (diff) |
TSCP: proper collecting and applying of paragraph and text weight
Change-Id: I22edc4adb87706a176c3afa3500963c4a5b46ee7
Reviewed-on: https://gerrit.libreoffice.org/44015
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/dialog/ClassificationDialog.cxx | 48 | ||||
-rw-r--r-- | svx/source/dialog/ClassificationEditView.cxx | 24 |
2 files changed, 59 insertions, 13 deletions
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(); } |