fb2read.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. #include <QtGui>
  2. #include <QTextEdit>
  3. #include <QtDebug>
  4. #include "fb2read.h"
  5. //---------------------------------------------------------------------------
  6. // Fb2ReadThread
  7. //---------------------------------------------------------------------------
  8. Fb2ReadThread::Fb2ReadThread(QObject *parent, const QString &filename)
  9. : QThread(parent)
  10. , m_document(NULL)
  11. , m_filename(filename)
  12. , m_abort(false)
  13. {
  14. }
  15. Fb2ReadThread::~Fb2ReadThread()
  16. {
  17. stop();
  18. wait();
  19. if (m_document) delete m_document;
  20. }
  21. QTextDocument * Fb2ReadThread::doc()
  22. {
  23. QMutexLocker locker(&mutex);
  24. Q_UNUSED(locker);
  25. return m_document ? m_document->clone() : NULL;
  26. }
  27. const QString & Fb2ReadThread::file()
  28. {
  29. QMutexLocker locker(&mutex);
  30. Q_UNUSED(locker);
  31. return m_filename;
  32. }
  33. void Fb2ReadThread::stop()
  34. {
  35. QMutexLocker locker(&mutex);
  36. Q_UNUSED(locker);
  37. m_abort = true;
  38. }
  39. void Fb2ReadThread::run()
  40. {
  41. QFile file(m_filename);
  42. if (!file.open(QFile::ReadOnly | QFile::Text)) {
  43. qCritical() << tr("Cannot read file %1:\n%2.").arg(m_filename).arg(file.errorString());
  44. return;
  45. }
  46. m_document = new QTextDocument();
  47. Fb2Handler handler(*m_document);
  48. QXmlSimpleReader reader;
  49. reader.setContentHandler(&handler);
  50. reader.setErrorHandler(&handler);
  51. QXmlInputSource source(&file);
  52. bool ok = reader.parse(source);
  53. m_document->moveToThread(QApplication::instance()->thread());
  54. if (ok) emit sendDocument();
  55. }
  56. //---------------------------------------------------------------------------
  57. // Fb2Handler::BaseHandler
  58. //---------------------------------------------------------------------------
  59. #define FB2_BEGIN_KEYHASH(x) \
  60. Fb2Handler::x::Keyword Fb2Handler::x::toKeyword(const QString &name) \
  61. { \
  62. static const KeywordHash map; \
  63. KeywordHash::const_iterator i = map.find(name); \
  64. return i == map.end() ? None : i.value(); \
  65. } \
  66. Fb2Handler::x::KeywordHash::KeywordHash() {
  67. #define FB2_END_KEYHASH }
  68. static QString Value(const QXmlAttributes &attributes, const QString &name)
  69. {
  70. int count = attributes.count();
  71. for (int i = 0; i < count; i++ ) {
  72. if (attributes.localName(i).compare(name, Qt::CaseInsensitive) == 0) {
  73. return attributes.value(i);
  74. }
  75. }
  76. return QString();
  77. }
  78. Fb2Handler::BaseHandler::~BaseHandler()
  79. {
  80. if (m_handler) delete m_handler;
  81. }
  82. bool Fb2Handler::BaseHandler::doStart(const QString &name, const QXmlAttributes &attributes)
  83. {
  84. if (m_handler) return m_handler->doStart(name, attributes);
  85. m_handler = NewTag(name, attributes); if (m_handler) return true;
  86. // qCritical() << QObject::tr("Unknown XML child tag: <%1> <%2>").arg(m_name).arg(name);
  87. m_handler = new BaseHandler(name);
  88. return true;
  89. }
  90. bool Fb2Handler::BaseHandler::doText(const QString &text)
  91. {
  92. if (m_handler) m_handler->doText(text); else TxtTag(text);
  93. return true;
  94. }
  95. bool Fb2Handler::BaseHandler::doEnd(const QString &name, bool & exists)
  96. {
  97. if (m_handler) {
  98. bool found = exists || name == m_name;
  99. m_handler->doEnd(name, found);
  100. if (m_handler->m_closed) { delete m_handler; m_handler = NULL; }
  101. if (found) { exists = true; return true; }
  102. }
  103. bool found = name == m_name;
  104. if (!found) qCritical() << QObject::tr("Conglict XML tags: <%1> - </%2>").arg(m_name).arg(name);
  105. m_closed = found || exists;
  106. if (m_closed) EndTag(m_name);
  107. exists = found;
  108. return true;
  109. }
  110. //---------------------------------------------------------------------------
  111. // Fb2Handler::RootHandler
  112. //---------------------------------------------------------------------------
  113. FB2_BEGIN_KEYHASH(RootHandler)
  114. insert("stylesheet", Style);
  115. insert("description", Descr);
  116. insert("body", Body);
  117. insert("binary", Binary);
  118. FB2_END_KEYHASH
  119. Fb2Handler::RootHandler::RootHandler(QTextDocument &document, const QString &name)
  120. : BaseHandler(name)
  121. , m_document(document)
  122. , m_cursor1(&document, false)
  123. , m_empty(true)
  124. {
  125. m_cursor1.beginEditBlock();
  126. }
  127. Fb2Handler::RootHandler::~RootHandler()
  128. {
  129. QTextBlockFormat blockFormat;
  130. blockFormat.setTopMargin(6);
  131. blockFormat.setBottomMargin(6);
  132. m_cursor1.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
  133. m_cursor1.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
  134. m_cursor1.mergeBlockFormat(blockFormat);
  135. m_cursor1.endEditBlock();
  136. }
  137. Fb2Handler::BaseHandler * Fb2Handler::RootHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  138. {
  139. switch (toKeyword(name)) {
  140. case Body : { BaseHandler * handler = new BodyHandler(m_cursor1, name); m_empty = false; return handler; }
  141. case Descr : return new DescrHandler(name);
  142. case Binary : return new BinaryHandler(m_document, name, attributes);
  143. default: return NULL;
  144. }
  145. }
  146. //---------------------------------------------------------------------------
  147. // Fb2Handler::DescrHandler
  148. //---------------------------------------------------------------------------
  149. Fb2Handler::BaseHandler * Fb2Handler::DescrHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  150. {
  151. Q_UNUSED(name);
  152. Q_UNUSED(attributes);
  153. return new BaseHandler(name);
  154. }
  155. //---------------------------------------------------------------------------
  156. // Fb2Handler::TextHandler
  157. //---------------------------------------------------------------------------
  158. Fb2Handler::TextHandler::TextHandler(Fb2TextCursor &cursor, const QString &name)
  159. : BaseHandler(name)
  160. , m_cursor(cursor)
  161. , m_blockFormat(m_cursor.blockFormat())
  162. , m_charFormat(m_cursor.charFormat())
  163. {
  164. }
  165. Fb2Handler::TextHandler::TextHandler(TextHandler &parent, const QString &name)
  166. : BaseHandler(name)
  167. , m_cursor(parent.m_cursor)
  168. , m_blockFormat(m_cursor.blockFormat())
  169. , m_charFormat(m_cursor.charFormat())
  170. {
  171. }
  172. Fb2Handler::BaseHandler * Fb2Handler::TextHandler::NewTag(const QString & name, const QXmlAttributes &attributes)
  173. {
  174. return BaseHandler::NewTag(name, attributes);
  175. }
  176. void Fb2Handler::TextHandler::EndTag(const QString &name)
  177. {
  178. Q_UNUSED(name);
  179. cursor().setCharFormat(m_charFormat);
  180. }
  181. //---------------------------------------------------------------------------
  182. // Fb2Handler::BodyHandler
  183. //---------------------------------------------------------------------------
  184. FB2_BEGIN_KEYHASH(BodyHandler)
  185. insert("image", Image);
  186. insert("title", Title);
  187. insert("epigraph", Epigraph);
  188. insert("section", Section);
  189. insert("p", Paragraph);
  190. insert("poem", Poem);
  191. insert("stanza", Stanza);
  192. insert("v", Verse);
  193. FB2_END_KEYHASH
  194. Fb2Handler::BodyHandler::BodyHandler(Fb2TextCursor &cursor, const QString &name)
  195. : TextHandler(cursor, name)
  196. , m_feed(false)
  197. {
  198. }
  199. Fb2Handler::BaseHandler * Fb2Handler::BodyHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  200. {
  201. switch (toKeyword(name)) {
  202. case Paragraph : return new BlockHandler(*this, name, attributes);
  203. case Image : return new ImageHandler(*this, name, attributes);
  204. case Section : return new SectionHandler(*this, name, attributes);
  205. case Title : return new TitleHandler(*this, name, attributes);
  206. case Poem : return new SectionHandler(*this, name, attributes);
  207. case Stanza : return new SectionHandler(*this, name, attributes);
  208. default: return NULL;
  209. }
  210. }
  211. //---------------------------------------------------------------------------
  212. // Fb2Handler::SectionHandler
  213. //---------------------------------------------------------------------------
  214. FB2_BEGIN_KEYHASH(SectionHandler)
  215. insert("title", Title);
  216. insert("epigraph", Epigraph);
  217. insert("image", Image);
  218. insert("annotation", Annotation);
  219. insert("section", Section);
  220. insert("p", Paragraph);
  221. insert("poem", Poem);
  222. insert("subtitle", Subtitle);
  223. insert("cite", Cite);
  224. insert("empty-line", Emptyline);
  225. insert("table", Table);
  226. FB2_END_KEYHASH
  227. Fb2Handler::SectionHandler::SectionHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
  228. : TextHandler(parent, name)
  229. , m_frame(cursor().currentFrame())
  230. , m_feed(false)
  231. {
  232. Q_UNUSED(attributes);
  233. QTextFrameFormat frameFormat;
  234. frameFormat.setBorder(1);
  235. frameFormat.setPadding(8);
  236. frameFormat.setTopMargin(4);
  237. frameFormat.setBottomMargin(4);
  238. if (name == "title") frameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 80));
  239. cursor().insertFrame(frameFormat);
  240. }
  241. Fb2Handler::BaseHandler * Fb2Handler::SectionHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  242. {
  243. Keyword keyword = toKeyword(name);
  244. switch (keyword) {
  245. case Paragraph:
  246. case Emptyline:
  247. case Image:
  248. case Title:
  249. if (m_feed) cursor().insertBlock();
  250. m_feed = true;
  251. break;
  252. default:
  253. m_feed = false;
  254. }
  255. switch (keyword) {
  256. case Emptyline : return new BaseHandler(name); break;
  257. case Paragraph : return new BlockHandler(*this, name, attributes); break;
  258. case Section : return new SectionHandler(*this, name, attributes); break;
  259. case Title : return new TitleHandler(*this, name, attributes); break;
  260. case Poem : return new PoemHandler(*this, name, attributes); break;
  261. case Image : return new ImageHandler(*this, name, attributes); break;
  262. default : return new UnknowHandler(*this, name); break;
  263. }
  264. ;
  265. }
  266. void Fb2Handler::SectionHandler::EndTag(const QString &name)
  267. {
  268. Q_UNUSED(name);
  269. if (m_frame) cursor().setPosition(m_frame->lastPosition());
  270. }
  271. //---------------------------------------------------------------------------
  272. // Fb2Handler::TitleHandler
  273. //---------------------------------------------------------------------------
  274. FB2_BEGIN_KEYHASH(TitleHandler)
  275. insert("p", Paragraph);
  276. insert("empty-line", Emptyline);
  277. FB2_END_KEYHASH
  278. Fb2Handler::TitleHandler::TitleHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
  279. : TextHandler(parent, name)
  280. , m_frame(cursor().currentFrame())
  281. , m_table(NULL)
  282. , m_feed(false)
  283. {
  284. Q_UNUSED(attributes);
  285. QTextTableFormat tableFormat;
  286. tableFormat.setBorder(0);
  287. tableFormat.setCellPadding(4);
  288. tableFormat.setCellSpacing(0);
  289. tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
  290. m_table = cursor().insertTable(1, 1, tableFormat);
  291. QTextTableCellFormat cellFormat;
  292. cellFormat.setBackground(Qt::darkGreen);
  293. cellFormat.setForeground(Qt::white);
  294. m_table->cellAt(cursor()).setFormat(cellFormat);
  295. QTextBlockFormat blockFormat;
  296. blockFormat.setAlignment(Qt::AlignHCenter);
  297. cursor().mergeBlockFormat(blockFormat);
  298. }
  299. Fb2Handler::BaseHandler * Fb2Handler::TitleHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  300. {
  301. if (m_feed) cursor().insertBlock(); else m_feed = true;
  302. switch (toKeyword(name)) {
  303. case Paragraph : return new BlockHandler(*this, name, attributes); break;
  304. case Emptyline : return new BlockHandler(*this, name, attributes); break;
  305. default : return new UnknowHandler(*this, name); break;
  306. }
  307. }
  308. void Fb2Handler::TitleHandler::EndTag(const QString &name)
  309. {
  310. Q_UNUSED(name);
  311. if (m_frame) cursor().setPosition(m_frame->lastPosition());
  312. }
  313. //---------------------------------------------------------------------------
  314. // Fb2Handler::PoemHandler
  315. //---------------------------------------------------------------------------
  316. FB2_BEGIN_KEYHASH(PoemHandler)
  317. insert("title", Title);
  318. insert("epigraph", Epigraph);
  319. insert("stanza", Stanza);
  320. insert("author", Author);
  321. insert("date", Date);
  322. FB2_END_KEYHASH
  323. Fb2Handler::PoemHandler::PoemHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
  324. : TextHandler(parent, name)
  325. , m_frame(cursor().currentFrame())
  326. , m_table(NULL)
  327. , m_feed(false)
  328. {
  329. Q_UNUSED(attributes);
  330. QTextTableFormat format;
  331. format.setBorder(1);
  332. format.setCellPadding(4);
  333. format.setCellSpacing(4);
  334. format.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
  335. m_table = cursor().insertTable(1, 1, format);
  336. }
  337. Fb2Handler::BaseHandler * Fb2Handler::PoemHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  338. {
  339. switch (toKeyword(name)) {
  340. case Title:
  341. case Epigraph:
  342. case Stanza:
  343. case Author:
  344. if (m_feed) m_table->appendRows(1);
  345. m_feed = true;
  346. return new StanzaHandler(*this, name, attributes);
  347. default:
  348. return NULL;
  349. }
  350. }
  351. void Fb2Handler::PoemHandler::EndTag(const QString &name)
  352. {
  353. Q_UNUSED(name);
  354. if (m_frame) cursor().setPosition(m_frame->lastPosition());
  355. }
  356. //---------------------------------------------------------------------------
  357. // Fb2Handler::StanzaHandler
  358. //---------------------------------------------------------------------------
  359. FB2_BEGIN_KEYHASH(StanzaHandler)
  360. insert("title", Title);
  361. insert("subtitle", Subtitle);
  362. insert("v", Verse);
  363. FB2_END_KEYHASH
  364. Fb2Handler::StanzaHandler::StanzaHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
  365. : TextHandler(parent, name)
  366. , m_feed(false)
  367. {
  368. Q_UNUSED(attributes);
  369. }
  370. Fb2Handler::BaseHandler * Fb2Handler::StanzaHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  371. {
  372. Keyword keyword = toKeyword(name);
  373. switch (keyword) {
  374. case Title:
  375. case Subtitle:
  376. case Verse:
  377. if (m_feed) cursor().insertBlock();
  378. m_feed = true;
  379. default: ;
  380. }
  381. switch (keyword) {
  382. case Title:
  383. case Subtitle : return new TitleHandler(*this, name, attributes);
  384. case Verse : return new BlockHandler(*this, name, attributes);
  385. default: return NULL;
  386. }
  387. }
  388. //---------------------------------------------------------------------------
  389. // Fb2Handler::BlockHandler
  390. //---------------------------------------------------------------------------
  391. FB2_BEGIN_KEYHASH(BlockHandler)
  392. insert("strong" , Strong);
  393. insert("emphasis" , Emphasis);
  394. insert("style" , Style);
  395. insert("a" , Anchor);
  396. insert("strikethrough" , Strike);
  397. insert("sub" , Sub);
  398. insert("sup" , Sup);
  399. insert("code" , Code);
  400. insert("image" , Image);
  401. FB2_END_KEYHASH
  402. Fb2Handler::BlockHandler::BlockHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes, QTextCharFormat * format)
  403. : TextHandler(parent, name)
  404. {
  405. Q_UNUSED(attributes);
  406. if (format) cursor().mergeCharFormat(*format);
  407. }
  408. Fb2Handler::BaseHandler * Fb2Handler::BlockHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  409. {
  410. Q_UNUSED(attributes);
  411. QTextCharFormat format;
  412. switch (toKeyword(name)) {
  413. case Image : return new ImageHandler(*this, name, attributes);
  414. case Strong : format.setFontWeight(QFont::Bold); break;
  415. case Emphasis : format.setFontItalic(true); break;
  416. case Strike : format.setFontStrikeOut(true); break;
  417. case Sub : format.setVerticalAlignment(QTextCharFormat::AlignSubScript); break;
  418. case Sup : format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); break;
  419. case Anchor : {
  420. QString href = Value(attributes, "href");
  421. if (!href.isEmpty()) {
  422. format.setAnchorHref(href);
  423. format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
  424. }
  425. } break;
  426. default:
  427. return new UnknowHandler(*this, name); break;
  428. }
  429. return new BlockHandler(*this, name, attributes, &format);
  430. }
  431. void Fb2Handler::BlockHandler::TxtTag(const QString &text)
  432. {
  433. cursor().insertText(text);
  434. }
  435. //---------------------------------------------------------------------------
  436. // Fb2Handler::ImageHandler
  437. //---------------------------------------------------------------------------
  438. Fb2Handler::ImageHandler::ImageHandler(TextHandler &parent, const QString &name, const QXmlAttributes &attributes)
  439. : TextHandler(parent, name)
  440. {
  441. QString image = Value(attributes, "href");
  442. while (image.left(1) == "#") image.remove(0, 1);
  443. if (!image.isEmpty()) cursor().insertImage(image);
  444. }
  445. Fb2Handler::BaseHandler * Fb2Handler::ImageHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  446. {
  447. Q_UNUSED(name);
  448. Q_UNUSED(attributes);
  449. return false;
  450. }
  451. //---------------------------------------------------------------------------
  452. // Fb2Handler::UnknowHandler
  453. //---------------------------------------------------------------------------
  454. Fb2Handler::UnknowHandler::UnknowHandler(TextHandler &parent, const QString &name)
  455. : TextHandler(parent, name)
  456. , m_parent(parent)
  457. {
  458. }
  459. Fb2Handler::BaseHandler * Fb2Handler::UnknowHandler::NewTag(const QString &name, const QXmlAttributes &attributes)
  460. {
  461. return m_parent.NewTag(name, attributes);
  462. }
  463. void Fb2Handler::UnknowHandler::TxtTag(const QString &text)
  464. {
  465. cursor().insertText(text);
  466. }
  467. //---------------------------------------------------------------------------
  468. // Fb2Handler::BinaryHandler
  469. //---------------------------------------------------------------------------
  470. Fb2Handler::BinaryHandler::BinaryHandler(QTextDocument &document, const QString &name, const QXmlAttributes &attributes)
  471. : BaseHandler(name)
  472. , m_document(document)
  473. , m_file(Value(attributes, "id"))
  474. {
  475. }
  476. void Fb2Handler::BinaryHandler::TxtTag(const QString &text)
  477. {
  478. m_text += text;
  479. }
  480. void Fb2Handler::BinaryHandler::EndTag(const QString &name)
  481. {
  482. Q_UNUSED(name);
  483. QByteArray in; in.append(m_text);
  484. QImage img = QImage::fromData(QByteArray::fromBase64(in));
  485. if (!m_file.isEmpty()) m_document.addResource(QTextDocument::ImageResource, QUrl(m_file), img);
  486. }
  487. //---------------------------------------------------------------------------
  488. // Fb2Handler
  489. //---------------------------------------------------------------------------
  490. Fb2Handler::Fb2Handler(QTextDocument & document)
  491. : m_document(document)
  492. , m_handler(NULL)
  493. {
  494. document.clear();
  495. }
  496. Fb2Handler::~Fb2Handler()
  497. {
  498. if (m_handler) delete m_handler;
  499. }
  500. bool Fb2Handler::startElement(const QString & namespaceURI, const QString & localName, const QString &qName, const QXmlAttributes &attributes)
  501. {
  502. Q_UNUSED(namespaceURI);
  503. Q_UNUSED(localName);
  504. const QString name = qName.toLower();
  505. if (m_handler) return m_handler->doStart(name, attributes);
  506. qCritical() << name;
  507. if (name == "fictionbook") {
  508. m_handler = new RootHandler(m_document, name);
  509. return true;
  510. } else {
  511. m_error = QObject::tr("The file is not an FB2 file.");
  512. return false;
  513. }
  514. }
  515. static bool isWhiteSpace(const QString &str)
  516. {
  517. return str.simplified().isEmpty();
  518. }
  519. bool Fb2Handler::characters(const QString &str)
  520. {
  521. QString s = str.simplified();
  522. if (s.isEmpty()) return true;
  523. if (isWhiteSpace(str.left(1))) s.prepend(" ");
  524. if (isWhiteSpace(str.right(1))) s.append(" ");
  525. return m_handler && m_handler->doText(s);
  526. }
  527. bool Fb2Handler::endElement(const QString & namespaceURI, const QString & localName, const QString &qName)
  528. {
  529. Q_UNUSED(namespaceURI);
  530. Q_UNUSED(localName);
  531. bool found = false;
  532. return m_handler && m_handler->doEnd(qName.toLower(), found);
  533. }
  534. bool Fb2Handler::fatalError(const QXmlParseException &exception)
  535. {
  536. qCritical() << QObject::tr("Parse error at line %1, column %2:\n%3")
  537. .arg(exception.lineNumber())
  538. .arg(exception.columnNumber())
  539. .arg(exception.message());
  540. return false;
  541. }
  542. QString Fb2Handler::errorString() const
  543. {
  544. return m_error;
  545. }
  546. #undef FB2_BEGIN_KEYHASH
  547. #undef FB2_END_KEYHASH