[PATCH] RTF: underline and other stuff
Nicolas Goutte
nicog at snafu.de
Wed Jul 24 21:12:40 BST 2002
The patch is for the directory filters/kword/rtf/import
I have tried to fix the loading of AbiWord's test file rtftest.rtf.
Changes:
- support advanced underline modes (thick, dot, dash dot, dash dot dot.)
- support conditional hyphen
- do not generate control characters under 32 (apart TAB, LF, CR.)
While working on the underline modes, I have found a bug in KWord, which does
not respect the dot and dash-dot modes. (Bug reported, number pending.)
I have found another bug, this time more in the filter and in the file that I
have tested. The problem is the sequence (in a \uc1 context )
\u8164\'20
The filter does not recognised the Unicode character value and tries to
generated a control character outside XML's valid characters. The sequence 20
is already considered as normal text.
Have a nice day/evening/night!
-------------- next part --------------
Index: rtfimport.cpp
===================================================================
RCS file: /home/kde/koffice/filters/kword/rtf/import/rtfimport.cpp,v
retrieving revision 1.24
diff -u -r1.24 rtfimport.cpp
--- rtfimport.cpp 2002/07/23 09:11:00 1.24
+++ rtfimport.cpp 2002/07/24 19:48:54
@@ -72,6 +72,7 @@
PROP( 0L, "|", insertSymbol, 0L, 0x00b7 ),
PROP( 0L, "}", insertSymbol, 0L, '}' ),
PROP( 0L, "~", insertSymbol, 0L, 0x00a0 ),
+ PROP( 0L, "-", insertSymbol, 0L, 0x00ad ),
PROP( 0L, "ansicpg", setCodepage, 0L, 0 ),
MEMBER( 0L, "b", setToggleProperty, state.format.bold, 0 ),
MEMBER( "@colortbl", "blue", setNumericProperty, blue, 0 ),
@@ -206,9 +207,13 @@
MEMBER( 0L, "u", insertUnicodeSymbol, state.format.uc, 0 ),
MEMBER( 0L, "uc", setNumericProperty, state.format.uc, 0 ),
MEMBER( 0L, "ul", setToggleProperty, state.format.underline, 0 ),
- MEMBER( 0L, "uld", setFlagProperty, state.format.underline, true ),
+ MEMBER( 0L, "uld", setFlagProperty, state.format.underlineDot, true ),
+ MEMBER( 0L, "uldash", setFlagProperty, state.format.underlineDash, true ),
+ MEMBER( 0L, "uldashd", setFlagProperty, state.format.underlineDashDot, true ),
+ MEMBER( 0L, "uldashdd", setFlagProperty, state.format.underlineDashDotDot, true ),
MEMBER( 0L, "uldb", setFlagProperty, state.format.underlined, true ),
MEMBER( 0L, "ulnone", setFlagProperty, state.format.underline, false ),
+ MEMBER( 0L, "ulth", setFlagProperty, state.format.underlineThick, true ),
MEMBER( 0L, "ulw", setFlagProperty, state.format.underline, true ),
MEMBER( 0L, "up", setUpProperty, state.format.baseline, 6 ),
MEMBER( 0L, "v", setToggleProperty, state.format.hidden, 0 ),
@@ -716,6 +721,11 @@
format.vertAlign = RTFFormat::Normal;
format.underline = false;
format.underlined = false;
+ format.underlineDash = false;
+ format.underlineThick = false;
+ format.underlineDot = false;
+ format.underlineDashDot = false;
+ format.underlineDashDotDot = false;
format.bold = false;
format.italic = false;
format.strike = false;
@@ -948,7 +958,7 @@
token.type = RTFTokenizer::PlainText;
token.text = buf;
- if (ch > 0)
+ if (ch > 31)
{
if (ch > 0x007f)
{
@@ -962,6 +972,14 @@
}
*text++ = ch;
}
+ else
+ {
+ // We have a control character, so we must check if it is XML-compactible
+ if ( ch == 9 || ch == 10 || ch == 13 )
+ *text++ = ch ;
+ else
+ kdWarning() << "RTFImport::insertUTF8: tried to insert control character " << ch << endl;
+ }
*text++ = 0;
(this->*destination.destproc)();
@@ -1787,14 +1805,48 @@
node.setAttribute( "value", format.fmt.italic );
node.closeNode( "ITALIC" );
}
- if (!baseFormat || format.fmt.underline != baseFormat->underline || format.fmt.underlined != baseFormat->underlined)
+ if (!baseFormat || format.fmt.underline != baseFormat->underline
+ || format.fmt.underlined != baseFormat->underlined
+ || format.fmt.underlineDash != baseFormat->underlineDash
+ || format.fmt.underlineThick != baseFormat->underlineThick
+ || format.fmt.underlineDot != baseFormat->underlineDot
+ || format.fmt.underlineDashDot != baseFormat->underlineDashDot
+ || format.fmt.underlineDashDotDot != baseFormat->underlineDashDotDot )
{
node.addNode( "UNDERLINE" );
- QCString st;
+ QCString st,styleline;
st.setNum(format.fmt.underline);
if ( format.fmt.underlined )
st="double";
- node.setAttribute( "value", st );
+ else if ( format.fmt.underlineDash )
+ {
+ st="1";
+ styleline="dash";
+ }
+ else if (format.fmt.underlineThick )
+ {
+ st="single-bold";
+ styleline="solid";
+ }
+ else if (format.fmt.underlineDot )
+ {
+ st="1";
+ styleline="dot"; // ### FIXME: KWord has bug and considers it as DashDot
+ }
+ else if (format.fmt.underlineDashDot )
+ {
+ st="1";
+ styleline="dashdot"; // ### FIXME: KWord has bug mixing Dot and DashDot
+ }
+ else if (format.fmt.underlineDashDotDot )
+ {
+ st="1";
+ styleline="dashdotdot"; // ### FIXME: KWord has bug mixing Dot and DashDot
+ }
+ node.setAttribute( "value", st );
+ if ( !styleline.isEmpty() )
+ node.setAttribute( "styleline", styleline );
+
node.closeNode( "UNDERLINE" );
}
if (!baseFormat || format.fmt.strike != baseFormat->strike || format.fmt.striked != baseFormat->striked)
Index: rtfimport.h
===================================================================
RCS file: /home/kde/koffice/filters/kword/rtf/import/rtfimport.h,v
retrieving revision 1.11
diff -u -r1.11 rtfimport.h
--- rtfimport.h 2002/07/23 09:11:00 1.11
+++ rtfimport.h 2002/07/24 19:48:54
@@ -133,6 +133,7 @@
int color, bgcolor;
int uc;
bool underline, underlined, bold, italic, strike, striked, hidden, caps;
+ bool underlineDash, underlineThick, underlineDot, underlineDashDot, underlineDashDotDot;
};
// Style sheet entry
More information about the kfm-devel
mailing list