/* 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_Style_Style.h" // Internal includes #include "ODe_Common.h" // AbiWord includes #include #include #include // External includes #include /******************************************************************************* * ODe_Style_Style ******************************************************************************/ /** * Constructor */ ODe_Style_Style::ODe_Style_Style() : m_pSectionProps(NULL), m_pParagraphProps(NULL), m_pTextProps(NULL), m_pTableProps(NULL), m_pColumnProps(NULL), m_pRowProps(NULL), m_pCellProps(NULL), m_pGraphicProps(NULL) { } /** * Destructor */ ODe_Style_Style::~ODe_Style_Style() { DELETEP(m_pSectionProps); DELETEP(m_pParagraphProps); DELETEP(m_pTextProps); DELETEP(m_pTableProps); DELETEP(m_pColumnProps); DELETEP(m_pRowProps); DELETEP(m_pCellProps); DELETEP(m_pGraphicProps); } /** * Writes and its subelements. * * @param rSpacesOffset Space characters written at the beginning of * each new line. */ bool ODe_Style_Style::write(GsfOutput* pODT, const UT_UTF8String& rSpacesOffset) const { UT_UTF8String output; UT_UTF8String subOffset; UT_UTF8String escape; output += rSpacesOffset; output += "write(output, subOffset); } ODE_WRITE_STYLE_PROPS(m_pSectionProps); ODE_WRITE_STYLE_PROPS(m_pParagraphProps); ODE_WRITE_STYLE_PROPS(m_pTextProps); ODE_WRITE_STYLE_PROPS(m_pTableProps); ODE_WRITE_STYLE_PROPS(m_pColumnProps); ODE_WRITE_STYLE_PROPS(m_pRowProps); ODE_WRITE_STYLE_PROPS(m_pCellProps); ODE_WRITE_STYLE_PROPS(m_pGraphicProps); #undef ODE_WRITE_STYLE_PROPS output += rSpacesOffset; output += "\n"; ODe_writeUTF8String(pODT, output); return true; } /** * Returns true if the specified PP_AttrProp contains properties that belongs to * elements */ bool ODe_Style_Style::hasTextStyleProps(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getProperty("color", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("text-decoration", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("text-position", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("font-family", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("font-size", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("lang", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("font-style", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("font-weight", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("display", pValue); if (ok && pValue != NULL) { return true; } return false; } /** * Returns true if the specified PP_AttrProp contains properties that belongs to * elements */ bool ODe_Style_Style::hasParagraphStyleProps(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getProperty("bgcolor", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("line-height", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("text-align", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("text-indent", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("widows", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("orphans", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getAttribute("listid", pValue); if (ok && pValue != NULL) { // This block is a list item, so, its margin-left property is not // valid as paragraph attribute. // So, we don't check for it. } else { ok = pAP->getProperty("margin-left", pValue); if (ok && pValue != NULL) { return true; } } ok = pAP->getProperty("margin-right", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("margin-top", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("margin-bottom", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("keep-with-next", pValue); if (ok && pValue != NULL) { return true; } return false; } /** * */ bool ODe_Style_Style::hasSectionInfo(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getProperty("columns", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("column-gap", pValue); if (ok && pValue != NULL) { return true; } ok= pAP->getProperty("page-margin-top",pValue); if (ok && pValue != NULL) { return true; } ok= pAP->getProperty("page-margin-left",pValue); if (ok && pValue != NULL) { return true; } ok= pAP->getProperty("page-margin-right",pValue); if (ok && pValue != NULL) { return true; } ok= pAP->getProperty("page-margin-bottom",pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("page-margin-header", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("page-margin-footer", pValue); if (ok && pValue != NULL) { return true; } return false; } /** * */ bool ODe_Style_Style::hasTableCellStyleProps(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; // Left border ok = pAP->getProperty("left-thickness", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("left-color", pValue); if (ok && pValue != NULL) { return true; } // Right border ok = pAP->getProperty("right-thickness", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("right-color", pValue); if (ok && pValue != NULL) { return true; } // Top border ok = pAP->getProperty("top-thickness", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("top-color", pValue); if (ok && pValue != NULL) { return true; } // Bottom border ok = pAP->getProperty("bot-thickness", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("bot-color", pValue); if (ok && pValue != NULL) { return true; } // Background color ok = pAP->getProperty("background-color", pValue); if (ok && pValue != NULL) { return true; } // If we reached this point it's because there are no table cell props at all // on this AbiWord element attributes and properties. return false; } /** * */ bool ODe_Style_Style::hasTableStyleProps(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getProperty("background-color", pValue); if (ok && pValue != NULL) { return true; } ok = pAP->getProperty("table-column-props", pValue); if (ok && pValue != NULL) { return true; } // If we reached this point it's because there are no table props at all // on this AbiWord element attributes and properties. return false; } /** * It does not take style names into consideration. * Read it like: "is style "T1" equivalent to style "T2" * It is *NOT* like: "is style A equal to style B" */ bool ODe_Style_Style::isEquivalentTo(const ODe_Style_Style& rStyle) { bool isEqual; isEqual = m_family == rStyle.m_family && m_parentStyleName == rStyle.m_parentStyleName && m_nextStyleName == rStyle.m_nextStyleName && m_masterPageName == rStyle.m_masterPageName; if (!isEqual) {return false;} #define ODE_EQUAL_STYLE_PROPS(m_pProps) \ if (m_pProps == NULL && rStyle.m_pProps == NULL) { \ isEqual = true; \ } else if (m_pProps != NULL && rStyle.m_pProps != NULL) { \ isEqual = (*m_pProps) == (*rStyle.m_pProps); \ } else { \ isEqual = false; \ } \ if (!isEqual) {return false;} ODE_EQUAL_STYLE_PROPS(m_pSectionProps); ODE_EQUAL_STYLE_PROPS(m_pParagraphProps); ODE_EQUAL_STYLE_PROPS(m_pTextProps); ODE_EQUAL_STYLE_PROPS(m_pTableProps); ODE_EQUAL_STYLE_PROPS(m_pColumnProps); ODE_EQUAL_STYLE_PROPS(m_pRowProps); ODE_EQUAL_STYLE_PROPS(m_pCellProps); ODE_EQUAL_STYLE_PROPS(m_pGraphicProps); #undef ODE_EQUAL_STYLE_PROPS // If not returned until here it's because they're equal. return true; } /** * */ bool ODe_Style_Style::isEmpty() const { #define ODE_IS_STYLE_PROPS_EMPTY(pStyleProps) \ if (pStyleProps) { \ if(!pStyleProps->isEmpty()) { return false; } \ } ODE_IS_STYLE_PROPS_EMPTY(m_pSectionProps); ODE_IS_STYLE_PROPS_EMPTY(m_pParagraphProps); ODE_IS_STYLE_PROPS_EMPTY(m_pTextProps); ODE_IS_STYLE_PROPS_EMPTY(m_pTableProps); ODE_IS_STYLE_PROPS_EMPTY(m_pColumnProps); ODE_IS_STYLE_PROPS_EMPTY(m_pRowProps); ODE_IS_STYLE_PROPS_EMPTY(m_pCellProps); ODE_IS_STYLE_PROPS_EMPTY(m_pGraphicProps); #undef ODE_IS_STYLE_PROPS_EMPTY return true; } /** * */ ODe_Style_Style& ODe_Style_Style::operator=(const ODe_Style_Style& rStyle) { #define ODE_COPY_STYLE_PROPS(m_pStyleProps, StyleProps) \ if (rStyle.m_pStyleProps) { \ if (m_pStyleProps == NULL) { \ m_pStyleProps = new StyleProps(); \ } \ *m_pStyleProps = *(rStyle.m_pStyleProps); \ } else { \ DELETEP(m_pStyleProps); \ } ODE_COPY_STYLE_PROPS(m_pSectionProps, SectionProps); ODE_COPY_STYLE_PROPS(m_pParagraphProps, ParagraphProps); ODE_COPY_STYLE_PROPS(m_pTextProps, TextProps); ODE_COPY_STYLE_PROPS(m_pTableProps, TableProps); ODE_COPY_STYLE_PROPS(m_pColumnProps, ColumnProps); ODE_COPY_STYLE_PROPS(m_pRowProps, RowProps); ODE_COPY_STYLE_PROPS(m_pCellProps, CellProps); ODE_COPY_STYLE_PROPS(m_pGraphicProps, GraphicProps); #undef ODE_COPY_STYLE_PROPS return *this; } /** * Defines the style from attributes and properties of an AbiWord style. * * @return "false" if an error ocurred. */ bool ODe_Style_Style::fetchAttributesFromAbiStyle(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getAttribute(PT_NAME_ATTRIBUTE_NAME, pValue); if (!ok) {return false;} m_name = pValue; ok = pAP->getAttribute(PT_FOLLOWEDBY_ATTRIBUTE_NAME, pValue); if (ok && pValue != NULL) { if (strcmp("Current Settings", pValue) != 0) { m_nextStyleName = pValue; } } ok = pAP->getAttribute(PT_BASEDON_ATTRIBUTE_NAME, pValue); if (ok && pValue != NULL) { if (strcmp(pValue, "None") != 0) { // OpenDocument don't use a "None" to say that is has no parent. // To say that it simply doesn't define this attribute. m_parentStyleName = pValue; } } if (m_pTextProps == NULL) { m_pTextProps = new TextProps(); } m_pTextProps->fetchAttributesFromAbiProps(*pAP); if (m_pParagraphProps == NULL) { m_pParagraphProps = new ParagraphProps(); } m_pParagraphProps->fetchAttributesFromAbiProps(*pAP); return true; } /** * Defines the style from attributes and properties of an AbiWord . */ void ODe_Style_Style::fetchAttributesFromAbiSpan(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getAttribute("style", pValue); if (ok && pValue != NULL) { m_parentStyleName = pValue; } if (m_pTextProps == NULL) { m_pTextProps = new TextProps(); } m_pTextProps->fetchAttributesFromAbiProps(*pAP); } /** * Fetch attributes from an AbiWord

tag. Usually paragraph style attributes. */ void ODe_Style_Style::fetchAttributesFromAbiBlock(const PP_AttrProp* pAP) { const gchar* pValue; bool ok; ok = pAP->getAttribute("style", pValue); if (ok && pValue != NULL) { m_parentStyleName = pValue; } if (m_pTextProps == NULL) { m_pTextProps = new TextProps(); } m_pTextProps->fetchAttributesFromAbiProps(*pAP); if (m_pParagraphProps == NULL) { m_pParagraphProps = new ParagraphProps(); } m_pParagraphProps->fetchAttributesFromAbiProps(*pAP); ok = pAP->getAttribute("listid", pValue); if (ok && pValue != NULL) { // This block is a list item, so, it's margin-left property is not // valid as paragraph attribute. m_pParagraphProps->m_marginLeft.clear(); } } /** * Fetch attributes from an AbiWord

tag. Usually column info for * an OpenDocument element. */ void ODe_Style_Style::fetchAttributesFromAbiSection(const PP_AttrProp* pAP) { if (m_pSectionProps == NULL) { m_pSectionProps = new SectionProps(); } m_pSectionProps->fetchAttributesFromAbiProps(*pAP); } /** * Defines the style from attributes and properties of an AbiWord . */ void ODe_Style_Style::fetchAttributesFromAbiTable(const PP_AttrProp* pAP) { if (m_pTableProps == NULL) { m_pTableProps = new TableProps(); } m_pTableProps->fetchAttributesFromAbiProps(*pAP); } /** * Defines the style from attributes and properties of an AbiWord . */ void ODe_Style_Style::fetchAttributesFromAbiCell(const PP_AttrProp* pAP) { if (m_pCellProps == NULL) { m_pCellProps = new CellProps(); } m_pCellProps->fetchAttributesFromAbiProps(*pAP); } /** * Defines the style from attributes and properties of an AbiWord . */ void ODe_Style_Style::fetchAttributesFromAbiFrame(const PP_AttrProp& rAP) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->fetchAttributesFromAbiProps(rAP); } /** * */ void ODe_Style_Style::setBreakBefore(const gchar* pBreakBefore) { if (m_pParagraphProps == NULL) { m_pParagraphProps = new ParagraphProps(); } m_pParagraphProps->m_breakBefore = pBreakBefore; } /** * */ const UT_UTF8String& ODe_Style_Style::getFontName() { if (m_pTextProps == NULL) { m_pTextProps = new TextProps(); } return m_pTextProps->m_fontName; } /** * */ void ODe_Style_Style::setColumnWidth(const gchar* pColumnWidth) { if (m_pColumnProps == NULL) { m_pColumnProps = new ColumnProps(); } m_pColumnProps->m_columnWidth = pColumnWidth; } /** * */ void ODe_Style_Style::setRowHeight(const gchar* pRowHeight) { if (m_pRowProps == NULL) { m_pRowProps = new RowProps(); } m_pRowProps->m_rowHeight = pRowHeight; } /** * */ void ODe_Style_Style::setTableCellBackgroundColor( const UT_UTF8String& rBackgroundColor) { if (m_pCellProps == NULL) { m_pCellProps = new CellProps(); } m_pCellProps->m_backgroundColor = rBackgroundColor; } /** * */ void ODe_Style_Style::setWrap(const UT_UTF8String& rWrap) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->m_wrap = rWrap; } /** * */ void ODe_Style_Style::setRunThrough(const UT_UTF8String& rRunThrough) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->m_runThrough = rRunThrough; } /** * */ void ODe_Style_Style::setPadding(const UT_UTF8String& rPadding) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->m_padding = rPadding; } /** * */ void ODe_Style_Style::setHorizontalPos(const UT_UTF8String& rHorizontalPos) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->m_horizontalPos = rHorizontalPos; } /** * */ void ODe_Style_Style::setVerticalPos(const UT_UTF8String& rVerticalPos) { if (m_pGraphicProps == NULL) { m_pGraphicProps = new GraphicProps(); } m_pGraphicProps->m_verticalPos = rVerticalPos; } /******************************************************************************* * SectionProps ******************************************************************************/ /** * */ bool ODe_Style_Style::SectionProps::isEmpty() const { return m_columnCount.empty() && m_columnGap.empty(); } /** * */ void ODe_Style_Style::SectionProps:: fetchAttributesFromAbiProps(const PP_AttrProp& rAP) { const gchar* pValue; bool ok; ok = rAP.getProperty("columns", pValue); if (ok && pValue != NULL) { m_columnCount = pValue; } ok = rAP.getProperty("column-gap", pValue); if (ok && pValue != NULL) { m_columnGap = pValue; } } /** * */ void ODe_Style_Style::SectionProps:: write(UT_UTF8String& rOutput, const UT_UTF8String& rSpacesOffset) const { if (isEmpty()) { return; } rOutput += rSpacesOffset; rOutput += "\n"; rOutput += rSpacesOffset; rOutput += " 1) && (pValue[len - 1] == '+')) { gchar* temp = (gchar*)pValue; temp[len-1] = '\0'; m_lineHeightAtLeast = UT_UTF8String_sprintf("%fin", UT_convertToDimension(temp, DIM_IN)); m_lineHeight.clear(); // make sure this is empty } else { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); } } else if(strstr(pValue, "pt")) { // "exactly" spacing m_lineHeight = UT_UTF8String_sprintf("%fin", UT_convertToDimension(pValue, DIM_IN)); m_lineHeightAtLeast.clear(); // make sure this is empty } else { //"single", "double", "1.5 lines", or "multiple" spacing m_lineHeight = UT_UTF8String_sprintf("%.0f%%", atof(pValue) * 100); m_lineHeightAtLeast.clear(); // make sure this is empty } } ok = rAP.getProperty("text-align", pValue); if (ok && pValue != NULL) { if(!strcmp(pValue, "right")) { m_textAlign = "end"; //see Bug 10719 } else { m_textAlign = pValue; } } ok = rAP.getProperty("text-indent", pValue); if (ok && pValue != NULL) { m_textIndent = pValue; } ok = rAP.getProperty("dom-dir", pValue); if (ok && pValue != NULL) { if(!strcmp(pValue, "rtl")) { m_writingMode = "rl"; } else { m_writingMode = "lr"; } } ok = rAP.getProperty("widows", pValue); if (ok && pValue != NULL) { m_widows = pValue; } ok = rAP.getProperty("orphans", pValue); if (ok && pValue != NULL) { m_orphans = pValue; } ok = rAP.getProperty("margin-left", pValue); if (ok && pValue != NULL) { m_marginLeft = pValue; } ok = rAP.getProperty("margin-right", pValue); if (ok && pValue != NULL) { m_marginRight = pValue; } ok = rAP.getProperty("margin-top", pValue); if (ok && pValue != NULL) { m_marginTop = pValue; } ok = rAP.getProperty("margin-bottom", pValue); if (ok && pValue != NULL) { m_marginBottom = pValue; } ok = rAP.getProperty("keep-with-next", pValue); if (ok && pValue != NULL) { if (!strcmp(pValue, "yes")) { m_keepWithNext = "always"; } else { m_keepWithNext = "auto"; } } } /** * */ void ODe_Style_Style::ParagraphProps:: write(UT_UTF8String& rOutput, const UT_UTF8String& rSpacesOffset) const { if (isEmpty()) { return; } rOutput += rSpacesOffset; rOutput += "