[go: up one dir, main page]

Menu

[80c337]: / qtextdocumentlobs.cpp  Maximize  Restore  History

Download this file

87 lines (78 with data), 2.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "qtextdocumentlobs.h"
const Lob StandardFrameSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"StandardFrame\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
const Lob TableFrameSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"TableFrame\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
const Lob BlockSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"Block\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
const Lob charFormatSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"charFormat\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
const Lob blockFormatSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"blockFormat\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
const Lob listFormatSym ()
{
static Lob result = Lob::fromXML( "<OMS name=\"listFormat\" cd=\"LurchUI\"/>" ).child().copy();
return result.copy();
}
bool isBlock ( Lob L )
{
return ( L.nodeType() == OmApplicationType ) && ( L.child().equivalentTo( BlockSym() ) );
}
bool isFrame ( Lob L )
{
return ( L.nodeType() == OmApplicationType )
&& ( ( L.child().equivalentTo( StandardFrameSym() ) )
|| ( L.child().equivalentTo( TableFrameSym() ) ) );
}
bool isText ( Lob L )
{
return L.nodeType() == OmStringType;
}
bool isListItem ( Lob L )
{
return isBlock( L ) && L.hasAttribute( listFormatSym() );
}
void normalize ( Lob L )
{
int n = (int)L.numChildren();
if ( isBlock( L ) ) {
for ( uint i = 1 ; i < L.numChildren() ; ) { // see conditional i++ below
Lob Li = L.child( i );
Lob Lj = L.child( i + 1 );
if ( isText( Li ) && isText( Lj )
&& Li.attribute( charFormatSym() ).equivalentTo(
Lj.attribute( charFormatSym() ), true ) ) {
Lob newLi = Lob::fromXML( "<OMSTR>"
+ escapeXML( Li.toVariant().toString()
+ Lj.toVariant().toString() )
+ "</OMSTR>" ).child();
foreach ( Lob key, Lj.attributeKeys() )
newLi.setAttribute( key, Li.attribute( key ) );
foreach ( Lob key, Li.attributeKeys() )
newLi.setAttribute( key, Li.attribute( key ) );
Li.set( newLi );
Lj.remove();
} else {
i++; // see for(;;) with missing final clause above
}
}
} else {
for ( int i = 0 ; i < n ; i++ )
normalize( L.child( i ) );
}
}