Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
KDE:Unstable:Applications
kdegraphics-mobipocket
_service:obs_scm:kdegraphics-mobipocket-VERSION...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8.obscpio of Package kdegraphics-mobipocket
07070100000000000081A40000000000000000000000016627827F00000050000000000000000000000000000000000000004500000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/.gitignore/.clang-format /compile_commands.json .clangd .cache .idea /cmake-build* build* 07070100000001000081A40000000000000000000000016627827F000001B5000000000000000000000000000000000000004900000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/.gitlab-ci.yml# SPDX-FileCopyrightText: None # SPDX-License-Identifier: CC0-1.0 include: - project: sysadmin/ci-utilities file: - /gitlab-templates/android.yml - /gitlab-templates/android-qt6.yml - /gitlab-templates/linux.yml - /gitlab-templates/linux-qt6.yml - /gitlab-templates/freebsd.yml - /gitlab-templates/freebsd-qt6.yml - /gitlab-templates/windows.yml - /gitlab-templates/windows-qt6.yml 07070100000002000081A40000000000000000000000016627827F0000019C000000000000000000000000000000000000004600000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/.kde-ci.yml# SPDX-FileCopyrightText: None # SPDX-License-Identifier: CC0-1.0 Dependencies: - 'on': ['Linux/Qt6', 'FreeBSD/Qt6', 'Windows/Qt6', 'Android/Qt6'] 'require': 'frameworks/extra-cmake-modules': '@latest-kf6' - 'on': ['Linux/Qt5', 'FreeBSD/Qt5', 'Windows/Qt5', 'Android/Qt5'] 'require': 'frameworks/extra-cmake-modules': '@stable' Options: require-passing-tests-on: ['Linux', 'FreeBSD', 'Windows'] 07070100000003000081A40000000000000000000000016627827F00000710000000000000000000000000000000000000004900000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/CMakeLists.txtcmake_minimum_required (VERSION 3.16 FATAL_ERROR) project(mobipocket VERSION 2.1.0) find_package(ECM 5.92.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) include(ECMGenerateExportHeader) include(ECMOptionalAddSubdirectory) include(CMakePackageConfigHelpers) include(ECMSetupVersion) include(ECMDeprecationSettings) set(REQUIRED_QT_VERSION 5.12.0) find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Gui) if(TARGET Qt6::Core) find_package(Qt6 REQUIRED COMPONENTS Core5Compat) endif() if (QT_MAJOR_VERSION STREQUAL "6") set(CMAKECONFIG_NAME "QMobipocket6") else() set(CMAKECONFIG_NAME "QMobipocket") endif() ecm_setup_version(PROJECT VARIABLE_PREFIX QMOBIPOCKET VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/lib/qmobipocket_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_NAME}ConfigVersion.cmake" SOVERSION "2" ) ecm_set_disabled_deprecation_versions( QT 6.4 ) add_subdirectory(lib) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/${CMAKECONFIG_NAME}") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/QMobipocketConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_NAME}Config.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(EXPORT QMobipocketTargets DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE ${CMAKECONFIG_NAME}Targets.cmake ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${CMAKECONFIG_NAME}ConfigVersion.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 07070100000004000081A40000000000000000000000016627827F00004643000000000000000000000000000000000000004200000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/COPYING GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. 07070100000005000081A40000000000000000000000016627827F00000115000000000000000000000000000000000000005500000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/QMobipocketConfig.cmake.in@PACKAGE_INIT@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") find_dependency(Qt@QT_MAJOR_VERSION@Core "@REQUIRED_QT_VERSION@") find_dependency(Qt@QT_MAJOR_VERSION@Gui "@REQUIRED_QT_VERSION@") include("${CMAKE_CURRENT_LIST_DIR}/@CMAKECONFIG_NAME@Targets.cmake") 07070100000006000041ED0000000000000000000000026627827F00000000000000000000000000000000000000000000003E00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib07070100000007000081A40000000000000000000000016627827F000007E7000000000000000000000000000000000000004D00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/CMakeLists.txtif (QT_MAJOR_VERSION STREQUAL "6") set(qmobipocket_INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR}/QMobipocket6) else() set(qmobipocket_INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR}/QMobipocket) endif() add_library(qmobipocket SHARED) set_target_properties(qmobipocket PROPERTIES VERSION ${QMOBIPOCKET_VERSION} SOVERSION ${QMOBIPOCKET_SOVERSION} ) if (QT_MAJOR_VERSION STREQUAL "6") set_target_properties(qmobipocket PROPERTIES LIBRARY_OUTPUT_NAME QMobipocket6 EXPORT_NAME QMobipocket6 ) endif() target_sources( qmobipocket PRIVATE decompressor.cpp mobipocket.cpp qfilestream.cpp ) if (QT_MAJOR_VERSION STREQUAL "5") set(_generate_export_header_version_args) else() # For Qt6/KF6 world transitively include the version header if(ECM_VERSION VERSION_LESS "5.106") set(include_version_header_code "#include <qmobipocket_version.h>\n") set(_generate_export_header_version_args CUSTOM_CONTENT_FROM_VARIABLE include_version_header_code) else() set(_generate_export_header_version_args USE_VERSION_HEADER) endif() endif() ecm_generate_export_header(qmobipocket VERSION ${QMOBIPOCKET_VERSION} DEPRECATED_BASE_VERSION 0 ${_generate_export_header_version_args} ) target_link_libraries (qmobipocket PUBLIC Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Gui ) if(TARGET Qt6::Core5Compat) target_link_libraries(qmobipocket PRIVATE Qt6::Core5Compat) endif() target_include_directories(qmobipocket INTERFACE "$<INSTALL_INTERFACE:${qmobipocket_INCLUDE_INSTALL_DIR}>" ) install(FILES mobipocket.h qfilestream.h ${CMAKE_CURRENT_BINARY_DIR}/qmobipocket_export.h DESTINATION ${qmobipocket_INCLUDE_INSTALL_DIR}/qmobipocket COMPONENT Devel ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmobipocket_version.h DESTINATION ${qmobipocket_INCLUDE_INSTALL_DIR} COMPONENT Devel ) install(TARGETS qmobipocket EXPORT QMobipocketTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) 07070100000008000081A40000000000000000000000016627827F00001B82000000000000000000000000000000000000004F00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/decompressor.cpp/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * RLE decompressor based on FBReader * * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com> * * * * Huffdic decompressor based on Python code by Igor Skochinsky * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "decompressor.h" #include "mobipocket.h" #include <QList> static const unsigned char TOKEN_CODE[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; namespace Mobipocket { class NOOPDecompressor : public Decompressor { public: NOOPDecompressor(const PDB& p) : Decompressor(p) {} QByteArray decompress(const QByteArray& data) override { return data; } }; class RLEDecompressor : public Decompressor { public: RLEDecompressor(const PDB& p) : Decompressor(p) {} QByteArray decompress(const QByteArray& data) override; }; class BitReader { public: BitReader(const QByteArray& d) : pos(0), data(d) { data.append("\000\000\000\000"); //krazy:exclude=strings len=data.size()*8; } quint32 read() { quint32 g=0; quint64 r=0; while (g<32) { r=(r << 8) | (quint8)data[(pos+g)>>3]; g=g+8 - ((pos+g) & 7); } return (r >> (g-32)); } bool eat(int n) { pos+=n; return pos <= len; } int left() { return len - pos; } private: int pos; int len; QByteArray data; }; class HuffdicDecompressor : public Decompressor { public: HuffdicDecompressor(const PDB& p); QByteArray decompress(const QByteArray& data) override; private: void unpack(BitReader reader, int depth = 0); QList<QByteArray> dicts; quint32 entry_bits; quint32 dict1[256]; quint32 dict2[64]; QByteArray buf; }; QByteArray RLEDecompressor::decompress(const QByteArray& data) { QByteArray ret; ret.reserve(8192); unsigned char token; unsigned short copyLength, N, shift; unsigned short shifted; int i=0; int maxIndex=data.size()-1; while (i<data.size()) { token = data.at(i++); switch (TOKEN_CODE[token]) { case 0: ret.append(token); break; case 1: if ((i + token > maxIndex) ) { goto endOfLoop; } ret.append(data.mid(i,token)); i+=token; break; case 2: ret.append(' '); ret.append(token ^ 0x80); break; case 3: if (i + 1 > maxIndex) { goto endOfLoop; } N = token; N<<=8; N+=(unsigned char)data.at(i++); copyLength = (N & 7) + 3; shift = (N & 0x3fff) / 8; shifted = ret.size()-shift; if (shifted>(ret.size()-1)) goto endOfLoop; for (int i=0;i<copyLength;i++) ret.append(ret.at(shifted+i)); break; } } endOfLoop: return ret; } quint32 readBELong(const QByteArray& data, int offset) { quint32 ret=0; for (int i=0;i<4;i++) { ret<<=8; ret+=(unsigned char)data[offset+i]; } return ret; } HuffdicDecompressor::HuffdicDecompressor(const PDB& p) : Decompressor(p) { QByteArray header=p.getRecord(0); quint32 huff_ofs=readBELong(header,0x70); quint32 huff_num=readBELong(header,0x74); quint32 off1,off2; QByteArray huff1=p.getRecord(huff_ofs); if (huff1.isNull()) goto fail; for (unsigned int i=1;i<huff_num;i++) { QByteArray h=p.getRecord(huff_ofs+i); if (h.isNull()) goto fail; dicts.append(h); } off1=readBELong(huff1,16); off2=readBELong(huff1,20); if (!huff1.startsWith("HUFF")) goto fail; //krazy:exclude=strings if (!dicts[0].startsWith("CDIC")) goto fail; //krazy:exclude=strings entry_bits=readBELong(dicts[0],12); memcpy(dict1,huff1.data()+off1, 256*4); memcpy(dict2,huff1.data()+off2, 64*4); return; fail: valid=false; } QByteArray HuffdicDecompressor::decompress(const QByteArray& data) { buf.clear(); unpack(BitReader(data)); return buf; } void HuffdicDecompressor::unpack(BitReader reader,int depth) { if (depth>32) goto fail; while (reader.left()) { quint32 dw=reader.read(); quint32 v=dict1[dw>>24]; quint8 codelen = v & 0x1F; if (!codelen) goto fail; quint32 code = dw >> (32 - codelen); quint32 r=(v >> 8); if (!( v & 0x80)) { while (code < dict2[(codelen-1)*2]) { codelen++; code = dw >> (32 - codelen); } r = dict2[(codelen-1)*2+1]; } r-=code; if (!codelen) goto fail; if (!reader.eat(codelen)) return; quint32 dict_no = r >> entry_bits; quint32 off1 = 16 + (r - (dict_no << entry_bits))*2; QByteArray dict=dicts[dict_no]; quint32 off2 = 16 + (unsigned char)dict[off1]*256 + (unsigned char)dict[off1+1]; quint32 blen = (unsigned char)dict[off2]*256 + (unsigned char)dict[off2+1]; QByteArray slice=dict.mid(off2+2,(blen & 0x7fff)); if (blen & 0x8000) buf+=slice; else unpack(BitReader(slice),depth+1); } return; fail: valid=false; } Decompressor* Decompressor::create(quint8 type, const PDB& pdb) { switch (type) { case 1 : return new NOOPDecompressor(pdb); case 2 : return new RLEDecompressor(pdb); case 'H' : return new HuffdicDecompressor(pdb); default : return nullptr; } } } 07070100000009000081A40000000000000000000000016627827F0000046F000000000000000000000000000000000000004D00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/decompressor.h/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef MOBI_DECOMPRESSOR_H #define MOBI_DECOMPRESSOR_H #include <QByteArray> namespace Mobipocket { class PDB; class Decompressor { public: Decompressor(const PDB& p) : pdb(p), valid(true) {} virtual QByteArray decompress(const QByteArray& data) = 0; virtual ~Decompressor() {} bool isValid() const { return valid; } static Decompressor* create(quint8 type, const PDB& pdb); protected: const PDB& pdb; bool valid; }; quint32 readBELong(const QByteArray& data, int offset); } #endif 0707010000000A000081A40000000000000000000000016627827F000025E1000000000000000000000000000000000000004D00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/mobipocket.cpp/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "mobipocket.h" #include "decompressor.h" #include <QIODevice> #include <QtEndian> #include <QBuffer> #include <QTextCodec> #include <QImageReader> #include <QRegularExpression> namespace Mobipocket { QByteArray Stream::read(int len) { QByteArray ret; ret.resize(len); len=read(ret.data(),len); if (len<0) len=0; ret.resize(len); return ret; } QByteArray Stream::readAll() { QByteArray ret, bit; while (!(bit=read(4096)).isEmpty()) ret+=bit; return ret; } struct PDBPrivate { QList<quint32> recordOffsets; Stream* device; QString fileType; quint16 nrecords; bool valid; void init(); }; void PDBPrivate::init() { valid=true; quint16 word; quint32 dword; if (!device->seek(0x3c)) goto fail; fileType=QString::fromLatin1(device->read(8)); if (!device->seek(0x4c)) goto fail; device->read((char*)&word,2); nrecords=qFromBigEndian(word); for (int i=0;i<nrecords;i++) { device->read((char*)&dword,4); recordOffsets.append(qFromBigEndian(dword)); device->read((char*)&dword,4); } return; fail: valid=false; } PDB::PDB(Stream* dev) : d(new PDBPrivate) { d->device=dev; d->init(); } PDB::~PDB() { delete d; } QByteArray PDB::getRecord(int i) const { if (i>=d->nrecords) return QByteArray(); quint32 offset=d->recordOffsets[i]; bool last=(i==(d->nrecords-1)); if (!d->device->seek(offset)) return QByteArray(); if (last) return d->device->readAll(); return d->device->read(d->recordOffsets[i+1]-offset); } bool PDB::isValid() const { return d->valid; } int PDB::recordCount() const { return d->nrecords; } //////////////////////////////////////////// struct DocumentPrivate { DocumentPrivate(Stream* d) : pdb(d), valid(true), firstImageRecord(0), drm(false), thumbnailIndex(0) {} PDB pdb; Decompressor* dec; quint16 ntextrecords; quint16 maxRecordSize; bool valid; // number of first record holding image. Usually it is directly after end of text, but not always quint16 firstImageRecord; QMap<Document::MetaKey, QString> metadata; QTextCodec* codec; bool drm; // index of thumbnail in image list. May be specified in EXTH. // If not then just use first image and hope for the best int thumbnailIndex; void init(); void findFirstImage(); void parseEXTH(const QByteArray& data); void parseHtmlHead(const QString& data); QString readEXTHRecord(const QByteArray& data, quint32& offset); QImage getImageFromRecord(int recnum); }; void DocumentPrivate::parseHtmlHead(const QString& data) { static const QRegularExpression title(QLatin1String("<dc:title.*>(.*)</dc:title>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); static const QRegularExpression author(QLatin1String("<dc:creator.*>(.*)</dc:creator>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); static const QRegularExpression copyright(QLatin1String("<dc:rights.*>(.*)</dc:rights>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); static const QRegularExpression subject(QLatin1String("<dc:subject.*>(.*)</dc:subject>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); static const QRegularExpression description(QLatin1String("<dc:description.*>(.*)</dc:description>"), QRegularExpression::CaseInsensitiveOption | QRegularExpression::InvertedGreedinessOption); // title could have been already taken from MOBI record if (!metadata.contains(Document::Title)) { if (const auto titleMatch = title.match(data); titleMatch.hasMatch()) metadata[Document::Title]=titleMatch.captured(1); } if (const auto authorMatch = author.match(data); authorMatch.hasMatch()) metadata[Document::Author]=authorMatch.captured(1); if (const auto copyrightMatch = copyright.match(data); copyrightMatch.hasMatch()) metadata[Document::Copyright]=copyrightMatch.captured(1); if (const auto subjectMatch = subject.match(data); subjectMatch.hasMatch()) metadata[Document::Subject]=subjectMatch.captured(1); if (const auto descriptionMatch = description.match(data); descriptionMatch.hasMatch()) metadata[Document::Description]=descriptionMatch.captured(1); } void DocumentPrivate::init() { quint32 encoding=0; valid=pdb.isValid(); if (!valid) return; QByteArray mhead=pdb.getRecord(0); if (mhead.isNull() || mhead.size() <14 ) goto fail; dec = Decompressor::create(mhead[1], pdb); if ((int)mhead[12]!=0 || (int)mhead[13]!=0) drm=true; if (!dec) goto fail; ntextrecords=(unsigned char)mhead[8]; ntextrecords<<=8; ntextrecords+=(unsigned char)mhead[9]; maxRecordSize=(unsigned char)mhead[10]; maxRecordSize<<=8; maxRecordSize+=(unsigned char)mhead[11]; if (mhead.size() > 31 ) encoding=readBELong(mhead, 28); if (encoding==65001) codec=QTextCodec::codecForName("UTF-8"); else codec=QTextCodec::codecForName("CP1252"); if (mhead.size()>176) parseEXTH(mhead); // try getting metadata from HTML if nothing or only title was recovered from MOBI and EXTH records if (metadata.size()<2 && !drm) parseHtmlHead(codec->toUnicode(dec->decompress(pdb.getRecord(1)))); return; fail: valid=false; } void DocumentPrivate::findFirstImage() { firstImageRecord=ntextrecords+1; while (firstImageRecord<pdb.recordCount()) { QByteArray rec=pdb.getRecord(firstImageRecord); if (rec.isNull()) return; QBuffer buf(&rec); buf.open(QIODevice::ReadOnly); QImageReader r(&buf); if (r.canRead()) return; firstImageRecord++; } } QString DocumentPrivate::readEXTHRecord(const QByteArray& data, quint32& offset) { quint32 len=readBELong(data,offset); offset+=4; len-=8; QString ret=codec->toUnicode(data.mid(offset,len)); offset+=len; return ret; } QImage DocumentPrivate::getImageFromRecord(int i) { QByteArray rec=pdb.getRecord(i); return (rec.isNull()) ? QImage() : QImage::fromData(rec); } void DocumentPrivate::parseEXTH(const QByteArray& data) { // try to get name if (data.size()>=92) { qint32 nameoffset=readBELong(data,84); qint32 namelen=readBELong(data,88); if ( (nameoffset + namelen) < data.size() ) { metadata[Document::Title]=codec->toUnicode(data.mid(nameoffset, namelen)); } } quint32 exthoffs=readBELong(data,20)+16; if (data.mid(exthoffs,4)!="EXTH") return; quint32 records=readBELong(data,exthoffs+8); quint32 offset=exthoffs+12; for (unsigned int i=0;i<records;i++) { if (offset+4 > quint32(data.size())) break; quint32 type=readBELong(data,offset); offset+=4; switch (type) { case 100: metadata[Document::Author]=readEXTHRecord(data,offset); break; case 103: metadata[Document::Description]=readEXTHRecord(data,offset); break; case 105: metadata[Document::Subject]=readEXTHRecord(data,offset); break; case 109: metadata[Document::Copyright]=readEXTHRecord(data,offset); break; case 202: offset += 4; thumbnailIndex = readBELong(data,offset); offset+=4; break; default: readEXTHRecord(data,offset); } } } Document::Document(Stream* dev) : d(new DocumentPrivate(dev)) { d->init(); } Document::~Document() { delete d; } QString Document::text(int size) const { QByteArray whole; for (int i=1;i<d->ntextrecords+1;i++) { QByteArray decompressedRecord = d->dec->decompress(d->pdb.getRecord(i)); if (decompressedRecord.size() > d->maxRecordSize) decompressedRecord.resize(d->maxRecordSize); whole+=decompressedRecord; if (!d->dec->isValid()) { d->valid=false; return QString(); } if (size!=-1 && whole.size()>size) break; } return d->codec->toUnicode(whole); } int Document::imageCount() const { //FIXME: don't count FLIS and FCIS records return d->pdb.recordCount()-d->ntextrecords; } bool Document::isValid() const { return d->valid; } QImage Document::getImage(int i) const { if (!d->firstImageRecord) d->findFirstImage(); return d->getImageFromRecord(d->firstImageRecord+i); } QMap<Document::MetaKey,QString> Document::metadata() const { return d->metadata; } bool Document::hasDRM() const { return d->drm; } QImage Document::thumbnail() const { if (!d->firstImageRecord) d->findFirstImage(); QImage img=d->getImageFromRecord(d->thumbnailIndex+d->firstImageRecord); // does not work, try first image if (img.isNull() && d->thumbnailIndex) { d->thumbnailIndex=0; img=d->getImageFromRecord(d->firstImageRecord); } return img; } } 0707010000000B000081A40000000000000000000000016627827F000007D2000000000000000000000000000000000000004B00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/mobipocket.h/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef MOBIPOCKET_H #define MOBIPOCKET_H #include <QString> #include <QByteArray> #include <QMap> #include <QImage> #include "qmobipocket_export.h" class QIODevice; namespace Mobipocket { /** Minimalistic stream abstraction. It is supposed to allow mobipocket document classes to be used with QIODevice (for Okular generator), and previously also with InputStream for Strigi analyzer. */ class QMOBIPOCKET_EXPORT Stream { public: virtual int read(char* buf, int size)=0; virtual bool seek(int pos)=0; QByteArray readAll(); QByteArray read(int len); virtual ~Stream() {} }; struct PDBPrivate; class PDB { public: PDB(Stream* s); ~PDB(); QString fileType() const; int recordCount() const; QByteArray getRecord(int i) const; bool isValid() const; private: PDBPrivate* const d; }; struct DocumentPrivate; class QMOBIPOCKET_EXPORT Document { public: enum MetaKey { Title, Author, Copyright, Description, Subject }; ~Document(); Document(Stream* s); QMap<MetaKey,QString> metadata() const; QString text(int size=-1) const; int imageCount() const; QImage getImage(int i) const; QImage thumbnail() const; bool isValid() const; // if true then it is impossible to get text of book. Images should still be readable bool hasDRM() const; private: DocumentPrivate* const d; }; } #endif 0707010000000C000081A40000000000000000000000016627827F000003C6000000000000000000000000000000000000004E00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/qfilestream.cpp/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "qfilestream.h" using namespace Mobipocket; QFileStream::QFileStream(const QString& name) : d(new QFile(name)) { d->open(QIODevice::ReadOnly); } QFileStream::~QFileStream() { delete d; } int QFileStream::read(char* buf, int size) { return d->read(buf,size); } bool QFileStream::seek(int pos) { return d->seek(pos); } 0707010000000D000081A40000000000000000000000016627827F000003C3000000000000000000000000000000000000004C00000000kdegraphics-mobipocket-VERSIONgit.20240423T114223~8c885b8/lib/qfilestream.h/*************************************************************************** * Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef QFILESTREAM_H #define QFILESTREAM_H #include <QFile> #include "mobipocket.h" namespace Mobipocket { class QMOBIPOCKET_EXPORT QFileStream : public Stream { public: QFileStream(const QString& name); ~QFileStream(); int read(char* buf, int size) override; bool seek(int pos) override; private: QFile *d; }; } #endif 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!93 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor