sc/source/filter/inc/rtfexp.hxx | 5 ++ sc/source/filter/rtf/rtfexp.cxx | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)
New commits: commit ec17398bfbde2d516d5afdf4f66a40f98fae3c26 Author: Henry Castro <[email protected]> AuthorDate: Tue Jul 25 15:36:52 2023 -0400 Commit: Caolán McNamara <[email protected]> CommitDate: Mon Jul 31 16:33:00 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 <[email protected]> Change-Id: I20c5d1128972f5ec9b9b2e246f466bdb173ef8a4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154906 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> 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 59e67d6442b9..fd96f11d7b9b 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( '{' ).WriteCharPtr( OOO_STRING_SVTOOLS_RTF_RTF ); rStrm.WriteCharPtr( OOO_STRING_SVTOOLS_RTF_ANSI ).WriteCharPtr( 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 0af19c807a89478f10b23d668e26a953a4d55adb Author: Henry Castro <[email protected]> AuthorDate: Tue Jul 25 15:31:22 2023 -0400 Commit: Caolán McNamara <[email protected]> CommitDate: Mon Jul 31 16:32:53 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 <[email protected]> Change-Id: I028226cb539865f1980f953385c887a3bd4b8e3f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154905 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> 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 487d3226a144..59e67d6442b9 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 );
