24#include <com/sun/star/text/XTextTable.hpp>
25#include <com/sun/star/text/XTextSection.hpp>
28#include <rtl/ustrbuf.hxx>
91struct SwXMLTableColumnCmpWidth_Impl
102class SwXMLTableColumns_Impl :
public o3tl::sorted_vector<std::unique_ptr<SwXMLTableColumn_Impl>, o3tl::less_uniqueptr_to<SwXMLTableColumn_Impl> > {
129#if OSL_DEBUG_LEVEL > 0
130 sal_uInt32 nEndCPos = 0
U;
132 const size_t nLines = rLines.
size();
133 for(
size_t nLine=0
U; nLine<nLines; ++nLine )
137 const size_t nBoxes = rBoxes.size();
139 sal_uInt32 nCPos = 0
U;
140 for(
size_t nBox=0
U; nBox<nBoxes; ++nBox )
144 if( nBox < nBoxes-1U ||
m_nWidth==0 )
147 std::unique_ptr<SwXMLTableColumn_Impl> pCol(
150 m_aCols.insert( std::move(pCol) );
152 if( nBox==nBoxes-1U )
155 "parent width will be lost" );
161#if OSL_DEBUG_LEVEL > 0
162 sal_uInt32 nCheckPos =
166 nEndCPos = nCheckPos;
170#if OSL_DEBUG_LEVEL > 0
172 OSL_ENSURE(
m_aCols.find(&aCol) !=
m_aCols.end(),
"couldn't find last column" );
175 "rows have different total widths" );
194 ::std::optional<OUString>
AddRow(
SwFrameFormat& rFrameFormat, std::u16string_view rNamePrefix, sal_uInt32 nLine );
196 sal_uInt32 nCol, sal_uInt32 nRow,
bool bTop );
200 std::u16string_view rNamePrefix,
211 if( !pFrameSize && !pBrush && !pRowSplit && !pHasTextChangesOnly )
218 SwXMLFrameFormats_Impl::iterator
i;
232 pTestFrameSize = pItem;
258 pTestRowSplit = pItem;
268 if( !pHasTextChangesOnly )
271 pTestHasTextChangesOnly = pItem;
275 if( pHasTextChangesOnly )
284 if( pBrush && (*pBrush != *pTestBrush) )
290 if( pHasTextChangesOnly && (!pHasTextChangesOnly->GetValue() != !pTestHasTextChangesOnly->GetValue()) )
294 auto const oName(
m_rFormatMap.find(pTestFormat)->second);
301 OUString
const name(OUString::Concat(rNamePrefix) +
"." + OUString::number(nLine+1));
305 return ::std::optional<OUString>(
name);
310 sal_uInt32 nCol, sal_uInt32 nRow,
bool bTop )
316 return OUString::Concat(rNamePrefix) +
"." + sTmp + OUString::number(nRow + 1);
318 return OUString::Concat(rNamePrefix)
319 +
"." + OUString::number(nCol + 1)
320 +
"." + OUString::number(nRow + 1);
324 std::u16string_view rNamePrefix,
325 sal_uInt32 nCol, sal_uInt32 nRow,
bool bTop )
340 if( !pVertOrient && !pBrush && !pBox && !pNumFormat && !pFrameDir && !pAttCnt &&
341 !pHasTextChangesOnly )
353 SwXMLFrameFormats_Impl::iterator
i;
370 pTestVertOrient = pItem;
410 pTestNumFormat = pItem;
425 pTestFrameDir = pItem;
451 if( !pHasTextChangesOnly )
454 pTestHasTextChangesOnly = pItem;
458 if( pHasTextChangesOnly )
466 if( pBrush && ( *pBrush != *pTestBrush ) )
469 if( pBox && ( *pBox != *pTestBox ) )
475 if( pFrameDir && pFrameDir->GetValue() != pTestFrameDir->GetValue() )
478 if( pAttCnt && ( *pAttCnt != *pTestAttCnt ) )
481 if( pHasTextChangesOnly && (!pHasTextChangesOnly->GetValue() != !pTestHasTextChangesOnly->GetValue()) )
485 auto const oName(
m_rFormatMap.find(pTestFormat)->second);
496 return ::std::optional<OUString>(
name);
527 inline void SetBaseSection(
const Reference < XTextSection >& rBase );
535 const Reference < XTextSection >& rBaseSection )
547 bool bEncoded =
false;
561 OUStringBuffer sValue;
565 sValue.makeStringAndClear() );
569 OUString sValue = OUString::number(
static_cast<sal_Int32
>(rCol.
GetRelWidth()) ) +
"*";
583 sal_uInt32 nAbsWidth, sal_uInt32 nBaseWidth,
584 std::u16string_view rNamePrefix,
600 const SwXMLTableColumns_Impl& rCols = pLines->
GetColumns();
601 sal_uInt32 nCPos = 0
U;
602 const size_t nColumns = rCols.size();
603 for(
size_t nColumn=0
U; nColumn<nColumns; ++nColumn )
607 sal_uInt32 nOldCPos = nCPos;
608 nCPos = pColumn->
GetPos();
610 sal_uInt32 nWidth = nCPos - nOldCPos;
626 sal_uInt32 nColAbsWidth = nWidth;
629 nColAbsWidth *= nAbsWidth;
630 nColAbsWidth += (nBaseWidth/2UL);
631 nColAbsWidth /= nBaseWidth;
637 if( it != rExpCols.
end() )
647 pColumn->
SetStyleName( OUString::Concat(rNamePrefix) +
"." + sTmp );
652 OUString::Concat(rNamePrefix) +
"." + OUString::number(nColumn + 1U) );
655 rExpCols.
insert( pColumn );
661 const size_t nLines = rLines.
size();
662 for(
size_t nLine=0
U; nLine<nLines; ++nLine )
667 if (
auto oNew = rExpRows.
AddRow(*pFrameFormat, rNamePrefix, nLine))
673 const size_t nBoxes = rBoxes.size();
675 sal_uInt32 nCPos = 0
U;
677 for(
size_t nBox=0
U; nBox<nBoxes; nBox++ )
681 if( nBox < nBoxes-1U )
687 const size_t nOldCol = nCol;
689 SwXMLTableColumns_Impl::const_iterator it = pLines->
GetColumns().find( &aCol );
690 OSL_ENSURE( it != pLines->
GetColumns().end(),
"couldn't find column" );
697 if (
auto oNew = rExpCells.
AddCell(*pFrameFormat2, rNamePrefix, nOldCol, nLine,
709 Reference < XText > xText( xCell, UNO_QUERY );
712 Reference<XPropertySet> xCellPropertySet( xCell,
714 Any aAny = xCellPropertySet->getPropertyValue(
"TextSection");
715 Reference < XTextSection > xTextSection;
716 aAny >>= xTextSection;
720 const bool bExportContent = bool(
getExportFlags() & SvXMLExportFlags::CONTENT );
721 if ( !bExportContent )
729 OSL_FAIL(
"here should be a XCell");
735 nAbsWidth, nBaseWidth,
737 nOldCol, nLine, bTop ),
738 rExpCols, rExpRows, rExpCells,
750 auto const it(rFormats.find(&rTableNd));
751 assert(it != rFormats.end());
764 sal_uInt32 nBaseWidth = 0;
768 || HoriOrientation::FULL == eTabHoriOri;
771 nBaseWidth = nAbsWidth;
785 pTableFormat->
GetName(), aExpCols, aExpRows, aExpCells,
801 auto const it(rTableInfo.
GetBoxFormats().find(pFrameFormat));
805 assert(!it->second->isEmpty());
814 OUString::number(nRowSpan) );
820 OUString::number(nColSpan) );
834 Reference<XText> xText( xCell, UNO_QUERY );
837 const OUString sCellFormula = xCell->getFormula();
841 if (!sCellFormula.isEmpty())
843 const OUString sQValue =
851 Reference<XPropertySet> xCellPropertySet(xCell,
853 if (xCellPropertySet.is())
855 sal_Int32 nNumberFormat = 0;
856 Any aAny = xCellPropertySet->getPropertyValue(
"NumberFormat");
857 aAny >>= nNumberFormat;
865 else if ( (-1 != nNumberFormat) && !xText->getString().isEmpty() )
871 *
this, nNumberFormat, xCell->getValue() );
876 aAny = xCellPropertySet->getPropertyValue(
"IsProtected");
877 if (*o3tl::doAccess<bool>(aAny))
885 aAny = xCellPropertySet->getPropertyValue(
"TextSection");
886 Reference < XTextSection > xTextSection;
887 aAny >>= xTextSection;
903 OSL_FAIL(
"here should be a XCell");
940 assert(!it->second->isEmpty());
948 const size_t nBoxes = rBoxes.size();
950 sal_uInt32 nCPos = 0
U;
952 for(
size_t nBox=0
U; nBox<nBoxes; ++nBox )
957 const sal_Int32 nRowSpan = pBox->
getRowSpan();
968 assert(!it->second->isEmpty());
978 if( nBox < nBoxes-1U )
984 const size_t nOldCol = nCol;
986 SwXMLTableColumns_Impl::const_iterator it = rLines.
GetColumns().find( &aCol );
987 OSL_ENSURE( it != rLines.
GetColumns().end(),
"couldn't find column" );
991 if ( nCol < nOldCol )
993 OSL_FAIL(
"table and/or table information seems to be corrupted." );
999 const sal_uInt32 nColSpan = nCol - nOldCol + 1U;
1001 if ( nRowSpan >= 1 )
1002 ExportTableBox( *pBox, nColSpan,
static_cast< sal_uInt32
>(nRowSpan), rTableInfo );
1004 for(
size_t i=nOldCol;
i<nCol; ++
i )
1018 sal_uInt32 nHeaderRows )
1021 "SwXMLExport::ExportTableLines: table columns infos missing" );
1027 for( nInfoPos=0; nInfoPos <
m_pTableLines->size(); nInfoPos++ )
1036 "SwXMLExport::ExportTableLines: table columns info missing" );
1037 OSL_ENSURE( 0==nInfoPos,
1038 "SwXMLExport::ExportTableLines: table columns infos are unsorted" );
1042 SwXMLTableLinesCache_Impl::iterator it =
m_pTableLines->begin();
1043 advance( it, nInfoPos );
1050 const SwXMLTableColumns_Impl& rCols = pLines->
GetColumns();
1051 size_t nColumn = 0
U;
1052 const size_t nColumns = rCols.size();
1053 sal_Int32 nColRep = 1;
1059 (nColumn < nColumns) ? rCols[nColumn].
get() :
nullptr;
1073 OUString::number(nColRep) );
1082 pColumn = pNextColumn;
1086 const size_t nLines = rLines.
size();
1088 if( nHeaderRows > 0 )
1093 OSL_ENSURE( nHeaderRows <= nLines,
"more headers then lines?" );
1094 for(
size_t nLine = 0
U; nLine < nHeaderRows; ++nLine )
1098 for(
size_t nLine = nHeaderRows; nLine < nLines; ++nLine )
1130 if (pTableFormat && !pTableFormat->
GetName().isEmpty())
1140 OUString sStyleName;
1148 if (
auto pSwDdeTable =
dynamic_cast<const SwDDETable*
>( &rTable) )
1151 const SwDDEFieldType* pDDEFieldType = pSwDdeTable->GetDDEFieldType();
1158 const OUString& sCmd = pDDEFieldType->
GetCmd();
1159 sal_Int32 nIdx{ 0 };
1168 if (pDDEFieldType->
GetType() == SfxLinkUpdateMode::ALWAYS)
1180 auto const it(rFormats.find(&rTableNd));
1181 assert(it != rFormats.end());
1200 for (
SwTableBox* pBox : pLine->GetTabBoxes())
1202 if (pBox->getRowSpan() <= 0)
1204 if (pBox->GetSttNd())
1219 const Reference < XTextContent > & rTextContent,
1220 bool bAutoStyles,
bool _bProgress )
1225 Reference < XTextTable > xTextTable( rTextContent, UNO_QUERY );
1226 OSL_ENSURE( xTextTable.is(),
"text table missing" );
1227 if( xTextTable.is() )
1233 OSL_ENSURE( pFormat,
"table format missing" );
1235 OSL_ENSURE( pTable,
"table missing" );
1237 OSL_ENSURE( pTableNd,
"table node missing" );
1245 const bool bExportStyles = bool(
GetExport().getExportFlags() & SvXMLExportFlags::STYLES );
constexpr sal_uInt32 getSwDefaultTextFormat()
The number formatter's default locale's @ Text format.
sal_uInt32 GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
constexpr tools::Long Width() const
const SvXMLNamespaceMap & GetNamespaceMap() const
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
SvXMLExportFlags getExportFlags() const
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
tools::Long GetHeight() const
const Size & GetSize() const
OUString const & GetCmd() const
SfxLinkUpdateMode GetType() const
virtual OUString GetName() const override
Only in derived classes.
bool IsInHeaderFooter(const SwNode &) const
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
void Width(tools::Long nNew)
Starts a section of nodes in the document model.
static void FillProgName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
SwTableBox is one table cell in the document model.
sal_Int32 getRowSpan() const
SwFrameFormat * GetFrameFormat()
SwTableLines & GetTabLines()
const SwStartNode * GetSttNd() const
SwTableLine is one table row in the document model.
SwFrameFormat * GetFrameFormat()
SwTableBoxes & GetTabBoxes()
bool hasSoftPageBreak() const
const SwTable & GetTable() const
SwTable is one table in the document model, containing rows (which contain cells).
SwTableNode * GetTableNode() const
const OUString & GetTableStyleName() const
Return the table style name of this table.
SwTableLines & GetTabLines()
SwTableFormat * GetFrameFormat()
static SwTable * FindTable(SwFrameFormat const *const pFormat)
sal_uInt16 GetRowsToRepeat() const
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType, const SdrObject *pObject=nullptr)
Is the frame format a text box?
sal_uInt32 GetWidthOpt() const
void SetWidthOpt(sal_uInt32 nWidth, bool bRel)
sal_uInt32 GetPos() const
static sal_uInt32 GetBoxWidth(const SwTableBox *pBox)
static rtl::Reference< SwXCell > CreateXCell(SwFrameFormat *pTableFormat, SwTableBox *pBox, SwTable *pTable=nullptr)
std::unique_ptr< SwXMLTableLinesCache_Impl > m_pTableLines
void ExportTableAutoStyles(const SwTableNode &rTableNd)
const SvXMLUnitConverter & GetTwipUnitConverter() const
void ExportTableFormat(const SwFrameFormat &rFormat, sal_uInt32 nAbsWidth)
void ExportTableColumnStyle(const SwXMLTableColumn_Impl &rCol)
void ExportTableBox(const SwTableBox &rBox, sal_uInt32 nColSpan, sal_uInt32 nRowSpan, SwXMLTableInfo_Impl &rTableInfo)
bool IsShowProgress() const
void ExportTable(const SwTableNode &rTableNd)
void ExportFormat(const SwFormat &rFormat, enum ::xmloff::token::XMLTokenEnum eClass, ::std::optional< OUString > const oStyleName)
void ExportTableLinesAutoStyles(const SwTableLines &rLines, sal_uInt32 nAbsWidth, sal_uInt32 nBaseWidth, std::u16string_view rNamePrefix, SwXMLTableColumnsSortByWidth_Impl &rExpCols, SwXMLTableFrameFormatsSort_Impl &rExpRows, SwXMLTableFrameFormatsSort_Impl &rExpCells, SwXMLTableInfo_Impl &rTableInfo, bool bTop=false)
void ExportTableLines(const SwTableLines &rLines, SwXMLTableInfo_Impl &rTableInfo, sal_uInt32 nHeaderRows=0)
void ExportTableLine(const SwTableLine &rLine, const SwXMLTableLines_Impl &rLines, SwXMLTableInfo_Impl &rTableInfo)
void SetRelWidth(sal_uInt32 nSet)
const OUString & GetStyleName() const
void SetStyleName(const OUString &rName)
SwXMLTableColumn_Impl(sal_uInt32 nPosition)
sal_uInt32 GetRelWidth() const
sal_uInt16 GetPrefix() const
The namespace (table or loext) that should be used for the elements.
bool IsBaseSectionValid() const
void SetBaseSection(const Reference< XTextSection > &rBase)
SwXMLTextParagraphExport::FormatMap const & m_rLineFormats
const SwTable * GetTable() const
const Reference< XTextSection > & GetBaseSection() const
SwXMLTextParagraphExport::FormatMap const & m_rBoxFormats
SwXMLTextParagraphExport::FormatMap const & GetBoxFormats() const
const SwFrameFormat * GetTableFormat() const
SwXMLTextParagraphExport::FormatMap const & GetLineFormats() const
Reference< XTextSection > m_xBaseSection
SwXMLTableInfo_Impl(const SwTable *pTable, sal_uInt16 nPrefix, SwXMLTextParagraphExport::FormatMap const &rLineFormats, SwXMLTextParagraphExport::FormatMap const &rBoxFormats)
const SwTableLines * m_pLines
SwXMLTableLines_Impl(const SwTableLines &rLines)
sal_uInt32 GetWidth() const
const SwXMLTableColumns_Impl & GetColumns() const
SwXMLTableColumns_Impl m_aCols
const SwTableLines * GetLines() const
void CollectTableLinesAutoStyles(const SwTableLines &rLines, SwFrameFormat &rFormat, bool bProgress)
::std::unordered_map< SwTableNode const *, ::std::pair< FormatMap, FormatMap > > m_TableFormats
::std::unordered_map< SwFrameFormat const *, ::std::optional< OUString > > FormatMap
std::vector< const SwTableNode * > maTableNodes
virtual void exportTable(const css::uno::Reference< css::text::XTextContent > &rTextContent, bool bAutoStyles, bool bProgress) override
virtual void exportTableAutoStyles() override
SwFrameFormat * GetFrameFormat()
SvXMLExport & GetExport()
bool isAutoStylesCollected() const
void exportText(const css::uno::Reference< css::text::XText > &rText, bool bIsProgress=false, bool bExportParagraph=true, TextPNS eExtensionNS=TextPNS::ODF)
std::vector< Value >::const_iterator const_iterator
const_iterator find(const Value &x) const
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(126)
constexpr TypedWhichId< SwFormatRowSplit > RES_ROW_SPLIT(128)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(108)
constexpr TypedWhichId< SvXMLAttrContainerItem > RES_UNKNOWNATR_CONTAINER(RES_UNKNOWNATR_BEGIN)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(162)
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(112)
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(104)
const sal_Unicode cTokenSeparator
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
XML_TABLE_COLUMN_PROPERTIES
XML_NUMBER_COLUMNS_SPANNED
XML_NUMBER_COLUMNS_REPEATED
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
void sw_GetTableBoxColStr(sal_uInt16 nCol, OUString &rNm)
std::vector< SwTableBox * > SwTableBoxes
std::vector< SwXMLTableLines_Impl * > SwXMLTableLinesCache_Impl
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_OOOW
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
constexpr sal_uInt16 XML_NAMESPACE_STYLE
vector< SwFrameFormat * > SwXMLFrameFormats_Impl
static OUString lcl_xmltble_appendBoxPrefix(std::u16string_view rNamePrefix, sal_uInt32 nCol, sal_uInt32 nRow, bool bTop)