sc/source/filter/inc/rtfexp.hxx |    5 ++
 sc/source/filter/rtf/rtfexp.cxx |   75 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

New commits:
commit cb72f56977faccbda9490bc16ea3cbf7a22c01b0
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Tue Jul 25 15:36:52 2023 -0400
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Sep 1 16:19:48 2023 +0200

    sc: filter: rtf: add method "WriteFontTable"
    
    Write the font table while visiting column/row and
    get the unique index to reference it.
    
    "The \fonttbl control word introduces the font table group.
    Unique \fN control words define each font available in the document,
    and are used to reference that font throughout the document."
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I20c5d1128972f5ec9b9b2e246f466bdb173ef8a4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154906
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156415
    Tested-by: Jenkins

diff --git a/sc/source/filter/inc/rtfexp.hxx b/sc/source/filter/inc/rtfexp.hxx
index 1c9f1bd7a4af..9d0b204540c7 100644
--- a/sc/source/filter/inc/rtfexp.hxx
+++ b/sc/source/filter/inc/rtfexp.hxx
@@ -28,12 +28,14 @@ class ScRTFExport : public ScExportBase
 {
     std::unique_ptr<sal_uLong[]>  m_pCellX;     // cumulative range in a table
     std::map<OUString, sal_Int32> m_pFontTable;
+    SvMemoryStream m_aFontStrm;
     SvMemoryStream m_aDocStrm;
 
     int                 AddFont( const SvxFontItem& rFontItem );
     void                WriteTab( SCTAB nTab );
     void                WriteRow( SCTAB nTab, SCROW nRow );
     void                WriteCell( SCTAB nTab,  SCROW nRow, SCCOL nCol );
+    void                WriteFontTable(const SvxFontItem& rFontItem, int 
nIndex);
 
 public:
 
diff --git a/sc/source/filter/rtf/rtfexp.cxx b/sc/source/filter/rtf/rtfexp.cxx
index 8d38def244b3..7349aa698591 100644
--- a/sc/source/filter/rtf/rtfexp.cxx
+++ b/sc/source/filter/rtf/rtfexp.cxx
@@ -19,6 +19,9 @@
 
 #include <scitems.hxx>
 
+#include <rtl/tencinfo.h>
+#include <osl/thread.h>
+
 #include <editeng/wghtitem.hxx>
 #include <editeng/postitem.hxx>
 #include <editeng/udlnitem.hxx>
@@ -60,6 +63,8 @@ void ScRTFExport::Write()
     rStrm.WriteChar( '{' ).WriteOString( OOO_STRING_SVTOOLS_RTF_RTF );
     rStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_ANSI ).WriteOString( 
SAL_NEWLINE_STRING );
 
+    m_aFontStrm.WriteChar( '{' ).WriteOString( OOO_STRING_SVTOOLS_RTF_FONTTBL 
);
+
     // Data
     for ( SCTAB nTab = aRange.aStart.Tab(); nTab <= aRange.aEnd.Tab(); nTab++ )
     {
@@ -68,6 +73,9 @@ void ScRTFExport::Write()
         WriteTab( nTab );
     }
 
+    m_aFontStrm.WriteChar( '}' );
+    m_aFontStrm.Seek(0);
+    rStrm.WriteStream(m_aFontStrm);
     m_aDocStrm.Seek(0);
     rStrm.WriteStream(m_aDocStrm);
     rStrm.WriteChar( '}' ).WriteOString( SAL_NEWLINE_STRING );
@@ -148,6 +156,51 @@ void ScRTFExport::WriteRow( SCTAB nTab, SCROW nRow )
     m_aDocStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_ROW ).WriteOString( 
SAL_NEWLINE_STRING );
 }
 
