filters

ExportDocStruct.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2001, 2002 Nicolas GOUTTE <goutte@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqstring.h>
22#include <tqtextcodec.h>
23#include <tqfile.h>
24
25#include <tdelocale.h>
26#include <kdebug.h>
27
28#include <KWEFBaseWorker.h>
29
30#include "ExportFilter.h"
31#include "ExportDocStruct.h"
32
33TQString HtmlDocStructWorker::getStartOfListOpeningTag(const CounterData::Style typeList, bool& ordered)
34{
35 TQString strResult;
36 switch (typeList)
37 {
38 case CounterData::STYLE_CUSTOMBULLET:
39 default:
40 case CounterData::STYLE_NONE:
41 case CounterData::STYLE_CIRCLEBULLET:
42 case CounterData::STYLE_SQUAREBULLET:
43 case CounterData::STYLE_DISCBULLET:
44 {
45 ordered=false;
46 strResult="<ul>\n";
47 break;
48 }
49 case CounterData::STYLE_NUM:
50 case CounterData::STYLE_ALPHAB_L:
51 case CounterData::STYLE_ALPHAB_U:
52 case CounterData::STYLE_ROM_NUM_L:
53 case CounterData::STYLE_ROM_NUM_U:
54 case CounterData::STYLE_CUSTOM:
55 {
56 ordered=true;
57 strResult="<ol>\n";
58 break;
59 }
60 }
61 return strResult;
62}
63
64void HtmlDocStructWorker::openFormatData(const FormatData& formatOrigin,
65 const FormatData& format, const bool force, const bool allowBold)
66{
67 // TODO/FIXME: find another way to find fixed fonts
68 // TODO/FIXME: (leaves out "Typewriter", "Monospace", "Mono")
69 if (format.text.fontName.contains("ourier"))
70 {
71 *m_streamOut << "<tt>"; // teletype
72 }
73
74 if (force || (formatOrigin.text.italic!=format.text.italic))
75 {
76 if (format.text.italic)
77 {
78 *m_streamOut << "<i>";
79 }
80 }
81
82 if (force || ((formatOrigin.text.weight>=75)!=(format.text.weight>=75)))
83 {
84 if (allowBold && (format.text.weight >= 75))
85 {
86 *m_streamOut << "<b>";
87 }
88 }
89
90 if (force || (formatOrigin.text.verticalAlignment!=format.text.verticalAlignment))
91 {
92 if (1==format.text.verticalAlignment)
93 {
94 *m_streamOut << "<sub>"; //Subscript
95 }
96 else if (2==format.text.verticalAlignment)
97 {
98 *m_streamOut << "<sup>"; //Superscript
99 }
100 }
101
102 // Strict (X)HTML gives use also <big> and <small> to play with.
103}
104
105void HtmlDocStructWorker::closeFormatData(const FormatData& formatOrigin,
106 const FormatData& format, const bool force, const bool allowBold)
107{
108 if (force || (formatOrigin.text.verticalAlignment!=format.text.verticalAlignment))
109 {
110 if (2==format.text.verticalAlignment)
111 {
112 *m_streamOut << "</sup>"; //Superscript
113 }
114 else if (1==format.text.verticalAlignment)
115 {
116 *m_streamOut << "</sub>"; //Subscript
117 }
118 }
119
120 if (force || ((formatOrigin.text.weight>=75)!=(format.text.weight>=75)))
121 {
122 if (allowBold && (format.text.weight >= 75))
123 {
124 *m_streamOut << "</b>";
125 }
126 }
127
128 if (force || (formatOrigin.text.italic!=format.text.italic))
129 {
130 if (format.text.italic)
131 {
132 *m_streamOut << "</i>";
133 }
134 }
135
136 if (format.text.fontName.contains("ourier")) // Courier?
137 {
138 *m_streamOut << "</tt>"; // teletype
139 }
140}
141
142void HtmlDocStructWorker::openParagraph(const TQString& strTag,
143 const LayoutData& layout,TQChar::Direction /*direction*/)
144{
145 *m_streamOut << '<' << strTag << ">";
146 openFormatData(layout.formatData,layout.formatData,true,(strTag[0]!='h'));
147}
148
149void HtmlDocStructWorker::closeParagraph(const TQString& strTag,
150 const LayoutData& layout)
151{
152 closeFormatData(layout.formatData,layout.formatData,true,(strTag[0]!='h'));
153 *m_streamOut << "</" << strTag << ">\n";
154}
155
156void HtmlDocStructWorker::openSpan(const FormatData& formatOrigin, const FormatData& format)
157{
158 openFormatData(formatOrigin,format,false,true);
159}
160
161void HtmlDocStructWorker::closeSpan(const FormatData& formatOrigin, const FormatData& format)
162{
163 closeFormatData(formatOrigin,format,false,true);
164}
165
Paragraph layout.