filters

DocumentElement.cxx

00001 /* DocumentElement: The items we are collecting to be put into the Writer
00002  * document: paragraph and spans of text, as well as section breaks.
00003  *
00004  * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * For further information visit http://libwpd.sourceforge.net
00022  *
00023  */
00024 
00025 /* "This product is not manufactured, approved, or supported by 
00026  * Corel Corporation or Corel Corporation Limited."
00027  */
00028 
00029 #include "DocumentElement.hxx"
00030 #include "DocumentHandler.hxx"
00031 #include "FilterInternal.hxx"
00032 #include <string.h>
00033 
00034 #define ASCII_SPACE 0x0020
00035 
00036 void TagElement::print() const
00037 {
00038     WRITER_DEBUG_MSG(("%s\n", msTagName.cstr()));
00039 }
00040 
00041 void TagOpenElement::write(DocumentHandler &xHandler) const
00042 {
00043     xHandler.startElement(getTagName().cstr(), maAttrList);
00044 }
00045 
00046 void TagOpenElement::print() const
00047 { 
00048     TagElement::print();    
00049 }
00050 
00051 void TagOpenElement::addAttribute(const char *szAttributeName, const WPXString &sAttributeValue)
00052 {
00053         maAttrList.insert(szAttributeName, sAttributeValue);
00054 }
00055 
00056 void TagCloseElement::write(DocumentHandler &xHandler) const
00057 {
00058     WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr()));
00059 
00060     xHandler.endElement(getTagName().cstr());
00061 }
00062 
00063 void CharDataElement::write(DocumentHandler &xHandler) const
00064 {
00065     WRITER_DEBUG_MSG(("TextElement: write\n"));
00066     xHandler.characters(msData);
00067 }
00068 
00069 TextElement::TextElement(const WPXString & sTextBuf) :
00070     msTextBuf(sTextBuf, false)
00071 {
00072 }
00073 
00074 // write: writes a text run, appropriately converting spaces to <text:s>
00075 // elements
00076 void TextElement::write(DocumentHandler &xHandler) const
00077 {
00078     WPXPropertyList xBlankAttrList;
00079         
00080     WPXString sTemp;
00081 
00082     int iNumConsecutiveSpaces = 0;
00083         WPXString::Iter i(msTextBuf);
00084     for (i.rewind(); i.next();) 
00085         {
00086         if (*(i()) == ASCII_SPACE)
00087             iNumConsecutiveSpaces++;
00088         else
00089             iNumConsecutiveSpaces = 0;
00090 
00091         if (iNumConsecutiveSpaces > 1) {
00092             if (sTemp.len() > 0) {
00093                 xHandler.characters(sTemp);
00094                 sTemp.clear();
00095             }
00096             xHandler.startElement("text:s", xBlankAttrList);
00097             xHandler.endElement("text:s");
00098         }
00099         else {
00100                         sTemp.append(i());
00101         }
00102     }
00103     xHandler.characters(sTemp);
00104 }
KDE Home | KDE Accessibility Home | Description of Access Keys