#include "GuiDocument.h"
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
parsing
::
xml
;
namespace
document_operation_visitors
{
class
:
public
,
public
::
{
protected
:
<
>
;
public
:
(
<
>
)
:parent(
)
{
}
void
(
<
>
,
*
)
{
if
(
)
{
.
(
);
<
>
=
;
;
FOREACH(Ptr<DocumentRun>, subRun, run->runs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subRun
);)
{
subRun
(
this
);
}
oldParent
;
}
else
{
FOREACH(Ptr<DocumentRun>, subRun, run->runs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subRun
);)
{
subRun
(
this
);
}
}
}
void
(
*
)
override
{
if
(
->
text
!=
L""
)
{
auto
=
(
).
(
L"nop"
);
auto
=
->
text
.
();
auto
=
begin
;
auto
=
reading
;
while
(
true
)
{
const
wchar_t
*
=
nullptr
;
auto
= *
reading
;
switch
(
c
)
{
case
L'\n'
:
tag
=
L"br"
;
break
;
case
L' '
:
tag
=
L"sp"
;
break
;
case
L'\t'
:
tag
=
L"tab"
;
break
;
}
if
(
tag
||
c
==
0
)
{
if
(
reading
>
last
)
{
auto
=
reading
[-
1
] ==
L'\r'
?
reading
-
1
:
reading
;
if
(
end
>
last
)
{
writer
.Text(
->
text
.
(
last
-
begin
,
end
-
last
));
}
last
=
reading
;
}
}
if
(
tag
)
{
writer
.Element(
tag
);
}
else
if
(
c
==
0
)
{
break
;
}
reading
++;
}
}
}
void
(
DocumentStylePropertiesRun
*
)
override
{
<
>
=
->
;
<
>
=
;
if
(
sp
||
sp
||
sp
)
{
<
>
=
new
;
element
.
=
L"font"
;
.
(
element
);
(
element
);
if
(
sp
)
{
writer
.
(
L"face"
,
sp
.
());
}
if
(
sp
)
{
writer
.
(
L"size"
,
sp
.
().
());
}
if
(
sp
)
{
writer
.
(
L"color"
,
sp
.
().
());
}
if
(
sp
)
{
writer
.
(
L"bkcolor"
,
sp
.
().
());
}
element
;
}
if
(
sp
)
{
<
>
=
new
;
element
.
=
sp
.
() ?
L"b"
:
L"b-"
;
.
(
element
);
element
;
}
if
(
sp
)
{
<
>
=
new
;
element
.
=
sp
.
() ?
L"i"
:
L"i-"
;
.
(
element
);
element
;
}
if
(
sp
)
{
<
>
=
new
;
element
.
=
sp
.
() ?
L"u"
:
L"u-"
;
.
(
element
);
element
;
}
if
(
sp
)
{
<
>
=
new
;
element
.
=
sp
.
() ?
L"s"
:
L"s-"
;
.
(
element
);
element
;
}
if
(
sp
||
sp
)
{
bool
=
sp
?
sp
.
() :
true
;
bool
=
sp
?
sp
.
() :
false
;
if
(!
ha
)
{
<
>
=
new
;
element
.
=
L"ha"
;
.
(
element
);
element
;
}
else
if
(!
va
)
{
<
>
=
new
;
element
.
=
L"va"
;
.
(
element
);
element
;
}
else
{
<
>
=
new
;
element
.
=
L"na"
;
.
(
element
);
element
;
}
}
(
0
,
);
oldParent
;
}
void
(
DocumentStyleApplicationRun
*
)
override
{
<
>
=
new
;
element
.
=
L"div"
;
(
element
).
(
L"style"
,
->
);
(
element
,
);
}
void
(
*
)
override
{
<
>
=
new
;
element
.
=
L"a"
;
(
element
);
if
(
->
!=
L"#NormalLink"
)
{
writer
.
(
L"normal"
,
->
);
}
if
(
->
!=
L"#ActiveLink"
)
{
writer
.
(
L"active"
,
->
);
}
if
(
->
!=
L""
)
{
writer
.
(
L"href"
,
->
);
}
(
element
,
);
}
void
(
*
)
override
{
(
);
writer
.
(
L"img"
)
.Attribute(
L"width"
,
(
->
.
))
.Attribute(
L"height"
,
(
->
.
))
.Attribute(
L"baseline"
,
(
->
))
.Attribute(
L"frameIndex"
,
(
->
))
.Attribute(
L"source"
,
->
)
;
}
void
(
DocumentEmbeddedObjectRun
*
)
override
{
(
);
writer
.
(
L"object"
)
.Attribute(
L"name"
,
->
)
;
}
void
(
*
)
override
{
<
>
=
new
;
element
.
=
L"p"
;
(
element
);
if
(
->
)
{
switch
(
->
.
())
{
case
::
:
writer
.
(
L"align"
,
L"Left"
);
break
;
case
::
:
writer
.
(
L"align"
,
L"Center"
);
break
;
case
::
:
writer
.
(
L"align"
,
L"Right"
);
break
;
}
}
(
element
,
);
}
};
}
using
namespace
document_operation_visitors
;
<
parsing
::
xml
::
>
::
()
{
<
>
=
new
;
<
>
=
new
;
doc
.
=
L"Doc"
;
xml
doc
;
{
<
>
=
new
;
content
.
=
L"Content"
;
doc
.
(
content
);
FOREACH(Ptr<DocumentParagraphRun>, p, paragraphs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
p
);)
{
(
content
);
p
(&
visitor
);
}
}
{
<
>
=
new
;
stylesElement
.
=
L"Styles"
;
doc
.
(
stylesElement
);
for
(
=
0
;
i
<
.
();
i
++)
{
=
.
()
i
];
if
(
name
.
()>
0
&&
name
0
] ==
L'#'
&& (
name
.
() <=
9
||
name
.
(
9
) !=
L"-Override"
))
continue
;
<
>
=
.
().
(
i
);
<
>
=
style
;
<
>
=
new
;
styleElement
.
=
L"Style"
;
stylesElement
.
(
styleElement
);
(
styleElement
).
(
L"name"
,
name
);
if
(
style
!=
L""
)
{
(
styleElement
).
(
L"parent"
,
style
);
}
if
(
sp
)
(
styleElement
).
(
L"face"
).Text(
sp
.
() );
if
(
sp
)
(
styleElement
).
(
L"size"
).Text(
sp
.
().
() );
if
(
sp
)
(
styleElement
).
(
L"color"
).Text(
sp
.
().
() );
if
(
sp
)
(
styleElement
).
(
L"bkcolor"
).Text(
sp
.
().
() );
if
(
sp
)
(
styleElement
).
(
L"b"
).Text(
sp
.
()?
L"true"
:
L"false"
);
if
(
sp
)
(
styleElement
).
(
L"i"
).Text(
sp
.
()?
L"true"
:
L"false"
);
if
(
sp
)
(
styleElement
).
(
L"u"
).Text(
sp
.
()?
L"true"
:
L"false"
);
if
(
sp
)
(
styleElement
).
(
L"s"
).Text(
sp
.
()?
L"true"
:
L"false"
);
if
(
sp
&&
sp
)
{
bool
=
sp
;
bool
=
sp
;
if
(!
h
)
{
(
styleElement
).
(
L"antialias"
).Text(
L"no"
);
}
else
if
(!
v
)
{
(
styleElement
).
(
L"antialias"
).Text(
L"horizontal"
);
}
else
{
(
styleElement
).
(
L"antialias"
).Text(
L"vertical"
);
}
}
}
}
return
xml
;
}
}
}