sw/source/filter/html/htmlflywriter.cxx |   38 ++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

New commits:
commit e2ee51b6b2aa2cbb347f99b8c7b1aee0ad8e5f9c
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jun 28 18:50:48 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Jun 29 09:37:10 2023 +0200

    ReqIF: output frame text instead of name in 'object' elements' alt text
    
    Change-Id: I79d827edf00143e06b2601018fdf647d6d342355
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153721
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 4dcd5129ca2e..d404e305e172 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1227,6 +1227,34 @@ OUString lclWriteOutImap(SwHTMLWriter& rWrt, const 
SfxItemSet& rItemSet, const S
     return aIMapName;
 }
 
+OUString getFrameFormatText(const SwFrameFormat& rFrameFormat)
+{
+    const SwFormatContent& rFlyContent = rFrameFormat.GetContent();
+    const SwNodeIndex* pSttIx = rFlyContent.GetContentIdx();
+    if (!pSttIx)
+        return {};
+
+    const SwNodeOffset nStt = pSttIx->GetIndex();
+    const auto& nodes = rFrameFormat.GetDoc()->GetNodes();
+    const SwNodeOffset nEnd = nodes[nStt]->EndOfSectionIndex();
+
+    OUStringBuffer result;
+    for (SwNodeOffset i = nStt + 1; i < nEnd; ++i)
+    {
+        if (const auto* pTextNd = nodes[i]->GetTextNode())
+        {
+            if (!result.isEmpty())
+                result.append("\n");
+            result.append(pTextNd->GetExpandText(
+                nullptr, 0, -1, true, true, false,
+                ExpandMode::ExpandFields | ExpandMode::HideInvisible | 
ExpandMode::HideDeletions
+                | ExpandMode::HideFieldmarkCommands));
+        }
+    }
+
+    return result.makeStringAndClear();
+}
+
 }
 
 SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const 
SwFrameFormat &rFrameFormat,
@@ -1449,13 +1477,19 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, 
SwHTMLWriter& rWrt, const S
 
     if (bReplacement)
     {
+        OUString aAltText = rAlternateText;
+        // In ReqIF mode, output text from the frame instead
+        if (rWrt.mbReqIF)
+            if (OUString aFrameText = getFrameFormatText(rFrameFormat); 
!aFrameText.isEmpty())
+                aAltText = aFrameText;
+
         // XHTML object replacement image's alternate text doesn't use the
         // "alt" attribute.
-        if (rAlternateText.isEmpty())
+        if (aAltText.isEmpty())
             // Empty alternate text is not valid.
             rHtml.characters(" ");
         else
-            rHtml.characters(rAlternateText.toUtf8());
+            rHtml.characters(aAltText.toUtf8());
     }
 
     return rWrt;

Reply via email to