Merge pull request #5392 from Jojo-Schmitz/rtf2html-sync

sync thirdparty/rtf2html with https://github.com/lvu/rtf2html
This commit is contained in:
anatoly-os 2019-10-29 11:12:52 +02:00 committed by GitHub
commit 4f1be2b67c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 209 additions and 87 deletions

View file

@ -49,8 +49,50 @@
/* Define to 1 for release version */
#define NDEBUG 1
/* Name of package */
#define PACKAGE "rtf2html"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "vlavrinenko@users.sourceforge.net"
/* Define to the full name of this package. */
#define PACKAGE_NAME "rtf2html"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "rtf2html 0.2.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "rtf2html"
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.2.0"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "0.2.0"
/* Define to 1 for debug version */
/* #undef _DEBUG */
/* Define to 1 for release version */
#define _NDEBUG 1
/* Define to 1 to use STLPort debug facilities */
/* #undef _STLP_DEBUG */
/* Define to 1 if you link STLPort statically */
/* #undef _STLP_USE_STATIC_LIB */
/* Define to 1 for debug version */
/* #undef __DEBUG__ */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif

View file

@ -1,5 +1,7 @@
#include "fmt_opts.h"
strmap formatting_options::styles;
std::string formatting_options::get_par_str() const
{
std::string style;
@ -52,11 +54,30 @@ std::string formatting_options::get_par_str() const
return std::string("<p>");
else
{
style.insert(0, "<p style=\"");
return style+"\">";
return std::string("<p class=\"") + formatting_options::get_style_id(style) + "\">";
}
}
std::string formatting_options::get_style_id(const std::string &style)
{
strmap::iterator i_style = styles.find(style);
if (i_style == styles.end())
{
i_style = styles.insert(strmap::value_type(style, std::string("cls") + from_int(styles.size()))).first;
}
return i_style->second;
}
std::string formatting_options::get_styles()
{
std::string result;
for (strmap::const_iterator i = styles.begin(); i != styles.end(); ++i)
{
result += std::string(".") + i->second + " {" + i->first + "}\n";
}
return result;
}
std::string formatter::format(const formatting_options &_opt)
{
formatting_options last_opt, opt(_opt);
@ -109,6 +130,12 @@ std::string formatter::format(const formatting_options &_opt)
style+=opt.chpBold?"bold":"normal";
style+=";";
}
if (opt.chpAllCaps!=last_opt.chpAllCaps)
{
style+="text-transform:";
style+=opt.chpAllCaps?"uppercase":"none";
style+=";";
}
if (opt.chpItalic!=last_opt.chpItalic)
{
style+="font-style:";
@ -177,6 +204,10 @@ std::string formatter::format(const formatting_options &_opt)
}
style+=";";
}
if (opt.chpVShift!=last_opt.chpVShift)
{
style += "position:relative;top:" + from_int(opt.chpVShift / 2) + "pt;";
}
if (opt.chpFont!=last_opt.chpFont)
{
style+="font-family:'";
@ -194,7 +225,7 @@ std::string formatter::format(const formatting_options &_opt)
style+=";";
}
opt_stack.push_back(opt);
return result+"<span style=\""+style+"\">";
return result + "<span class=\"" + formatting_options::get_style_id(style) + "\">";
}
std::string formatter::close()

View file

