#include "GuiDocumentClipboard.h"
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
stream
;
namespace
document_clipboard_visitors
{
class
:
public
,
public
::
{
typedef
::
;
public
:
<
>
;
*
;
&
;
(
*
,
&
)
:model(
)
, writer(
)
{
;
style
.
(
0
,
0
,
0
,
0
);
style
.
(
0
,
0
,
0
,
0
);
style
->
(
::
,
style
);
.
(
style
);
}
void
(
*
)
{
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
);
}
}
(
)
{
auto
=
.
();
if
(
result
.
() ==
9
)
result
result
.
(
7
);
return
result
;
}
void
(
*
)
override
{
=
->
();
if
(
text
.
() >
0
)
{
=
.
() -
1
];
.
(
L"<span style=\""
);
if
(
style
.
.
)
.
(
L"font-weight:bold; "
);
if
(
style
.
.
)
.
(
L"font-style:italic; "
);
if
(
style
.
.
&&
style
.
.
)
.
(
L"text-decoration:underline line-through; "
);
else
if
(
style
.
.
)
.
(
L"text-decoration:underline; "
);
else
if
(
style
.
.
)
.
(
L"text-decoration:line-through; "
);
if
(
style
.
.
!=
L""
)
.
(
L"font-family:"
+
style
.
.
+
L"; "
);
if
(
style
.
.
!=
0
)
.
(
L"font-size:"
+
(
style
.
.
) +
L"px; "
);
if
(
style
.
.
!=
0
)
.
(
L"color:"
+
(
style
.
) +
L"; "
);
if
(
style
.
.
!=
0
)
.
(
L"background-color:"
+
(
style
.
) +
L"; "
);
.
(
L"\">"
);
for
(
=
0
;
i
<
text
.
();
i
++)
{
switch
(
wchar_t
=
text
i
])
{
case
L'&'
:
.
(
L"&"
);
break
;
case
L'<'
:
.
(
L"<"
);
break
;
case
L'>'
:
.
(
L">"
);
break
;
case
L'\r'
:
break
;
case
L'\n'
:
.
(
L"<br>"
);
break
;
case
L' '
:
.
(
L" "
);
break
;
case
L'\t'
:
.
(
L"<pre>\t</pre>"
);
break
;
default
:
.
(
c
);
break
;
}
}
.
(
L"</span>"
);
}
}
void
(
DocumentStylePropertiesRun
*
)
override
{
=
.
() -
1
];
style
->
(
->
,
style
);
.
(
style
);
(
);
.
(
.
() -
1
);
}
void
(
DocumentStyleApplicationRun
*
)
override
{
=
.
() -
1
];
style
->
(
->
,
style
);
.
(
style
);
(
);
.
(
.
() -
1
);
}
void
(
*
)
override
{
.
(
L"<a href=\""
);
for
(
=
0
;
i
<
->
.
();
i
++)
{
switch
(
wchar_t
=
->
i
])
{
case
L'&'
:
.
(
L"&"
);
break
;
case
L'<'
:
.
(
L"<"
);
break
;
case
L'>'
:
.
(
L">"
);
break
;
case
L'"'
:
.
(
L"""
);
break
;
case
L'\''
:
.
(
L"'"
);
break
;
default
:
.
(
c
);
break
;
}
}
.
(
L"\">"
);
=
.
() -
1
];
style
=
->
((
->
==
L""
?
::
:
->
),
style
);
.
(
style
);
(
);
.
(
.
() -
1
);
.
(
L"</a>"
);
}
void
(
*
)
override
{
if
(
->
)
{
.
(
L"<img width=\""
+
(
->
.
) +
L"\" height=\""
+
(
->
.
) +
L"\" src=\"data:image/"
);
auto
=
->
();
if
(
format
==
::
)
{
format
=
::
;
}
switch
(
format
)
{
case
::
:
.
(
L"bmp;base64,"
);
break
;
case
::
:
.
(
L"gif;base64,"
);
break
;
case
::
:
.
(
L"icon;base64,"
);
break
;
case
::
:
.
(
L"jpeg;base64,"
);
break
;
case
::
:
.
(
L"png;base64,"
);
break
;
case
::
:
.
(
L"tiff;base64,"
);
break
;
case
::
:
.
(
L"wmp;base64,"
);
break
;
default
:
.
(
L"unsupported;base64,\"/>"
);
return
;
}
;
->
(
memoryStream
,
format
);
memoryStream
.
(
0
);
while
(
true
)
{
[
3
] = {
0
,
0
,
0
};
=
memoryStream
.
(&
bytes
,
sizeof
(
bytes
));
if
(
read
==
0
)
break
;
=
bytes
[
0
] / (
1
<<
2
);
= ((
bytes
[
0
] % (
1
<<
2
)) <<
4
) +
bytes
[
1
] / (
1
<<
4
);
= ((
bytes
[
1
] % (
1
<<
4
)) <<
2
) +
bytes
[
2
] / (
1
<<
6
);
=
bytes
[
2
] % (
1
<<
6
);
const
wchar_t
*
=
L"ABCDEFG"
L"HIJKLMN"
L"OPQRST"
L"UVWXYZ"
L"abcdefg"
L"hijklmn"
L"opqrst"
L"uvwxyz"
L"0123456789"
L"+/"
;
#define BASE64_CHAR(b) BASE64[b]
switch
(
read
)
{
case
1
:
writer.WriteChar(BASE64_CHAR(b1));
writer.WriteChar(BASE64_CHAR(b2));
.
(
L'='
);
.
(
L'='
);
break
;
case
2
:
writer.WriteChar(BASE64_CHAR(b1));
writer.WriteChar(BASE64_CHAR(b2));
writer.WriteChar(BASE64_CHAR(b3));
.
(
L'='
);
break
;
case
3
:
writer.WriteChar(BASE64_CHAR(b1));
writer.WriteChar(BASE64_CHAR(b2));
writer.WriteChar(BASE64_CHAR(b3));
writer.WriteChar(BASE64_CHAR(b4));
break
;
}
#undef BASE64_CHAR
}
.
(
L"\"/>"
);
}
}
void
(
DocumentEmbeddedObjectRun
*
)
override
{
}
void
(
*
)
override
{
(
);
}
};
}
using
namespace
document_clipboard_visitors
;
#define HTML_LINE(LINE) LINE "\r\n"
void
(
<
>
,
& ,
&
,
& )
{
=
HTML_LINE("<!DOCTYPE html>")
HTML_LINE("<title>GacUI Document 1.0</title>")
"<title>GacUI Document 1.0</title>"
"\r\n"
HTML_LINE("<meta charset=\"utf-8\"/>")
"<meta charset=\"utf-8\"/>"
"\r\n"
;
;
{
;
(
memoryStream
,
encoder
);
(
encoderStream
);
(
.
(),
writer
);
FOREACH(Ptr<DocumentParagraphRun>, paragraph, model->paragraphs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
paragraph
);)
{
writer
.
(
L"<p style=\"text-align:"
);
if
(
paragraph
)
{
switch
(
paragraph
.
())
{
case
::
:
writer
.
(
L"left;"
);
break
;
case
::
:
writer
.
(
L"center;"
);
break
;
case
::
:
writer
.
(
L"right;"
);
break
;
}
}
else
{
writer
.
(
L"left;"
);
}
writer
.
(
L"\">"
);
paragraph
(&
visitor
);
writer
.
(
L"</p>\r\n"
);
}
}
char
=
0
;
memoryStream
.
(&
zero
,
sizeof
(
zero
));
= (
const
char
*)
memoryStream
.
();
=
;
}
void
SaveDocumentToHtmlClipboardStream
(
<
>
,
stream
::
&
)
{
,
, ;
(
,
header
,
content
,
footer
);
char
[] =
HTML_LINE("StartHTML:-1")
HTML_LINE("StartFragment:0000000000")
"StartFragment:0000000000"
"\r\n"
HTML_LINE("EndFragment:0000000000")
"EndFragment:0000000000"
"\r\n"
;
char
[] =
"<!--StartFragment-->"
;
char
[] =
"<!--EndFragment-->"
;
=
sizeof
(
clipboardHeader
) -
1
+
header
.
() +
sizeof
(
commentStart
) -
1
;
=
offsetStart
+
content
.
();
=
(
offsetStart
);
=
(
offsetEnd
);
(
(
clipboardHeader
,
"EndFragment:"
) -
offsetStartString
.
() -
2
,
offsetStartString
.
(),
offsetStartString
.
());
(
clipboardHeader
+
sizeof
(
clipboardHeader
) -
1
-
offsetEndString
.
() -
2
,
offsetEndString
.
(),
offsetEndString
.
());
.
(
clipboardHeader
,
sizeof
(
clipboardHeader
) -
1
);
if
(
header
.
() >
0
)
.
((
void
*)
header
.
(),
header
.
());
.
(
commentStart
,
sizeof
(
commentStart
) -
1
);
if
(
content
.
() >
0
)
.
((
void
*)
content
.
(),
content
.
());
.
(
commentEnd
,
sizeof
(
commentEnd
) -
1
);
if
(
footer
.
() >
0
)
.
((
void
*)
footer
.
(),
footer
.
());
}
#undef HTML_LINE
}
}