--Boundary-00=_E7z4KlzI2O0r6Wi Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Here is a patch that introduces page borders into the MS Word filter. Cyrille wanted me to post it here for review before committing it. I have tested it with oowriter since kword doesn't show page borders yet. In addition to the fo:border* attributes, it also creates fo:margin and fo:padding attributes for pages. I'm not sure if these are handled correctly yet by KOffice, but I'm going to find out. Comments are welcome. -Inge --Boundary-00=_E7z4KlzI2O0r6Wi Content-Type: text/x-patch; charset="UTF-8"; name="msword-odf-page-borders.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="msword-odf-page-borders.diff" Index: filters/kword/msword-odf/paragraph.cpp =================================================================== --- filters/kword/msword-odf/paragraph.cpp (revision 1039416) +++ filters/kword/msword-odf/paragraph.cpp (working copy) @@ -421,6 +421,7 @@ // // TODO: Check if we can use fo:border instead of all the // fo:border-{top,bottom,left,right} + // TODO: Check if borderStyle is "double" and add attributes for that. if ( !refPap || refPap->brcTop.brcType != pap.brcTop.brcType ) { style->addProperty( "fo:border-top", Conversion::setBorderAttributes( pap.brcTop ), KoGenStyle::ParagraphType ); Index: filters/kword/msword-odf/document.cpp =================================================================== --- filters/kword/msword-odf/document.cpp (revision 1039416) +++ filters/kword/msword-odf/document.cpp (working copy) @@ -358,6 +358,7 @@ m_masterStyle->addAttribute("style:display-name", masterStyleName.append(QString::number(m_textHandler->m_sectionNumber))); m_masterStyleName = m_mainStyles->lookup(*m_masterStyle, masterStyleName, KoGenStyles::DontForceNumbering); delete m_masterStyle; //delete the object since we've added it to the collection + //set master style name in m_textHandler because that's where we'll write it m_textHandler->m_masterStyleName = m_masterStyleName; //get a pointer to the object in the collection @@ -379,11 +380,15 @@ bool landscape = (sep->dmOrientPage == 2); m_pageLayoutStyle->addProperty("style:print-orientation", landscape? "landscape" : "portrait"); m_pageLayoutStyle->addProperty("style:num-format", "1"); + + // Set default left/right margins for the case when there is no + // border. This will be changed below if there are borders defined. m_pageLayoutStyle->addPropertyPt("fo:margin-left", (double)sep->dxaLeft / 20.0); m_pageLayoutStyle->addPropertyPt("fo:margin-right", (double)sep->dxaRight / 20.0); - QString header(""); + //set the minimum height of header/footer to the full margin minus margin above header //TODO the margin between header/footer and text is just hard-coded for now + QString header(""); header.append("dyaTop - sep->dyaHdrTop)/20.0)); header.append("pt\"/>"); @@ -395,12 +400,62 @@ footer.append(""); m_pageLayoutStyle->addProperty("1header-style", header, KoGenStyle::StyleChildElement); m_pageLayoutStyle->addProperty("2footer-style", footer, KoGenStyle::StyleChildElement); + m_pageLayoutStyle->setAutoStyleInStylesDotXml(true); pageLayoutStyleName = m_mainStyles->lookup(*m_pageLayoutStyle, pageLayoutStyleName, KoGenStyles::DontForceNumbering); m_masterStyle->addAttribute("style:page-layout-name", pageLayoutStyleName); - // TODO apply brcTop/brcLeft etc. to the main FRAME + // Page borders + // FIXME: check if we can use fo:border instead of fo:border-left, etc. + if (sep->brcLeft.brcType != 0 ) { + m_pageLayoutStyle->addProperty( "fo:border-left", + Conversion::setBorderAttributes( sep->brcLeft ) ); + + } + if (sep->brcTop.brcType != 0 ) { + m_pageLayoutStyle->addProperty( "fo:border-top", + Conversion::setBorderAttributes( sep->brcTop ) ); + } + if (sep->brcRight.brcType != 0 ) { + m_pageLayoutStyle->addProperty( "fo:border-right", + Conversion::setBorderAttributes( sep->brcRight ) ); + } + if (sep->brcBottom.brcType != 0 ) { + m_pageLayoutStyle->addProperty( "fo:border-bottom", + Conversion::setBorderAttributes( sep->brcBottom ) ); + } + + // the pgbOffsetFrom variable determins how to calculate the margins and paddings. + if (sep->pgbOffsetFrom == 0) { + // page border offset is from the text + m_pageLayoutStyle->addPropertyPt("fo:padding-left", sep->brcLeft.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:padding-top", sep->brcTop.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:padding-right", sep->brcRight.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:padding-bottom", sep->brcBottom.dptSpace); + // FIXME: How should fo:margin be created in this case? + } + else { + // page border offset is from the edge of the page + + // Add margin. This value is fetched directly from the BRC's. + m_pageLayoutStyle->addPropertyPt("fo:margin-left", sep->brcLeft.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:margin-top", sep->brcTop.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:margin-right", sep->brcRight.dptSpace); + m_pageLayoutStyle->addPropertyPt("fo:margin-bottom", sep->brcBottom.dptSpace); + + // The *20 and /20 below is the conversion between twips (1/20th of a point) and points. + m_pageLayoutStyle->addPropertyPt("fo:padding-left", + (sep->dxaLeft - (sep->brcLeft.dptSpace * 20)) / 20); + m_pageLayoutStyle->addPropertyPt("fo:padding-top", + (sep->dyaTop - (sep->brcTop.dptSpace * 20)) / 20); + m_pageLayoutStyle->addPropertyPt("fo:padding-right", + (sep->dxaRight - (sep->brcRight.dptSpace * 20)) / 20); + m_pageLayoutStyle->addPropertyPt("fo:padding-bottom", + (sep->dyaBottom - (sep->brcBottom.dptSpace * 20)) / 20); + } + + // TODO use sep->fEndNote to set the 'use endnotes or footnotes' flag } @@ -412,14 +467,14 @@ kDebug(30513) << "setting margin for header..."; m_pageLayoutStyle->addPropertyPt("fo:margin-top", (double)sep->dyaHdrTop / 20.0); } - else { - kDebug(30513) << "setting margin for no header..."; + else if (sep->brcTop.brcType == 0 ) { + kDebug(30513) << "setting margin for no header and no top border..."; m_pageLayoutStyle->addPropertyPt("fo:margin-top", (double)sep->dyaTop / 20.0); } if(m_hasFooter) { m_pageLayoutStyle->addPropertyPt("fo:margin-bottom", (double)sep->dyaHdrBottom / 20.0); } - else { + else if (sep->brcBottom.brcType == 0 ) { m_pageLayoutStyle->addPropertyPt("fo:margin-bottom", (double)sep->dyaBottom / 20.0); } //insert the page-layout style into the collection, --Boundary-00=_E7z4KlzI2O0r6Wi Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ koffice-devel mailing list koffice-devel@kde.org https://mail.kde.org/mailman/listinfo/koffice-devel --Boundary-00=_E7z4KlzI2O0r6Wi--