/* AbiSource * * Copyright (C) 2005 INdT * Author: Daniel d'Andrada T. de Carvalho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ // Class definition include #include "ODe_Common.h" #include "ODe_DocumentData.h" #include "ODe_ListLevelStyle.h" #include "ODe_Style_List.h" #include "ODe_Style_MasterPage.h" #include "ODe_Style_PageLayout.h" #include "ODe_Style_Style.h" #include "ut_misc.h" // External includes #include #include /** * Constructor */ ODe_DocumentData::ODe_DocumentData(PD_Document* pAbiDoc) : m_styles(pAbiDoc), m_pOfficeTextTemp(NULL), m_pAbiDoc(pAbiDoc) { } /** * Destructor */ ODe_DocumentData::~ODe_DocumentData() { UT_GenericVector* pMasterPageVector; UT_uint32 count, i; pMasterPageVector = m_masterStyles.enumerate(); count = pMasterPageVector->getItemCount(); for (i=0; i from the info that goes on the // tag of abw files. ODe_Style_PageLayout* pPageLayout; pPageLayout = new ODe_Style_PageLayout(); pPageLayout->setName("Standard"); m_stylesAutoStyles.addPageLayout(pPageLayout); pPageLayout->fetchAttributesFromAbiDoc(m_pAbiDoc); // Create the "Standard" master page style ODe_Style_MasterPage* pMPStyle; pMPStyle = new ODe_Style_MasterPage("Standard", "Standard"); m_masterStyles.insert("Standard", pMPStyle); m_pOfficeTextTemp = gsf_output_memory_new(); if (m_pOfficeTextTemp == NULL) { return false; } // If we've reached this point, everything is fine. return true; } /** * Do all necessary work after having read the AbiWord document. */ bool ODe_DocumentData::doPostListeningWork() { UT_GenericVector* pStylesVector; UT_GenericVector* pListStyles; UT_GenericVector* pListLevelStyles; UT_uint32 i, j, count, count2; //// // Build the element for the Styles XML file. pStylesVector = m_stylesAutoStyles.getParagraphStyles(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } pStylesVector = m_stylesAutoStyles.getTextStyles(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } pStylesVector = m_styles.getParagraphStylesEnumeration(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } pStylesVector = m_styles.getTextStylesEnumeration(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } //// // Build the element for the Content XML file. pStylesVector = m_contentAutoStyles.getParagraphStyles(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } pStylesVector = m_contentAutoStyles.getTextStyles(); count = pStylesVector->getItemCount(); for (i=0; igetFontName() ); } pListStyles = m_contentAutoStyles.getListStyles(); count = pListStyles->getItemCount(); for (i=0; igetNthItem(i)->getListLevelStyles(); count2 = pListLevelStyles->getItemCount(); for (j=0; jgetFontName()); } } //// // Build/expand the paragraph elements for the Styles // XML file based on the existence of AbiWord's default-tab-interval // property in any of the automatic or normal styles. // pStylesVector = m_contentAutoStyles.getParagraphStyles(); count = pStylesVector->getItemCount(); for (i=0; igetItemCount(); for (i=0; igetItemCount(); for (i=0; igetDefaultTabInterval(); if (defaultTabInterval.empty()) return; // remove the default tab interval property from the style pStyle->setDefaultTabInterval(""); // ... and create a default style to hold the default tab interval property ODe_Style_Style* pDefaultStyle = m_styles.getDefaultStyles().getStyle("paragraph"); if (!pDefaultStyle) { pDefaultStyle = new ODe_Style_Style(); pDefaultStyle->setFamily("paragraph"); pDefaultStyle->makeDefaultStyle(); m_styles.getDefaultStyles().storeStyle("paragraph", pDefaultStyle); } // NOTE: if a paragraph default style already exists with a default tab interval // property set, then we'll just overwrite it. This can happen because AbiWord // supports such a property on every paragraph and paragraph style, but ODT only // supports one on the default paragraph style. pDefaultStyle->setDefaultTabInterval(defaultTabInterval); } /** * */ bool ODe_DocumentData::writeStylesXML(GsfOutfile* pOdt) const { GsfOutput* pStylesStream; UT_GenericVector* pMasterPageVector; bool ok; UT_uint32 count, i; pStylesStream = gsf_outfile_new_child (pOdt, "styles.xml", FALSE); const char * const preamble [] = { "\n", "\n", "\n"}; ODe_writeToStream(pStylesStream, preamble, G_N_ELEMENTS(preamble)); m_stylesXMLFontDecls.write(pStylesStream); m_styles.write(pStylesStream); m_stylesAutoStyles.write(pStylesStream); ODe_writeUTF8String(pStylesStream, " \n"); pMasterPageVector = m_masterStyles.enumerate(); count = pMasterPageVector->getItemCount(); for (i=0; iwrite(pStylesStream); if (!ok) { return false; } } ODe_writeUTF8String(pStylesStream, " \n"); ODe_writeUTF8String(pStylesStream, ""); ODe_gsf_output_close(pStylesStream); return true; } /** * */ bool ODe_DocumentData::writeContentXML(GsfOutfile* pOdt) { GsfOutput* pContentStream; pContentStream = gsf_outfile_new_child (pOdt, "content.xml", FALSE); const char * const preamble [] = { "\n", "\n", "\n"}; ODe_writeToStream(pContentStream, preamble, G_N_ELEMENTS(preamble)); m_contentXMLFontDecls.write(pContentStream); m_contentAutoStyles.write(pContentStream); ODe_writeUTF8String(pContentStream, " \n" " \n"); ODe_gsf_output_write(pContentStream, gsf_output_size (m_pOfficeTextTemp), gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pOfficeTextTemp))); ODe_gsf_output_close (m_pOfficeTextTemp); m_pOfficeTextTemp = NULL; ODe_writeUTF8String(pContentStream, " \n" " \n" ""); ODe_gsf_output_close(pContentStream); return true; }