22#include <tqtextcodec.h>
29#include <KWEFBaseWorker.h>
31#include "ExportFilter.h"
34TQString HtmlCssWorker::escapeCssIdentifier(
const TQString& strText)
const
44 const TQChar qch0(strText[0]);
45 if (((
int)qch0<
'a' || (
int)qch0>
'z') && ((
int)qch0<
'A' || (
int)qch0>
'Z'))
52 for (uint i=0; i<strText.length(); i++)
54 const TQChar qch(strText.at(i));
55 const ushort ch=qch.unicode();
57 if (((ch>=
'a') && (ch<=
'z'))
58 || ((ch>=
'A') && (ch<=
'Z'))
59 || ((ch>=
'0') && (ch<=
'9'))
60 || (ch==
'-') || (ch==
'_'))
65 else if ((ch<=
' ') || (ch>=128 && ch<=160))
70 else if ((ch>=161) && (getCodec()->canEncode(qch)))
82 strReturn+=TQString::number(ch,16);
89TQString HtmlCssWorker::textFormatToCss(
const TextFormatting& formatOrigin,
99 TQString fontName = formatData.fontName;
100 if (!fontName.isEmpty()
101 && (force || (formatOrigin.fontName!=formatData.fontName)))
103 strElement+=
"font-family: ";
104 if (fontName.find(
' ')==-1)
105 strElement+=escapeHtmlText(fontName);
109 strElement+=escapeHtmlText(fontName);
116 if (force || (formatOrigin.italic!=formatData.italic))
119 strElement+=
"font-style: ";
120 if ( formatData.italic )
122 strElement+=
"italic";
126 strElement+=
"normal";
131 if (force || ((formatOrigin.weight>=75)!=(formatData.weight>=75)))
133 strElement+=
"font-weight: ";
134 if ( formatData.weight >= 75 )
140 strElement+=
"normal";
145 if (force || (formatOrigin.fontSize!=formatData.fontSize))
147 const int size=formatData.fontSize;
151 strElement+=
"font-size: ";
152 strElement+=TQString::number(size,10);
157 if (force || (formatOrigin.fgColor!=formatData.fgColor))
159 if ( formatData.fgColor.isValid() )
162 strElement+=
"color: ";
163 strElement+=formatData.fgColor.name();
168 if (force || (formatOrigin.bgColor!=formatData.bgColor))
170 if ( formatData.bgColor.isValid() )
173 strElement+=
"background-color: ";
174 strElement+=formatData.bgColor.name();
182 strElement+=
"text-decoration: ";
185 strElement+=
"underline";
189 strElement+=
"line-through";
198 if (force || (formatOrigin.fontAttribute!=formatData.fontAttribute))
200 bool smallcaps=
false;
201 strElement+=
"text-transform: ";
202 if ( formatData.fontAttribute==
"uppercase" )
204 strElement+=
"uppercase";
206 else if ( formatData.fontAttribute==
"lowercase" )
208 strElement+=
"lowercase";
210 else if ( formatData.fontAttribute==
"smallcaps" )
221 strElement+=
"font-variant:";
223 strElement+=
"small-caps";
225 strElement+=
"normal";
234TQString HtmlCssWorker::getStartOfListOpeningTag(
const CounterData::Style typeList,
bool& ordered)
239 case CounterData::STYLE_CUSTOMBULLET:
246 case CounterData::STYLE_NONE:
249 strResult=
"<ul style=\"list-style-type:none\">\n";
252 case CounterData::STYLE_CIRCLEBULLET:
255 strResult=
"<ul style=\"list-style-type:circle\">\n";
258 case CounterData::STYLE_SQUAREBULLET:
261 strResult=
"<ul style=\"list-style-type:square\">\n";
264 case CounterData::STYLE_DISCBULLET:
267 strResult=
"<ul style=\"list-style-type:disc\">\n";
270 case CounterData::STYLE_NUM:
273 strResult=
"<ol style=\"list-style-type:decimal\">\n";
276 case CounterData::STYLE_ALPHAB_L:
279 strResult=
"<ol style=\"list-style-type:lower-alpha\">\n";
282 case CounterData::STYLE_ALPHAB_U:
285 strResult=
"<ol style=\"list-style-type:upper-alpha\">\n";
288 case CounterData::STYLE_ROM_NUM_L:
291 strResult=
"<ol style=\"list-style-type:lower-roman\">\n";
294 case CounterData::STYLE_ROM_NUM_U:
297 strResult=
"<ol style=\"list-style-type:upper-roman\">\n";
300 case CounterData::STYLE_CUSTOM:
311TQString HtmlCssWorker::layoutToCss(
const LayoutData& layoutOrigin,
312 const LayoutData& layout,
const bool force)
const
321 strLayout += TQString(
"text-align:%1; ").arg(layout.
alignment);
329 kdWarning(30503) <<
"Unknown alignment: " << layout.
alignment << endl;
336 strLayout += TQString(
"margin-left:%1pt; ").arg(layout.
indentLeft);
342 strLayout += TQString(
"margin-right:%1pt; ").arg(layout.
indentRight);
347 strLayout += TQString(
"text-indent:%1pt; ").arg(layout.
indentFirst);
353 strLayout += TQString(
"margin-bottom:%1pt; ").arg(layout.
marginBottom);
359 strLayout += TQString(
"margin-top:%1pt; ").arg(layout.
marginTop);
368 case LayoutData::LS_CUSTOM:
373 const TQString height ( TQString::number(layout.
lineSpacing) );
374 strLayout +=
"style:line-spacing:";
380 case LayoutData::LS_SINGLE:
382 strLayout +=
"line-height:normal; ";
385 case LayoutData::LS_ONEANDHALF:
387 strLayout +=
"line-height:150%; ";
390 case LayoutData::LS_DOUBLE:
392 strLayout +=
"line-height:200%; ";
395 case LayoutData::LS_MULTIPLE:
397 const TQString mult ( TQString::number( tqRound( layout.
lineSpacing * 100 ) ) );
398 strLayout +=
"line-height:";
403 case LayoutData::LS_FIXED:
406 const TQString height ( TQString::number(layout.
lineSpacing) );
407 strLayout +=
"line-height:";
412 case LayoutData::LS_ATLEAST:
417 const TQString height ( TQString::number(layout.
lineSpacing) );
418 strLayout +=
"line-height:";
425 kdWarning(30503) <<
"Unsupported lineSpacingType: " << layout.
lineSpacingType <<
" (Ignoring!)" << endl;
440 strLayout +=
"text-shadow:";
445 double xDistance,yDistance;
451 xDistance= (-distance);
452 yDistance= (-distance);
458 yDistance= (-distance);
463 xDistance= (distance);
464 yDistance= (-distance);
469 xDistance= (distance);
475 xDistance= (distance);
476 yDistance= (distance);
482 yDistance= (distance);
487 xDistance= (-distance);
488 yDistance= (distance);
493 xDistance= (distance);
504 if ( (!xDistance) && (!yDistance) )
506 strLayout +=
"text-shadow:";
511 strLayout +=
"text-shadow:";
512 strLayout+=TQString(
"%1 %2pt %3pt; ").arg(layout.
shadowColor.name())
513 .arg(xDistance,0,
'f',0).arg(yDistance,0,
'f',0);
521 strLayout+=textFormatToCss(layoutOrigin.formatData.text,
522 layout.formatData.text,force);
527void HtmlCssWorker::openParagraph(
const TQString& strTag,
528 const LayoutData& layout, TQChar::Direction direction)
530 const LayoutData& styleLayout=m_styleMap[layout.styleName];
532 *m_streamOut <<
'<' << strTag;
535 *m_streamOut <<
" class=\"" << escapeCssIdentifier(layout.styleName);
536 *m_streamOut <<
"\"";
538 TQString strStyle=layoutToCss(styleLayout,layout,
false);
539 if (!strStyle.isEmpty())
541 *m_streamOut <<
" style=\"" << strStyle;
542 if (direction == TQChar::DirRLE) {
543 *m_streamOut <<
"direction: rtl; unicode-bidi: embed; ";
544 }
else if (direction == TQChar::DirRLO) {
545 *m_streamOut <<
"direction: rtl; unicode-bidi: override; ";
552 if ( 1==layout.formatData.text.verticalAlignment )
554 *m_streamOut <<
"<sub>";
556 else if ( 2==layout.formatData.text.verticalAlignment )
558 *m_streamOut <<
"<sup>";
560 if ( layout.
alignment ==
"center" ) *m_streamOut <<
"<center>";
563void HtmlCssWorker::closeParagraph(
const TQString& strTag,
566 if ( 2==layout.formatData.text.verticalAlignment )
568 *m_streamOut <<
"</sup>";
570 else if ( 1==layout.formatData.text.verticalAlignment )
572 *m_streamOut <<
"</sub>";
575 if ( layout.
alignment ==
"center" ) *m_streamOut <<
"</center>";
576 *m_streamOut <<
"</" << strTag <<
">\n";
579void HtmlCssWorker::openSpan(
const FormatData& formatOrigin,
const FormatData& format)
581 *m_streamOut <<
"<span style=\"";
582 *m_streamOut << textFormatToCss(formatOrigin.text,format.text,
false);
583 *m_streamOut <<
"\">";
585 if ( 1==format.text.verticalAlignment )
587 *m_streamOut <<
"<sub>";
589 else if ( 2==format.text.verticalAlignment )
591 *m_streamOut <<
"<sup>";
595void HtmlCssWorker::closeSpan(
const FormatData& formatOrigin,
const FormatData& format)
597 if ( 2==format.text.verticalAlignment )
599 *m_streamOut <<
"</sup>";
601 else if ( 1==format.text.verticalAlignment )
603 *m_streamOut <<
"</sub>";
606 *m_streamOut <<
"</span>";
609bool HtmlCssWorker::doFullPaperFormat(
const int format,
610 const double width,
const double height,
const int orientation)
612 TQString strWidth, strHeight, strUnits;
613 KWEFUtil::GetNativePaperFormat(format, strWidth, strHeight, strUnits);
615 if ((strWidth.isEmpty())||(strHeight.isEmpty())||(strUnits.isEmpty()))
619 strWidth=TQString::number(width);
620 strHeight=TQString::number(height);
625 TQString strTemp(strWidth);
630 m_strPageSize=
"size: ";
631 m_strPageSize+=strWidth;
632 m_strPageSize+=strUnits;
634 m_strPageSize+=strHeight;
635 m_strPageSize+=strUnits;
640bool HtmlCssWorker::doFullPaperBorders (
const double top,
const double left,
641 const double bottom,
const double right)
643 m_strPaperBorders=
" margin-top: ";
644 m_strPaperBorders+=TQString::number(top);
645 m_strPaperBorders+=
"pt;\n";
646 m_strPaperBorders+=
" margin-left: ";
647 m_strPaperBorders+=TQString::number(left);
648 m_strPaperBorders+=
"pt;\n";
649 m_strPaperBorders+=
" margin-bottom: ";
650 m_strPaperBorders+=TQString::number(bottom);
651 m_strPaperBorders+=
"pt;\n";
652 m_strPaperBorders+=
" margin-right: ";
653 m_strPaperBorders+=TQString::number(right);
654 m_strPaperBorders+=
"pt;\n";
659bool HtmlCssWorker::doOpenStyles(
void)
661 *m_streamOut <<
"<style type=\"text/css\">\n";
666 *m_streamOut <<
"<!--\n";
670 const TQString strVersion(
"$Revision: 483471 $");
673 *m_streamOut <<
"/* KWORD_CSS_EXPORT ="
674 << strVersion.mid(10).remove(
'$')
678 *m_streamOut <<
"BODY\n{\n background-color: #FFFFFF\n}\n";
683bool HtmlCssWorker::doFullDefineStyle(
LayoutData& layout)
686 m_styleMap[layout.styleName]=layout;
691 *m_streamOut <<
"." << escapeCssIdentifier(layout.styleName);
692 *m_streamOut <<
"\n{\n " << layoutToCss(layout,layout,
true) <<
"\n}\n";
697bool HtmlCssWorker::doCloseStyles(
void)
699 if (!m_strPageSize.isEmpty())
701 *m_streamOut <<
"@page\n{\n ";
702 *m_streamOut << m_strPageSize;
703 *m_streamOut <<
"\n";
704 *m_streamOut << m_strPaperBorders;
705 *m_streamOut <<
"}\n";
712 *m_streamOut <<
"-->\n";
714 *m_streamOut <<
"</style>\n";
double lineSpacing
Space between lines in pt, if lineSpacingType==0.
int shadowDirection
direction of <SHADOW>
TQColor shadowColor
red, green, blue of <SHADOW>
double indentFirst
indentation correction of first line (can be negative!)
double indentRight
right indentation (a negative value means invalid)
double shadowDistance
distance of <SHADOW>
double indentLeft
left indentation (a negative value means invalid)
TQString alignment
left, right, center, justify
int lineSpacingType
0=custom, 10=one line, 15=one and half lines, 20= 2 lines
double marginTop
space before the paragraph (a negative value means invalid)
double marginBottom
space after the paragraph (a negative value means invalid)
TextFormatting is a container for data retrieved from the <FORMAT> tag and its subtags to be used in ...
bool underline
Any underline? (If true, we do not know if simple or double or what else)
bool strikeout
true if strikeout