/* 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_ListLevelStyle.h" // Internal includes #include "ODe_Common.h" // AbiWord includes #include #include /******************************************************************************* * ODe_ListLevelStyle ******************************************************************************/ /** * */ void ODe_ListLevelStyle::fetchAttributesFromAbiBlock(const PP_AttrProp& rAP) { const XML_Char* pValue; bool ok; ok = rAP.getAttribute("listid", pValue); UT_ASSERT(ok && pValue != NULL); m_AbiListId = pValue; ok = rAP.getAttribute("level", pValue); UT_ASSERT(ok && pValue != NULL); m_level = pValue; ok = rAP.getProperty("text-indent", pValue); if (ok && pValue != NULL) { if (pValue[0] == '-') { // We want this value to be positive pValue++; m_minLabelWidth = pValue; } else { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); } } ok = rAP.getProperty("margin-left", pValue); if (ok && pValue != NULL) { double abiMarginLeft; double abiTextIndent; abiMarginLeft = UT_convertToDimension(pValue, DIM_CM); if (!m_minLabelWidth.empty()) { rAP.getProperty("text-indent", pValue); abiTextIndent = UT_convertToDimension(pValue, DIM_CM); } else { abiTextIndent = 0.0; } UT_UTF8String_sprintf(m_spaceBefore, "%f%s", abiMarginLeft + abiTextIndent, UT_dimensionName(DIM_CM)); } } /** * */ void ODe_ListLevelStyle::_writeTextProperties(GsfOutput* pODT, const UT_UTF8String& rSpacesOffset) const { UT_UTF8String output; if (!m_fontName.empty()) { UT_UTF8String_sprintf(output, "%s\n", rSpacesOffset.utf8_str(), m_fontName.utf8_str()); ODe_writeUTF8String(pODT, output); } } /** * */ void ODe_ListLevelStyle::_writeListLevelProperties(GsfOutput* pODT, const UT_UTF8String& rSpacesOffset) const { if (!m_minLabelWidth.empty() || !m_spaceBefore.empty()) { UT_UTF8String output; UT_UTF8String_sprintf(output, "%s\n", rSpacesOffset.utf8_str(), m_level.utf8_str(), m_bulletChar.utf8_str()); ODe_writeUTF8String(pODT, output); output = rSpacesOffset; output += " "; _writeTextProperties(pODT, output); _writeListLevelProperties(pODT, output); UT_UTF8String_sprintf(output, "%s\n", rSpacesOffset.utf8_str()); ODe_writeUTF8String(pODT, output); return true; } /******************************************************************************* * ODe_Numbered_ListLevelStyle ******************************************************************************/ /** * */ void ODe_Numbered_ListLevelStyle::fetchAttributesFromAbiBlock( const PP_AttrProp& rAP) { // We first load the common attributes. ODe_ListLevelStyle::fetchAttributesFromAbiBlock(rAP); const XML_Char* pValue; bool ok; ok = rAP.getProperty("list-style", pValue); UT_ASSERT(ok && pValue != NULL); if (!UT_strcmp(pValue, "Numbered List")) { m_numFormat = "1"; } else if (!UT_strcmp(pValue, "Lower Case List")) { m_numFormat = "a"; } else if (!UT_strcmp(pValue, "Upper Case List")) { m_numFormat = "A"; } else if (!UT_strcmp(pValue, "Lower Roman List")) { m_numFormat = "i"; } else if (!UT_strcmp(pValue, "Upper Roman List")) { m_numFormat = "I"; } else if (!UT_strcmp(pValue, "Hebrew List")) { // OpenDocument doesn't support this kind of list, as far as I know. // Collapse to an ordinary numbered list. m_numFormat = "1"; } else if (!UT_strcmp(pValue, "Arabic List")) { // OpenDocument doesn't support this kind of list, as far as I know. // Collapse to an ordinary numbered list. m_numFormat = "1"; } else { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); } ok = rAP.getProperty("start-value", pValue); if (ok && pValue != NULL) { m_startValue = pValue; } // Abiword aways displays the entire level hierarchy. // OBS: This attribute is irrelevant for the first level. if (UT_strcmp(m_level.utf8_str(), "1") != 0) { m_displayLevels = m_level; } } /** * */ bool ODe_Numbered_ListLevelStyle::write(GsfOutput* pODT, const UT_UTF8String& rSpacesOffset) const { UT_UTF8String output; // Build and write the opening tag. UT_UTF8String_sprintf(output, "%s\n", rSpacesOffset.utf8_str()); ODe_writeUTF8String(pODT, output); return true; }