]> git.saurik.com Git - wxWidgets.git/blob - src/richtext/richtextxml.cpp
put expdecl in the correct place in DECLARE/IMPLEMENT_VARIANT_OBJECT_EXPORTED
[wxWidgets.git] / src / richtext / richtextxml.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextxml.cpp
3 // Purpose: XML and HTML I/O for wxRichTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_RICHTEXT && wxUSE_XML
20
21 #include "wx/richtext/richtextxml.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/intl.h"
25 #include "wx/module.h"
26 #endif
27
28 #include "wx/filename.h"
29 #include "wx/clipbrd.h"
30 #include "wx/wfstream.h"
31 #include "wx/sstream.h"
32 #include "wx/txtstrm.h"
33 #include "wx/tokenzr.h"
34 #include "wx/xml/xml.h"
35
36 IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler)
37
38 #if wxUSE_STREAMS
39 bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
40 {
41 if (!stream.IsOk())
42 return false;
43
44 buffer->Clear();
45
46 wxXmlDocument* xmlDoc = new wxXmlDocument;
47 bool success = true;
48
49 // This is the encoding to convert to (memory encoding rather than file encoding)
50 wxString encoding(wxT("UTF-8"));
51
52 #if !wxUSE_UNICODE && wxUSE_INTL
53 encoding = wxLocale::GetSystemEncodingName();
54 #endif
55
56 if (!xmlDoc->Load(stream, encoding))
57 {
58 success = false;
59 }
60 else
61 {
62 if (xmlDoc->GetRoot() && xmlDoc->GetRoot()->GetType() == wxXML_ELEMENT_NODE && xmlDoc->GetRoot()->GetName() == wxT("richtext"))
63 {
64 wxXmlNode* child = xmlDoc->GetRoot()->GetChildren();
65 while (child)
66 {
67 if (child->GetType() == wxXML_ELEMENT_NODE)
68 {
69 wxString name = child->GetName();
70 if (name == wxT("richtext-version"))
71 {
72 }
73 else
74 ImportXML(buffer, child);
75 }
76
77 child = child->GetNext();
78 }
79 }
80 else
81 {
82 success = false;
83 }
84 }
85
86 delete xmlDoc;
87
88 buffer->UpdateRanges();
89
90 return success;
91 }
92
93 /// Recursively import an object
94 bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
95 {
96 wxString name = node->GetName();
97
98 bool doneChildren = false;
99
100 if (name == wxT("paragraphlayout"))
101 {
102 wxString partial = node->GetPropVal(wxT("partialparagraph"), wxEmptyString);
103 if (partial == wxT("true"))
104 buffer->SetPartialParagraph(true);
105 }
106 else if (name == wxT("paragraph"))
107 {
108 wxRichTextParagraph* para = new wxRichTextParagraph(buffer);
109 buffer->AppendChild(para);
110
111 GetStyle(para->GetAttributes(), node, true);
112
113 wxXmlNode* child = node->GetChildren();
114 while (child)
115 {
116 wxString childName = child->GetName();
117 if (childName == wxT("text"))
118 {
119 wxString text;
120 wxXmlNode* textChild = child->GetChildren();
121 while (textChild)
122 {
123 if (textChild->GetType() == wxXML_TEXT_NODE ||
124 textChild->GetType() == wxXML_CDATA_SECTION_NODE)
125 {
126 wxString text2 = textChild->GetContent();
127
128 // Strip whitespace from end
129 if (!text2.empty() && text2[text2.length()-1] == wxT('\n'))
130 text2 = text2.Mid(0, text2.length()-1);
131
132 if (!text2.empty() && text2[0] == wxT('"'))
133 text2 = text2.Mid(1);
134 if (!text2.empty() && text2[text2.length()-1] == wxT('"'))
135 text2 = text2.Mid(0, text2.length() - 1);
136
137 text += text2;
138 }
139 textChild = textChild->GetNext();
140 }
141
142 wxRichTextPlainText* textObject = new wxRichTextPlainText(text, para);
143 GetStyle(textObject->GetAttributes(), child, false);
144
145 para->AppendChild(textObject);
146 }
147 else if (childName == wxT("image"))
148 {
149 int imageType = wxBITMAP_TYPE_PNG;
150 wxString value = node->GetPropVal(wxT("imagetype"), wxEmptyString);
151 if (!value.empty())
152 imageType = wxAtoi(value);
153
154 wxString data;
155
156 wxXmlNode* imageChild = child->GetChildren();
157 while (imageChild)
158 {
159 wxString childName = imageChild->GetName();
160 if (childName == wxT("data"))
161 {
162 wxXmlNode* dataChild = imageChild->GetChildren();
163 while (dataChild)
164 {
165 data = dataChild->GetContent();
166 // wxLogDebug(data);
167 dataChild = dataChild->GetNext();
168 }
169
170 }
171 imageChild = imageChild->GetNext();
172 }
173
174 if (!data.empty())
175 {
176 wxRichTextImage* imageObj = new wxRichTextImage(para);
177 para->AppendChild(imageObj);
178
179 wxStringInputStream strStream(data);
180
181 imageObj->GetImageBlock().ReadHex(strStream, data.length(), imageType);
182 }
183 }
184 child = child->GetNext();
185 }
186
187 doneChildren = true;
188 }
189
190 if (!doneChildren)
191 {
192 wxXmlNode* child = node->GetChildren();
193 while (child)
194 {
195 ImportXML(buffer, child);
196 child = child->GetNext();
197 }
198 }
199
200 return true;
201 }
202
203
204 //-----------------------------------------------------------------------------
205 // xml support routines
206 //-----------------------------------------------------------------------------
207
208 bool wxRichTextXMLHandler::HasParam(wxXmlNode* node, const wxString& param)
209 {
210 return (GetParamNode(node, param) != NULL);
211 }
212
213 wxXmlNode *wxRichTextXMLHandler::GetParamNode(wxXmlNode* node, const wxString& param)
214 {
215 wxCHECK_MSG(node, NULL, wxT("You can't access node data before it was initialized!"));
216
217 wxXmlNode *n = node->GetChildren();
218
219 while (n)
220 {
221 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
222 return n;
223 n = n->GetNext();
224 }
225 return NULL;
226 }
227
228
229 wxString wxRichTextXMLHandler::GetNodeContent(wxXmlNode *node)
230 {
231 wxXmlNode *n = node;
232 if (n == NULL) return wxEmptyString;
233 n = n->GetChildren();
234
235 while (n)
236 {
237 if (n->GetType() == wxXML_TEXT_NODE ||
238 n->GetType() == wxXML_CDATA_SECTION_NODE)
239 return n->GetContent();
240 n = n->GetNext();
241 }
242 return wxEmptyString;
243 }
244
245
246 wxString wxRichTextXMLHandler::GetParamValue(wxXmlNode *node, const wxString& param)
247 {
248 if (param.empty())
249 return GetNodeContent(node);
250 else
251 return GetNodeContent(GetParamNode(node, param));
252 }
253
254 wxString wxRichTextXMLHandler::GetText(wxXmlNode *node, const wxString& param, bool WXUNUSED(translate))
255 {
256 wxXmlNode *parNode = GetParamNode(node, param);
257 if (!parNode)
258 parNode = node;
259 wxString str1(GetNodeContent(parNode));
260 return str1;
261 }
262
263 // For use with earlier versions of wxWidgets
264 #ifndef WXUNUSED_IN_UNICODE
265 #if wxUSE_UNICODE
266 #define WXUNUSED_IN_UNICODE(x) WXUNUSED(x)
267 #else
268 #define WXUNUSED_IN_UNICODE(x) x
269 #endif
270 #endif
271
272 // write string to output:
273 inline static void OutputString(wxOutputStream& stream, const wxString& str,
274 wxMBConv *WXUNUSED_IN_UNICODE(convMem) = NULL, wxMBConv *convFile = NULL)
275 {
276 if (str.empty()) return;
277 #if wxUSE_UNICODE
278 if (convFile)
279 {
280 const wxWX2MBbuf buf(str.mb_str(*convFile));
281 stream.Write((const char*)buf, strlen((const char*)buf));
282 }
283 else
284 {
285 const wxWX2MBbuf buf(str.mb_str(wxConvUTF8));
286 stream.Write((const char*)buf, strlen((const char*)buf));
287 }
288 #else
289 if ( convFile == NULL )
290 stream.Write(str.mb_str(), str.Len());
291 else
292 {
293 wxString str2(str.wc_str(*convMem), *convFile);
294 stream.Write(str2.mb_str(), str2.Len());
295 }
296 #endif
297 }
298
299 // Same as above, but create entities first.
300 // Translates '<' to "&lt;", '>' to "&gt;" and '&' to "&amp;"
301 static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
302 wxMBConv *convMem = NULL, wxMBConv *convFile = NULL)
303 {
304 wxString buf;
305 size_t i, last, len;
306 wxChar c;
307
308 len = str.Len();
309 last = 0;
310 for (i = 0; i < len; i++)
311 {
312 c = str.GetChar(i);
313
314 // Original code excluded "&amp;" but we _do_ want to convert
315 // the ampersand beginning &amp; because otherwise when read in,
316 // the original "&amp;" becomes "&".
317
318 if (c == wxT('<') || c == wxT('>') || c == wxT('"') ||
319 (c == wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ ))
320 {
321 OutputString(stream, str.Mid(last, i - last), convMem, convFile);
322 switch (c)
323 {
324 case wxT('<'):
325 OutputString(stream, wxT("&lt;"), NULL, NULL);
326 break;
327 case wxT('>'):
328 OutputString(stream, wxT("&gt;"), NULL, NULL);
329 break;
330 case wxT('&'):
331 OutputString(stream, wxT("&amp;"), NULL, NULL);
332 break;
333 case wxT('"'):
334 OutputString(stream, wxT("&quot;"), NULL, NULL);
335 break;
336 default: break;
337 }
338 last = i + 1;
339 }
340 }
341 OutputString(stream, str.Mid(last, i - last), convMem, convFile);
342 }
343
344 inline static void OutputIndentation(wxOutputStream& stream, int indent)
345 {
346 wxString str = wxT("\n");
347 for (int i = 0; i < indent; i++)
348 str << wxT(' ') << wxT(' ');
349 OutputString(stream, str, NULL, NULL);
350 }
351
352 // Convert a colour to a 6-digit hex string
353 static wxString ColourToHexString(const wxColour& col)
354 {
355 wxString hex;
356
357 hex += wxDecToHex(col.Red());
358 hex += wxDecToHex(col.Green());
359 hex += wxDecToHex(col.Blue());
360
361 return hex;
362 }
363
364 // Convert 6-digit hex string to a colour
365 static wxColour HexStringToColour(const wxString& hex)
366 {
367 unsigned char r = (unsigned char)wxHexToDec(hex.Mid(0, 2));
368 unsigned char g = (unsigned char)wxHexToDec(hex.Mid(2, 2));
369 unsigned char b = (unsigned char)wxHexToDec(hex.Mid(4, 2));
370
371 return wxColour(r, g, b);
372 }
373
374 bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
375 {
376 if (!stream.IsOk())
377 return false;
378
379 wxString version(wxT("1.0") ) ;
380
381 bool deleteConvFile = false;
382 wxString fileEncoding;
383 wxMBConv* convFile = NULL;
384
385 #if wxUSE_UNICODE
386 fileEncoding = wxT("UTF-8");
387 convFile = & wxConvUTF8;
388 #else
389 fileEncoding = wxT("ISO-8859-1");
390 convFile = & wxConvISO8859_1;
391 #endif
392
393 // If SetEncoding has been called, change the output encoding.
394 if (!m_encoding.empty() && m_encoding.Lower() != fileEncoding.Lower())
395 {
396 if (m_encoding == wxT("<System>"))
397 {
398 fileEncoding = wxLocale::GetSystemEncodingName();
399 }
400 else
401 {
402 fileEncoding = m_encoding;
403 }
404
405 // GetSystemEncodingName may not have returned a name
406 if (fileEncoding.empty())
407 #if wxUSE_UNICODE
408 fileEncoding = wxT("UTF-8");
409 #else
410 fileEncoding = wxT("ISO-8859-1");
411 #endif
412 convFile = new wxCSConv(fileEncoding);
413 deleteConvFile = true;
414 }
415
416 #if !wxUSE_UNICODE
417 wxMBConv* convMem = wxConvCurrent;
418 #else
419 wxMBConv* convMem = NULL;
420 #endif
421
422 wxString s ;
423 s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
424 (const wxChar*) version, (const wxChar*) fileEncoding );
425 OutputString(stream, s, NULL, NULL);
426 OutputString(stream, wxT("<richtext version=\"1.0.0.0\" xmlns=\"http://www.wxwidgets.org\">") , NULL, NULL);
427
428 int level = 1;
429 bool success = ExportXML(stream, convMem, convFile, *buffer, level);
430
431 OutputString(stream, wxT("\n</richtext>") , NULL, NULL);
432 OutputString(stream, wxT("\n"), NULL, NULL);
433
434 if (deleteConvFile)
435 delete convFile;
436
437 return success;
438 }
439
440 /// Recursively export an object
441 bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int indent)
442 {
443 wxString objectName;
444 if (obj.IsKindOf(CLASSINFO(wxRichTextParagraphLayoutBox)))
445 objectName = wxT("paragraphlayout");
446 else if (obj.IsKindOf(CLASSINFO(wxRichTextParagraph)))
447 objectName = wxT("paragraph");
448 else if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
449 objectName = wxT("text");
450 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
451 objectName = wxT("image");
452 else
453 objectName = wxT("object");
454
455 if (obj.IsKindOf(CLASSINFO(wxRichTextPlainText)))
456 {
457 wxRichTextPlainText& text = (wxRichTextPlainText&) obj;
458
459 OutputIndentation(stream, indent);
460 OutputString(stream, wxT("<") + objectName, convMem, convFile);
461
462 wxString style = CreateStyle(obj.GetAttributes(), false);
463
464 OutputString(stream, style + wxT(">"), convMem, convFile);
465
466 wxString str = text.GetText();
467 if (!str.empty() && (str[0] == wxT(' ') || str[str.length()-1] == wxT(' ')))
468 {
469 OutputString(stream, wxT("\""), convMem, convFile);
470 OutputStringEnt(stream, str, convMem, convFile);
471 OutputString(stream, wxT("\""), convMem, convFile);
472 }
473 else
474 OutputStringEnt(stream, str, convMem, convFile);
475 }
476 else if (obj.IsKindOf(CLASSINFO(wxRichTextImage)))
477 {
478 wxRichTextImage& imageObj = (wxRichTextImage&) obj;
479
480 if (imageObj.GetImage().Ok() && !imageObj.GetImageBlock().Ok())
481 imageObj.MakeBlock();
482
483 OutputIndentation(stream, indent);
484 OutputString(stream, wxT("<") + objectName, convMem, convFile);
485 if (!imageObj.GetImageBlock().Ok())
486 {
487 // No data
488 OutputString(stream, wxT(">"), convMem, convFile);
489 }
490 else
491 {
492 OutputString(stream, wxString::Format(wxT(" imagetype=\"%d\">"), (int) imageObj.GetImageBlock().GetImageType()));
493 }
494
495 OutputIndentation(stream, indent+1);
496 OutputString(stream, wxT("<data>"), convMem, convFile);
497
498 imageObj.GetImageBlock().WriteHex(stream);
499
500 OutputString(stream, wxT("</data>"), convMem, convFile);
501 }
502 else if (obj.IsKindOf(CLASSINFO(wxRichTextCompositeObject)))
503 {
504 OutputIndentation(stream, indent);
505 OutputString(stream, wxT("<") + objectName, convMem, convFile);
506
507 bool isPara = false;
508 if (objectName == wxT("paragraph") || objectName == wxT("paragraphlayout"))
509 isPara = true;
510
511 wxString style = CreateStyle(obj.GetAttributes(), isPara);
512
513 if (objectName == wxT("paragraphlayout") && ((wxRichTextParagraphLayoutBox&) obj).GetPartialParagraph())
514 style << wxT(" partialparagraph=\"true\"");
515
516 OutputString(stream, style + wxT(">"), convMem, convFile);
517
518 wxRichTextCompositeObject& composite = (wxRichTextCompositeObject&) obj;
519 size_t i;
520 for (i = 0; i < composite.GetChildCount(); i++)
521 {
522 wxRichTextObject* child = composite.GetChild(i);
523 ExportXML(stream, convMem, convFile, *child, indent+1);
524 }
525 }
526
527 if (objectName != wxT("text"))
528 OutputIndentation(stream, indent);
529
530 OutputString(stream, wxT("</") + objectName + wxT(">"), convMem, convFile);
531
532 return true;
533 }
534
535 /// Create style parameters
536 wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara)
537 {
538 wxString str;
539 if (attr.HasTextColour() && attr.GetTextColour().Ok())
540 {
541 str << wxT(" textcolor=\"#") << ColourToHexString(attr.GetTextColour()) << wxT("\"");
542 }
543 if (attr.HasBackgroundColour() && attr.GetBackgroundColour().Ok())
544 {
545 str << wxT(" bgcolor=\"#") << ColourToHexString(attr.GetBackgroundColour()) << wxT("\"");
546 }
547
548 if (attr.GetFont().Ok())
549 {
550 if (attr.HasSize())
551 str << wxT(" fontsize=\"") << attr.GetFont().GetPointSize() << wxT("\"");
552
553 //if (attr.HasFamily())
554 // str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
555
556 if (attr.HasItalic())
557 str << wxT(" fontstyle=\"") << attr.GetFont().GetStyle() << wxT("\"");
558
559 if (attr.HasWeight())
560 str << wxT(" fontweight=\"") << attr.GetFont().GetWeight() << wxT("\"");
561
562 if (attr.HasUnderlined())
563 str << wxT(" fontunderlined=\"") << (int) attr.GetFont().GetUnderlined() << wxT("\"");
564
565 if (attr.HasFaceName())
566 str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
567 }
568
569 if (!attr.GetCharacterStyleName().empty())
570 str << wxT(" charactertyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
571
572 if (isPara)
573 {
574 if (attr.HasAlignment())
575 str << wxT(" alignment=\"") << (int) attr.GetAlignment() << wxT("\"");
576
577 if (attr.HasLeftIndent())
578 {
579 str << wxT(" leftindent=\"") << (int) attr.GetLeftIndent() << wxT("\"");
580 str << wxT(" leftsubindent=\"") << (int) attr.GetLeftSubIndent() << wxT("\"");
581 }
582
583 if (attr.HasRightIndent())
584 str << wxT(" rightindent=\"") << (int) attr.GetRightIndent() << wxT("\"");
585
586 if (attr.HasParagraphSpacingAfter())
587 str << wxT(" parspacingafter=\"") << (int) attr.GetParagraphSpacingAfter() << wxT("\"");
588
589 if (attr.HasParagraphSpacingBefore())
590 str << wxT(" parspacingbefore=\"") << (int) attr.GetParagraphSpacingBefore() << wxT("\"");
591
592 if (attr.HasLineSpacing())
593 str << wxT(" linespacing=\"") << (int) attr.GetLineSpacing() << wxT("\"");
594
595 if (attr.HasBulletStyle())
596 str << wxT(" bulletstyle=\"") << (int) attr.GetBulletStyle() << wxT("\"");
597
598 if (attr.HasBulletNumber())
599 str << wxT(" bulletnumber=\"") << (int) attr.GetBulletNumber() << wxT("\"");
600
601 if (attr.HasBulletSymbol())
602 str << wxT(" bulletsymbol=\"") << wxString(attr.GetBulletSymbol()) << wxT("\"");
603
604 if (!attr.GetParagraphStyleName().empty())
605 str << wxT(" parstyle=\"") << wxString(attr.GetParagraphStyleName()) << wxT("\"");
606
607 if (attr.HasTabs())
608 {
609 str << wxT(" tabs=\"");
610 size_t i;
611 for (i = 0; i < attr.GetTabs().GetCount(); i++)
612 {
613 if (i > 0)
614 str << wxT(",");
615 str << attr.GetTabs()[i];
616 }
617 str << wxT("\"");
618 }
619 }
620
621 return str;
622 }
623
624 /// Get style parameters
625 bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool isPara)
626 {
627 wxString fontFacename;
628 int fontSize = 12;
629 int fontFamily = wxDEFAULT;
630 int fontWeight = wxNORMAL;
631 int fontStyle = wxNORMAL;
632 bool fontUnderlined = false;
633
634 int fontFlags = 0;
635
636 fontFacename = node->GetPropVal(wxT("fontface"), wxEmptyString);
637 if (!fontFacename.IsEmpty())
638 fontFlags |= wxTEXT_ATTR_FONT_FACE;
639
640 wxString value;
641 //value = node->GetPropVal(wxT("fontfamily"), wxEmptyString);
642 //if (!value.empty())
643 // fontFamily = wxAtoi(value);
644
645 value = node->GetPropVal(wxT("fontstyle"), wxEmptyString);
646 if (!value.empty())
647 {
648 fontStyle = wxAtoi(value);
649 fontFlags |= wxTEXT_ATTR_FONT_ITALIC;
650 }
651
652 value = node->GetPropVal(wxT("fontsize"), wxEmptyString);
653 if (!value.empty())
654 {
655 fontSize = wxAtoi(value);
656 fontFlags |= wxTEXT_ATTR_FONT_SIZE;
657 }
658
659 value = node->GetPropVal(wxT("fontweight"), wxEmptyString);
660 if (!value.empty())
661 {
662 fontWeight = wxAtoi(value);
663 fontFlags |= wxTEXT_ATTR_FONT_WEIGHT;
664 }
665
666 value = node->GetPropVal(wxT("fontunderlined"), wxEmptyString);
667 if (!value.empty())
668 {
669 fontUnderlined = wxAtoi(value) != 0;
670 fontFlags |= wxTEXT_ATTR_FONT_UNDERLINE;
671 }
672
673 attr.SetFlags(fontFlags);
674
675 if (attr.HasFlag(wxTEXT_ATTR_FONT))
676 attr.SetFont(* wxTheFontList->FindOrCreateFont(fontSize, fontFamily, fontStyle, fontWeight, fontUnderlined, fontFacename));
677
678 // Restore correct font flags
679 attr.SetFlags(fontFlags);
680
681 value = node->GetPropVal(wxT("textcolor"), wxEmptyString);
682 if (!value.empty())
683 {
684 if (value[0] == wxT('#'))
685 attr.SetTextColour(HexStringToColour(value.Mid(1)));
686 else
687 attr.SetTextColour(value);
688 }
689
690 value = node->GetPropVal(wxT("backgroundcolor"), wxEmptyString);
691 if (!value.empty())
692 {
693 if (value[0] == wxT('#'))
694 attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
695 else
696 attr.SetBackgroundColour(value);
697 }
698
699 value = node->GetPropVal(wxT("characterstyle"), wxEmptyString);
700 if (!value.empty())
701 attr.SetCharacterStyleName(value);
702
703 // Set paragraph attributes
704 if (isPara)
705 {
706 value = node->GetPropVal(wxT("alignment"), wxEmptyString);
707 if (!value.empty())
708 attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
709
710 int leftSubIndent = 0;
711 int leftIndent = 0;
712 bool hasLeftIndent = false;
713
714 value = node->GetPropVal(wxT("leftindent"), wxEmptyString);
715 if (!value.empty())
716 {
717 leftIndent = wxAtoi(value);
718 hasLeftIndent = true;
719 }
720
721 value = node->GetPropVal(wxT("leftsubindent"), wxEmptyString);
722 if (!value.empty())
723 {
724 leftSubIndent = wxAtoi(value);
725 hasLeftIndent = true;
726 }
727
728 if (hasLeftIndent)
729 attr.SetLeftIndent(leftIndent, leftSubIndent);
730
731 value = node->GetPropVal(wxT("rightindent"), wxEmptyString);
732 if (!value.empty())
733 attr.SetRightIndent(wxAtoi(value));
734
735 value = node->GetPropVal(wxT("parspacingbefore"), wxEmptyString);
736 if (!value.empty())
737 attr.SetParagraphSpacingBefore(wxAtoi(value));
738
739 value = node->GetPropVal(wxT("parspacingafter"), wxEmptyString);
740 if (!value.empty())
741 attr.SetParagraphSpacingAfter(wxAtoi(value));
742
743 value = node->GetPropVal(wxT("linespacing"), wxEmptyString);
744 if (!value.empty())
745 attr.SetLineSpacing(wxAtoi(value));
746
747 value = node->GetPropVal(wxT("bulletstyle"), wxEmptyString);
748 if (!value.empty())
749 attr.SetBulletStyle(wxAtoi(value));
750
751 value = node->GetPropVal(wxT("bulletnumber"), wxEmptyString);
752 if (!value.empty())
753 attr.SetBulletNumber(wxAtoi(value));
754
755 value = node->GetPropVal(wxT("bulletsymbol"), wxEmptyString);
756 if (!value.empty())
757 attr.SetBulletSymbol(value[0]);
758
759 value = node->GetPropVal(wxT("parstyle"), wxEmptyString);
760 if (!value.empty())
761 attr.SetParagraphStyleName(value);
762
763 value = node->GetPropVal(wxT("tabs"), wxEmptyString);
764 if (!value.empty())
765 {
766 wxArrayInt tabs;
767 wxStringTokenizer tkz(value, wxT(","));
768 while (tkz.HasMoreTokens())
769 {
770 wxString token = tkz.GetNextToken();
771 tabs.Add(wxAtoi(token));
772 }
773 attr.SetTabs(tabs);
774 }
775 }
776
777 return true;
778 }
779
780 #endif
781 // wxUSE_STREAMS
782
783 #endif
784 // wxUSE_RICHTEXT && wxUSE_XML