diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2021-04-27 15:06:48 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-05-29 23:34:36 +0200 |
commit | 9bf4e0d8f538cb0b51d2e803156301a956deaac3 (patch) | |
tree | 04aebf91c7856670e9a7f1f334923b151a2a5b4a /sc | |
parent | bda9929821de620f1f85528abd1c4bba46d937d6 (diff) |
tdf#127484 - Use HTML caption tag to name externally linked tables
Change-Id: I0abca8e1966e93337c16609211c146c0ed97c62f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114743
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/html/htmlimp.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/html/htmlpars.cxx | 25 | ||||
-rw-r--r-- | sc/source/filter/inc/htmlpars.hxx | 9 |
3 files changed, 41 insertions, 8 deletions
diff --git a/sc/source/filter/html/htmlimp.cxx b/sc/source/filter/html/htmlimp.cxx index 4a9a3a93b099..f1004ba0fe73 100644 --- a/sc/source/filter/html/htmlimp.cxx +++ b/sc/source/filter/html/htmlimp.cxx @@ -181,14 +181,17 @@ void ScHTMLImport::WriteToDocument( assert(!"can't move"); } // insert table number as name - InsertRangeName( *mpDoc, ScfTools::GetNameFromHTMLIndex( nTableId ), aNewRange ); + OUStringBuffer aName(ScfTools::GetNameFromHTMLIndex(nTableId)); // insert table id as name if (!pTable->GetTableName().isEmpty()) - { - OUString aName( ScfTools::GetNameFromHTMLName( pTable->GetTableName() ) ); - if (!mpDoc->GetRangeName()->findByUpperName(ScGlobal::getCharClassPtr()->uppercase(aName))) - InsertRangeName( *mpDoc, aName, aNewRange ); - } + aName.append(" - " + pTable->GetTableName()); + // insert table caption as name + if (!pTable->GetTableCaption().isEmpty()) + aName.append(" - " + pTable->GetTableCaption()); + if (!mpDoc->GetRangeName()->findByUpperName( + ScGlobal::getCharClassPtr()->uppercase(aName.toString()))) + InsertRangeName(*mpDoc, aName.toString(), aNewRange); + } } diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index 394691b70cbe..e320269352ed 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -1804,7 +1804,8 @@ ScHTMLTable::ScHTMLTable( ScHTMLTable& rParentTable, const HtmlImportInfo& rInfo mbPreFormText( bPreFormText ), mbRowOn( false ), mbDataOn( false ), - mbPushEmptyLine( false ) + mbPushEmptyLine( false ), + mbCaptionOn ( false ) { if( mbPreFormText ) { @@ -1851,7 +1852,8 @@ ScHTMLTable::ScHTMLTable( mbPreFormText( false ), mbRowOn( false ), mbDataOn( false ), - mbPushEmptyLine( false ) + mbPushEmptyLine( false ), + mbCaptionOn ( false ) { // open the first "cell" of the document ImplRowOn(); @@ -1901,6 +1903,9 @@ void ScHTMLTable::PutText( const HtmlImportInfo& rInfo ) mxCurrEntry->AdjustStart( rInfo ); else mxCurrEntry->AdjustEnd( rInfo ); + if (mbCaptionOn) + maCaptionBuffer.append(rInfo.aText); + } } @@ -1950,6 +1955,20 @@ ScHTMLTable* ScHTMLTable::TableOff( const HtmlImportInfo& rInfo ) return mbPreFormText ? this : CloseTable( rInfo ); } +void ScHTMLTable::CaptionOn() +{ + mbCaptionOn = true; + maCaptionBuffer.setLength(0); +} + +void ScHTMLTable::CaptionOff() +{ + if (!mbCaptionOn) + return; + maCaption = maCaptionBuffer.makeStringAndClear().trim(); + mbCaptionOn = false; +} + ScHTMLTable* ScHTMLTable::PreOn( const HtmlImportInfo& rInfo ) { PushEntry( rInfo ); @@ -2823,6 +2842,8 @@ void ScHTMLQueryParser::ProcessToken( const HtmlImportInfo& rInfo ) // --- table handling --- case HtmlTokenId::TABLE_ON: TableOn( rInfo ); break; // <table> case HtmlTokenId::TABLE_OFF: TableOff( rInfo ); break; // </table> + case HtmlTokenId::CAPTION_ON: mpCurrTable->CaptionOn(); break; // <caption> + case HtmlTokenId::CAPTION_OFF: mpCurrTable->CaptionOff(); break; // </caption> case HtmlTokenId::TABLEROW_ON: mpCurrTable->RowOn( rInfo ); break; // <tr> case HtmlTokenId::TABLEROW_OFF: mpCurrTable->RowOff( rInfo ); break; // </tr> case HtmlTokenId::TABLEHEADER_ON: // <th> diff --git a/sc/source/filter/inc/htmlpars.hxx b/sc/source/filter/inc/htmlpars.hxx index 1bf8c9b91008..a683a0c984d7 100644 --- a/sc/source/filter/inc/htmlpars.hxx +++ b/sc/source/filter/inc/htmlpars.hxx @@ -338,6 +338,8 @@ public: /** Returns the name of the table, specified in the TABLE tag. */ const OUString& GetTableName() const { return maTableName; } + /** Returns the caption of the table, specified in the <caption> tag. */ + const OUString& GetTableCaption() const { return maCaption; } /** Returns the unique identifier of the table. */ ScHTMLTableId GetTableId() const { return maTableId.mnTableId; } /** Returns the cell spanning of the specified cell. */ @@ -368,6 +370,10 @@ public: /** Closes *this* table (</table> tag). @return Pointer to the parent table. */ ScHTMLTable* TableOff( const HtmlImportInfo& rInfo ); + /** Processes the caption of the table (<caption> tag). */ + void CaptionOn(); + /** Processes the caption of the table (</caption> tag). */ + void CaptionOff(); /** Starts a *new* table based on preformatted text (<pre> tag). @return Pointer to the new table. */ ScHTMLTable* PreOn( const HtmlImportInfo& rInfo ); @@ -517,6 +523,8 @@ private: ScHTMLTable* mpParentTable; /// Pointer to parent table. ScHTMLTableMapPtr mxNestedTables; /// Table of nested HTML tables. OUString maTableName; /// Table name from <table id> option. + OUString maCaption; /// Caption name of the table from <caption> </caption> + OUStringBuffer maCaptionBuffer; /// Caption buffer of the table from <caption> </caption> ScHTMLTableAutoId maTableId; /// Unique identifier of this table. SfxItemSet maTableItemSet; /// Items for the entire table. SfxItemSetPtr mxRowItemSet; /// Items for the current table row. @@ -539,6 +547,7 @@ private: bool mbRowOn:1; /// true = Inside of <tr> </tr>. bool mbDataOn:1; /// true = Inside of <td> </td> or <th> </th>. bool mbPushEmptyLine:1; /// true = Insert empty line before current entry. + bool mbCaptionOn:1; /// true = Inside of <caption> </caption> }; /** The "global table" representing the entire HTML document. */ |