Skip to content

Commit

Permalink
Merge pull request #107 from pkb/docx
Browse files Browse the repository at this point in the history
docx and FB3 formats support (for QT only)
  • Loading branch information
buggins committed Oct 15, 2019
2 parents 5e03c29 + a5ec1d5 commit 880e463
Show file tree
Hide file tree
Showing 19 changed files with 4,182 additions and 10 deletions.
1 change: 1 addition & 0 deletions cr3gui/CMakeLists.txt
Expand Up @@ -97,6 +97,7 @@ elseif ( ${GUI} STREQUAL CRGUI_QT )

SET(CR3_SOURCES ${CR3_SOURCES} src/cr3qt.cpp)
SET (EXTRA_LIBS ${QT_LIBRARIES} ${STD_LIBS} )
SET(CR3_STYLES ${CR3_STYLES} data/fb3.css)

INSTALL( FILES ${CR3_STYLES} DESTINATION root/crengine)
INSTALL( DIRECTORY data/hyph/ DESTINATION root/crengine/hyph
Expand Down
103 changes: 103 additions & 0 deletions cr3qt/data/docx.css
@@ -0,0 +1,103 @@
body { text-align: left; margin: 0; text-indent: 0px }

p { $def.all }

empty-line { height: 1em }

a { display: inline; $link.all }
a[type="note"] { $footnote-link.all }

image { text-align: center; text-indent: 0px; display: block }
p image { display: inline }
li image { display: inline }

li { display: list-item; text-indent: 0em; }
ol { display: block; list-style-type: decimal; margin-left: 1em }

.h1, .h2 {
$title.all
}

.h3, .h4, .h5, .h6 {
$subtitle.all
}

.h1, .h2, .h3, .h4, .h5, .h6 {
hyphenate: none;
}

.h1, .h2, .h3, .h4, .h5, .h6 {
display: block;
margin-top: 0.5em;
margin-bottom: 0.3em;
padding: 10px ;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.h1, .h2 {
page-break-inside: avoid;
page-break-after: avoid;
}

.h3, .h4, .h5, .h6 {
page-break-inside: avoid;
page-break-after: avoid;
}

.h1 { font-size: 150% }
.h2 { font-size: 140% }
.h3 { font-size: 130% }
.h4 { font-size: 120% }
.h5 { font-size: 110% }

table { font-size: 80% }
td, th { text-indent: 0px; padding: 3px }
th { font-weight: bold; text-align: center; background-color: #DDD }
/* #808080; */
table caption { text-indent: 0px; padding: 4px; background-color: #EEE }

body[name="notes"] { $footnote.all }
body[name="notes"] section title { display: run-in; text-align: left; $footnote-title.all page-break-before: auto; page-break-inside: auto; page-break-after: auto; }
body[name="notes"] section title p { display: inline }

body[name="comments"] { $footnote.all }
body[name="comments"] section title { display: run-in; text-align: left; $footnote-title.all page-break-before: auto; page-break-inside: auto; page-break-after: auto; }
body[name="comments"] section title p { display: inline }

description { display: block; }
title-info { display: block; }
annotation { $annotation.all }
date { display: block; font-size: 80%; font-style: italic; text-align: center }
genre { display: none; }
author { display: none; }
book-title { display: none; }
keywords { display: none; }
lang { display: none; }
src-lang { display: none; }
translator { display: none; }
document-info { display: none; }
publish-info { display: none; }
custom-info { display: none; }
coverpage { display: none }

strong,em,u,s,sub,sup {
display: inline;
}

sub { vertical-align: sub; font-size: 70% }
sup { vertical-align: super; font-size: 70% }

strong { font-weight: bold }
em { font-style: italic }

u { text-decoration: underline; }
s { text-decoration: line-through; }


img {
margin: 0.5em;
text-align: center;
text-indent: 0em;
border-style: solid;
border-width: medium;
}
136 changes: 136 additions & 0 deletions cr3qt/data/fb3.css
@@ -0,0 +1,136 @@
body { text-align: left; margin: 0; text-indent: 0px }

p { $def.all }

empty-line { height: 1em }

hr { height: 1px; background-color: #808080; margin-top: 0.5em; margin-bottom: 0.5em; /* 2px */ }

a { display: inline; $link.all }
a[type="note"] { $footnote-link.all }

image { text-align: center; text-indent: 0px; display: block }
p image { display: inline }
li image { display: inline }

li { display: list-item; text-indent: 0em; }
ul { display: block; list-style-type: disc; margin-left: 1em }
ol { display: block; list-style-type: decimal; margin-left: 1em }

v { text-align: left; text-align-last: right; text-indent: 1em hanging }

stanza { $poem.all }
stanza + stanza { margin-top: 1em; }
poem { margin-top: 1em; margin-bottom: 1em; text-indent: 0px }
text-author { $text-author.all }

epigraph, epigraph p { $epigraph.all }
cite, cite p { $cite.all }

title p, h1 p, h2 p {
$title.all
}

subtitle, subtitle p, h3 p, h4 p, h5 p, h6 p {
$subtitle.all
}

title, h1, h2, h3, h4, h5, h6, subtitle {
hyphenate: none;
}

h1, h2, h3, h4, h5, h6 {
display: block;
margin-top: 0.5em;
margin-bottom: 0.3em;
padding: 10px ;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
title, h1, h2 {
page-break-before: always;
page-break-inside: avoid;
page-break-after: avoid;
}
ol title, ul title {
page-break-before: auto;
}
subtitle, h3, h4, h5, h6 {
page-break-inside: avoid;
page-break-after: avoid;
}
h1 { font-size: 150% }
h2 { font-size: 140% }
h3 { font-size: 130% }
h4 { font-size: 120% }
h5 { font-size: 110% }

table { font-size: 80% }
td, th { text-indent: 0px; padding: 3px }
th { font-weight: bold; text-align: center; background-color: #DDD }
/* #808080; */
table caption { text-indent: 0px; padding: 4px; background-color: #EEE }

tt, samp, kbd, code, pre { font-family: "Courier New", "Courier", monospace; }
code, pre {
display: block;
white-space: pre;
$pre.all
}

body[name="notes"] { $footnote.all }
body[name="notes"] section title { display: run-in; text-align: left; $footnote-title.all page-break-before: auto; page-break-inside: auto; page-break-after: auto; }
body[name="notes"] section title p { display: inline }

body[name="comments"] { $footnote.all }
body[name="comments"] section title { display: run-in; text-align: left; $footnote-title.all page-break-before: auto; page-break-inside: auto; page-break-after: auto; }
body[name="comments"] section title p { display: inline }

description { display: block; }
title-info { display: block; }
annotation { $annotation.all }
date { display: block; font-size: 80%; font-style: italic; text-align: center }
genre { display: none; }
author { display: none; }
book-title { display: none; }
keywords { display: none; }
lang { display: none; }
src-lang { display: none; }
translator { display: none; }
document-info { display: none; }
publish-info { display: none; }
custom-info { display: none; }
coverpage { display: none }

head, form, script { display: none; }

b,strong,i,em,dfn,var,q,u,underline,del,s,strike,small,big,sub,sup,acronym,tt,sa mp,kbd,code {
display: inline;
}

spacing { display: inline; letter-spacing: 5px }

sub { vertical-align: sub; font-size: 70% }
sup { vertical-align: super; font-size: 70% }

strong, b { font-weight: bold }
emphasis, i, em, dfn, var { font-style: italic }
u,underline { text-decoration: underline; }
del, s, strike, strikethrough { text-decoration: line-through; }

small { font-size: 80%; }
big { font-size: 130%; }

nobr { display: inline; hyphenate: none; white-space: nowrap; }

dl { margin-left: 0em; }
dt { display: block; margin-left: 0em; margin-top:0.3em; font-weight: bold; }
dd { display: block; margin-left: 1.3em; }

img {
margin: 0.5em;
text-align: center;
text-indent: 0em;
border-style: solid;
border-width: medium;
}
6 changes: 6 additions & 0 deletions cr3qt/src/cr3widget.cpp
Expand Up @@ -1232,6 +1232,9 @@ void CR3View::OnLoadFileFormatDetected( doc_format_t fileFormat )
case doc_format_txt:
filename = "txt.css";
break;
case doc_format_fb3:
filename = "fb3.css";
break;
case doc_format_rtf:
filename = "rtf.css";
break;
Expand All @@ -1244,6 +1247,9 @@ void CR3View::OnLoadFileFormatDetected( doc_format_t fileFormat )
case doc_format_doc:
filename = "doc.css";
break;
case doc_format_docx:
filename = "docx.css";
break;
case doc_format_chm:
filename = "chm.css";
break;
Expand Down
5 changes: 3 additions & 2 deletions cr3qt/src/mainwindow.cpp
Expand Up @@ -231,11 +231,12 @@ void MainWindow::on_actionOpen_triggered()
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open book file"),
lastPath,
QString(tr("All supported formats")) + QString(" (*.fb2 *.txt *.tcr *.rtf *.doc *.epub *.html *.shtml *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;")
QString(tr("All supported formats")) + QString(" (*.fb2 *.fb3 *.txt *.tcr *.rtf *.doc *.docx *.epub *.html *.shtml *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;")
+ QString(tr("FB2 books")) + QString(" (*.fb2 *.fb2.zip);;")
+ QString(tr("FB3 books")) + QString(" (*.fb3);;")
+ QString(tr("Text files")) + QString(" (*.txt);;")
+ QString(tr("Rich text")) + QString(" (*.rtf);;")
+ QString(tr("MS Word document")) + QString(" (*.doc);;")
+ QString(tr("MS Word document")) + QString(" (*.doc *.docx);;")
+ QString(tr("HTML files")) + QString(" (*.shtml *.htm *.html);;")
+ QString(tr("EPUB files")) + QString(" (*.epub);;")
+ QString(tr("CHM files")) + QString(" (*.chm);;")
Expand Down
5 changes: 4 additions & 1 deletion crengine/CMakeLists.txt
Expand Up @@ -44,7 +44,10 @@ if ( NOT ${GUI} STREQUAL FB2PROPS )
src/chmfmt.cpp
src/epubfmt.cpp
src/pdbfmt.cpp
src/wordfmt.cpp
src/wordfmt.cpp
src/lvopc.cpp
src/docxfmt.cpp
src/fb3fmt.cpp
src/crconcurrent.cpp
src/private/lvbasefont.cpp
src/private/lvbitmapfont.cpp
Expand Down
2 changes: 2 additions & 0 deletions crengine/include/bookformats.h
Expand Up @@ -7,13 +7,15 @@
typedef enum {
doc_format_none,
doc_format_fb2,
doc_format_fb3,
doc_format_txt,
doc_format_rtf,
doc_format_epub,
doc_format_html,
doc_format_txt_bookmark, // coolreader TXT format bookmark
doc_format_chm,
doc_format_doc,
doc_format_docx,
doc_format_pdb,
doc_format_max = doc_format_pdb
// don't forget update getDocFormatName() when changing this enum
Expand Down
11 changes: 11 additions & 0 deletions crengine/include/docxfmt.h
@@ -0,0 +1,11 @@
#ifndef DOCXFMT_H
#define DOCXFMT_H

#include "../include/crsetup.h"
#include "../include/lvtinydom.h"


bool DetectDocXFormat( LVStreamRef stream );
bool ImportDocXDocument( LVStreamRef stream, ldomDocument * doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback );

#endif // DOCXFMT_H
10 changes: 10 additions & 0 deletions crengine/include/fb3fmt.h
@@ -0,0 +1,10 @@
#ifndef FB3FMT_H
#define FB3FMT_H

#include "../include/crsetup.h"
#include "../include/lvtinydom.h"

bool DetectFb3Format( LVStreamRef stream );
bool ImportFb3Document( LVStreamRef stream, ldomDocument * doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback );

#endif // FB3FMT_H

0 comments on commit 880e463

Please sign in to comment.