diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-11 14:14:49 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-12 12:58:49 +0200 |
commit | 69fe10662845288c09a05716a93876e2ca95c4bd (patch) | |
tree | 00bbef5dab6f863cdbf427c4d91f60f279ec685b | |
parent | f0d9aab05249ff9ea97a60fa5305f2ae32e2bdbb (diff) |
sd html export: "single document" publish mode & support tables
Change-Id: I0c9f45011091f962d5304c9efcaebbed7e6c3d9d
-rw-r--r-- | sd/source/filter/html/htmlex.cxx | 202 | ||||
-rw-r--r-- | sd/source/filter/html/htmlex.hxx | 9 | ||||
-rw-r--r-- | sd/source/filter/html/htmlpublishmode.hxx | 10 | ||||
-rw-r--r-- | sd/source/filter/html/sdhtmlfilter.cxx | 7 |
4 files changed, 208 insertions, 20 deletions
diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx index 16600d157e4c..b06f5b863c26 100644 --- a/sd/source/filter/html/htmlex.cxx +++ b/sd/source/filter/html/htmlex.cxx @@ -82,6 +82,8 @@ #include "buttonset.hxx" #include <basegfx/polygon/b2dpolygon.hxx> +#include <svx/svdotable.hxx> + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -89,6 +91,8 @@ using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::document; +using namespace sdr::table; + // get parameter from Itemset #define RESTOHTML( res ) StringToHTMLString(SD_RESSTR(res)) @@ -312,36 +316,51 @@ OUString HtmlState::SetLink( const OUString& aLink, const OUString& aTarget ) return aStr; } +namespace +{ -// methods of the class HtmlExport -static OUString getParagraphStyle( SdrOutliner* pOutliner, sal_Int32 nPara ) +OUString getParagraphStyle( SdrOutliner* pOutliner, sal_Int32 nPara ) { SfxItemSet aParaSet( pOutliner->GetParaAttribs( nPara ) ); - OUString sStyle("direction:"); + OUString sStyle; + if( static_cast<const SvxFrameDirectionItem*>(aParaSet.GetItem( EE_PARA_WRITINGDIR ))->GetValue() == FRMDIR_HORI_RIGHT_TOP ) { - sStyle += "rtl;"; + + sStyle = "direction: rtl;"; } else { - sStyle += "ltr;"; + // This is the default so don't write it out + // sStyle += "direction: ltr;"; } return sStyle; } +void lclAppendStyle(OUStringBuffer& aBuffer, const OUString& aTag, const OUString& aStyle) +{ + if (aStyle.isEmpty()) + aBuffer.append("<" + aTag + ">"); + else + aBuffer.append("<" + aTag + " style=\"" + aStyle + "\">"); +} + +} // anonymous namespace // constructor for the html export helper classes HtmlExport::HtmlExport( const OUString& aPath, const Sequence< PropertyValue >& rParams, + const OUString& rFilterOptions, SdDrawDocument* pExpDoc, - ::sd::DrawDocShell* pDocShell ) + sd::DrawDocShell* pDocShell ) : maPath( aPath ), + maFilterOptions( rFilterOptions ), mpDoc(pExpDoc), mpDocSh( pDocShell ), meEC(NULL), - meMode( PUBLISH_HTML ), + meMode( PUBLISH_SINGLE_DOCUMENT ), mbContentsPage(false), mnButtonThema(-1), mnWidthPixel( PUB_MEDRES_WIDTH ), @@ -380,6 +399,9 @@ HtmlExport::HtmlExport( case PUBLISH_KIOSK: ExportKiosk(); break; + case PUBLISH_SINGLE_DOCUMENT: + ExportSingleDocument(); + break; } mpDoc->SetChanged(bChange); @@ -616,6 +638,74 @@ void HtmlExport::InitExportParameters( const Sequence< PropertyValue >& rParams maDocFileName = maIndex; } +void HtmlExport::ExportSingleDocument() +{ + SdrOutliner* pOutliner = mpDoc->GetInternalOutliner(); + + maPageNames.resize(mnSdPageCount); + + mnPagesWritten = 0; + InitProgress(mnSdPageCount); + + OUStringBuffer aStr(maHTMLHeader); + aStr.append(CreateMetaCharset()); + aStr.append("</head>\r\n"); + aStr.append(CreateBodyTag()); + + for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; ++nSdPage) + { + SdPage* pPage = maPages[nSdPage]; + maPageNames[nSdPage] = pPage->GetName(); + + if( mbDocColors ) + { + SetDocColors( pPage ); + } + + // page title + OUString sTitleText(CreateTextForTitle(pOutliner, pPage, pPage->GetPageBackgroundColor())); + OUString sStyle; + + if (nSdPage != 0) // First page - no need for a page brake here + sStyle += "page-break-before:always; "; + sStyle += getParagraphStyle(pOutliner, 0); + + lclAppendStyle(aStr, "h1", sStyle); + + aStr.append(sTitleText); + aStr.append("</h1>\r\n"); + + // write outline text + aStr.append(CreateTextForPage( pOutliner, pPage, true, pPage->GetPageBackgroundColor() )); + + // notes + if(mbNotes) + { + SdPage* pNotesPage = maNotesPages[ nSdPage ]; + OUString aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) ); + + if (!aNotesStr.isEmpty()) + { + aStr.append("<br>\r\n<h3>"); + aStr.append(RESTOHTML(STR_HTMLEXP_NOTES)); + aStr.append(":</h3>\r\n"); + + aStr.append(aNotesStr); + } + } + + if (mpProgress) + mpProgress->SetState(++mnPagesWritten); + + } + + // close page + aStr.append("</body>\r\n</html>"); + + WriteHtml(maDocFileName, false, aStr.makeStringAndClear()); + + pOutliner->Clear(); +} // exports the (in the c'tor specified impress document) to html void HtmlExport::ExportHtml() @@ -1022,9 +1112,7 @@ bool HtmlExport::CreateHtmlTextForPresPages() // page title OUString sTitleText( CreateTextForTitle(pOutliner,pPage, pPage->GetPageBackgroundColor()) ); - aStr.append("<h1 style=\""); - aStr.append(getParagraphStyle(pOutliner, 0)); - aStr.append("\">"); + lclAppendStyle(aStr, "h1", getParagraphStyle(pOutliner, 0)); aStr.append(sTitleText); aStr.append("</h1>\r\n"); @@ -1123,6 +1211,90 @@ OUString HtmlExport::CreateTextForPage( SdrOutliner* pOutliner, { OUStringBuffer aStr; + for (sal_uInt32 i = 0; i <pPage->GetObjCount(); i++ ) + { + SdrObject* pObject = pPage->GetObj(i); + PresObjKind eKind = pPage->GetPresObjKind(pObject); + + if (eKind == PRESOBJ_TABLE) + { + SdrTableObj* pTableObject = (SdrTableObj*) pObject; + + CellPos aStart, aEnd; + + aStart = pTableObject->getFirstCell(); + aEnd = pTableObject->getLastCell(); + + sal_Int32 nColCount = pTableObject->getColumnCount(); + aStr.append("<table>\r\n"); + for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++) + { + aStr.append(" <tr>\r\n"); + for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++) + { + aStr.append(" <td>\r\n"); + sal_Int32 nCellIndex = nRow * nColCount + nCol; + SdrText* pText = pTableObject->getText(nCellIndex); + if (!pText || !pText->GetOutlinerParaObject()) + continue; + + pOutliner->SetText(*(pText->GetOutlinerParaObject())); + + sal_Int32 nCount = pOutliner->GetParagraphCount(); + + Paragraph* pPara = NULL; + + sal_Int16 nCurrentDepth = -1; + + for (sal_Int32 nPara = 0; nPara < nCount; nPara++) + { + pPara = pOutliner->GetParagraph(nPara); + if(pPara == 0) + continue; + + const sal_Int16 nDepth = (sal_uInt16) pOutliner->GetDepth(nPara); + OUString aParaText = ParagraphToHTMLString(pOutliner, nPara, rBackgroundColor); + + if (aParaText.isEmpty()) + continue; + + if (nDepth < 0) + { + lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, nPara)); + aStr.append(aParaText); + aStr.append("</p>\r\n"); + } + else + { + while(nCurrentDepth < nDepth) + { + aStr.append("<ul>\r\n"); + nCurrentDepth++; + } + while(nCurrentDepth > nDepth) + { + aStr.append("</ul>\r\n"); + nCurrentDepth--; + } + lclAppendStyle(aStr, "li", getParagraphStyle(pOutliner, nPara)); + aStr.append(aParaText); + aStr.append("</li>\r\n"); + } + } + while(nCurrentDepth >= 0) + { + aStr.append("</ul>\r\n"); + nCurrentDepth--; + } + pOutliner->Clear(); + aStr.append(" </td>\r\n"); + } + aStr.append(" </tr>\r\n"); + } + aStr.append("</table>\r\n"); + } + } + SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT); if(!pTO) pTO = GetLayoutTextObject(pPage); @@ -1175,7 +1347,7 @@ OUString HtmlExport::CreateTextForPage( SdrOutliner* pOutliner, OUString sStyle(getParagraphStyle(pOutliner, nPara)); if(nActDepth >= 0 ) { - aStr.append("<li style=\"" + sStyle + "\">"); + lclAppendStyle(aStr, "li", sStyle); } if(nActDepth <= 0 && bHeadLine) @@ -1186,7 +1358,7 @@ OUString HtmlExport::CreateTextForPage( SdrOutliner* pOutliner, } else { - aStr.append("<h2 style=\"" + sStyle + "\">"); + lclAppendStyle(aStr, "h2", sStyle); } } aStr.append(aParaText); @@ -1230,7 +1402,7 @@ OUString HtmlExport::CreateTextForNotesPage( SdrOutliner* pOutliner, sal_Int32 nCount = pOutliner->GetParagraphCount(); for (sal_Int32 nPara = 0; nPara < nCount; nPara++) { - aStr.append("<p style=\"" + getParagraphStyle(pOutliner, nPara) + "\">"); + lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, nPara)); aStr.append(ParagraphToHTMLString(pOutliner, nPara, rBackgroundColor)); aStr.append("</p>\r\n"); } @@ -1958,9 +2130,7 @@ bool HtmlExport::CreateOutlinePages() if (aTitle.isEmpty()) aTitle = maPageNames[nSdPage]; - aStr.append("<p style=\""); - aStr.append(getParagraphStyle(pOutliner, 0)); - aStr.append("\">"); + lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, 0)); aStr.append(CreateLink(aLink, aTitle)); aStr.append("</p>"); diff --git a/sd/source/filter/html/htmlex.hxx b/sd/source/filter/html/htmlex.hxx index 56f9e153dec4..53b1292ead49 100644 --- a/sd/source/filter/html/htmlex.hxx +++ b/sd/source/filter/html/htmlex.hxx @@ -83,6 +83,7 @@ class HtmlExport std::vector< SdPage* > maNotesPages; OUString maPath; + OUString maFilterOptions; SdDrawDocument* mpDoc; ::sd::DrawDocShell* mpDocSh; @@ -205,12 +206,18 @@ class HtmlExport void ExportHtml(); void ExportKiosk(); void ExportWebCast(); + void ExportSingleDocument(); bool WriteHtml( const OUString& rFileName, bool bAddExtension, const OUString& rHtmlData ); OUString GetButtonName( int nButton ) const; public: - HtmlExport( const OUString& aPath, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rParams, SdDrawDocument* pExpDoc, ::sd::DrawDocShell* pDocShell ); + HtmlExport(const OUString& aPath, + const css::uno::Sequence<css::beans::PropertyValue>& rParams, + const OUString& rFilterOptions, + SdDrawDocument* pExpDoc, + sd::DrawDocShell* pDocShell); + virtual ~HtmlExport(); static OUString ColorToHTMLString( Color aColor ); diff --git a/sd/source/filter/html/htmlpublishmode.hxx b/sd/source/filter/html/htmlpublishmode.hxx index a7871dbae55d..95740c0b4a6d 100644 --- a/sd/source/filter/html/htmlpublishmode.hxx +++ b/sd/source/filter/html/htmlpublishmode.hxx @@ -20,8 +20,14 @@ #ifndef INCLUDED_SD_SOURCE_FILTER_HTML_HTMLPUBLISHMODE_HXX #define INCLUDED_SD_SOURCE_FILTER_HTML_HTMLPUBLISHMODE_HXX -enum HtmlPublishMode { - PUBLISH_HTML, PUBLISH_FRAMES, PUBLISH_WEBCAST, PUBLISH_KIOSK }; +enum HtmlPublishMode +{ + PUBLISH_HTML, + PUBLISH_FRAMES, + PUBLISH_WEBCAST, + PUBLISH_KIOSK, + PUBLISH_SINGLE_DOCUMENT +}; #endif diff --git a/sd/source/filter/html/sdhtmlfilter.cxx b/sd/source/filter/html/sdhtmlfilter.cxx index 23f27ede3da9..db809d7e99dc 100644 --- a/sd/source/filter/html/sdhtmlfilter.cxx +++ b/sd/source/filter/html/sdhtmlfilter.cxx @@ -64,12 +64,17 @@ sal_Bool SdHTMLFilter::Export() SfxItemSet *pSet = mrMedium.GetItemSet(); ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aParams; + OUString sFilterOptions; const SfxPoolItem* pItem; + if ( pSet->GetItemState( SID_FILTER_DATA, false, &pItem ) == SFX_ITEM_SET ) ((SfxUnoAnyItem*)pItem)->GetValue() >>= aParams; - delete( new HtmlExport( mrMedium.GetName(), aParams, &mrDocument, &mrDocShell ) ); + if (pSet->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == SFX_ITEM_SET) + sFilterOptions = ((SfxStringItem*)pItem)->GetValue(); + + HtmlExport aExport(mrMedium.GetName(), aParams, sFilterOptions, &mrDocument, &mrDocShell); return true; } |