Skip to content

Commit 616b13b

Browse files
authored
Merge pull request #107 from pkb/docx
docx and FB3 formats support (for QT only)
2 parents d6e9ef1 + fea0fbc commit 616b13b

File tree

19 files changed

+4182
-10
lines changed

19 files changed

+4182
-10
lines changed

cr3gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ elseif ( ${GUI} STREQUAL CRGUI_QT )
9797

9898
SET(CR3_SOURCES ${CR3_SOURCES} src/cr3qt.cpp)
9999
SET (EXTRA_LIBS ${QT_LIBRARIES} ${STD_LIBS} )
100+
SET(CR3_STYLES ${CR3_STYLES} data/fb3.css)
100101

101102
INSTALL( FILES ${CR3_STYLES} DESTINATION root/crengine)
102103
INSTALL( DIRECTORY data/hyph/ DESTINATION root/crengine/hyph

cr3qt/data/docx.css

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
body { text-align: left; margin: 0; text-indent: 0px }
2+
3+
p { $def.all }
4+
5+
empty-line { height: 1em }
6+
7+
a { display: inline; $link.all }
8+
a[type="note"] { $footnote-link.all }
9+
10+
image { text-align: center; text-indent: 0px; display: block }
11+
p image { display: inline }
12+
li image { display: inline }
13+
14+
li { display: list-item; text-indent: 0em; }
15+
ol { display: block; list-style-type: decimal; margin-left: 1em }
16+
17+
.h1, .h2 {
18+
$title.all
19+
}
20+
21+
.h3, .h4, .h5, .h6 {
22+
$subtitle.all
23+
}
24+
25+
.h1, .h2, .h3, .h4, .h5, .h6 {
26+
hyphenate: none;
27+
}
28+
29+
.h1, .h2, .h3, .h4, .h5, .h6 {
30+
display: block;
31+
margin-top: 0.5em;
32+
margin-bottom: 0.3em;
33+
padding: 10px ;
34+
margin-top: 0.5em;
35+
margin-bottom: 0.5em;
36+
}
37+
.h1, .h2 {
38+
page-break-inside: avoid;
39+
page-break-after: avoid;
40+
}
41+
42+
.h3, .h4, .h5, .h6 {
43+
page-break-inside: avoid;
44+
page-break-after: avoid;
45+
}
46+
47+
.h1 { font-size: 150% }
48+
.h2 { font-size: 140% }
49+
.h3 { font-size: 130% }
50+
.h4 { font-size: 120% }
51+
.h5 { font-size: 110% }
52+
53+
table { font-size: 80% }
54+
td, th { text-indent: 0px; padding: 3px }
55+
th { font-weight: bold; text-align: center; background-color: #DDD }
56+
/* #808080; */
57+
table caption { text-indent: 0px; padding: 4px; background-color: #EEE }
58+
59+
body[name="notes"] { $footnote.all }
60+
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; }
61+
body[name="notes"] section title p { display: inline }
62+
63+
body[name="comments"] { $footnote.all }
64+
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; }
65+
body[name="comments"] section title p { display: inline }
66+
67+
description { display: block; }
68+
title-info { display: block; }
69+
annotation { $annotation.all }
70+
date { display: block; font-size: 80%; font-style: italic; text-align: center }
71+
genre { display: none; }
72+
author { display: none; }
73+
book-title { display: none; }
74+
keywords { display: none; }
75+
lang { display: none; }
76+
src-lang { display: none; }
77+
translator { display: none; }
78+
document-info { display: none; }
79+
publish-info { display: none; }
80+
custom-info { display: none; }
81+
coverpage { display: none }
82+
83+
strong,em,u,s,sub,sup {
84+
display: inline;
85+
}
86+
87+
sub { vertical-align: sub; font-size: 70% }
88+
sup { vertical-align: super; font-size: 70% }
89+
90+
strong { font-weight: bold }
91+
em { font-style: italic }
92+
93+
u { text-decoration: underline; }
94+
s { text-decoration: line-through; }
95+
96+
97+
img {
98+
margin: 0.5em;
99+
text-align: center;
100+
text-indent: 0em;
101+
border-style: solid;
102+
border-width: medium;
103+
}

cr3qt/data/fb3.css

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
body { text-align: left; margin: 0; text-indent: 0px }
2+
3+
p { $def.all }
4+
5+
empty-line { height: 1em }
6+
7+
hr { height: 1px; background-color: #808080; margin-top: 0.5em; margin-bottom: 0.5em; /* 2px */ }
8+
9+
a { display: inline; $link.all }
10+
a[type="note"] { $footnote-link.all }
11+
12+
image { text-align: center; text-indent: 0px; display: block }
13+
p image { display: inline }
14+
li image { display: inline }
15+
16+
li { display: list-item; text-indent: 0em; }
17+
ul { display: block; list-style-type: disc; margin-left: 1em }
18+
ol { display: block; list-style-type: decimal; margin-left: 1em }
19+
20+
v { text-align: left; text-align-last: right; text-indent: 1em hanging }
21+
22+
stanza { $poem.all }
23+
stanza + stanza { margin-top: 1em; }
24+
poem { margin-top: 1em; margin-bottom: 1em; text-indent: 0px }
25+
text-author { $text-author.all }
26+
27+
epigraph, epigraph p { $epigraph.all }
28+
cite, cite p { $cite.all }
29+
30+
title p, h1 p, h2 p {
31+
$title.all
32+
}
33+
34+
subtitle, subtitle p, h3 p, h4 p, h5 p, h6 p {
35+
$subtitle.all
36+
}
37+
38+
title, h1, h2, h3, h4, h5, h6, subtitle {
39+
hyphenate: none;
40+
}
41+
42+
h1, h2, h3, h4, h5, h6 {
43+
display: block;
44+
margin-top: 0.5em;
45+
margin-bottom: 0.3em;
46+
padding: 10px ;
47+
margin-top: 0.5em;
48+
margin-bottom: 0.5em;
49+
}
50+
title, h1, h2 {
51+
page-break-before: always;
52+
page-break-inside: avoid;
53+
page-break-after: avoid;
54+
}
55+
ol title, ul title {
56+
page-break-before: auto;
57+
}
58+
subtitle, h3, h4, h5, h6 {
59+
page-break-inside: avoid;
60+
page-break-after: avoid;
61+
}
62+
h1 { font-size: 150% }
63+
h2 { font-size: 140% }
64+
h3 { font-size: 130% }
65+
h4 { font-size: 120% }
66+
h5 { font-size: 110% }
67+
68+
table { font-size: 80% }
69+
td, th { text-indent: 0px; padding: 3px }
70+
th { font-weight: bold; text-align: center; background-color: #DDD }
71+
/* #808080; */
72+
table caption { text-indent: 0px; padding: 4px; background-color: #EEE }
73+
74+
tt, samp, kbd, code, pre { font-family: "Courier New", "Courier", monospace; }
75+
code, pre {
76+
display: block;
77+
white-space: pre;
78+
$pre.all
79+
}
80+
81+
body[name="notes"] { $footnote.all }
82+
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; }
83+
body[name="notes"] section title p { display: inline }
84+
85+
body[name="comments"] { $footnote.all }
86+
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; }
87+
body[name="comments"] section title p { display: inline }
88+
89+
description { display: block; }
90+
title-info { display: block; }
91+
annotation { $annotation.all }
92+
date { display: block; font-size: 80%; font-style: italic; text-align: center }
93+
genre { display: none; }
94+
author { display: none; }
95+
book-title { display: none; }
96+
keywords { display: none; }
97+
lang { display: none; }
98+
src-lang { display: none; }
99+
translator { display: none; }
100+
document-info { display: none; }
101+
publish-info { display: none; }
102+
custom-info { display: none; }
103+
coverpage { display: none }
104+
105+
head, form, script { display: none; }
106+
107+
b,strong,i,em,dfn,var,q,u,underline,del,s,strike,small,big,sub,sup,acronym,tt,sa mp,kbd,code {
108+
display: inline;
109+
}
110+
111+
spacing { display: inline; letter-spacing: 5px }
112+
113+
sub { vertical-align: sub; font-size: 70% }
114+
sup { vertical-align: super; font-size: 70% }
115+
116+
strong, b { font-weight: bold }
117+
emphasis, i, em, dfn, var { font-style: italic }
118+
u,underline { text-decoration: underline; }
119+
del, s, strike, strikethrough { text-decoration: line-through; }
120+
121+
small { font-size: 80%; }
122+
big { font-size: 130%; }
123+
124+
nobr { display: inline; hyphenate: none; white-space: nowrap; }
125+
126+
dl { margin-left: 0em; }
127+
dt { display: block; margin-left: 0em; margin-top:0.3em; font-weight: bold; }
128+
dd { display: block; margin-left: 1.3em; }
129+
130+
img {
131+
margin: 0.5em;
132+
text-align: center;
133+
text-indent: 0em;
134+
border-style: solid;
135+
border-width: medium;
136+
}

cr3qt/src/cr3widget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,9 @@ void CR3View::OnLoadFileFormatDetected( doc_format_t fileFormat )
12321232
case doc_format_txt:
12331233
filename = "txt.css";
12341234
break;
1235+
case doc_format_fb3:
1236+
filename = "fb3.css";
1237+
break;
12351238
case doc_format_rtf:
12361239
filename = "rtf.css";
12371240
break;
@@ -1244,6 +1247,9 @@ void CR3View::OnLoadFileFormatDetected( doc_format_t fileFormat )
12441247
case doc_format_doc:
12451248
filename = "doc.css";
12461249
break;
1250+
case doc_format_docx:
1251+
filename = "docx.css";
1252+
break;
12471253
case doc_format_chm:
12481254
filename = "chm.css";
12491255
break;

cr3qt/src/mainwindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,12 @@ void MainWindow::on_actionOpen_triggered()
231231
}
232232
QString fileName = QFileDialog::getOpenFileName(this, tr("Open book file"),
233233
lastPath,
234-
QString(tr("All supported formats")) + QString(" (*.fb2 *.txt *.tcr *.rtf *.doc *.epub *.html *.shtml *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;")
234+
QString(tr("All supported formats")) + QString(" (*.fb2 *.fb3 *.txt *.tcr *.rtf *.doc *.docx *.epub *.html *.shtml *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;")
235235
+ QString(tr("FB2 books")) + QString(" (*.fb2 *.fb2.zip);;")
236+
+ QString(tr("FB3 books")) + QString(" (*.fb3);;")
236237
+ QString(tr("Text files")) + QString(" (*.txt);;")
237238
+ QString(tr("Rich text")) + QString(" (*.rtf);;")
238-
+ QString(tr("MS Word document")) + QString(" (*.doc);;")
239+
+ QString(tr("MS Word document")) + QString(" (*.doc *.docx);;")
239240
+ QString(tr("HTML files")) + QString(" (*.shtml *.htm *.html);;")
240241
+ QString(tr("EPUB files")) + QString(" (*.epub);;")
241242
+ QString(tr("CHM files")) + QString(" (*.chm);;")

crengine/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ if ( NOT ${GUI} STREQUAL FB2PROPS )
4444
src/chmfmt.cpp
4545
src/epubfmt.cpp
4646
src/pdbfmt.cpp
47-
src/wordfmt.cpp
47+
src/wordfmt.cpp
48+
src/lvopc.cpp
49+
src/docxfmt.cpp
50+
src/fb3fmt.cpp
4851
src/crconcurrent.cpp
4952
src/private/lvbasefont.cpp
5053
src/private/lvbitmapfont.cpp

crengine/include/bookformats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
typedef enum {
88
doc_format_none,
99
doc_format_fb2,
10+
doc_format_fb3,
1011
doc_format_txt,
1112
doc_format_rtf,
1213
doc_format_epub,
1314
doc_format_html,
1415
doc_format_txt_bookmark, // coolreader TXT format bookmark
1516
doc_format_chm,
1617
doc_format_doc,
18+
doc_format_docx,
1719
doc_format_pdb,
1820
doc_format_max = doc_format_pdb
1921
// don't forget update getDocFormatName() when changing this enum

crengine/include/docxfmt.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef DOCXFMT_H
2+
#define DOCXFMT_H
3+
4+
#include "../include/crsetup.h"
5+
#include "../include/lvtinydom.h"
6+
7+
8+
bool DetectDocXFormat( LVStreamRef stream );
9+
bool ImportDocXDocument( LVStreamRef stream, ldomDocument * doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback );
10+
11+
#endif // DOCXFMT_H

crengine/include/fb3fmt.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef FB3FMT_H
2+
#define FB3FMT_H
3+
4+
#include "../include/crsetup.h"
5+
#include "../include/lvtinydom.h"
6+
7+
bool DetectFb3Format( LVStreamRef stream );
8+
bool ImportFb3Document( LVStreamRef stream, ldomDocument * doc, LVDocViewCallback * progressCallback, CacheLoadingCallback * formatCallback );
9+
10+
#endif // FB3FMT_H

0 commit comments

Comments
 (0)