@ -52,14 +52,16 @@ struct font {
};
typedef std::map<int, font> fontmap;
typedef std::map<std::string, std::string> strmap;
struct formatting_options
{
static strmap styles;
enum halign {align_left, align_right, align_center, align_justify, align_error};
enum valign {va_normal, va_sub, va_sup};
bool chpBold, chpItalic, chpUnderline;
bool chpBold, chpAllCaps, chpItalic, chpUnderline;
valign chpVAlign;
int chpFontSize, chpHighlight;
int chpFontSize, chpHighlight, chpVShift;
color chpFColor, chpBColor;
font chpFont;
int papLeft, papRight, papFirst;
@ -68,20 +70,22 @@ struct formatting_options
bool papInTbl;
formatting_options()
{
chpBold=chpItalic=chpUnderline=false;
chpBold=chpAllCaps=chpItalic=chpUnderline=false;
chpVAlign=va_normal;
chpFontSize=chpHighlight=0;
chpFontSize=chpHighlight=chpVShift=0;
papLeft=papRight=papFirst=papBefore=papAfter=0;
papAlign=align_left;
papInTbl=false;
}
bool operator==(const formatting_options &opt) // tests only for character options
{
return chpBold==opt.chpBold && chpItalic==opt.chpItalic
return chpBold==opt.chpBold && chpAllCaps == opt.chpAllCaps
&& chpItalic==opt.chpItalic
&& chpUnderline==opt.chpUnderline && chpVAlign==opt.chpVAlign
&& chpFontSize==opt.chpFontSize
&& chpFColor==opt.chpFColor && chpBColor==opt.chpBColor
&& chpHighlight==opt.chpHighlight && chpFont==opt.chpFont;
&& chpHighlight==opt.chpHighlight && chpFont==opt.chpFont
&& chpVShift==opt.chpVShift;
}
bool operator!=(const formatting_options &opt) // tests only for character options
{
@ -89,17 +93,21 @@ struct formatting_options
}
formatting_options &operator=(const formatting_options &opt)
{
chpBold=opt.chpBold; chpItalic=opt.chpItalic;
chpBold=opt.chpBold; chpAllCaps=opt.chpAllCaps;
chpItalic=opt.chpItalic;
chpUnderline=opt.chpUnderline; chpVAlign=opt.chpVAlign;
chpFontSize=opt.chpFontSize;
chpFColor=opt.chpFColor; chpBColor=opt.chpBColor;
chpHighlight=opt.chpHighlight; chpFont=opt.chpFont;
chpVShift=opt.chpVShift;
papLeft=opt.papLeft; papRight=opt.papRight;
papFirst=opt.papFirst; papBefore=opt.papBefore; papAfter=opt.papAfter;
papAlign=opt.papAlign; papInTbl=opt.papInTbl;
return *this;
}
std::string get_par_str() const;
static std::string get_style_id(const std::string &style);
static std::string get_styles();
};
typedef std::stack<formatting_options> fo_stack;

View file

