summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2011-06-08 14:44:37 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2011-06-08 14:44:37 +0200
commita90fa6413ffd378194be05f0e1210aaf009f9e3e (patch)
treeb59063c93a0e999500d9aa3f009ac2c9d4ff144d /writerperfect
parent991fce7134052aafabe972876e1a70d680641c3c (diff)
Laying foundation for multipage support in writerperfect's OdgGenerator
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/source/filter/OdgGenerator.cxx263
1 files changed, 150 insertions, 113 deletions
diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index 3b085eb6e6d0..8a37d5d061d6 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -68,6 +68,10 @@ public:
std::vector<DocumentElement *> mGraphicsGradientStyles;
std::vector<DocumentElement *> mGraphicsAutomaticStyles;
+ // page styles
+ std::vector<DocumentElement *> mPageAutomaticStyles;
+ std::vector<DocumentElement *> mPageMasterStyles;
+
OdfDocumentHandler *mpHandler;
::WPXPropertyList mxStyle;
@@ -75,6 +79,7 @@ public:
int miGradientIndex;
int miDashIndex;
int miGraphicsStyleIndex;
+ int miPageIndex;
double mfWidth;
double mfHeight;
@@ -86,6 +91,7 @@ OdgGeneratorPrivate::OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const Odf
miGradientIndex(1),
miDashIndex(1),
miGraphicsStyleIndex(1),
+ miPageIndex(1),
mfWidth(0.0),
mfHeight(0.0),
mxStreamType(streamType)
@@ -118,33 +124,23 @@ OdgGeneratorPrivate::~OdgGeneratorPrivate()
{
delete((*iterGraphicsGradientStyles));
}
-}
-OdgGenerator::OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType):
- mpImpl(new OdgGeneratorPrivate(pHandler, streamType))
-{
-}
+ for (std::vector<DocumentElement *>::iterator iterPageAutomaticStyles = mPageAutomaticStyles.begin();
+ iterPageAutomaticStyles != mPageAutomaticStyles.end(); iterPageAutomaticStyles++)
+ {
+ delete((*iterPageAutomaticStyles));
+ }
-OdgGenerator::~OdgGenerator()
-{
- if (mpImpl)
- delete mpImpl;
+ for (std::vector<DocumentElement *>::iterator iterPageMasterStyles = mPageMasterStyles.begin();
+ iterPageMasterStyles != mPageMasterStyles.end(); iterPageMasterStyles++)
+ {
+ delete((*iterPageMasterStyles));
+ }
}
-void OdgGenerator::startGraphics(const ::WPXPropertyList &propList)
+OdgGenerator::OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType):
+ mpImpl(new OdgGeneratorPrivate(pHandler, streamType))
{
- mpImpl->miGradientIndex = 1;
- mpImpl->miDashIndex = 1;
- mpImpl->miGraphicsStyleIndex = 1;
- mpImpl->mfWidth = 0.0;
- mpImpl->mfHeight = 0.0;
-
- if (propList["svg:width"])
- mpImpl->mfWidth = propList["svg:width"]->getDouble();
-
- if (propList["svg:height"])
- mpImpl->mfHeight = propList["svg:height"]->getDouble();
-
mpImpl->mpHandler->startDocument();
TagOpenElement tmpOfficeDocumentContent(
(mpImpl->mxStreamType == ODF_FLAT_XML) ? "office:document" : (
@@ -165,50 +161,9 @@ void OdgGenerator::startGraphics(const ::WPXPropertyList &propList)
if (mpImpl->mxStreamType == ODF_FLAT_XML)
tmpOfficeDocumentContent.addAttribute("office:mimetype", "application/vnd.oasis.opendocument.graphics");
tmpOfficeDocumentContent.write(mpImpl->mpHandler);
-
- if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_SETTINGS_XML))
- {
- TagOpenElement("office:settings").write(mpImpl->mpHandler);
-
- TagOpenElement configItemSetOpenElement("config:config-item-set");
- configItemSetOpenElement.addAttribute("config:name", "ooo:view-settings");
- configItemSetOpenElement.write(mpImpl->mpHandler);
-
- TagOpenElement configItemOpenElement("config:config-item");
-
- configItemOpenElement.addAttribute("config:name", "VisibleAreaTop");
- configItemOpenElement.addAttribute("config:type", "int");
- configItemOpenElement.write(mpImpl->mpHandler);
- mpImpl->mpHandler->characters("0");
- mpImpl->mpHandler->endElement("config:config-item");
-
- configItemOpenElement.addAttribute("config:name", "VisibleAreaLeft");
- configItemOpenElement.addAttribute("config:type", "int");
- configItemOpenElement.write(mpImpl->mpHandler);
- mpImpl->mpHandler->characters("0");
- mpImpl->mpHandler->endElement("config:config-item");
-
- configItemOpenElement.addAttribute("config:name", "VisibleAreaWidth");
- configItemOpenElement.addAttribute("config:type", "int");
- configItemOpenElement.write(mpImpl->mpHandler);
- WPXString sWidth; sWidth.sprintf("%li", (unsigned long)(2540 * mpImpl->mfWidth));
- mpImpl->mpHandler->characters(sWidth);
- mpImpl->mpHandler->endElement("config:config-item");
-
- configItemOpenElement.addAttribute("config:name", "VisibleAreaHeight");
- configItemOpenElement.addAttribute("config:type", "int");
- configItemOpenElement.write(mpImpl->mpHandler);
- WPXString sHeight; sHeight.sprintf("%li", (unsigned long)(2540 * mpImpl->mfHeight));
- mpImpl->mpHandler->characters(sHeight);
- mpImpl->mpHandler->endElement("config:config-item");
-
- mpImpl->mpHandler->endElement("config:config-item-set");
-
- mpImpl->mpHandler->endElement("office:settings");
- }
}
-void OdgGenerator::endGraphics()
+OdgGenerator::~OdgGenerator()
{
if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML))
{
@@ -247,40 +202,12 @@ void OdgGenerator::endGraphics()
if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML))
{
- TagOpenElement tmpStylePageLayoutOpenElement("style:page-layout");
- tmpStylePageLayoutOpenElement.addAttribute("style:name", "PM0");
- tmpStylePageLayoutOpenElement.write(mpImpl->mpHandler);
-
- TagOpenElement tmpStylePageLayoutPropertiesOpenElement("style:page-layout-properties");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-top", "0in");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-bottom", "0in");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-left", "0in");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-right", "0in");
- WPXString sValue;
- sValue = doubleToString(mpImpl->mfWidth); sValue.append("in");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", sValue);
- sValue = doubleToString(mpImpl->mfHeight); sValue.append("in");
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", sValue);
- tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait");
- tmpStylePageLayoutPropertiesOpenElement.write(mpImpl->mpHandler);
-
- mpImpl->mpHandler->endElement("style:page-layout-properties");
-
- mpImpl->mpHandler->endElement("style:page-layout");
-
- TagOpenElement tmpStyleStyleOpenElement("style:style");
- tmpStyleStyleOpenElement.addAttribute("style:name", "dp1");
- tmpStyleStyleOpenElement.addAttribute("style:family", "drawing-page");
- tmpStyleStyleOpenElement.write(mpImpl->mpHandler);
-
- TagOpenElement tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties");
- // tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:background-size", "border");
- tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none");
- tmpStyleDrawingPagePropertiesOpenElement.write(mpImpl->mpHandler);
-
- mpImpl->mpHandler->endElement("style:drawing-page-properties");
-
- mpImpl->mpHandler->endElement("style:style");
+ // writing out the page automatic styles
+ for (std::vector<DocumentElement *>::iterator iterPageAutomaticStyles = mpImpl->mPageAutomaticStyles.begin();
+ iterPageAutomaticStyles != mpImpl->mPageAutomaticStyles.end(); iterPageAutomaticStyles++)
+ {
+ (*iterPageAutomaticStyles)->write(mpImpl->mpHandler);
+ }
}
if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML))
@@ -292,14 +219,11 @@ void OdgGenerator::endGraphics()
{
TagOpenElement("office:master-styles").write(mpImpl->mpHandler);
- TagOpenElement tmpStyleMasterPageOpenElement("style:master-page");
- tmpStyleMasterPageOpenElement.addAttribute("style:name", "Default");
- tmpStyleMasterPageOpenElement.addAttribute("style:page-layout-name", "PM0");
- tmpStyleMasterPageOpenElement.addAttribute("draw:style-name", "dp1");
- tmpStyleMasterPageOpenElement.write(mpImpl->mpHandler);
-
- mpImpl->mpHandler->endElement("style:master-page");
-
+ for (std::vector<DocumentElement *>::const_iterator pageMasterIter = mpImpl->mPageMasterStyles.begin();
+ pageMasterIter != mpImpl->mPageMasterStyles.end(); pageMasterIter++)
+ {
+ (*pageMasterIter)->write(mpImpl->mpHandler);
+ }
mpImpl->mpHandler->endElement("office:master-styles");
}
@@ -309,19 +233,12 @@ void OdgGenerator::endGraphics()
TagOpenElement("office:drawing").write(mpImpl->mpHandler);
- TagOpenElement tmpDrawPageOpenElement("draw:page");
- tmpDrawPageOpenElement.addAttribute("draw:name", "page1");
- tmpDrawPageOpenElement.addAttribute("draw:style-name", "dp1");
- tmpDrawPageOpenElement.addAttribute("draw:master-page-name", "Default");
- tmpDrawPageOpenElement.write(mpImpl->mpHandler);
-
for (std::vector<DocumentElement *>::const_iterator bodyIter = mpImpl->mBodyElements.begin();
bodyIter != mpImpl->mBodyElements.end(); bodyIter++)
{
(*bodyIter)->write(mpImpl->mpHandler);
}
- mpImpl->mpHandler->endElement("draw:page");
mpImpl->mpHandler->endElement("office:drawing");
mpImpl->mpHandler->endElement("office:body");
}
@@ -334,6 +251,126 @@ void OdgGenerator::endGraphics()
(mpImpl->mxStreamType == ODF_META_XML) ? "office:document-meta" : "office:document" )))));
mpImpl->mpHandler->endDocument();
+
+ if (mpImpl)
+ delete mpImpl;
+}
+
+void OdgGenerator::startGraphics(const ::WPXPropertyList &propList)
+{
+ if (propList["svg:width"])
+ mpImpl->mfWidth = propList["svg:width"]->getDouble();
+
+ if (propList["svg:height"])
+ mpImpl->mfHeight = propList["svg:height"]->getDouble();
+
+ if (mpImpl->miPageIndex == 1 && ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_SETTINGS_XML)))
+ {
+ TagOpenElement("office:settings").write(mpImpl->mpHandler);
+
+ TagOpenElement configItemSetOpenElement("config:config-item-set");
+ configItemSetOpenElement.addAttribute("config:name", "ooo:view-settings");
+ configItemSetOpenElement.write(mpImpl->mpHandler);
+
+ TagOpenElement configItemOpenElement("config:config-item");
+
+ configItemOpenElement.addAttribute("config:name", "VisibleAreaTop");
+ configItemOpenElement.addAttribute("config:type", "int");
+ configItemOpenElement.write(mpImpl->mpHandler);
+ mpImpl->mpHandler->characters("0");
+ mpImpl->mpHandler->endElement("config:config-item");
+
+ configItemOpenElement.addAttribute("config:name", "VisibleAreaLeft");
+ configItemOpenElement.addAttribute("config:type", "int");
+ configItemOpenElement.write(mpImpl->mpHandler);
+ mpImpl->mpHandler->characters("0");
+ mpImpl->mpHandler->endElement("config:config-item");
+
+ configItemOpenElement.addAttribute("config:name", "VisibleAreaWidth");
+ configItemOpenElement.addAttribute("config:type", "int");
+ configItemOpenElement.write(mpImpl->mpHandler);
+ WPXString sWidth; sWidth.sprintf("%li", (unsigned long)(2540 * mpImpl->mfWidth));
+ mpImpl->mpHandler->characters(sWidth);
+ mpImpl->mpHandler->endElement("config:config-item");
+
+ configItemOpenElement.addAttribute("config:name", "VisibleAreaHeight");
+ configItemOpenElement.addAttribute("config:type", "int");
+ configItemOpenElement.write(mpImpl->mpHandler);
+ WPXString sHeight; sHeight.sprintf("%li", (unsigned long)(2540 * mpImpl->mfHeight));
+ mpImpl->mpHandler->characters(sHeight);
+ mpImpl->mpHandler->endElement("config:config-item");
+
+ mpImpl->mpHandler->endElement("config:config-item-set");
+
+ mpImpl->mpHandler->endElement("office:settings");
+ }
+
+
+ TagOpenElement *pStyleMasterPageOpenElement = new TagOpenElement("style:master-page");
+
+ TagOpenElement *pDrawPageOpenElement = new TagOpenElement("draw:page");
+
+ TagOpenElement *pStylePageLayoutOpenElement = new TagOpenElement("style:page-layout");
+
+ WPXString sValue;
+ sValue.sprintf("page%i", mpImpl->miPageIndex);
+ pDrawPageOpenElement->addAttribute("draw:name", sValue);
+
+ sValue.sprintf("PM%i", mpImpl->miPageIndex);
+ pStyleMasterPageOpenElement->addAttribute("style:page-layout-name", sValue);
+ pStylePageLayoutOpenElement->addAttribute("style:name", "PM1");
+
+ mpImpl->mPageAutomaticStyles.push_back(pStylePageLayoutOpenElement);
+
+ TagOpenElement *pStylePageLayoutPropertiesOpenElement = new TagOpenElement("style:page-layout-properties");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-top", "0in");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-bottom", "0in");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-left", "0in");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-right", "0in");
+ sValue.sprintf("%s%s", doubleToString(mpImpl->mfWidth).cstr(), "in");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:page-width", sValue);
+ sValue.sprintf("%s%s", doubleToString(mpImpl->mfHeight).cstr(), "in");
+ pStylePageLayoutPropertiesOpenElement->addAttribute("fo:page-height", sValue);
+ pStylePageLayoutPropertiesOpenElement->addAttribute("style:print-orientation", "portrait");
+ mpImpl->mPageAutomaticStyles.push_back(pStylePageLayoutPropertiesOpenElement);
+
+ mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:page-layout-properties"));
+
+ mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:page-layout"));
+
+ sValue.sprintf("dp%i", mpImpl->miPageIndex);
+ pDrawPageOpenElement->addAttribute("draw:style-name", sValue);
+ pStyleMasterPageOpenElement->addAttribute("draw:style-name", sValue);
+
+ TagOpenElement *pStyleStyleOpenElement = new TagOpenElement("style:style");
+ pStyleStyleOpenElement->addAttribute("style:name", sValue);
+ pStyleStyleOpenElement->addAttribute("style:family", "drawing-page");
+ mpImpl->mPageAutomaticStyles.push_back(pStyleStyleOpenElement);
+
+ sValue.sprintf("Page%i", mpImpl->miPageIndex);
+ pDrawPageOpenElement->addAttribute("draw:master-page-name", sValue);
+ pStyleMasterPageOpenElement->addAttribute("style:name", sValue);
+
+ mpImpl->mBodyElements.push_back(pDrawPageOpenElement);
+
+ mpImpl->mPageMasterStyles.push_back(pStyleMasterPageOpenElement);
+ mpImpl->mPageMasterStyles.push_back(new TagCloseElement("style:master-page"));
+
+
+ TagOpenElement *pStyleDrawingPagePropertiesOpenElement = new TagOpenElement("style:drawing-page-properties");
+ // pStyleDrawingPagePropertiesOpenElement->addAttribute("draw:background-size", "border");
+ pStyleDrawingPagePropertiesOpenElement->addAttribute("draw:fill", "none");
+ mpImpl->mPageAutomaticStyles.push_back(pStyleDrawingPagePropertiesOpenElement);
+
+ mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:drawing-page-properties"));
+
+ mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:style"));
+}
+
+void OdgGenerator::endGraphics()
+{
+ mpImpl->mBodyElements.push_back(new TagCloseElement("draw:page"));
+ mpImpl->miPageIndex++;
}
void OdgGenerator::setStyle(const ::WPXPropertyList & propList, const ::WPXPropertyListVector& gradient)