00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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;
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;
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