summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-10-02 14:20:55 +0100
committerMiklos Vajna <vmiklos@collabora.com>2024-10-04 13:30:32 +0200
commitac5d2b5bad52179f2930f9baac8f78ec90d7ee11 (patch)
tree7240f1ca73e26cf7671a7d6760853f2f703d3a01
parentdbb054045fae8605794c17aae052a9d588fe33fc (diff)
add a 'simple-html' export to editeng
currently justs supports hyperlinks and nothing else over plain text. puts each paragraph in a separate div Change-Id: I645d28e0bb6ed13e930e1555753846d10ecf5dd9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174388 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--editeng/source/editeng/editview.cxx5
-rw-r--r--editeng/source/editeng/impedit.hxx1
-rw-r--r--editeng/source/editeng/impedit4.cxx55
-rw-r--r--include/editeng/editview.hxx1
-rw-r--r--sw/inc/AnnotationWin.hxx2
-rw-r--r--sw/source/uibase/docvw/AnnotationWin.cxx5
-rw-r--r--sw/source/uibase/docvw/PostItMgr.cxx1
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx1
8 files changed, 71 insertions, 0 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index d4b60fecf415..0be3f1d1cb96 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -666,6 +666,11 @@ ErrCode EditView::Read( SvStream& rInput, EETextFormat eFormat, SvKeyValueIterat
return rInput.GetError();
}
+OString EditView::GetSimpleHtml() const
+{
+ return pImpEditView->pEditEngine->pImpEditEngine->GetSimpleHtml();
+}
+
void EditView::Cut()
{
Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard());
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 6c6ddf43f135..58a72816d8fb 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -929,6 +929,7 @@ public:
EditPaM Read(SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, const EditSelection& rSel, SvKeyValueIterator* pHTTPHeaderAttrs = nullptr);
void Write(SvStream& rOutput, EETextFormat eFormat, const EditSelection& rSel);
+ OString GetSimpleHtml() const;
std::unique_ptr<EditTextObject> CreateTextObject();
std::unique_ptr<EditTextObject> CreateTextObject(const EditSelection& rSel);
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index d3dc29892d6a..adbdf2ccee62 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -58,6 +58,7 @@
#include <editeng/emphasismarkitem.hxx>
#include "textconv.hxx"
#include <rtl/tencinfo.h>
+#include <svtools/htmlout.hxx>
#include <svtools/rtfout.hxx>
#include <tools/stream.hxx>
#include <edtspell.hxx>
@@ -1039,6 +1040,60 @@ void ImpEditEngine::WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput,
}
}
+// Currently not good enough to be used for a ::Write of EETextFormat::Html, it
+// only supports hyperlinks over plain text
+OString ImpEditEngine::GetSimpleHtml() const
+{
+ OStringBuffer aOutput;
+
+ sal_Int32 nStartNode = 0;
+ sal_Int32 nEndNode = maEditDoc.Count()-1;
+
+ // iterate over the paragraphs ...
+ for (sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++)
+ {
+ const ContentNode* pNode = maEditDoc.GetObject( nNode );
+
+ const ParaPortion* pParaPortion = FindParaPortion( pNode );
+
+ sal_Int32 nIndex = 0;
+ sal_Int32 nEndPortion = pParaPortion->GetTextPortions().Count() - 1;
+
+ aOutput.append("<div>");
+ for (sal_Int32 n = 0; n <= nEndPortion; n++)
+ {
+ const TextPortion& rTextPortion = pParaPortion->GetTextPortions()[n];
+
+ const SvxURLField* pURLField = nullptr;
+ if ( rTextPortion.GetKind() == PortionKind::FIELD )
+ {
+ const EditCharAttrib* pAttr = pNode->GetCharAttribs().FindFeature(nIndex);
+ const SvxFieldItem* pFieldItem = dynamic_cast<const SvxFieldItem*>(pAttr->GetItem());
+ if( pFieldItem )
+ {
+ const SvxFieldData* pFieldData = pFieldItem->GetField();
+ pURLField = dynamic_cast<const SvxURLField*>(pFieldData);
+ }
+ }
+
+ OUString aRTFStr = EditDoc::GetParaAsString(pNode, nIndex, nIndex + rTextPortion.GetLen());
+ if (pURLField)
+ aOutput.append("<a href=\"" + pURLField->GetURL().toUtf8() + "\">");
+
+ aOutput.append(HTMLOutFuncs::ConvertStringToHTML(aRTFStr));
+
+ if (pURLField)
+ aOutput.append("</a>");
+
+ nIndex = nIndex + rTextPortion.GetLen();
+ }
+
+ aOutput.append("</div>");
+ }
+
+ return aOutput.makeStringAndClear();
+}
+
std::unique_ptr<EditTextObject> ImpEditEngine::GetEmptyTextObject()
{
EditSelection aEmptySel;
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index 0bafa99bb35f..852e43e9e5ff 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -279,6 +279,7 @@ public:
void RemoveAttribsKeepLanguages( bool bRemoveParaAttribs );
ErrCode Read( SvStream& rInput, EETextFormat eFormat, SvKeyValueIterator* pHTTPHeaderAttrs );
+ OString GetSimpleHtml() const;
void SetBackgroundColor( const Color& rColor );
Color const & GetBackgroundColor() const;
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index 235a1a70b587..91c98155f05c 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -77,6 +77,7 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public InterimItemWindow
OUString GetAuthor() const;
Date GetDate() const;
tools::Time GetTime() const;
+ OString GetSimpleHtml() const;
void GeneratePostItName();
sal_uInt32 MoveCaret();
@@ -105,6 +106,7 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public InterimItemWindow
SwSidebarItem& GetSidebarItem() { return mrSidebarItem; }
OutlinerView* GetOutlinerView() { return mpOutlinerView.get();}
+ const OutlinerView* GetOutlinerView() const { return mpOutlinerView.get();}
Outliner* GetOutliner() { return mpOutliner.get();}
bool HasScrollbar() const;
bool IsScrollbarVisible() const;
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx
index 3bb933f61fbd..77e7421cb127 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -499,6 +499,11 @@ void SwAnnotationWin::UpdateHTML(const OUString& rHtml)
UpdateData();
}
+OString SwAnnotationWin::GetSimpleHtml() const
+{
+ return GetOutlinerView()->GetEditView().GetSimpleHtml();
+}
+
bool SwAnnotationWin::IsReadOnlyOrProtected() const
{
return mbReadonly ||
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index bc4df5ecb409..4768a62f1339 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -174,6 +174,7 @@ namespace {
aAnnotation.put("parentId", pField->GetParentPostItId());
aAnnotation.put("author", pField->GetPar1().toUtf8().getStr());
aAnnotation.put("text", pField->GetPar2().toUtf8().getStr());
+ aAnnotation.put("html", pWin->GetSimpleHtml());
aAnnotation.put("resolved", pField->GetResolved() ? "true" : "false");
aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
aAnnotation.put("anchorPos", aSVRect.toString());
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 0571fc2947eb..c103d218de0d 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3383,6 +3383,7 @@ void SwXTextDocument::getPostIts(tools::JsonWriter& rJsonWriter)
rJsonWriter.put("parentId", pField->GetParentPostItId());
rJsonWriter.put("author", pField->GetPar1());
rJsonWriter.put("text", pField->GetPar2());
+ rJsonWriter.put("html", pWin->GetSimpleHtml());
rJsonWriter.put("resolved", pField->GetResolved() ? "true" : "false");
rJsonWriter.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
rJsonWriter.put("anchorPos", aSVRect.toString());