00001 /***************************************************************************
00002 rtfhtml.cpp - description
00003 -------------------
00004 begin : Wed Oct 13 1999
00005 copyright : (C) 1999 by The team of BibleTime
00006 email : info@bibletime.de
00007 ***************************************************************************/
00008
00009 /***************************************************************************
00010 * *
00011 * This program is free software; you can redistribute it and/or modify *
00012 * it under the terms of the GNU General Public License as published by *
00013 * the Free Software Foundation; either version 2 of the License, or *
00014 * (at your option) any later version. *
00015 * *
00016 ***************************************************************************/
00017
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <rtfhtml.h>
00021
00022
00023 RTFHTML::RTFHTML() {
00024
00025 }
00026
00027
00028 char RTFHTML::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00029 {
00030 char *to, *from;
00031 int len;
00032 bool center = false;
00033
00034 len = strlen(text) + 1; // shift string to right of buffer
00035 if (len < maxlen) {
00036 memmove(&text[maxlen - len], text, len);
00037 from = &text[maxlen - len];
00038 }
00039 else from = text; // -------------------------------
00040 for (to = text; *from; from++) {
00041 if (*from == '\\') // a RTF command
00042 {
00043 if ((from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r') && (from[4] == 'd'))
00044 { // switch all modifier off
00045 if (center)
00046 {
00047 *to++ = '<';
00048 *to++ = '/';
00049 *to++ = 'C';
00050 *to++ = 'E';
00051 *to++ = 'N';
00052 *to++ = 'T';
00053 *to++ = 'E';
00054 *to++ = 'R';
00055 *to++ = '>';
00056 center = false;
00057 }
00058 from += 4;
00059 continue;
00060 }
00061 if ((from[1] == 'p') && (from[2] == 'a') && (from[3] == 'r'))
00062 {
00063 *to++ = '<';
00064 *to++ = 'P';
00065 *to++ = '>';
00066 *to++ = '\n';
00067 from += 3;
00068 continue;
00069 }
00070 if (from[1] == ' ')
00071 {
00072 from += 1;
00073 continue;
00074 }
00075 if ((from[1] == 'q') && (from[2] == 'c')) // center on
00076 {
00077 if (!center)
00078 {
00079 *to++ = '<';
00080 *to++ = 'C';
00081 *to++ = 'E';
00082 *to++ = 'N';
00083 *to++ = 'T';
00084 *to++ = 'E';
00085 *to++ = 'R';
00086 *to++ = '>';
00087 center = true;
00088 }
00089 from += 2;
00090 continue;
00091 }
00092 }
00093
00094 *to++ = *from;
00095 }
00096 *to++ = 0;
00097 *to = 0;
00098 return 0;
00099 }
1.2.15