| 1 | /* AbiSource |
| 2 | * |
| 3 | * Copyright (C) 2011 Volodymyr Rudyj <[email protected]> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA. |
| 19 | */ |
| 20 | #include "ie_exp_EPUB_EPUB3Writer.h" |
| 21 | |
| 22 | IE_Exp_EPUB_EPUB3Writer::IE_Exp_EPUB_EPUB3Writer(IE_Exp_HTML_OutputWriter* |
| 23 | pOutputWriter): |
| 24 | IE_Exp_HTML_DocumentWriter(pOutputWriter) |
| 25 | { |
| 26 | m_pTagWriter->enableXmlMode(true); |
| 27 | } |
| 28 | |
| 29 | void IE_Exp_EPUB_EPUB3Writer::openDocument() |
| 30 | { |
| 31 | m_pTagWriter->openTag("html", false, false); |
| 32 | m_pTagWriter->addAttribute("xmlns", "http://www.w3.org/1999/xhtml"); |
| 33 | m_pTagWriter->addAttribute("profile", EPUB3_CONTENT_PROFILE); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | void IE_Exp_EPUB_EPUB3Writer::openAnnotation() |
| 38 | { |
| 39 | m_pTagWriter->openTag("a", true); |
| 40 | m_pTagWriter->addAttribute("href", |
| 41 | UT_UTF8String_sprintf("#annotation-%d", |
| 42 | m_iAnnotationCount + 1).utf8_str()); |
| 43 | |
| 44 | m_pTagWriter->addAttribute("epub:type", "annoref"); |
| 45 | } |
| 46 | |
| 47 | void IE_Exp_EPUB_EPUB3Writer::closeAnnotation() |
| 48 | { |
| 49 | m_pTagWriter->closeTag(); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void IE_Exp_EPUB_EPUB3Writer::insertDTD() |
| 54 | { |
| 55 | m_pOutputWriter->write("<?xml version=\"1.0\"?>\n"); |
| 56 | } |
| 57 | |
| 58 | void IE_Exp_EPUB_EPUB3Writer::insertTOC(const gchar * /*title*/, |
| 59 | const std::vector<UT_UTF8String> & /*items*/, |
| 60 | const std::vector<UT_UTF8String> & /*itemUriList*/) |
| 61 | { |
| 62 | |
| 63 | } |
| 64 | |
| 65 | void IE_Exp_EPUB_EPUB3Writer::insertEndnotes( |
| 66 | const std::vector<UT_UTF8String> &endnotes) |
| 67 | { |
| 68 | if (endnotes.size() == 0) return; |
| 69 | |
| 70 | m_pTagWriter->openTag("aside"); |
| 71 | m_pTagWriter->addAttribute("epub:type", "rearnotes"); |
| 72 | |
| 73 | for (size_t i = 0; i < endnotes.size(); i++) |
| 74 | { |
| 75 | m_pTagWriter->openTag("section"); |
| 76 | // m_pTagWriter->addAttribute("class", "endnote_anchor"); |
| 77 | m_pTagWriter->addAttribute("id", UT_UTF8String_sprintf("endnote-%d", |
| 78 | m_iEndnoteAnchorCount + 1).utf8_str()); |
| 79 | m_pTagWriter->addAttribute("epub:type", "rearnote"); |
| 80 | m_pTagWriter->writeData(endnotes.at(i).utf8_str()); |
| 81 | m_pTagWriter->closeTag(); |
| 82 | m_iEndnoteAnchorCount++; |
| 83 | } |
| 84 | |
| 85 | m_pTagWriter->closeTag(); |
| 86 | } |
| 87 | |
| 88 | void IE_Exp_EPUB_EPUB3Writer::insertFootnotes( |
| 89 | const std::vector<UT_UTF8String> &footnotes) |
| 90 | { |
| 91 | if (footnotes.size() == 0) return; |
| 92 | |
| 93 | m_pTagWriter->openTag("aside"); |
| 94 | m_pTagWriter->addAttribute("epub:type", "footnotes"); |
| 95 | for (size_t i = 0; i < footnotes.size(); i++) { |
| 96 | m_pTagWriter->openTag("section"); |
| 97 | // m_pTagWriter->addAttribute("class", "footnote_anchor"); |
| 98 | m_pTagWriter->addAttribute("id", |
| 99 | UT_UTF8String_sprintf("footnote-%d", i + 1).utf8_str()); |
| 100 | m_pTagWriter->addAttribute("epub:type", "footnote"); |
| 101 | m_pTagWriter->writeData(footnotes.at(i).utf8_str()); |
| 102 | m_pTagWriter->closeTag(); |
| 103 | } |
| 104 | m_pTagWriter->closeTag(); |
| 105 | } |
| 106 | |
| 107 | void IE_Exp_EPUB_EPUB3Writer::insertAnnotations( |
| 108 | const std::vector<UT_UTF8String> &titles, |
| 109 | const std::vector<UT_UTF8String> &authors, |
| 110 | const std::vector<UT_UTF8String> &annotations) |
| 111 | { |
| 112 | m_pTagWriter->openTag("section"); |
| 113 | m_pTagWriter->addAttribute("epub:type", "annotations"); |
| 114 | |
| 115 | for(size_t i = 0; i < annotations.size(); i++) |
| 116 | { |
| 117 | UT_UTF8String title = titles.at(i); |
| 118 | UT_UTF8String author = authors.at(i); |
| 119 | UT_UTF8String annotation = annotations.at(i); |
| 120 | |
| 121 | m_pTagWriter->openTag("section"); |
| 122 | // m_pTagWriter->addAttribute("class", "annotation"); |
| 123 | m_pTagWriter->addAttribute("epub:type", "annotation"); |
| 124 | m_pTagWriter->addAttribute("id", UT_UTF8String_sprintf("annotation-%d", |
| 125 | i + 1).utf8_str()); |
| 126 | if (title.length()) |
| 127 | { |
| 128 | m_pTagWriter->openTag("h4"); |
| 129 | m_pTagWriter->writeData(title.utf8_str()); |
| 130 | m_pTagWriter->closeTag(); |
| 131 | } |
| 132 | |
| 133 | /*if (author.length()) |
| 134 | { |
| 135 | m_pTagWriter->openTag("span"); |
| 136 | m_pTagWriter->addAttribute("class", "annotation-author"); |
| 137 | m_pTagWriter->writeData(author.utf8_str()); |
| 138 | m_pTagWriter->closeTag(); |
| 139 | m_pTagWriter->openTag("br", false, true); |
| 140 | m_pTagWriter->closeTag(); |
| 141 | }*/ |
| 142 | |
| 143 | if (annotation.length()) |
| 144 | { |
| 145 | m_pTagWriter->openTag("blockquote"); |
| 146 | // m_pTagWriter->addAttribute("class", "annotation-content"); |
| 147 | m_pTagWriter->writeData(annotation.utf8_str()); |
| 148 | m_pTagWriter->closeTag(); |
| 149 | } |
| 150 | |
| 151 | m_pTagWriter->closeTag(); |
| 152 | } |
| 153 | |
| 154 | m_pTagWriter->closeTag(); |
| 155 | } |
| 156 | |
| 157 | IE_Exp_HTML_DocumentWriter *IE_Exp_EPUB_EPUB3WriterFactory:: |
| 158 | constructDocumentWriter(IE_Exp_HTML_OutputWriter* pOutputWriter) |
| 159 | { |
| 160 | return new IE_Exp_EPUB_EPUB3Writer(pOutputWriter); |
| 161 | } |