filters

TextRunStyle.cxx

00001 /* TextRunStyle: Stores (and writes) paragraph/span-style-based information
00002  * (e.g.: a paragraph might be bold) that is needed at the head of an OO
00003  * document.
00004  *
00005  * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
00006  * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
00007  * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023  *
00024  * For further information visit http://libwpd.sourceforge.net
00025  *
00026  */
00027 
00028 /* "This product is not manufactured, approved, or supported by
00029  * Corel Corporation or Corel Corporation Limited."
00030  */
00031 #include "FilterInternal.hxx"
00032 #include "TextRunStyle.hxx"
00033 #include "WriterProperties.hxx"
00034 #include "DocumentElement.hxx"
00035 
00036 #include <cstring>
00037 
00038 #ifdef _MSC_VER
00039 #include <minmax.h>
00040 #endif
00041 
00042 ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
00043     mpPropList(pPropList),
00044     mxTabStops(xTabStops),
00045     msName(sName)
00046 {
00047 }
00048 
00049 ParagraphStyle::~ParagraphStyle()
00050 {
00051     delete mpPropList;
00052 }
00053 
00054 void ParagraphStyle::write(DocumentHandler &xHandler) const
00055 {
00056     WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
00057 
00058         WPXPropertyList propList;
00059     propList.insert("style:name", msName.cstr());
00060     propList.insert("style:family", "paragraph");
00061     propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
00062     if ((*mpPropList)["style:master-page-name"])
00063         propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr());
00064         xHandler.startElement("style:style", propList);
00065 
00066         propList.clear();
00067     WPXPropertyList::Iter i((*mpPropList));
00068     for (i.rewind(); i.next(); )
00069     {
00070                 if (strcmp(i.key(), "style:list-style-name") == 0)
00071                         propList.insert("style:list-style-name", i()->getStr());
00072         if (strcmp(i.key(), "fo:margin-left") == 0)
00073             propList.insert("fo:margin-left", i()->getStr());
00074         if (strcmp(i.key(), "fo:margin-right") == 0)
00075             propList.insert("fo:margin-right", i()->getStr());
00076         if (strcmp(i.key(), "fo:text-indent") == 0)
00077             propList.insert("fo:text-indent", i()->getStr());
00078         if (strcmp(i.key(), "fo:margin-top") == 0)
00079             propList.insert("fo:margin-top", i()->getStr());
00080         if (strcmp(i.key(), "fo:margin-bottom") == 0)
00081             propList.insert("fo:margin-bottom", i()->getStr());
00082         if (strcmp(i.key(), "fo:line-height") == 0)
00083             propList.insert("fo:line-height", i()->getStr());
00084         if (strcmp(i.key(), "fo:break-before") == 0) 
00085             propList.insert("fo:break-before", i()->getStr());
00086         if (strcmp(i.key(), "fo:text-align") == 0) 
00087             propList.insert("fo:text-align", i()->getStr());
00088                 if (strcmp(i.key(), "fo:text-align-last") == 0)
00089                         propList.insert("fo:text-align-last", i()->getStr());
00090     }
00091     
00092     propList.insert("style:justify-single-word", "false");
00093     xHandler.startElement("style:properties", propList);
00094 
00095         if (mxTabStops.count() > 0) 
00096         {
00097                 TagOpenElement tabListOpen("style:tab-stops");
00098                 tabListOpen.write(xHandler);
00099                 WPXPropertyListVector::Iter i(mxTabStops);
00100                 for (i.rewind(); i.next();)
00101                 {
00102                         TagOpenElement tabStopOpen("style:tab-stop");
00103                         
00104                         WPXPropertyList::Iter j(i());
00105                         for (j.rewind(); j.next(); )
00106                         {
00107                                 tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());            
00108                         }
00109                         tabStopOpen.write(xHandler);
00110                         xHandler.endElement("style:tab-stop");
00111                 }
00112                 xHandler.endElement("style:tab-stops");
00113         }
00114 
00115     xHandler.endElement("style:properties");
00116     xHandler.endElement("style:style");
00117 }
00118 
00119 SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
00120     Style(psName),
00121         mPropList(xPropList)
00122 {
00123 }
00124 
00125 void SpanStyle::write(DocumentHandler &xHandler) const 
00126 {
00127     WRITER_DEBUG_MSG(("Writing a span style..\n"));
00128         WPXPropertyList styleOpenList;    
00129     styleOpenList.insert("style:name", getName());
00130     styleOpenList.insert("style:family", "text");
00131         xHandler.startElement("style:style", styleOpenList);
00132 
00133         WPXPropertyList propList(mPropList);    
00134 
00135     if (mPropList["style:font-name"])
00136     {
00137         propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
00138         propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
00139     }
00140 
00141     if (mPropList["fo:font-size"])
00142     {
00143         propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
00144         propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
00145     }
00146     
00147     if (mPropList["fo:font-weight"])
00148     {
00149         propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
00150         propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
00151     }
00152 
00153     if (mPropList["fo:font-style"])
00154     {
00155         propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
00156         propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
00157     }
00158 
00159         xHandler.startElement("style:properties", propList);
00160 
00161     xHandler.endElement("style:properties");
00162     xHandler.endElement("style:style");
00163 }
KDE Home | KDE Accessibility Home | Description of Access Keys