summaryrefslogtreecommitdiff
path: root/sw/source/core
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2021-05-23 12:46:09 +0200
committerLászló Németh <nemeth@numbertext.org>2021-05-23 18:51:58 +0200
commita8a9b4f4635bff3f1b7ec63b62f661bc15196cd6 (patch)
tree03b0f7ce90c36b5fce9e73015f5c951cc936e444 /sw/source/core
parenta04ac0ecea9468cedea3bba85fb65cad5f911a2a (diff)
tdf#142448 sw offapi: add custom color metadata field shading
using the new com::sun::star::rdf::URIs::LO_EXT_SHADING URI (modelled after odf:prefix and odf:suffix). Custom color field shading of text:meta annotated text ranges and text:meta-field metadata fields allows quick visual check of metadata categories. For example, RDF triple content.xml#id1753384014 urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading FF0000 sets red (FF0000) shading color for the text span with xml:id="id1753384014". Pressing Ctrl-F8 or View->Field Shadings can disable custom color metadata field shading on the UI. Note: neither LO_EXT_SHADING, nor odf:prefix and odf:suffix changes invalidate the View (MetaPortion), but run-time update of shading color can be triggered without save and reload of the document e.g. by using (temporary) bookmarks on the annotated text spans. To run unit test with enabled visibility, use (cd sw && make UITest_sw_styleInspector UITEST_TEST_NAME="styleInspector.styleNavigator.test_metadata_shading_color" SAL_USE_VCLPLUGIN=gen) in Linux command line. Change-Id: I5de93cfa32ac6793d7dbdc7b64e6f4beacb2e8d7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116015 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source/core')
-rw-r--r--sw/source/core/inc/unometa.hxx2
-rw-r--r--sw/source/core/text/inftxt.cxx12
-rw-r--r--sw/source/core/text/inftxt.hxx4
-rw-r--r--sw/source/core/text/itrform2.cxx65
-rw-r--r--sw/source/core/text/txtfld.cxx3
-rw-r--r--sw/source/core/txtnode/fmtatr2.cxx4
-rw-r--r--sw/source/core/unocore/unorefmk.cxx27
7 files changed, 97 insertions, 20 deletions
diff --git a/sw/source/core/inc/unometa.hxx b/sw/source/core/inc/unometa.hxx
index ea4c3e66836c..ca298fcd8f63 100644
--- a/sw/source/core/inc/unometa.hxx
+++ b/sw/source/core/inc/unometa.hxx
@@ -263,7 +263,7 @@ public:
void getPrefixAndSuffix(
const css::uno::Reference< css::frame::XModel>& xModel,
const css::uno::Reference< css::rdf::XMetadatable>& xMetaField,
- OUString *const o_pPrefix, OUString *const o_pSuffix);
+ OUString *const o_pPrefix, OUString *const o_pSuffix, OUString *const o_pShadowColor);
#endif // INCLUDED_SW_SOURCE_CORE_INC_UNOMETA_HXX
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index c399ac758a24..6e5318097e2b 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -1125,7 +1125,7 @@ void SwTextPaintInfo::DrawCheckBox(const SwFieldFormCheckboxPortion &rPor, bool
m_pOut->Pop();
}
-void SwTextPaintInfo::DrawBackground( const SwLinePortion &rPor ) const
+void SwTextPaintInfo::DrawBackground( const SwLinePortion &rPor, const Color *pColor ) const
{
OSL_ENSURE( OnWin(), "SwTextPaintInfo::DrawBackground: printer pollution ?" );
@@ -1145,7 +1145,11 @@ void SwTextPaintInfo::DrawBackground( const SwLinePortion &rPor ) const
}
else
{
- pOut->SetFillColor( SwViewOption::GetFieldShadingsColor() );
+ if ( pColor )
+ pOut->SetFillColor( *pColor );
+ else
+ pOut->SetFillColor( SwViewOption::GetFieldShadingsColor() );
+
pOut->SetLineColor();
}
@@ -1313,7 +1317,7 @@ void SwTextPaintInfo::DrawBorder( const SwLinePortion &rPor ) const
}
void SwTextPaintInfo::DrawViewOpt( const SwLinePortion &rPor,
- PortionType nWhich ) const
+ PortionType nWhich, const Color *pColor ) const
{
if( !OnWin() || IsMulti() )
return;
@@ -1366,7 +1370,7 @@ void SwTextPaintInfo::DrawViewOpt( const SwLinePortion &rPor,
}
}
if ( bDraw )
- DrawBackground( rPor );
+ DrawBackground( rPor, pColor );
}
static void lcl_InitHyphValues( PropertyValues &rVals,
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx
index bb245d5b031f..f11ea65ed918 100644
--- a/sw/source/core/text/inftxt.hxx
+++ b/sw/source/core/text/inftxt.hxx
@@ -399,8 +399,8 @@ public:
void DrawLineBreak( const SwLinePortion &rPor ) const;
void DrawRedArrow( const SwLinePortion &rPor ) const;
void DrawPostIts( bool bScript ) const;
- void DrawBackground( const SwLinePortion &rPor ) const;
- void DrawViewOpt( const SwLinePortion &rPor, PortionType nWhich ) const;
+ void DrawBackground( const SwLinePortion &rPor, const Color *pColor=nullptr ) const;
+ void DrawViewOpt( const SwLinePortion &rPor, PortionType nWhich, const Color *pColor=nullptr ) const;
void DrawBackBrush( const SwLinePortion &rPor ) const;
/**
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index e672eabb3fce..2eddba6c1c6e 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -54,8 +54,15 @@
#include <IDocumentSettingAccess.hxx>
#include <IMark.hxx>
#include <IDocumentMarkAccess.hxx>
-
-#include <vector>
+#include <comphelper/processfactory.hxx>
+#include <docsh.hxx>
+#include <unocrsrhelper.hxx>
+#include <com/sun/star/rdf/Statement.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/URIs.hpp>
+#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
+#include <com/sun/star/rdf/XLiteral.hpp>
+#include <com/sun/star/text/XTextContent.hpp>
using namespace ::com::sun::star;
@@ -842,9 +849,11 @@ namespace {
class SwMetaPortion : public SwTextPortion
{
+ Color m_aShadowColor;
public:
SwMetaPortion() { SetWhichPor( PortionType::Meta ); }
virtual void Paint( const SwTextPaintInfo &rInf ) const override;
+ void SetShadowColor(const Color& rCol ) { m_aShadowColor = rCol; }
};
}
@@ -853,7 +862,12 @@ void SwMetaPortion::Paint( const SwTextPaintInfo &rInf ) const
{
if ( Width() )
{
- rInf.DrawViewOpt( *this, PortionType::Meta );
+ rInf.DrawViewOpt( *this, PortionType::Meta,
+ // custom shading (RDF metadata)
+ COL_BLACK == m_aShadowColor
+ ? nullptr
+ : &m_aShadowColor );
+
SwTextPortion::Paint( rInf );
}
}
@@ -919,7 +933,50 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const
pPor = new SwRefPortion;
else if (GetFnt()->IsMeta())
{
- pPor = new SwMetaPortion;
+ auto pMetaPor = new SwMetaPortion;
+
+ // set custom LO_EXT_SHADING color, if it exists
+ SwTextFrame const*const pFrame(rInf.GetTextFrame());
+ SwPosition aPosition(pFrame->MapViewToModelPos(rInf.GetIdx()));
+ SwPaM aPam(aPosition);
+ uno::Reference<text::XTextContent> const xRet(
+ SwUnoCursorHelper::GetNestedTextContent(
+ *aPam.GetNode().GetTextNode(), aPosition.nContent.GetIndex(), false) );
+ if (xRet.is())
+ {
+ const SwDoc & rDoc = rInf.GetTextFrame()->GetDoc();
+ static uno::Reference< uno::XComponentContext > xContext(
+ ::comphelper::getProcessComponentContext());
+
+ static uno::Reference< rdf::XURI > xODF_SHADING(
+ rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING), uno::UNO_SET_THROW);
+
+ uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(
+ rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+
+ const css::uno::Reference<css::rdf::XResource> xSubject(xRet, uno::UNO_QUERY);
+ const uno::Reference<rdf::XRepository>& xRepository =
+ xDocumentMetadataAccess->getRDFRepository();
+ const uno::Reference<container::XEnumeration> xEnum(
+ xRepository->getStatements(xSubject, xODF_SHADING, nullptr), uno::UNO_SET_THROW);
+
+ while (xEnum->hasMoreElements())
+ {
+ rdf::Statement stmt;
+ if (!(xEnum->nextElement() >>= stmt)) {
+ throw uno::RuntimeException();
+ }
+ const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY);
+ if (!xObject.is()) continue;
+ if (xEnum->hasMoreElements()) {
+ SAL_INFO("sw.uno", "ignoring other odf:shading statements");
+ }
+ Color rColor = Color::STRtoRGB(xObject->getValue());
+ pMetaPor->SetShadowColor(rColor);
+ break;
+ }
+ }
+ pPor = pMetaPor;
}
else
{
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index e150f7f489f1..c1375b52fe09 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -304,7 +304,8 @@ static SwFieldPortion * lcl_NewMetaPortion(SwTextAttr & rHint, const bool bPrefi
OSL_ENSURE(pField, "lcl_NewMetaPortion: no meta field?");
if (pField)
{
- pField->GetPrefixAndSuffix(bPrefix ? &fix : nullptr, bPrefix ? nullptr : &fix);
+ OUString color;
+ pField->GetPrefixAndSuffix(bPrefix ? &fix : nullptr, bPrefix ? nullptr : &fix, &color);
}
return new SwFieldPortion( fix );
}
diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx
index 73eb992c5c97..afc82565c515 100644
--- a/sw/source/core/txtnode/fmtatr2.cxx
+++ b/sw/source/core/txtnode/fmtatr2.cxx
@@ -730,7 +730,7 @@ MetaField::MetaField(SwFormatMeta * const i_pFormat,
}
void MetaField::GetPrefixAndSuffix(
- OUString *const o_pPrefix, OUString *const o_pSuffix)
+ OUString *const o_pPrefix, OUString *const o_pSuffix, OUString *const o_pShadowsColor)
{
try
{
@@ -743,7 +743,7 @@ void MetaField::GetPrefixAndSuffix(
SwDocShell const * const pShell(pTextNode->GetDoc().GetDocShell());
const uno::Reference<frame::XModel> xModel(
pShell ? pShell->GetModel() : nullptr, uno::UNO_SET_THROW);
- getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
+ getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix, o_pShadowsColor);
}
}
catch (const uno::Exception&)
diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx
index a88d2d4f8a98..3156ef10ed35 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -1422,7 +1422,7 @@ SwXMetaField::removeVetoableChangeListener(
}
static uno::Reference<rdf::XURI> const&
-lcl_getURI(const bool bPrefix)
+lcl_getURI(const sal_Int16 eKnown)
{
static uno::Reference< uno::XComponentContext > xContext(
::comphelper::getProcessComponentContext());
@@ -1432,7 +1432,18 @@ lcl_getURI(const bool bPrefix)
static uno::Reference< rdf::XURI > xOdfSuffix(
rdf::URI::createKnown(xContext, rdf::URIs::ODF_SUFFIX),
uno::UNO_SET_THROW);
- return bPrefix ? xOdfPrefix : xOdfSuffix;
+ static uno::Reference< rdf::XURI > xOdfShading(
+ rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING),
+ uno::UNO_SET_THROW);
+ switch (eKnown)
+ {
+ case rdf::URIs::ODF_PREFIX:
+ return xOdfPrefix;
+ case rdf::URIs::ODF_SUFFIX:
+ return xOdfSuffix;
+ default:
+ return xOdfShading;
+ }
}
static OUString
@@ -1464,7 +1475,7 @@ void
getPrefixAndSuffix(
const uno::Reference<frame::XModel>& xModel,
const uno::Reference<rdf::XMetadatable>& xMetaField,
- OUString *const o_pPrefix, OUString *const o_pSuffix)
+ OUString *const o_pPrefix, OUString *const o_pSuffix, OUString *const o_pShadingColor)
{
try {
const uno::Reference<rdf::XRepositorySupplier> xRS(
@@ -1475,11 +1486,15 @@ getPrefixAndSuffix(
xMetaField, uno::UNO_QUERY_THROW);
if (o_pPrefix)
{
- *o_pPrefix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(true));
+ *o_pPrefix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(rdf::URIs::ODF_PREFIX));
}
if (o_pSuffix)
{
- *o_pSuffix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(false));
+ *o_pSuffix = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(rdf::URIs::ODF_SUFFIX));
+ }
+ if (o_pShadingColor)
+ {
+ *o_pShadingColor = lcl_getPrefixOrSuffix(xRepo, xMeta, lcl_getURI(rdf::URIs::LO_EXT_SHADING));
}
} catch (uno::RuntimeException &) {
throw;
@@ -1506,7 +1521,7 @@ SwXMetaField::getPresentation(sal_Bool bShowCommand)
const OUString content( getString() );
OUString prefix;
OUString suffix;
- getPrefixAndSuffix(GetModel(), this, &prefix, &suffix);
+ getPrefixAndSuffix(GetModel(), this, &prefix, &suffix, nullptr);
return prefix + content + suffix;
}
}