editeng/source/editeng/editview.cxx      |    5 ++
 editeng/source/editeng/impedit.hxx       |    1 
 editeng/source/editeng/impedit4.cxx      |   55 +++++++++++++++++++++++++++++++
 include/editeng/editview.hxx             |    1 
 sw/inc/AnnotationWin.hxx                 |    2 +
 sw/source/uibase/docvw/AnnotationWin.cxx |    5 ++
 sw/source/uibase/docvw/PostItMgr.cxx     |    1 
 sw/source/uibase/uno/unotxdoc.cxx        |    1 
 8 files changed, 71 insertions(+)

New commits:
commit 5212833fa0ec1aa5cb9112c67a3715a9ddf57168
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Oct 2 14:20:55 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Oct 5 20:55:15 2024 +0200

    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 <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174504
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/editeng/source/editeng/editview.cxx 
b/editeng/source/editeng/editview.cxx
index d76f0a1c69c0..590b2680834c 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -668,6 +668,11 @@ ErrCode EditView::Read( SvStream& rInput, EETextFormat 
eFormat, SvKeyValueIterat
     return rInput.GetError();
 }
 
+OString EditView::GetSimpleHtml() const
+{
+    return mpImpEditView->mpEditEngine->mpImpEditEngine->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 d9d8f6ea8b4a..3387607c4c5b 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -1039,6 +1039,7 @@ public:
     EditPaM         Read( SvStream& rInput, const OUString& rBaseURL, 
EETextFormat eFormat, const EditSelection& rSel, SvKeyValueIterator* 
pHTTPHeaderAttrs = nullptr);
     void            Write( SvStream& rOutput, EETextFormat eFormat );
     void            Write(SvStream& rOutput, EETextFormat eFormat, const 
EditSelection& rSel);
+    OString         GetSimpleHtml() const;
 
     std::unique_ptr<EditTextObject> CreateTextObject(sal_Int32 nPara, 
sal_Int32 nParas);
     std::unique_ptr<EditTextObject> CreateTextObject();
diff --git a/editeng/source/editeng/impedit4.cxx 
b/editeng/source/editeng/impedit4.cxx
index 7df703d9e559..0417e8f3f4ec 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>
@@ -1067,6 +1068,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 a1cb4eb9603b..9672506dc9a4 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -277,6 +277,7 @@ public:
     void                RemoveAttribsKeepLanguages( bool bRemoveParaAttribs );
 
     SAL_DLLPRIVATE 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 291978eee471..0a91496bea86 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -78,6 +78,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();
@@ -107,6 +108,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 1ad47437caa7..bfd777c68630 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 2d4ff760c04b..447731267b40 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -176,6 +176,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 60332a6f7b78..2880505e7db6 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3496,6 +3496,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());

Reply via email to