|
|
@@ -336,7 +336,8 @@ bool VExporter::exportToPDFViaWK(VDocument *p_webDocument,
|
|
|
p_styleContent,
|
|
|
p_bodyContent,
|
|
|
true,
|
|
|
- true)) {
|
|
|
+ true,
|
|
|
+ false)) {
|
|
|
pdfExported = -1;
|
|
|
return;
|
|
|
}
|
|
|
@@ -395,7 +396,8 @@ bool VExporter::exportToCustom(VDocument *p_webDocument,
|
|
|
p_styleContent,
|
|
|
p_bodyContent,
|
|
|
true,
|
|
|
- true)) {
|
|
|
+ true,
|
|
|
+ false)) {
|
|
|
exported = -1;
|
|
|
return;
|
|
|
}
|
|
|
@@ -561,7 +563,8 @@ bool VExporter::exportToHTML(VDocument *p_webDocument,
|
|
|
p_styleContent,
|
|
|
p_bodyContent,
|
|
|
p_opt.m_embedCssStyle,
|
|
|
- p_opt.m_completeHTML)) {
|
|
|
+ p_opt.m_completeHTML,
|
|
|
+ p_opt.m_embedImages)) {
|
|
|
htmlExported = -1;
|
|
|
return;
|
|
|
}
|
|
|
@@ -610,6 +613,33 @@ bool VExporter::fixStyleResources(const QString &p_folder,
|
|
|
return altered;
|
|
|
}
|
|
|
|
|
|
+bool VExporter::embedStyleResources(QString &p_html)
|
|
|
+{
|
|
|
+ bool altered = false;
|
|
|
+ QRegExp reg("\\burl\\(\"((file|qrc):[^\"\\)]+)\"\\);");
|
|
|
+
|
|
|
+ int pos = 0;
|
|
|
+ while (pos < p_html.size()) {
|
|
|
+ int idx = p_html.indexOf(reg, pos);
|
|
|
+ if (idx == -1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString dataURI = g_webUtils->dataURI(QUrl(reg.cap(1)));
|
|
|
+ if (dataURI.isEmpty()) {
|
|
|
+ pos = idx + reg.matchedLength();
|
|
|
+ } else {
|
|
|
+ // Replace the url string in html.
|
|
|
+ QString newUrl = QString("url('%1');").arg(dataURI);
|
|
|
+ p_html.replace(idx, reg.matchedLength(), newUrl);
|
|
|
+ pos = idx + newUrl.size();
|
|
|
+ altered = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return altered;
|
|
|
+}
|
|
|
+
|
|
|
bool VExporter::fixBodyResources(const QUrl &p_baseUrl,
|
|
|
const QString &p_folder,
|
|
|
QString &p_html)
|
|
|
@@ -651,6 +681,45 @@ bool VExporter::fixBodyResources(const QUrl &p_baseUrl,
|
|
|
return altered;
|
|
|
}
|
|
|
|
|
|
+bool VExporter::embedBodyResources(const QUrl &p_baseUrl, QString &p_html)
|
|
|
+{
|
|
|
+ bool altered = false;
|
|
|
+ if (p_baseUrl.isEmpty()) {
|
|
|
+ return altered;
|
|
|
+ }
|
|
|
+
|
|
|
+ QRegExp reg("<img ([^>]*)src=\"([^\"]+)\"([^>]*)>");
|
|
|
+
|
|
|
+ int pos = 0;
|
|
|
+ while (pos < p_html.size()) {
|
|
|
+ int idx = p_html.indexOf(reg, pos);
|
|
|
+ if (idx == -1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (reg.cap(2).isEmpty()) {
|
|
|
+ pos = idx + reg.matchedLength();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ QUrl srcUrl(p_baseUrl.resolved(reg.cap(2)));
|
|
|
+ QString dataURI = g_webUtils->dataURI(srcUrl);
|
|
|
+ if (dataURI.isEmpty()) {
|
|
|
+ pos = idx + reg.matchedLength();
|
|
|
+ } else {
|
|
|
+ // Replace the url string in html.
|
|
|
+ QString newUrl = QString("<img %1src='%2'%3>").arg(reg.cap(1))
|
|
|
+ .arg(dataURI)
|
|
|
+ .arg(reg.cap(3));
|
|
|
+ p_html.replace(idx, reg.matchedLength(), newUrl);
|
|
|
+ pos = idx + newUrl.size();
|
|
|
+ altered = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return altered;
|
|
|
+}
|
|
|
+
|
|
|
QString VExporter::getResourceRelativePath(const QString &p_file)
|
|
|
{
|
|
|
int idx = p_file.lastIndexOf('/');
|
|
|
@@ -901,7 +970,8 @@ bool VExporter::outputToHTMLFile(const QString &p_file,
|
|
|
const QString &p_styleContent,
|
|
|
const QString &p_bodyContent,
|
|
|
bool p_embedCssStyle,
|
|
|
- bool p_completeHTML)
|
|
|
+ bool p_completeHTML,
|
|
|
+ bool p_embedImages)
|
|
|
{
|
|
|
QFile file(p_file);
|
|
|
if (!file.open(QFile::WriteOnly)) {
|
|
|
@@ -916,7 +986,7 @@ bool VExporter::outputToHTMLFile(const QString &p_file,
|
|
|
QString html(m_exportHtmlTemplate);
|
|
|
if (!p_styleContent.isEmpty() && p_embedCssStyle) {
|
|
|
QString content(p_styleContent);
|
|
|
- fixStyleResources(resFolderPath, content);
|
|
|
+ embedStyleResources(content);
|
|
|
html.replace(HtmlHolder::c_styleHolder, content);
|
|
|
}
|
|
|
|
|
|
@@ -926,7 +996,12 @@ bool VExporter::outputToHTMLFile(const QString &p_file,
|
|
|
|
|
|
if (p_completeHTML) {
|
|
|
QString content(p_bodyContent);
|
|
|
- fixBodyResources(m_baseUrl, resFolderPath, content);
|
|
|
+ if (p_embedImages) {
|
|
|
+ embedBodyResources(m_baseUrl, content);
|
|
|
+ } else {
|
|
|
+ fixBodyResources(m_baseUrl, resFolderPath, content);
|
|
|
+ }
|
|
|
+
|
|
|
html.replace(HtmlHolder::c_bodyHolder, content);
|
|
|
} else {
|
|
|
html.replace(HtmlHolder::c_bodyHolder, p_bodyContent);
|