+void ScRTFExport::WriteFontTable(const SvxFontItem& rFontItem, int nIndex)
+{
+    m_aFontStrm.WriteChar( '{' );
+    m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_F );
+    m_aFontStrm.WriteOString( OString::number(nIndex) );
+
+    FontFamily eFamily = rFontItem.GetFamily();
+    if (eFamily == FAMILY_DONTKNOW)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FNIL );
+    else if (eFamily == FAMILY_DECORATIVE)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FDECOR );
+    else if (eFamily == FAMILY_MODERN)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FMODERN );
+    else if (eFamily == FAMILY_ROMAN)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FROMAN );
+    else if (eFamily == FAMILY_SCRIPT)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FSCRIPT );
+    else if (eFamily == FAMILY_SWISS)
+        m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FSWISS );
+
+    m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FPRQ );
+
+    sal_uInt16 nVal = 0;
+    FontPitch ePitch = rFontItem.GetPitch();
+    if ( ePitch == PITCH_FIXED )
+        nVal = 1;
+    else if ( ePitch == PITCH_VARIABLE )
+        nVal = 2;
+    m_aFontStrm.WriteOString( OString::number(nVal) );
+
+    rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_MS_1252;
+    rtl_TextEncoding eChrSet = rFontItem.GetCharSet();
+    if (IsOpenSymbol(rFontItem.GetFamilyName()))
+        eChrSet = RTL_TEXTENCODING_UTF8;
+    else if( RTL_TEXTENCODING_DONTKNOW == eChrSet )
+        eChrSet = osl_getThreadTextEncoding();
+
+    m_aFontStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_FCHARSET );
+    m_aFontStrm.WriteOString( 
OString::number(rtl_getBestWindowsCharsetFromTextEncoding( eChrSet )) );
+
+    m_aFontStrm.WriteChar( ' ' );
+    RTFOutFuncs::Out_String( m_aFontStrm, rFontItem.GetFamilyName(), eDestEnc 
);
+    m_aFontStrm.WriteOString( ";}" );
+}
+
 int ScRTFExport::AddFont(const SvxFontItem& rFontItem)
 {
     auto nRet = m_pFontTable.size();
@@ -155,6 +208,7 @@ int ScRTFExport::AddFont(const SvxFontItem& rFontItem)
     if (itFont == m_pFontTable.end())
     {
         m_pFontTable[rFontItem.GetFamilyName()] = nRet;
+        WriteFontTable(rFontItem, nRet);
     }
     else
     {
@@ -204,11 +258,15 @@ void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, 
SCCOL nCol )
 
     bool bResetAttr(false);
 
+    const SvxFontItem&          rFontItem       = pAttr->GetItem( ATTR_FONT );
     const SvxHorJustifyItem&    rHorJustifyItem = pAttr->GetItem( 
ATTR_HOR_JUSTIFY );
     const SvxWeightItem&        rWeightItem     = pAttr->GetItem( 
ATTR_FONT_WEIGHT );
     const SvxPostureItem&       rPostureItem    = pAttr->GetItem( 
ATTR_FONT_POSTURE );
     const SvxUnderlineItem&     rUnderlineItem  = pAttr->GetItem( 
ATTR_FONT_UNDERLINE );
 
+    m_aDocStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_F )
+        .WriteOString( OString::number(AddFont(rFontItem)) );
+
     const char* pChar;
 
     switch( rHorJustifyItem.GetValue() )
commit f0b2a9b1b33b55487dacc0998736dd403416d4df
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Tue Jul 25 15:31:22 2023 -0400
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Sep 1 16:19:40 2023 +0200

    sc: filter: rtf: add method "AddFont"
    
    Create a map font name associated with unique index.
    
    "The \fonttbl control word introduces the font table group.
    Unique \fN control words define each font available in the document,
    and are used to reference that font throughout the document"..
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I028226cb539865f1980f953385c887a3bd4b8e3f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154905
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156414

diff --git a/sc/source/filter/inc/rtfexp.hxx b/sc/source/filter/inc/rtfexp.hxx
index 14ee8ec023f7..1c9f1bd7a4af 100644
--- a/sc/source/filter/inc/rtfexp.hxx
+++ b/sc/source/filter/inc/rtfexp.hxx
@@ -19,6 +19,7 @@
 
 #pragma once
 
+#include <map>
 #include <memory>
 #include "expbase.hxx"
 #include <tools/solar.h>
@@ -26,8 +27,10 @@
 class ScRTFExport : public ScExportBase
 {
     std::unique_ptr<sal_uLong[]>  m_pCellX;     // cumulative range in a table
+    std::map<OUString, sal_Int32> m_pFontTable;
     SvMemoryStream m_aDocStrm;
 
+    int                 AddFont( const SvxFontItem& rFontItem );
     void                WriteTab( SCTAB nTab );
     void                WriteRow( SCTAB nTab, SCROW nRow );
     void                WriteCell( SCTAB nTab,  SCROW nRow, SCCOL nCol );
diff --git a/sc/source/filter/rtf/rtfexp.cxx b/sc/source/filter/rtf/rtfexp.cxx
index 99336e6f022c..8d38def244b3 100644
--- a/sc/source/filter/rtf/rtfexp.cxx
+++ b/sc/source/filter/rtf/rtfexp.cxx
@@ -22,6 +22,7 @@
 #include <editeng/wghtitem.hxx>
 #include <editeng/postitem.hxx>
 #include <editeng/udlnitem.hxx>
+#include <editeng/fontitem.hxx>
 #include <editeng/justifyitem.hxx>
 #include <svtools/rtfout.hxx>
 #include <svtools/rtfkeywd.hxx>
@@ -147,6 +148,22 @@ void ScRTFExport::WriteRow( SCTAB nTab, SCROW nRow )
     m_aDocStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_ROW ).WriteOString( 
SAL_NEWLINE_STRING );
 }
 
+int ScRTFExport::AddFont(const SvxFontItem& rFontItem)
+{
+    auto nRet = m_pFontTable.size();
+    auto itFont(m_pFontTable.find(rFontItem.GetFamilyName()));
+    if (itFont == m_pFontTable.end())
+    {
+        m_pFontTable[rFontItem.GetFamilyName()] = nRet;
+    }
+    else
+    {
+        nRet = itFont->second;
+    }
+
+    return nRet;
+}
+
 void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, SCCOL nCol )
 {
     const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );

Reply via email to