@ -17,24 +17,24 @@
*/
/* <EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RTF <20> HTML, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
Copyright (C) 2003 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, vlavrinenko@users.sourceforge.net
/* Это конвертер RTF в HTML, реализованный, в принципе, как текстовый фильтр.
Copyright (C) 2003 Валентин Лавриненко, vlavrinenko@users.sourceforge.net
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD>/<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GNU,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Free Software Foundation.
Данная библиотека является свободным программным обеспечением. Вы
вправе распространять ее и/или модифицировать в соответствии с условиями
версии 2.1 либо по вашему выбору с условиями более поздней версии
Стандартной Общественной Лицензии Ограниченного Применения GNU,
опубликованной Free Software Foundation.
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GNU.
Мы распространяем эту библиотеку в надежде на то, что она будет вам
полезной, однако НЕ ПРЕДОСТАВЛЯЕМ НА НЕЕ НИКАКИХ ГАРАНТИЙ, в том числе
ГАРАНТИИ ТОВАРНОГО СОСТОЯНИЯ ПРИ ПРОДАЖЕ и ПРИГОДНОСТИ ДЛЯ ИСПОЛЬЗОВАНИЯ
В КОНКРЕТНЫХ ЦЕЛЯХ. Для получения более подробной информации ознакомьтесь
со Стандартной Общественной Лицензией Ограниченного Применений GNU.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GNU. <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Free Software Foundation, Inc., 59 Temple
Вместе с данной библиотекой вы должны были получить экземпляр Стандартной
Общественной Лицензии Ограниченного Применения GNU. Если вы его не
получили, сообщите об этом во Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.
*/
@ -87,29 +87,15 @@ QString rtf2html(const QString& iString)
{
rtf_keyword kw(++buf_in);
if (kw.is_control_char())
{
switch (kw.control_char())
{
case '\\': case '{': case '}':
par_html.write(kw.control_char());
break;
case '\'':
{
std::string stmp(1,*buf_in++);
stmp+=*buf_in++;
int code=std::strtol(stmp.c_str(), NULL, 16);
switch (code)
{
case 167:
par_html.write("&bull;");
break;
case 188:
par_html.write("&hellip;");
break;
default:
par_html.write((char)code);
}
par_html.write(char_by_code(buf_in));
break;
}
case '*':
bAsterisk=true;
break;
@ -117,27 +103,38 @@ QString rtf2html(const QString& iString)
par_html.write("&nbsp;");
break;
}
}
else //kw.is_control_char
{
if (bAsterisk)
{
bAsterisk=false;
skip_group(buf_in);
cur_options=foStack.top();
foStack.pop();
}
else
{
switch (kw.keyword())
{
case rtf_keyword::rkw_filetbl:
case rtf_keyword::rkw_unicode:
{
char buf[128];
sprintf(buf,"&#%d;",kw.parameter());
par_html.write(buf);
break;
}
case rtf_keyword::rkw_filetbl:
case rtf_keyword::rkw_stylesheet:
case rtf_keyword::rkw_header:
case rtf_keyword::rkw_footer: case rtf_keyword::rkw_headerf:
case rtf_keyword::rkw_header:
case rtf_keyword::rkw_footer: case rtf_keyword::rkw_headerf:
case rtf_keyword::rkw_footerf: case rtf_keyword::rkw_pict:
case rtf_keyword::rkw_object:
// we'll skip such groups
skip_group(buf_in);
break;
// document title
case rtf_keyword::rkw_info:
case rtf_keyword::rkw_info:
{
int depth=1;
bool in_title=false;
@ -149,13 +146,24 @@ QString rtf2html(const QString& iString)
case '\\':
{
rtf_keyword kw1(++buf_in);
if (kw1.keyword()==rtf_keyword::rkw_title)
if (in_title && kw1.is_control_char() && kw1.control_char() == '\'')
title += char_by_code(buf_in);
else if (kw1.keyword()==rtf_keyword::rkw_title)
in_title=true;
break;
}
case '{': ++depth; ++buf_in; break;
case '}': --depth; ++buf_in; in_title=false; break;
default: if (in_title) title+=*buf_in; ++buf_in; break;
case '{':
++depth; ++buf_in;
break;
case '}':
--depth; ++buf_in;
in_title=false;
break;
default:
if (in_title)
title += *buf_in;
++buf_in;
break;
}
}
break;
@ -200,9 +208,9 @@ QString rtf2html(const QString& iString)
break;
}
// font table
case rtf_keyword::rkw_fonttbl:
case rtf_keyword::rkw_fonttbl:
{
font fnt;
font fnt;
int font_num;
bool full_name=false;
bool in_font=false;
@ -277,7 +285,7 @@ QString rtf2html(const QString& iString)
}
// special characters
case rtf_keyword::rkw_line: case rtf_keyword::rkw_softline:
par_html.write("<br/>");
par_html.write("<br>");
break;
case rtf_keyword::rkw_tab:
par_html.write("&nbsp;&nbsp;"); // maybe, this can be done better
@ -309,7 +317,7 @@ QString rtf2html(const QString& iString)
case rtf_keyword::rkw_rdblquote:
par_html.write("&rdquo;");
break;
// paragraph formatting
// paragraph formatting
case rtf_keyword::rkw_ql:
cur_options.papAlign=formatting_options::align_left;
break;
@ -351,7 +359,7 @@ QString rtf2html(const QString& iString)
{
html+=t_str;
}
else
else
{
if (cur_options.papInTbl)
{
@ -381,6 +389,9 @@ QString rtf2html(const QString& iString)
case rtf_keyword::rkw_b:
cur_options.chpBold=!(kw.parameter()==0);
break;
case rtf_keyword::rkw_caps:
cur_options.chpAllCaps=!(kw.parameter()==0);
break;
case rtf_keyword::rkw_i:
cur_options.chpItalic=!(kw.parameter()==0);
break;
@ -393,6 +404,12 @@ QString rtf2html(const QString& iString)
case rtf_keyword::rkw_fs:
cur_options.chpFontSize=kw.parameter();
break;
case rtf_keyword::rkw_dn:
cur_options.chpVShift = kw.parameter() == -1 ? 6 : kw.parameter();
break;
case rtf_keyword::rkw_up:
cur_options.chpVShift = kw.parameter() == -1 ? -6 : -kw.parameter();
break;
case rtf_keyword::rkw_cf:
cur_options.chpFColor=colortbl[kw.parameter()];
break;
@ -406,8 +423,8 @@ QString rtf2html(const QString& iString)
cur_options.chpFont=fonttbl[kw.parameter()];
break;
case rtf_keyword::rkw_plain:
cur_options.chpBold=cur_options.chpItalic
=cur_options.chpUnderline=false;
cur_options.chpBold=cur_options.chpAllCaps
=cur_options.chpItalic=cur_options.chpUnderline=false;
cur_options.chpVAlign=formatting_options::va_normal;
cur_options.chpFontSize=cur_options.chpHighlight=0;
cur_options.chpFColor=cur_options.chpBColor=color();
@ -417,8 +434,8 @@ QString rtf2html(const QString& iString)
case rtf_keyword::rkw_intbl:
cur_options.papInTbl=true;
break;
case rtf_keyword::rkw_trowd:
CurCellDefs=CellDefsList.insert(CellDefsList.end(),
case rtf_keyword::rkw_trowd:
CurCellDefs=CellDefsList.insert(CellDefsList.end(),
table_cell_defs());
// fall through
case rtf_keyword::rkw_row:
@ -503,6 +520,7 @@ QString rtf2html(const QString& iString)
break;
}
}
}
break;
}
case '{':

View file

@ -6,6 +6,7 @@ rtf_keyword::keyword_map::keyword_map() : base_class()
insert(value_type("blue", rkw_blue));
insert(value_type("brdrnone", rkw_brdrnone));
insert(value_type("bullet", rkw_bullet));
insert(value_type("caps", rkw_caps));
insert(value_type("cb", rkw_cb));
insert(value_type("cell", rkw_cell));
insert(value_type("cellx", rkw_cellx));
@ -20,6 +21,7 @@ rtf_keyword::keyword_map::keyword_map() : base_class()
insert(value_type("clvmgf", rkw_clvmgf));
insert(value_type("clvmrg", rkw_clvmrg));
insert(value_type("colortbl", rkw_colortbl));
insert(value_type("dn", rkw_dn));
insert(value_type("emdash", rkw_emdash));
insert(value_type("emspace", rkw_emspace));
insert(value_type("endash", rkw_endash));
@ -83,6 +85,8 @@ rtf_keyword::keyword_map::keyword_map() : base_class()
insert(value_type("trrh", rkw_trrh));
insert(value_type("ul", rkw_ul));
insert(value_type("ulnone", rkw_ulnone));
insert(value_type("up", rkw_up));
insert(value_type("u", rkw_unicode));
}
rtf_keyword::keyword_map rtf_keyword::keymap;

