1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /* AbiWord
4  * Copyright (C) 2001 AbiSource, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA��
19  * 02110-1301 USA.
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "ut_types.h"
26 #include "ut_assert.h"
27 #include "ut_debugmsg.h"
28 #include "ut_string.h"
29 #include "ie_imp_KWord_1.h"
30 #include "ie_types.h"
31 #include "pd_Document.h"
32 #include "ut_growbuf.h"
33 #include "ut_units.h"
34 #include "ut_string_class.h"
35 #include "ie_impexp_KWord_1.h"
36 
37 /*
38  * This file is meant to import KWord 1.x documents.
39  * Kword is a component of KOffice for KDE.
40  */
41 
42 /*****************************************************************/
43 /*****************************************************************/
44 
45 #define X_CheckError(v)			do {  if (!(v))								\
46 									  {  m_error = UT_ERROR;			\
47 										 return; } } while (0)
48 
49 #define	X_EatIfAlreadyError()	do {  if (m_error) return; } while (0)
50 
51 /***********************************************************/
52 /***********************************************************/
53 
IE_Imp_KWord_1_Sniffer(const char * _name)54 IE_Imp_KWord_1_Sniffer::IE_Imp_KWord_1_Sniffer (const char * _name) :
55   IE_ImpSniffer(_name)
56 {
57   //
58 }
59 
60 // supported suffixes
61 static IE_SuffixConfidence IE_Imp_KWord_1_Sniffer__SuffixConfidence[] = {
62 	{ "kwd", 	UT_CONFIDENCE_PERFECT 	},
63 	{ "", 	UT_CONFIDENCE_ZILCH 	}
64 };
65 
getSuffixConfidence()66 const IE_SuffixConfidence * IE_Imp_KWord_1_Sniffer::getSuffixConfidence ()
67 {
68 	return IE_Imp_KWord_1_Sniffer__SuffixConfidence;
69 }
70 
71 // supported mimetypes
72 static IE_MimeConfidence IE_Imp_KWord_1_Sniffer__MimeConfidence[] = {
73 	{ IE_MIME_MATCH_FULL, 	IE_MIMETYPE_KWord, 		UT_CONFIDENCE_GOOD 	},
74 	{ IE_MIME_MATCH_FULL, 	"application/x-kword", 	UT_CONFIDENCE_GOOD 	},
75 	{ IE_MIME_MATCH_BOGUS, 	"", 					UT_CONFIDENCE_ZILCH }
76 };
77 
getMimeConfidence()78 const IE_MimeConfidence * IE_Imp_KWord_1_Sniffer::getMimeConfidence ()
79 {
80 	return IE_Imp_KWord_1_Sniffer__MimeConfidence;
81 }
82 
recognizeContents(const char * szBuf,UT_uint32)83 UT_Confidence_t IE_Imp_KWord_1_Sniffer::recognizeContents(const char *szBuf, UT_uint32 /*iNumbytes*/)
84 {
85 
86   // first, look for the <?xml at the beginning of the document
87   if(strncmp(szBuf, "<?xml", 4) != 0)
88     return UT_CONFIDENCE_ZILCH;
89 
90   // now look for the KWord beginning tag <DOC
91   if(strstr(szBuf, "<DOC") == NULL)
92     return UT_CONFIDENCE_ZILCH;
93 
94   return UT_CONFIDENCE_PERFECT;
95 }
96 
constructImporter(PD_Document * pDocument,IE_Imp ** ppie)97 UT_Error IE_Imp_KWord_1_Sniffer::constructImporter(PD_Document *pDocument, IE_Imp **ppie)
98 {
99   IE_Imp_KWord_1 *p = new IE_Imp_KWord_1(pDocument);
100   *ppie = p;
101   return UT_OK;
102 }
103 
getDlgLabels(const char ** pszDesc,const char ** pszSuffixList,IEFileType * ft)104 bool IE_Imp_KWord_1_Sniffer::getDlgLabels(const char **pszDesc, const char **pszSuffixList,
105                                           IEFileType *ft)
106 {
107   *pszDesc = "KWord 1.x (.kwd)";
108   *pszSuffixList = "*.kwd";
109   *ft = getFileType();
110   return true;
111 }
112 
113 /*****************************************************************/
114 /*****************************************************************/
115 
~IE_Imp_KWord_1()116 IE_Imp_KWord_1::~IE_Imp_KWord_1()
117 {
118 }
119 
IE_Imp_KWord_1(PD_Document * pDocument)120 IE_Imp_KWord_1::IE_Imp_KWord_1(PD_Document *pDocument) : IE_Imp_XML(pDocument, true)
121   , m_bInText(false)
122 {
123 }
124 
charData(const gchar * s,int len)125 void IE_Imp_KWord_1::charData(const gchar *s, int len)
126 {
127   X_EatIfAlreadyError();	// xml parser keeps running until buffer consumed
128 
129   UT_ASSERT(sizeof(gchar) == sizeof(UT_Byte));
130   UT_ASSERT(sizeof(gchar) != sizeof(UT_UCSChar));
131 
132   if(!m_bInText)
133     return;
134 
135   // parse UTF-8 text and convert to Unicode.
136 
137   const UT_Byte * ss = reinterpret_cast<const UT_Byte *>(s);
138   UT_UCS4String buf;
139   UT_Byte currentChar;
140 
141   for (int k=0; k<len; k++)
142     {
143       currentChar = ss[k];
144 
145       if ((ss[k] < 0x80) && (m_lenCharDataSeen > 0))
146 	{
147 	  // is it us-ascii and we are in a UTF-8
148 	  // multi-byte sequence.  puke.
149 	  X_CheckError(0);
150 	}
151 
152       if (currentChar < 0x80)			// plain us-ascii part of latin-1
153 	{
154 	  buf += ss[k];		// copy as is.
155 	}
156       else if ((currentChar & 0xf0) == 0xf0)	// lead byte in 4-byte surrogate pair
157 	{
158 	  // surrogate pairs are defined in section 3.7 of the
159 	  // unicode standard version 2.0 as an extension
160 	  // mechanism for rare characters in future extensions
161 	  // of the unicode standard.
162 	  UT_ASSERT(m_lenCharDataSeen == 0);
163 	  UT_ASSERT(UT_NOT_IMPLEMENTED);
164 	}
165       else if ((currentChar & 0xe0) == 0xe0)  // lead byte in 3-byte sequence
166 	{
167 	  UT_ASSERT(m_lenCharDataSeen == 0);
168 	  m_lenCharDataExpected = 3;
169 	  m_charDataSeen[m_lenCharDataSeen++] = currentChar;
170 	}
171       else if ((currentChar & 0xc0) == 0xc0)	// lead byte in 2-byte sequence
172 	{
173 	  UT_ASSERT(m_lenCharDataSeen == 0);
174 	  m_lenCharDataExpected = 2;
175 	  m_charDataSeen[m_lenCharDataSeen++] = currentChar;
176 	}
177       else if ((currentChar & 0x80) == 0x80)		// trailing byte in multi-byte sequence
178 	{
179 	  UT_ASSERT(m_lenCharDataSeen > 0);
180 	  m_charDataSeen[m_lenCharDataSeen++] = currentChar;
181 	  if (m_lenCharDataSeen == m_lenCharDataExpected)
182 	    {
183 	      buf += g_utf8_get_char(m_charDataSeen);
184 	      m_lenCharDataSeen = 0;
185 	    }
186 	}
187     }
188 
189   m_szTextBuffer += buf;
190 }
191 
192 /*****************************************************************/
193 /*****************************************************************/
194 
195 #define TT_OTHER           0                    // anything else
196 #define TT_ATTRIBUTE       1                    // attributes of document
197 #define TT_BOTTOMBORDER    2                    // bottom border
198 #define TT_CHARSET         3                    // chatset
199 #define TT_CLIPARTS        4                    // cliparts
200 #define TT_COLOR           5                    // color stuff
201 #define TT_COUNTER         6                    // ??
202 #define TT_DOC             7                    // a document <kwd>
203 #define TT_FLOW            8                    // allignment
204 #define TT_FOLLOWING       9                    // ??
205 #define TT_FONT            10                   // a font
206 #define TT_FORMAT          11                   // ??
207 #define TT_FORMATS         12                   // ??
208 #define TT_FRAME           13                   // a frame
209 #define TT_FRAMESET        14                   // a frameset
210 #define TT_INDENTS         15                   // indent
211 #define TT_ITALIC          16                   // italic font
212 #define TT_LAYOUT          17                   // layout
213 #define TT_LEFTBORDER      18                   // left border
214 #define TT_LINESPACING     19                   // line spacing
215 #define TT_NAME            20                   // ??
216 #define TT_OFFSETS         21                   // offsets
217 #define TT_PAPER           22                   // ??
218 #define TT_PAPERBORDERS    23                   // ??
219 #define TT_PAGEBREAKING    24                   // page breaking
220 #define TT_PARAGRAPH       25                   // paragraphs
221 #define TT_RIGHTBORDER     26                   // right border
222 #define TT_SIZE            27                   // size of a font
223 #define TT_STRIKEOUT       28                   // strikeout font
224 #define TT_STYLE           29                   // style
225 #define TT_STYLES          30                   // styles
226 #define TT_TEXT            31                   // written text
227 #define TT_TOPBORDER       32                   // top border
228 #define TT_UNDERLINE       33                   // underline font
229 #define TT_VERTALIGN       34                   // vertical alignment
230 #define TT_WEIGHT          35                   // font weight
231 
232 // KEEP IN ALPHABETICAL ORDER!!
233 
234 static struct xmlToIdMapping s_Tokens[] =
235 {
236   { "ATTRIBUTE",     TT_ATTRIBUTE    },
237   { "BOTTOMBORDER",  TT_BOTTOMBORDER },
238   { "CHARSET",       TT_CHARSET      },
239   { "CLIPARTS",      TT_CLIPARTS     },
240   { "COLOR",      TT_COLOR     },
241   { "COUNTER",       TT_COUNTER      },
242   { "DOC",           TT_DOC          },
243   { "FLOW",          TT_FLOW         },
244   { "FOLLOWING",     TT_FOLLOWING    },
245   { "FONT",          TT_FONT         },
246   { "FORMAT",        TT_FORMAT       },
247   { "FORMATS",       TT_FORMATS      },
248   { "FRAME",         TT_FRAME        },
249   { "FRAMESET",      TT_FRAMESET     },
250   { "INDENTS",       TT_INDENTS      },
251   { "ITALIC",        TT_ITALIC       },
252   { "LAYOUT",        TT_LAYOUT       },
253   { "LEFTBORDER",    TT_LEFTBORDER   },
254   { "LINESPACING",   TT_LINESPACING  },
255   { "NAME",          TT_NAME         },
256   { "OFFSETS",       TT_OFFSETS      },
257   { "PAPER",         TT_PAPER        },
258   { "PAPERBORDERS",  TT_PAPERBORDERS },
259   { "PAGEBREAKING",  TT_PAGEBREAKING },
260   { "PARAGRAPH",     TT_PARAGRAPH    },
261   { "RIGHTBORDER",   TT_RIGHTBORDER  },
262   { "SIZE",          TT_SIZE         },
263   { "STRIKEOUT",     TT_STRIKEOUT    },
264   { "STYLE",         TT_STYLE        },
265   { "STYLES",        TT_STYLES       },
266   { "TEXT",          TT_TEXT         },
267   { "TOPBORDER",     TT_TOPBORDER    },
268   { "UNDERLINE",     TT_UNDERLINE    },
269   { "VERTALIGN",     TT_VERTALIGN    },
270   { "WEIGHT",        TT_WEIGHT       }
271 };
272 
273 #define TokenTableSize ((sizeof(s_Tokens)/sizeof(s_Tokens[0])))
274 
275 /*****************************************************************/
276 /*****************************************************************/
277 
278 #define X_TestParseState(ps) ((m_parseState==(ps)))
279 
280 #define X_VerifyParseState(ps) do { if (!(X_TestParseState(ps))) { m_error = UT_IE_BOGUSDOCUMENT; return; } } while(0)
281 
282 #define X_CheckDocument(b) do {  if (!(b)) { m_error = UT_IE_BOGUSDOCUMENT; return; } } while (0)
283 
284 #define X_CheckError(v) do {  if (!(v)) {  m_error = UT_ERROR; return; } } while (0)
285 
286 #define X_EatIfAlreadyError() do {  if (m_error) return; } while (0)
287 
288 /*****************************************************************/
289 /*****************************************************************/
290 
291 // turns a KWord justification number into left/right/center/justify
292 static const char *
numberToJustification(const char * justification_name)293 numberToJustification(const char * justification_name)
294 {
295 	if (! strcmp(justification_name,"0"))
296 		return "left";
297 	else if (! strcmp(justification_name,"1"))
298 		return "right";
299 	else if (! strcmp(justification_name,"2"))
300 		return "center";
301 	else if (! strcmp(justification_name,"3"))
302 		return "justify";
303 	else
304 	{
305 		UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
306 		return "";
307 	}
308 }
309 
310 // turns as KWord page-size number into a fp_PageSize::Predefined
311 static fp_PageSize::Predefined
kPageToFpPageSize(const char * sz)312 kPageToFpPageSize (const char * sz)
313 {
314   // TODO: handle more of these
315 
316   if(!strcmp(sz, "0"))
317     return fp_PageSize::psA3;
318   else if(!strcmp(sz, "1"))
319     return fp_PageSize::psA4;
320   else if(!strcmp(sz, "2"))
321     return fp_PageSize::psA5;
322   else if(!strcmp(sz, "3"))
323     return fp_PageSize::psLetter;
324   else if(!strcmp(sz, "4"))
325     return fp_PageSize::psLegal;
326   else if(!strcmp(sz, "7"))
327     return fp_PageSize::psB5;
328   else
329     return fp_PageSize::psCustom;
330 }
331 
332 #if 0
333 // superscript/subscript/normal
334 static const char *
335 kVertAlignToTextPos ( const char * sz )
336 {
337   if (!strcmp(sz, "1"))
338     return "superscript";
339   else if(!strcmp(sz, "2"))
340     return "subscript";
341   else
342     return "normal";
343 }
344 #endif
345 
346 /*****************************************************************/
347 /*****************************************************************/
348 
startElement(const gchar * name,const gchar ** atts)349 void IE_Imp_KWord_1::startElement(const gchar *name, const gchar **atts)
350 {
351   // xml parser keeps running until buffer consumed
352   X_EatIfAlreadyError();
353 
354   UT_uint32 tokenIndex = _mapNameToToken(name, s_Tokens, TokenTableSize);
355 
356   const gchar *pVal = 0;
357 
358   switch (tokenIndex)
359   {
360     case TT_ATTRIBUTE:
361       {
362         xxx_UT_DEBUGMSG(("ABIDEBUG: begin ATTRIBUTE\n"));
363         break;
364       }
365 
366     case TT_BOTTOMBORDER:
367       {
368         xxx_UT_DEBUGMSG(("ABIDEBUG: begin BOTTOMBORDER\n"));
369         break;
370       }
371 
372     case TT_CHARSET:
373       {
374         xxx_UT_DEBUGMSG(("ABIDEBUG: begin CHARSET\n"));
375         break;
376       }
377 
378     case TT_CLIPARTS:
379       {
380         xxx_UT_DEBUGMSG(("ABIDEBUG: begin CLIPARTS\n"));
381         break;
382       }
383 
384     case TT_COLOR:
385       {
386 
387         const gchar *p = NULL;
388 	int red, green, blue;
389 	red = green = blue = 0;
390 	p = _getXMLPropValue("red", atts);
391 	if (p != NULL) {
392 	  red = atoi(p);
393 	  if (red < 0)
394 	    red = 0;
395 	  else if (red > 255)
396 	    red = 255;
397 	}
398 	if (p != NULL) {
399 	  p = _getXMLPropValue("green", atts);
400 	  green = atoi(p);
401 	  if (green < 0)
402 	    green = 0;
403 	  else if (green > 255)
404 	    green = 255;
405 	}
406 	if (p != NULL) {
407 	  p = _getXMLPropValue("blue", atts);
408 	  blue = atoi(p);
409 	  if (blue < 0)
410 	    blue = 0;
411 	  else if (blue > 255)
412 	    blue = 255;
413 	}
414 
415 	m_szCharProps += "color:";
416 	m_szCharProps += UT_String_sprintf("%02x%02x%02x", red, green, blue);
417 	m_szCharProps += "; ";
418 	break;
419 
420       }
421 
422     case TT_COUNTER:
423       {
424         xxx_UT_DEBUGMSG(("ABIDEBUG: begin COUNTER\n"));
425         break;
426       }
427 
428     case TT_DOC:
429       {
430         //  X_VerifyParseState(_PS_Init);
431         m_parseState = _PS_Doc;
432         return;
433       }
434 
435     case TT_FOLLOWING:
436       {
437         xxx_UT_DEBUGMSG(("ABIDEBUG: begin FOLLOWING\n"));
438         break;
439       }
440 
441     case TT_FRAME:
442       {
443         xxx_UT_DEBUGMSG(("ABIDEBUG: begin FRAME\n"));
444 
445 	if(m_szSectProps.size() >= 2)
446 		m_szSectProps[m_szSectProps.size() - 2] = 0; // knock off the final ';'
447 
448 	const gchar *propsArray[3];
449 	propsArray[0] = static_cast<const gchar *>("props");
450 	propsArray[1] = static_cast<const gchar *>(m_szSectProps.c_str());
451 	propsArray[2] = 0;
452 
453 	X_CheckError(appendStrux(PTX_Section,static_cast<const gchar**>(&propsArray[0])));
454 	m_szSectProps.clear(); //reset cached properties
455 
456 	UT_DEBUGMSG(("DOM: CREATED SECTION\n"));
457 
458         break;
459       }
460 
461     case TT_FRAMESET:
462       {
463         xxx_UT_DEBUGMSG(("ABIDEBUG: begin FRAMESET\n"));
464         break;
465       }
466 
467     case TT_INDENTS:
468       {
469         xxx_UT_DEBUGMSG(("ABIDEBUG: begin INDENTS\n"));
470         break;
471       }
472 
473     case TT_LAYOUT:
474       {
475         xxx_UT_DEBUGMSG(("ABIDEBUG: begin LAYOUT\n"));
476         break;
477       }
478 
479     case TT_LEFTBORDER:
480       {
481         xxx_UT_DEBUGMSG(("ABIDEBUG: begin LEFTBORDER\n"));
482         break;
483       }
484 
485     case TT_LINESPACING:
486       {
487         xxx_UT_DEBUGMSG(("ABIDEBUG: begin LINESPACING\n"));
488         break;
489       }
490 
491     case TT_OFFSETS:
492       {
493         xxx_UT_DEBUGMSG(("ABIDEBUG: begin OFFSETS\n"));
494         break;
495       }
496 
497     case TT_PAPER:
498       {
499         xxx_UT_DEBUGMSG(("ABIDEBUG: begin PAPER\n"));
500 
501 	const gchar * pProp = NULL;
502 
503 	pProp = _getXMLPropValue("format", atts);
504 	if(pProp)
505 	  {
506 	    // set the page size - we still set width&height below
507 	    getDoc()->m_docPageSize.Set(kPageToFpPageSize(pProp));
508 	  }
509 
510 	pProp = _getXMLPropValue("orientation", atts);
511 	if(pProp)
512 	  {
513 	    if(strcmp(pProp, "1") == 0)
514 	      {
515 		// set to landscape
516 		getDoc()->m_docPageSize.setLandscape();
517 	      }
518 	    else
519 	      {
520 		// set to portrait
521 		getDoc()->m_docPageSize.setPortrait();
522 	      }
523 	  }
524 
525 	double page_width, page_height;
526 	page_width = page_height = 0.0;
527 	pProp = _getXMLPropValue("width", atts);
528 	if(pProp)
529 	  {
530 	    // get the page width
531 	    page_width = atof(pProp);
532 	  }
533 
534 	pProp = _getXMLPropValue("height", atts);
535 	if(pProp)
536 	  {
537 	    // get the page height
538 	    page_height = atof(pProp);
539 	  }
540 
541 	if ( page_height != 0. && page_width != 0. )
542 	  getDoc()->m_docPageSize.Set(page_width, page_height, DIM_MM);
543 	break;
544       }
545 
546     case TT_PAPERBORDERS:
547       {
548         xxx_UT_DEBUGMSG(("ABIDEBUG: begin PAPERBORDERS\n"));
549 
550 	// margins
551 
552 	const gchar * pProp = NULL;
553 
554 	pProp = _getXMLPropValue("right", atts);
555 	if(pProp)
556 	  {
557 	    // page-margin-right from mm
558 	    m_szSectProps += "page-margin-right:";
559 	    m_szSectProps += pProp;
560 	    m_szSectProps += "mm; ";
561 	  }
562 
563 	// todo: really get these
564 	m_szSectProps += "page-margin-footer:0.0mm; page-margin-header:0.0mm; ";
565 
566 	pProp = _getXMLPropValue("left", atts);
567 	if(pProp)
568 	  {
569 	    // page-margin-left from mm
570 	    m_szSectProps += "page-margin-left:";
571 	    m_szSectProps += pProp;
572 	    m_szSectProps += "mm; ";
573 	  }
574 
575 	pProp = _getXMLPropValue("top", atts);
576 	if(pProp)
577 	  {
578 	    // page-margin-top from mm
579 	    m_szSectProps += "page-margin-top:";
580 	    m_szSectProps += pProp;
581 	    m_szSectProps += "mm; ";
582 	  }
583 
584 	pProp = _getXMLPropValue("bottom", atts);
585 	if(pProp)
586 	  {
587 	    // page-margin-bottom from mm
588 	    m_szSectProps += "page-margin-bottom:";
589 	    m_szSectProps += pProp;
590 	    m_szSectProps += "mm; ";
591 	  }
592 
593         break;
594       }
595 
596     case TT_PAGEBREAKING:
597       {
598         xxx_UT_DEBUGMSG(("ABIDEBUG: begin PAGEBREAKING\n"));
599         break;
600       }
601 
602     case TT_PARAGRAPH:
603       {
604         xxx_UT_DEBUGMSG(("ABIDEBUG: begin PARAGRPAH\n"));
605 
606         const gchar *pProp = NULL;
607 
608         pProp = _getXMLPropValue("value", atts);
609         if (pProp)
610         {
611           m_ParaProps += "text-align:";
612           m_ParaProps += numberToJustification(pProp);
613           m_ParaProps += "; ";
614         }
615 
616 	if(m_ParaProps.size() >= 2)
617 		m_ParaProps[m_ParaProps.size()-2] = 0;
618 
619 	const gchar * props[3];
620 	props[0] = "props";
621 	props[1] = m_ParaProps.c_str();
622 	props[2] = 0;
623 
624 	// TODO: handle more properties
625         X_CheckError(appendStrux(PTX_Block, props));
626 
627 	UT_DEBUGMSG(("DOM: CREATED PARAGRAPH\n"));
628         break;
629       }
630 
631     case TT_RIGHTBORDER:
632       {
633         xxx_UT_DEBUGMSG(("ABIDEBUG: begin RIGHTBORDER\n"));
634         break;
635       }
636 
637     case TT_STYLE:
638       {
639         xxx_UT_DEBUGMSG(("ABIDEBUG: begin STYLE\n"));
640         break;
641       }
642 
643     case TT_STYLES:
644       {
645         xxx_UT_DEBUGMSG(("ABIDEBUG: begin STYLES\n"));
646         break;
647       }
648 
649     case TT_TEXT:
650       {
651         m_bInText = true;
652         return;
653       }
654 
655     case TT_TOPBORDER:
656       {
657         xxx_UT_DEBUGMSG(("ABIDEBUG: begin TOPBORDER\n"));
658         break;
659       }
660 
661     case TT_ITALIC:
662       {
663         pVal = static_cast<const gchar *>(_getXMLPropValue("value", atts));
664         if (pVal && strcmp(pVal, "1") == 0 )
665         m_szCharProps += "font-style:italic; ";
666         break;
667       }
668 
669     case TT_UNDERLINE:
670       {
671         pVal = static_cast<const gchar *>(_getXMLPropValue("value", atts));
672         if (pVal && strcmp(pVal, "1") == 0 )
673         m_szCharProps += "text-decoration:underline; ";
674         break;
675       }
676 
677     case TT_WEIGHT:
678       {
679         pVal = static_cast<const gchar *>(_getXMLPropValue("value", atts));
680         if ( pVal && strcmp ( pVal, "75" ) == 0 )
681         m_szCharProps += "font-weight:bold; ";
682         break;
683       }
684 
685     case TT_STRIKEOUT:
686       {
687         pVal = static_cast<const gchar *>(_getXMLPropValue("value", atts));
688         if (pVal && strcmp(pVal, "1") == 0 )
689         m_szCharProps += "text-decoration:strike-through; ";
690         break;
691       }
692 
693     case TT_FONT:
694       {
695         pVal = static_cast<const gchar *>(_getXMLPropValue("name", atts));
696         if (pVal)
697         {
698           m_szCharProps += "font-face:";
699           m_szCharProps += pVal;
700           m_szCharProps += "; ";
701         }
702         break;
703       }
704 
705     case TT_SIZE:
706       {
707         pVal = static_cast<const gchar *>(_getXMLPropValue("value", atts));
708         if (pVal)
709         {
710           m_szCharProps += "font-size:";
711           m_szCharProps += pVal;
712           m_szCharProps += "; ";
713         }
714         break;
715       }
716 
717     case TT_FLOW:
718     case TT_FORMAT:
719     case TT_NAME:
720     case TT_VERTALIGN:
721     default:
722       xxx_UT_DEBUGMSG(("ABIDEBUG: work in progress\n"));
723       break;
724     }
725 
726 }
727 
_appendText()728 void IE_Imp_KWord_1::_appendText()
729 {
730   if (m_szTextBuffer.size())
731     {
732       if (!appendSpan(static_cast<const UT_UCSChar *>(m_szTextBuffer.ucs4_str()), m_szTextBuffer.size()))
733       {
734         UT_DEBUGMSG(("Error appending text run\n"));
735         return;
736       }
737       UT_DEBUGMSG(("DOM: APPENDED TEXT\n"));
738       m_szTextBuffer.clear();
739     }
740 }
741 
endElement(const gchar * name)742 void IE_Imp_KWord_1::endElement(const gchar *name)
743 {
744   X_EatIfAlreadyError();
745 
746   UT_uint32 tokenIndex = _mapNameToToken (name, s_Tokens, TokenTableSize);
747 
748   switch (tokenIndex)
749   {
750     case TT_ATTRIBUTE:
751       xxx_UT_DEBUGMSG(("ABIDEBUG: end ATTRIBUTE\n"));
752       break;
753 
754     case TT_BOTTOMBORDER:
755       xxx_UT_DEBUGMSG(("ABIDEBUG: end BOTTOMBORDER\n"));
756       break;
757 
758     case TT_CHARSET:
759       xxx_UT_DEBUGMSG(("ABIDEBUG: end CHARSET\n"));
760       break;
761 
762     case TT_CLIPARTS:
763       xxx_UT_DEBUGMSG(("ABIDEBUG: end CLIPARTS\n"));
764       break;
765 
766     case TT_COLOR:
767       xxx_UT_DEBUGMSG(("ABIDEBUG: end COLOR\n"));
768       break;
769 
770     case TT_COUNTER:
771       xxx_UT_DEBUGMSG(("ABIDEBUG: end COUNTER\n"));
772       break;
773 
774     case TT_DOC:
775     {
776       //  X_VerifyParseState(_PS_Init);
777       m_parseState = _PS_Doc;
778       return;
779     }
780 
781     case TT_FLOW:
782       xxx_UT_DEBUGMSG(("ABIDEBUG: end FLOW\n"));
783       break;
784 
785     case TT_FOLLOWING:
786       xxx_UT_DEBUGMSG(("ABIDEBUG: end FOLLOWING\n"));
787       break;
788 
789     case TT_FONT:
790       xxx_UT_DEBUGMSG(("ABIDEBUG: end FONT\n"));
791       break;
792 
793     case TT_FORMAT:
794     {
795       const gchar *propsArray[3];
796 
797       if (m_szCharProps.size() == 0)
798         {
799           xxx_UT_DEBUGMSG(("ABIDEBUG: no properties\n"));
800           _appendText ();
801           break;
802         }
803 
804 	if(m_szCharProps.size() >= 2)
805 		m_szCharProps[m_szCharProps.size() - 2] = 0; // knock off the final ';'
806 
807       propsArray[0] = static_cast<const gchar *>("props");
808       propsArray[1] = static_cast<const gchar *>(m_szCharProps.c_str());
809       propsArray[2] = 0;
810 
811       xxx_UT_DEBUGMSG(("ABIDEBUG: formatting properties are: %s\n",propsArray[1]));
812 
813       X_CheckError(_pushInlineFmt(propsArray));
814       X_CheckError(appendFmt(&m_vecInlineFmt));
815 
816       UT_DEBUGMSG(("DOM: APPENDED FORMAT\n"));
817 
818       m_szCharProps.clear();
819       _appendText();
820 
821       _popInlineFmt();
822       X_CheckError(appendFmt(&m_vecInlineFmt));
823 
824       break;
825     }
826 
827     case TT_FORMATS:
828       xxx_UT_DEBUGMSG(("ABIDEBUG: end FORMATS\n"));
829       break;
830 
831     case TT_FRAME:
832       xxx_UT_DEBUGMSG(("ABIDEBUG: end FRAME\n"));
833       break;
834 
835     case TT_FRAMESET:
836       xxx_UT_DEBUGMSG(("ABIDEBUG: end FRAMESET\n"));
837       break;
838 
839     case TT_INDENTS:
840       xxx_UT_DEBUGMSG(("ABIDEBUG: end INDENTS\n"));
841       break;
842 
843     case TT_ITALIC:
844       xxx_UT_DEBUGMSG(("ABIDEBUG: end ITALIC\n"));
845       break;
846 
847     case TT_LAYOUT:
848       xxx_UT_DEBUGMSG(("ABIDEBUG: end LAYOUT\n"));
849       break;
850 
851     case TT_LEFTBORDER:
852       xxx_UT_DEBUGMSG(("ABIDEBUG: end LEFTBORDER\n"));
853       break;
854 
855     case TT_LINESPACING:
856       xxx_UT_DEBUGMSG(("ABIDEBUG: end LINESPACING\n"));
857       break;
858 
859    case TT_NAME:
860       xxx_UT_DEBUGMSG(("ABIDEBUG: end NAME\n"));
861       break;
862 
863     case TT_OFFSETS:
864       xxx_UT_DEBUGMSG(("ABIDEBUG: end OFFSETS\n"));
865       break;
866 
867     case TT_PAPER:
868       xxx_UT_DEBUGMSG(("ABIDEBUG: end PAPER\n"));
869       break;
870 
871     case TT_PAPERBORDERS:
872       xxx_UT_DEBUGMSG(("ABIDEBUG: end PAPERBORDERS\n"));
873       break;
874 
875     case TT_PAGEBREAKING:
876       xxx_UT_DEBUGMSG(("ABIDEBUG: end PAGEBREAKING\n"));
877       break;
878 
879     case TT_PARAGRAPH:
880       xxx_UT_DEBUGMSG(("ABIDEBUG: end PARAGRPAH\n"));
881       break;
882 
883     case TT_RIGHTBORDER:
884       xxx_UT_DEBUGMSG(("ABIDEBUG: end RIGHTBORDER\n"));
885       break;
886 
887     case TT_SIZE:
888       xxx_UT_DEBUGMSG(("ABIDEBUG: end SIZE\n"));
889       break;
890 
891     case TT_STRIKEOUT:
892       xxx_UT_DEBUGMSG(("ABIDEBUG: end STRIKEOUT\n"));
893       break;
894 
895     case TT_STYLE:
896       xxx_UT_DEBUGMSG(("ABIDEBUG: end STYLE\n"));
897       break;
898 
899     case TT_STYLES:
900       xxx_UT_DEBUGMSG(("ABIDEBUG: end STYLES\n"));
901       break;
902 
903     case TT_TEXT:
904       m_bInText = false;
905       return;
906 
907     case TT_TOPBORDER:
908       xxx_UT_DEBUGMSG(("ABIDEBUG: end TOPBORDER\n"));
909       break;
910 
911     case TT_UNDERLINE:
912       xxx_UT_DEBUGMSG(("ABIDEBUG: end UNDERLINE\n"));
913       break;
914 
915     case TT_VERTALIGN:
916       xxx_UT_DEBUGMSG(("ABIDEBUG: end VERTALIGN\n"));
917       break;
918 
919     case TT_WEIGHT:
920       xxx_UT_DEBUGMSG(("ABIDEBUG: end WEIGHT\n"));
921       break;
922 
923   }
924 
925 }
926