filters

PageSpan.cxx

00001 /* SectionStyle: Stores (and writes) section-based information (e.g.: a column
00002  * break needs a new section) that is needed at the head of an OO document and
00003  * is referenced throughout the entire document
00004  *
00005  * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  * For further information visit http://libwpd.sourceforge.net
00023  *
00024  */
00025 
00026 /* "This product is not manufactured, approved, or supported by
00027  * Corel Corporation or Corel Corporation Limited."
00028  */
00029 #include "FilterInternal.hxx"
00030 #include "PageSpan.hxx"
00031 #include "DocumentElement.hxx"
00032 
00033 
00034 PageSpan::PageSpan(const WPXPropertyList &xPropList) :
00035 #if 0
00036 const int iSpan, const float fFormLength, const float fFormWidth, const WPXFormOrientation fFormOrientation,
00037                    const float fLeftMargin, const float fRightMargin, const float fTopMargin, const float fBottomMargin):
00038     miSpan(iSpan),
00039     mfFormLength(fFormLength),
00040     mfFormWidth(fFormWidth),
00041     mfFormOrientation(fFormOrientation),
00042     mfMarginLeft(fLeftMargin),
00043     mfMarginRight(fRightMargin),
00044     mfMarginTop(fTopMargin),
00045     mfMarginBottom(fBottomMargin),
00046 #endif
00047         mxPropList(xPropList),
00048     mpHeaderContent(NULL),
00049     mpFooterContent(NULL),
00050     mpHeaderLeftContent(NULL),
00051     mpFooterLeftContent(NULL)
00052 {
00053 }
00054 
00055 PageSpan::~PageSpan()
00056 {
00057     delete mpHeaderContent;
00058     delete mpHeaderLeftContent;
00059     delete mpFooterContent;
00060     delete mpFooterLeftContent;
00061 }
00062 
00063 int PageSpan::getSpan() const
00064 {
00065         if (mxPropList["libwpd:num-pages"])
00066                 return mxPropList["libwpd:num-pages"]->getInt();
00067 
00068         return 0; // should never happen
00069 }
00070 
00071 float PageSpan::getMarginLeft() const
00072 {
00073         if (mxPropList["fo:margin-left"])
00074                 return mxPropList["fo:margin-left"]->getFloat();
00075 
00076          return 0.0f;
00077 }
00078 
00079 float PageSpan::getMarginRight() const
00080 {
00081         if (mxPropList["fo:margin-right"])
00082                 return mxPropList["fo:margin-right"]->getFloat();
00083 
00084          return 0.0f;
00085 }
00086 
00087 void PageSpan::writePageMaster(const int iNum, DocumentHandler &xHandler) const
00088 {
00089         WPXPropertyList propList;
00090 
00091     WPXString sPageMasterName;
00092         sPageMasterName.sprintf("PM%i", iNum+2);
00093         propList.insert("style:name", sPageMasterName);
00094     xHandler.startElement("style:page-master", propList);
00095 
00096     WPXPropertyList tempPropList = mxPropList;
00097     if (!tempPropList["style:writing-mode"])
00098         tempPropList.insert("style:writing-mode", WPXString("lr-tb"));
00099     if (!tempPropList["style:footnote-max-height"])
00100         tempPropList.insert("style:footnote-max-height", WPXString("0inch"));
00101         xHandler.startElement("style:properties", tempPropList);
00102 
00103     WPXPropertyList footnoteSepPropList;
00104     footnoteSepPropList.insert("style:width", WPXString("0.0071inch"));
00105     footnoteSepPropList.insert("style:distance-before-sep", WPXString("0.0398inch"));
00106     footnoteSepPropList.insert("style:distance-after-sep", WPXString("0.0398inch"));
00107     footnoteSepPropList.insert("style:adjustment", WPXString("left"));
00108     footnoteSepPropList.insert("style:rel-width", WPXString("25\%"));
00109     footnoteSepPropList.insert("style:color", WPXString("#000000"));
00110     xHandler.startElement("style:footnote-sep", footnoteSepPropList);
00111 
00112     xHandler.endElement("style:footnote-sep");
00113         xHandler.endElement("style:properties");
00114         xHandler.endElement("style:page-master");
00115 }
00116 
00117 void PageSpan::writeMasterPages(const int iStartingNum, const int iPageMasterNum, const bool bLastPageSpan,
00118                                 DocumentHandler &xHandler) const
00119 {
00120         WPXPropertyList propList; // scratch space
00121 
00122     int iSpan = 0;
00123     (bLastPageSpan) ? iSpan = 1 : iSpan = getSpan();
00124 
00125     for (int i=iStartingNum; i<(iStartingNum+iSpan); i++)
00126     {
00127         TagOpenElement masterPageOpen("style:master-page");
00128         WPXString sMasterPageName;
00129         sMasterPageName.sprintf("Page Style %i", i);
00130         WPXString sPageMasterName;
00131         sPageMasterName.sprintf("PM%i", iPageMasterNum+2);
00132                 propList.insert("style:name", sMasterPageName);
00133         propList.insert("style:page-master-name", sPageMasterName);
00134         if (!bLastPageSpan)
00135         {
00136             WPXString sNextMasterPageName;
00137             sNextMasterPageName.sprintf("Page Style %i", (i+1));
00138                         propList.insert("style:next-style-name", sNextMasterPageName);
00139         }
00140                 xHandler.startElement("style:master-page", propList);
00141 
00142         if (mpHeaderContent)
00143             _writeHeaderFooter("style:header", *mpHeaderContent, xHandler);
00144         if (mpHeaderLeftContent)
00145             _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, xHandler);
00146         if (mpFooterContent)
00147             _writeHeaderFooter("style:footer", *mpFooterContent, xHandler);
00148         if (mpFooterLeftContent)
00149             _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, xHandler);
00150 
00151                 xHandler.endElement("style:master-page");
00152     }
00153 
00154 }
00155 
00156 void PageSpan::_writeHeaderFooter(const char *headerFooterTagName,
00157                   const std::vector<DocumentElement *> & headerFooterContent,
00158                   DocumentHandler &xHandler) const
00159 {
00160     TagOpenElement headerFooterOpen(headerFooterTagName);
00161     headerFooterOpen.write(xHandler);
00162     for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin();
00163          iter != headerFooterContent.end();
00164          iter++) {
00165         (*iter)->write(xHandler);
00166     }
00167     TagCloseElement headerFooterClose(headerFooterTagName);
00168     headerFooterClose.write(xHandler);
00169 }
00170 
KDE Home | KDE Accessibility Home | Description of Access Keys