View file

@ -1,39 +1,39 @@
#ifndef __RTF_KEYWORD_H__
#define __RTF_KEYWORD_H__
#include "config.h"
#include <string>
#include <cstdlib>
#include <map>
#include <ctype.h>
#include <stdlib.h>
class rtf_keyword{
public:
enum keyword_type {rkw_unknown,
rkw_b, rkw_bin, rkw_blue, rkw_brdrnone, rkw_bullet,
rkw_cb, rkw_cell, rkw_cellx, rkw_cf, rkw_clbrdrb, rkw_clbrdrl,
rkw_clbrdrr, rkw_clbrdrt, rkw_clvertalb, rkw_clvertalc,
rkw_clvertalt, rkw_clvmgf, rkw_clvmrg, rkw_colortbl,
rkw_caps, rkw_cb, rkw_cell, rkw_cellx, rkw_cf, rkw_clbrdrb, rkw_clbrdrl,
rkw_clbrdrr, rkw_clbrdrt, rkw_clvertalb, rkw_clvertalc,
rkw_clvertalt, rkw_clvmgf, rkw_clvmrg, rkw_colortbl,
rkw_dn,
rkw_emdash, rkw_emspace, rkw_endash, rkw_enspace,
rkw_fi, rkw_field, rkw_filetbl,
rkw_fi, rkw_field, rkw_filetbl,
rkw_f, rkw_fprq, rkw_fcharset,
rkw_fnil, rkw_froman, rkw_fswiss, rkw_fmodern,
rkw_fnil, rkw_froman, rkw_fswiss, rkw_fmodern,
rkw_fscript, rkw_fdecor, rkw_ftech, rkw_fbidi,
rkw_fldrslt, rkw_fonttbl, rkw_footer, rkw_footerf, rkw_fs,
rkw_green,
rkw_header, rkw_headerf, rkw_highlight,
rkw_i, rkw_info, rkw_intbl,
rkw_i, rkw_info, rkw_intbl,
rkw_ldblquote, rkw_li, rkw_line, rkw_lquote,
rkw_margl,
rkw_object,
rkw_paperw, rkw_par, rkw_pard, rkw_pict, rkw_plain,
rkw_qc, rkw_qj, rkw_ql, rkw_qmspace, rkw_qr,
rkw_paperw, rkw_par, rkw_pard, rkw_pict, rkw_plain,
rkw_qc, rkw_qj, rkw_ql, rkw_qmspace, rkw_qr,
rkw_rdblquote, rkw_red, rkw_ri, rkw_row, rkw_rquote,
rkw_sa, rkw_sb, rkw_sect, rkw_softline, rkw_stylesheet,
rkw_sub, rkw_super,
rkw_tab, rkw_title, rkw_trleft, rkw_trowd, rkw_trrh,
rkw_ul, rkw_ulnone
rkw_sa, rkw_sb, rkw_sect, rkw_softline, rkw_stylesheet,
rkw_sub, rkw_super,
rkw_tab, rkw_title, rkw_trleft, rkw_trowd, rkw_trrh,
rkw_ul, rkw_ulnone, rkw_up, rkw_unicode
};
private:
class keyword_map : public std::map<std::string, keyword_type>
@ -91,8 +91,7 @@ rtf_keyword::rtf_keyword(InputIter &iter)
if (param_str.empty())
param=-1;
else
// param=std::atoi(param_str.c_str());
param=atoi(param_str.c_str());
param=std::atoi(param_str.c_str());
if (curchar==' ')
++iter;
keyword_map::iterator kw_pos=keymap.find(s_keyword);

View file

@ -71,7 +71,7 @@ std::string table::make()
{
if ((*row)->CellDefs->size()!=(*row)->Cells.size())
throw std::logic_error("Number of Cells and number of CellDefs are unequal!");
for (cell_def=(*row)->CellDefs->begin(), cell=(*row)->Cells.begin();
for (cell_def=(*row)->CellDefs->begin(), cell=(*row)->Cells.begin();
cell!=(*row)->Cells.end();
++cell, prev_cell_def=cell_def++
)
@ -82,15 +82,13 @@ std::string table::make()
(*cell_def)->Left=(*prev_cell_def)->Right;
if ((*cell_def)->FirstMerged)
{
for (span_row=row, ++span_row; span_row!=end();
for (span_row=row, ++span_row; span_row!=end();
++span_row)
{
cell_def_2=
std::find_if((*span_row)->CellDefs->begin(),
(*span_row)->CellDefs->end(),
std::bind2nd(
std::mem_fun(&table_cell_def::right_equals),
(*cell_def)->Right));
[cell_def](table_cell_def* def) { return def->right_equals((*cell_def)->Right); });
if (cell_def_2==(*span_row)->CellDefs->end())
break;
if (!(*cell_def_2)->Merged)
@ -113,7 +111,7 @@ std::string table::make()
result+=from_int(std::distance(pts.begin(), pt));
result+="></td>";
}
for (cell_def=(*row)->CellDefs->begin(), cell=(*row)->Cells.begin();
for (cell_def=(*row)->CellDefs->begin(), cell=(*row)->Cells.begin();
cell!=(*row)->Cells.end(); ++cell, ++cell_def)
{
ptp=pts.find((*cell_def)->Right);
@ -139,9 +137,7 @@ std::string table::make()
cell_def_2=
std::find_if((*row2)->CellDefs->begin(),
(*row2)->CellDefs->end(),
std::bind2nd(
std::mem_fun(&table_cell_def::right_equals),
left));
[left](table_cell_def* def) { return def->right_equals(left); } );
if (cell_def_2!=(*row2)->CellDefs->end())
{
bleft=bleft && (*cell_def_2)->BorderRight;
@ -149,9 +145,7 @@ std::string table::make()
cell_def_2=
std::find_if((*row2)->CellDefs->begin(),
(*row2)->CellDefs->end(),
std::bind2nd(
std::mem_fun(&table_cell_def::left_equals),
right));
[right](table_cell_def* def) { return def->left_equals(right); } );
if (cell_def_2!=(*row2)->CellDefs->end())
{
bright=bright && (*cell_def_2)->BorderLeft;
@ -200,7 +194,7 @@ std::string table::make()
result+=" valign=bottom";
break;
case table_cell_def::valign_center:
break;
break;
}
result+=">";

View file

@ -8,6 +8,9 @@
template <class InputIter>
void skip_group(InputIter &iter);
template <class InputIter>
std::string char_by_code(InputIter &iter);
/****************************************
function assumes that file pointer points AFTER the opening brace
@ -43,4 +46,27 @@ void skip_group(InputIter &iter)
}
}
template <class InputIter>
std::string char_by_code(InputIter &iter)
{
std::string stmp(1, *iter++);
stmp += *iter++;
int code = std::strtol(stmp.c_str(), NULL, 16);
switch (code)
{
case 0x3f:
return std::string();
case 147:
return "&ldquo;";
case 148:
return "&rdquo;";
case 167:
return "&sect;";
case 188:
return "&frac14;";
default:
return std::string(1, (char)code); //(std::string("&#") + from_int(code) + ";");
}
}
#endif