The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rtfhtml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * rtfhtml.cpp - filter to convert RTF to HTML
4  *
5  * $Id: rtfhtml.cpp 3749 2020-07-06 23:51:56Z scribe $
6  *
7  * Copyright 1999 The team of Bibletime (info@bibletime.de)
8  * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <rtfhtml.h>
26 #include <swbuf.h>
27 #include <utilstr.h>
28 #include <ctype.h>
29 #include <sysdata.h>
30 
32 
34 {
35 }
36 
37 
38 char RTFHTML::processText(SWBuf &text, const SWKey *key, const SWModule *module)
39 {
40  bool center = false;
41 
42  const char *from;
43  SWBuf orig = text;
44  from = orig.c_str();
45  for (text = ""; *from; from++)
46  {
47  if (*from == '\\') // a RTF command
48  {
49  // \u12345?
50  if ( *(from+1) == 'u' && (*(from+2) == '-' || isdigit(*(from+2)))) {
51  from += 2;
52  const char *end = from;
53  while (isdigit(*++end));
54  SWBuf num;
55  num.append(from, end-from);
56  SW_s16 n = atoi(num.c_str());
57  SW_u32 u = (SW_u16)n;
58  getUTF8FromUniChar(u, &text);
59  from += (end-from);
60  continue;
61  }
62  if ( !strncmp(from+1, "pard", 4) )
63  //(from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r') && (from[4] == 'd'))
64  { // switch all modifiers off
65  if (center)
66  {
67  text += "</center>";
68  center = false;
69  }
70  from += 4;
71  continue;
72  }
73  if ( !strncmp(from+1, "par", 3) )
74  //(from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r'))
75  {
76  text += "<p/>\n";
77  from += 3;
78  continue;
79  }
80  if (from[1] == ' ')
81  {
82  from += 1;
83  continue;
84  }
85  if ( !strncmp(from+1, "qc", 2) )
86  //(from[1] == 'q') && (from[2] == 'c')) // center on
87  {
88  if (!center)
89  {
90  text += "<center>";
91  center = true;
92  }
93  from += 2;
94  continue;
95  }
96  }
97 
98  text += *from;
99  }
100  return 0;
101 }
102 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: rtfhtml.cpp:38
unsigned short SW_u16
Definition: sysdata.h:38
SWBuf * getUTF8FromUniChar(SW_u32 uchar, SWBuf *appendTo)
Definition: utilstr.h:165
unsigned int SW_u32
Definition: sysdata.h:41
RTFHTML()
Definition: rtfhtml.cpp:33
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
signed short SW_s16
Definition: sysdata.h:37