filters

ExportDocStruct.cc

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2001, 2002 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qstring.h>
00022 #include <qtextcodec.h>
00023 #include <qfile.h>
00024 
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 
00028 #include <KWEFBaseWorker.h>
00029 
00030 #include "ExportFilter.h"
00031 #include "ExportDocStruct.h"
00032 
00033 QString HtmlDocStructWorker::getStartOfListOpeningTag(const CounterData::Style typeList, bool& ordered)
00034 {
00035     QString strResult;
00036     switch (typeList)
00037     {
00038     case CounterData::STYLE_CUSTOMBULLET:
00039     default:
00040     case CounterData::STYLE_NONE:
00041     case CounterData::STYLE_CIRCLEBULLET:
00042     case CounterData::STYLE_SQUAREBULLET:
00043     case CounterData::STYLE_DISCBULLET:
00044         {
00045             ordered=false;
00046             strResult="<ul>\n";
00047             break;
00048         }
00049     case CounterData::STYLE_NUM:
00050     case CounterData::STYLE_ALPHAB_L:
00051     case CounterData::STYLE_ALPHAB_U:
00052     case CounterData::STYLE_ROM_NUM_L:
00053     case CounterData::STYLE_ROM_NUM_U:
00054     case CounterData::STYLE_CUSTOM:
00055         {
00056             ordered=true;
00057             strResult="<ol>\n";
00058             break;
00059         }
00060     }
00061     return strResult;
00062 }
00063 
00064 void HtmlDocStructWorker::openFormatData(const FormatData& formatOrigin,
00065     const FormatData& format, const bool force, const bool allowBold)
00066 {
00067     // TODO/FIXME: find another way to find fixed fonts
00068     // TODO/FIXME: (leaves out "Typewriter", "Monospace", "Mono")
00069     if (format.text.fontName.contains("ourier"))
00070     {
00071         *m_streamOut << "<tt>"; // teletype
00072     }
00073 
00074     if (force || (formatOrigin.text.italic!=format.text.italic))
00075     {
00076         if (format.text.italic)
00077         {
00078             *m_streamOut << "<i>";
00079         }
00080     }
00081 
00082     if (force || ((formatOrigin.text.weight>=75)!=(format.text.weight>=75)))
00083     {
00084         if (allowBold && (format.text.weight >= 75))
00085         {
00086             *m_streamOut << "<b>";
00087         }
00088     }
00089 
00090     if (force || (formatOrigin.text.verticalAlignment!=format.text.verticalAlignment))
00091     {
00092         if (1==format.text.verticalAlignment)
00093         {
00094             *m_streamOut << "<sub>"; //Subscript
00095         }
00096         else if (2==format.text.verticalAlignment)
00097         {
00098             *m_streamOut << "<sup>"; //Superscript
00099         }
00100     }
00101 
00102     // Strict (X)HTML gives use also <big> and <small> to play with.
00103 }
00104 
00105 void HtmlDocStructWorker::closeFormatData(const FormatData& formatOrigin,
00106     const FormatData& format, const bool force, const bool allowBold)
00107 {
00108     if (force || (formatOrigin.text.verticalAlignment!=format.text.verticalAlignment))
00109     {
00110         if (2==format.text.verticalAlignment)
00111         {
00112             *m_streamOut << "</sup>"; //Superscript
00113         }
00114         else if (1==format.text.verticalAlignment)
00115         {
00116             *m_streamOut << "</sub>"; //Subscript
00117         }
00118     }
00119 
00120     if (force || ((formatOrigin.text.weight>=75)!=(format.text.weight>=75)))
00121     {
00122         if (allowBold && (format.text.weight >= 75))
00123         {
00124             *m_streamOut << "</b>";
00125         }
00126     }
00127 
00128     if (force || (formatOrigin.text.italic!=format.text.italic))
00129     {
00130         if (format.text.italic)
00131         {
00132             *m_streamOut << "</i>";
00133         }
00134     }
00135 
00136     if (format.text.fontName.contains("ourier")) // Courier?
00137     {
00138         *m_streamOut << "</tt>"; // teletype
00139     }
00140 }
00141 
00142 void HtmlDocStructWorker::openParagraph(const QString& strTag,
00143     const LayoutData& layout,QChar::Direction /*direction*/)
00144 {
00145     *m_streamOut << '<' << strTag << ">";
00146     openFormatData(layout.formatData,layout.formatData,true,(strTag[0]!='h'));
00147 }
00148 
00149 void HtmlDocStructWorker::closeParagraph(const QString& strTag,
00150     const LayoutData& layout)
00151 {
00152     closeFormatData(layout.formatData,layout.formatData,true,(strTag[0]!='h'));
00153     *m_streamOut << "</" << strTag << ">\n";
00154 }
00155 
00156 void HtmlDocStructWorker::openSpan(const FormatData& formatOrigin, const FormatData& format)
00157 {
00158     openFormatData(formatOrigin,format,false,true);
00159 }
00160 
00161 void HtmlDocStructWorker::closeSpan(const FormatData& formatOrigin, const FormatData& format)
00162 {
00163     closeFormatData(formatOrigin,format,false,true);
00164 }
00165 
KDE Home | KDE Accessibility Home | Description of Access Keys