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 #ifdef _MSC_VER
00037 #include <minmax.h>
00038 #endif
00039 
00040 ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
00041     mpPropList(pPropList),
00042     mxTabStops(xTabStops),
00043     msName(sName)
00044 {
00045 }
00046 
00047 ParagraphStyle::~ParagraphStyle()
00048 {
00049     delete mpPropList;
00050 }
00051 
00052 void ParagraphStyle::write(DocumentHandler &xHandler) const
00053 {
00054     WRITER_DEBUG_MSG(("Writing a paragraph style..\n"));
00055 
00056         WPXPropertyList propList;
00057     propList.insert("style:name", msName.cstr());
00058     propList.insert("style:family", "paragraph");
00059     propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
00060     if ((*mpPropList)["style:master-page-name"])
00061         propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr());
00062         xHandler.startElement("style:style", propList);
00063 
00064         propList.clear();
00065     WPXPropertyList::Iter i((*mpPropList));
00066     for (i.rewind(); i.next(); )
00067     {
00068                 if (strcmp(i.key(), "style:list-style-name") == 0)
00069                         propList.insert("style:list-style-name", i()->getStr());
00070         if (strcmp(i.key(), "fo:margin-left") == 0)
00071             propList.insert("fo:margin-left", i()->getStr());
00072         if (strcmp(i.key(), "fo:margin-right") == 0)
00073             propList.insert("fo:margin-right", i()->getStr());
00074         if (strcmp(i.key(), "fo:text-indent") == 0)
00075             propList.insert("fo:text-indent", i()->getStr());
00076         if (strcmp(i.key(), "fo:margin-top") == 0)
00077             propList.insert("fo:margin-top", i()->getStr());
00078         if (strcmp(i.key(), "fo:margin-bottom") == 0)
00079             propList.insert("fo:margin-bottom", i()->getStr());
00080         if (strcmp(i.key(), "fo:line-height") == 0)
00081             propList.insert("fo:line-height", i()->getStr());
00082         if (strcmp(i.key(), "fo:break-before") == 0) 
00083             propList.insert("fo:break-before", i()->getStr());
00084         if (strcmp(i.key(), "fo:text-align") == 0) 
00085             propList.insert("fo:text-align", i()->getStr());
00086                 if (strcmp(i.key(), "fo:text-align-last") == 0)
00087                         propList.insert("fo:text-align-last", i()->getStr());
00088     }
00089     
00090     propList.insert("style:justify-single-word", "false");
00091     xHandler.startElement("style:properties", propList);
00092 
00093         if (mxTabStops.count() > 0) 
00094         {
00095                 TagOpenElement tabListOpen("style:tab-stops");
00096                 tabListOpen.write(xHandler);
00097                 WPXPropertyListVector::Iter i(mxTabStops);
00098                 for (i.rewind(); i.next();)
00099                 {
00100                         TagOpenElement tabStopOpen("style:tab-stop");
00101                         
00102                         WPXPropertyList::Iter j(i());
00103                         for (j.rewind(); j.next(); )
00104                         {
00105                                 tabStopOpen.addAttribute(j.key(), j()->getStr().cstr());            
00106                         }
00107                         tabStopOpen.write(xHandler);
00108                         xHandler.endElement("style:tab-stop");
00109                 }
00110                 xHandler.endElement("style:tab-stops");
00111         }
00112 
00113     xHandler.endElement("style:properties");
00114     xHandler.endElement("style:style");
00115 }
00116 
00117 SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) :
00118     Style(psName),
00119         mPropList(xPropList)
00120 {
00121 }
00122 
00123 void SpanStyle::write(DocumentHandler &xHandler) const 
00124 {
00125     WRITER_DEBUG_MSG(("Writing a span style..\n"));
00126         WPXPropertyList styleOpenList;    
00127     styleOpenList.insert("style:name", getName());
00128     styleOpenList.insert("style:family", "text");
00129         xHandler.startElement("style:style", styleOpenList);
00130 
00131         WPXPropertyList propList(mPropList);    
00132 
00133     if (mPropList["style:font-name"])
00134     {
00135         propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr());
00136         propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr());
00137     }
00138 
00139     if (mPropList["fo:font-size"])
00140     {
00141         propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr());
00142         propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr());
00143     }
00144     
00145     if (mPropList["fo:font-weight"])
00146     {
00147         propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr());
00148         propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr());
00149     }
00150 
00151     if (mPropList["fo:font-style"])
00152     {
00153         propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr());
00154         propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr());
00155     }
00156 
00157         xHandler.startElement("style:properties", propList);
00158 
00159     xHandler.endElement("style:properties");
00160     xHandler.endElement("style:style");
00161 }
KDE Home | KDE Accessibility Home | Description of Access Keys