#include "GuiDocument.h"
#include "GuiParserManager.h"
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
parsing
::
tabling
;
using
namespace
parsing
::
xml
;
using
namespace
regex
;
namespace
document_operation_visitors
{
class
:
public
::
{
public
:
<
>
;
<
>
;
;
<
>
;
<
>
;
;
::
&
;
(
<
>
,
<
>
,
,
<
>
,
<
>
,
::
&
)
:model(
)
, container(
)
, paragraphIndex(
)
, resource(
)
, resolver(
)
, regexAttributeApply(
L"/{@(<value>[^{}]+)/}"
)
, errors(
)
{
}
void
(
const
&
)
{
<
>
=
new
;
run
;
.
(
run
);
}
void
(
*
)
override
{
(
->
.
);
}
void
(
*
)
override
{
(
->
.
);
}
void
(
*
)
override
{
}
void
(
* )
override
{
}
void
(
*
)
override
{
<
>
;
bool
=
false
;
*
=
;
if
(
->
.
==
L"br"
)
{
(
L"\r\n"
);
}
else
if
(
->
.
==
L"sp"
)
{
(
L" "
);
}
else
if
(
->
.
==
L"tab"
)
{
(
L"\t"
);
}
else
if
(
->
.
==
L"img"
)
{
<
>
=
new
;
run
= -
1
;
if
(
<
>
=
(
,
L"source"
))
{
run
source
.
;
,
;
if
(
(
run
,
protocol
,
path
))
{
<
>
=
(
protocol
,
path
).
<
>();
if
(
imageData
)
{
run
imageData
();
}
if
(
run
&&
run
() >
0
)
{
run
run
(
0
)->
();
run
=
0
;
}
}
FOREACH(Ptr<XmlAttribute>, att, node->attributes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
att
);)
{
if
(
att
.
==
L"width"
)
{
run
.
=
(
att
.
);
}
else
if
(
att
.
==
L"height"
)
{
run
.
=
(
att
.
);
}
else
if
(
att
.
==
L"baseline"
)
{
run
=
(
att
.
);
}
else
if
(
att
.
==
L"frameIndex"
)
{
run
=
(
att
.
);
}
else
if
(
att
.
!=
L"source"
)
{
.
(
({ {
},
att
.
.
},
L"Unknown attribute in <img>: \""
+
att
.
+
L"\"."
));
}
}
.
(
run
);
}
else
{
.
(
({ {
},
->
.
},
L"Attribute \"source\" is missing in <img>."
));
}
}
else
if
(
->
.
==
L"object"
)
{
<
DocumentEmbeddedObjectRun
>
=
new
DocumentEmbeddedObjectRun
;
run
= -
1
;
if
(
auto
=
(
,
L"name"
))
{
run
=
name
->value.value;
.
(
run
);
}
else
{
.
(
({ {
},
->
.
},
L"The \"name\" attribute in <object> is missing."
));
}
}
else
if
(
->
.
==
L"font"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
<
>
=
new
;
run
sp
;
FOREACH(Ptr<XmlAttribute>, att, node->attributes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
att
);)
{
if
(
att
.
==
L"face"
)
{
sp
att
.
;
}
else
if
(
att
.
==
L"size"
)
{
sp
::
(
att
.
);
}
else
if
(
att
.
==
L"color"
)
{
sp
::
(
att
.
);
}
else
if
(
att
.
==
L"bkcolor"
)
{
sp
::
(
att
.
);
}
else
{
.
(
({ {
},
att
.
.
},
L"Unknown attribute in <font>: \""
+
att
.
+
L"\"."
));
}
}
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"b"
||
->
.
==
L"b-"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
=
->
.
==
L"b"
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"i"
||
->
.
==
L"i-"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
=
->
.
==
L"i"
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"u"
||
->
.
==
L"u-"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
=
->
.
==
L"u"
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"s"
||
->
.
==
L"s-"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
=
->
.
==
L"s"
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"ha"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
true
;
run
false
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"va"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
true
;
run
true
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"na"
)
{
<
DocumentStylePropertiesRun
>
=
new
DocumentStylePropertiesRun
();
run
new
;
run
false
;
run
false
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"div"
)
{
if
(
<
>
=
(
,
L"style"
))
{
=
att
.
;
<
DocumentStyleApplicationRun
>
=
new
DocumentStyleApplicationRun
;
run
styleName
;
.
(
run
);
createdContainer
run
;
}
else
{
createdContainer
;
}
}
else
if
(
->
.
==
L"a"
)
{
<
>
=
new
;
run
=
L"#NormalLink"
;
run
=
L"#ActiveLink"
;
if
(
<
>
=
(
,
L"normal"
))
{
run
att
.
;
}
if
(
<
>
=
(
,
L"active"
))
{
run
att
.
;
}
if
(
<
>
=
(
,
L"href"
))
{
run
att
.
;
}
run
run
;
.
(
run
);
createdContainer
run
;
}
else
if
(
->
.
==
L"p"
)
{
FOREACH(Ptr<XmlNode>, sub, node->subNodes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
sub
);)
{
sub
(
this
);
}
}
else
{
if
(
->
.
!=
L"nop"
)
{
.
(
({ {
},
->
.
},
L"Unknown element in <p>: \""
+
->
.
+
L"\"."
));
}
FOREACH(Ptr<XmlNode>, sub, node->subNodes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
sub
);)
{
sub
(
this
);
}
}
if
(
createdContainer
)
{
<
>
=
;
createdContainer
;
FOREACH(Ptr<XmlNode>, subNode, subNodeContainer->subNodes)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
subNodeContainer
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subNode
);)
{
subNode
(
this
);
}
oldContainer
;
}
}
void
(
*
)
override
{
}
void
(
*
)
override
{
}
};
<
>
(
<
>
,
<
>
,
::
&
)
{
<
>
=
new
;
if
(
<
>
=
(
,
L"parent"
))
{
style
parent
.
;
}
<
>
=
new
;
style
sp
;
FOREACH(Ptr<XmlElement>, att, XmlGetElements(styleElement))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
(
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
att
);)
{
if
(
att
.
==
L"face"
)
{
sp
(
att
);
}
else
if
(
att
.
==
L"size"
)
{
sp
::
(
(
att
));
}
else
if
(
att
.
==
L"color"
)
{
sp
::
(
(
att
));
}
else
if
(
att
.
==
L"bkcolor"
)
{
sp
::
(
(
att
));
}
else
if
(
att
.
==
L"b"
)
{
sp
=
(
att
)==
L"true"
;
}
else
if
(
att
.
==
L"i"
)
{
sp
=
(
att
)==
L"true"
;
}
else
if
(
att
.
==
L"u"
)
{
sp
=
(
att
)==
L"true"
;
}
else
if
(
att
.
==
L"s"
)
{
sp
=
(
att
)==
L"true"
;
}
else
if
(
att
.
==
L"antialias"
)
{
=
(
att
);
if
(
value
==
L"horizontal"
||
value
==
L"default"
)
{
sp
true
;
sp
false
;
}
else
if
(
value
==
L"no"
)
{
sp
false
;
sp
false
;
}
else
if
(
value
==
L"vertical"
)
{
sp
true
;
sp
true
;
}
}
else
{
.
(
({ {
},
att
.
},
L"Unknown element in <Style>: \""
+
att
.
+
L"\"."
));
}
}
return
style
;
}
}
using
namespace
document_operation_visitors
;
<
>
::
(
<
>
,
<
parsing
::
xml
::
>
,
<
>
,
::
&
)
{
<
>
=
new
;
if
(
.
==
L"Doc"
)
{
FOREACH(Ptr<XmlElement>, partElement, XmlGetElements(xml->rootElement))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
(
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
partElement
);)
{
if
(
partElement
.
==
L"Styles"
)
{
FOREACH(Ptr<XmlElement>, styleElement, XmlGetElements(partElement))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
(
partElement
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
styleElement
);)
{
if
(
styleElement
.
==
L"Style"
)
{
if
(
<
>
=
(
styleElement
,
L"name"
))
{
auto
=
(
,
styleElement
,
);
auto
=
name
.
;
if
(!
model
.
().
(
styleName
))
{
model
.
(
styleName
,
style
);
if
(
styleName
.
() >
9
&&
styleName
.
(
9
) ==
L"-Override"
)
{
auto
=
<
>();
overridedStyle
new
;
(
overridedStyle
,
style
);
styleName
styleName
.
(
styleName
.
() -
9
);
auto
=
model
.
().
(
styleName
);
if
(
index
== -
1
)
{
model
.
(
styleName
,
overridedStyle
);
}
else
{
auto
=
model
.
()
index
];
(
overridedStyle
,
originalStyle
);
originalStyle
overridedStyle
;
}
}
}
}
else
{
.
(
({ {
},
styleElement
.
},
L"Attribute \"name\" is missing in <Style>."
));
}
}
else
{
.
(
({ {
},
styleElement
.
},
L"Unknown element in <Styles>: \""
+
styleElement
.
+
L"\"."
));
}
}
}
else
if
(
partElement
.
==
L"Content"
)
{
FOREACH_INDEXER(Ptr<XmlElement>, p, i, XmlGetElements(partElement))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
(
partElement
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
p
);
i
++)
{
if
(
p
.
==
L"p"
)
{
<
>
=
new
;
if
(
<
>
=
(
p
,
L"align"
))
{
if
(
att
.
==
L"Left"
)
{
paragraph
::
;
}
else
if
(
att
.
==
L"Center"
)
{
paragraph
::
;
}
else
if
(
att
.
==
L"Right"
)
{
paragraph
::
;
}
else
{
.
(
({ {
},
att
.
.
},
L"Unknown value in align attribute \""
+
att
.
+
L"\"."
));
}
}
model
.
(
paragraph
);
(
model
,
paragraph
,
i
,
,
,
);
p
(&
visitor
);
}
else
{
.
(
({ {
},
p
.
},
L"Unknown element in <Content>: \""
+
p
.
+
L"\"."
));
}
}
}
else
{
.
(
({ {
},
partElement
.
},
L"Unknown element in <Doc>: \""
+
partElement
.
+
L"\"."
));
}
}
}
else
{
.
(
({ {
},
.
},
L"The root element of document should be \"Doc\"."
));
}
return
model
;
}
}
}