22#include "ImportFormatting.h"
23#include "ImportStyle.h"
25StackItem::StackItem() : fontSize(0),
26 pos(0), italic(false), bold(false), underline(false), strikeout(false),
31StackItem::~StackItem()
35void PopulateProperties(StackItem* stackItem,
const TQString& strStyleProps,
36 const TQXmlAttributes& attributes, AbiPropsMap& abiPropsMap,
44 if (stackItem->italic)
46 abiPropsMap.setProperty(
"font-style",
"italic");
50 abiPropsMap.setProperty(
"font-weight",
"bold");
53 if (stackItem->underline)
55 abiPropsMap.setProperty(
"text-decoration",
"underline");
57 else if (stackItem->strikeout)
59 abiPropsMap.setProperty(
"text-decoration",
"line-through");
64 kdDebug(30506)<<
"===== from style=\"" << strStyleProps <<
"\"" << endl;
65 abiPropsMap.splitAndAddAbiProps(strStyleProps);
67 kdDebug(30506)<<
"========== props=\"" << attributes.value(
"props") <<
"\"" << endl;
68 abiPropsMap.splitAndAddAbiProps(attributes.value(
"props"));
69 abiPropsMap.splitAndAddAbiProps(attributes.value(
"PROPS"));
71 stackItem->italic=(abiPropsMap[
"font-style"].getValue()==
"italic");
72 stackItem->bold=(abiPropsMap[
"font-weight"].getValue()==
"bold");
74 TQString strDecoration=abiPropsMap[
"text-decoration"].getValue();
75 stackItem->underline=(strDecoration==
"underline");
76 stackItem->strikeout=(strDecoration==
"line-through");
78 TQString strTextPosition=abiPropsMap[
"text-position"].getValue();
79 if (strTextPosition==
"subscript")
81 stackItem->textPosition=1;
83 else if (strTextPosition==
"superscript")
85 stackItem->textPosition=2;
87 else if (!strTextPosition.isEmpty())
90 stackItem->textPosition=0;
93 TQString strColour=abiPropsMap[
"color"].getValue();
94 if (!strColour.isEmpty())
97 stackItem->fgColor.setNamedColor(
"#"+strColour);
100 TQString strBackgroundTextColor=abiPropsMap[
"bgcolor"].getValue();
101 if (strBackgroundTextColor==
"transparent")
104 stackItem->bgColor.setRgb(255,255,255);
106 else if(!strBackgroundTextColor.isEmpty())
109 stackItem->bgColor.setNamedColor(
"#"+strBackgroundTextColor);
112 TQString strFontSize=abiPropsMap[
"font-size"].getValue();
113 if (!strFontSize.isEmpty())
115 const int size=int(ValueWithLengthUnit(strFontSize));
118 stackItem->fontSize=size;
122 TQString strFontFamily=abiPropsMap[
"font-family"].getValue();
123 if (!strFontFamily.isEmpty() && (strFontFamily!=
"(null)"))
126 stackItem->fontName=strFontFamily;
130void AddFormat(TQDomElement& formatElementOut, StackItem* stackItem, TQDomDocument& mainDocument)
132 TQDomElement element;
133 if (!stackItem->fontName.isEmpty())
135 element=mainDocument.createElement(
"FONT");
136 element.setAttribute(
"name",stackItem->fontName);
137 formatElementOut.appendChild(element);
140 if (stackItem->fontSize>0)
142 element=mainDocument.createElement(
"SIZE");
143 element.setAttribute(
"value",stackItem->fontSize);
144 formatElementOut.appendChild(element);
147 element=mainDocument.createElement(
"ITALIC");
148 element.setAttribute(
"value",stackItem->italic?1:0);
149 formatElementOut.appendChild(element);
151 element=mainDocument.createElement(
"WEIGHT");
152 element.setAttribute(
"value",stackItem->bold?75:50);
153 formatElementOut.appendChild(element);
155 element=mainDocument.createElement(
"UNDERLINE");
156 element.setAttribute(
"value",stackItem->underline?1:0);
157 formatElementOut.appendChild(element);
159 element=mainDocument.createElement(
"STRIKEOUT");
160 element.setAttribute(
"value",stackItem->strikeout?1:0);
161 formatElementOut.appendChild(element);
163 if ((stackItem->textPosition>=0) && (stackItem->textPosition<=2))
165 element=mainDocument.createElement(
"VERTALIGN");
166 element.setAttribute(
"value",stackItem->textPosition);
167 formatElementOut.appendChild(element);
170 if (stackItem->fgColor.isValid())
172 element=mainDocument.createElement(
"COLOR");
173 element.setAttribute(
"red", stackItem->fgColor.red());
174 element.setAttribute(
"green",stackItem->fgColor.green());
175 element.setAttribute(
"blue", stackItem->fgColor.blue());
176 formatElementOut.appendChild(element);
179 if (stackItem->bgColor.isValid())
181 element=mainDocument.createElement(
"TEXTBACKGROUNDCOLOR");
182 element.setAttribute(
"red", stackItem->bgColor.red());
183 element.setAttribute(
"green",stackItem->bgColor.green());
184 element.setAttribute(
"blue", stackItem->bgColor.blue());
185 formatElementOut.appendChild(element);
189void AddLayout(
const TQString& strStyleName, TQDomElement& layoutElement,
190 StackItem* stackItem, TQDomDocument& mainDocument,
191 const AbiPropsMap& abiPropsMap,
const int level,
const bool isStyle)
193 TQDomElement element;
194 element=mainDocument.createElement(
"NAME");
195 element.setAttribute(
"value",strStyleName);
196 layoutElement.appendChild(element);
198 TQString strFollowing=abiPropsMap[
"followedby"].getValue();
199 TQDomElement followingElement=mainDocument.createElement(
"FOLLOWING");
200 followingElement.setAttribute(
"name",strFollowing);
201 if ((strFollowing.isEmpty())
202 || (strFollowing==
"Current Settings"))
208 followingElement.setAttribute(
"name",
"Normal");
209 layoutElement.appendChild(followingElement);
217 layoutElement.appendChild(followingElement);
220 TQString strFlow=abiPropsMap[
"text-align"].getValue();
221 element=mainDocument.createElement(
"FLOW");
222 if ((strFlow==
"left") || (strFlow==
"center") || (strFlow==
"right") || (strFlow==
"justify"))
224 element.setAttribute(
"align",strFlow);
228 element.setAttribute(
"align",
"left");
230 layoutElement.appendChild(element);
233 int kwordNumberingType;
235 TQString kwordRightText;
237 if ((level<=0) || (level>=15))
240 kwordNumberingType=2;
246 kwordNumberingType=1;
251 element=mainDocument.createElement(
"COUNTER");
252 element.setAttribute(
"type",kwordType);
253 element.setAttribute(
"depth",kwordDepth);
254 element.setAttribute(
"start",1);
255 element.setAttribute(
"numberingtype",kwordNumberingType);
256 element.setAttribute(
"lefttext",
"");
257 element.setAttribute(
"righttext",kwordRightText);
258 element.setAttribute(
"bullet",64);
259 element.setAttribute(
"bulletfont",
"Symbol");
260 element.setAttribute(
"customdef",
"");
261 layoutElement.appendChild(element);
263 TQString strLeftMargin=abiPropsMap[
"margin-left"].getValue();
264 TQString strRightMargin=abiPropsMap[
"margin-right"].getValue();
265 TQString strTextIndent=abiPropsMap[
"text-indent"].getValue();
267 if ( !strLeftMargin.isEmpty()
268 || !strRightMargin.isEmpty()
269 || !strTextIndent.isEmpty() )
271 element=mainDocument.createElement(
"INDENTS");
272 if (!strLeftMargin.isEmpty())
273 element.setAttribute(
"left",ValueWithLengthUnit(strLeftMargin));
274 if (!strRightMargin.isEmpty())
275 element.setAttribute(
"right",ValueWithLengthUnit(strRightMargin));
276 if (!strTextIndent.isEmpty())
277 element.setAttribute(
"first",ValueWithLengthUnit(strTextIndent));
278 layoutElement.appendChild(element);
281 TQString strTopMargin=abiPropsMap[
"margin-top"].getValue();
282 TQString strBottomMargin=abiPropsMap[
"margin-bottom"].getValue();
283 if (!strTopMargin.isEmpty() || !strBottomMargin.isEmpty() )
285 element=mainDocument.createElement(
"OFFSETS");
286 const double margin_top=ValueWithLengthUnit(strTopMargin);
287 const double margin_bottom=ValueWithLengthUnit(strBottomMargin);
289 if (!strBottomMargin.isEmpty())
290 element.setAttribute(
"after",margin_bottom);
291 if (!strTopMargin.isEmpty())
292 element.setAttribute(
"before",margin_top);
293 layoutElement.appendChild(element);
296 TQString strLineHeight=abiPropsMap[
"line-height"].getValue();
297 if(!strLineHeight.isEmpty())
299 element=mainDocument.createElement(
"LINESPACING");
303 lineHeight=strLineHeight.toDouble(&flag);
307 if ( lineHeight == 1.0 )
309 element.setAttribute(
"value",
"single" );
310 element.setAttribute(
"type",
"single" );
312 else if (lineHeight==1.5)
314 element.setAttribute(
"value",
"oneandhalf" );
315 element.setAttribute(
"type",
"oneandhalf" );
317 else if (lineHeight==2.0)
319 element.setAttribute(
"value",
"double" );
320 element.setAttribute(
"type",
"double" );
322 else if ( lineHeight > 0.0 )
324 element.setAttribute(
"type",
"multiple" );
325 element.setAttribute(
"spacingvalue", lineHeight );
329 kdWarning(30506) <<
"Unsupported line height " << lineHeight <<
" (Ignoring !)" << endl;
335 bool atleast =
false;
336 lineHeight = ValueWithLengthUnit( strLineHeight, &atleast );
341 kdDebug(30506) <<
"at-least" << endl;
342 element.setAttribute(
"type",
"atleast" );
346 element.setAttribute(
"type",
"exact" );
351 element.setAttribute(
"spacingvalue", lineHeight );
354 layoutElement.appendChild(element);
357 TQString strTab=abiPropsMap[
"tabstops"].getValue();
358 if(!strTab.isEmpty())
360 TQStringList listTab=TQStringList::split(
",",strTab);
361 for ( TQStringList::Iterator it = listTab.begin(); it != listTab.end(); ++it )
363 TQStringList tab=TQStringList::split(
"/",*it);
364 const TQChar tabType=tab[1].at(0);
365 const TQChar tabFilling=tab[1].at(1);
369 else if (tabType==
'C')
371 else if (tabType==
'R')
373 else if(tabType==
'D')
375 else if(tabType==
'B')
379 kdWarning(30506)<<
"Unknown tabulator type: " << TQString(tabType) << endl;
384 if (tabFilling.isNull() || tabFilling==
'0')
386 else if (tabFilling==
'1')
391 else if (tabFilling==
'3')
395 element=mainDocument.createElement(
"TABULATOR");
396 element.setAttribute(
"ptpos",ValueWithLengthUnit(tab[0]));
397 element.setAttribute(
"type",type);
398 element.setAttribute(
"filling",filling);
399 element.setAttribute(
"width",width);
400 layoutElement.appendChild(element);
404 TQDomElement formatElementOut=mainDocument.createElement(
"FORMAT");
405 layoutElement.appendChild(formatElementOut);
407 AddFormat(formatElementOut, stackItem, mainDocument);
410void AddStyle(TQDomElement& styleElement,
const TQString& strStyleName,
411 const StyleData& styleData, TQDomDocument& mainDocument)
416 TQXmlAttributes attributes;
417 AbiPropsMap abiPropsMap;
419 PopulateProperties(&stackItem, styleData.m_props, attributes, abiPropsMap,
false);
420 AddLayout(strStyleName, styleElement, &stackItem, mainDocument, abiPropsMap, styleData.m_level,
true);