fbreader-0.99.4.orig/0000755000706400070640000000000012056124565012722 5ustar bagebagefbreader-0.99.4.orig/build_packages.sh0000755000706400070640000001007712056124565016223 0ustar bagebage#! /bin/bash version=`cat fbreader/VERSION` tmpdir=fbreader-$version if [ "$1" == "-non-GPL" ]; then distdir=distributions-nonGPL pkgdir=packages-nonGPL prepare_nonGPL=true shift; else distdir=distributions pkgdir=packages prepare_nonGPL=false fi if [ $# -lt 1 ]; then echo "usage:" echo " $0 [-non-GPL] " echo "or" echo " $0 [-non-GPL] all" echo "or" echo " $0 [-non-GPL] supported" echo "" echo "available architectures are:" for pkgtype in $distdir/*; do for archtype in $pkgtype/*; do echo " `basename $archtype`-`basename $pkgtype`"; done; done; exit 1; fi create_tmpdir() { mkdir $tmpdir cp -r Makefile build_packages.sh zlibrary fbreader makefiles README.build CHANGES* distributions distributions-nonGPL ChangeLog $tmpdir rm -rf `find $tmpdir -name ".svn"` make -C $tmpdir distclean 1> /dev/null 2>&1 if [ "$prepare_nonGPL" == "true" ]; then pushd $tmpdir > /dev/null; echo -en "Removing Arabic localization... "; rm -rf fbreader/data/resources/ar.xml zlibrary/core/data/resources/ar.xml fbreader/data/help/MiniHelp.*.ar.fb2; echo OK; echo -en "Removing Finnish localization... "; rm -rf fbreader/data/resources/fi.xml zlibrary/core/data/resources/fi.xml fbreader/data/help/MiniHelp.*.fi.fb2; echo OK; echo -en "Removing Swedish localization... "; rm -rf fbreader/data/resources/sv.xml zlibrary/core/data/resources/sv.xml fbreader/data/help/MiniHelp.*.sv.fb2; echo OK; echo -en "Removing German localization... "; rm -rf fbreader/data/resources/de.xml zlibrary/core/data/resources/de.xml fbreader/data/help/MiniHelp.*.de.fb2; echo OK; echo -en "Removing Czech hyphenation patterns... "; zip -dq zlibrary/text/data/hyphenationPatterns.zip cs.pattern; echo OK; echo -en "Removing Indonesian hyphenation patterns... "; zip -dq zlibrary/text/data/hyphenationPatterns.zip id.pattern; echo OK; echo -en "Removing Qt-based interface... "; rm -rf zlibrary/ui/src/opie zlibrary/ui/src/qtopia zlibrary/ui/src/qt zlibrary/ui/src/qt4 echo OK; popd > /dev/null; fi; } remove_tmpdir() { rm -rf $tmpdir } build_package() { make_package="make -f makefiles/packaging.mk -C $tmpdir DIST_DIR=$distdir" case "$2" in debian) case "$1" in maemo) /scratchbox/login sb-conf se SDK_ARM /scratchbox/login -d `pwd` $make_package ARCHITECTURE=$1 $2 ;; maemo2|maemo3) /scratchbox/login sb-conf se SDK_ARMEL /scratchbox/login -d `pwd` $make_package ARCHITECTURE=$1 $2 ;; maemo4) /scratchbox/login sb-conf se CHINOOK_ARMEL /scratchbox/login -d `pwd` $make_package ARCHITECTURE=$1 $2 ;; maemo5) /scratchbox/login sb-conf se FREMANTLE_ARMEL /scratchbox/login -d `pwd` $make_package ARCHITECTURE=$1 $2 ;; *) $make_package ARCHITECTURE=$1 $2 ;; esac; mkdir -p $pkgdir/$1 mv -f $tmpdir/*.deb $tmpdir/*.dsc $tmpdir/*.changes $tmpdir/*.tar.gz $pkgdir/$1 ;; ipk|debipk) $make_package ARCHITECTURE=$1 $2 mkdir -p $pkgdir/$1 mv -f $tmpdir/*.ipk $pkgdir/$1 ;; motopkg) $make_package ARCHITECTURE=$1 $2 mkdir -p $pkgdir/$1 mv -f $tmpdir/*.pkg $pkgdir/$1 ;; tarball) $make_package ARCHITECTURE=$1 $2 mkdir -p $pkgdir/$1 mv -f $tmpdir/*.tgz $pkgdir/$1 ;; nsi) $make_package ARCHITECTURE=$1 $2 mkdir -p $pkgdir/$1 mv -f $tmpdir/*.exe $pkgdir/$1 ;; *) echo no rule is defined for package type ''$2''; ;; esac; } if [ $1 == all ]; then create_tmpdir for pkgtype in $distdir/*; do for archtype in $pkgtype/*; do build_package `basename $archtype` `basename $pkgtype`; done; done; remove_tmpdir elif [ $1 == supported ]; then create_tmpdir build_package desktop debian build_package win32 nsi build_package source tarball remove_tmpdir else while [ $# -gt 0 ] ; do archtype=`echo $1 | cut -d "-" -f 1`; pkgtype=`echo $1 | cut -d "-" -f 2`; extra=`echo $1 | cut -d "-" -f 3`; if [ "$pkgtype" != "" -a "$extra" == "" -a -d $distdir/$pkgtype/$archtype ]; then create_tmpdir build_package $archtype $pkgtype remove_tmpdir else echo "unknown architecture: $1" fi; shift; done; fi; fbreader-0.99.4.orig/fbreader/0000755000706400070640000000000012056124565014474 5ustar bagebagefbreader-0.99.4.orig/fbreader/openzaurus/0000755000706400070640000000000012056124565016707 5ustar bagebagefbreader-0.99.4.orig/fbreader/openzaurus/gpe/0000755000706400070640000000000012056124565017462 5ustar bagebagefbreader-0.99.4.orig/fbreader/openzaurus/gpe/fbreader.desktop0000644000706400070640000000024712056124565022632 0ustar bagebage[Desktop Entry] Name=FBReader Comment=E-Book Reader Exec=FBReader Icon=fbreader/FBReader Type=Application Terminal=0 Categories=Application;Utility StartupNotify=True fbreader-0.99.4.orig/fbreader/openzaurus/Makefile0000644000706400070640000000160212056124565020346 0ustar bagebageROOTDIR = $(CURDIR)/../.. include $(ROOTDIR)/makefiles/config.mk ifeq "$(UI_TYPE)" "opie" PICSDIR = $(INSTALLDIR)/pics/fbreader APPDIR = $(INSTALLDIR)/apps/Applications STYLE = $(RESOLUTION) else # UI_TYPE == gpe PICSDIR = $(SHAREDIR)/pixmaps/fbreader APPDIR = $(SHAREDIR)/applications STYLE = gpe$(RESOLUTION) endif install: @install -d $(DESTDIR)$(PICSDIR) @install -m 0644 ../data/icons/application/$(TARGET_ARCH)_$(RESOLUTION).png $(DESTDIR)$(PICSDIR)/FBReader.png @install -m 0644 ../data/default/config.openzaurus.xml $(DESTDIR)$(SHAREDIR)/FBReader/default/config.xml @install -m 0644 ../data/default/keymap.zaurus.xml $(DESTDIR)$(SHAREDIR)/FBReader/default/keymap.xml @install -m 0644 ../data/default/styles.$(STYLE).xml $(DESTDIR)$(SHAREDIR)/FBReader/default/styles.xml @install -d $(DESTDIR)$(APPDIR) @install -m 0644 $(UI_TYPE)/fbreader.desktop $(DESTDIR)$(APPDIR) clean: fbreader-0.99.4.orig/fbreader/openzaurus/opie0000777000706400070640000000000012056124565020655 2../opieustar bagebagefbreader-0.99.4.orig/fbreader/scripts/0000755000706400070640000000000012056124565016163 5ustar bagebagefbreader-0.99.4.orig/fbreader/scripts/install_config.sh0000755000706400070640000000070512056124565021517 0ustar bagebage#!/bin/sh if [ $# != 3 ]; then echo -e "usage\n $0 "; exit 0; fi; case "$1" in desktop|win32) ;; macosx) ;; maemo) case "$2" in maemo5) config_file=data/default/config.maemo5.xml ;; *) config_file=data/default/config.maemo.xml ;; esac; ;; pepperpad3) ;; zaurus_640x480) ;; *) ;; esac; if [ "$config_file" != "" ]; then install -m 0644 $config_file $3/config.xml; fi; fbreader-0.99.4.orig/fbreader/scripts/install_toolbar_and_menu.sh0000755000706400070640000000234412056124565023563 0ustar bagebage#!/bin/sh if [ $# != 3 ]; then echo -e "usage\n $0 "; exit 0; fi; case "$1" in desktop|win32) toolbar_file=data/default/toolbar.desktop.xml fullscreen_toolbar_file=data/default/fullscreen_toolbar.desktop.xml ;; macosx) toolbar_file=data/default/toolbar.macosx.xml ;; maemo) case "$2" in maemo5) ;; *) toolbar_file=data/default/toolbar.maemo.xml ;; esac; ;; pepperpad3) toolbar_file=data/default/toolbar.full.xml ;; zaurus_640x480) toolbar_file=data/default/toolbar.zaurus.xml ;; *) toolbar_file=data/default/toolbar.short.xml ;; esac; case "$1" in zaurus_640x480|zaurus_240x320|pma400) menubar_file=data/default/menubar.xml ;; maemo) case "$2" in maemo5) menubar_file=data/default/menubar.maemo5.xml ;; *) menubar_file=data/default/menubar.xml ;; esac; ;; moto) menubar_file=data/default/menubar.moto.xml ;; *) ;; esac; if [ "$toolbar_file" != "" ]; then install -m 0644 $toolbar_file $3/toolbar.xml; fi; if [ "$fullscreen_toolbar_file" != "" ]; then install -m 0644 $fullscreen_toolbar_file $3/fullscreen_toolbar.xml; fi; if [ "$menubar_file" != "" ]; then install -m 0644 $menubar_file $3/menubar.xml; fi; fbreader-0.99.4.orig/fbreader/scripts/install_help.sh0000755000706400070640000000114412056124565021200 0ustar bagebage#!/bin/sh if [ $# != 2 ]; then echo -e "usage\n $0 "; exit 0; fi; case "$1" in desktop|openzaurus_640x480|pdaxrom|pepperpad3|zaurus_640x480|macosx) platform=desktop; ;; maemo) platform=maemo; ;; opensimpad-0.9.0|qvfb) platform=640x480; ;; openzaurus_240x320|pma400|zaurus_240x320|moto) platform=240x320; ;; win32) platform=win32; ;; *) echo "$0: unknown platform \"$1\""; exit 0; ;; esac; installdir=$2; for file in data/help/MiniHelp.$platform.*.fb2; do lang=`echo $file | cut -d . -f 3`; install -m 0644 $file $installdir/MiniHelp.$lang.fb2 done fbreader-0.99.4.orig/fbreader/pepperpad30000777000706400070640000000000012056124565020053 2desktopustar bagebagefbreader-0.99.4.orig/fbreader/LICENSE0000644000706400070640000004311012056124565015500 0ustar bagebage GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library 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. Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. , 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 Library General Public License instead of this License. fbreader-0.99.4.orig/fbreader/opensimpad-0.9.00000777000706400070640000000000012056124565020074 2opieustar bagebagefbreader-0.99.4.orig/fbreader/qvfb0000777000706400070640000000000012056124565016231 2opieustar bagebagefbreader-0.99.4.orig/fbreader/moto/0000755000706400070640000000000012056124565015452 5ustar bagebagefbreader-0.99.4.orig/fbreader/moto/FBReader.desktop0000644000706400070640000000036512056124565020463 0ustar bagebage[Desktop Entry] Comment=E-book reader Exec=bin/FBReader.sh BigIcon=pics/FBReader-b.png Icon=pics/FBReader-s.png Version=0.8.11 Type=Application Name=FBReader Category=Office Description=E-book reader Vendor=Geometer Plus Version=0.8.13 Shared=2 fbreader-0.99.4.orig/fbreader/moto/Makefile0000644000706400070640000000170512056124565017115 0ustar bagebageROOTDIR = $(CURDIR)/../.. include $(ROOTDIR)/makefiles/config.mk install: @install -m 0644 ../data/default/config.$(TARGET_ARCH).xml $(DESTDIR)$(SHAREDIR)/FBReader/default/config.xml @install -m 0644 ../data/default/keymap.$(TARGET_ARCH).xml $(DESTDIR)$(SHAREDIR)/FBReader/default/keymap.xml @install -m 0644 ../data/default/styles.$(TARGET_ARCH).xml $(DESTDIR)$(SHAREDIR)/FBReader/default/styles.xml @install -d $(DESTDIR)$(INSTALLDIR)/pics @install -d $(DESTDIR)$(INSTALLDIR)/.FBReader @install -m 0644 ../data/icons/application/32x24.png $(DESTDIR)$(INSTALLDIR)/pics/FBReader-s.png @install -m 0644 ../data/icons/application/64x43.png $(DESTDIR)$(INSTALLDIR)/pics/FBReader-b.png @install -m 0644 ../data/icons/application/48x48.png $(DESTDIR)$(INSTALLDIR)/pics/FBReader.png @install -m 0644 FBReader.desktop $(DESTDIR)$(INSTALLDIR)/FBReader.desktop @install FBReader.sh $(DESTDIR)$(BINDIR) @install util/language_detector $(DESTDIR)$(BINDIR) clean: fbreader-0.99.4.orig/fbreader/moto/util/0000755000706400070640000000000012056124565016427 5ustar bagebagefbreader-0.99.4.orig/fbreader/moto/util/language_detector0000755000706400070640000001465412056124565022043 0ustar bagebageELFa( 44 (444(( /lib/ld-linux.so.2GNU%401#*.+3-2&,)$"!%( /'    I!$;<c ddE$h:"-" v<8HXT?، E0`_lH<D"~($" L`!j:4<$\ ̍(؍ c<L" +hD"x.!=J @^ libqte-mt.so.2_ZNK7QString4utf8Ev_DYNAMIC_ZN6QArrayIcED1Ev_init_ZN7QString11shared_nullE_ZN11QStringData10deleteSelfEv_ZN6QArrayIcED0Ev_ZN7QGArray9duplicateERKS__ZN7QGArray7newDataEv_fini_ZN7QGArrayD2Ev_GLOBAL_OFFSET_TABLE__ZN6QArrayIcE6detachEv_ZN7QGArray10deleteDataEPNS_10array_dataE_ZTV6QArrayIcE__data_start_Jv_RegisterClasses__gmon_start__libezxappbase.so.1_ZdlPv_ZN9ZLanguage21getSystemLanguageCodeEvlibezxappsdk.so.1libezxopenwindow.so.1libipp-miscGen.so.1libipp-jp.so.1libipp-codecJP.so.1libezxpm.solibstdc++.so.5_ZNSs6assignEPKcjpthread_create_ZNSt15basic_streambufIcSt11char_traitsIcEE13_S_pback_sizeE_ZNSs7replaceEjjPKcj_ZNSt15basic_streambufIwSt11char_traitsIwEE13_S_pback_sizeE_ZNSt8ios_base4InitC1Ev_ZNSsC1EPKcRKSaIcE_ZNSt8ios_base4InitD1Ev_ZN9__gnu_cxx17_Atomic_add_mutexE_ZSt4cout_ZSt20__throw_out_of_rangePKc_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E_ZNSs4_Rep10_M_destroyERKSaIcElibm.so.6libgcc_s.so.1libc.so.6abort__cxa_atexitpthread_mutex_unlockpthread_mutex_lock_IO_stdin_used__libc_start_mainstrlenlibpthread.so.0_edata__bss_start__bss_start____bss_end____end____fini_array_end__fini_array_start__init_array_end__init_array_startGLIBC_2.0GLIBC_2.1.3GLIBC_2.1GLIBCPP_3.2.3GLIBCPP_3.20ii si S ii }) r)t x|+3 0 $ (,048<@DHLP!T#X$\%`*d-h.l1p2@-]L- Əʌ ƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌ|ƏʌtƏʌlƏʌdƏʌ\ƏʌT$  --0-븑dTD- 00S蠅|p@-LP0S@@0 R 0000 R00p4@-0S/ 0S/@-< Q\@-  @x8G-(MP`] @ \$ BQ!pPa  \2 P0` fcw ^ S d`- @V pD xxP VB PTU(Ѝ @( ꠒ0p0xxE8  @- *蠒@-@#@ꠒD-L @@00<  0bCT*` 00Pb@ET:褂tx0D-L H0 D00@cD1@CS (0P0@DS0@lp@-(0 @Cr 004s@-@-0enbasic_string::_M_check(Lm S ، \(ԅ  ؋@oXooGCC: (GNU) 3.3.6GCC: (GNU) 3.3.6GCC: (GNU) 3.3.6GCC: (GNU) 3.3.6GCC: (GNU) 3.3.6GCC: (GNU) 3.3.6GCC: (GNU) 3.3.6.shstrtab.interp.note.ABI-tag.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.data.eh_frame.dynamic.ctors.dtors.jcr.got.bss.comment  !((l' @/ԅ7o hDoXX S ؋ @\   e، ` 4k <q\\ whhP ( ~fbreader-0.99.4.orig/fbreader/moto/util/language_detector.cpp0000644000706400070640000000205212056124565022606 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include int main() { std::string language = (const char*)ZLanguage::getSystemLanguageCode().utf8(); language.erase(2); if (language.length() != 2) { language = "en"; } std::cout << language; return 0; } fbreader-0.99.4.orig/fbreader/moto/util/Makefile0000644000706400070640000000030212056124565020062 0ustar bagebageROOTDIR = ../../.. TARGET = language_detector include $(ROOTDIR)/makefiles/qsubdir.mk $(TARGET): language_detector.o @$(LD) $(LDFLAGS) -o $@ $^ $(UILIBS) distclean: clean @$(RM) $(TARGET) fbreader-0.99.4.orig/fbreader/moto/FBReader.sh0000755000706400070640000000034312056124565017423 0ustar bagebage#!/bin/bash this=`basename $0` this=`echo $0 | sed -e 's/\/'$this'$//'` cd $this/.. . /home/native/.profile export HOME=`pwd` export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH exec bin/FBReader -lang `bin/language_detector` $2 fbreader-0.99.4.orig/fbreader/desktop/0000755000706400070640000000000012056124565016145 5ustar bagebagefbreader-0.99.4.orig/fbreader/desktop/FBReader.10000644000706400070640000000251412056124565017643 0ustar bagebage.TH FBREADER 1 .SH NAME FBReader \- e-book reader .SH SYNOPSIS .B FBReader [\fB\-lang \fIlanguage\fP] [\fIe-book\fP] .SH DESCRIPTION FBReader is an e-book reader. It supports most open e-book formats, and can read compressed e-book archives. .PP For more information on using the program, see the "About FBReader" button on its toolbar. .SH OPTIONS .TP \fB-lang \fIlanguage\fP Language for user interface. Current version (0.12.0) of fbreader supports Arabic (specify \fB\-lang ar\fP option), Chinese (\fB\-lang zh\fP), Czech (\fB\-lang cs\fP), Dutch (\fB\-lang nl\fP), English (\fB\-lang en\fP), Finnish (\fB\-lang fi\fP), French (\fB\-lang fr\fP), German (\fB\-lang de\fP), Hungarian (\fB\-lang hu\fP), Indonesian (\fB\-lang id\fP), Italian (\fB\-lang it\fP), Lithuanian (\fB\-lang lt\fP), Russian (\fB\-lang ru\fP), Spanish (\fB\-lang es\fP) and Swedish (\fB\-lang sv\fP) and Ukrainian (\fB\-lang uk\fP). .TP \fIe-book\fP Name of file to open. If this parameter is missing or if FBReader cannot open the specified file, the last opened file will be reopened. If you start FBReader for the first time or the last opened file is missing, "About FBReader" text will be opened. .SH AUTHOR This man page was written by Joey Hess and Nikolay Pultsin for the Debian system, but may be freely reused on other systems. fbreader-0.99.4.orig/fbreader/desktop/desktop0000644000706400070640000000147112056124565017544 0ustar bagebage[Desktop Entry] Name=FBReader GenericName=E-book reader GenericName[ar]=قارئ الكتب الإلكترونية GenericName[es]=Lector de Libros GenericName[hu]=E-könyv olvasó GenericName[pl]=Czytnik e-książek GenericName[ru]=Чтение электронных книг GenericName[zh_CN]=电子书阅读 Comment=FBReader E-book reader Comment[ar]=قارئ الكتب الإلكترونية Comment[es]=FBReader Lector de Libros Elecrónicos Comment[hu]=FBReader, E-könyv olvasó program Comment[pl]=FBReader, czytnik książek elektronicznych Comment[ru]=FBReader, программа для чтения электронных книг Comment[zh_CN]=FBReader 电子书阅读器 TryExec=FBReader Exec=FBReader %F StartupNotify=true Terminal=false Type=Application Icon=FBReader Categories=Office;Viewer;Literature; fbreader-0.99.4.orig/fbreader/desktop/Makefile0000644000706400070640000000133712056124565017611 0ustar bagebageROOTDIR = $(CURDIR)/../.. include $(ROOTDIR)/makefiles/config.mk TARGET = FBReader SHARE_FBREADER = $(DESTDIR)$(SHAREDIR)/FBReader BINARY = $(DESTDIR)$(BINDIR)/FBReader install: @strip $(BINARY) @install -d $(DESTDIR)/usr/share/applications @install -m 0644 desktop $(DESTDIR)/usr/share/applications/$(TARGET).desktop @install -d $(DESTDIR)$(IMAGEDIR) @install -m 0644 ../data/icons/application/$(TARGET_ARCH).png $(DESTDIR)$(IMAGEDIR)/FBReader.png @install -m 0644 ../data/default/config.desktop.xml $(SHARE_FBREADER)/default/config.xml @install -m 0644 ../data/default/keymap.desktop.xml $(SHARE_FBREADER)/default/keymap.xml @install -m 0644 ../data/default/styles.desktop.xml $(SHARE_FBREADER)/default/styles.xml clean: fbreader-0.99.4.orig/fbreader/pepperpad/0000755000706400070640000000000012056124565016454 5ustar bagebagefbreader-0.99.4.orig/fbreader/pepperpad/fbreader.spec0000644000706400070640000001025312056124565021103 0ustar bagebage# Upstream: Nikolay Pultsin %define desktop_vendor rpmforge Summary: E-book reader Name: fbreader Version: 0.8.8 Release: 1 License: GPL Group: Applications/Multimedia URL: http://www.fbreader.org/ Packager: Nikolay Pultsin Source: http://www.fbreader.org/fbreader-sources-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: zlib-devel, libpng-devel, gtk2-devel BuildRequires: desktop-file-utils BuildRequires: bzip2-devel, expat-devel, libjpeg-devel %description FBReader is an e-book reader for Linux PDAs and desktop computers. FBReader supports several e-book formats: plucker, palmdoc, zTXT, HTML, fb2, plain text, etc. %prep %setup %build %{__make} %{?_smp_mflags} INSTALLDIR=%{_prefix} TARGET_ARCH=pepperpad3 UI_TYPE=gtk TARGET_STATUS=release %install %{__rm} -rf %{buildroot} %makeinstall INSTALLDIR=%{_prefix} TARGET_ARCH=pepperpad3 UI_TYPE=gtk TARGET_STATUS=release DESTDIR=%{buildroot} %clean %{__rm} -rf %{buildroot} %files %defattr(-, root, root, 0755) %{_bindir}/FBReader %{_datadir}/FBReader %{_datadir}/pixmaps/FBReader.png %{_datadir}/pixmaps/FBReader %{_datadir}/applications/FBReader.desktop %{_libdir}/libzlcore.so.%{version} %{_libdir}/libzltext.so.%{version} %{_libdir}/zlibrary/ui/zlui-gtk.so %{_datadir}/zlibrary %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %changelog * Sun Nov 18 2007 Nikolay Pultsin - 0.8.8-1 - new upstream version - excluded keynames.patch * Sun Nov 18 2007 Nikolay Pultsin - 0.8.7b-1 - new upstream version - excluded rpath.patch - spec file cleanup * Sun Jun 3 2007 Nikolay Pultsin - 0.8.4-1 - new upstream version - removed gcc.patch - added keynames.patch - fixed homepage link * Sat May 19 2007 Mikhail Sobolev - 0.8.3d-1 - new upstream version * Mon May 14 2007 Mikhail Sobolev - 0.8.3c-1 - new upstream version - fixed day of week in changelog * Sun May 12 2007 Mikhail Sobolev - 0.8.3b-1 - new upstream version * Thu May 10 2007 Mikhail Sobolev - 0.8.3-1 - new upstream version * Mon Apr 9 2007 Mikhail Sobolev - 0.8.1d-1 - new upstream version * Wed Mar 26 2007 Mikhail Sobolev - 0.8.1c-1 - new upstream version * Wed Mar 26 2007 Mikhail Sobolev - 0.8.1b-1 - new upstream version * Wed Mar 26 2007 Mikhail Sobolev - 0.8.1a-1 - new upstream version - fixed wrong .so name for zlibrary - added application pixmap to the list of included files - added pixmap dir to the list of automatically included stuff - desktop version now has its own .desktop file: include it, do not generate our own one - now really include it * Tue Dec 5 2006 Mikhail Sobolev - 0.7.4q-1 - new upstream version * Mon Nov 27 2006 Mikhail Sobolev - 0.7.4p-1 - new upstream version * Tue Nov 21 2006 Mikhail Sobolev - 0.7.4o-1 - new upstream version * Mon Nov 06 2006 Mikhail Sobolev - 0.7.4n-3 - Introduced pepper_pad_2 variable that should indicate whether we build for Pepper Pad 2 - Cleaned up BuildRequires * Mon Nov 06 2006 Mikhail Sobolev - 0.7.4n-2 - Merged the changes done by Victor Rehorst to support Pepper Pad 2 * Sun Nov 05 2006 Mikhail Sobolev - 0.7.4n-1 - Trying new upstream version * Sat Nov 04 2006 Mikhail Sobolev - 0.7.4m-3 - Included execution of ldconfig * Sat Nov 04 2006 Mikhail Sobolev - 0.7.4m-2 - Updated based on Kad's comments * Sat Nov 04 2006 Mikhail Sobolev - 0.7.4m-1 - Upgraded to version 0.7.4m * Sat Nov 04 2006 Mikhail Sobolev - 0.7.4-2 - Modified spec to support gtk+ instead of qt * Fri May 26 2006 Dries Verachtert - 0.7.4-1 - 4419+/dries - Updated to release 0.7.4. * Sun Mar 26 2006 Dries Verachtert - 0.7.3-1 - Updated to release 0.7.3. * Fri Feb 17 2006 Dries Verachtert - 0.7.2-1 - Updated to release 0.7.2. * Wed Dec 07 2005 Dries Verachtert - 0.7.1-0.b - Initial package. fbreader-0.99.4.orig/fbreader/pdaxrom/0000755000706400070640000000000012056124565016146 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/Makefile0000644000706400070640000000167712056124565017621 0ustar bagebageROOTDIR = $(CURDIR)/../.. include $(ROOTDIR)/makefiles/config.mk install: @install -m 0644 ../data/default/config.pdaxrom.xml $(DESTDIR)$(SHAREDIR)/FBReader/default/config.xml @install -m 0644 ../data/default/keymap.pdaxrom.xml $(DESTDIR)$(SHAREDIR)/FBReader/default/keymap.xml @install -m 0644 ../data/default/styles.640x480.xml $(DESTDIR)$(SHAREDIR)/FBReader/default/styles.xml @install -d $(DESTDIR)$(SHAREDIR)/pixmaps/FBReader @install -m 0644 ../data/icons/application/$(TARGET_ARCH).png $(DESTDIR)$(SHAREDIR)/pixmaps/FBReader/FBReader.png @install -d $(DESTDIR)/$(INSTALLDIR)/apps/Office/FBReader @install -m 0644 data/apps/Office/FBReader/AppRun $(DESTDIR)$(INSTALLDIR)/apps/Office/FBReader @install -m 0644 data/apps/Office/FBReader/AppInfo.xml $(DESTDIR)$(INSTALLDIR)/apps/Office/FBReader @install -d $(DESTDIR)/$(SHAREDIR)/applications @install -m 0644 data/share/applications/FBReader.desktop $(DESTDIR)/$(SHAREDIR)/applications clean: fbreader-0.99.4.orig/fbreader/pdaxrom/data/0000755000706400070640000000000012056124565017057 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/share/0000755000706400070640000000000012056124565020161 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/share/applications/0000755000706400070640000000000012056124565022647 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/share/applications/FBReader.desktop0000644000706400070640000000031712056124565025655 0ustar bagebage[Desktop Entry] Name=FBReader Comment=E-Book Reader Exec=FBReader Icon=FBReader/FBReader.png Terminal=0 Type=Application Categories=Application;Office;WordProcessor; StartupNotify=False SingleInstance=False fbreader-0.99.4.orig/fbreader/pdaxrom/data/apps/0000755000706400070640000000000012056124565020022 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/apps/Office/0000755000706400070640000000000012056124565021215 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/apps/Office/FBReader/0000755000706400070640000000000012056124565022627 5ustar bagebagefbreader-0.99.4.orig/fbreader/pdaxrom/data/apps/Office/FBReader/AppRun0000755000706400070640000000003512056124565023760 0ustar bagebage#!/bin/sh exec FBReader "$@" fbreader-0.99.4.orig/fbreader/pdaxrom/data/apps/Office/FBReader/AppInfo.xml0000644000706400070640000000017112056124565024704 0ustar bagebage FBReader E-Book Reader fbreader-0.99.4.orig/fbreader/macosx/0000755000706400070640000000000012056124565015766 5ustar bagebagefbreader-0.99.4.orig/fbreader/macosx/Info.plist0000644000706400070640000000254712056124565017746 0ustar bagebage CFBundleDocumentTypes CFBundleTypeExtensions oebzip epub fb2 CFBundleTypeIconFile FBReader.icns CFBundleTypeMIMETypes application/epub+zip CFBundleTypeName e-book CFBundleTypeRole Viewer LSIsAppleDefaultForType CFBundleDevelopmentRegion English CFBundleExecutable FBReader CFBundleIconFile FBReader.icns CFBundleIdentifier org.geometerplus.fbreader CFBundleInfoDictionaryVersion 6.0 CFBundleName FBReader CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSMinimumSystemVersion 10.5 fbreader-0.99.4.orig/fbreader/macosx/English.lproj/0000755000706400070640000000000012056124565020504 5ustar bagebagefbreader-0.99.4.orig/fbreader/macosx/English.lproj/MainMenu.xib0000644000706400070640000002411212056124565022721 0ustar bagebage 1050 9L31a 677 949.54 353.00 YES YES com.apple.InterfaceBuilder.CocoaPlugin YES YES YES YES NSApplication FirstResponder NSApplication AMainMenu YES _NSMainMenu 15 2 {{50, 50}, {450, 600}} 1954021376 FBReader CocoaWindow {3.40282e+38, 3.40282e+38} 256 {450, 600} {{0, 0}, {1920, 1178}} {3.40282e+38, 3.40282e+38} ZLCocoaAppDelegate NSFontManager YES delegate 495 window 532 YES 0 YES -2 RmlsZSdzIE93bmVyA -1 First Responder -3 Application 29 YES 371 YES 372 YES 420 494 YES YES -1.IBPluginDependency -2.IBPluginDependency -3.IBPluginDependency 29.IBEditorWindowLastContentRect 29.IBPluginDependency 29.ImportedFromIB2 29.WindowOrigin 29.editorWindowContentRectSynchronizationRect 371.IBEditorWindowLastContentRect 371.IBWindowTemplateEditedContentRect 371.NSWindowTemplate.visibleAtLaunch 371.editorWindowContentRectSynchronizationRect 371.windowTemplate.maxSize 372.IBPluginDependency 420.IBPluginDependency 494.IBPluginDependency YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{354, 735}, {24, 20}} com.apple.InterfaceBuilder.CocoaPlugin {74, 862} {{6, 978}, {478, 20}} {{590, 191}, {450, 600}} {{590, 191}, {450, 600}} {{33, 99}, {480, 360}} {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin YES YES YES YES YES YES 533 YES CocoaWindow NSWindow IBProjectSource ../zlibrary/ui/src/cocoa/application/CocoaWindow.h ZLCocoaAppDelegate NSObject window NSWindow IBProjectSource ../zlibrary/ui/src/cocoa/library/ZLCocoaAppDelegate.h 0 ../cocoa.xcodeproj 3 fbreader-0.99.4.orig/fbreader/macosx/Makefile0000644000706400070640000000167012056124565017432 0ustar bagebageROOTDIR = $(CURDIR)/../.. include $(ROOTDIR)/makefiles/config.mk SHARE_FBREADER = $(DESTDIR)$(SHAREDIR)/FBReader BINARY = $(DESTDIR)$(BINDIR)/FBReader install: @strip $(BINARY) @install -m 0644 Info.plist $(DESTDIR)$(INSTALLDIR)/Contents @install -m 0644 ../data/icons/application/FBReader.icns $(DESTDIR)$(INSTALLDIR)/Contents/Resources @install -m 0644 ../data/default/config.macosx.xml $(SHARE_FBREADER)/default/config.xml @install -m 0644 ../data/default/keymap.macosx.xml $(SHARE_FBREADER)/default/keymap.xml @install -m 0644 ../data/default/styles.desktop.xml $(SHARE_FBREADER)/default/styles.xml @$(QTBASEDIR)/bin/macdeployqt $(DESTDIR)$(INSTALLDIR) @for fw in QtDeclarative QtScript QtSql QtSvg QtXmlPatterns; do \ rm -rf $(DESTDIR)$(INSTALLDIR)/Contents/Frameworks/$$fw.framework; \ done @for plugin in accessible codecs bearer graphicssystems qmltooling; do \ rm -rf $(DESTDIR)$(INSTALLDIR)/Contents/PlugIns/$$plugin; \ done fbreader-0.99.4.orig/fbreader/src/0000755000706400070640000000000012056124565015263 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/libraryActions/0000755000706400070640000000000012056124565020250 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryBookActions.h0000644000706400070640000000310612056124565024161 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __LIBRARYBOOKACTIONS_H__ #define __LIBRARYBOOKACTIONS_H__ #include #include class Book; class BookReadAction : public ZLRunnableWithKey { public: BookReadAction(shared_ptr book); void run(); ZLResourceKey key() const; private: const shared_ptr myBook; }; class BookEditInfoAction : public ZLRunnableWithKey { public: BookEditInfoAction(shared_ptr book); void run(); ZLResourceKey key() const; private: const shared_ptr myBook; }; class BookRemoveAction : public ZLRunnableWithKey { public: BookRemoveAction(shared_ptr book); private: void run(); ZLResourceKey key() const; bool makesSense() const; int removeBookDialog() const; private: const shared_ptr myBook; }; #endif /* __LIBRARYBOOKACTIONS_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryActions/AuthorInfoDialog.cpp0000644000706400070640000001103312056124565024150 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include "AuthorInfoDialog.h" #include "../library/Library.h" #include "../library/Author.h" class AuthorNameEntry : public ZLComboOptionEntry { public: AuthorNameEntry(AuthorInfoDialog &dialog, std::size_t index); const std::string &initialValue() const; const std::vector &values() const; void onAccept(const std::string &value); void onValueSelected(int index); public: std::size_t Index; private: AuthorInfoDialog &myInfoDialog; mutable std::vector myValues; std::string myValue; }; class AuthorSortKeyEntry : public ZLStringOptionEntry { public: AuthorSortKeyEntry(AuthorInfoDialog &dialog); const std::string &initialValue() const; void onAccept(const std::string &value); private: AuthorInfoDialog &myInfoDialog; }; AuthorNameEntry::AuthorNameEntry(AuthorInfoDialog &dialog, std::size_t index) : ZLComboOptionEntry(true), Index(index), myInfoDialog(dialog) { } const std::string &AuthorNameEntry::initialValue() const { return myInfoDialog.initialAuthor()->name(); } void AuthorNameEntry::onAccept(const std::string &value) { myInfoDialog.name() = value; } const std::vector &AuthorNameEntry::values() const { if (myValues.empty()) { const AuthorList &authors = myInfoDialog.authors(); for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { myValues.push_back((*it)->name()); } } return myValues; } void AuthorNameEntry::onValueSelected(int index) { Index = index; myInfoDialog.sortKeyEntry().resetView(); } AuthorSortKeyEntry::AuthorSortKeyEntry(AuthorInfoDialog &dialog) : myInfoDialog(dialog) { } const std::string &AuthorSortKeyEntry::initialValue() const { const AuthorList &authors = myInfoDialog.authors(); std::size_t index = std::min(myInfoDialog.nameEntry().Index, authors.size() - 1); return authors[index]->sortKey(); } void AuthorSortKeyEntry::onAccept(const std::string &value) { myInfoDialog.sortKey() = value; } bool AuthorInfoDialog::run(shared_ptr author) { AuthorInfoDialog dlg(author); if (dlg.dialog().run()) { dlg.dialog().acceptValues(); shared_ptr newAuthor = Author::getAuthor(dlg.name(), dlg.sortKey()); Library::Instance().replaceAuthor(author, newAuthor); return true; } return false; } AuthorInfoDialog::AuthorInfoDialog(shared_ptr author) : myInitialAuthor(author) { const AuthorList &authors = Library::Instance().authors(); for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { if (!it->isNull()) { myAuthors.push_back(*it); } } AuthorList::iterator jt = std::lower_bound(myAuthors.begin(), myAuthors.end(), myInitialAuthor, AuthorComparator()); if (jt == myAuthors.end() || *jt != myInitialAuthor) { myAuthors.insert(jt, myInitialAuthor); } myDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("AuthorInfoDialog")); myNameEntry = new AuthorNameEntry(*this, jt - myAuthors.begin()); mySortKeyEntry = new AuthorSortKeyEntry(*this); myDialog->addOption(ZLResourceKey("name"), myNameEntry); myDialog->addOption(ZLResourceKey("sortKey"), mySortKeyEntry); myDialog->addButton(ZLDialogManager::OK_BUTTON, true); myDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); } ZLDialog &AuthorInfoDialog::dialog() { return *myDialog; } shared_ptr AuthorInfoDialog::initialAuthor() { return myInitialAuthor; } const AuthorList &AuthorInfoDialog::authors() const { return myAuthors; } std::string &AuthorInfoDialog::name() { return myName; } std::string &AuthorInfoDialog::sortKey() { return mySortKey; } AuthorNameEntry &AuthorInfoDialog::nameEntry() { return *myNameEntry; } AuthorSortKeyEntry &AuthorInfoDialog::sortKeyEntry() { return *mySortKeyEntry; } fbreader-0.99.4.orig/fbreader/src/libraryActions/AuthorInfoDialog.h0000644000706400070640000000307712056124565023626 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __AUTHORINFODIALOG_H__ #define __AUTHORINFODIALOG_H__ #include #include "../library/Lists.h" class ZLDialog; class AuthorNameEntry; class AuthorSortKeyEntry; class AuthorInfoDialog { public: static bool run(shared_ptr author); private: AuthorInfoDialog(shared_ptr author); ZLDialog &dialog(); public: shared_ptr initialAuthor(); const AuthorList &authors() const; std::string &name(); std::string &sortKey(); AuthorNameEntry &nameEntry(); AuthorSortKeyEntry &sortKeyEntry(); private: const shared_ptr myInitialAuthor; AuthorList myAuthors; shared_ptr myDialog; AuthorNameEntry *myNameEntry; AuthorSortKeyEntry *mySortKeyEntry; std::string myName; std::string mySortKey; }; #endif /* __AUTHORINFODIALOG_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryTagActions.cpp0000644000706400070640000001046312056124565024341 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include #include #include "LibraryTagActions.h" #include "BooksUtil.h" #include "../library/Library.h" #include "../library/Tag.h" #include "../library/Lists.h" class TagNameEntry : public ZLComboOptionEntry { public: TagNameEntry(const std::vector &values, const std::string &initialValue); const std::string &initialValue() const; const std::vector &values() const; void onAccept(const std::string &value); private: const std::vector &myValues; std::string myValue; }; class TagIncludeSubtagsEntry : public ZLBooleanOptionEntry { public: TagIncludeSubtagsEntry(); bool initialState() const; void onAccept(bool state); private: bool myValue; }; TagEditOrCloneAction::TagEditOrCloneAction(shared_ptr tag) : myTag(tag) { } void TagEditOrCloneAction::run() { shared_ptr dialog = ZLDialogManager::Instance().createDialog(ZLResourceKey(resourceKeyName())); TagList tags; BooksUtil::collectTagsFromLibrary(tags); std::vector names; for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { if (!it->isNull()) { names.push_back((*it)->fullName()); } } TagNameEntry *tagNameEntry = new TagNameEntry(names, myTag->fullName()); dialog->addOption(ZLResourceKey("name"), tagNameEntry); TagIncludeSubtagsEntry *includeSubtagsEntry = new TagIncludeSubtagsEntry(); const Library &library = Library::Instance(); if (library.hasSubtags(myTag)) { if (!library.hasBooks(myTag)) { includeSubtagsEntry->setActive(false); } dialog->addOption(ZLResourceKey("includeSubtags"), includeSubtagsEntry); } dialog->addButton(ZLDialogManager::OK_BUTTON, true); dialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); if (dialog->run()) { dialog->acceptValues(); onAccept(tagNameEntry->initialValue(), includeSubtagsEntry->initialState()); } } TagEditAction::TagEditAction(shared_ptr tag) : TagEditOrCloneAction(tag) { } void TagEditAction::onAccept(const std::string &name, bool includeSubTags) { Library::Instance().renameTag(myTag, Tag::getTagByFullName(name), includeSubTags); } ZLResourceKey TagEditAction::key() const { return ZLResourceKey("edit"); } std::string TagEditAction::resourceKeyName() const { return "editTagDialog"; } TagCloneAction::TagCloneAction(shared_ptr tag) : TagEditOrCloneAction(tag) { } void TagCloneAction::onAccept(const std::string &name, bool includeSubTags) { Library::Instance().cloneTag(myTag, Tag::getTagByFullName(name), includeSubTags); } ZLResourceKey TagCloneAction::key() const { return ZLResourceKey("clone"); } std::string TagCloneAction::resourceKeyName() const { return "cloneTagDialog"; } TagRemoveAction::TagRemoveAction(shared_ptr tag) : myTag(tag) { } void TagRemoveAction::run() { BooksUtil::removeTag(myTag); } ZLResourceKey TagRemoveAction::key() const { return ZLResourceKey("delete"); } TagNameEntry::TagNameEntry(const std::vector &values, const std::string &initialValue) : ZLComboOptionEntry(true), myValues(values), myValue(initialValue) { } const std::string &TagNameEntry::initialValue() const { return myValue; } const std::vector &TagNameEntry::values() const { return myValues; } void TagNameEntry::onAccept(const std::string &value) { myValue = value; } TagIncludeSubtagsEntry::TagIncludeSubtagsEntry() : myValue(true) { } bool TagIncludeSubtagsEntry::initialState() const { return myValue; } void TagIncludeSubtagsEntry::onAccept(bool state) { myValue = state; } fbreader-0.99.4.orig/fbreader/src/libraryActions/BooksUtil.cpp0000644000706400070640000000530012056124565022665 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "BooksUtil.h" #include "../library/Library.h" #include "../library/Tag.h" #include "../fbreader/FBReader.h" void BooksUtil::removeTag(shared_ptr tag) { ZLResourceKey boxKey("removeTagBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), tag->fullName()); enum { REMOVE_TAG, REMOVE_SUBTREE, DONT_REMOVE } code = DONT_REMOVE; Library &library = Library::Instance(); if (library.hasSubtags(tag)) { if (library.hasBooks(tag)) { switch (ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("thisOnly"), ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON )) { case 0: code = REMOVE_TAG; break; case 1: code = REMOVE_SUBTREE; break; } } else { if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_SUBTREE; } } } else { if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::CANCEL_BUTTON) == 0) { code = REMOVE_TAG; } } if (code != DONT_REMOVE) { library.removeTag(tag, code == REMOVE_SUBTREE); // TODO: select current node (?) again FBReader::Instance().refreshWindow(); } } void BooksUtil::collectTagsFromLibrary(TagList &tags) { const TagList &lTags = Library::Instance().tags(); TagSet tagSet; for (TagList::const_iterator it = lTags.begin(); it != lTags.end(); ++it) { shared_ptr tag = *it; if (tag.isNull()) { tagSet.insert(tag); tags.push_back(tag); } else { TagList tagStack; do { tagStack.push_back(tag); tag = tag->parent(); } while (!tag.isNull() && tagSet.find(tag) == tagSet.end()); tagSet.insert(tagStack.begin(), tagStack.end()); tags.insert(tags.end(), tagStack.rbegin(), tagStack.rend()); } } } fbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryTagActions.h0000644000706400070640000000364212056124565024007 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __LIBRARYTAGACTIONS_H__ #define __LIBRARYTAGACTIONS_H__ #include #include class Tag; class TagEditOrCloneAction : public ZLRunnableWithKey { public: TagEditOrCloneAction(shared_ptr tag); private: void run(); protected: virtual void onAccept(const std::string &name, bool includeSubTags) = 0; virtual std::string resourceKeyName() const = 0; protected: const shared_ptr myTag; }; class TagEditAction : public TagEditOrCloneAction { public: TagEditAction(shared_ptr tag); private: ZLResourceKey key() const; void onAccept(const std::string &name, bool includeSubTags); std::string resourceKeyName() const; }; class TagCloneAction : public TagEditOrCloneAction { public: TagCloneAction(shared_ptr tag); private: ZLResourceKey key() const; void onAccept(const std::string &name, bool includeSubTags); std::string resourceKeyName() const; }; class TagRemoveAction : public ZLRunnableWithKey { public: TagRemoveAction(shared_ptr tag); private: void run(); ZLResourceKey key() const; private: const shared_ptr myTag; }; #endif /* __LIBRARYTAGACTIONS_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryBookActions.cpp0000644000706400070640000001032412056124565024514 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "LibraryBookActions.h" #include "../library/Book.h" #include "../fbreader/FBReader.h" #include "../optionsDialog/bookInfo/BookInfoDialog.h" BookReadAction::BookReadAction(shared_ptr book) : myBook(book) { } void BookReadAction::run() { FBReader &fbreader = FBReader::Instance(); fbreader.openBook(myBook); fbreader.showBookTextView(); } ZLResourceKey BookReadAction::key() const { return ZLResourceKey("read"); } BookRemoveAction::BookRemoveAction(shared_ptr book) : myBook(book) { } void BookRemoveAction::run() { switch (removeBookDialog()) { case Library::REMOVE_FROM_DISK: { const std::string path = myBook->file().physicalFilePath(); ZLFile physicalFile(path); if (!physicalFile.remove()) { ZLResourceKey boxKey("removeFileErrorBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), path); ZLDialogManager::Instance().errorBox(boxKey, message); } } // yes, we go through this label case Library::REMOVE_FROM_LIBRARY: Library::Instance().removeBook(myBook); FBReader::Instance().refreshWindow(); case Library::REMOVE_DONT_REMOVE: break; } } ZLResourceKey BookRemoveAction::key() const { return ZLResourceKey("delete"); } bool BookRemoveAction::makesSense() const { return Library::Instance().canRemove(myBook) != Library::REMOVE_DONT_REMOVE; } int BookRemoveAction::removeBookDialog() const { ZLResourceKey boxKey("removeBookBox"); const ZLResource &msgResource = ZLResource::resource("dialog")[boxKey]; switch (Library::Instance().canRemove(myBook)) { case Library::REMOVE_DONT_REMOVE: return Library::REMOVE_DONT_REMOVE; case Library::REMOVE_FROM_DISK: { ZLFile physFile(myBook->file().physicalFilePath()); const std::string message = ZLStringUtil::printf(msgResource["deleteFile"].value(), physFile.name(false)); if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { return Library::REMOVE_FROM_DISK; } return Library::REMOVE_DONT_REMOVE; } case Library::REMOVE_FROM_LIBRARY: { const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook->title()); if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { return Library::REMOVE_FROM_LIBRARY; } return Library::REMOVE_DONT_REMOVE; } case Library::REMOVE_FROM_LIBRARY_AND_DISK: { ZLResourceKey removeFileKey("removeFile"); ZLResourceKey removeLinkKey("removeLink"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook->title()); switch(ZLDialogManager::Instance().questionBox(boxKey, message, removeLinkKey, removeFileKey, ZLDialogManager::CANCEL_BUTTON)) { case 0: return Library::REMOVE_FROM_LIBRARY; case 1: return Library::REMOVE_FROM_DISK; case 2: return Library::REMOVE_DONT_REMOVE; } } } return Library::REMOVE_DONT_REMOVE; } BookEditInfoAction::BookEditInfoAction(shared_ptr book) : myBook(book) { } void BookEditInfoAction::run() { if (BookInfoDialog(myBook).dialog().run()) { // TODO: select current node (?) again FBReader::Instance().refreshWindow(); } } ZLResourceKey BookEditInfoAction::key() const { return ZLResourceKey("edit"); } fbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryAuthorActions.cpp0000644000706400070640000000245112056124565025066 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include "LibraryAuthorActions.h" #include "AuthorInfoDialog.h" #include "../library/Author.h" #include "../fbreader/FBReader.h" AuthorEditInfoAction::AuthorEditInfoAction(shared_ptr author) : myAuthor(author) { } AuthorEditInfoAction::~AuthorEditInfoAction() { } void AuthorEditInfoAction::run() { if (AuthorInfoDialog::run(myAuthor)) { // TODO: select current node (?) again FBReader::Instance().refreshWindow(); } } ZLResourceKey AuthorEditInfoAction::key() const { return ZLResourceKey("edit"); } fbreader-0.99.4.orig/fbreader/src/libraryActions/LibraryAuthorActions.h0000644000706400070640000000227012056124565024532 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __LIBRARYAUTHORACTIONS_H__ #define __LIBRARYAUTHORACTIONS_H__ #include #include class Author; class AuthorEditInfoAction : public ZLRunnableWithKey { public: AuthorEditInfoAction(shared_ptr author); ~AuthorEditInfoAction(); void run(); ZLResourceKey key() const; private: const shared_ptr myAuthor; }; #endif /* __LIBRARYAUTHORACTIONS_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryActions/BooksUtil.h0000644000706400070640000000211212056124565022330 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __BOOKSUTIL_H__ #define __BOOKSUTIL_H__ #include #include "../library/Lists.h" class Tag; class BooksUtil { public: static void removeTag(shared_ptr tag); static void collectTagsFromLibrary(TagList &tags); private: BooksUtil(); }; #endif /* __BOOKSUTIL_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/0000755000706400070640000000000012056124565017254 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/migration/Migration_0_99_0.cpp0000644000706400070640000000644612056124565022702 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "../database/booksdb/BooksDB.h" #include "../library/Number.h" #include "Migration.h" static const std::string RENAME_TABLE_TO_OBSOLETE = "ALTER TABLE BookSeries RENAME TO BookSeries_Obsolete"; static const std::string CREATE_NEW_TABLE = \ "CREATE TABLE IF NOT EXISTS BookSeries ( " \ " book_id INTEGER UNIQUE NOT NULL REFERENCES Books (book_id), " \ " series_id INTEGER NOT NULL REFERENCES Series (series_id), " \ " book_index TEXT " \ "); "; static const std::string DROP_OBSOLETE_TABLE = "DROP TABLE BookSeries_Obsolete"; static const std::string LOAD_OBSOLETE_SERIES_QUERY = "SELECT book_id, series_id, book_index" \ " FROM BookSeries_Obsolete;"; class Migration_0_99_0_Runnable : public DBRunnable { public: bool run(); }; bool Migration_0_99_0_Runnable::run() { DBConnection &connection = BooksDB::Instance().connection(); shared_ptr renameTable = SQLiteFactory::createCommand(RENAME_TABLE_TO_OBSOLETE, connection); shared_ptr createNewTable = SQLiteFactory::createCommand(CREATE_NEW_TABLE, connection); shared_ptr dropObsoleteTable = SQLiteFactory::createCommand(DROP_OBSOLETE_TABLE, connection); shared_ptr loadObsoleteSeries = SQLiteFactory::createCommand(LOAD_OBSOLETE_SERIES_QUERY, connection); shared_ptr insertBookSeries = SQLiteFactory::createCommand(BooksDBQuery::SET_BOOKSERIES, connection, "@book_id", DBValue::DBINT, "@series_id", DBValue::DBINT, "@book_index", DBValue::DBTEXT); if (!renameTable->execute()) { return false; } if (!createNewTable->execute()) { return false; } shared_ptr reader = loadObsoleteSeries->executeReader(); while (reader->next()) { ((DBIntValue &) *insertBookSeries->parameter("@book_id").value()) = reader->intValue(0); ((DBIntValue &) *insertBookSeries->parameter("@series_id").value()) = reader->intValue(1); Number seriesIndex; if (reader->type(2) == DBValue::DBREAL){ seriesIndex = Number((int)reader->realValue(2)); } else { seriesIndex = Number(reader->intValue(2)); } ((DBTextValue &) *insertBookSeries->parameter("@book_index").value()) = seriesIndex.value(); if (!insertBookSeries->execute()) { ZLLogger::Instance().println("Migration", "problems with inserting series & book index"); } } dropObsoleteTable->execute(); return true; } Migration_0_99_0::Migration_0_99_0() : Migration("0.99.0") { } void Migration_0_99_0::doMigrationInternal() { Migration_0_99_0_Runnable r; BooksDB::Instance().executeAsTransaction(r); } fbreader-0.99.4.orig/fbreader/src/migration/migrate.h0000644000706400070640000000207612056124565021062 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #ifndef __MIGRATE_H__ #define __MIGRATE_H__ #include #include class MigrationRunnable : public ZLRunnable { public: MigrationRunnable(); bool shouldMigrate() const; void run(); private: ZLStringOption myVersionOption; }; #endif /* __MIGRATE_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/Migration.cpp0000644000706400070640000000463712056124565021723 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include "../options/FBCategoryKey.h" #include "Migration.h" void Migration::moveOption( const ZLCategoryKey &oldCategory, const std::string &oldGroup, const std::string &oldName, const ZLCategoryKey &newCategory, const std::string &newGroup, const std::string &newName, const std::string &defaultValue ) { ZLStringOption newOption(newCategory, newGroup, newName, defaultValue); const std::string newValue = newOption.value(); ZLStringOption oldOption(oldCategory, oldGroup, oldName, newValue); const std::string oldValue = oldOption.value(); if (newValue != oldValue) { newOption.setValue(oldValue); oldOption.setValue(newValue); } } bool Migration::isLikeToFileName(const std::string &str) { return ZLStringUtil::stringStartsWith(str, "/") || ZLStringUtil::stringStartsWith(str, "\\\\") || ((str.length() > 2) && (str.substr(1, 2) == ":\\")); } Migration::Migration(const std::string &version) : myVersion(version) { } Migration::~Migration() { } int Migration::extractVersionInformation(const std::string &name) { int major = std::atoi(name.c_str()); int minor = 0; int point = 0; int index = name.find('.'); if (index > 0) { minor = std::atoi(name.c_str() + index + 1); index = name.find('.', index + 1); if (index > 0) { point = std::atoi(name.c_str() + index + 1); } } return 10000 * major + 100 * minor + point; } void Migration::doMigration() { ZLStringOption versionOption(FBCategoryKey::SYSTEM, "Version", "FBReaderVersion", "0"); if (extractVersionInformation(versionOption.value()) < extractVersionInformation(myVersion)) { doMigrationInternal(); } } fbreader-0.99.4.orig/fbreader/src/migration/BookInfo.h0000644000706400070640000000255512056124565021142 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __BOOKINFO_H__ #define __BOOKINFO_H__ #include #include struct BookInfo { BookInfo(const std::string &fileName); ~BookInfo(); bool isFull() const; void reset(); ZLStringOption AuthorDisplayNameOption; ZLStringOption AuthorSortKeyOption; ZLStringOption TitleOption; ZLStringOption SeriesTitleOption; ZLStringOption IndexInSeriesOption; ZLStringOption LanguageOption; ZLStringOption EncodingOption; ZLStringOption TagsOption; const BookInfo &operator = (const BookInfo &bi); }; inline BookInfo::~BookInfo() {} #endif /* __BOOKINFO_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_8_16.cpp0000644000706400070640000000610612056124565022670 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include "Migration.h" #include "FB2MigrationReader.h" #include "OEBMigrationReader.h" #include "HtmlDCTagsReader.h" #include "BookInfo.h" #include "../options/FBCategoryKey.h" #include "../formats/oeb/OEBPlugin.h" #include "../formats/pdb/PdbPlugin.h" #include "../formats/pdb/PalmDocStream.h" Migration_0_8_16::Migration_0_8_16() : Migration("0.8.16") { } void Migration_0_8_16::doMigrationInternal() { PluginCollection &collection = PluginCollection::Instance(); std::vector optionGroups; ZLOption::listOptionGroups(optionGroups); for (std::vector::const_iterator it = optionGroups.begin(); it != optionGroups.end(); ++it) { if (isLikeToFileName(*it)) { ZLFile file(*it); if (collection.plugin(file, false) != 0) { BookInfo info(*it); ZLStringOption &languageOption = info.LanguageOption; const std::string &language = languageOption.value(); if (language == "") { languageOption.setValue(collection.DefaultLanguageOption.value()); } else if (language == "cz") { languageOption.setValue("cs"); } else if (language == "none") { languageOption.setValue(ZLLanguageUtil::OtherLanguageCode); } else if ((language == "chinese") || (language == "anycharacter")) { languageOption.setValue("zh"); } const std::string extension = file.extension(); if (extension == "fb2") { ZLBooleanOption seriesOption(FBCategoryKey::BOOKS, *it, "SequenceDefined", false); if (!seriesOption.value() || info.TagsOption.value().empty()) { FB2MigrationReader(info, !seriesOption.value()).doRead(ZLFile(*it)); } seriesOption.setValue(true); } else if ((extension == "opf") || (extension == "oebzip") || (extension == "epub")) { if (info.TagsOption.value().empty()) { OEBMigrationReader(info).doRead(OEBPlugin::opfFile(ZLFile(*it))); } } else if ((extension == "prc") || (extension == "pdb") || (extension == "mobi")) { const std::string fileType = PdbPlugin::fileType(file); if (info.TagsOption.value().empty() && ((fileType == "BOOKMOBI") || (fileType == "TEXtREAd"))) { shared_ptr stream = new PalmDocStream(file); if (!stream.isNull()) { HtmlDCTagsReader(info).readDocument(*stream); } } } } } } } fbreader-0.99.4.orig/fbreader/src/migration/migrate.cpp0000644000706400070640000000272712056124565021420 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include "../options/FBCategoryKey.h" #include "Migration.h" #include "migrate.h" MigrationRunnable::MigrationRunnable() : myVersionOption(FBCategoryKey::SYSTEM, "Version", "FBReaderVersion", "0") { } bool MigrationRunnable::shouldMigrate() const { return Migration::extractVersionInformation(myVersionOption.value()) < Migration::extractVersionInformation(VERSION); } void MigrationRunnable::run() { Migration_0_8_11().doMigration(); Migration_0_8_13().doMigration(); Migration_0_8_16().doMigration(); Migration_0_10_4().doMigration(); Migration_0_11_0().doMigration(); Migration_0_99_0().doMigration(); Migration_0_99_1().doMigration(); myVersionOption.setValue(VERSION); } fbreader-0.99.4.orig/fbreader/src/migration/HtmlDCTagsReader.h0000644000706400070640000000246612056124565022512 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __HTMLDCTAGSREADER_H__ #define __HTMLDCTAGSREADER_H__ #include "../formats/html/HtmlReader.h" #include "BookInfo.h" class HtmlDCTagsReader : public HtmlReader { public: HtmlDCTagsReader(BookInfo &info); private: void startDocumentHandler(); void endDocumentHandler(); bool tagHandler(const HtmlTag &tag); bool characterDataHandler(const char *text, std::size_t len, bool convert); private: BookInfo &myInfo; bool myReadTag; std::string myBuffer; std::string myTagList; }; #endif /* __HTMLDCTAGSREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/FB2MigrationReader.cpp0000644000706400070640000000577612056124565023345 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "FB2MigrationReader.h" #include "../formats/fb2/FB2TagManager.h" FB2MigrationReader::FB2MigrationReader(BookInfo &info, bool updateSeries) : myInfo(info), myUpdateSeries(updateSeries), myUpdateTags(info.TagsOption.value().empty()) { } void FB2MigrationReader::characterDataHandler(const char *text, std::size_t len) { if (myReadState == READ_GENRE) { myGenreBuffer.append(text, len); } } void FB2MigrationReader::startElementHandler(int tag, const char **attributes) { switch (tag) { case _BODY: interrupt(); break; case _TITLE_INFO: myReadState = READ_SOMETHING; break; case _GENRE: if ((myReadState == READ_SOMETHING) && myUpdateTags) { myReadState = READ_GENRE; } break; case _SEQUENCE: if ((myReadState == READ_SOMETHING) && myUpdateSeries) { const char *name = attributeValue(attributes, "name"); if (name != 0) { std::string seriesTitle = name; ZLUnicodeUtil::utf8Trim(seriesTitle); myInfo.SeriesTitleOption.setValue(seriesTitle); const char *number = attributeValue(attributes, "number"); myInfo.IndexInSeriesOption.setValue((number != 0) ? std::string(number) : std::string()); } } break; default: break; } } void FB2MigrationReader::endElementHandler(int tag) { switch (tag) { case _TITLE_INFO: myReadState = READ_NOTHING; break; case _GENRE: if (myReadState == READ_GENRE) { ZLUnicodeUtil::utf8Trim(myGenreBuffer); if (!myGenreBuffer.empty()) { const std::vector &tags = FB2TagManager::Instance().humanReadableTags(myGenreBuffer); if (!tags.empty()) { myTags.insert(tags.begin(), tags.end()); } else { myTags.insert(myGenreBuffer); } myGenreBuffer.erase(); } myReadState = READ_SOMETHING; } break; default: break; } } void FB2MigrationReader::doRead(const ZLFile &file) { myReadState = READ_NOTHING; readDocument(file); if (myUpdateTags) { std::string tagList; for (std::set::const_iterator it = myTags.begin(); it != myTags.end(); ++it) { if (it != myTags.begin()) { tagList += ","; } tagList += *it; } myInfo.TagsOption.setValue(tagList); } } fbreader-0.99.4.orig/fbreader/src/migration/FB2MigrationReader.h0000644000706400070640000000275312056124565023002 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FB2MIGRATIONREADER_H__ #define __FB2MIGRATIONREADER_H__ #include #include #include "../formats/fb2/FB2Reader.h" #include "BookInfo.h" class FB2MigrationReader : public FB2Reader { public: FB2MigrationReader(BookInfo &info, bool updateSeries); void doRead(const ZLFile &file); void startElementHandler(int tag, const char **attributes); void endElementHandler(int tag); void characterDataHandler(const char *text, std::size_t len); private: BookInfo &myInfo; enum { READ_NOTHING, READ_SOMETHING, READ_GENRE } myReadState; bool myUpdateSeries; bool myUpdateTags; std::string myGenreBuffer; std::set myTags; }; #endif /* __FB2MIGRATIONREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_10_4.cpp0000644000706400070640000000271712056124565022662 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include #include "Migration.h" #include "../options/FBCategoryKey.h" Migration_0_10_4::Migration_0_10_4() : Migration("0.10.4") { } void Migration_0_10_4::doMigrationInternal() { std::vector groups; ZLOption::listOptionGroups(groups); for (std::vector::const_iterator it = groups.begin(); it != groups.end(); ++it) { static const std::string zipPostfix = ".zip"; static const std::string sizeName = "Size"; if (ZLStringUtil::stringEndsWith(ZLUnicodeUtil::toLower(*it), zipPostfix)) { ZLIntegerOption option(FBCategoryKey::BOOKS, *it, sizeName, -1); option.setValue(-1); } } } fbreader-0.99.4.orig/fbreader/src/migration/Migration.h0000644000706400070640000000457712056124565021373 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #ifndef __MIGRATION_H__ #define __MIGRATION_H__ #include #include #include #include class Migration { public: static int extractVersionInformation(const std::string &name); protected: static void moveOption( const ZLCategoryKey &oldCategory, const std::string &oldGroup, const std::string &oldName, const ZLCategoryKey &newCategory, const std::string &newGroup, const std::string &newName, const std::string &defaultValue ); static bool isLikeToFileName(const std::string &str); public: Migration(const std::string &version); virtual ~Migration(); void doMigration(); protected: virtual void doMigrationInternal() = 0; private: const std::string myVersion; friend class Migration_0_11_0_Runnable; }; class Migration_0_8_11 : public Migration { public: Migration_0_8_11(); protected: void doMigrationInternal(); }; class Migration_0_8_13 : public Migration { public: Migration_0_8_13(); protected: void doMigrationInternal(); }; class Migration_0_8_16 : public Migration { public: Migration_0_8_16(); protected: void doMigrationInternal(); }; class Migration_0_10_4 : public Migration { public: Migration_0_10_4(); protected: void doMigrationInternal(); }; class Migration_0_11_0 : public Migration { public: Migration_0_11_0(); protected: void doMigrationInternal(); }; class Migration_0_99_0 : public Migration { public: Migration_0_99_0(); protected: void doMigrationInternal(); }; class Migration_0_99_1 : public Migration { public: Migration_0_99_1(); protected: void doMigrationInternal(); }; #endif /* __MIGRATION_H__ */ fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_8_13.cpp0000644000706400070640000000322512056124565022664 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include "Migration.h" Migration_0_8_13::Migration_0_8_13() : Migration("0.8.13") { } void Migration_0_8_13::doMigrationInternal() { std::vector optionNames; ZLOption::listOptionNames("Style", optionNames); for (std::vector::const_iterator it = optionNames.begin(); it != optionNames.end(); ++it) { if (ZLStringUtil::stringEndsWith(*it, ":lineSpacing") || ZLStringUtil::stringEndsWith(*it, ":lineSpace")) { ZLDoubleOption doubleOption(ZLCategoryKey::LOOK_AND_FEEL, "Style", *it, 0.0); ZLIntegerOption intOption(ZLCategoryKey::LOOK_AND_FEEL, "Style", *it + "Percent", -1); const double doubleValue = doubleOption.value(); const int intValue = intOption.value(); doubleOption.setValue((intValue == -1) ? 0.0 : (intValue / 100.0)); intOption.setValue((int)(doubleValue * 100)); } } } fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_99_1.cpp0000644000706400070640000000227312056124565022675 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include "Migration.h" #include "../fbreader/FBReaderActions.h" #include "../database/networkdb/NetworkDB.h" Migration_0_99_1::Migration_0_99_1() : Migration("0.99.1") { } void Migration_0_99_1::doMigrationInternal() { shared_ptr cmd = SQLiteFactory::createCommand("DROP TABLE IF EXISTS NetFiles", NetworkDB::Instance().connection()); cmd->execute(); } fbreader-0.99.4.orig/fbreader/src/migration/HtmlDCTagsReader.cpp0000644000706400070640000000334612056124565023043 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "HtmlDCTagsReader.h" HtmlDCTagsReader::HtmlDCTagsReader(BookInfo &info) : HtmlReader(info.EncodingOption.value()), myInfo(info) { } bool HtmlDCTagsReader::tagHandler(const HtmlReader::HtmlTag &tag) { if (tag.Name == "BODY") { return false; } else if (tag.Name == "DC:SUBJECT") { myReadTag = tag.Start; ZLStringUtil::stripWhiteSpaces(myBuffer); if (!tag.Start && !myBuffer.empty()) { if (!myTagList.empty()) { myTagList += ","; } myTagList += myBuffer; myBuffer.erase(); } } return true; } void HtmlDCTagsReader::startDocumentHandler() { myReadTag = false; } void HtmlDCTagsReader::endDocumentHandler() { myInfo.TagsOption.setValue(myTagList); } bool HtmlDCTagsReader::characterDataHandler(const char *text, std::size_t len, bool convert) { if (myReadTag) { if (convert) { myConverter->convert(myBuffer, text, text + len); } else { myBuffer.append(text, len); } } return true; } fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_8_11.cpp0000644000706400070640000001065012056124565022662 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include "Migration.h" #include "../fbreader/FBReaderActions.h" static void changeActionNames(const std::map map, const std::string &group) { const int length = ZLIntegerOption(ZLCategoryKey::CONFIG, group, "Number", 0).value(); for (int i = 0; i < length; ++i) { std::string optionName = "Action"; ZLStringUtil::appendNumber(optionName, i); ZLStringOption option(ZLCategoryKey::CONFIG, group, optionName, ""); std::string value = option.value(); std::map::const_iterator it = map.find(value); if (it != map.end()) { option.setValue(it->second); } } } static void changeActionNames() { std::map oldToNewNames; oldToNewNames["0"] = "none"; oldToNewNames["1"] = ActionCode::SHOW_LIBRARY; oldToNewNames["30"] = ActionCode::OPEN_PREVIOUS_BOOK; oldToNewNames["5"] = ActionCode::SHOW_TOC; oldToNewNames["15"] = ActionCode::SCROLL_TO_HOME; oldToNewNames["16"] = ActionCode::SCROLL_TO_START_OF_TEXT; oldToNewNames["17"] = ActionCode::SCROLL_TO_END_OF_TEXT; oldToNewNames["33"] = ActionCode::GOTO_NEXT_TOC_SECTION; oldToNewNames["34"] = ActionCode::GOTO_PREVIOUS_TOC_SECTION; oldToNewNames["9"] = ActionCode::PAGE_SCROLL_FORWARD; oldToNewNames["10"] = ActionCode::PAGE_SCROLL_BACKWARD; oldToNewNames["11"] = ActionCode::LINE_SCROLL_FORWARD; oldToNewNames["12"] = ActionCode::LINE_SCROLL_BACKWARD; oldToNewNames["3"] = ActionCode::UNDO; oldToNewNames["4"] = ActionCode::REDO; oldToNewNames["35"] = ActionCode::COPY_SELECTED_TEXT_TO_CLIPBOARD; oldToNewNames["37"] = ActionCode::OPEN_SELECTED_TEXT_IN_DICTIONARY; oldToNewNames["36"] = ActionCode::CLEAR_SELECTION; oldToNewNames["6"] = ActionCode::SEARCH; oldToNewNames["7"] = ActionCode::FIND_PREVIOUS; oldToNewNames["8"] = ActionCode::FIND_NEXT; oldToNewNames["19"] = ActionCode::INCREASE_FONT; oldToNewNames["20"] = ActionCode::DECREASE_FONT; oldToNewNames["21"] = ActionCode::SHOW_HIDE_POSITION_INDICATOR; oldToNewNames["22"] = ActionCode::TOGGLE_FULLSCREEN; oldToNewNames["23"] = ActionCode::FULLSCREEN_ON; oldToNewNames["27"] = ActionCode::ROTATE_SCREEN; oldToNewNames["2"] = ActionCode::SHOW_OPTIONS_DIALOG; oldToNewNames["25"] = ActionCode::SHOW_BOOK_INFO_DIALOG; oldToNewNames["24"] = ActionCode::ADD_BOOK; oldToNewNames["18"] = ActionCode::CANCEL; oldToNewNames["29"] = ActionCode::QUIT; changeActionNames(oldToNewNames, "Keys"); changeActionNames(oldToNewNames, "Keys90"); changeActionNames(oldToNewNames, "Keys180"); changeActionNames(oldToNewNames, "Keys270"); } Migration_0_8_11::Migration_0_8_11() : Migration("0.8.11") { } void Migration_0_8_11::doMigrationInternal() { moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "ScrollingDelay", ZLCategoryKey::CONFIG, "TapScrolling", "ScrollingDelay", "0" ); moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "Mode", ZLCategoryKey::CONFIG, "TapScrolling", "Mode", "0" ); moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "LinesToKeep", ZLCategoryKey::CONFIG, "TapScrolling", "LinesToKeep", "1" ); moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "LinesToScroll", ZLCategoryKey::CONFIG, "TapScrolling", "LinesToScroll", "1" ); moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "PercentToScroll", ZLCategoryKey::CONFIG, "TapScrolling", "PercentToScroll", "50" ); moveOption( ZLCategoryKey::CONFIG, "FingerTapScrolling", "Enabled", ZLCategoryKey::CONFIG, "TapScrolling", "Enabled", "true" ); moveOption( ZLCategoryKey::CONFIG, "Options", "ScrollingDelay", ZLCategoryKey::CONFIG, "LargeScrolling", "ScrollingDelay", "250" ); changeActionNames(); } fbreader-0.99.4.orig/fbreader/src/migration/Migration_0_11_0.cpp0000644000706400070640000004623112056124565022656 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include #include #include #include "BookInfo.h" #include "Migration.h" #include "../options/FBCategoryKey.h" #include "../formats/FormatPlugin.h" #include "../database/booksdb/BooksDBUtil.h" #include "../database/booksdb/BooksDB.h" #include "../library/Book.h" #include "../library/Tag.h" static const std::string BOOK_LIST_GROUP = "BookList"; static const std::string BOOK_LIST_SIZE = "Size"; static const std::string BOOK_LIST_PREFIX = "Book"; static const std::string CURRENT_STATE_GROUP = "State"; static const std::string RECENT_BOOKS_GROUP = "LastOpenedBooks"; static const std::string BOOK = "Book"; static const std::size_t MaxXmlListSize = 10; static const std::string PARAGRAPH_OPTION_NAME = "Paragraph"; static const std::string WORD_OPTION_NAME = "Word"; static const std::string CHAR_OPTION_NAME = "Char"; static const std::string POSITION_IN_BUFFER = "PositionInBuffer"; static const std::string BUFFER_SIZE = "UndoBufferSize"; static const char * const BUFFER_PARAGRAPH_PREFIX = "Paragraph_"; static const char * const BUFFER_WORD_PREFIX = "Word_"; static const int MaxXmlStackSize = 20; static const std::string SIZE = "Size"; static const std::string ENTRIES_NUMBER = "EntriesNumber"; static const std::string PALM_TYPE = "PalmType"; static const std::string NET_FILES_GROUP = "Files"; class Migration_0_11_0_Runnable : public DBRunnable { public: bool run(); private: bool migrateBooks(); bool migrateBookList(); bool migrateState(); bool migrateNetwork(); bool migrateBook(const ZLFile &file); std::string tags2string(const TagList &tags); bool stringEquals(const std::string &tags1, const std::string &tags2); bool migrateRecentBooks(); bool migrateBooksState(); bool migrateBookStateStack(const std::string &fileName, const Book &book); bool migrateBookLastState(const std::string &fileName, const Book &book); bool shouldReadDisk(const std::string &fileName); bool clearBooksOptions(); static void moveOption(const ZLCategoryKey &category, const std::string &oldGroup, const std::string &newGroup, const std::string &name, const std::string &defaultValue); static void moveOption(const ZLCategoryKey &category, const std::string &oldGroup, const std::string &newGroup, const std::string &name, int defaultValue); static void movePercentGroups(std::vector &optionGroups); static void moveBookGroup(const std::string &oldgroup, const std::string &newgroup); private: std::map > myBooks; }; inline bool Migration_0_11_0_Runnable::shouldReadDisk(const std::string &fileName) { const std::string ext = ZLFile(fileName).extension(); return ext == "fb2" || ext == "epub" || ext == "mobi" || ext == "oebzip" || ext == "opf"; //return ext == "fb2"; //return true; } void Migration_0_11_0_Runnable::moveOption(const ZLCategoryKey &category, const std::string &oldGroup, const std::string &newGroup, const std::string &name, const std::string &defaultValue) { ZLStringOption newOption(category, newGroup, name, defaultValue); ZLStringOption oldOption(category, oldGroup, name, defaultValue); newOption.setValue(oldOption.value()); oldOption.setValue(defaultValue); } void Migration_0_11_0_Runnable::moveOption(const ZLCategoryKey &category, const std::string &oldGroup, const std::string &newGroup, const std::string &name, int defaultValue) { ZLIntegerOption newOption(category, newGroup, name, defaultValue); ZLIntegerOption oldOption(category, oldGroup, name, defaultValue); newOption.setValue(oldOption.value()); oldOption.setValue(defaultValue); } static bool percentPathPredicate(const std::string &path) { static const std::string _start = "%APPLICATION_PATH%"; return ZLStringUtil::stringStartsWith(path, _start); } void Migration_0_11_0_Runnable::movePercentGroups(std::vector &optionGroups) { std::vector::iterator it = optionGroups.begin(); while ((it = std::find_if(it, optionGroups.end(), percentPathPredicate)) != optionGroups.end()) { const std::string oldgroup = *it; const std::string newgroup = ZLFile(oldgroup).resolvedPath(); if (std::find(optionGroups.begin(), optionGroups.end(), newgroup) == optionGroups.end()) { moveBookGroup(oldgroup, newgroup); *it++ = newgroup; } else { if (BookInfo(newgroup).TitleOption.value().empty()) { moveBookGroup(oldgroup, newgroup); } it = optionGroups.erase(it); } ZLOption::clearGroup(oldgroup); } } void Migration_0_11_0_Runnable::moveBookGroup(const std::string &oldgroup, const std::string &newgroup) { BookInfo oldbi(oldgroup); BookInfo newbi(newgroup); newbi = oldbi; oldbi.reset(); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, PARAGRAPH_OPTION_NAME, 0); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, WORD_OPTION_NAME, 0); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, CHAR_OPTION_NAME, 0); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, POSITION_IN_BUFFER, 0); int stackSize = ZLIntegerOption(ZLCategoryKey::STATE, oldgroup, BUFFER_SIZE, 0).value(); for (int i = 0; i < stackSize; ++i) { std::string bufferParagraph = BUFFER_PARAGRAPH_PREFIX; std::string bufferWord = BUFFER_WORD_PREFIX; ZLStringUtil::appendNumber(bufferParagraph, i); ZLStringUtil::appendNumber(bufferWord, i); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, bufferParagraph, -1); moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, bufferWord, -1); } moveOption(ZLCategoryKey::STATE, oldgroup, newgroup, BUFFER_SIZE, 0); } Migration_0_11_0::Migration_0_11_0() : Migration("0.11.0") { } void Migration_0_11_0::doMigrationInternal() { Migration_0_11_0_Runnable r; BooksDB::Instance().executeAsTransaction(r); //r.run(); } bool Migration_0_11_0_Runnable::run() { const ZLTime start; if (!migrateBooks()) { std::cerr << std::endl << "VERDICT: migrateBooks failed" << std::endl << std::endl; } std::cerr << "migration total 0: " << ZLTime().millisecondsFrom(start) << "ms" << std::endl; if (!migrateBookList()) { std::cerr << std::endl << "VERDICT: migrateBookList failed" << std::endl << std::endl; } std::cerr << "migration total 1: " << ZLTime().millisecondsFrom(start) << "ms" << std::endl; if (!migrateState()) { std::cerr << std::endl << "VERDICT: migrateState failed" << std::endl << std::endl; } std::cerr << "migration total 2: " << ZLTime().millisecondsFrom(start) << "ms" << std::endl; if (!migrateNetwork()) { std::cerr << std::endl << "VERDICT: migrateNetwork failed" << std::endl << std::endl; } std::cerr << "migration total 3: " << ZLTime().millisecondsFrom(start) << "ms" << std::endl; if (!clearBooksOptions()) { std::cerr << std::endl << "VERDICT: clearBooksOptions failed" << std::endl << std::endl; } std::cerr << "migration total 4: " << ZLTime().millisecondsFrom(start) << "ms" << std::endl; return true; } bool Migration_0_11_0_Runnable::migrateBooks() { /*std::map ext2time; std::map ext2num; unsigned long totalTime = 0, totalNum = 0;*/ PluginCollection &collection = PluginCollection::Instance(); std::vector optionGroups; ZLOption::listOptionGroups(optionGroups); movePercentGroups(optionGroups); bool res = true; for (std::vector::const_iterator it = optionGroups.begin(); it != optionGroups.end(); ++it) { const std::string &name = *it; if (Migration::isLikeToFileName(name)) { /* TODO: check correctness of migration order: * 1) palmType * 2) size * 3) book (depends on palmType and size) */ const std::string palmType = ZLStringOption(FBCategoryKey::BOOKS, name, PALM_TYPE, "").value(); if (!palmType.empty()) { BooksDB::Instance().setPalmType(name, palmType); } ZLStringOption(FBCategoryKey::BOOKS, name, PALM_TYPE, "").setValue(""); // clean books.xml ZLFile file(name); if (file.physicalFilePath() == name) { int size = ZLIntegerOption(FBCategoryKey::BOOKS, name, SIZE, -1).value(); if (size != -1) { BooksDB::Instance().setFileSize(name, size); } } if (collection.plugin(file, false) != 0) { if (!BookInfo(name).TitleOption.value().empty()) { //ZLTime start; if (!migrateBook(ZLFile(name))) { std::cerr << "ERROR(2): migrateBook failed" << std::endl; res = false; } /*ZLTime end; { unsigned time = end.millisecondsFrom(start); std::string ext = ZLFile(name).extension(); totalTime += time; totalNum += 1; ext2time[ext] += time; ext2num[ext] += 1; }*/ } BookInfo(name).reset(); // clean books.xml } else { ZLOption::clearGroup(name); // clean books.xml } ZLIntegerOption(FBCategoryKey::BOOKS, name, SIZE, -1).setValue(-1); // clean books.xml if (!ZLStringOption(FBCategoryKey::BOOKS, name, ENTRIES_NUMBER, "").value().empty()) { ZLOption::clearGroup(name); // clean books.xml } } } /*std::cerr << " ext" << " time,ms" << " time/total,%" << " number of books" << " time for 1 book,ms" << std::endl; std::cerr << "---------------------------------------------------------------------------" << std::endl; for (std::map::const_iterator it = ext2time.begin(); it != ext2time.end(); ++it) { const std::string &ext = it->first; unsigned long time = it->second; unsigned long num = ext2num[ext]; std::cerr << std::setw(8) << ext << std::setw(10) << time << std::setw(15) << ((float) time) / totalTime * 100.0 << std::setw(18) << num << std::setw(22) << ((float) time) / num << std::endl; } std::cerr << "---------------------------------------------------------------------------" << std::endl; std::cerr << "total:" << std::endl; std::cerr << std::setw(8) << "" << std::setw(10) << totalTime << std::setw(15) << "" << std::setw(20) << totalNum << std::setw(20) << "" << std::endl;*/ return res; } bool Migration_0_11_0_Runnable::migrateBook(const ZLFile &file) { shared_ptr infoBook = Book::loadFromBookInfo(file); if (infoBook.isNull()) { std::cerr << "ERROR: loading book from BookInfo failed: " << file.path() << std::endl; return false; } if (shouldReadDisk(file.path()) && BooksDBUtil::isBookFull(*infoBook)) { shared_ptr fileBook = Book::loadFromFile(file); //shared_ptr fileBook = infoBook; //shared_ptr fileBook; if (!fileBook.isNull()) { std::string tagList1 = tags2string(infoBook->tags()); std::string tagList2 = tags2string(fileBook->tags()); if (stringEquals(tagList1, tagList2)) { infoBook->removeAllTags(); const TagList &tList = fileBook->tags(); for (TagList::const_iterator it = tList.begin(); it != tList.end(); ++it) { infoBook->addTag(*it); } } } } myBooks.insert(std::make_pair(file.path(), infoBook)); const bool code = BooksDB::Instance().saveBook(infoBook); if (!code) { std::cerr << "ERROR: saving book to database failed: " << file.path() << std::endl; } return code; } std::string Migration_0_11_0_Runnable::tags2string(const TagList &tags) { std::string tagList; TagList::const_iterator it = tags.begin(); if (it != tags.end()) { tagList += (*it++)->fullName(); while (it != tags.end()) { tagList += ','; tagList += (*it++)->fullName(); } } return tagList; } bool Migration_0_11_0_Runnable::stringEquals(const std::string &tags1, const std::string &tags2) { std::size_t i1 = 0; std::size_t i2 = 0; while (i1 < tags1.size() && i2 < tags2.size()) { if (std::isspace(tags1[i1])) { ++i1; continue; } if (std::isspace(tags2[i2])) { ++i2; continue; } if (tags1[i1++] != tags2[i2++]) { return false; } } if (i1 == tags1.size() && i2 < tags2.size()) { while (i2 < tags2.size()) { if (!std::isspace(tags2[i2++])) { return false; } } return true; } if (i1 < tags1.size() && i2 == tags2.size()) { while (i1 < tags1.size()) { if (!std::isspace(tags1[i1++])) { return false; } } return true; } return true; } bool Migration_0_11_0_Runnable::migrateBookList() { bool res = true; int size = ZLIntegerOption(ZLCategoryKey::STATE, BOOK_LIST_GROUP, BOOK_LIST_SIZE, 0).value(); for (int i = 0; i < size; ++i) { std::string optionName = BOOK_LIST_PREFIX; ZLStringUtil::appendNumber(optionName, i); const std::string &fileName = ZLStringOption(ZLCategoryKey::STATE, BOOK_LIST_GROUP, optionName, "").value(); if (!fileName.empty()) { std::map >::iterator it = myBooks.find(fileName); if (it != myBooks.end()) { shared_ptr book = it->second; if (!book.isNull() && book->bookId() != 0) { if (!BooksDB::Instance().insertIntoBookList(*book)) { std::cerr << "ERROR: insert into BookList failed: " << fileName << std::endl; res = false; } } } } } ZLOption::clearGroup(BOOK_LIST_GROUP); // clean state.xml return res; } bool Migration_0_11_0_Runnable::migrateState() { bool res = true; if (!migrateRecentBooks()) { std::cerr << "ERROR(2): migrateRecentBooks failed" << std::endl; res = false; } if (!migrateBooksState()) { std::cerr << "ERROR(2): migrateBooksState failed" << std::endl; res = false; } ZLOption::clearGroup(RECENT_BOOKS_GROUP); // clean state.xml ZLOption::clearGroup(CURRENT_STATE_GROUP); // clean state.xml return res; } bool Migration_0_11_0_Runnable::migrateRecentBooks() { BookList books; for (std::size_t i = 0; i < MaxXmlListSize; ++i) { std::string num = BOOK; ZLStringUtil::appendNumber(num, i); std::string name = ZLStringOption(ZLCategoryKey::STATE, RECENT_BOOKS_GROUP, num, "").value(); if (!name.empty()) { //shared_ptr book = BooksDBUtil::getBook(name, false); std::map >::const_iterator it = myBooks.find(name); if (it == myBooks.end()) { if ((it = myBooks.find(ZLFile(name).resolvedPath())) == myBooks.end()) { continue; } } shared_ptr book = it->second; if (!book.isNull() && book->bookId() != 0 && std::find(books.begin(), books.end(), book) == books.end()) { books.push_back(book); } } } bool res = BooksDB::Instance().saveRecentBooks(books); if (!res) { std::cerr << "ERROR: saving recent books list failed (" << books.size() << " item[s])" << std::endl; } return res; } bool Migration_0_11_0_Runnable::migrateBooksState() { bool res = true; for (std::map >::const_iterator it = myBooks.begin(); it != myBooks.end(); ++it) { const std::string &fileName = it->first; if (it->second.isNull()) { std::cerr << "ERROR: book in map is null: " << fileName << std::endl; res = false; continue; } const Book &book = *it->second; if (!migrateBookStateStack(fileName, book)) { res = false; } if (!migrateBookLastState(fileName, book)) { res = false; } } return res; } bool Migration_0_11_0_Runnable::migrateBookStateStack(const std::string &fileName, const Book &book) { std::deque stack; bool res = true; int stackSize = ZLIntegerOption(ZLCategoryKey::STATE, fileName, BUFFER_SIZE, 0).value(); if (stackSize > 0) { if (stackSize > MaxXmlStackSize) { stackSize = MaxXmlStackSize; } for (int i = 0; i < stackSize; ++i) { std::string bufferParagraph = BUFFER_PARAGRAPH_PREFIX; std::string bufferWord = BUFFER_WORD_PREFIX; ZLStringUtil::appendNumber(bufferParagraph, i); ZLStringUtil::appendNumber(bufferWord, i); ReadingState pos( ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferParagraph, -1).value(), ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferWord, -1).value(), 0 ); stack.push_back(pos); ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferParagraph, -1).setValue(-1); // clean state.xml ZLIntegerOption(ZLCategoryKey::STATE, fileName, bufferWord, -1).setValue(-1); // clean state.xml } if (!BooksDB::Instance().saveBookStateStack(book, stack)) { std::cerr << "ERROR: saving book state stack failed: " << fileName << std::endl; res = false; } stack.clear(); } ZLIntegerOption(ZLCategoryKey::STATE, fileName, BUFFER_SIZE, 0).setValue(0); // clean state.xml return res; } bool Migration_0_11_0_Runnable::migrateBookLastState(const std::string &fileName, const Book &book) { const ReadingState state( ZLIntegerOption(ZLCategoryKey::STATE, fileName, PARAGRAPH_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, fileName, WORD_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, fileName, CHAR_OPTION_NAME, 0).value() ); const int stackPos = ZLIntegerOption(ZLCategoryKey::STATE, fileName, POSITION_IN_BUFFER, 0).value(); if (state.Paragraph == 0 && state.Word == 0 && state.Character == 0 && stackPos == 0) { return true; } ZLIntegerOption(ZLCategoryKey::STATE, fileName, PARAGRAPH_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, fileName, WORD_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, fileName, CHAR_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, fileName, POSITION_IN_BUFFER, 0).setValue(0); bool res1 = BooksDB::Instance().setBookState(book, state); bool res2 = BooksDB::Instance().setStackPos(book, stackPos); if (!res1) { std::cerr << "ERROR: saving book last state failed: " << fileName << std::endl; } if (!res2) { std::cerr << "ERROR: saving book state stack position failed: " << fileName << std::endl; } return res1 && res2; } bool Migration_0_11_0_Runnable::migrateNetwork() { bool res = true; // FBReader desktop 0.99.1 deprecates NetFiles table, so don't fill it // std::vector urls; // ZLOption::listOptionNames(NET_FILES_GROUP, urls); // for (std::vector::const_iterator it = urls.begin(); it != urls.end(); ++it) { // const std::string &url = *it; // const std::string fileName = ZLStringOption(ZLCategoryKey::NETWORK, NET_FILES_GROUP, url, "").value(); // if (!BooksDB::Instance().setNetFile(url, fileName)) { // std::cerr << "ERROR: saving file's URL failed: " << std::endl // << "\tURL = " << url << std::endl // << "\tfileName = " << fileName << std::endl; // res = false; // } // } ZLOption::clearGroup(NET_FILES_GROUP); // clean state.xml return res; } bool Migration_0_11_0_Runnable::clearBooksOptions() { bool res = true; for (std::map >::const_iterator it = myBooks.begin(); it != myBooks.end(); ++it) { const std::string &fileName = it->first; if (it->second.isNull()) { std::cerr << "ERROR: book in map is null in clearBooksOptions: " << fileName << std::endl; res = false; continue; } ZLOption::clearGroup(fileName); // clear books.xml & state.xml } return res; } fbreader-0.99.4.orig/fbreader/src/migration/OEBMigrationReader.cpp0000644000706400070640000000456712056124565023376 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include "OEBMigrationReader.h" OEBMigrationReader::OEBMigrationReader(BookInfo &info) : myInfo(info) { } static const std::string METADATA = "metadata"; static const std::string DC_METADATA = "dc-metadata"; void OEBMigrationReader::characterDataHandler(const char *text, std::size_t len) { if (myReadSubject) { myBuffer.append(text, len); } } bool OEBMigrationReader::testDCTag(const std::string &name, const std::string &tag) const { return testTag(ZLXMLNamespace::DublinCore, name, tag) || testTag(ZLXMLNamespace::DublinCoreLegacy, name, tag); } void OEBMigrationReader::startElementHandler(const char *tag, const char**) { const std::string tagString = ZLUnicodeUtil::toLower(tag); if ((METADATA == tagString) || (DC_METADATA == tagString)) { myDCMetadataTag = tagString; myReadMetaData = true; } else if (myReadMetaData) { if (testDCTag("subject", tagString)) { myReadSubject = true; } } } void OEBMigrationReader::endElementHandler(const char *tag) { const std::string tagString = ZLUnicodeUtil::toLower(tag); if (myDCMetadataTag == tagString) { interrupt(); } else if (myReadSubject) { ZLUnicodeUtil::utf8Trim(myBuffer); if (!myBuffer.empty()) { if (!myTagList.empty()) { myTagList += ','; } myTagList += myBuffer; myBuffer.erase(); } myReadSubject = false; } } bool OEBMigrationReader::processNamespaces() const { return true; } void OEBMigrationReader::doRead(const ZLFile &file) { myReadMetaData = false; myReadSubject = false; readDocument(file); myInfo.TagsOption.setValue(myTagList); } fbreader-0.99.4.orig/fbreader/src/migration/BookInfo.cpp0000644000706400070640000000501712056124565021471 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include "BookInfo.h" #include "../options/FBCategoryKey.h" static const std::string EMPTY = ""; BookInfo::BookInfo(const std::string &fileName) : AuthorDisplayNameOption(FBCategoryKey::BOOKS, fileName, "AuthorDisplayName", EMPTY), AuthorSortKeyOption(FBCategoryKey::BOOKS, fileName, "AuthorSortKey", EMPTY), TitleOption(FBCategoryKey::BOOKS, fileName, "Title", EMPTY), SeriesTitleOption(FBCategoryKey::BOOKS, fileName, "Sequence", EMPTY), IndexInSeriesOption(FBCategoryKey::BOOKS, fileName, "Series Number in Sequence", EMPTY), LanguageOption(FBCategoryKey::BOOKS, fileName, "Language", EMPTY), EncodingOption(FBCategoryKey::BOOKS, fileName, "Encoding", EMPTY), TagsOption(FBCategoryKey::BOOKS, fileName, "TagList", EMPTY) { } void BookInfo::reset() { AuthorDisplayNameOption.setValue(EMPTY); AuthorSortKeyOption.setValue(EMPTY); TitleOption.setValue(EMPTY); SeriesTitleOption.setValue(EMPTY); IndexInSeriesOption.setValue(EMPTY); LanguageOption.setValue(EMPTY); EncodingOption.setValue(EMPTY); TagsOption.setValue(EMPTY); } bool BookInfo::isFull() const { return !AuthorDisplayNameOption.value().empty() && !AuthorSortKeyOption.value().empty() && !TitleOption.value().empty() && !EncodingOption.value().empty(); } const BookInfo &BookInfo::operator = (const BookInfo &bi) { AuthorDisplayNameOption.setValue(bi.AuthorDisplayNameOption.value()); AuthorSortKeyOption.setValue(bi.AuthorSortKeyOption.value()); TitleOption.setValue(bi.TitleOption.value()); SeriesTitleOption.setValue(bi.SeriesTitleOption.value()); IndexInSeriesOption.setValue(bi.IndexInSeriesOption.value()); LanguageOption.setValue(bi.LanguageOption.value()); EncodingOption.setValue(bi.EncodingOption.value()); TagsOption.setValue(bi.TagsOption.value()); return bi; } fbreader-0.99.4.orig/fbreader/src/migration/OEBMigrationReader.h0000644000706400070640000000301212056124565023023 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __OEBMIGRATIONREADER_H__ #define __OEBMIGRATIONREADER_H__ #include #include #include "BookInfo.h" class OEBMigrationReader : public ZLXMLReader { public: OEBMigrationReader(BookInfo &info); void doRead(const ZLFile &file); void startElementHandler(const char *tag, const char **attributes); void endElementHandler(const char *tag); void characterDataHandler(const char *text, std::size_t len); bool processNamespaces() const; private: bool testDCTag(const std::string &name, const std::string &tag) const; private: BookInfo &myInfo; bool myReadMetaData; bool myReadSubject; std::string myDCMetadataTag; std::string myBuffer; std::string myTagList; }; #endif /* __OEBMIGRATIONREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/external/0000755000706400070640000000000012056124565017105 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/external/ProgramCollection.cpp0000644000706400070640000001527212056124565023243 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "ProgramCollection.h" #include "../options/FBCategoryKey.h" class ProgramCollectionBuilder : public ZLXMLReader { public: ProgramCollectionBuilder(ProgramCollectionMap &collectionMap); ~ProgramCollectionBuilder(); private: void startElementHandler(const char *tag, const char **attributes); void endElementHandler(const char *tag); private: ProgramCollectionMap &myCollectionMap; shared_ptr myCurrentCollection; shared_ptr myCurrentProgram; }; static const std::string SECTION = "section"; static const std::string PROGRAM = "program"; static const std::string ACTION = "action"; static const std::string OPTION = "option"; ProgramCollectionBuilder::ProgramCollectionBuilder(ProgramCollectionMap &collectionMap) : myCollectionMap(collectionMap) { } ProgramCollectionBuilder::~ProgramCollectionBuilder() { } void ProgramCollectionBuilder::startElementHandler(const char *tag, const char **attributes) { if (SECTION == tag) { const char *name = attributeValue(attributes, "name"); if (name != 0) { myCurrentCollection = myCollectionMap.myMap[name]; if (myCurrentCollection.isNull()) { myCurrentCollection = new ProgramCollection(name); myCollectionMap.myMap[name] = myCurrentCollection; } } } else if (!myCurrentCollection.isNull() && (PROGRAM == tag)) { const char *name = attributeValue(attributes, "name"); const char *protocol = attributeValue(attributes, "protocol"); const char *testFile = attributeValue(attributes, "testFile"); if ((name != 0) && (protocol != 0)) { shared_ptr channel = ZLCommunicationManager::Instance().createMessageOutputChannel(protocol, (testFile != 0) ? testFile : ""); if (!channel.isNull()) { std::string sName = name; if (!sName.empty()) { if (sName[0] == '%') { sName = ZLResource::resource("external")[sName.substr(1)].value(); } myCurrentProgram = new Program(sName, channel); myCurrentCollection->myNames.push_back(sName); myCurrentCollection->myPrograms[sName] = myCurrentProgram; } } } } else if (!myCurrentProgram.isNull() && (ACTION == tag)) { const char *name = attributeValue(attributes, "name"); if (name != 0) { static const std::string NAME = "name"; ZLCommunicationManager::Data &data = myCurrentProgram->myCommandData[name]; for (const char **it = attributes; (*it != 0) && (*(it + 1) != 0); it += 2) { if (NAME != *it) { data[*it] = *(it + 1); } } } } else if (!myCurrentProgram.isNull() && (OPTION == tag)) { const char *name = attributeValue(attributes, "name"); if (name != 0) { const char *defaultValue = attributeValue(attributes, "defaultValue"); const std::string sName = name; const std::string sDefaultValue = (defaultValue != 0) ? defaultValue : std::string(); myCurrentProgram->myOptions.push_back(Program::OptionDescription(sName, sDefaultValue)); myCurrentProgram->myDefaultValues[sName] = sDefaultValue; } } } void ProgramCollectionBuilder::endElementHandler(const char *tag) { if (SECTION == tag) { if (!myCurrentCollection.isNull()) { const std::vector &names = myCurrentCollection->names(); ZLStringOption &nameOption = myCurrentCollection->CurrentNameOption; if (!names.empty() && (std::find(names.begin(), names.end(), nameOption.value()) == names.end())) { nameOption.setValue(names.front()); } } myCurrentCollection = 0; myCurrentProgram = 0; } else if (PROGRAM == tag) { myCurrentProgram = 0; } } ProgramCollectionMap::ProgramCollectionMap() { ProgramCollectionBuilder builder(*this); builder.readDocument(ZLFile(ZLibrary::DefaultFilesPathPrefix() + "external.xml")); } shared_ptr ProgramCollectionMap::collection(const std::string &name) const { std::map >::const_iterator it = myMap.find(name); return (it != myMap.end()) ? it->second : 0; } ProgramCollection::ProgramCollection(const std::string &name) : EnableCollectionOption(ZLCategoryKey::CONFIG, name, "Enabled", true), CurrentNameOption(ZLCategoryKey::CONFIG, name, "Name", "") { } const std::vector &ProgramCollection::names() const { return myNames; } shared_ptr ProgramCollection::program(const std::string &name) const { std::map >::const_iterator it = myPrograms.find(name); return (it != myPrograms.end()) ? it->second : 0; } shared_ptr ProgramCollection::currentProgram() const { if (!EnableCollectionOption.value()) { return 0; } return program(CurrentNameOption.value()); } Program::Program(const std::string &name, shared_ptr channel) : myName(name), myChannel(channel) { } void Program::run(const std::string &command, const std::string ¶meter) const { if (!myChannel.isNull()) { std::map::const_iterator it = myCommandData.find(command); if (it != myCommandData.end()) { ZLCommunicationManager::Data data = it->second; for (ZLCommunicationManager::Data::iterator jt = data.begin(); jt != data.end(); ++jt) { if (!jt->second.empty() && jt->second[0] == '%') { const std::string optionName = jt->second.substr(1); std::map::const_iterator st = myDefaultValues.find(optionName); jt->second = ZLStringOption( FBCategoryKey::EXTERNAL, myName, optionName, (st != myDefaultValues.end()) ? st->second : "").value(); } } shared_ptr sender = myChannel->createSender(data); if (!sender.isNull()) { sender->sendStringMessage(parameter); } } } } const std::vector &Program::options() const { return myOptions; } Program::OptionDescription::OptionDescription(const std::string &name, const std::string &defaultValue) : OptionName(name), DefaultValue(defaultValue) { } fbreader-0.99.4.orig/fbreader/src/external/ProgramCollection.h0000644000706400070640000000470312056124565022705 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __PROGRAMCOLLECTION_H__ #define __PROGRAMCOLLECTION_H__ #include #include #include #include #include #include class Program { private: Program(const std::string &name, shared_ptr channel); public: void run(const std::string &command, const std::string ¶meter) const; public: struct OptionDescription { OptionDescription(const std::string &name, const std::string &defaultValue); std::string OptionName; std::string DefaultValue; }; const std::vector &options() const; private: const std::string myName; shared_ptr myChannel; std::map myCommandData; std::vector myOptions; std::map myDefaultValues; friend class ProgramCollection; friend class ProgramCollectionBuilder; }; class ProgramCollection { public: mutable ZLBooleanOption EnableCollectionOption; mutable ZLStringOption CurrentNameOption; public: ProgramCollection(const std::string &name); const std::vector &names() const; shared_ptr currentProgram() const; shared_ptr program(const std::string &name) const; private: std::vector myNames; std::map > myPrograms; friend class ProgramCollectionBuilder; }; class ProgramCollectionMap { public: ProgramCollectionMap(); shared_ptr collection(const std::string &name) const; private: std::map > myMap; friend class ProgramCollectionBuilder; }; #endif /* __PROGRAMCOLLECTION_H__ */ fbreader-0.99.4.orig/fbreader/src/encodingOption/0000755000706400070640000000000012056124565020242 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/encodingOption/EncodingOptionEntry.h0000644000706400070640000000412512056124565024356 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __ENCODINGOPTIONENTRY_H__ #define __ENCODINGOPTIONENTRY_H__ #include #include class AbstractEncodingEntry : public ZLComboOptionEntry { public: AbstractEncodingEntry(const std::string ¤tValue); const std::string &initialValue() const; const std::vector &values() const; void onAccept(const std::string &value); void onValueSelected(int index); virtual void onAcceptValue(const std::string &value) = 0; private: std::vector mySetNames; std::map > myValues; mutable std::map myInitialValues; std::map myValueByName; std::string myInitialSetName; friend class EncodingSetEntry; }; class EncodingEntry : public AbstractEncodingEntry { public: EncodingEntry(ZLStringOption &encodingOption); void onAcceptValue(const std::string &value); private: ZLStringOption &myEncodingOption; }; class EncodingSetEntry : public ZLComboOptionEntry { public: EncodingSetEntry(AbstractEncodingEntry &encodingEntry); const std::string &initialValue() const; const std::vector &values() const; void onAccept(const std::string&) {} void onValueSelected(int index); private: AbstractEncodingEntry &myEncodingEntry; }; #endif /* __ENCODINGOPTIONENTRY_H__ */ fbreader-0.99.4.orig/fbreader/src/encodingOption/EncodingOptionEntry.cpp0000644000706400070640000000757712056124565024727 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "EncodingOptionEntry.h" #include "../library/Book.h" AbstractEncodingEntry::AbstractEncodingEntry(const std::string ¤tValue) { if (currentValue == Book::AutoEncoding) { myInitialSetName = currentValue; myInitialValues[currentValue] = currentValue; setActive(false); return; } const std::string &value = ZLUnicodeUtil::toLower(currentValue); const std::vector > &sets = ZLEncodingCollection::Instance().sets(); for (std::vector >::const_iterator it = sets.begin(); it != sets.end(); ++it) { const std::vector &infos = (*it)->infos(); mySetNames.push_back((*it)->name()); std::vector &names = myValues[(*it)->name()]; for (std::vector::const_iterator jt = infos.begin(); jt != infos.end(); ++jt) { const std::vector &aliases = (*jt)->aliases(); for (std::vector::const_iterator kt = aliases.begin(); kt != aliases.end(); ++kt) { if (value == ZLUnicodeUtil::toLower(*kt)) { myInitialSetName = (*it)->name(); myInitialValues[myInitialSetName] = (*jt)->visibleName(); break; } } names.push_back((*jt)->visibleName()); myValueByName[(*jt)->visibleName()] = (*jt)->name(); } } if (myInitialSetName.empty()) { myInitialSetName = mySetNames[0]; } } const std::vector &AbstractEncodingEntry::values() const { if (initialValue() == Book::AutoEncoding) { static std::vector AUTO_ENCODING; if (AUTO_ENCODING.empty()) { AUTO_ENCODING.push_back(Book::AutoEncoding); } return AUTO_ENCODING; } std::map >::const_iterator it = myValues.find(myInitialSetName); return it->second; } const std::string &AbstractEncodingEntry::initialValue() const { if (myInitialValues[myInitialSetName].empty()) { std::map >::const_iterator it = myValues.find(myInitialSetName); myInitialValues[myInitialSetName] = it->second[0]; } return myInitialValues[myInitialSetName]; } void AbstractEncodingEntry::onAccept(const std::string &value) { if (initialValue() != Book::AutoEncoding) { onAcceptValue(myValueByName[value]); } } void AbstractEncodingEntry::onValueSelected(int index) { myInitialValues[myInitialSetName] = values()[index]; } EncodingEntry::EncodingEntry(ZLStringOption &encodingOption) : AbstractEncodingEntry(encodingOption.value()), myEncodingOption(encodingOption) { } void EncodingEntry::onAcceptValue(const std::string &value) { myEncodingOption.setValue(value); } EncodingSetEntry::EncodingSetEntry(AbstractEncodingEntry &encodingEntry) : myEncodingEntry(encodingEntry) { } const std::string &EncodingSetEntry::initialValue() const { return myEncodingEntry.myInitialSetName; } const std::vector &EncodingSetEntry::values() const { return myEncodingEntry.mySetNames; } void EncodingSetEntry::onValueSelected(int index) { myEncodingEntry.myInitialSetName = values()[index]; myEncodingEntry.resetView(); } fbreader-0.99.4.orig/fbreader/src/options/0000755000706400070640000000000012056124565016756 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/options/FBCategoryKey.h0000644000706400070640000000215412056124565021567 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBCATEGORYKEY_H__ #define __FBCATEGORYKEY_H__ #include class FBCategoryKey : public ZLCategoryKey { public: static const FBCategoryKey BOOKS; static const FBCategoryKey SEARCH; static const FBCategoryKey EXTERNAL; private: FBCategoryKey(const std::string &name); }; #endif /* __FBCATEGORYKEY_H__ */ fbreader-0.99.4.orig/fbreader/src/options/FBOptions.h0000644000706400070640000000324512056124565020776 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBOPTIONS_H__ #define __FBOPTIONS_H__ #include #include #include #include #include class FBOptions { public: static FBOptions& Instance(); private: static FBOptions *ourInstance; public: ZLIntegerRangeOption LeftMarginOption; ZLIntegerRangeOption RightMarginOption; ZLIntegerRangeOption TopMarginOption; ZLIntegerRangeOption BottomMarginOption; ZLColorOption BackgroundColorOption; ZLColorOption RegularTextColorOption; ZLColorOption &colorOption(const std::string &style); private: FBOptions(); FBOptions(const FBOptions&); const FBOptions &operator = (const FBOptions&); private: std::map > myColorOptions; }; inline FBOptions& FBOptions::Instance() { if (ourInstance == 0) { ourInstance = new FBOptions(); } return *ourInstance; } #endif /* __FBOPTIONS_H__ */ fbreader-0.99.4.orig/fbreader/src/options/FBOptions.cpp0000644000706400070640000000506412056124565021332 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include "FBOptions.h" FBOptions* FBOptions::ourInstance = 0; static const std::string OPTIONS = "Options"; static const std::string COLORS = "Colors"; FBOptions::FBOptions() : LeftMarginOption(ZLCategoryKey::LOOK_AND_FEEL, OPTIONS, "LeftMargin", 0, 1000, 4), RightMarginOption(ZLCategoryKey::LOOK_AND_FEEL, OPTIONS, "RightMargin", 0, 1000, 4), TopMarginOption(ZLCategoryKey::LOOK_AND_FEEL, OPTIONS, "TopMargin", 0, 1000, 0), BottomMarginOption(ZLCategoryKey::LOOK_AND_FEEL, OPTIONS, "BottomMargin", 0, 1000, 4), BackgroundColorOption(ZLCategoryKey::LOOK_AND_FEEL, COLORS, "Background", ZLColor(255, 255, 255)), RegularTextColorOption(ZLCategoryKey::LOOK_AND_FEEL, COLORS, "Text", ZLColor(0, 0, 0)) { myColorOptions["internal"] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "Hyperlink", ZLColor(33, 96, 180) ); myColorOptions["external"] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "ExternalHyperlink", ZLColor(33, 96, 180) ); myColorOptions["book"] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "BookHyperlink", ZLColor(23, 68, 128) ); myColorOptions[ZLTextStyle::SELECTION_BACKGROUND] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "SelectionBackground", ZLColor(82, 131, 194) ); myColorOptions[ZLTextStyle::HIGHLIGHTED_TEXT] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "SelectedText", ZLColor(60, 139, 255) ); myColorOptions[ZLTextStyle::TREE_LINES] = new ZLColorOption( ZLCategoryKey::LOOK_AND_FEEL, COLORS, "TreeLines", ZLColor(127, 127, 127) ); } ZLColorOption &FBOptions::colorOption(const std::string &style) { std::map >::const_iterator it = myColorOptions.find(style); return it != myColorOptions.end() ? *it->second : RegularTextColorOption; } fbreader-0.99.4.orig/fbreader/src/options/FBCategoryKey.cpp0000644000706400070640000000205612056124565022123 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include "FBCategoryKey.h" FBCategoryKey::FBCategoryKey(const std::string &name) : ZLCategoryKey(name) { } const FBCategoryKey FBCategoryKey::BOOKS("books"); const FBCategoryKey FBCategoryKey::SEARCH("search"); const FBCategoryKey FBCategoryKey::EXTERNAL("external"); fbreader-0.99.4.orig/fbreader/src/options/FBTextStyle.h0000644000706400070640000000402212056124565021302 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBTEXTSTYLE_H__ #define __FBTEXTSTYLE_H__ #include class FBTextStyle : public ZLTextStyle { public: static shared_ptr InstanceAsPtr(); static FBTextStyle &Instance(); private: static shared_ptr ourInstance; private: FBTextStyle(); public: bool isDecorated() const; const std::string &fontFamily() const; int fontSize() const; bool bold() const; bool italic() const; const std::string &colorStyle() const; short spaceBefore(const ZLTextStyleEntry::Metrics &metrics) const; short spaceAfter(const ZLTextStyleEntry::Metrics &metrics) const; short lineStartIndent(const ZLTextStyleEntry::Metrics &metrics, bool rtl) const; short lineEndIndent(const ZLTextStyleEntry::Metrics &metrics, bool rtl) const; short firstLineIndentDelta(const ZLTextStyleEntry::Metrics &metrics) const; int verticalShift() const; ZLTextAlignmentType alignment() const; double lineSpace() const; bool allowHyphenations() const; public: ZLStringOption FontFamilyOption; ZLIntegerRangeOption FontSizeOption; ZLBooleanOption BoldOption; ZLBooleanOption ItalicOption; ZLIntegerOption AlignmentOption; ZLDoubleOption LineSpaceOption; ZLIntegerOption LineSpacePercentOption; }; #endif /* __FBTEXTSTYLE_H__ */ fbreader-0.99.4.orig/fbreader/src/options/FBTextStyle.cpp0000644000706400070640000000564412056124565021650 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "FBTextStyle.h" shared_ptr FBTextStyle::ourInstance; shared_ptr FBTextStyle::InstanceAsPtr() { if (ourInstance.isNull()) { ourInstance = new FBTextStyle(); } return ourInstance; } FBTextStyle &FBTextStyle::Instance() { return (FBTextStyle&)*InstanceAsPtr(); } static const std::string GROUP = "Style"; FBTextStyle::FBTextStyle() : FontFamilyOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:fontFamily", ""), FontSizeOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:fontSize", 5, 72, 26), BoldOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:bold", false), ItalicOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:italic", false), AlignmentOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:alignment", ALIGN_JUSTIFY), LineSpaceOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:lineSpacing", 1.4), LineSpacePercentOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP, "Base:lineSpacingPercent", 140) { } const std::string &FBTextStyle::colorStyle() const { return REGULAR_TEXT; } bool FBTextStyle::isDecorated() const { return false; } const std::string &FBTextStyle::fontFamily() const { return FontFamilyOption.value(); } int FBTextStyle::fontSize() const { return FontSizeOption.value(); } bool FBTextStyle::bold() const { return BoldOption.value(); } bool FBTextStyle::italic() const { return ItalicOption.value(); } short FBTextStyle::spaceBefore(const ZLTextStyleEntry::Metrics&) const { return 0; } short FBTextStyle::spaceAfter(const ZLTextStyleEntry::Metrics&) const { return 0; } short FBTextStyle::lineStartIndent(const ZLTextStyleEntry::Metrics&, bool) const { return 0; } short FBTextStyle::lineEndIndent(const ZLTextStyleEntry::Metrics&, bool) const { return 0; } short FBTextStyle::firstLineIndentDelta(const ZLTextStyleEntry::Metrics&) const { return 0; } int FBTextStyle::verticalShift() const { return 0; } ZLTextAlignmentType FBTextStyle::alignment() const { return (ZLTextAlignmentType)AlignmentOption.value(); } double FBTextStyle::lineSpace() const { return LineSpacePercentOption.value() / 100.0; } bool FBTextStyle::allowHyphenations() const { return true; } fbreader-0.99.4.orig/fbreader/src/libraryTree/0000755000706400070640000000000012056124565017547 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/libraryTree/AuthorNode.cpp0000644000706400070640000000346712056124565022335 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include #include "LibraryNodes.h" #include "../library/Author.h" #include "../libraryActions/LibraryAuthorActions.h" const ZLTypeId AuthorNode::TYPE_ID(FBReaderNode::TYPE_ID); const ZLResource &AuthorNode::resource() const { return ZLResource::resource("libraryView")["authorNode"]; } const ZLTypeId &AuthorNode::typeId() const { return TYPE_ID; } AuthorNode::AuthorNode(ZLBlockTreeView::RootNode *parent, std::size_t atPosition, shared_ptr author) : FBReaderNode(parent, atPosition), myAuthor(author) { } void AuthorNode::init() { registerExpandTreeAction(); if (!myAuthor.isNull()) { registerAction(new AuthorEditInfoAction(myAuthor)); } } shared_ptr AuthorNode::author() const { return myAuthor; } std::string AuthorNode::title() const { return myAuthor.isNull() ? resource()["unknownAuthor"].value() : myAuthor->name(); } shared_ptr AuthorNode::extractCoverImage() const { return defaultCoverImage("booktree-author.png"); } fbreader-0.99.4.orig/fbreader/src/libraryTree/LibraryView.cpp0000644000706400070640000000515612056124565022521 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "LibraryView.h" #include "LibraryNodes.h" #include "../library/Library.h" #include "../library/Book.h" #include "../options/FBOptions.h" LibraryView::LibraryView(ZLPaintContext &context) : ZLBlockTreeView(context), myCollectionRevision(0) { } void LibraryView::paint() { const std::size_t revision = Library::Instance().revision(); if (myCollectionRevision < revision) { myCollectionRevision = revision; makeUpToDate(); } ZLBlockTreeView::paint(); } const std::string &LibraryView::caption() const { return ZLResource::resource("library")["caption"].value(); } ZLColor LibraryView::backgroundColor() const { return FBOptions::Instance().BackgroundColorOption.value(); } void LibraryView::showBook(shared_ptr book) { makeUpToDate(); ZLBlockTreeNode::List bookNodes; std::queue nodesQueue; nodesQueue.push(&rootNode()); while (!nodesQueue.empty()) { const ZLBlockTreeNode::List &children = nodesQueue.front()->children(); nodesQueue.pop(); for (ZLBlockTreeNode::List::const_iterator it = children.begin(); it != children.end(); ++it) { if ((*it)->isInstanceOf(BookNode::TYPE_ID)) { // TODO: replace with == for shared_ptr //if (((BookNode*)*it)->book() == book) { if (((BookNode*)*it)->book()->file() == book->file()) { bookNodes.push_back(*it); } } else { nodesQueue.push(*it); } } } if (bookNodes.empty()) { return; } ZLBlockTreeNode *nodeToShow = bookNodes[0]; VisibilityMode mode = INVISIBLE; for (ZLBlockTreeNode::List::iterator it = bookNodes.begin(); it != bookNodes.end(); ++it) { VisibilityMode nodeMode = visibilityMode(*it); if ((nodeMode == VISIBLE && mode != VISIBLE) || (nodeMode != INVISIBLE && mode == INVISIBLE)) { nodeToShow = *it; mode = nodeMode; } } ensureVisible(nodeToShow); } fbreader-0.99.4.orig/fbreader/src/libraryTree/LibraryNodes.h0000644000706400070640000000552012056124565022317 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __LIBRARYNODES_H__ #define __LIBRARYNODES_H__ #include "../blockTree/FBReaderNode.h" class ZLImage; class Author; class Book; class Tag; class AuthorNode : public FBReaderNode { public: static const ZLTypeId TYPE_ID; public: AuthorNode(ZLBlockTreeView::RootNode *parent, std::size_t atPosition, shared_ptr author); void init(); shared_ptr author() const; private: const ZLResource &resource() const; const ZLTypeId &typeId() const; shared_ptr extractCoverImage() const; std::string title() const; private: shared_ptr myAuthor; }; class SeriesNode : public FBReaderNode { public: static const ZLTypeId TYPE_ID; public: SeriesNode(AuthorNode *parent); void init(); shared_ptr book() const; private: const ZLResource &resource() const; const ZLTypeId &typeId() const; shared_ptr extractCoverImage() const; std::string title() const; }; class TagNode : public FBReaderNode { public: static const ZLTypeId TYPE_ID; private: static std::size_t positionToInsert(ZLBlockTreeNode *parent, shared_ptr tag); public: TagNode(ZLBlockTreeView::RootNode *parent, shared_ptr tag); TagNode(TagNode *parent, shared_ptr tag); void init(); shared_ptr tag() const; private: const ZLResource &resource() const; const ZLTypeId &typeId() const; shared_ptr extractCoverImage() const; std::string title() const; private: const shared_ptr myTag; }; class BookNode : public FBReaderNode { public: static const ZLTypeId TYPE_ID; public: BookNode(AuthorNode *parent, shared_ptr book); BookNode(SeriesNode *parent, shared_ptr book); BookNode(TagNode *parent, std::size_t atPosition, shared_ptr book); shared_ptr book() const; private: void init(); bool highlighted() const; const ZLResource &resource() const; const ZLTypeId &typeId() const; shared_ptr extractCoverImage() const; std::string title() const; std::string summary() const; private: const shared_ptr myBook; }; #endif /* __LIBRARYNODES_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryTree/LibraryView.h0000644000706400070640000000405512056124565022163 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #ifndef __LIBRARYVIEW_H__ #define __LIBRARYVIEW_H__ #include #include #include #include "../library/Lists.h" class Book; class Author; class Tag; class TagComparator; class AuthorNode; class TagNode; class LibraryView : public ZLBlockTreeView { protected: LibraryView(ZLPaintContext &context); public: void showBook(shared_ptr); private: ZLColor backgroundColor() const; const std::string &caption() const; private: void paint(); protected: virtual void makeUpToDate() = 0; private: std::size_t myCollectionRevision; }; class LibraryByAuthorView : public LibraryView { public: LibraryByAuthorView(ZLPaintContext &context); private: void makeUpToDate(); void addAuthorSubtree(shared_ptr author, std::size_t atPosition); void fillAuthorSubtree(AuthorNode *node, const std::set > &visibleBooks); bool isSubtreeUpToDate(AuthorNode *node); void updateAuthorSubtree(AuthorNode *node); }; class LibraryByTagView : public LibraryView { public: LibraryByTagView(ZLPaintContext &context); private: void makeUpToDate(); void collectTagNodes(const ZLBlockTreeNode &root, std::map,TagNode*,TagComparator> &nodeMap); void updateBookList(TagNode *tagNode); }; #endif /* __LIBRARYVIEW_H__ */ fbreader-0.99.4.orig/fbreader/src/libraryTree/TagNode.cpp0000644000706400070640000000447612056124565021607 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "LibraryNodes.h" #include "../library/Tag.h" #include "../libraryActions/LibraryTagActions.h" const ZLTypeId TagNode::TYPE_ID(FBReaderNode::TYPE_ID); const ZLTypeId &TagNode::typeId() const { return TYPE_ID; } const ZLResource &TagNode::resource() const { return ZLResource::resource("libraryView")["tagNode"]; } std::size_t TagNode::positionToInsert(ZLBlockTreeNode *parent, shared_ptr tag) { const ZLBlockTreeNode::List &children = parent->children(); ZLBlockTreeNode::List::const_reverse_iterator it = children.rbegin(); for (; it != children.rend(); ++it) { if (!(*it)->isInstanceOf(TagNode::TYPE_ID) || TagComparator()(((TagNode*)*it)->tag(), tag)) { break; } } return children.rend() - it; } TagNode::TagNode(ZLBlockTreeView::RootNode *parent, shared_ptr tag) : FBReaderNode(parent, positionToInsert(parent, tag)), myTag(tag) { } TagNode::TagNode(TagNode *parent, shared_ptr tag) : FBReaderNode(parent, positionToInsert(parent, tag)), myTag(tag) { } void TagNode::init() { registerExpandTreeAction(); if (!myTag.isNull()) { registerAction(new TagEditAction(myTag)); registerAction(new TagCloneAction(myTag)); registerAction(new TagRemoveAction(myTag)); } } shared_ptr TagNode::tag() const { return myTag; } std::string TagNode::title() const { if (myTag.isNull()) { return resource()["noTags"].value(); } return myTag->name(); } shared_ptr TagNode::extractCoverImage() const { return defaultCoverImage("booktree-tag.png"); } fbreader-0.99.4.orig/fbreader/src/libraryTree/LibraryByAuthorView.cpp0000644000706400070640000001333512056124565024175 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include "LibraryView.h" #include "LibraryNodes.h" #include "../library/Library.h" #include "../library/Book.h" #include "../library/Author.h" LibraryByAuthorView::LibraryByAuthorView(ZLPaintContext &context) : LibraryView(context) { } void LibraryByAuthorView::addAuthorSubtree(shared_ptr author, std::size_t atPosition) { static const std::set > emptySet; fillAuthorSubtree(new AuthorNode(&rootNode(), atPosition, author), emptySet); } void LibraryByAuthorView::fillAuthorSubtree(AuthorNode *authorNode, const std::set > &visibleBooks) { const BookList &books = Library::Instance().books(authorNode->author()); SeriesNode *seriesNode = 0; for (BookList::const_iterator it = books.begin(); it != books.end(); ++it) { std::string series = (*it)->seriesTitle(); if (!series.empty() && (seriesNode == 0 || seriesNode->book()->seriesTitle() != series)) { BookList::const_iterator jt = it + 1; if (jt == books.end() || (*jt)->seriesTitle() != series) { series.clear(); } } if (series.empty()) { seriesNode = 0; new BookNode(authorNode, *it); } else { if (seriesNode == 0 || seriesNode->book()->seriesTitle() != series) { seriesNode = new SeriesNode(authorNode); } new BookNode(seriesNode, *it); if (visibleBooks.find(*it) != visibleBooks.end()) { seriesNode->open(true); } } } } bool LibraryByAuthorView::isSubtreeUpToDate(AuthorNode *authorNode) { const BookList &books = Library::Instance().books(authorNode->author()); BookList::const_iterator it = books.begin(); const ZLBlockTreeNode::List &nodes = authorNode->children(); for (ZLBlockTreeNode::List::const_iterator nIt = nodes.begin(); nIt != nodes.end(); ++nIt) { FBReaderNode &node = *(FBReaderNode*)*nIt; if (node.isInstanceOf(BookNode::TYPE_ID)) { shared_ptr book = ((BookNode&)node).book(); if (it == books.end() || *it != book || !book->seriesTitle().empty()) { return false; } ++it; } else /* if (node.isInstanceOf(SeriesNode::TYPE_ID)) */ { const ZLBlockTreeNode::List &bNodes = node.children(); for (ZLBlockTreeNode::List::const_iterator bookIt = bNodes.begin(); bookIt != bNodes.end(); ++bookIt) { shared_ptr book = ((BookNode*)*bookIt)->book(); if (it == books.end() || *it != book || book->seriesTitle().empty()) { return false; } ++it; } } } return it == books.end(); } void LibraryByAuthorView::updateAuthorSubtree(AuthorNode *authorNode) { std::set > visibleBooks; const ZLBlockTreeNode::List &nodes = authorNode->children(); for (ZLBlockTreeNode::List::const_iterator nIt = nodes.begin(); nIt != nodes.end(); ++nIt) { FBReaderNode &node = *(FBReaderNode*)*nIt; if (node.isInstanceOf(BookNode::TYPE_ID)) { visibleBooks.insert(((BookNode&)node).book()); } else if (node.isOpen()) { const ZLBlockTreeNode::List &bNodes = node.children(); for (ZLBlockTreeNode::List::const_iterator bookIt = bNodes.begin(); bookIt != bNodes.end(); ++bookIt) { visibleBooks.insert(((BookNode*)*bookIt)->book()); } } } authorNode->clear(); fillAuthorSubtree(authorNode, visibleBooks); } void LibraryByAuthorView::makeUpToDate() { ZLBlockTreeNode *topNode = firstVisibleNode(); AuthorNode *topAuthorNode = 0; if (topNode != &rootNode()) { FBReaderNode *lNode = (FBReaderNode*)topNode; while (!lNode->isInstanceOf(AuthorNode::TYPE_ID)) { lNode = (FBReaderNode*)lNode->parent(); } topAuthorNode = (AuthorNode*)lNode; } bool topAuthorNodeIsUpdated = false; const AuthorList &authors = Library::Instance().authors(); std::set nodesToDelete; ZLBlockTreeNode::List rootChildren = rootNode().children(); AuthorComparator comparator; ZLBlockTreeNode::List::iterator nodeIt = rootChildren.begin(); std::size_t nodeCount = 0; for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { bool processed = false; while (nodeIt != rootChildren.end()) { AuthorNode *authorNode = (AuthorNode*)*nodeIt; if (authorNode->author() == *it) { if (!isSubtreeUpToDate(authorNode)) { updateAuthorSubtree(authorNode); if (authorNode == topAuthorNode) { topAuthorNodeIsUpdated = true; } } ++nodeIt; ++nodeCount; processed = true; break; } else if (comparator(authorNode->author(), *it)) { nodesToDelete.insert(*nodeIt); ++nodeIt; ++nodeCount; } else { break; } } if (!processed) { addAuthorSubtree(*it, nodeCount); ++nodeCount; } } nodesToDelete.insert(nodeIt, rootChildren.end()); if (topAuthorNodeIsUpdated) { setFirstVisibleNode(topAuthorNode); } else if (nodesToDelete.find(topAuthorNode) != nodesToDelete.end()) { ZLBlockTreeNode *visible = topAuthorNode->previous(); while (nodesToDelete.find(visible) != nodesToDelete.end()) { visible = visible->previous(); } setFirstVisibleNode(visible); } for (std::set::iterator it = nodesToDelete.begin(); it != nodesToDelete.end(); ++it) { delete *it; } } fbreader-0.99.4.orig/fbreader/src/libraryTree/BookNode.cpp0000644000706400070640000000656612056124565021770 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "LibraryNodes.h" #include "../library/Book.h" #include "../library/Author.h" #include "../library/Tag.h" #include "../libraryActions/LibraryBookActions.h" #include "../fbreader/FBReader.h" #include "../formats/FormatPlugin.h" const ZLTypeId BookNode::TYPE_ID(FBReaderNode::TYPE_ID); const ZLTypeId &BookNode::typeId() const { return TYPE_ID; } const ZLResource &BookNode::resource() const { return ZLResource::resource("libraryView")["bookNode"]; } BookNode::BookNode(AuthorNode *parent, shared_ptr book) : FBReaderNode(parent), myBook(book) { } BookNode::BookNode(SeriesNode *parent, shared_ptr book) : FBReaderNode(parent), myBook(book) { } BookNode::BookNode(TagNode *parent, std::size_t atPosition, shared_ptr book) : FBReaderNode(parent, atPosition), myBook(book) { } void BookNode::init() { registerAction(new BookReadAction(myBook)); registerAction(new BookEditInfoAction(myBook)); registerAction(new BookRemoveAction(myBook)); } shared_ptr BookNode::book() const { return myBook; } std::string BookNode::title() const { return myBook->title(); } std::string BookNode::summary() const { FBReaderNode *parent = (FBReaderNode*)this->parent(); while (!parent->isInstanceOf(AuthorNode::TYPE_ID) && !parent->isInstanceOf(TagNode::TYPE_ID)) { parent = (FBReaderNode*)parent->parent(); } if (parent->isInstanceOf(AuthorNode::TYPE_ID)) { const TagList &tags = myBook->tags(); if (tags.empty()) { return std::string(); } else { std::string tagsText; for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { if (!tagsText.empty()) { tagsText += ", "; } tagsText += (*it)->name(); } return tagsText; } } else { const AuthorList &authors = myBook->authors(); if (authors.empty()) { return ZLResource::resource("libraryView")["authorNode"]["unknownAuthor"].value(); } else { std::string authorsText; for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { if (!authorsText.empty()) { authorsText += ", "; } authorsText += (*it)->name(); } return authorsText; } } } bool BookNode::highlighted() const { return myBook->file() == FBReader::Instance().currentBook()->file(); } shared_ptr BookNode::extractCoverImage() const { shared_ptr plugin = PluginCollection::Instance().plugin(*myBook); if (!plugin.isNull()) { shared_ptr cover = plugin->coverImage(myBook->file()); if (!cover.isNull()) { return cover; } } return defaultCoverImage("booktree-book.png"); } fbreader-0.99.4.orig/fbreader/src/libraryTree/LibraryByTagView.cpp0000644000706400070640000000614612056124565023450 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include "LibraryView.h" #include "LibraryNodes.h" #include "../library/Library.h" #include "../library/Book.h" #include "../library/Tag.h" #include "../libraryActions/BooksUtil.h" LibraryByTagView::LibraryByTagView(ZLPaintContext &context) : LibraryView(context) { } void LibraryByTagView::collectTagNodes(const ZLBlockTreeNode &root, std::map,TagNode*,TagComparator> &nodeMap) { const ZLBlockTreeNode::List &children = root.children(); for (ZLBlockTreeNode::List::const_iterator it = children.begin(); it != children.end(); ++it) { if ((*it)->isInstanceOf(TagNode::TYPE_ID)) { TagNode *tagNode = (TagNode*)*it; nodeMap[tagNode->tag()] = tagNode; collectTagNodes(*tagNode, nodeMap); } } } void LibraryByTagView::updateBookList(TagNode *tagNode) { const BookList &books = Library::Instance().books(tagNode->tag()); const ZLBlockTreeNode::List &subNodes = tagNode->children(); BookList::const_iterator jt = books.begin(); ZLBlockTreeNode::List::const_iterator kt = subNodes.begin(); for (; jt != books.end() && kt != subNodes.end(); ++jt, ++kt) { if (!(*kt)->isInstanceOf(BookNode::TYPE_ID)) { break; } if (((BookNode*)(*kt))->book()->file() != (*jt)->file()) { break; } } std::size_t index = jt - books.begin(); while (tagNode->children().size() > index) { ZLBlockTreeNode *bookNode = tagNode->children()[index]; if (!bookNode->isInstanceOf(BookNode::TYPE_ID)) { break; } delete bookNode; } for (; jt != books.end(); ++jt) { new BookNode(tagNode, index++, *jt); } } void LibraryByTagView::makeUpToDate() { TagList tags; BooksUtil::collectTagsFromLibrary(tags); std::map,TagNode*,TagComparator> nodeMap; collectTagNodes(rootNode(), nodeMap); for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { shared_ptr tag = *it; TagNode *tagNode = nodeMap[tag]; if (tagNode == 0) { tagNode = (tag.isNull() || tag->parent().isNull()) ? new TagNode(&rootNode(), tag) : new TagNode(nodeMap[tag->parent()], tag); nodeMap[tag] = tagNode; } updateBookList(tagNode); } for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { nodeMap.erase(nodeMap.find(*it)); } for (std::map,TagNode*,TagComparator>::reverse_iterator it = nodeMap.rbegin(); it != nodeMap.rend(); ++it) { delete it->second; } } fbreader-0.99.4.orig/fbreader/src/libraryTree/SeriesNode.cpp0000644000706400070640000000341712056124565022320 0ustar bagebage/* * Copyright (C) 2009-2012 Geometer Plus * * 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. */ #include #include #include "LibraryNodes.h" #include "../library/Book.h" const ZLTypeId SeriesNode::TYPE_ID(FBReaderNode::TYPE_ID); const ZLResource &SeriesNode::resource() const { return ZLResource::resource("libraryView")["seriesNode"]; } const ZLTypeId &SeriesNode::typeId() const { return TYPE_ID; } SeriesNode::SeriesNode(AuthorNode *parent) : FBReaderNode(parent) { } void SeriesNode::init() { registerExpandTreeAction(); } shared_ptr SeriesNode::book() const { return ((BookNode&)*children().front()).book(); } std::string SeriesNode::title() const { return book()->seriesTitle(); } shared_ptr SeriesNode::extractCoverImage() const { const std::vector &books = children(); for (std::vector::const_iterator it = books.begin(); it != books.end(); ++it) { shared_ptr bookCover = ((FBReaderNode*)*it)->coverImage(); if (!bookCover.isNull()) { return bookCover; } } return 0; } fbreader-0.99.4.orig/fbreader/src/fbreader/0000755000706400070640000000000012056124565017035 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/fbreader/RecentBooksPopupData.cpp0000644000706400070640000000347612056124565023607 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include "RecentBooksPopupData.h" #include "FBReader.h" #include "../library/Book.h" #include "../library/Author.h" RecentBooksPopupData::RecentBooksPopupData() : myId(0) { } void RecentBooksPopupData::updateId() { ++myId; } std::size_t RecentBooksPopupData::id() const { return myId; } std::size_t RecentBooksPopupData::count() const { return Library::Instance().recentBooks().size(); } const std::string RecentBooksPopupData::text(std::size_t index) { const BookList &books = Library::Instance().recentBooks(); if (index >= books.size()) { return ""; } const Book &book = *books[index]; const AuthorList authors = book.authors(); if (authors.empty()) { return book.title(); } else { return authors[0]->name() + ". " + book.title(); } } void RecentBooksPopupData::run(std::size_t index) { FBReader &fbreader = FBReader::Instance(); const BookList &books = Library::Instance().recentBooks(); if (index >= books.size()) { return; } fbreader.openBook(books[index]); fbreader.showBookTextView(); fbreader.refreshWindow(); } fbreader-0.99.4.orig/fbreader/src/fbreader/BooksOrderAction.cpp0000644000706400070640000000176612056124565022762 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include "FBReader.h" #include "FBReaderActions.h" BooksOrderAction::BooksOrderAction() : ModeDependentAction(FBReader::LIBRARY_MODE) { } void BooksOrderAction::run() { FBReader::Instance().showLibraryView(); } fbreader-0.99.4.orig/fbreader/src/fbreader/FBView.h0000644000706400070640000000633312056124565020335 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBVIEW_H__ #define __FBVIEW_H__ #include #include #include class FBIndicatorStyle : public ZLTextPositionIndicatorInfo { public: ZLIntegerRangeOption TypeOption; ZLBooleanOption IsSensitiveOption; ZLBooleanOption ShowTextPositionOption; ZLBooleanOption ShowTimeOption; ZLColorOption ColorOption; ZLIntegerRangeOption HeightOption; ZLIntegerRangeOption OffsetOption; ZLIntegerRangeOption FontSizeOption; public: FBIndicatorStyle(); Type type() const; bool isSensitive() const; bool isTextPositionShown() const; bool isTimeShown() const; ZLColor color() const; int height() const; int offset() const; int fontSize() const; }; class FBView : public ZLTextView { private: class TapScroller; public: static FBIndicatorStyle& commonIndicatorInfo(); static ZLBooleanOption &selectionOption(); virtual bool hasContents() const; private: static shared_ptr ourIndicatorInfo; static shared_ptr ourSelectionOption; protected: void doTapScrolling(int y); public: FBView(ZLPaintContext &context); void setCaption(const std::string &caption); private: bool onFingerTap(int x, int y); const std::string &caption() const; int leftMargin() const; int rightMargin() const; int topMargin() const; int bottomMargin() const; ZLColor backgroundColor() const; ZLColor color(const std::string &colorStyle) const; shared_ptr baseStyle() const; bool isSelectionEnabled() const; int doubleClickDelay() const; protected: bool onStylusPress(int x, int y); virtual bool _onStylusPress(int x, int y); bool onStylusRelease(int x, int y); virtual bool _onStylusRelease(int x, int y); bool onStylusMove(int x, int y); virtual bool _onStylusMove(int x, int y); bool onStylusMovePressed(int x, int y); virtual bool _onStylusMovePressed(int x, int y); int pressedX() const; int pressedY() const; bool isReleasedWithoutMotion() const; std::string word(const ZLTextElementRectangle &rectangle) const; shared_ptr indicatorInfo() const; private: std::string myCaption; int myPressedX; int myPressedY; bool myIsReleasedWithoutMotion; shared_ptr myTapScroller; }; inline int FBView::pressedX() const { return myPressedX; } inline int FBView::pressedY() const { return myPressedY; } inline bool FBView::isReleasedWithoutMotion() const { return myIsReleasedWithoutMotion; } #endif /* __FBVIEW_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/FBReaderActions.h0000644000706400070640000002077712056124565022156 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBREADERACTIONS_H__ #define __FBREADERACTIONS_H__ #include #include "FBReader.h" class ZLTextView; class ActionCode { public: static const std::string SHOW_READING; static const std::string SHOW_LIBRARY; static const std::string SHOW_NETWORK_LIBRARY; static const std::string SHOW_TOC; static const std::string SHOW_HELP; static const std::string SHOW_OPTIONS_DIALOG; static const std::string SHOW_BOOK_INFO_DIALOG; static const std::string SHOW_LIBRARY_OPTIONS_DIALOG; static const std::string SHOW_NETWORK_OPTIONS_DIALOG; static const std::string SHOW_SYSTEM_OPTIONS_DIALOG; static const std::string SHOW_READING_OPTIONS_DIALOG; static const std::string SHOW_LOOKANDFEEL_OPTIONS_DIALOG; static const std::string UNDO; static const std::string REDO; static const std::string SEARCH; static const std::string FIND_PREVIOUS; static const std::string FIND_NEXT; static const std::string PAGE_SCROLL_FORWARD; static const std::string PAGE_SCROLL_BACKWARD; static const std::string LINE_SCROLL_FORWARD; static const std::string LINE_SCROLL_BACKWARD; static const std::string MOUSE_SCROLL_FORWARD; static const std::string MOUSE_SCROLL_BACKWARD; static const std::string TAP_SCROLL_FORWARD; static const std::string TAP_SCROLL_BACKWARD; static const std::string SCROLL_TO_HOME; static const std::string SCROLL_TO_START_OF_TEXT; static const std::string SCROLL_TO_END_OF_TEXT; static const std::string CANCEL; static const std::string INCREASE_FONT; static const std::string DECREASE_FONT; static const std::string SHOW_HIDE_POSITION_INDICATOR; static const std::string TOGGLE_FULLSCREEN; static const std::string FULLSCREEN_ON; static const std::string ADD_BOOK; static const std::string ROTATE_SCREEN; static const std::string QUIT; static const std::string FORCE_QUIT; static const std::string OPEN_PREVIOUS_BOOK; static const std::string GOTO_NEXT_TOC_SECTION; static const std::string GOTO_PREVIOUS_TOC_SECTION; static const std::string COPY_SELECTED_TEXT_TO_CLIPBOARD; static const std::string CLEAR_SELECTION; static const std::string OPEN_SELECTED_TEXT_IN_DICTIONARY; static const std::string GOTO_PAGE_NUMBER; static const std::string GOTO_PAGE_NUMBER_WITH_PARAMETER; static const std::string ORGANIZE_BOOKS_BY_AUTHOR; static const std::string ORGANIZE_BOOKS_BY_TAG; static const std::string FILTER_LIBRARY; private: ActionCode(); }; class ModeDependentAction : public ZLApplication::Action { protected: ModeDependentAction(int visibleInModes); public: bool isVisible() const; private: int myVisibleInModes; }; class SetModeAction : public ModeDependentAction { public: SetModeAction(FBReader::ViewMode modeToSet, int visibleInModes); void run(); private: FBReader::ViewMode myModeToSet; }; class ShowHelpAction : public ZLApplication::Action { public: void run(); }; class ShowOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowLibraryOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowNetworkOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowSystemOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowReadingOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowLookAndFeelOptionsDialogAction : public ZLApplication::Action { public: void run(); }; class ShowContentsAction : public SetModeAction { public: ShowContentsAction(); bool isVisible() const; }; class ShowNetworkTreeLibraryAction : public ZLApplication::Action { public: ShowNetworkTreeLibraryAction(); protected: void run(); }; class AddBookAction : public ModeDependentAction { private: class FileFilter; private: ZLStringOption DirectoryOption; ZLStringOption FileOption; public: AddBookAction(int visibleInModes); void run(); }; class ShowBookInfoAction : public ModeDependentAction { public: ShowBookInfoAction(); void run(); }; class ScrollToHomeAction : public ModeDependentAction { public: ScrollToHomeAction(); bool isEnabled() const; void run(); }; class ScrollToStartOfTextAction : public ModeDependentAction { public: ScrollToStartOfTextAction(); bool isEnabled() const; void run(); }; class ScrollToEndOfTextAction : public ModeDependentAction { public: ScrollToEndOfTextAction(); bool isEnabled() const; void run(); }; class UndoAction : public ModeDependentAction { public: UndoAction(int visibleInModes); bool isEnabled() const; void run(); }; class RedoAction : public ModeDependentAction { public: RedoAction(); bool isEnabled() const; void run(); }; class SearchAction : public ZLApplication::Action { public: bool isVisible() const; }; class SearchPatternAction : public SearchAction { public: SearchPatternAction(); void run(); private: ZLBooleanOption SearchBackwardOption; ZLBooleanOption SearchIgnoreCaseOption; ZLBooleanOption SearchInWholeTextOption; ZLBooleanOption SearchThisSectionOnlyOption; ZLStringOption SearchPatternOption; friend class SearchPatternEntry; }; class FindNextAction : public SearchAction { public: bool isEnabled() const; void run(); }; class FindPreviousAction : public SearchAction { public: bool isEnabled() const; void run(); }; class ChangeFontSizeAction : public ZLApplication::Action { public: ChangeFontSizeAction(int delta); bool isEnabled() const; void run(); private: const int myDelta; }; class CancelAction : public ZLApplication::Action { public: void run(); }; class ToggleIndicatorAction : public ZLApplication::Action { public: bool isVisible() const; void run(); }; class QuitAction : public ZLApplication::Action { public: void run(); }; class ForceQuitAction : public ZLApplication::Action { public: void run(); }; class OpenPreviousBookAction : public ZLApplication::Action { public: bool isVisible() const; void run(); }; class GotoNextTOCSectionAction : public ZLApplication::Action { public: bool isVisible() const; bool isEnabled() const; void run(); }; class GotoPreviousTOCSectionAction : public ZLApplication::Action { public: bool isVisible() const; bool isEnabled() const; void run(); }; class GotoPageNumberAction : public ModeDependentAction { public: GotoPageNumberAction(const std::string ¶meter); bool isVisible() const; bool isEnabled() const; void run(); private: const std::string myParameter; }; class SelectionAction : public ZLApplication::Action { public: bool isVisible() const; bool isEnabled() const; protected: ZLTextView &textView() const; }; class CopySelectedTextAction : public SelectionAction { public: bool isVisible() const; void run(); }; class OpenSelectedTextInDictionaryAction : public SelectionAction { public: bool isVisible() const; void run(); }; class ClearSelectionAction : public SelectionAction { public: void run(); }; class SearchOnNetworkAction : ZLApplication::Action { public: SearchOnNetworkAction(); void run(); private: virtual void doSearch() = 0; }; class SimpleSearchOnNetworkAction : public SearchOnNetworkAction { private: void doSearch(); std::string makeSummary(const std::string &pattern); }; class AdvancedSearchOnNetworkAction : public SearchOnNetworkAction { private: void doSearch(); std::string makeSummary(const std::string &titleAndSeries, const std::string &author, const std::string &category, const std::string &description); void appendQueryValue(std::string &query, const std::string &name, const std::string &value); }; class FBFullscreenAction : public ZLApplication::FullscreenAction { public: void run(); }; class BooksOrderAction : public ModeDependentAction { public: BooksOrderAction(); void run(); }; class FilterLibraryAction : public ModeDependentAction { public: FilterLibraryAction(); void run(); }; #endif /* __FBREADERACTIONS_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/ScrollingAction.h0000644000706400070640000000425012056124565022301 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __SCROLLINGACTION_H__ #define __SCROLLINGACTION_H__ #include #include #include class ScrollingAction : public ZLApplication::Action { protected: ScrollingAction( ZLTextAreaController::ScrollingMode textScrollingMode, ZLBlockTreeView::ScrollingMode blockScrollingMode, bool forward ); public: virtual std::size_t textOptionValue() const = 0; virtual int scrollingDelay() const; bool isEnabled() const; bool useKeyDelay() const; void run(); private: const ZLTextAreaController::ScrollingMode myTextScrollingMode; const ZLBlockTreeView::ScrollingMode myBlockScrollingMode; const bool myForward; }; class LineScrollingAction : public ScrollingAction { public: LineScrollingAction(bool forward); private: int scrollingDelay() const; std::size_t textOptionValue() const; }; class PageScrollingAction : public ScrollingAction { public: PageScrollingAction(bool forward); private: int scrollingDelay() const; std::size_t textOptionValue() const; }; class MouseWheelScrollingAction : public ScrollingAction { public: MouseWheelScrollingAction(bool forward); private: std::size_t textOptionValue() const; }; class TapScrollingAction : public ScrollingAction { public: TapScrollingAction(bool forward); private: std::size_t textOptionValue() const; bool isEnabled() const; }; #endif /* __SCROLLINGACTION_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/AddBookAction.cpp0000644000706400070640000000400412056124565022200 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "FBReaderActions.h" #include "FBReader.h" #include "../library/Book.h" #include "../formats/FormatPlugin.h" class AddBookAction::FileFilter : public ZLOpenFileDialog::Filter { private: bool accepts(const ZLFile &file) const; }; bool AddBookAction::FileFilter::accepts(const ZLFile &file) const { return file.isArchive() || !PluginCollection::Instance().plugin(file, false).isNull(); } static const std::string GROUP_NAME = "OpenFileDialog"; AddBookAction::AddBookAction(int visibleInModes) : ModeDependentAction(visibleInModes), DirectoryOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP_NAME, "Directory", ZLFile("~").path()), FileOption(ZLCategoryKey::LOOK_AND_FEEL, GROUP_NAME, "File", std::string()) { } void AddBookAction::run() { const ZLResourceKey dialogKey("addFileDialog"); FileFilter filter; shared_ptr dialog = ZLDialogManager::Instance().createOpenFileDialog(dialogKey, DirectoryOption.value(), FileOption.value(), filter); bool code = dialog->run(); DirectoryOption.setValue(dialog->directoryPath()); FileOption.setValue(dialog->filePath()); if (code) { FBReader::Instance().openFile(ZLFile(dialog->filePath())); } } fbreader-0.99.4.orig/fbreader/src/fbreader/BookTextView.h0000644000706400070640000000510612056124565021602 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __BOOKTEXTVIEW_H__ #define __BOOKTEXTVIEW_H__ #include #include "ReadingState.h" #include #include "FBView.h" class Book; class BookTextView : public FBView { public: ZLBooleanOption ShowTOCMarksOption; public: BookTextView(ZLPaintContext &context); ~BookTextView(); void setModel(shared_ptr model, shared_ptr book); void setContentsModel(shared_ptr contentsModel); void saveState(); void gotoParagraph(int num, bool end = false); bool canUndoPageMove(); void undoPageMove(); bool canRedoPageMove(); void redoPageMove(); void scrollToHome(); bool _onStylusPress(int x, int y); bool _onStylusMove(int x, int y); bool _onStylusRelease(int x, int y); bool onStylusClick(int x, int y, int count); private: typedef ReadingState Position; Position cursorPosition(const ZLTextWordCursor &cursor) const; bool pushCurrentPositionIntoStack(bool doPushSamePosition = true); void replaceCurrentPositionInStack(); void preparePaintInfo(); bool getHyperlinkInfo(const ZLTextElementRectangle &rectangle, std::string &id, ZLHyperlinkType &type) const; shared_ptr createPositionIndicator(const ZLTextPositionIndicatorInfo &info); void paint(); private: class PositionIndicatorWithLabels; private: void readBookState(const Book &book); int readStackPos(const Book &book); void saveBookState(const Book &book); private: shared_ptr myContentsModel; shared_ptr myBook; typedef std::deque PositionStack; PositionStack myPositionStack; unsigned int myCurrentPointInStack; unsigned int myMaxStackSize; bool myLockUndoStackChanges; bool myStackChanged; }; inline void BookTextView::preparePaintInfo() { ZLTextView::preparePaintInfo(); saveState(); } #endif /* __BOOKTEXTVIEW_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/RecentBooksPopupData.h0000644000706400070640000000227112056124565023244 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #ifndef __RECENTBOOKSPOPUPDATA_H__ #define __RECENTBOOKSPOPUPDATA_H__ #include class RecentBooksPopupData : public ZLPopupData { public: RecentBooksPopupData(); void updateId(); private: std::size_t id() const; std::size_t count() const; const std::string text(std::size_t index); void run(std::size_t index); private: std::size_t myId; }; #endif /* __RECENTBOOKSPOPUPDATA_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/FBReaderActions.cpp0000644000706400070640000003750012056124565022501 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include #include #include #include #include #include "FBReader.h" #include "FBReaderActions.h" #include "BookTextView.h" #include "ContentsView.h" #include "../optionsDialog/bookInfo/BookInfoDialog.h" #include "../optionsDialog/library/LibraryOptionsDialog.h" #include "../optionsDialog/network/NetworkOptionsDialog.h" #include "../optionsDialog/system/SystemOptionsDialog.h" #include "../optionsDialog/reading/ReadingOptionsDialog.h" #include "../optionsDialog/lookAndFeel/OptionsPage.h" #include "../optionsDialog/lookAndFeel/LookAndFeelOptionsDialog.h" #include "../bookmodel/BookModel.h" #include "../options/FBTextStyle.h" #include "../database/booksdb/BooksDBUtil.h" #include "../database/booksdb/BooksDB.h" #include "../library/Library.h" #include "../library/Book.h" ModeDependentAction::ModeDependentAction(int visibleInModes) : myVisibleInModes(visibleInModes) { } bool ModeDependentAction::isVisible() const { return (FBReader::Instance().mode() & myVisibleInModes) != 0; } SetModeAction::SetModeAction(FBReader::ViewMode modeToSet, int visibleInModes) : ModeDependentAction(visibleInModes), myModeToSet(modeToSet) { } void SetModeAction::run() { FBReader::Instance().setMode(myModeToSet); } void ShowHelpAction::run() { FBReader &fbreader = FBReader::Instance(); shared_ptr book = BooksDBUtil::getBook(fbreader.helpFileName(ZLibrary::Language())); if (book.isNull()) { book = BooksDBUtil::getBook(fbreader.helpFileName("en")); } if (!book.isNull()) { fbreader.openBook(book); fbreader.setMode(FBReader::BOOK_TEXT_MODE); fbreader.refreshWindow(); } else { ZLDialogManager::Instance().errorBox(ZLResourceKey("noHelpBox")); } } void ShowOptionsDialogAction::run() { std::string actionId = FBReader::Instance().LastOpenedPreferencesDialog.value(); if (actionId.empty()) { return; } FBReader::Instance().doAction(actionId); } void ShowLibraryOptionsDialogAction::run() { FBReader::Instance().LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_LIBRARY_OPTIONS_DIALOG); LibraryOptionsDialog().dialog().run(); } void ShowNetworkOptionsDialogAction::run() { FBReader::Instance().LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_NETWORK_OPTIONS_DIALOG); NetworkOptionsDialog().dialog().run(); } void ShowSystemOptionsDialogAction::run() { FBReader::Instance().LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_SYSTEM_OPTIONS_DIALOG); SystemOptionsDialog().dialog().run(); } void ShowReadingOptionsDialogAction::run() { FBReader::Instance().LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_READING_OPTIONS_DIALOG); ReadingOptionsDialog().dialog().run(); } void ShowLookAndFeelOptionsDialogAction::run() { FBReader::Instance().LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_LOOKANDFEEL_OPTIONS_DIALOG); LookAndFeelOptionsDialog().dialog().run(); } ShowContentsAction::ShowContentsAction() : SetModeAction(FBReader::CONTENTS_MODE, FBReader::BOOK_TEXT_MODE) { } bool ShowContentsAction::isVisible() const { return ModeDependentAction::isVisible() && !((ContentsView&)*FBReader::Instance().myContentsView).isEmpty(); } ScrollToHomeAction::ScrollToHomeAction() : ModeDependentAction(FBReader::BOOK_TEXT_MODE) { } bool ScrollToHomeAction::isEnabled() const { if (!isVisible()) { return false; } ZLTextWordCursor cursor = FBReader::Instance().bookTextView().textArea().startCursor(); return cursor.isNull() || !cursor.isStartOfParagraph() || !cursor.paragraphCursor().isFirst(); } void ScrollToHomeAction::run() { FBReader::Instance().bookTextView().scrollToHome(); } ScrollToStartOfTextAction::ScrollToStartOfTextAction() : ModeDependentAction(FBReader::BOOK_TEXT_MODE) { } bool ScrollToStartOfTextAction::isEnabled() const { if (!isVisible()) { return false; } ZLTextWordCursor cursor = FBReader::Instance().bookTextView().textArea().startCursor(); return cursor.isNull() || !cursor.isStartOfParagraph() || !cursor.paragraphCursor().isFirst(); } void ScrollToStartOfTextAction::run() { FBReader::Instance().bookTextView().scrollToStartOfText(); } ScrollToEndOfTextAction::ScrollToEndOfTextAction() : ModeDependentAction(FBReader::BOOK_TEXT_MODE) { } bool ScrollToEndOfTextAction::isEnabled() const { if (!isVisible()) { return false; } ZLTextWordCursor cursor = FBReader::Instance().bookTextView().textArea().endCursor(); return cursor.isNull() || !cursor.isEndOfParagraph() || !cursor.paragraphCursor().isLast(); } void ScrollToEndOfTextAction::run() { FBReader::Instance().bookTextView().scrollToEndOfText(); } ShowBookInfoAction::ShowBookInfoAction() : ModeDependentAction(FBReader::BOOK_TEXT_MODE | FBReader::CONTENTS_MODE | FBReader::FOOTNOTE_MODE) { } void ShowBookInfoAction::run() { FBReader &fbreader = FBReader::Instance(); fbreader.LastOpenedPreferencesDialog.setValue(ActionCode::SHOW_BOOK_INFO_DIALOG); shared_ptr book = fbreader.myModel->book(); if (BookInfoDialog(book).dialog().run()) { fbreader.openBook(book); fbreader.refreshWindow(); } } UndoAction::UndoAction(int visibleInModes) : ModeDependentAction(visibleInModes) { } bool UndoAction::isEnabled() const { FBReader &fbreader = FBReader::Instance(); return (fbreader.mode() != FBReader::BOOK_TEXT_MODE) || fbreader.bookTextView().canUndoPageMove(); } void UndoAction::run() { FBReader &fbreader = FBReader::Instance(); if (fbreader.mode() == FBReader::BOOK_TEXT_MODE) { fbreader.bookTextView().undoPageMove(); } else { fbreader.restorePreviousMode(); } } RedoAction::RedoAction() : ModeDependentAction(FBReader::BOOK_TEXT_MODE) { } bool RedoAction::isEnabled() const { return isVisible() && FBReader::Instance().bookTextView().canRedoPageMove(); } void RedoAction::run() { FBReader::Instance().bookTextView().redoPageMove(); } ChangeFontSizeAction::ChangeFontSizeAction(int delta) : myDelta(delta) { } bool ChangeFontSizeAction::isEnabled() const { ZLIntegerRangeOption &option = FBTextStyle::Instance().FontSizeOption; if (myDelta < 0) { return option.value() > option.minValue(); } else { return option.value() < option.maxValue(); } } void ChangeFontSizeAction::run() { FBReader &fbreader = FBReader::Instance(); ZLIntegerRangeOption &option = FBTextStyle::Instance().FontSizeOption; option.setValue(option.value() + myDelta); fbreader.clearTextCaches(); fbreader.refreshWindow(); } bool OpenPreviousBookAction::isVisible() const { const FBReader &fbreader = FBReader::Instance(); if ((fbreader.mode() != FBReader::BOOK_TEXT_MODE) && (fbreader.mode() != FBReader::CONTENTS_MODE)) { return false; } return Library::Instance().recentBooks().size() > 1; } void OpenPreviousBookAction::run() { FBReader &fbreader = FBReader::Instance(); const BookList &books = Library::Instance().recentBooks(); fbreader.openBook(books[1]); fbreader.refreshWindow(); fbreader.resetWindowCaption(); } void CancelAction::run() { FBReader &fbreader = FBReader::Instance(); switch (fbreader.myActionOnCancel) { case FBReader::UNFULLSCREEN: if (fbreader.isFullscreen()) { fbreader.setFullscreen(false); return; } else if (fbreader.mode() != FBReader::BOOK_TEXT_MODE) { fbreader.restorePreviousMode(); return; } break; case FBReader::RETURN_TO_TEXT_MODE: if (fbreader.mode() != FBReader::BOOK_TEXT_MODE) { fbreader.restorePreviousMode(); return; } else if (fbreader.isFullscreen()) { fbreader.setFullscreen(false); return; } break; } if (fbreader.QuitOnCancelOption.value()) { fbreader.quit(); } } bool ToggleIndicatorAction::isVisible() const { ZLIntegerRangeOption &option = FBView::commonIndicatorInfo().TypeOption; switch (option.value()) { case FBIndicatorStyle::FB_INDICATOR: case FBIndicatorStyle::NONE: return true; } return false; } void ToggleIndicatorAction::run() { ZLIntegerRangeOption &option = FBView::commonIndicatorInfo().TypeOption; switch (option.value()) { case FBIndicatorStyle::OS_SCROLLBAR: break; case FBIndicatorStyle::FB_INDICATOR: option.setValue(FBIndicatorStyle::NONE); FBReader::Instance().refreshWindow(); break; case FBIndicatorStyle::NONE: option.setValue(FBIndicatorStyle::FB_INDICATOR); FBReader::Instance().refreshWindow(); break; } } void QuitAction::run() { FBReader::Instance().closeView(); } void ForceQuitAction::run() { FBReader::Instance().quit(); } bool GotoNextTOCSectionAction::isVisible() const { FBReader &fbreader = FBReader::Instance(); if (fbreader.mode() != FBReader::BOOK_TEXT_MODE) { return false; } const ContentsView &contentsView = (const ContentsView&)*fbreader.myContentsView; shared_ptr model = contentsView.textArea().model(); return !model.isNull() && (model->paragraphsNumber() > 1); } bool GotoNextTOCSectionAction::isEnabled() const { FBReader &fbreader = FBReader::Instance(); const ContentsView &contentsView = (const ContentsView&)*fbreader.myContentsView; shared_ptr model = contentsView.textArea().model(); return !model.isNull() && ((int)contentsView.currentTextViewParagraph() < (int)model->paragraphsNumber() - 1); } void GotoNextTOCSectionAction::run() { FBReader &fbreader = FBReader::Instance(); ContentsView &contentsView = (ContentsView&)*fbreader.myContentsView; std::size_t current = contentsView.currentTextViewParagraph(); const ContentsModel &contentsModel = (const ContentsModel&)*contentsView.textArea().model(); int reference = contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[current + 1])); if (reference != -1) { ((ZLTextView&)*fbreader.myBookTextView).gotoParagraph(reference); fbreader.refreshWindow(); } } bool GotoPreviousTOCSectionAction::isVisible() const { const FBReader &fbreader = FBReader::Instance(); if (fbreader.mode() != FBReader::BOOK_TEXT_MODE) { return false; } const ContentsView &contentsView = (const ContentsView&)*fbreader.myContentsView; shared_ptr model = contentsView.textArea().model(); return !model.isNull() && (model->paragraphsNumber() > 1); } bool GotoPreviousTOCSectionAction::isEnabled() const { const FBReader &fbreader = FBReader::Instance(); const ContentsView &contentsView = (const ContentsView&)*fbreader.myContentsView; shared_ptr model = contentsView.textArea().model(); if (model.isNull()) { return false; } const ContentsModel &contentsModel = (const ContentsModel&)*model; int tocIndex = contentsView.currentTextViewParagraph(false); if (tocIndex > 0) { return true; } if (tocIndex == 0) { const ZLTextWordCursor &cursor = fbreader.bookTextView().textArea().startCursor(); if (cursor.isNull()) { return false; } if (cursor.elementIndex() > 0) { return true; } return contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[0])) > (int)cursor.paragraphCursor().index(); } return false; } void GotoPreviousTOCSectionAction::run() { FBReader &fbreader = FBReader::Instance(); ContentsView &contentsView = (ContentsView&)*fbreader.myContentsView; std::size_t current = contentsView.currentTextViewParagraph(false); const ContentsModel &contentsModel = (const ContentsModel&)*contentsView.textArea().model(); int reference = contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[current])); const ZLTextWordCursor &cursor = fbreader.bookTextView().textArea().startCursor(); if (!cursor.isNull() && (cursor.elementIndex() == 0)) { int paragraphIndex = cursor.paragraphCursor().index(); if (reference == paragraphIndex) { reference = contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[current - 1])); } else if (reference == paragraphIndex - 1) { const ZLTextModel &textModel = *fbreader.bookTextView().textArea().model(); const ZLTextParagraph *para = textModel[paragraphIndex]; if ((para != 0) && (para->kind() == ZLTextParagraph::END_OF_SECTION_PARAGRAPH)) { reference = contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[current - 1])); } } } if (reference != -1) { ((ZLTextView&)*fbreader.myBookTextView).gotoParagraph(reference); fbreader.refreshWindow(); } } GotoPageNumberAction::GotoPageNumberAction(const std::string ¶meter) : ModeDependentAction(FBReader::BOOK_TEXT_MODE), myParameter(parameter) { } bool GotoPageNumberAction::isVisible() const { return ModeDependentAction::isVisible() && !FBReader::Instance().bookTextView().hasMultiSectionModel(); } bool GotoPageNumberAction::isEnabled() const { return ModeDependentAction::isEnabled() && (FBReader::Instance().bookTextView().pageNumber() > 1); } void GotoPageNumberAction::run() { FBReader &fbreader = FBReader::Instance(); int pageIndex = 0; const int pageNumber = fbreader.bookTextView().pageNumber(); if (!myParameter.empty()) { const std::string value = fbreader.visualParameter(myParameter); if (value.empty()) { return; } pageIndex = std::atoi(value.c_str()); } else { shared_ptr gotoPageDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("gotoPageDialog")); ZLIntegerRangeOption pageIndexOption(ZLCategoryKey::CONFIG, "gotoPageDialog", "Index", 1, pageNumber, pageIndex); gotoPageDialog->addOption(ZLResourceKey("pageNumber"), new ZLSimpleSpinOptionEntry(pageIndexOption, 1)); gotoPageDialog->addButton(ZLDialogManager::OK_BUTTON, true); gotoPageDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); if (gotoPageDialog->run()) { gotoPageDialog->acceptValues(); pageIndex = pageIndexOption.value(); } else { return; } } fbreader.bookTextView().gotoPage(std::max(1, std::min(pageIndex, pageNumber))); fbreader.refreshWindow(); } bool SelectionAction::isVisible() const { shared_ptr view = FBReader::Instance().currentView(); return !view.isNull() && view->isInstanceOf(ZLTextView::TYPE_ID); } bool SelectionAction::isEnabled() const { if (!isVisible()) { return false; } const ZLTextSelectionModel &selectionModel = textView().selectionModel(); return !selectionModel.text().empty() || !selectionModel.image().isNull(); } ZLTextView &SelectionAction::textView() const { return (ZLTextView&)*FBReader::Instance().currentView(); } bool CopySelectedTextAction::isVisible() const { return SelectionAction::isVisible() && ZLDialogManager::Instance().isClipboardSupported(ZLDialogManager::CLIPBOARD_MAIN); } void CopySelectedTextAction::run() { textView().selectionModel().copySelectionToClipboard(ZLDialogManager::CLIPBOARD_MAIN); } bool OpenSelectedTextInDictionaryAction::isVisible() const { return SelectionAction::isVisible() && FBReader::Instance().isDictionarySupported(); } void OpenSelectedTextInDictionaryAction::run() { FBReader::Instance().openInDictionary(textView().selectionModel().text()); } void ClearSelectionAction::run() { textView().selectionModel().clear(); FBReader::Instance().refreshWindow(); } void FBFullscreenAction::run() { FBReader &fbreader = FBReader::Instance(); if (!fbreader.isFullscreen()) { fbreader.myActionOnCancel = FBReader::UNFULLSCREEN; } FullscreenAction::run(); } FilterLibraryAction::FilterLibraryAction() : ModeDependentAction(FBReader::LIBRARY_MODE) { } void FilterLibraryAction::run() { } fbreader-0.99.4.orig/fbreader/src/fbreader/FBReaderActionCode.cpp0000644000706400070640000000777312056124565023122 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include "FBReaderActions.h" const std::string ActionCode::SHOW_READING = "showReading"; const std::string ActionCode::SHOW_LIBRARY = "showLibrary"; const std::string ActionCode::SHOW_NETWORK_LIBRARY = "showNetworkLibrary"; const std::string ActionCode::SHOW_TOC = "toc"; const std::string ActionCode::SHOW_HELP = "showHelp"; const std::string ActionCode::SHOW_BOOK_INFO_DIALOG = "bookInfo"; const std::string ActionCode::SHOW_OPTIONS_DIALOG = "preferences"; const std::string ActionCode::SHOW_LIBRARY_OPTIONS_DIALOG = "libraryOptions"; const std::string ActionCode::SHOW_NETWORK_OPTIONS_DIALOG = "networkOptions"; const std::string ActionCode::SHOW_SYSTEM_OPTIONS_DIALOG = "systemOptions"; const std::string ActionCode::SHOW_READING_OPTIONS_DIALOG = "readingOptions"; const std::string ActionCode::SHOW_LOOKANDFEEL_OPTIONS_DIALOG = "lookAndFeelOptions"; const std::string ActionCode::UNDO = "undo"; const std::string ActionCode::REDO = "redo"; const std::string ActionCode::SEARCH = "search"; const std::string ActionCode::FIND_PREVIOUS = "findPrevious"; const std::string ActionCode::FIND_NEXT = "findNext"; const std::string ActionCode::PAGE_SCROLL_FORWARD = "pageForward"; const std::string ActionCode::PAGE_SCROLL_BACKWARD = "pageBackward"; const std::string ActionCode::LINE_SCROLL_FORWARD = "lineForward"; const std::string ActionCode::LINE_SCROLL_BACKWARD = "lineBackward"; const std::string ActionCode::MOUSE_SCROLL_FORWARD = "mouseScrollForward"; const std::string ActionCode::MOUSE_SCROLL_BACKWARD = "mouseScrollBackward"; const std::string ActionCode::TAP_SCROLL_FORWARD = "tapScrollForward"; const std::string ActionCode::TAP_SCROLL_BACKWARD = "tapScrollBackward"; const std::string ActionCode::SCROLL_TO_HOME = "gotoHome"; const std::string ActionCode::SCROLL_TO_START_OF_TEXT = "gotoSectionStart"; const std::string ActionCode::SCROLL_TO_END_OF_TEXT = "gotoSectionEnd"; const std::string ActionCode::CANCEL = "cancel"; const std::string ActionCode::INCREASE_FONT = "increaseFont"; const std::string ActionCode::DECREASE_FONT = "decreaseFont"; const std::string ActionCode::SHOW_HIDE_POSITION_INDICATOR = "toggleIndicator"; const std::string ActionCode::TOGGLE_FULLSCREEN = "toggleFullscreen"; const std::string ActionCode::FULLSCREEN_ON = "onFullscreen"; const std::string ActionCode::ADD_BOOK = "addBook"; const std::string ActionCode::ROTATE_SCREEN = "rotate"; const std::string ActionCode::QUIT = "quit"; const std::string ActionCode::FORCE_QUIT = "forceQuit"; const std::string ActionCode::OPEN_PREVIOUS_BOOK = "previousBook"; const std::string ActionCode::GOTO_NEXT_TOC_SECTION = "nextTOCSection"; const std::string ActionCode::GOTO_PREVIOUS_TOC_SECTION = "previousTOCSection"; const std::string ActionCode::COPY_SELECTED_TEXT_TO_CLIPBOARD = "copyToClipboard"; const std::string ActionCode::CLEAR_SELECTION = "clearSelection"; const std::string ActionCode::OPEN_SELECTED_TEXT_IN_DICTIONARY = "openInDictionary"; const std::string ActionCode::GOTO_PAGE_NUMBER = "gotoPageNumber"; const std::string ActionCode::GOTO_PAGE_NUMBER_WITH_PARAMETER = "gotoPageNumberWithParameter"; const std::string ActionCode::ORGANIZE_BOOKS_BY_AUTHOR = "byAuthor"; const std::string ActionCode::ORGANIZE_BOOKS_BY_TAG = "byTag"; const std::string ActionCode::FILTER_LIBRARY = "filterLibrary"; fbreader-0.99.4.orig/fbreader/src/fbreader/TimeUpdater.h0000644000706400070640000000200212056124565021423 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __TIMEUPDATER_H__ #define __TIMEUPDATER_H__ #include class TimeUpdater : public ZLRunnable { public: TimeUpdater(); private: void run(); private: short myTime; }; #endif /* __TIMEUPDATER_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/FBView.cpp0000644000706400070640000001763212056124565020674 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "FBView.h" #include "FBReader.h" #include "FBReaderActions.h" #include "../options/FBOptions.h" #include "../options/FBTextStyle.h" static const std::string INDICATOR = "Indicator"; FBIndicatorStyle::FBIndicatorStyle() : TypeOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "Type", 0, 2, ZLTextPositionIndicatorInfo::OS_SCROLLBAR), IsSensitiveOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "TouchSensitive", true), ShowTextPositionOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "PositionText", false), ShowTimeOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "Time", false), ColorOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "Color", ZLColor(127, 127, 127)), HeightOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "Height", 1, 100, 16), OffsetOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "Offset", 0, 100, 3), FontSizeOption(ZLCategoryKey::LOOK_AND_FEEL, INDICATOR, "FontSize", 4, 72, 14) { } ZLTextPositionIndicatorInfo::Type FBIndicatorStyle::type() const { return (ZLTextPositionIndicatorInfo::Type)TypeOption.value(); } bool FBIndicatorStyle::isSensitive() const { return IsSensitiveOption.value(); } bool FBIndicatorStyle::isTextPositionShown() const { return ShowTextPositionOption.value(); } bool FBIndicatorStyle::isTimeShown() const { return ShowTimeOption.value(); } ZLColor FBIndicatorStyle::color() const { return ColorOption.value(); } int FBIndicatorStyle::height() const { return HeightOption.value(); } int FBIndicatorStyle::offset() const { return OffsetOption.value(); } int FBIndicatorStyle::fontSize() const { return FontSizeOption.value(); } shared_ptr FBView::ourIndicatorInfo; shared_ptr FBView::ourSelectionOption; FBIndicatorStyle& FBView::commonIndicatorInfo() { if (ourIndicatorInfo.isNull()) { ourIndicatorInfo = new FBIndicatorStyle(); } return (FBIndicatorStyle&)*ourIndicatorInfo; } FBView::FBView(ZLPaintContext &context) : ZLTextView(context) { } shared_ptr FBView::indicatorInfo() const { if (ourIndicatorInfo.isNull()) { ourIndicatorInfo = new FBIndicatorStyle(); } return ourIndicatorInfo; } void FBView::doTapScrolling(int y) { if (2 * y < context().height()) { FBReader::Instance().doAction(ActionCode::TAP_SCROLL_BACKWARD); } else { FBReader::Instance().doAction(ActionCode::TAP_SCROLL_FORWARD); } } bool FBView::onFingerTap(int, int y) { doTapScrolling(y); return true; } const std::string &FBView::caption() const { return myCaption; } void FBView::setCaption(const std::string &caption) { myCaption = caption; std::replace(myCaption.begin(), myCaption.end(), '\n', ' '); std::replace(myCaption.begin(), myCaption.end(), '\r', ' '); ZLUnicodeUtil::cleanUtf8String(myCaption); } bool FBView::onStylusPress(int x, int y) { if (!myTapScroller.isNull()) { ZLTimeManager::Instance().removeTask(myTapScroller); myTapScroller.reset(); } myPressedX = x; myPressedY = y; myIsReleasedWithoutMotion = false; if (ZLTextView::onStylusPress(x, y)) { return true; } myIsReleasedWithoutMotion = true; if (_onStylusPress(x, y)) { return true; } return true; } bool FBView::_onStylusPress(int, int) { return false; } class FBView::TapScroller : public ZLRunnable { public: TapScroller(FBView &view, int y); private: void run(); private: FBView &myView; const int myY; }; FBView::TapScroller::TapScroller(FBView &view, int y) : myView(view), myY(y) { } void FBView::TapScroller::run() { myView.doTapScrolling(myY); } bool FBView::onStylusRelease(int x, int y) { const bool hadSelection = !selectionModel().isEmpty(); if (!myTapScroller.isNull()) { ZLTimeManager::Instance().removeTask(myTapScroller); myTapScroller.reset(); } if (ZLTextView::onStylusRelease(x, y)) { return true; } if (_onStylusRelease(x, y)) { return true; } FBReader &fbreader = FBReader::Instance(); myIsReleasedWithoutMotion = myIsReleasedWithoutMotion && std::abs(x - pressedX()) <= 5 && std::abs(y - pressedY()) <= 5; if (!hadSelection && isReleasedWithoutMotion() && fbreader.EnableTapScrollingOption.value() && (!ZLBooleanOption(ZLCategoryKey::EMPTY, ZLOption::PLATFORM_GROUP, ZLOption::FINGER_TAP_DETECTABLE, false).value() || !fbreader.TapScrollingOnFingerOnlyOption.value())) { myTapScroller = new TapScroller(*this, y); ZLTimeManager::Instance().addAutoRemovableTask(myTapScroller, doubleClickDelay()); return true; } return false; } bool FBView::_onStylusRelease(int, int) { return false; } bool FBView::onStylusMove(int x, int y) { if (ZLTextView::onStylusMove(x, y)) { return true; } if (_onStylusMove(x, y)) { return true; } return false; } bool FBView::_onStylusMove(int, int) { return false; } bool FBView::onStylusMovePressed(int x, int y) { if (myIsReleasedWithoutMotion) { if (std::abs(x - pressedX()) > 5 || std::abs(y - pressedY()) > 5) { myIsReleasedWithoutMotion = false; activateSelection(pressedX(), pressedY()); } } if (ZLTextView::onStylusMovePressed(x, y)) { return true; } if (_onStylusMovePressed(x, y)) { return true; } return false; } bool FBView::_onStylusMovePressed(int, int) { return false; } std::string FBView::word(const ZLTextElementRectangle &rectangle) const { std::string txt; if (rectangle.Kind == ZLTextElement::WORD_ELEMENT) { ZLTextWordCursor cursor = textArea().startCursor(); cursor.moveToParagraph(rectangle.ParagraphIndex); cursor.moveTo(rectangle.ElementIndex, 0); const ZLTextWord &word = (ZLTextWord&)cursor.element(); ZLUnicodeUtil::Ucs4String ucs4; ZLUnicodeUtil::utf8ToUcs4(ucs4, word.Data, word.Size); ZLUnicodeUtil::Ucs4String::iterator it = ucs4.begin(); while ((it != ucs4.end()) && !ZLUnicodeUtil::isLetter(*it)) { ++it; } if (it != ucs4.end()) { ucs4.erase(ucs4.begin(), it); it = ucs4.end() - 1; while (!ZLUnicodeUtil::isLetter(*it)) { --it; } ucs4.erase(it + 1, ucs4.end()); ZLUnicodeUtil::ucs4ToUtf8(txt, ucs4); } } return txt; } int FBView::leftMargin() const { return FBOptions::Instance().LeftMarginOption.value(); } int FBView::rightMargin() const { return FBOptions::Instance().RightMarginOption.value(); } int FBView::topMargin() const { return FBOptions::Instance().TopMarginOption.value(); } int FBView::bottomMargin() const { return FBOptions::Instance().BottomMarginOption.value(); } ZLColor FBView::backgroundColor() const { return FBOptions::Instance().BackgroundColorOption.value(); } ZLColor FBView::color(const std::string &colorStyle) const { return FBOptions::Instance().colorOption(colorStyle).value(); } shared_ptr FBView::baseStyle() const { return FBTextStyle::InstanceAsPtr(); } ZLBooleanOption &FBView::selectionOption() { if (ourSelectionOption.isNull()) { ourSelectionOption = new ZLBooleanOption(ZLCategoryKey::LOOK_AND_FEEL, "Options", "IsSelectionEnabled", true); } return *ourSelectionOption; } bool FBView::isSelectionEnabled() const { return selectionOption().value(); } int FBView::doubleClickDelay() const { return isSelectionEnabled() ? 200 : 0; } bool FBView::hasContents() const { return true; } fbreader-0.99.4.orig/fbreader/src/fbreader/FBReader.h0000644000706400070640000001257612056124565020633 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBREADER_H__ #define __FBREADER_H__ #include #include #include #include #include #include #include #include #include "../library/Library.h" #include "../external/ProgramCollection.h" class ZLFile; class ZLMessageHandler; class Book; class BookModel; class BookTextView; class FBReader : public ZLApplication { public: static FBReader &Instance(); public: // returns true if description was found or error message was shown static bool createBook(const ZLFile &bookFile, shared_ptr &book); static const std::string PageIndexParameter; public: enum ViewMode { UNDEFINED_MODE = 0, BOOK_TEXT_MODE = 1 << 0, FOOTNOTE_MODE = 1 << 1, CONTENTS_MODE = 1 << 2, BOOKMARKS_MODE = 1 << 3, LIBRARY_MODE = 1 << 4, ALL_MODES = 0xFF }; public: ZLBooleanOption QuitOnCancelOption; ZLIntegerRangeOption KeyScrollingDelayOption; ZLIntegerRangeOption LinesToScrollOption; ZLIntegerRangeOption LinesToKeepOption; ZLBooleanOption EnableTapScrollingOption; ZLBooleanOption TapScrollingOnFingerOnlyOption; ZLBooleanOption UseSeparateBindingsOption; ZLBooleanOption EnableSingleClickDictionaryOption; ZLStringOption LastOpenedPreferencesDialog; public: FBReader(const std::string &bookToOpen); ~FBReader(); void setMode(ViewMode mode); ViewMode mode() const; shared_ptr currentBook() const; void refreshWindow(); private: void initWindow(); void clearTextCaches(); void restorePreviousMode(); bool closeView(); std::string helpFileName(const std::string &language) const; void openFile(const ZLFile &file); bool canDragFiles(const std::vector &filePaths) const; void dragFiles(const std::vector &filePaths); bool isViewFinal() const; void showLibraryView(); public: shared_ptr keyBindings(); shared_ptr keyBindings(ZLView::Angle angle); bool isDictionarySupported() const; void openInDictionary(const std::string &word); shared_ptr webBrowserCollection() const; void openLinkInBrowser(const std::string &url) const; void tryShowFootnoteView(const std::string &id, ZLHyperlinkType type); BookTextView &bookTextView() const; void showBookTextView(); void openBook(shared_ptr book); bool showAuthDialog(const std::string &siteName, std::string &userName, std::string &password, const ZLResourceKey &errorKey); void saveUserName(const std::string &siteName, std::string &userName); private: shared_ptr dictionaryCollection() const; void openBookInternal(shared_ptr book); friend class OpenBookRunnable; void rebuildCollectionInternal(); friend class RebuildCollectionRunnable; friend class OptionsApplyRunnable; private: ViewMode myMode; ViewMode myPreviousMode; shared_ptr myFootnoteView; shared_ptr myBookTextView; shared_ptr myContentsView; shared_ptr myLibraryByAuthorView; shared_ptr myLibraryByTagView; shared_ptr myRecentBooksPopupData; shared_ptr myPreferencesPopupData; ZLTime myLastScrollingTime; shared_ptr myModel; shared_ptr myBindings0; shared_ptr myBindings90; shared_ptr myBindings180; shared_ptr myBindings270; std::string myBookToOpen; bool myBookAlreadyOpen; ProgramCollectionMap myProgramCollectionMap; shared_ptr myOpenFileHandler; enum { RETURN_TO_TEXT_MODE, UNFULLSCREEN } myActionOnCancel; friend class OpenFileHandler; friend class OptionsDialog; friend class SystemOptionsDialog; friend class FBView; //friend class ShowCollectionAction; friend class ShowHelpAction; //friend class ShowOptionsDialogAction; friend class ShowContentsAction; friend class AddBookAction; friend class ShowBookInfoAction; //friend class ScrollToHomeAction; //friend class ScrollToStartOfTextAction; //friend class ScrollToEndOfTextAction; friend class UndoAction; //friend class RedoAction; friend class SearchAction; friend class SearchPatternAction; friend class FindNextAction; friend class FindPreviousAction; friend class ScrollingAction; friend class ScrollingAction2; friend class ChangeFontSizeAction; friend class CancelAction; //friend class ToggleIndicatorAction; friend class QuitAction; friend class OpenPreviousBookAction; friend class GotoNextTOCSectionAction; friend class GotoPreviousTOCSectionAction; //friend class GotoPageNumber; friend class SelectionAction; friend class FBFullscreenAction; friend class BooksOrderAction; friend class LogOutAction; }; #endif /* __FBREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/PreferencesPopupData.cpp0000644000706400070640000000442612056124565023626 0ustar bagebage/* * Copyright (C) 2010-2012 Geometer Plus * * 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. */ #include "PreferencesPopupData.h" #include #include "FBReaderActions.h" PreferencesPopupData::PreferencesPopupData() { myActionIds.push_back(ActionCode::SHOW_BOOK_INFO_DIALOG); myActionIds.push_back(ActionCode::SHOW_READING_OPTIONS_DIALOG); myActionIds.push_back(ActionCode::SHOW_LOOKANDFEEL_OPTIONS_DIALOG); myActionIds.push_back(ActionCode::SHOW_LIBRARY_OPTIONS_DIALOG); myActionIds.push_back(ActionCode::SHOW_NETWORK_OPTIONS_DIALOG); myActionIds.push_back(ActionCode::SHOW_SYSTEM_OPTIONS_DIALOG); } std::size_t PreferencesPopupData::id() const { return myId; } void PreferencesPopupData::updateId() { ++myId; myInvalidated = true; } std::size_t PreferencesPopupData::count() const { if (myInvalidated) { myInvalidated = false; myVisibleActionIds.clear(); const FBReader& fbreader = FBReader::Instance(); const std::size_t size = myActionIds.size(); for (std::size_t i = 0; i < size; ++i) { const std::string &actionId = myActionIds[i]; if (fbreader.action(actionId)->isVisible()) { myVisibleActionIds.push_back(actionId); } } } return myVisibleActionIds.size(); } const std::string PreferencesPopupData::text(std::size_t index) { if (index >= myVisibleActionIds.size()) { return ""; } const std::string &actionId = myVisibleActionIds[index]; return resource(actionId)["label"].value(); } void PreferencesPopupData::run(std::size_t index) { if (index >= myVisibleActionIds.size()) { return; } FBReader::Instance().doAction(myVisibleActionIds[index]); } fbreader-0.99.4.orig/fbreader/src/fbreader/SearchActions.cpp0000644000706400070640000001162112056124565022270 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "FBReader.h" #include "FBView.h" #include "FBReaderActions.h" #include "../options/FBCategoryKey.h" #include static const std::string SEARCH = "Search"; static const std::string PATTERN = "Pattern"; class SearchPatternEntry : public ZLComboOptionEntry { public: SearchPatternEntry(SearchPatternAction &action); const std::string &initialValue() const; const std::vector &values() const; void onAccept(const std::string &value); private: SearchPatternAction &myAction; mutable std::vector myValues; }; SearchPatternEntry::SearchPatternEntry(SearchPatternAction &action) : ZLComboOptionEntry(true), myAction(action) { } const std::string &SearchPatternEntry::initialValue() const { return values()[0]; } const std::vector &SearchPatternEntry::values() const { if (myValues.empty()) { myValues.push_back(myAction.SearchPatternOption.value()); for (int i = 1; i < 6; ++i) { std::string pattern = PATTERN; ZLStringUtil::appendNumber(pattern, i); std::string value = ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").value(); if (!value.empty()) { myValues.push_back(value); } } } return myValues; } void SearchPatternEntry::onAccept(const std::string &value) { std::string v = value; ZLStringUtil::stripWhiteSpaces(v); if (v != values()[0]) { myAction.SearchPatternOption.setValue(v); int index = 1; for (std::vector::const_iterator it = myValues.begin(); (index < 6) && (it != myValues.end()); ++it) { if (*it != v) { std::string pattern = PATTERN; ZLStringUtil::appendNumber(pattern, index++); ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").setValue(*it); } } } } bool SearchAction::isVisible() const { shared_ptr view = FBReader::Instance().currentView(); return !view.isNull() && view->isInstanceOf(ZLTextView::TYPE_ID) && ((FBView&)*view).hasContents(); } SearchPatternAction::SearchPatternAction() : SearchBackwardOption(FBCategoryKey::SEARCH, SEARCH, "Backward", false), SearchIgnoreCaseOption(FBCategoryKey::SEARCH, SEARCH, "IgnoreCase", true), SearchInWholeTextOption(FBCategoryKey::SEARCH, SEARCH, "WholeText", false), SearchThisSectionOnlyOption(FBCategoryKey::SEARCH, SEARCH, "ThisSectionOnly", false), SearchPatternOption(FBCategoryKey::SEARCH, SEARCH, PATTERN, "") { } void SearchPatternAction::run() { ZLTextView &textView = (ZLTextView&)*FBReader::Instance().currentView(); shared_ptr searchDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("textSearchDialog")); searchDialog->addOption(ZLResourceKey("text"), new SearchPatternEntry(*this)); searchDialog->addOption(ZLResourceKey("ignoreCase"), SearchIgnoreCaseOption); searchDialog->addOption(ZLResourceKey("wholeText"), SearchInWholeTextOption); searchDialog->addOption(ZLResourceKey("backward"), SearchBackwardOption); if (textView.hasMultiSectionModel()) { searchDialog->addOption(ZLResourceKey("currentSection"), SearchThisSectionOnlyOption); } searchDialog->addButton(ZLResourceKey("go"), true); searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); if (searchDialog->run()) { searchDialog->acceptValues(); textView.search( SearchPatternOption.value(), SearchIgnoreCaseOption.value(), SearchInWholeTextOption.value(), SearchBackwardOption.value(), SearchThisSectionOnlyOption.value() ); } } bool FindNextAction::isEnabled() const { shared_ptr view = FBReader::Instance().currentView(); return !view.isNull() && view->isInstanceOf(ZLTextView::TYPE_ID) && ((ZLTextView&)*view).canFindNext(); return false; } void FindNextAction::run() { ((ZLTextView&)*FBReader::Instance().currentView()).findNext(); } bool FindPreviousAction::isEnabled() const { shared_ptr view = FBReader::Instance().currentView(); return !view.isNull() && view->isInstanceOf(ZLTextView::TYPE_ID) && ((ZLTextView&)*view).canFindPrevious(); } void FindPreviousAction::run() { ((ZLTextView&)*FBReader::Instance().currentView()).findPrevious(); } fbreader-0.99.4.orig/fbreader/src/fbreader/ReadingState.h0000644000706400070640000000316712056124565021567 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __READINGSTATE_H___ #define __READINGSTATE_H___ struct ReadingState { int Paragraph; int Word; int Character; ReadingState(); ReadingState(int paragraph, int word, int character); bool operator == (const ReadingState &rs) const; bool operator != (const ReadingState &rs) const; }; inline ReadingState::ReadingState(): Paragraph(0), Word(0), Character(0) {} inline ReadingState::ReadingState(int paragraph, int word, int character): Paragraph(paragraph), Word(word), Character(character) {} inline bool ReadingState::operator == (const ReadingState &rs) const { return Paragraph == rs.Paragraph && Word == rs.Word && Character == rs.Character; } inline bool ReadingState::operator != (const ReadingState &rs) const { return Paragraph != rs.Paragraph || Word != rs.Word || Character != rs.Character; } #endif /* __READINGSTATE_H___ */ fbreader-0.99.4.orig/fbreader/src/fbreader/PreferencesPopupData.h0000644000706400070640000000252612056124565023272 0ustar bagebage/* * Copyright (C) 2010-2012 Geometer Plus * * 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. */ #ifndef __PREFERENCESPOPUPDATA_H__ #define __PREFERENCESPOPUPDATA_H__ #include #include #include class PreferencesPopupData: public ZLPopupData { public: PreferencesPopupData(); void updateId(); private: std::size_t id() const; std::size_t count() const; const std::string text(std::size_t index); void run(std::size_t index); private: std::size_t myId; std::vector myActionIds; mutable bool myInvalidated; mutable std::vector myVisibleActionIds; }; #endif /* __PREFERENCESPOPUPDATA_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/main.cpp0000644000706400070640000000201212056124565020460 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "FBReader.h" int main(int argc, char **argv) { if (!ZLibrary::init(argc, argv)) { return 1; } ZLibrary::run(new FBReader(argc == 1 ? std::string() : argv[1])); ZLibrary::shutdown(); return 0; } fbreader-0.99.4.orig/fbreader/src/fbreader/SearchOnNetworkAction.cpp0000644000706400070640000001447012056124565023761 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "../options/FBCategoryKey.h" #include "FBReaderActions.h" #include "../network/NetworkLink.h" #include "../network/NetworkLinkCollection.h" #include "../network/SearchResult.h" #include "../network/authentication/NetworkAuthenticationManager.h" #include "../networkActions/NetworkOperationRunnable.h" #include "../network/tree/NetworkLibrary.h" static const std::string SEARCH_PARAMETER_ID = "networkSearchPattern"; ShowNetworkTreeLibraryAction::ShowNetworkTreeLibraryAction() { } void ShowNetworkTreeLibraryAction::run() { NetworkLibrary::Instance().showDialog(); } SearchOnNetworkAction::SearchOnNetworkAction() { } void SearchOnNetworkAction::run() { // NetworkLinkCollection &collection = NetworkLinkCollection::Instance(); // for (std::size_t i = 0; i < collection.size(); ++i) { // NetworkLink &link = collection.link(i); // if (link.isEnabled()) { // shared_ptr mgr = link.authenticationManager(); // if (!mgr.isNull()) { // IsAuthorisedRunnable checker(*mgr); // checker.executeWithUI(); // if (checker.result() == B3_TRUE && mgr->needsInitialization()) { // InitializeAuthenticationManagerRunnable initializer(*mgr); // initializer.executeWithUI(); // if (initializer.hasErrors()) { // LogOutRunnable logout(*mgr); // logout.executeWithUI(); // } // } // } // } // } // doSearch(); } void SimpleSearchOnNetworkAction::doSearch() { FBReader &fbreader = FBReader::Instance(); const std::string pattern = fbreader.visualParameter(SEARCH_PARAMETER_ID); if (pattern.empty()) { return; } if (!NetworkOperationRunnable::tryConnect()) { return; } SimpleSearchRunnable runnable(pattern); runnable.executeWithUI(); runnable.showErrorMessage(); shared_ptr result = runnable.result(); if (!result.isNull()) { std::string summary = makeSummary(pattern); SearchResult::setLastSearchResult(summary, result); } fbreader.refreshWindow(); } void AdvancedSearchOnNetworkAction::doSearch() { shared_ptr searchDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("networkSearchDialog")); ZLStringOption titleAndSeriesOption(FBCategoryKey::SEARCH, "network", "title", ""); searchDialog->addOption(ZLResourceKey("titleAndSeries"), titleAndSeriesOption); ZLStringOption authorOption(FBCategoryKey::SEARCH, "network", "author", ""); searchDialog->addOption(ZLResourceKey("author"), authorOption); //ZLStringOption seriesOption(FBCategoryKey::SEARCH, "network", "series", ""); //searchDialog->addOption(ZLResourceKey("series"), seriesOption); ZLStringOption categoryOption(FBCategoryKey::SEARCH, "network", "category", ""); searchDialog->addOption(ZLResourceKey("category"), categoryOption); ZLStringOption descriptionOption(FBCategoryKey::SEARCH, "network", "description", ""); searchDialog->addOption(ZLResourceKey("description"), descriptionOption); searchDialog->addButton(ZLResourceKey("go"), true); searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); if (searchDialog->run()) { searchDialog->acceptValues(); searchDialog.reset(); std::string titleAndSeriesPattern = titleAndSeriesOption.value(); ZLUnicodeUtil::utf8Trim(titleAndSeriesPattern); std::string authorPattern = authorOption.value(); ZLUnicodeUtil::utf8Trim(authorPattern); //std::string seriesPattern = seriesOption.value(); //ZLUnicodeUtil::utf8Trim(seriesPattern); std::string categoryPattern = categoryOption.value(); ZLUnicodeUtil::utf8Trim(categoryPattern); std::string descriptionPattern = descriptionOption.value(); ZLUnicodeUtil::utf8Trim(descriptionPattern); if (!titleAndSeriesPattern.empty() || !authorPattern.empty() || //!seriesPattern.empty() || !categoryPattern.empty() || !descriptionPattern.empty()) { if (!NetworkOperationRunnable::tryConnect()) { return; } AdvancedSearchRunnable runnable(titleAndSeriesPattern, authorPattern, categoryPattern, descriptionPattern); runnable.executeWithUI(); runnable.showErrorMessage(); shared_ptr result = runnable.result(); if (!result.isNull()) { std::string summary = makeSummary(titleAndSeriesPattern, authorPattern, categoryPattern, descriptionPattern); SearchResult::setLastSearchResult(summary, result); } FBReader::Instance().refreshWindow(); } } } std::string SimpleSearchOnNetworkAction::makeSummary(const std::string &pattern) { const ZLResource &resource = ZLResource::resource("dialog")["networkSearchDialog"]; return ZLStringUtil::printf(resource["annotation"].value(), pattern); } std::string AdvancedSearchOnNetworkAction::makeSummary(const std::string &titleAndSeries, const std::string &author, const std::string &category, const std::string &description) { const ZLResource &resource = ZLResource::resource("dialog")["networkSearchDialog"]; std::string query; appendQueryValue(query, resource["titleAndSeries"].value(), titleAndSeries); appendQueryValue(query, resource["author"].value(), author); appendQueryValue(query, resource["category"].value(), category); appendQueryValue(query, resource["description"].value(), description); return ZLStringUtil::printf(resource["annotation"].value(), query); } void AdvancedSearchOnNetworkAction::appendQueryValue(std::string &query, const std::string &name, const std::string &value) { if (value.empty()) { return; } if (!query.empty()) { query.append(", "); } query.append(name).append("=\"").append(value).append("\""); } fbreader-0.99.4.orig/fbreader/src/fbreader/ContentsView.h0000644000706400070640000000227712056124565021646 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __CONTENTSVIEW_H__ #define __CONTENTSVIEW_H__ #include "FBView.h" class ContentsView : public FBView { public: ContentsView(ZLPaintContext &context); ~ContentsView(); bool isEmpty() const; std::size_t currentTextViewParagraph(bool includeStart = true) const; void gotoReference(); private: bool _onStylusPress(int x, int y); bool _onStylusMove(int x, int y); }; #endif /* __CONTENTSVIEW_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/BookTextView.cpp0000644000706400070640000003250512056124565022140 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include #include #include #include "BookTextView.h" #include "FBReader.h" #include "../bookmodel/FBTextKind.h" #include "../bookmodel/BookModel.h" #include "../external/ProgramCollection.h" #include "../database/booksdb/BooksDB.h" #include "../library/Book.h" class BookTextView::PositionIndicatorWithLabels : public PositionIndicator { public: PositionIndicatorWithLabels(BookTextView &bookTextView, const ZLTextPositionIndicatorInfo &info); private: void draw(); }; static const std::string LAST_STATE_GROUP = "LastState"; static const std::string PARAGRAPH_OPTION_NAME = "Paragraph"; static const std::string WORD_OPTION_NAME = "Word"; static const std::string CHAR_OPTION_NAME = "Char"; static const std::string POSITION_IN_BUFFER = "PositionInBuffer"; static const std::string STATE_VALID = "Valid"; BookTextView::BookTextView(ZLPaintContext &context) : FBView(context), ShowTOCMarksOption(ZLCategoryKey::LOOK_AND_FEEL, "Indicator", "ShowTOCMarks", false) { myCurrentPointInStack = 0; myMaxStackSize = 20; myLockUndoStackChanges = false; myStackChanged = false; } BookTextView::~BookTextView() { saveState(); setModel(0, 0); } void BookTextView::readBookState(const Book &book) { ReadingState state; if (ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).value()) { state.Paragraph = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).value(); state.Word = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).value(); state.Character = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).value(); } else { BooksDB::Instance().loadBookState(book, state); } gotoPosition(state.Paragraph, state.Word, state.Character); } int BookTextView::readStackPos(const Book &book) { if (ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).value()) { return ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).value(); } else { return BooksDB::Instance().loadStackPos(book); } } void BookTextView::saveBookState(const Book &book) { const ReadingState state( ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).value(), ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).value() ); const int stackPos = ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).value(); BooksDB::Instance().setBookState(book, state); BooksDB::Instance().setStackPos(book, stackPos); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).setValue(0); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).setValue(0); ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).setValue(false); } void BookTextView::setModel(shared_ptr model, shared_ptr book) { FBView::setModel(model); if (!myBook.isNull()) { saveBookState(*myBook); } myBook = book; if (book.isNull()) { return; } readBookState(*book); myPositionStack.clear(); myCurrentPointInStack = 0; BooksDB::Instance().loadBookStateStack(*book, myPositionStack); myStackChanged = false; if (myPositionStack.size() > 0) { int stackPos = readStackPos(*book); if ((stackPos < 0) || (stackPos > (int) myPositionStack.size())) { stackPos = myPositionStack.size(); } myCurrentPointInStack = stackPos; while (myPositionStack.size() > myMaxStackSize) { myPositionStack.erase(myPositionStack.begin()); if (myCurrentPointInStack > 0) { --myCurrentPointInStack; } myStackChanged = true; } } } void BookTextView::setContentsModel(shared_ptr contentsModel) { myContentsModel = contentsModel; } void BookTextView::saveState() { const ZLTextWordCursor &cursor = textArea().startCursor(); if (myBook.isNull()) { return; } if (!cursor.isNull()) { ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, PARAGRAPH_OPTION_NAME, 0).setValue(cursor.paragraphCursor().index()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, WORD_OPTION_NAME, 0).setValue(cursor.elementIndex()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, CHAR_OPTION_NAME, 0).setValue(cursor.charIndex()); ZLIntegerOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, POSITION_IN_BUFFER, 0).setValue(myCurrentPointInStack); ZLBooleanOption(ZLCategoryKey::STATE, LAST_STATE_GROUP, STATE_VALID, false).setValue(true); if (myStackChanged) { BooksDB::Instance().saveBookStateStack(*myBook, myPositionStack); myStackChanged = false; } } } BookTextView::Position BookTextView::cursorPosition(const ZLTextWordCursor &cursor) const { return Position(cursor.paragraphCursor().index(), cursor.elementIndex(), cursor.charIndex()); } bool BookTextView::pushCurrentPositionIntoStack(bool doPushSamePosition) { const ZLTextWordCursor &cursor = textArea().startCursor(); if (cursor.isNull()) { return false; } Position pos = cursorPosition(cursor); if (!doPushSamePosition && !myPositionStack.empty() && (myPositionStack.back() == pos)) { return false; } myPositionStack.push_back(pos); myStackChanged = true; while (myPositionStack.size() > myMaxStackSize) { myPositionStack.erase(myPositionStack.begin()); if (myCurrentPointInStack > 0) { --myCurrentPointInStack; } } return true; } void BookTextView::replaceCurrentPositionInStack() { const ZLTextWordCursor &cursor = textArea().startCursor(); if (!cursor.isNull()) { myPositionStack[myCurrentPointInStack] = cursorPosition(cursor); myStackChanged = true; } } void BookTextView::gotoParagraph(int num, bool end) { if (textArea().isEmpty()) { return; } if (!myLockUndoStackChanges) { if (myPositionStack.size() > myCurrentPointInStack) { myPositionStack.erase(myPositionStack.begin() + myCurrentPointInStack, myPositionStack.end()); myStackChanged = true; } pushCurrentPositionIntoStack(false); myCurrentPointInStack = myPositionStack.size(); } FBView::gotoParagraph(num, end); } bool BookTextView::canUndoPageMove() { if (textArea().isEmpty()) { return false; } if (myCurrentPointInStack == 0) { return false; } if ((myCurrentPointInStack == 1) && (myPositionStack.size() == 1)) { const ZLTextWordCursor &cursor = textArea().startCursor(); if (!cursor.isNull()) { return myPositionStack.back() != cursorPosition(cursor); } } return true; } void BookTextView::undoPageMove() { if (canUndoPageMove()) { if (myCurrentPointInStack == myPositionStack.size()) { if (!pushCurrentPositionIntoStack(false)) { -- myCurrentPointInStack; } } else { replaceCurrentPositionInStack(); } --myCurrentPointInStack; Position &pos = myPositionStack[myCurrentPointInStack]; myLockUndoStackChanges = true; gotoPosition(pos.Paragraph, pos.Word, pos.Character); myLockUndoStackChanges = false; FBReader::Instance().refreshWindow(); } } bool BookTextView::canRedoPageMove() { return !textArea().isEmpty() && myCurrentPointInStack + 1 < myPositionStack.size(); } void BookTextView::redoPageMove() { if (canRedoPageMove()) { replaceCurrentPositionInStack(); ++myCurrentPointInStack; Position &pos = myPositionStack[myCurrentPointInStack]; myLockUndoStackChanges = true; gotoPosition(pos.Paragraph, pos.Word, pos.Character); myLockUndoStackChanges = false; if (myCurrentPointInStack + 1 == myPositionStack.size()) { myPositionStack.pop_back(); myStackChanged = true; } FBReader::Instance().refreshWindow(); } } bool BookTextView::getHyperlinkInfo(const ZLTextElementRectangle &rectangle, std::string &id, ZLHyperlinkType &type) const { if ((rectangle.Kind != ZLTextElement::WORD_ELEMENT) && (rectangle.Kind != ZLTextElement::IMAGE_ELEMENT)) { return false; } ZLTextWordCursor cursor = textArea().startCursor(); cursor.moveToParagraph(rectangle.ParagraphIndex); cursor.moveToParagraphStart(); ZLTextKind hyperlinkKind = REGULAR; for (int i = 0; i < rectangle.ElementIndex; ++i) { const ZLTextElement &element = cursor.element(); if (element.kind() == ZLTextElement::CONTROL_ELEMENT) { const ZLTextControlEntry &control = ((const ZLTextControlElement&)element).entry(); if (control.isHyperlink()) { hyperlinkKind = control.kind(); id = ((const ZLTextHyperlinkControlEntry&)control).label(); type = ((const ZLTextHyperlinkControlEntry&)control).hyperlinkType(); } else if (!control.isStart() && (control.kind() == hyperlinkKind)) { hyperlinkKind = REGULAR; } } cursor.nextWord(); } return hyperlinkKind != REGULAR; } bool BookTextView::_onStylusPress(int x, int y) { return false; } bool BookTextView::onStylusClick(int x, int y, int count) { FBReader &fbreader = FBReader::Instance(); const ZLTextElementRectangle *rectangle = textArea().elementByCoordinates(x, y); if (rectangle != 0) { std::string id; ZLHyperlinkType type; if (getHyperlinkInfo(*rectangle, id, type)) { fbreader.tryShowFootnoteView(id, type); return true; } if (fbreader.isDictionarySupported() && fbreader.EnableSingleClickDictionaryOption.value()) { const std::string txt = word(*rectangle); if (!txt.empty()) { fbreader.openInDictionary(txt); return true; } } } return FBView::onStylusClick(x, y, count); } bool BookTextView::_onStylusRelease(int x, int y) { FBReader &fbreader = FBReader::Instance(); if (!isReleasedWithoutMotion()) { return false; } const ZLTextElementRectangle *rectangle = textArea().elementByCoordinates(x, y); if (rectangle != 0) { std::string id; ZLHyperlinkType type; if (getHyperlinkInfo(*rectangle, id, type)) { fbreader.tryShowFootnoteView(id, type); return true; } if (fbreader.isDictionarySupported() && fbreader.EnableSingleClickDictionaryOption.value()) { const std::string txt = word(*rectangle); if (!txt.empty()) { fbreader.openInDictionary(txt); return true; } } } return false; } bool BookTextView::_onStylusMove(int x, int y) { const ZLTextElementRectangle *rectangle = textArea().elementByCoordinates(x, y); std::string id; ZLHyperlinkType type; FBReader::Instance().setHyperlinkCursor((rectangle != 0) && getHyperlinkInfo(*rectangle, id, type)); return true; } shared_ptr BookTextView::createPositionIndicator(const ZLTextPositionIndicatorInfo &info) { return new PositionIndicatorWithLabels(*this, info); } BookTextView::PositionIndicatorWithLabels::PositionIndicatorWithLabels(BookTextView &bookTextView, const ZLTextPositionIndicatorInfo &info) : PositionIndicator(bookTextView, info) { } void BookTextView::PositionIndicatorWithLabels::draw() { PositionIndicator::draw(); const BookTextView& bookTextView = (const BookTextView&)textView(); if (bookTextView.ShowTOCMarksOption.value()) { shared_ptr contentsModelPtr = bookTextView.myContentsModel; if (!contentsModelPtr.isNull()) { ContentsModel &contentsModel = (ContentsModel&)*contentsModelPtr; const int marksNumber = contentsModel.paragraphsNumber(); const std::size_t startIndex = startTextIndex(); const std::size_t endIndex = endTextIndex(); const std::vector &textSizeVector = textSize(); const int fullWidth = right() - left() - 1; const std::size_t startPosition = textSizeVector[startIndex]; const std::size_t fullTextSize = textSizeVector[endIndex] - startPosition; const int bottom = this->bottom(); const int top = this->top(); for (int i = 0; i < marksNumber; ++i) { std::size_t reference = contentsModel.reference((ZLTextTreeParagraph*)contentsModel[i]); if ((startIndex < reference) && (reference < endIndex)) { int position = left() + 2 + (int) (1.0 * fullWidth * (textSizeVector[reference] - startPosition) / fullTextSize); context().drawLine(position, bottom, position, top); } } } } } void BookTextView::scrollToHome() { if (!textArea().startCursor().isNull() && textArea().startCursor().isStartOfParagraph() && textArea().startCursor().paragraphCursor().index() == 0) { return; } gotoParagraph(0, false); FBReader::Instance().refreshWindow(); } void BookTextView::paint() { FBView::paint(); std::string pn; ZLStringUtil::appendNumber(pn, pageIndex()); FBReader::Instance().setVisualParameter(FBReader::PageIndexParameter, pn); } fbreader-0.99.4.orig/fbreader/src/fbreader/ScrollingAction.cpp0000644000706400070640000000642112056124565022636 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include "FBReader.h" #include "ScrollingAction.h" ScrollingAction::ScrollingAction( ZLTextAreaController::ScrollingMode textScrollingMode, ZLBlockTreeView::ScrollingMode blockScrollingMode, bool forward ) : myTextScrollingMode(textScrollingMode), myBlockScrollingMode(blockScrollingMode), myForward(forward) { } int ScrollingAction::scrollingDelay() const { return 0; } bool ScrollingAction::isEnabled() const { return true; } bool ScrollingAction::useKeyDelay() const { return false; } void ScrollingAction::run() { FBReader &fbreader = FBReader::Instance(); shared_ptr view = fbreader.currentView(); int delay = fbreader.myLastScrollingTime.millisecondsTo(ZLTime()); if (view.isNull() || (delay >= 0 && delay < scrollingDelay())) { return; } if (view->isInstanceOf(ZLTextView::TYPE_ID)) { ((ZLTextView&)*view).scrollPage(myForward, myTextScrollingMode, textOptionValue()); FBReader::Instance().refreshWindow(); } else if (view->isInstanceOf(ZLBlockTreeView::TYPE_ID)) { ((ZLBlockTreeView&)*view).scroll(myBlockScrollingMode, !myForward); } fbreader.myLastScrollingTime = ZLTime(); } LineScrollingAction::LineScrollingAction(bool forward) : ScrollingAction(ZLTextAreaController::SCROLL_LINES, ZLBlockTreeView::ITEM, forward) { } int LineScrollingAction::scrollingDelay() const { return FBReader::Instance().KeyScrollingDelayOption.value(); } std::size_t LineScrollingAction::textOptionValue() const { return FBReader::Instance().LinesToScrollOption.value(); } PageScrollingAction::PageScrollingAction(bool forward) : ScrollingAction(ZLTextAreaController::KEEP_LINES, ZLBlockTreeView::PAGE, forward) { } int PageScrollingAction::scrollingDelay() const { return FBReader::Instance().KeyScrollingDelayOption.value(); } std::size_t PageScrollingAction::textOptionValue() const { return FBReader::Instance().LinesToKeepOption.value(); } MouseWheelScrollingAction::MouseWheelScrollingAction(bool forward) : ScrollingAction(ZLTextAreaController::SCROLL_LINES, ZLBlockTreeView::ITEM, forward) { } std::size_t MouseWheelScrollingAction::textOptionValue() const { return 1; } TapScrollingAction::TapScrollingAction(bool forward) : ScrollingAction(ZLTextAreaController::KEEP_LINES, ZLBlockTreeView::NONE, forward) { } std::size_t TapScrollingAction::textOptionValue() const { return FBReader::Instance().LinesToKeepOption.value(); } bool TapScrollingAction::isEnabled() const { return FBReader::Instance().EnableTapScrollingOption.value(); } fbreader-0.99.4.orig/fbreader/src/fbreader/ContentsView.cpp0000644000706400070640000000673012056124565022177 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "ContentsView.h" #include "BookTextView.h" #include "FBReader.h" #include "../bookmodel/BookModel.h" ContentsView::ContentsView(ZLPaintContext &context) : FBView(context) { } ContentsView::~ContentsView() { } bool ContentsView::_onStylusMove(int x, int y) { FBReader &fbreader = FBReader::Instance(); int index = textArea().paragraphIndexByCoordinates(x, y); if ((index < 0) || ((int)textArea().model()->paragraphsNumber() <= index)) { fbreader.setHyperlinkCursor(false); return true; } const ContentsModel &contentsModel = (const ContentsModel&)*textArea().model(); const ZLTextTreeParagraph *paragraph = (const ZLTextTreeParagraph*)contentsModel[index]; fbreader.setHyperlinkCursor(contentsModel.reference(paragraph) >= 0); return true; } bool ContentsView::_onStylusPress(int x, int y) { FBReader &fbreader = FBReader::Instance(); const ContentsModel &contentsModel = (const ContentsModel&)*textArea().model(); int index = textArea().paragraphIndexByCoordinates(x, y); if ((index < 0) || ((int)contentsModel.paragraphsNumber() <= index)) { return false; } const ZLTextTreeParagraph *paragraph = (const ZLTextTreeParagraph*)contentsModel[index]; int reference = contentsModel.reference(paragraph); if (reference >= 0) { fbreader.bookTextView().gotoParagraph(reference); fbreader.showBookTextView(); } return true; } bool ContentsView::isEmpty() const { shared_ptr model = textArea().model(); return model.isNull() || model->paragraphsNumber() == 0; } std::size_t ContentsView::currentTextViewParagraph(bool includeStart) const { const ZLTextWordCursor &cursor = FBReader::Instance().bookTextView().textArea().startCursor(); if (!cursor.isNull()) { long reference = cursor.paragraphCursor().index(); bool startOfParagraph = cursor.elementIndex() == 0; if (cursor.isEndOfParagraph()) { ++reference; startOfParagraph = true; } shared_ptr model = textArea().model(); std::size_t length = model->paragraphsNumber(); const ContentsModel &contentsModel = (const ContentsModel&)*model; for (std::size_t i = 1; i < length; ++i) { long contentsReference = contentsModel.reference(((const ZLTextTreeParagraph*)contentsModel[i])); if ((contentsReference > reference) || (!includeStart && startOfParagraph && (contentsReference == reference))) { return i - 1; } } return length - 1; } return (std::size_t)-1; } void ContentsView::gotoReference() { textArea().model()->removeAllMarks(); const std::size_t selected = currentTextViewParagraph(); highlightParagraph(selected); preparePaintInfo(); gotoParagraph(selected); scrollPage(false, ZLTextAreaController::SCROLL_PERCENTAGE, 40); } fbreader-0.99.4.orig/fbreader/src/fbreader/TimeUpdater.cpp0000644000706400070640000000231012056124565021760 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "FBView.h" #include "TimeUpdater.h" TimeUpdater::TimeUpdater() : myTime(-1) { } void TimeUpdater::run() { if (FBView::commonIndicatorInfo().ShowTimeOption.value()) { ZLTime time; short minutes = time.hours() * 60 + time.minutes(); if (myTime != minutes) { myTime = minutes; ZLApplication::Instance().refreshWindow(); } } } fbreader-0.99.4.orig/fbreader/src/fbreader/FootnoteView.h0000644000706400070640000000206712056124565021643 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FOOTNOTEVIEW_H__ #define __FOOTNOTEVIEW_H__ #include "FBView.h" class FootnoteView : public FBView { public: FootnoteView(ZLPaintContext &context); }; inline FootnoteView::FootnoteView(ZLPaintContext &context) : FBView(context) {} #endif /* __FOOTNOTEVIEW_H__ */ fbreader-0.99.4.orig/fbreader/src/fbreader/FBReader.cpp0000644000706400070640000004360512056124565021163 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "FBReader.h" #include "FBReaderActions.h" #include "ScrollingAction.h" #include "BookTextView.h" #include "FootnoteView.h" #include "ContentsView.h" #include "RecentBooksPopupData.h" #include "PreferencesPopupData.h" #include "TimeUpdater.h" #include "../libraryTree/LibraryView.h" #include "../network/NetworkLinkCollection.h" #include "../networkActions/NetworkOperationRunnable.h" #include "../migration/migrate.h" #include "../options/FBCategoryKey.h" #include "../bookmodel/BookModel.h" #include "../bookmodel/FBHyperlinkType.h" #include "../formats/FormatPlugin.h" #include "../database/booksdb/BooksDB.h" #include "../database/booksdb/BooksDBUtil.h" #include "../library/Book.h" #include "../networkActions/AuthenticationDialog.h" #include "../network/NetworkErrors.h" static const std::string OPTIONS = "Options"; const std::string FBReader::PageIndexParameter = "pageIndex"; class OpenFileHandler : public ZLMessageHandler { public: void onMessageReceived(const std::vector &arguments) { if (arguments.size() == 1) { FBReader &fbreader = FBReader::Instance(); fbreader.myBookAlreadyOpen = true; fbreader.presentWindow(); fbreader.openFile(ZLFile(arguments[0])); } } }; FBReader &FBReader::Instance() { return (FBReader&)ZLApplication::Instance(); } FBReader::FBReader(const std::string &bookToOpen) : ZLApplication("FBReader"), QuitOnCancelOption(ZLCategoryKey::CONFIG, OPTIONS, "QuitOnCancel", false), KeyScrollingDelayOption(ZLCategoryKey::CONFIG, "Scrollings", "Delay", 0, 2000, 100), LinesToScrollOption(ZLCategoryKey::CONFIG, "SmallScrolling", "LinesToScroll", 1, 20, 1), LinesToKeepOption(ZLCategoryKey::CONFIG, "LargeScrolling", "LinesToKeepOption", 0, 20, 0), EnableTapScrollingOption(ZLCategoryKey::CONFIG, "TapScrolling", "Enabled", true), TapScrollingOnFingerOnlyOption(ZLCategoryKey::CONFIG, "TapScrolling", "FingerOnly", true), UseSeparateBindingsOption(ZLCategoryKey::CONFIG, "KeysOptions", "UseSeparateBindings", false), EnableSingleClickDictionaryOption(ZLCategoryKey::CONFIG, "Dictionary", "SingleClick", false), LastOpenedPreferencesDialog(ZLCategoryKey::CONFIG, "PreferencesDialog", "LastOpened", ""), myBindings0(new ZLKeyBindings("Keys")), myBindings90(new ZLKeyBindings("Keys90")), myBindings180(new ZLKeyBindings("Keys180")), myBindings270(new ZLKeyBindings("Keys270")), myBookToOpen(bookToOpen), myBookAlreadyOpen(false), myActionOnCancel(UNFULLSCREEN) { myBookTextView = new BookTextView(*context()); myFootnoteView = new FootnoteView(*context()); myContentsView = new ContentsView(*context()); myLibraryByAuthorView = new LibraryByAuthorView(*context()); myLibraryByTagView = new LibraryByTagView(*context()); myRecentBooksPopupData = new RecentBooksPopupData(); myPreferencesPopupData = new PreferencesPopupData(); myMode = UNDEFINED_MODE; myPreviousMode = BOOK_TEXT_MODE; setMode(BOOK_TEXT_MODE); addAction(ActionCode::SHOW_READING, new UndoAction(FBReader::ALL_MODES & ~FBReader::BOOK_TEXT_MODE)); addAction(ActionCode::SHOW_LIBRARY, new SetModeAction(FBReader::LIBRARY_MODE, FBReader::BOOK_TEXT_MODE | FBReader::CONTENTS_MODE)); addAction(ActionCode::SHOW_NETWORK_LIBRARY, new ShowNetworkTreeLibraryAction()); registerPopupData(ActionCode::SHOW_LIBRARY, myRecentBooksPopupData); addAction(ActionCode::SHOW_OPTIONS_DIALOG, new ShowOptionsDialogAction()); addAction(ActionCode::SHOW_TOC, new ShowContentsAction()); addAction(ActionCode::SHOW_BOOK_INFO_DIALOG, new ShowBookInfoAction()); addAction(ActionCode::SHOW_LIBRARY_OPTIONS_DIALOG, new ShowLibraryOptionsDialogAction()); addAction(ActionCode::SHOW_NETWORK_OPTIONS_DIALOG, new ShowNetworkOptionsDialogAction()); addAction(ActionCode::SHOW_SYSTEM_OPTIONS_DIALOG, new ShowSystemOptionsDialogAction()); addAction(ActionCode::SHOW_READING_OPTIONS_DIALOG, new ShowReadingOptionsDialogAction()); addAction(ActionCode::SHOW_LOOKANDFEEL_OPTIONS_DIALOG, new ShowLookAndFeelOptionsDialogAction()); addAction(ActionCode::ADD_BOOK, new AddBookAction(FBReader::BOOK_TEXT_MODE | FBReader::LIBRARY_MODE | FBReader::CONTENTS_MODE)); addAction(ActionCode::UNDO, new UndoAction(FBReader::BOOK_TEXT_MODE)); addAction(ActionCode::REDO, new RedoAction()); addAction(ActionCode::SEARCH, new SearchPatternAction()); addAction(ActionCode::FIND_NEXT, new FindNextAction()); addAction(ActionCode::FIND_PREVIOUS, new FindPreviousAction()); addAction(ActionCode::SCROLL_TO_HOME, new ScrollToHomeAction()); addAction(ActionCode::SCROLL_TO_START_OF_TEXT, new ScrollToStartOfTextAction()); addAction(ActionCode::SCROLL_TO_END_OF_TEXT, new ScrollToEndOfTextAction()); addAction(ActionCode::PAGE_SCROLL_FORWARD, new PageScrollingAction(true)); addAction(ActionCode::PAGE_SCROLL_BACKWARD, new PageScrollingAction(false)); addAction(ActionCode::LINE_SCROLL_FORWARD, new LineScrollingAction(true)); addAction(ActionCode::LINE_SCROLL_BACKWARD, new LineScrollingAction(false)); addAction(ActionCode::MOUSE_SCROLL_FORWARD, new MouseWheelScrollingAction(true)); addAction(ActionCode::MOUSE_SCROLL_BACKWARD, new MouseWheelScrollingAction(false)); addAction(ActionCode::TAP_SCROLL_FORWARD, new TapScrollingAction(true)); addAction(ActionCode::TAP_SCROLL_BACKWARD, new TapScrollingAction(false)); addAction(ActionCode::INCREASE_FONT, new ChangeFontSizeAction(2)); addAction(ActionCode::DECREASE_FONT, new ChangeFontSizeAction(-2)); addAction(ActionCode::ROTATE_SCREEN, new RotationAction()); addAction(ActionCode::TOGGLE_FULLSCREEN, new FBFullscreenAction()); addAction(ActionCode::FULLSCREEN_ON, new FBFullscreenAction()); addAction(ActionCode::CANCEL, new CancelAction()); addAction(ActionCode::SHOW_HIDE_POSITION_INDICATOR, new ToggleIndicatorAction()); addAction(ActionCode::QUIT, new QuitAction()); addAction(ActionCode::FORCE_QUIT, new ForceQuitAction()); addAction(ActionCode::OPEN_PREVIOUS_BOOK, new OpenPreviousBookAction()); addAction(ActionCode::SHOW_HELP, new ShowHelpAction()); addAction(ActionCode::GOTO_NEXT_TOC_SECTION, new GotoNextTOCSectionAction()); addAction(ActionCode::GOTO_PREVIOUS_TOC_SECTION, new GotoPreviousTOCSectionAction()); addAction(ActionCode::COPY_SELECTED_TEXT_TO_CLIPBOARD, new CopySelectedTextAction()); addAction(ActionCode::OPEN_SELECTED_TEXT_IN_DICTIONARY, new OpenSelectedTextInDictionaryAction()); addAction(ActionCode::CLEAR_SELECTION, new ClearSelectionAction()); addAction(ActionCode::GOTO_PAGE_NUMBER, new GotoPageNumberAction(std::string())); addAction(ActionCode::GOTO_PAGE_NUMBER_WITH_PARAMETER, new GotoPageNumberAction(PageIndexParameter)); shared_ptr booksOrderAction = new BooksOrderAction(); addAction(ActionCode::ORGANIZE_BOOKS_BY_AUTHOR, booksOrderAction); addAction(ActionCode::ORGANIZE_BOOKS_BY_TAG, booksOrderAction); addAction(ActionCode::FILTER_LIBRARY, new FilterLibraryAction()); registerPopupData(ActionCode::SHOW_OPTIONS_DIALOG, myPreferencesPopupData); myOpenFileHandler = new OpenFileHandler(); ZLCommunicationManager::Instance().registerHandler("openFile", myOpenFileHandler); ZLNetworkManager::Instance().setUserAgent(std::string("FBReader/") + VERSION); } FBReader::~FBReader() { ZLTextStyleCollection::deleteInstance(); PluginCollection::deleteInstance(); ZLTextHyphenator::deleteInstance(); } void FBReader::initWindow() { ZLApplication::initWindow(); trackStylus(true); MigrationRunnable migration; if (migration.shouldMigrate()) { ZLDialogManager::Instance().wait(ZLResourceKey("migrate"), migration); } if (!myBookAlreadyOpen) { shared_ptr book; if (!myBookToOpen.empty()) { createBook(ZLFile(myBookToOpen), book); } if (book.isNull()) { const BookList &books = Library::Instance().recentBooks(); if (!books.empty()) { book = books[0]; } } if (book.isNull()) { book = BooksDBUtil::getBook(helpFileName(ZLibrary::Language())); } if (book.isNull()) { book = BooksDBUtil::getBook(helpFileName("en")); } openBook(book); } refreshWindow(); ZLTimeManager::Instance().addTask(new TimeUpdater(), 1000); } void FBReader::refreshWindow() { ZLApplication::refreshWindow(); ((RecentBooksPopupData&)*myRecentBooksPopupData).updateId(); ((PreferencesPopupData&)*myPreferencesPopupData).updateId(); } bool FBReader::createBook(const ZLFile &bookFile, shared_ptr &book) { shared_ptr plugin = PluginCollection::Instance().plugin(bookFile, false); if (!plugin.isNull()) { std::string error = plugin->tryOpen(bookFile); if (!error.empty()) { ZLResourceKey boxKey("openBookErrorBox"); ZLDialogManager::Instance().errorBox( boxKey, ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), error) ); } else { book = BooksDBUtil::getBook(bookFile.path()); if (!book.isNull()) { BooksDB::Instance().insertIntoBookList(*book); } } return true; } if (!bookFile.isArchive()) { return false; } std::queue archiveNames; archiveNames.push(bookFile.path()); std::vector items; while (!archiveNames.empty()) { shared_ptr archiveDir = ZLFile(archiveNames.front()).directory(); archiveNames.pop(); if (archiveDir.isNull()) { continue; } archiveDir->collectFiles(items, true); for (std::vector::const_iterator it = items.begin(); it != items.end(); ++it) { const std::string itemName = archiveDir->itemPath(*it); ZLFile subFile(itemName); if (subFile.isArchive()) { archiveNames.push(itemName); } else if (createBook(subFile, book)) { return true; } } items.clear(); } return false; } class OpenBookRunnable : public ZLRunnable { public: OpenBookRunnable(shared_ptr book) : myBook(book) {} void run() { FBReader::Instance().openBookInternal(myBook); } private: shared_ptr myBook; }; void FBReader::openBook(shared_ptr book) { OpenBookRunnable runnable(book); ZLDialogManager::Instance().wait(ZLResourceKey("loadingBook"), runnable); if (!book.isNull()) { showBookTextView(); } resetWindowCaption(); } void FBReader::openBookInternal(shared_ptr book) { if (!book.isNull()) { BookTextView &bookTextView = (BookTextView&)*myBookTextView; ContentsView &contentsView = (ContentsView&)*myContentsView; FootnoteView &footnoteView = (FootnoteView&)*myFootnoteView; bookTextView.saveState(); bookTextView.setModel(0, 0); bookTextView.setContentsModel(0); contentsView.setModel(0); myModel.reset(); myModel = new BookModel(book); ZLTextHyphenator::Instance().load(book->language()); bookTextView.setModel(myModel->bookTextModel(), book); bookTextView.setCaption(book->title()); bookTextView.setContentsModel(myModel->contentsModel()); footnoteView.setModel(0); footnoteView.setCaption(book->title()); contentsView.setModel(myModel->contentsModel()); contentsView.setCaption(book->title()); Library::Instance().addBook(book); Library::Instance().addBookToRecentList(book); ((RecentBooksPopupData&)*myRecentBooksPopupData).updateId(); } } void FBReader::openLinkInBrowser(const std::string &url) const { if (url.empty()) { return; } shared_ptr collection = webBrowserCollection(); if (collection.isNull()) { return; } shared_ptr program = collection->currentProgram(); if (program.isNull()) { return; } std::string copy = url; NetworkLinkCollection::Instance().rewriteUrl(copy, true); ZLLogger::Instance().println("URL", copy); program->run("openLink", copy); } void FBReader::tryShowFootnoteView(const std::string &id, ZLHyperlinkType type) { switch (type) { case HYPERLINK_EXTERNAL: openLinkInBrowser(id); break; case HYPERLINK_INTERNAL: if (myMode == BOOK_TEXT_MODE && !myModel.isNull()) { BookModel::Label label = myModel->label(id); if (!label.Model.isNull()) { if (label.Model == myModel->bookTextModel()) { bookTextView().gotoParagraph(label.ParagraphNumber); } else { FootnoteView &view = ((FootnoteView&)*myFootnoteView); view.setModel(label.Model); setMode(FOOTNOTE_MODE); view.gotoParagraph(label.ParagraphNumber); } setHyperlinkCursor(false); refreshWindow(); } } break; case HYPERLINK_BOOK: // DownloadBookRunnable downloader(id); // downloader.executeWithUI(); // if (downloader.hasErrors()) { // downloader.showErrorMessage(); // } else { // shared_ptr book; // createBook(ZLFile(downloader.fileName()), book); // if (!book.isNull()) { // Library::Instance().addBook(book); // openBook(book); // refreshWindow(); // } // } break; } } FBReader::ViewMode FBReader::mode() const { return myMode; } bool FBReader::isViewFinal() const { return myMode == BOOK_TEXT_MODE; } void FBReader::showLibraryView() { if (ZLStringOption(ZLCategoryKey::LOOK_AND_FEEL, "ToggleButtonGroup", "booksOrder", "").value() == ActionCode::ORGANIZE_BOOKS_BY_TAG) { setView(myLibraryByTagView); } else { setView(myLibraryByAuthorView); } } void FBReader::setMode(ViewMode mode) { //TODO remove code for old network library view if (mode == myMode) { return; } if (mode != BOOK_TEXT_MODE) { myActionOnCancel = RETURN_TO_TEXT_MODE; } myPreviousMode = myMode; myMode = mode; switch (myMode) { case BOOK_TEXT_MODE: setHyperlinkCursor(false); ((ZLTextView&)*myBookTextView).forceScrollbarUpdate(); setView(myBookTextView); break; case CONTENTS_MODE: ((ContentsView&)*myContentsView).gotoReference(); setView(myContentsView); break; case FOOTNOTE_MODE: setView(myFootnoteView); break; case LIBRARY_MODE: { shared_ptr currentBook = myModel->book(); ((LibraryView&)*myLibraryByAuthorView).showBook(currentBook); ((LibraryView&)*myLibraryByTagView).showBook(currentBook); showLibraryView(); break; } case BOOKMARKS_MODE: break; case UNDEFINED_MODE: case ALL_MODES: break; } refreshWindow(); } BookTextView &FBReader::bookTextView() const { return (BookTextView&)*myBookTextView; } void FBReader::showBookTextView() { setMode(BOOK_TEXT_MODE); } void FBReader::restorePreviousMode() { setMode(myPreviousMode); myPreviousMode = BOOK_TEXT_MODE; } bool FBReader::closeView() { if (myMode == BOOK_TEXT_MODE) { quit(); return true; } else { restorePreviousMode(); return false; } } std::string FBReader::helpFileName(const std::string &language) const { return ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter + "help" + ZLibrary::FileNameDelimiter + "MiniHelp." + language + ".fb2"; } void FBReader::openFile(const ZLFile &file) { shared_ptr book; createBook(file, book); if (!book.isNull()) { openBook(book); refreshWindow(); } } bool FBReader::canDragFiles(const std::vector &filePaths) const { switch (myMode) { case BOOK_TEXT_MODE: case FOOTNOTE_MODE: case CONTENTS_MODE: case LIBRARY_MODE: return filePaths.size() > 0; default: return false; } } void FBReader::dragFiles(const std::vector &filePaths) { switch (myMode) { case BOOK_TEXT_MODE: case FOOTNOTE_MODE: case CONTENTS_MODE: if (filePaths.size() > 0) { openFile(ZLFile(filePaths[0])); } break; case LIBRARY_MODE: if (filePaths.size() > 0) { openFile(ZLFile(filePaths[0])); } break; default: break; } } void FBReader::clearTextCaches() { ((ZLTextView&)*myBookTextView).clearCaches(); ((ZLTextView&)*myFootnoteView).clearCaches(); ((ZLTextView&)*myContentsView).clearCaches(); } shared_ptr FBReader::keyBindings() { return UseSeparateBindingsOption.value() ? keyBindings(rotation()) : myBindings0; } shared_ptr FBReader::keyBindings(ZLView::Angle angle) { switch (angle) { case ZLView::DEGREES0: return myBindings0; case ZLView::DEGREES90: return myBindings90; case ZLView::DEGREES180: return myBindings180; case ZLView::DEGREES270: return myBindings270; } return 0; } shared_ptr FBReader::dictionaryCollection() const { return myProgramCollectionMap.collection("Dictionary"); } bool FBReader::isDictionarySupported() const { shared_ptr collection = dictionaryCollection(); return !collection.isNull() && !collection->currentProgram().isNull(); } void FBReader::openInDictionary(const std::string &word) { shared_ptr dictionary = dictionaryCollection()->currentProgram(); dictionary->run("present", ZLibrary::ApplicationName()); dictionary->run("showWord", word); } shared_ptr FBReader::webBrowserCollection() const { return myProgramCollectionMap.collection("Web Browser"); } shared_ptr FBReader::currentBook() const { return myModel->book(); } bool FBReader::showAuthDialog(const std::string &siteName, std::string &userName, std::string &password, const ZLResourceKey &errorKey) { std::string message = errorKey.Name.empty() ? std::string() : NetworkErrors::errorMessage(errorKey.Name); return AuthenticationDialog::run(siteName, userName, password, message); } void FBReader::saveUserName(const std::string &siteName, std::string &userName) { UserList userList(siteName); userList.saveUser(userName); } fbreader-0.99.4.orig/fbreader/src/bookmodel/0000755000706400070640000000000012056124565017236 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/bookmodel/BookModel.h0000644000706400070640000000517012056124565021265 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __BOOKMODEL_H__ #define __BOOKMODEL_H__ #include #include #include #include #include class ZLImage; class Book; class ContentsModel : public ZLTextTreeModel { public: ContentsModel(const std::string &language); void setReference(const ZLTextTreeParagraph *paragraph, int reference); int reference(const ZLTextTreeParagraph *paragraph) const; private: std::map myReferenceByParagraph; }; class BookModel : public ZLUserDataHolder { public: struct Label { Label(shared_ptr model, int paragraphNumber) : Model(model), ParagraphNumber(paragraphNumber) {} const shared_ptr Model; const int ParagraphNumber; }; public: class HyperlinkMatcher { public: virtual Label match(const std::map &lMap, const std::string &id) const = 0; }; public: BookModel(const shared_ptr book); ~BookModel(); void setHyperlinkMatcher(shared_ptr matcher); shared_ptr bookTextModel() const; shared_ptr contentsModel() const; const ZLImageMap &imageMap() const; Label label(const std::string &id) const; const shared_ptr book() const; private: const shared_ptr myBook; shared_ptr myBookTextModel; shared_ptr myContentsModel; ZLImageMap myImages; std::map > myFootnotes; std::map myInternalHyperlinks; shared_ptr myHyperlinkMatcher; friend class BookReader; }; inline shared_ptr BookModel::bookTextModel() const { return myBookTextModel; } inline shared_ptr BookModel::contentsModel() const { return myContentsModel; } inline const ZLImageMap &BookModel::imageMap() const { return myImages; } #endif /* __BOOKMODEL_H__ */ fbreader-0.99.4.orig/fbreader/src/bookmodel/BookReader.cpp0000644000706400070640000002102612056124565021760 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "BookReader.h" #include "BookModel.h" #include "../library/Book.h" BookReader::BookReader(BookModel &model) : myModel(model) { myCurrentTextModel = 0; myLastTOCParagraphIsEmpty = false; myContentsParagraphExists = false; myInsideTitle = false; mySectionContainsRegularContents = false; } BookReader::~BookReader() { } void BookReader::setMainTextModel() { myCurrentTextModel = myModel.myBookTextModel; } void BookReader::setFootnoteTextModel(const std::string &id) { std::map >::iterator it = myModel.myFootnotes.find(id); if (it != myModel.myFootnotes.end()) { myCurrentTextModel = (*it).second; } else { myCurrentTextModel = new ZLTextPlainModel(myModel.myBookTextModel->language(), 8192); myModel.myFootnotes.insert(std::make_pair(id, myCurrentTextModel)); } } bool BookReader::paragraphIsOpen() const { if (myCurrentTextModel.isNull()) { return false; } for (std::list >::const_iterator it = myModelsWithOpenParagraphs.begin(); it != myModelsWithOpenParagraphs.end(); ++it) { if (*it == myCurrentTextModel) { return true; } } return false; } void BookReader::unsetTextModel() { myCurrentTextModel.reset(); } void BookReader::pushKind(FBTextKind kind) { myKindStack.push_back(kind); } bool BookReader::popKind() { if (!myKindStack.empty()) { myKindStack.pop_back(); return true; } return false; } bool BookReader::isKindStackEmpty() const { return myKindStack.empty(); } void BookReader::beginParagraph(ZLTextParagraph::Kind kind) { endParagraph(); if (myCurrentTextModel != 0) { ((ZLTextPlainModel&)*myCurrentTextModel).createParagraph(kind); for (std::vector::const_iterator it = myKindStack.begin(); it != myKindStack.end(); ++it) { myCurrentTextModel->addControl(*it, true); } if (!myHyperlinkReference.empty()) { myCurrentTextModel->addHyperlinkControl(myHyperlinkKind, myHyperlinkType, myHyperlinkReference); } myModelsWithOpenParagraphs.push_back(myCurrentTextModel); } } void BookReader::endParagraph() { if (paragraphIsOpen()) { flushTextBufferToParagraph(); myModelsWithOpenParagraphs.remove(myCurrentTextModel); } } void BookReader::addControl(FBTextKind kind, bool start) { if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addControl(kind, start); } if (!start && !myHyperlinkReference.empty() && (kind == myHyperlinkKind)) { myHyperlinkReference.erase(); } } void BookReader::addStyleEntry(const ZLTextStyleEntry &entry) { if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addStyleEntry(entry); } } void BookReader::addStyleCloseEntry() { addControl(REGULAR, false); //used instead in XHTMLReader //TODO implement ZLTextModel::addStyleCloseEntry() // if (paragraphIsOpen()) { // flushTextBufferToParagraph(); // myCurrentTextModel->addStyleCloseEntry(); // } } void BookReader::addFixedHSpace(unsigned char length) { if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addFixedHSpace(length); } } void BookReader::addHyperlinkControl(FBTextKind kind, const std::string &label) { myHyperlinkKind = kind; std::string type; switch (myHyperlinkKind) { case INTERNAL_HYPERLINK: case FOOTNOTE: myHyperlinkType = HYPERLINK_INTERNAL; type = "internal"; break; case EXTERNAL_HYPERLINK: myHyperlinkType = HYPERLINK_EXTERNAL; type = "external"; break; case BOOK_HYPERLINK: myHyperlinkType = HYPERLINK_BOOK; type = "book"; break; default: myHyperlinkType = HYPERLINK_NONE; break; } ZLLogger::Instance().println( "hyperlink", " + control (" + type + "): " + label ); if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addHyperlinkControl(kind, myHyperlinkType, label); } myHyperlinkReference = label; } void BookReader::addHyperlinkLabel(const std::string &label) { if (!myCurrentTextModel.isNull()) { int paragraphNumber = myCurrentTextModel->paragraphsNumber(); if (paragraphIsOpen()) { --paragraphNumber; } addHyperlinkLabel(label, paragraphNumber); } } void BookReader::addHyperlinkLabel(const std::string &label, int paragraphNumber) { ZLLogger::Instance().println( "hyperlink", " + label: " + label ); myModel.myInternalHyperlinks.insert(std::make_pair( label, BookModel::Label(myCurrentTextModel, paragraphNumber) )); } void BookReader::addData(const std::string &data) { if (!data.empty() && paragraphIsOpen()) { if (!myInsideTitle) { mySectionContainsRegularContents = true; } myBuffer.push_back(data); } } void BookReader::addContentsData(const std::string &data) { if (!data.empty() && !myTOCStack.empty()) { myContentsBuffer.push_back(data); } } void BookReader::flushTextBufferToParagraph() { myCurrentTextModel->addText(myBuffer); myBuffer.clear(); } void BookReader::addImage(const std::string &id, shared_ptr image) { myModel.myImages[id] = image; } void BookReader::insertEndParagraph(ZLTextParagraph::Kind kind) { if ((myCurrentTextModel != 0) && mySectionContainsRegularContents) { std::size_t size = myCurrentTextModel->paragraphsNumber(); if ((size > 0) && (((*myCurrentTextModel)[(std::size_t)-1])->kind() != kind)) { ((ZLTextPlainModel&)*myCurrentTextModel).createParagraph(kind); mySectionContainsRegularContents = false; } } } void BookReader::insertEndOfSectionParagraph() { insertEndParagraph(ZLTextParagraph::END_OF_SECTION_PARAGRAPH); } void BookReader::insertEndOfTextParagraph() { insertEndParagraph(ZLTextParagraph::END_OF_TEXT_PARAGRAPH); } void BookReader::addImageReference(const std::string &id, short vOffset) { if (myCurrentTextModel != 0) { mySectionContainsRegularContents = true; if (paragraphIsOpen()) { flushTextBufferToParagraph(); myCurrentTextModel->addImage(id, myModel.imageMap(), vOffset); } else { beginParagraph(); myCurrentTextModel->addControl(IMAGE, true); myCurrentTextModel->addImage(id, myModel.imageMap(), vOffset); myCurrentTextModel->addControl(IMAGE, false); endParagraph(); } } } void BookReader::beginContentsParagraph(int referenceNumber) { if (myCurrentTextModel == myModel.myBookTextModel) { ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel; if (referenceNumber == -1) { referenceNumber = myCurrentTextModel->paragraphsNumber(); } ZLTextTreeParagraph *peek = myTOCStack.empty() ? 0 : myTOCStack.top(); if (!myContentsBuffer.empty()) { contentsModel.addText(myContentsBuffer); myContentsBuffer.clear(); myLastTOCParagraphIsEmpty = false; } if (myLastTOCParagraphIsEmpty) { contentsModel.addText("..."); } ZLTextTreeParagraph *para = contentsModel.createParagraph(peek); contentsModel.addControl(CONTENTS_TABLE_ENTRY, true); contentsModel.setReference(para, referenceNumber); myTOCStack.push(para); myLastTOCParagraphIsEmpty = true; myContentsParagraphExists = true; } } void BookReader::endContentsParagraph() { if (!myTOCStack.empty()) { ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel; if (!myContentsBuffer.empty()) { contentsModel.addText(myContentsBuffer); myContentsBuffer.clear(); myLastTOCParagraphIsEmpty = false; } if (myLastTOCParagraphIsEmpty) { contentsModel.addText("..."); myLastTOCParagraphIsEmpty = false; } myTOCStack.pop(); } myContentsParagraphExists = false; } void BookReader::setReference(std::size_t contentsParagraphNumber, int referenceNumber) { ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel; if (contentsParagraphNumber >= contentsModel.paragraphsNumber()) { return; } contentsModel.setReference((const ZLTextTreeParagraph*)contentsModel[contentsParagraphNumber], referenceNumber); } void BookReader::reset() { myKindStack.clear(); } fbreader-0.99.4.orig/fbreader/src/bookmodel/BookModel.cpp0000644000706400070640000000440112056124565021614 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include "BookModel.h" #include "BookReader.h" #include "../formats/FormatPlugin.h" #include "../library/Book.h" BookModel::BookModel(const shared_ptr book) : myBook(book) { myBookTextModel = new ZLTextPlainModel(book->language(), 102400); myContentsModel = new ContentsModel(book->language()); shared_ptr plugin = PluginCollection::Instance().plugin(book->file(), false); if (!plugin.isNull()) { plugin->readModel(*this); } } BookModel::~BookModel() { } void BookModel::setHyperlinkMatcher(shared_ptr matcher) { myHyperlinkMatcher = matcher; } BookModel::Label BookModel::label(const std::string &id) const { if (!myHyperlinkMatcher.isNull()) { return myHyperlinkMatcher->match(myInternalHyperlinks, id); } std::map::const_iterator it = myInternalHyperlinks.find(id); return (it != myInternalHyperlinks.end()) ? it->second : Label(0, -1); } ContentsModel::ContentsModel(const std::string &language) : ZLTextTreeModel(language) { } void ContentsModel::setReference(const ZLTextTreeParagraph *paragraph, int reference) { myReferenceByParagraph[paragraph] = reference; } int ContentsModel::reference(const ZLTextTreeParagraph *paragraph) const { std::map::const_iterator it = myReferenceByParagraph.find(paragraph); return (it != myReferenceByParagraph.end()) ? it->second : -1; } const shared_ptr BookModel::book() const { return myBook; } fbreader-0.99.4.orig/fbreader/src/bookmodel/BookReader.h0000644000706400070640000000635212056124565021432 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __BOOKREADER_H__ #define __BOOKREADER_H__ #include #include #include #include #include #include "FBHyperlinkType.h" #include "FBTextKind.h" class BookModel; class ZLTextModel; class ZLInputStream; class ZLTextStyleEntry; class BookReader { public: BookReader(BookModel &model); virtual ~BookReader(); void setMainTextModel(); void setFootnoteTextModel(const std::string &id); void unsetTextModel(); void insertEndOfSectionParagraph(); void insertEndOfTextParagraph(); void pushKind(FBTextKind kind); bool popKind(); bool isKindStackEmpty() const; void beginParagraph(ZLTextParagraph::Kind kind = ZLTextParagraph::TEXT_PARAGRAPH); void endParagraph(); bool paragraphIsOpen() const; void addControl(FBTextKind kind, bool start); void addStyleEntry(const ZLTextStyleEntry &entry); void addStyleCloseEntry(); //TODO reimplement void addHyperlinkControl(FBTextKind kind, const std::string &label); void addHyperlinkLabel(const std::string &label); void addHyperlinkLabel(const std::string &label, int paragraphNumber); void addFixedHSpace(unsigned char length); void addImageReference(const std::string &id, short vOffset = 0); void addImage(const std::string &id, shared_ptr image); void beginContentsParagraph(int referenceNumber = -1); void endContentsParagraph(); bool contentsParagraphIsOpen() const; void setReference(std::size_t contentsParagraphNumber, int referenceNumber); void addData(const std::string &data); void addContentsData(const std::string &data); void enterTitle() { myInsideTitle = true; } void exitTitle() { myInsideTitle = false; } const BookModel &model() const { return myModel; } void reset(); private: void insertEndParagraph(ZLTextParagraph::Kind kind); void flushTextBufferToParagraph(); private: BookModel &myModel; shared_ptr myCurrentTextModel; std::list > myModelsWithOpenParagraphs; std::vector myKindStack; bool myContentsParagraphExists; std::stack myTOCStack; bool myLastTOCParagraphIsEmpty; bool mySectionContainsRegularContents; bool myInsideTitle; std::vector myBuffer; std::vector myContentsBuffer; std::string myHyperlinkReference; FBHyperlinkType myHyperlinkType; FBTextKind myHyperlinkKind; }; inline bool BookReader::contentsParagraphIsOpen() const { return myContentsParagraphExists; } #endif /* __BOOKREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/bookmodel/FBTextKind.h0000644000706400070640000000326412056124565021356 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBTEXTKIND_H__ #define __FBTEXTKIND_H__ enum FBTextKind { // please, don't change these numbers // add new text kinds at end of this enumeration // // all the values MUST be in the range 0..127 REGULAR = 0, TITLE = 1, SECTION_TITLE = 2, POEM_TITLE = 3, SUBTITLE = 4, ANNOTATION = 5, EPIGRAPH = 6, STANZA = 7, VERSE = 8, PREFORMATTED = 9, IMAGE = 10, END_OF_SECTION = 11, CITE = 12, AUTHOR = 13, DATEKIND = 14, INTERNAL_HYPERLINK = 15, FOOTNOTE = 16, EMPHASIS = 17, STRONG = 18, SUB = 19, SUP = 20, CODE = 21, STRIKETHROUGH = 22, CONTENTS_TABLE_ENTRY = 23, //LIBRARY_AUTHOR_ENTRY = 24, //LIBRARY_BOOK_ENTRY = 25, LIBRARY_ENTRY = 25, //RECENT_BOOK_LIST = 26, ITALIC = 27, BOLD = 28, DEFINITION = 29, DEFINITION_DESCRIPTION = 30, H1 = 31, H2 = 32, H3 = 33, H4 = 34, H5 = 35, H6 = 36, EXTERNAL_HYPERLINK = 37, BOOK_HYPERLINK = 38, }; #endif /* __FBTEXTKIND_H__ */ fbreader-0.99.4.orig/fbreader/src/bookmodel/FBHyperlinkType.h0000644000706400070640000000176712056124565022441 0ustar bagebage/* * Copyright (C) 2011-2012 Geometer Plus * * 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. */ #ifndef __FBHYPERLINKTYPE_H__ #define __FBHYPERLINKTYPE_H__ enum FBHyperlinkType { HYPERLINK_NONE = 0, HYPERLINK_INTERNAL = 1, HYPERLINK_EXTERNAL = 2, HYPERLINK_BOOK = 3, }; #endif /* __FBHYPERLINKTYPE_H__ */ fbreader-0.99.4.orig/fbreader/src/tree/0000755000706400070640000000000012056124565016222 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/tree/FBTree.h0000644000706400070640000000326212056124565017505 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __FBTREE_H__ #define __FBTREE_H__ #include class FBTree : public ZLTreeTitledNode { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; private: class ExpandTreeAction; public: static shared_ptr defaultCoverImage(const std::string &id); //static std::string defaultImageUrl(const std::string &id); public: //TODO make protected void expand(); private: static std::map > ourDefaultCovers; static std::map ourDefaultUrls; public: FBTree(ZLTreeNode *parent, std::size_t position = (std::size_t)-1); // shared_ptr coverImage() const; std::string subtitle() const; protected: void registerExpandTreeAction(); private: // mutable bool myCoverImageIsStored; // mutable shared_ptr myStoredCoverImage; }; #endif /* __FBTREE_H__ */ fbreader-0.99.4.orig/fbreader/src/tree/FBTree.cpp0000644000706400070640000000740012056124565020036 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include "FBTree.h" const ZLTypeId FBTree::TYPE_ID(ZLTreeTitledNode::TYPE_ID); const ZLTypeId &FBTree::typeId() const { return TYPE_ID; } std::map > FBTree::ourDefaultCovers; std::map FBTree::ourDefaultUrls; // is there already any implementation of this stuff anywhere? //TODO move it to some Utils class static char hex_helper(int c) { static char tmp[] = "0123456789ABCDEF"; return tmp[c]; } static std::string percent_encoding(const std::string &str) { std::string result; for (std::size_t i = 0; i < str.size(); ++i) { const char c = str[i]; if (str[i] == '\\' || str[i] == '/') { result += '/'; } else if (std::isalpha(c) || std::isdigit(c) || c == '.' || c == '-' || c == '_' || c == '~') { result += str[i]; } else { result += "%"; result += hex_helper((c & 0xf0) >> 4); result += hex_helper(c & 0x0f); } } return result; } //TODO maybe use just one expand action? class FBTree::ExpandTreeAction : public ZLTreeAction { public: ExpandTreeAction(FBTree &node); void run(); ZLResourceKey key() const; private: FBTree &myNode; }; FBTree::ExpandTreeAction::ExpandTreeAction(FBTree &node) : myNode(node) { } void FBTree::ExpandTreeAction::run() { myNode.expand(); } ZLResourceKey FBTree::ExpandTreeAction::key() const { return ZLResourceKey("expandTree"); } shared_ptr FBTree::defaultCoverImage(const std::string &id) { shared_ptr cover = ourDefaultCovers[id]; if (cover.isNull()) { cover = new ZLFileImage( ZLFile(ZLibrary::ApplicationImageDirectory() + ZLibrary::FileNameDelimiter + id), 0 ); ourDefaultCovers[id] = cover; } return cover; } //std::string FBTree::defaultImageUrl(const std::string &id) { // std::string &url = ourDefaultUrls[id]; // if (url.empty()) { // url = ZLibrary::ApplicationImageDirectory(); // url += "/"; // url += id; // url = LOCALFILE_SCHEME + SCHEME_POSTFIX + percent_encoding(url); // } // return url; //} void FBTree::expand() { if (ZLTreeListener *handler = listener()) { handler->onExpandRequest(this); } } FBTree::FBTree(ZLTreeNode *parent, std::size_t position) : ZLTreeTitledNode(parent, position)/*, myCoverImageIsStored(false)*/ { } std::string FBTree::subtitle() const { std::string result; int count = 0; const ZLTreeNode::List &subNodes = children(); ZLTreeNode::List::const_iterator it = subNodes.begin(); for (; it != subNodes.end() && count < 3; ++it, ++count) { if (count > 0) { result += ", "; } result += ((const FBTree*)*it)->title(); } if (it != subNodes.end()) { result += ", ..."; } return result; } void FBTree::registerExpandTreeAction() { registerAction(new ExpandTreeAction(*this)); } //shared_ptr FBTree::coverImage() const { // if (!myCoverImageIsStored) { // myCoverImageIsStored = true; // myStoredCoverImage = image(); // } // return myStoredCoverImage; //} fbreader-0.99.4.orig/fbreader/src/formats/0000755000706400070640000000000012056124565016736 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/formats/pdf/0000755000706400070640000000000012056124565017507 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfBookReader.cpp0000644000706400070640000001671612056124565022675 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include "PdfBookReader.h" #include "PdfObject.h" #include "../../bookmodel/BookModel.h" static void readLine(ZLInputStream &stream, std::string &buffer) { buffer.clear(); char ch; while (1) { if (stream.read(&ch, 1) != 1) { return; } if ((ch == 10) || (ch == 13)) { if (!buffer.empty()) { return; } } else { buffer += ch; } } } PdfBookReader::PdfBookReader(BookModel &model) : myModelReader(model) { } PdfBookReader::~PdfBookReader() { } shared_ptr PdfBookReader::readObjectFromLocation(ZLInputStream &stream, const std::pair &address) { std::map,int>::const_iterator jt = myObjectLocationMap.find(address); if (jt == myObjectLocationMap.end()) { return 0; } stream.seek(jt->second, true); char ch = 0; PdfObject::readToken(stream, myBuffer, ch); if (address.first != atoi(myBuffer.c_str())) { return 0; } PdfObject::readToken(stream, myBuffer, ch); if (address.second != atoi(myBuffer.c_str())) { return 0; } PdfObject::readToken(stream, myBuffer, ch); if (myBuffer != "obj") { return 0; } return PdfObject::readObject(stream, ch); } shared_ptr PdfBookReader::resolveReference(shared_ptr ref, ZLInputStream &stream) { if (ref.isNull() || (ref->type() != PdfObject::REFERENCE)) { return ref; } const PdfObjectReference &reference = (const PdfObjectReference&)*ref; const std::pair address(reference.number(), reference.generation()); std::map,shared_ptr >::const_iterator it = myObjectMap.find(address); if (it != myObjectMap.end()) { return it->second; } std::map,int>::const_iterator jt = myObjectLocationMap.find(address); shared_ptr object = readObjectFromLocation(stream, address); myObjectMap.insert(std::make_pair(address, object)); return object; } static void stripBuffer(std::string &buffer) { int index = buffer.find('%'); if (index >= 0) { buffer.erase(index); } ZLStringUtil::stripWhiteSpaces(buffer); } bool PdfBookReader::readReferenceTable(ZLInputStream &stream, int xrefOffset) { while (true) { stream.seek(xrefOffset, true); readLine(stream, myBuffer); stripBuffer(myBuffer); if (myBuffer != "xref") { return false; } while (true) { readLine(stream, myBuffer); stripBuffer(myBuffer); if (myBuffer == "trailer") { break; } const int index = myBuffer.find(' '); const int start = atoi(myBuffer.c_str()); const int len = atoi(myBuffer.c_str() + index + 1); for (int i = 0; i < len; ++i) { readLine(stream, myBuffer); stripBuffer(myBuffer); if (myBuffer.length() != 18) { return false; } const int objectOffset = atoi(myBuffer.c_str()); const int objectGeneration = atoi(myBuffer.c_str() + 11); const bool objectInUse = myBuffer[17] == 'n'; if (objectInUse) { myObjectLocationMap[std::make_pair(start + i, objectGeneration)] = objectOffset; } } } char ch = 0; shared_ptr trailer = PdfObject::readObject(stream, ch); if (trailer.isNull() || (trailer->type() != PdfObject::DICTIONARY)) { return false; } if (myTrailer.isNull()) { myTrailer = trailer; } PdfDictionaryObject &trailerDictionary = (PdfDictionaryObject&)*trailer; shared_ptr previous = trailerDictionary["Prev"]; if (previous.isNull()) { return true; } if (previous->type() != PdfObject::INTEGER_NUMBER) { return false; } xrefOffset = ((PdfIntegerObject&)*previous).value(); } } bool PdfBookReader::readBook(shared_ptr stream) { if (stream.isNull() || !stream->open()) { return false; } readLine(*stream, myBuffer); if (!ZLStringUtil::stringStartsWith(myBuffer, "%PDF-")) { return false; } std::string version = myBuffer.substr(5); std::cerr << "version = " << version << "\n"; std::size_t eofOffset = stream->sizeOfOpened(); if (eofOffset < 100) { return false; } stream->seek(eofOffset - 100, true); bool readXrefOffset = false; std::size_t xrefOffset = (std::size_t)-1; while (true) { readLine(*stream, myBuffer); if (myBuffer.empty()) { break; } stripBuffer(myBuffer); if (readXrefOffset) { if (!myBuffer.empty()) { xrefOffset = atoi(myBuffer.c_str()); break; } } else if (myBuffer == "startxref") { readXrefOffset = true; } } if (!readReferenceTable(*stream, xrefOffset)) { return false; } PdfDictionaryObject &trailerDictionary = (PdfDictionaryObject&)*myTrailer; shared_ptr root = resolveReference(trailerDictionary["Root"], *stream); if (root.isNull() || (root->type() != PdfObject::DICTIONARY)) { return false; } PdfDictionaryObject &rootDictionary = (PdfDictionaryObject&)*root; if (rootDictionary["Type"] != PdfNameObject::nameObject("Catalog")) { return false; } shared_ptr pageRootNode = resolveReference(rootDictionary["Pages"], *stream); if (pageRootNode.isNull() || (pageRootNode->type() != PdfObject::DICTIONARY)) { return false; } PdfDictionaryObject &pageRootNodeDictionary = (PdfDictionaryObject&)*pageRootNode; if (pageRootNodeDictionary["Type"] != PdfNameObject::nameObject("Pages")) { return false; } /* shared_ptr count = pageRootNodeDictionary["Count"]; if (!count.isNull() && (count->type() == PdfObject::INTEGER_NUMBER)) { std::cerr << "count = " << ((PdfIntegerObject&)*count).value() << "\n"; } */ shared_ptr pages = pageRootNodeDictionary["Kids"]; if (pages.isNull() || (pages->type() != PdfObject::ARRAY)) { return false; } const PdfArrayObject& pagesArray = (const PdfArrayObject&)*pages; const std::size_t pageNumber = pagesArray.size(); for (std::size_t i = 0; i < pageNumber; ++i) { processPage(pagesArray[i], *stream); } return true; } void PdfBookReader::processContents(shared_ptr contentsObject, ZLInputStream &stream) { contentsObject = resolveReference(contentsObject, stream); } void PdfBookReader::processPage(shared_ptr pageObject, ZLInputStream &stream) { pageObject = resolveReference(pageObject, stream); if (pageObject.isNull() || pageObject->type() != PdfObject::DICTIONARY) { return; } const PdfDictionaryObject &pageDictionary = (const PdfDictionaryObject&)*pageObject; shared_ptr contents = pageDictionary["Contents"]; if (contents.isNull()) { return; } switch (contents->type()) { default: break; case PdfObject::REFERENCE: processContents(contents, stream); break; case PdfObject::ARRAY: { const PdfArrayObject &array = (const PdfArrayObject&)*contents; const std::size_t len = array.size(); for (std::size_t i = 0; i < len; ++i) { processContents(array[i], stream); } break; } } } fbreader-0.99.4.orig/fbreader/src/formats/pdf/StringStream.cpp0000644000706400070640000000303412056124565022635 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #include #include "StringStream.h" StringStream::StringStream(const std::string &data) : myData(data), myOffset(0) { } bool StringStream::open() { myOffset = 0; return true; } std::size_t StringStream::read(char *buffer, std::size_t maxSize) { std::size_t size = std::min(maxSize, myData.length() - myOffset); memcpy(buffer, myData.data() + myOffset, size); myOffset += size; return size; } void StringStream::close() { } void StringStream::seek(int offset, bool absoluteOffset) { if (!absoluteOffset) { offset += myOffset; } myOffset = std::min((std::size_t)std::max(0, offset), myData.length()); } std::size_t StringStream::offset() const { return myOffset; } std::size_t StringStream::sizeOfOpened() { return myData.length(); } fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfDescriptionReader.cpp0000644000706400070640000000200612056124565024251 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "PdfDescriptionReader.h" PdfDescriptionReader::PdfDescriptionReader(Book &book) : myBook(book) { } bool PdfDescriptionReader::readMetaInfo(shared_ptr stream) { return true; } fbreader-0.99.4.orig/fbreader/src/formats/pdf/StringStream.h0000644000706400070640000000236512056124565022310 0ustar bagebage/* * Copyright (C) 2008-2012 Geometer Plus * * 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. */ #ifndef __STRINGSTREAM_H__ #define __STRINGSTREAM_H__ #include class StringStream : public ZLInputStream { public: StringStream(const std::string &data); public: bool open(); std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); std::size_t offset() const; std::size_t sizeOfOpened(); private: const std::string &myData; std::size_t myOffset; }; #endif /* __STRINGSTREAM_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfPlugin.cpp0000644000706400070640000000256512056124565022113 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include "PdfPlugin.h" #include "PdfDescriptionReader.h" #include "PdfBookReader.h" #include "../../library/Book.h" bool PdfPlugin::acceptsFile(const ZLFile &file) const { return file.extension() == "pdf"; } bool PdfPlugin::readMetaInfo(Book &book) const { return PdfDescriptionReader(book).readMetaInfo(ZLFile(path).inputStream()); } bool PdfPlugin::readLanguageAndEncoding(Book &book) const { return true; } bool PdfPlugin::readModel(BookModel &model) const { return PdfBookReader(model).readBook(ZLFile(book.fileName()).inputStream()); } fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfObject.cpp0000644000706400070640000002623112056124565022057 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "PdfObject.h" PdfObject::~PdfObject() { } shared_ptr PdfIntegerObject::integerObject(int value) { if ((value < 0) || (value >= 256)) { return new PdfIntegerObject(value); } else { static shared_ptr* table = new shared_ptr[256]; if (table[value].isNull()) { table[value] = new PdfIntegerObject(value); } return table[value]; } } PdfIntegerObject::PdfIntegerObject(int value) : myValue(value) { std::cerr << "PdfIntegerObject " << value << "\n"; } int PdfIntegerObject::value() const { return myValue; } PdfObject::Type PdfIntegerObject::type() const { return INTEGER_NUMBER; } shared_ptr PdfBooleanObject::TRUE() { static shared_ptr value = new PdfBooleanObject(true); return value; } shared_ptr PdfBooleanObject::FALSE() { static shared_ptr value = new PdfBooleanObject(false); return value; } PdfBooleanObject::PdfBooleanObject(bool value) : myValue(value) { std::cerr << "PdfBooleanObject " << value << "\n"; } bool PdfBooleanObject::value() const { return myValue; } PdfObject::Type PdfBooleanObject::type() const { return BOOLEAN; } PdfStringObject::PdfStringObject(const std::string &value) : myValue(value) { std::cerr << "PdfStringObject " << value << "\n"; } PdfObject::Type PdfStringObject::type() const { return STRING; } std::map > PdfNameObject::ourObjectMap; shared_ptr PdfNameObject::nameObject(const std::string &id) { // TODO: process escaped characters std::map >::const_iterator it = ourObjectMap.find(id); if (it != ourObjectMap.end()) { return it->second; } std::cerr << "PdfNameObject " << id << "\n"; shared_ptr object = new PdfNameObject(); ourObjectMap.insert(std::make_pair(id, object)); return object; } PdfNameObject::PdfNameObject() { } PdfObject::Type PdfNameObject::type() const { return NAME; } PdfDictionaryObject::PdfDictionaryObject() { } void PdfDictionaryObject::setObject(shared_ptr id, shared_ptr object) { myMap[id] = object; } shared_ptr PdfDictionaryObject::operator[](shared_ptr id) const { std::map,shared_ptr >::const_iterator it = myMap.find(id); return (it != myMap.end()) ? it->second : 0; } shared_ptr PdfDictionaryObject::operator[](const std::string &id) const { return operator[](PdfNameObject::nameObject(id)); } PdfObject::Type PdfDictionaryObject::type() const { return DICTIONARY; } PdfArrayObject::PdfArrayObject() { } void PdfArrayObject::addObject(shared_ptr object) { myVector.push_back(object); } shared_ptr PdfArrayObject::popLast() { if (!myVector.empty()) { shared_ptr last = myVector.back(); myVector.pop_back(); return last; } return 0; } int PdfArrayObject::size() const { return myVector.size(); } shared_ptr PdfArrayObject::operator[](int index) const { return myVector[index]; } PdfObject::Type PdfArrayObject::type() const { return ARRAY; } PdfObjectReference::PdfObjectReference(int number, int generation) : myNumber(number), myGeneration(generation) { } int PdfObjectReference::number() const { return myNumber; } int PdfObjectReference::generation() const { return myGeneration; } PdfObject::Type PdfObjectReference::type() const { return REFERENCE; } PdfStreamObject::PdfStreamObject(const PdfDictionaryObject &dictionary, ZLInputStream &dataStream) { char ch; skipWhiteSpaces(dataStream, ch); shared_ptr length = dictionary["Length"]; if (!length.isNull() && (length->type() == INTEGER_NUMBER)) { int value = ((PdfIntegerObject&)*length).value(); if (value > 0) { shared_ptr filter = dictionary["Filter"]; if (filter == PdfNameObject::nameObject("FlateDecode")) { dataStream.seek(1, false); ZLZDecompressor decompressor(value - 2); char buffer[2048]; while (true) { std::size_t size = decompressor.decompress(dataStream, buffer, 2048); if (size == 0) { break; } myData.append(buffer, size); } std::cerr << myData << "\n"; } else { myData.append(value, '\0'); myData[0] = ch; dataStream.read((char*)myData.data() + 1, value - 1); } } } /* shared_ptr filter = dictionary["Filter"]; if (!filter.isNull()) { switch (filter->type()) { default: break; case NAME: myFilters.push_back( (filter == PdfNameObject::nameObject("FlateDecode")) ? FLATE : UNKNOWN ); break; case ARRAY: { // TODO: process filters array } } } */ } PdfObject::Type PdfStreamObject::type() const { return STREAM; } enum PdfCharacterType { PDF_CHAR_REGULAR, PDF_CHAR_WHITESPACE, PDF_CHAR_DELIMITER }; static PdfCharacterType *PdfCharacterTypeTable = 0; void PdfObject::skipWhiteSpaces(ZLInputStream &stream, char &ch) { if (PdfCharacterTypeTable == 0) { PdfCharacterTypeTable = new PdfCharacterType[256]; for (int i = 0; i < 256; ++i) { PdfCharacterTypeTable[i] = PDF_CHAR_REGULAR; } PdfCharacterTypeTable[0] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable[9] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable[10] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable[12] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable[13] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable[32] = PDF_CHAR_WHITESPACE; PdfCharacterTypeTable['('] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable[')'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['<'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['>'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['['] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable[']'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['{'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['}'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['/'] = PDF_CHAR_DELIMITER; PdfCharacterTypeTable['%'] = PDF_CHAR_DELIMITER; } while ((PdfCharacterTypeTable[(unsigned char)ch] == PDF_CHAR_WHITESPACE) && (stream.read(&ch, 1) == 1)) { } } void PdfObject::readToken(ZLInputStream &stream, std::string &buffer, char &ch) { buffer.clear(); skipWhiteSpaces(stream, ch); while (PdfCharacterTypeTable[(unsigned char)ch] == PDF_CHAR_REGULAR) { buffer += ch; if (stream.read(&ch, 1) != 1) { break; } } } shared_ptr PdfObject::readObject(ZLInputStream &stream, char &ch) { skipWhiteSpaces(stream, ch); PdfObject::Type type = PdfObject::NIL; bool hexString = false; switch (ch) { case '(': hexString = false; type = PdfObject::STRING; break; case '<': stream.read(&ch, 1); hexString = true; type = (ch == '<') ? PdfObject::DICTIONARY : PdfObject::STRING; break; case '>': // end of dictionary stream.read(&ch, 1); if (ch == '>') { stream.read(&ch, 1); } return 0; case '/': type = PdfObject::NAME; break; case '[': type = PdfObject::ARRAY; break; case ']': // end of array stream.read(&ch, 1); return 0; case '+': case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': type = PdfObject::INTEGER_NUMBER; break; case 't': case 'f': type = PdfObject::BOOLEAN; break; } switch (type) { case PdfObject::DICTIONARY: { ch = 0; shared_ptr name; shared_ptr value; shared_ptr next; PdfDictionaryObject *dictionary = new PdfDictionaryObject(); while (true) { next = readObject(stream, ch); if (next.isNull()) { break; } PdfObject::Type oType = next->type(); if (oType == PdfObject::NAME) { name = next; value = readObject(stream, ch); if (value.isNull()) { break; } dictionary->setObject(name, value); } else if (oType == PdfObject::INTEGER_NUMBER) { if (value.isNull() || (value->type() != PdfObject::INTEGER_NUMBER)) { break; } skipWhiteSpaces(stream, ch); if (ch != 'R') { break; } const int number = ((PdfIntegerObject&)*value).value(); const int generation = ((PdfIntegerObject&)*next).value(); dictionary->setObject(name, new PdfObjectReference(number, generation)); value = 0; ch = 0; } else { break; } } std::string token; readToken(stream, token, ch); if (token == "stream") { shared_ptr d = dictionary; return new PdfStreamObject(*dictionary, stream); } else { return dictionary; } } case PdfObject::NAME: { std::string name; stream.read(&ch, 1); readToken(stream, name, ch); return PdfNameObject::nameObject(name); } case PdfObject::BOOLEAN: { std::string name; readToken(stream, name, ch); return (name == "true") ? PdfBooleanObject::TRUE() : PdfBooleanObject::FALSE(); } case PdfObject::INTEGER_NUMBER: { std::string str; if ((ch == '+') || (ch == '-')) { str += ch; stream.read(&ch, 1); } while ((ch >= '0') && (ch <= '9')) { str += ch; stream.read(&ch, 1); } return PdfIntegerObject::integerObject(atoi(str.c_str())); } case PdfObject::STRING: { std::string value; if (hexString) { char num[3]; num[2] = '\0'; while (ch != '>') { num[0] = ch; stream.read(num + 1, 1); value += (char)strtol(num, 0, 16); stream.read(&ch, 1); } ch = 0; } else { // TODO: implement } return new PdfStringObject(value); } case PdfObject::ARRAY: { PdfArrayObject *array = new PdfArrayObject(); ch = 0; while (true) { skipWhiteSpaces(stream, ch); if (ch == 'R') { const int size = array->size(); if ((size >= 2) && ((*array)[size - 1]->type() == PdfObject::INTEGER_NUMBER) && ((*array)[size - 2]->type() == PdfObject::INTEGER_NUMBER)) { const int generation = ((PdfIntegerObject&)*array->popLast()).value(); const int number = ((PdfIntegerObject&)*array->popLast()).value(); array->addObject(new PdfObjectReference(number, generation)); ch = 0; } } shared_ptr object = readObject(stream, ch); if (object.isNull()) { break; } array->addObject(object); } std::cerr << "PdfArrayObject " << array->size() << "\n"; return array; } default: break; } std::string buffer; stream.read(&ch, 1); while (PdfCharacterTypeTable[(unsigned char)ch] == PDF_CHAR_REGULAR) { buffer += ch; stream.read(&ch, 1); } std::cerr << "buffer = " << buffer << "\n"; return 0; } fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfPlugin.h0000644000706400070640000000246012056124565021552 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __PdfPLUGIN_H__ #define __PdfPLUGIN_H__ #include "../FormatPlugin.h" class PdfPlugin : public FormatPlugin { public: PdfPlugin(); ~PdfPlugin(); bool providesMetaInfo() const; bool acceptsFile(const ZLFile &file) const; bool readMetaInfo(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; }; inline PdfPlugin::PdfPlugin() {} inline PdfPlugin::~PdfPlugin() {} inline bool PdfPlugin::providesMetaInfo() const { return true; } #endif /* __PdfPLUGIN_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfObject.h0000644000706400070640000000757612056124565021537 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __PDFOBJECT_H__ #define __PDFOBJECT_H__ #include #include #include #include class ZLInputStream; class PdfObject { public: static shared_ptr readObject(ZLInputStream &stream, char &ch); static void readToken(ZLInputStream &stream, std::string &buffer, char &ch); protected: static void skipWhiteSpaces(ZLInputStream &stream, char &ch); public: enum Type { BOOLEAN, INTEGER_NUMBER, REAL_NUMBER, STRING, NAME, ARRAY, DICTIONARY, STREAM, NIL, REFERENCE }; virtual ~PdfObject(); virtual Type type() const = 0; }; class PdfBooleanObject : public PdfObject { public: static shared_ptr TRUE(); static shared_ptr FALSE(); private: PdfBooleanObject(bool value); public: bool value() const; private: Type type() const; private: const bool myValue; }; class PdfIntegerObject : public PdfObject { public: static shared_ptr integerObject(int value); private: PdfIntegerObject(int value); public: int value() const; private: Type type() const; private: const int myValue; }; class PdfStringObject : public PdfObject { private: PdfStringObject(const std::string &value); private: Type type() const; private: std::string myValue; friend shared_ptr PdfObject::readObject(ZLInputStream &stream, char &ch); }; class PdfNameObject : public PdfObject { public: static shared_ptr nameObject(const std::string &id); private: static std::map > ourObjectMap; private: PdfNameObject(); private: Type type() const; }; class PdfDictionaryObject : public PdfObject { private: PdfDictionaryObject(); void setObject(shared_ptr id, shared_ptr object); public: shared_ptr operator [] (shared_ptr id) const; shared_ptr operator [] (const std::string &id) const; private: Type type() const; private: std::map,shared_ptr > myMap; friend shared_ptr PdfObject::readObject(ZLInputStream &stream, char &ch); }; class PdfStreamObject : public PdfObject { private: PdfStreamObject(const PdfDictionaryObject &dictionary, ZLInputStream &dataStream); private: Type type() const; private: std::string myData; /* enum EncodingType { UNKNOWN, FLATE, }; std::vector myFilters; */ friend shared_ptr PdfObject::readObject(ZLInputStream &stream, char &ch); }; class PdfArrayObject : public PdfObject { private: PdfArrayObject(); void addObject(shared_ptr object); shared_ptr popLast(); public: int size() const; shared_ptr operator [] (int index) const; private: Type type() const; private: std::vector > myVector; friend shared_ptr PdfObject::readObject(ZLInputStream &stream, char &ch); }; class PdfObjectReference : public PdfObject { public: PdfObjectReference(int number, int generation); int number() const; int generation() const; private: Type type() const; private: const int myNumber; const int myGeneration; }; #endif /* __PDFOBJECT_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfDescriptionReader.h0000644000706400070640000000223612056124565023723 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __PDFDESCRIPTIONREADER_H__ #define __PDFDESCRIPTIONREADER_H__ #include class Book; class PdfDescriptionReader { public: PdfDescriptionReader(Book &book); ~PdfDescriptionReader(); bool readMetaInfo(shared_ptr stream); private: Book &myBook; }; inline PdfDescriptionReader::~PdfDescriptionReader() {} #endif /* __PDFDESCRIPTIONREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/pdf/PdfBookReader.h0000644000706400070640000000336112056124565022332 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __PdfBOOKREADER_H__ #define __PdfBOOKREADER_H__ #include #include "../../bookmodel/BookReader.h" class PdfObject; class PdfObjectReference; class PdfBookReader { public: PdfBookReader(BookModel &model); ~PdfBookReader(); bool readBook(shared_ptr stream); private: bool readReferenceTable(ZLInputStream &stream, int offset); shared_ptr resolveReference(shared_ptr reference, ZLInputStream &stream); shared_ptr readObjectFromLocation(ZLInputStream &stream, const std::pair &address); void processPage(shared_ptr pageObject, ZLInputStream &stream); void processContents(shared_ptr contentsObject, ZLInputStream &stream); private: BookReader myModelReader; std::string myBuffer; std::map,int> myObjectLocationMap; std::map,shared_ptr > myObjectMap; shared_ptr myTrailer; }; #endif /* __PdfBOOKREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/doc/0000755000706400070640000000000012056124565017503 5ustar bagebagefbreader-0.99.4.orig/fbreader/src/formats/doc/DocBookReader.cpp0000644000706400070640000002644612056124565022666 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include #include #include "DocBookReader.h" #include "../../bookmodel/BookModel.h" #include "../../library/Book.h" #include "OleStorage.h" #include "OleMainStream.h" DocBookReader::DocBookReader(BookModel &model, const std::string &encoding) : myModelReader(model), myPictureCounter(0), myEncoding(encoding) { myReadState = READ_TEXT; } bool DocBookReader::readBook() { const ZLFile &file = myModelReader.model().book()->file(); shared_ptr stream = file.inputStream(); if (stream.isNull() || !stream->open()) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); myModelReader.beginParagraph(); if (!readDocument(stream, true)) { return false; } myModelReader.insertEndOfTextParagraph(); return true; } void DocBookReader::handleChar(ZLUnicodeUtil::Ucs2Char ucs2char) { if (myReadState == READ_FIELD && myReadFieldState == READ_FIELD_INFO) { myFieldInfoBuffer.push_back(ucs2char); return; } if (myReadState == READ_FIELD && myReadFieldState == DONT_READ_FIELD_TEXT) { return; } if (myReadState == READ_FIELD && myReadFieldState == READ_FIELD_TEXT && ucs2char == WORD_HORIZONTAL_TAB) { //to remove pagination from TOC (from doc saved in OpenOffice) myReadFieldState = DONT_READ_FIELD_TEXT; return; } std::string utf8String; ZLUnicodeUtil::Ucs2String ucs2String; ucs2String.push_back(ucs2char); ZLUnicodeUtil::ucs2ToUtf8(utf8String, ucs2String); if (!myModelReader.paragraphIsOpen()) { myModelReader.beginParagraph(); } myModelReader.addData(utf8String); } void DocBookReader::handleHardLinebreak() { if (myModelReader.paragraphIsOpen()) { myModelReader.endParagraph(); } myModelReader.beginParagraph(); if (!myCurrentStyleEntry.isNull()) { myModelReader.addStyleEntry(*myCurrentStyleEntry); } for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } void DocBookReader::handleParagraphEnd() { if (myModelReader.paragraphIsOpen()) { myModelReader.endParagraph(); } myModelReader.beginParagraph(); myCurrentStyleEntry = 0; } void DocBookReader::handlePageBreak() { if (myModelReader.paragraphIsOpen()) { myModelReader.endParagraph(); } myCurrentStyleEntry = 0; myModelReader.insertEndOfSectionParagraph(); myModelReader.beginParagraph(); } void DocBookReader::handleTableSeparator() { handleChar(SPACE); handleChar(VERTICAL_LINE); handleChar(SPACE); } void DocBookReader::handleTableEndRow() { handleParagraphEnd(); } void DocBookReader::handleFootNoteMark() { //TODO implement } void DocBookReader::handleStartField() { if (myReadState == READ_FIELD) { //for nested fields handleEndField(); } myReadState = READ_FIELD; myReadFieldState = READ_FIELD_INFO; myHyperlinkTypeState = NO_HYPERLINK; } void DocBookReader::handleSeparatorField() { static const std::string HYPERLINK = "HYPERLINK"; static const std::string SEQUENCE = "SEQ"; // static const std::string PAGE = "PAGE"; // static const std::string PAGEREF = "PAGEREF"; // static const std::string SHAPE = "SHAPE"; static const std::string SPACE_DELIMETER = " "; static const std::string LOCAL_LINK = "\\l"; static const std::string QUOTE = "\""; myReadFieldState = READ_FIELD_TEXT; myHyperlinkTypeState = NO_HYPERLINK; ZLUnicodeUtil::Ucs2String buffer = myFieldInfoBuffer; myFieldInfoBuffer.clear(); std::string utf8String; ZLUnicodeUtil::ucs2ToUtf8(utf8String, buffer); ZLUnicodeUtil::utf8Trim(utf8String); if (utf8String.empty()) { return; } std::vector result = ZLStringUtil::split(utf8String, SPACE_DELIMETER); //TODO split function can returns empty string, maybe fix it std::vector splitted; for (std::size_t i = 0; i < result.size(); ++i) { if (!result.at(i).empty()) { splitted.push_back(result.at(i)); } } if (!splitted.empty() && splitted.at(0) == SEQUENCE) { myReadFieldState = READ_FIELD_TEXT; myHyperlinkTypeState = NO_HYPERLINK; return; } if (splitted.size() < 2 || splitted.at(0) != HYPERLINK) { myReadFieldState = DONT_READ_FIELD_TEXT; //to remove pagination from TOC and not hyperlink fields return; } if (splitted.at(1) == LOCAL_LINK) { std::string link = parseLink(buffer); if (!link.empty()) { myModelReader.addHyperlinkControl(INTERNAL_HYPERLINK, link); myHyperlinkTypeState = INT_HYPERLINK_INSERTED; } } else { std::string link = parseLink(buffer, true); if (!link.empty()) { myModelReader.addHyperlinkControl(EXTERNAL_HYPERLINK, link); myHyperlinkTypeState = EXT_HYPERLINK_INSERTED; } } } void DocBookReader::handleEndField() { myFieldInfoBuffer.clear(); if (myReadState == READ_TEXT) { return; } if (myHyperlinkTypeState == EXT_HYPERLINK_INSERTED) { myModelReader.addControl(EXTERNAL_HYPERLINK, false); } else if (myHyperlinkTypeState == INT_HYPERLINK_INSERTED) { myModelReader.addControl(INTERNAL_HYPERLINK, false); } myReadState = READ_TEXT; myHyperlinkTypeState = NO_HYPERLINK; } void DocBookReader::handleImage(const ZLFileImage::Blocks &blocks) { std::string number; ZLStringUtil::appendNumber(number, myPictureCounter++); myModelReader.addImageReference(number); ZLFile file(myModelReader.model().book()->file().path(), ZLMimeType::IMAGE_AUTO); myModelReader.addImage(number, new ZLFileImage(file, blocks, ZLFileImage::ENCODING_NONE)); } void DocBookReader::handleOtherControlChar(ZLUnicodeUtil::Ucs2Char ucs2char) { if (ucs2char == WORD_MINUS) { handleChar(MINUS); } else if (ucs2char == WORD_SOFT_HYPHEN) { //skip } else if (ucs2char == WORD_HORIZONTAL_TAB) { handleChar(ucs2char); } else { // myTextBuffer.clear(); } } void DocBookReader::handleFontStyle(unsigned int fontStyle) { if (myReadState == READ_FIELD && myReadFieldState == READ_FIELD_TEXT && myHyperlinkTypeState != NO_HYPERLINK) { //to fix bug with hyperlink, that's only bold and doesn't looks like hyperlink return; } while (!myKindStack.empty()) { myModelReader.addControl(myKindStack.back(), false); myKindStack.pop_back(); } if (fontStyle & OleMainStream::CharInfo::FONT_BOLD) { myKindStack.push_back(BOLD); } if (fontStyle & OleMainStream::CharInfo::FONT_ITALIC) { myKindStack.push_back(ITALIC); } for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } void DocBookReader::handleParagraphStyle(const OleMainStream::Style &styleInfo) { if (styleInfo.HasPageBreakBefore) { handlePageBreak(); } shared_ptr entry = new ZLTextStyleEntry(ZLTextStyleEntry::STYLE_OTHER_ENTRY); switch (styleInfo.Alignment) { default: // in that case, use default alignment type break; case OleMainStream::Style::ALIGNMENT_LEFT: entry->setAlignmentType(ALIGN_LEFT); break; case OleMainStream::Style::ALIGNMENT_RIGHT: entry->setAlignmentType(ALIGN_RIGHT); break; case OleMainStream::Style::ALIGNMENT_CENTER: entry->setAlignmentType(ALIGN_CENTER); break; case OleMainStream::Style::ALIGNMENT_JUSTIFY: entry->setAlignmentType(ALIGN_JUSTIFY); break; } //TODO in case, where style is heading, but size is small it works wrong const ZLTextStyleEntry::SizeUnit unit = ZLTextStyleEntry::SIZE_UNIT_PERCENT; switch (styleInfo.StyleIdCurrent) { default: break; case OleMainStream::Style::STYLE_H1: entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 140, unit); break; case OleMainStream::Style::STYLE_H2: entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 120, unit); break; case OleMainStream::Style::STYLE_H3: entry->setLength(ZLTextStyleEntry::LENGTH_FONT_SIZE, 110, unit); break; } myCurrentStyleEntry = entry; myModelReader.addStyleEntry(*myCurrentStyleEntry); // we should have the same font style, as for the previous paragraph, // if it has the same StyleIdCurrent if (myCurrentStyleInfo.StyleIdCurrent != OleMainStream::Style::STYLE_INVALID && myCurrentStyleInfo.StyleIdCurrent == styleInfo.StyleIdCurrent) { for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } else { myKindStack.clear(); // fill by the fontstyle, that was got from Stylesheet handleFontStyle(styleInfo.CurrentCharInfo.FontStyle); } myCurrentStyleInfo = styleInfo; } void DocBookReader::handleBookmark(const std::string &name) { myModelReader.addHyperlinkLabel(name); } std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode) { //TODO add support for HYPERLINK like that: // [0x13] HYPERLINK "http://site.ru/some text" \t "_blank" [0x14] text [0x15] //Current implementation search for last QUOTE, so, it reads \t and _blank as part of link //Last quote searching is need to handle link like that: // [0x13] HYPERLINK "http://yandex.ru/yandsearch?text='some text' и "some text2"" [0x14] link text [0x15] static const ZLUnicodeUtil::Ucs2Char QUOTE = 0x22; std::size_t i, first = 0; //TODO maybe functions findFirstOf and findLastOf should be in ZLUnicodeUtil class for (i = 0; i < s.size(); ++i) { if (s.at(i) == QUOTE) { first = i; break; } } if (i == s.size()) { return std::string(); } std::size_t j, last = 0; for (j = s.size(); j > 0 ; --j) { if (s.at(j - 1) == QUOTE) { last = j - 1; break; } } if (j == 0 || last == first) { return std::string(); } ZLUnicodeUtil::Ucs2String link; for (std::size_t k = first + 1; k < last; ++k) { ZLUnicodeUtil::Ucs2Char ch = s.at(k); if (urlencode && ZLUnicodeUtil::isSpace(ch)) { //TODO maybe implement function for encoding all signs in url, not only spaces and quotes //TODO maybe add backslash support link.push_back('%'); link.push_back('2'); link.push_back('0'); } else if (urlencode && ch == QUOTE) { link.push_back('%'); link.push_back('2'); link.push_back('2'); } else { link.push_back(ch); } } std::string utf8String; ZLUnicodeUtil::ucs2ToUtf8(utf8String, link); return utf8String; } void DocBookReader::footnotesStartHandler() { handlePageBreak(); } void DocBookReader::ansiDataHandler(const char *buffer, std::size_t len) { if (myConverter.isNull()) { // lazy converter initialization ZLEncodingCollection &collection = ZLEncodingCollection::Instance(); ZLEncodingConverterInfoPtr info = collection.info(myEncoding); myConverter = info.isNull() ? collection.defaultConverter() : info->createConverter(); } std::string utf8String; myConverter->convert(utf8String, buffer, buffer + len); ZLUnicodeUtil::utf8ToUcs2(myBuffer, utf8String); } void DocBookReader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { myBuffer.push_back(symbol); } fbreader-0.99.4.orig/fbreader/src/formats/doc/OleMainStream.cpp0000644000706400070640000011055412056124565022715 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "OleUtil.h" #include "OleStorage.h" #include "DocInlineImageReader.h" #include "OleMainStream.h" OleMainStream::Style::Style() : StyleIdCurrent(STYLE_INVALID), StyleIdNext(STYLE_INVALID), HasPageBreakBefore(false), BeforeParagraphIndent(0), AfterParagraphIndent(0), LeftIndent(0), FirstLineIndent(0), RightIndent(0), Alignment(ALIGNMENT_DEFAULT) { } OleMainStream::CharInfo::CharInfo() : FontStyle(FONT_REGULAR), FontSize(20) { } OleMainStream::SectionInfo::SectionInfo() : CharPosition(0), IsNewPage(true) { } OleMainStream::InlineImageInfo::InlineImageInfo() : DataPosition(0) { } OleMainStream::FloatImageInfo::FloatImageInfo() : ShapeId(0) { } OleMainStream::OleMainStream(shared_ptr storage, OleEntry oleEntry, shared_ptr stream) : OleStream(storage, oleEntry, stream) { } bool OleMainStream::open(bool doReadFormattingData) { if (OleStream::open() == false) { return false; } static const std::size_t HEADER_SIZE = 768; //size of data in header of main stream char headerBuffer[HEADER_SIZE]; seek(0, true); if (read(headerBuffer, HEADER_SIZE) != HEADER_SIZE) { return false; } bool result = readFIB(headerBuffer); if (!result) { return false; } // determining table stream number unsigned int tableNumber = (OleUtil::getU2Bytes(headerBuffer, 0xA) & 0x0200) ? 1 : 0; std::string tableName = tableNumber == 0 ? "0" : "1"; tableName += "Table"; OleEntry tableEntry; result = myStorage->getEntryByName(tableName, tableEntry); if (!result) { // cant't find table stream (that can be only in case if file format is below Word 7/8), so building simple table stream // TODO: CHECK may be not all old documents have ANSI ZLLogger::Instance().println("DocPlugin", "cant't find table stream, building own simple piece table, that includes all charachters"); Piece piece = {myStartOfText, myEndOfText - myStartOfText, true, Piece::PIECE_TEXT, 0}; myPieces.push_back(piece); return true; } result = readPieceTable(headerBuffer, tableEntry); if (!result) { ZLLogger::Instance().println("DocPlugin", "error during reading piece table"); return false; } if (!doReadFormattingData) { return true; } OleEntry dataEntry; if (myStorage->getEntryByName("Data", dataEntry)) { myDataStream = new OleStream(myStorage, dataEntry, myBaseStream); } //result of reading following structures doesn't check, because all these //problems can be ignored, and document can be showed anyway, maybe with wrong formatting readBookmarks(headerBuffer, tableEntry); readStylesheet(headerBuffer, tableEntry); //readSectionsInfoTable(headerBuffer, tableEntry); //it isn't used now readParagraphStyleTable(headerBuffer, tableEntry); readCharInfoTable(headerBuffer, tableEntry); readFloatingImages(headerBuffer, tableEntry); return true; } const OleMainStream::Pieces &OleMainStream::getPieces() const { return myPieces; } const OleMainStream::CharInfoList &OleMainStream::getCharInfoList() const { return myCharInfoList; } const OleMainStream::StyleInfoList &OleMainStream::getStyleInfoList() const { return myStyleInfoList; } const OleMainStream::BookmarksList &OleMainStream::getBookmarks() const { return myBookmarks; } const OleMainStream::InlineImageInfoList &OleMainStream::getInlineImageInfoList() const { return myInlineImageInfoList; } const OleMainStream::FloatImageInfoList &OleMainStream::getFloatImageInfoList() const { return myFloatImageInfoList; } ZLFileImage::Blocks OleMainStream::getFloatImage(unsigned int shapeId) const { if (myFLoatImageReader.isNull()) { return ZLFileImage::Blocks(); } return myFLoatImageReader->getBlocksForShapeId(shapeId); } ZLFileImage::Blocks OleMainStream::getInlineImage(unsigned int dataPosition) const { if (myDataStream.isNull()) { return ZLFileImage::Blocks(); } DocInlineImageReader imageReader(myDataStream); return imageReader.getImagePieceInfo(dataPosition); } bool OleMainStream::readFIB(const char *headerBuffer) { int flags = OleUtil::getU2Bytes(headerBuffer, 0xA); //offset for flags if (flags & 0x0004) { //flag for complex format ZLLogger::Instance().println("DocPlugin", "This was fast-saved. Some information is lost"); //lostInfo = (flags & 0xF0) >> 4); } if (flags & 0x1000) { //flag for using extending charset ZLLogger::Instance().println("DocPlugin", "File uses extended character set (get_word8_char)"); } else { ZLLogger::Instance().println("DocPlugin", "File uses get_8bit_char character set"); } if (flags & 0x100) { //flag for encrypted files ZLLogger::Instance().println("DocPlugin", "File is encrypted"); // Encryption key = %08lx ; NumUtil::get4Bytes(header, 14) return false; } unsigned int charset = OleUtil::getU2Bytes(headerBuffer, 0x14); //offset for charset number if (charset && charset != 0x100) { //0x100 = default charset ZLLogger::Instance().println("DocPlugin", "Using not default character set %d"); } else { ZLLogger::Instance().println("DocPlugin", "Using default character set"); } myStartOfText = OleUtil::get4Bytes(headerBuffer, 0x18); //offset for start of text value myEndOfText = OleUtil::get4Bytes(headerBuffer, 0x1c); //offset for end of text value return true; } void OleMainStream::splitPieces(const Pieces &s, Pieces &dest1, Pieces &dest2, Piece::PieceType type1, Piece::PieceType type2, int boundary) { Pieces source = s; dest1.clear(); dest2.clear(); int sumLength = 0; std::size_t i = 0; for (i = 0; i < source.size(); ++i) { Piece piece = source.at(i); if (piece.Length + sumLength >= boundary) { Piece piece2 = piece; piece.Length = boundary - sumLength; piece.Type = type1; piece2.Type = type2; piece2.Offset += piece.Length * 2; piece2.Length -= piece.Length; if (piece.Length > 0) { dest1.push_back(piece); } if (piece2.Length > 0) { dest2.push_back(piece2); } ++i; break; } sumLength += piece.Length; piece.Type = type1; dest1.push_back(piece); } for (; i < source.size(); ++i) { Piece piece = source.at(i); piece.Type = type2; dest2.push_back(piece); } } std::string OleMainStream::getPiecesTableBuffer(const char *headerBuffer, OleStream &tableStream) { unsigned int clxOffset = OleUtil::getU4Bytes(headerBuffer, 0x01A2); //offset for CLX structure unsigned int clxLength = OleUtil::getU4Bytes(headerBuffer, 0x01A6); //offset for value of CLX structure length //1 step : loading CLX table from table stream char *clxBuffer = new char[clxLength]; if (!tableStream.seek(clxOffset, true)) { ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- error for seeking to CLX structure"); return std::string(); } if (tableStream.read(clxBuffer, clxLength) != clxLength) { ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure length is invalid"); return std::string(); } std::string clx(clxBuffer, clxLength); delete[] clxBuffer; //2 step: searching for pieces table buffer at CLX //(determines it by 0x02 as start symbol) std::size_t from = 0; std::size_t i; std::string pieceTableBuffer; while ((i = clx.find_first_of(0x02, from)) != std::string::npos) { if (clx.size() < i + 1 + 4) { ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure has invalid format"); return std::string(); } unsigned int pieceTableLength = OleUtil::getU4Bytes(clx.c_str(), i + 1); pieceTableBuffer = std::string(clx, i + 1 + 4); if (pieceTableBuffer.length() != pieceTableLength) { from = i + 1; continue; } break; } return pieceTableBuffer; } bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tableEntry) { OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string piecesTableBuffer = getPiecesTableBuffer(headerBuffer, tableStream); if (piecesTableBuffer.empty()) { return false; } //getting count of Character Positions for different types of subdocuments in Main Stream int ccpText = OleUtil::get4Bytes(headerBuffer, 0x004C); //text int ccpFtn = OleUtil::get4Bytes(headerBuffer, 0x0050); //footnote subdocument int ccpHdd = OleUtil::get4Bytes(headerBuffer, 0x0054); //header subdocument int ccpMcr = OleUtil::get4Bytes(headerBuffer, 0x0058); //macro subdocument int ccpAtn = OleUtil::get4Bytes(headerBuffer, 0x005C); //comment subdocument int ccpEdn = OleUtil::get4Bytes(headerBuffer, 0x0060); //endnote subdocument int ccpTxbx = OleUtil::get4Bytes(headerBuffer, 0x0064); //textbox subdocument int ccpHdrTxbx = OleUtil::get4Bytes(headerBuffer, 0x0068); //textbox subdocument of the header int lastCP = ccpFtn + ccpHdd + ccpMcr + ccpAtn + ccpEdn + ccpTxbx + ccpHdrTxbx; if (lastCP != 0) { ++lastCP; } lastCP += ccpText; //getting the CP (character positions) and CP descriptors std::vector cp; //array of character positions for pieces unsigned int j = 0; for (j = 0; ; j += 4) { if (piecesTableBuffer.size() < j + 4) { ZLLogger::Instance().println("DocPlugin", "invalid piece table, cp ends not with a lastcp"); break; } int curCP = OleUtil::get4Bytes(piecesTableBuffer.c_str(), j); cp.push_back(curCP); if (curCP == lastCP) { break; } } if (cp.size() < 2) { ZLLogger::Instance().println("DocPlugin", "invalid piece table, < 2 pieces"); return false; } std::vector descriptors; for (std::size_t k = 0; k < cp.size() - 1; ++k) { //j + 4, because it should be taken after CP in PiecesTable Buffer //k * 8, because it should be taken 8 byte for each descriptor std::size_t substrFrom = j + 4 + k * 8; if (piecesTableBuffer.size() < substrFrom + 8) { ZLLogger::Instance().println("DocPlugin", "invalid piece table, problems with descriptors reading"); break; } descriptors.push_back(piecesTableBuffer.substr(substrFrom, 8)); } //filling the Pieces vector std::size_t minValidSize = std::min(cp.size() - 1, descriptors.size()); if (minValidSize == 0) { ZLLogger::Instance().println("DocPlugin", "invalid piece table, there are no pieces"); return false; } for (std::size_t i = 0; i < minValidSize; ++i) { //4byte integer with offset and ANSI flag int fcValue = OleUtil::get4Bytes(descriptors.at(i).c_str(), 0x2); //offset for piece structure Piece piece; piece.IsANSI = (fcValue & 0x40000000) == 0x40000000; //ansi flag piece.Offset = fcValue & 0x3FFFFFFF; //gettting offset for current piece piece.Length = cp.at(i + 1) - cp.at(i); myPieces.push_back(piece); } //split pieces into different types Pieces piecesText, piecesFootnote, piecesOther; splitPieces(myPieces, piecesText, piecesFootnote, Piece::PIECE_TEXT, Piece::PIECE_FOOTNOTE, ccpText); splitPieces(piecesFootnote, piecesFootnote, piecesOther, Piece::PIECE_FOOTNOTE, Piece::PIECE_OTHER, ccpFtn); myPieces.clear(); for (std::size_t i = 0; i < piecesText.size(); ++i) { myPieces.push_back(piecesText.at(i)); } for (std::size_t i = 0; i < piecesFootnote.size(); ++i) { myPieces.push_back(piecesFootnote.at(i)); } for (std::size_t i = 0; i < piecesOther.size(); ++i) { myPieces.push_back(piecesOther.at(i)); } //converting length and offset depending on isANSI for (std::size_t i = 0; i < myPieces.size(); ++i) { Piece &piece = myPieces.at(i); if (!piece.IsANSI) { piece.Length *= 2; } else { piece.Offset /= 2; } } //filling startCP field unsigned int curStartCP = 0; for (std::size_t i = 0; i < myPieces.size(); ++i) { Piece &piece = myPieces.at(i); piece.startCP = curStartCP; if (piece.IsANSI) { curStartCP += piece.Length; } else { curStartCP += piece.Length / 2; } } return true; } bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tableEntry) { //SttbfBkmk structure is a table of bookmark name strings unsigned int beginNamesInfo = OleUtil::getU4Bytes(headerBuffer, 0x142); // address of SttbfBkmk structure std::size_t namesInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x146); // length of SttbfBkmk structure if (namesInfoLength == 0) { return true; //there's no bookmarks } OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string buffer; if (!readToBuffer(buffer, beginNamesInfo, namesInfoLength, tableStream)) { return false; } unsigned int recordsNumber = OleUtil::getU2Bytes(buffer.c_str(), 0x2); //count of records std::vector names; unsigned int offset = 0x6; //initial offset for (unsigned int i = 0; i < recordsNumber; ++i) { if (buffer.size() < offset + 2) { ZLLogger::Instance().println("DocPlugin", "problmes with reading bookmarks names"); break; } unsigned int length = OleUtil::getU2Bytes(buffer.c_str(), offset) * 2; //length of string in bytes ZLUnicodeUtil::Ucs2String name; for (unsigned int j = 0; j < length; j+=2) { char ch1 = buffer.at(offset + 2 + j); char ch2 = buffer.at(offset + 2 + j + 1); ZLUnicodeUtil::Ucs2Char ucs2Char = (unsigned int)ch1 | ((unsigned int)ch2 << 8); name.push_back(ucs2Char); } std::string utf8Name; ZLUnicodeUtil::ucs2ToUtf8(utf8Name, name); names.push_back(utf8Name); offset += length + 2; } //plcfBkmkf structure is table recording beginning CPs of bookmarks unsigned int beginCharPosInfo = OleUtil::getU4Bytes(headerBuffer, 0x14A); // address of plcfBkmkf structure std::size_t charPosInfoLen = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x14E); // length of plcfBkmkf structure if (charPosInfoLen == 0) { return true; //there's no bookmarks } if (!readToBuffer(buffer, beginCharPosInfo, charPosInfoLen, tableStream)) { return false; } static const unsigned int BKF_SIZE = 4; std::size_t size = calcCountOfPLC(charPosInfoLen, BKF_SIZE); std::vector charPage; for (std::size_t index = 0, offset = 0; index < size; ++index, offset += 4) { charPage.push_back(OleUtil::getU4Bytes(buffer.c_str(), offset)); } for (std::size_t i = 0; i < names.size(); ++i) { if (i >= charPage.size()) { break; //for the case if something in these structures goes wrong, to not to lose all bookmarks } Bookmark bookmark; bookmark.CharPosition = charPage.at(i); bookmark.Name = names.at(i); myBookmarks.push_back(bookmark); } return true; } bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tableEntry) { //STSH structure is a stylesheet unsigned int beginStshInfo = OleUtil::getU4Bytes(headerBuffer, 0xa2); // address of STSH structure std::size_t stshInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xa6); // length of STSH structure OleStream tableStream(myStorage, tableEntry, myBaseStream); char *buffer = new char[stshInfoLength]; if (!tableStream.seek(beginStshInfo, true)) { ZLLogger::Instance().println("DocPlugin", "problems with reading STSH structure"); return false; } if (tableStream.read(buffer, stshInfoLength) != stshInfoLength) { ZLLogger::Instance().println("DocPlugin", "problems with reading STSH structure, invalid length"); return false; } std::size_t stdCount = (std::size_t)OleUtil::getU2Bytes(buffer, 2); std::size_t stdBaseInFile = (std::size_t)OleUtil::getU2Bytes(buffer, 4); myStyleSheet.resize(stdCount); std::vector isFilled; isFilled.resize(stdCount, false); std::size_t stdLen = 0; bool styleSheetWasChanged = false; do { //make it in while loop, because some base style can be after their successors styleSheetWasChanged = false; for (std::size_t index = 0, offset = 2 + (std::size_t)OleUtil::getU2Bytes(buffer, 0); index < stdCount; index++, offset += 2 + stdLen) { stdLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset); if (isFilled.at(index)) { continue; } if (stdLen == 0) { //if record is empty, left it default isFilled[index] = true; continue; } Style styleInfo = myStyleSheet.at(index); const unsigned int styleAndBaseType = OleUtil::getU2Bytes(buffer, offset + 4); const unsigned int styleType = styleAndBaseType % 16; const unsigned int baseStyleId = styleAndBaseType / 16; if (baseStyleId == Style::STYLE_NIL || baseStyleId == Style::STYLE_USER) { //if based on nil or user style, left default } else { int baseStyleIndex = getStyleIndex(baseStyleId, isFilled, myStyleSheet); if (baseStyleIndex < 0) { //this base style is not filled yet, so pass it at some time continue; } styleInfo = myStyleSheet.at(baseStyleIndex); styleInfo.StyleIdCurrent = Style::STYLE_INVALID; } // parse STD structure unsigned int tmp = OleUtil::getU2Bytes(buffer, offset + 6); unsigned int upxCount = tmp % 16; styleInfo.StyleIdNext = tmp / 16; //adding current style myStyleSheet[index] = styleInfo; isFilled[index] = true; styleSheetWasChanged = true; std::size_t pos = 2 + stdBaseInFile; std::size_t nameLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); nameLen = nameLen * 2 + 2; //from Unicode characters to bytes + Unicode null charachter length pos += 2 + nameLen; if (pos % 2 != 0) { ++pos; } if (pos >= stdLen) { continue; } std::size_t upxLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); if (pos + upxLen > stdLen) { //UPX length too large continue; } //for style info styleType must be equal 1 if (styleType == 1 && upxCount >= 1) { if (upxLen >= 2) { styleInfo.StyleIdCurrent = OleUtil::getU2Bytes(buffer, offset + pos + 2); getStyleInfo(0, buffer + offset + pos + 4, upxLen - 2, styleInfo); myStyleSheet[index] = styleInfo; } pos += 2 + upxLen; if (pos % 2 != 0) { ++pos; } upxLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); } if (upxLen == 0 || pos + upxLen > stdLen) { //too small/too large continue; } //for char info styleType can be equal 1 or 2 if ((styleType == 1 && upxCount >= 2) || (styleType == 2 && upxCount >= 1)) { CharInfo charInfo; getCharInfo(0, Style::STYLE_INVALID, buffer + offset + pos + 2, upxLen, charInfo); styleInfo.CurrentCharInfo = charInfo; myStyleSheet[index] = styleInfo; } } } while (styleSheetWasChanged); delete[] buffer; return true; } bool OleMainStream::readCharInfoTable(const char *headerBuffer, const OleEntry &tableEntry) { //PlcfbteChpx structure is table with formatting for particular run of text unsigned int beginCharInfo = OleUtil::getU4Bytes(headerBuffer, 0xfa); // address of PlcfbteChpx structure std::size_t charInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xfe); // length of PlcfbteChpx structure if (charInfoLength < 4) { return false; } OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string buffer; if (!readToBuffer(buffer, beginCharInfo, charInfoLength, tableStream)) { return false; } static const unsigned int CHPX_SIZE = 4; std::size_t size = calcCountOfPLC(charInfoLength, CHPX_SIZE); std::vector charBlocks; for (std::size_t index = 0, offset = (size + 1) * 4; index < size; ++index, offset += CHPX_SIZE) { charBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), offset)); } char *formatPageBuffer = new char[OleStorage::BBD_BLOCK_SIZE]; for (std::size_t index = 0; index < charBlocks.size(); ++index) { seek(charBlocks.at(index) * OleStorage::BBD_BLOCK_SIZE, true); if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) { return false; } unsigned int crun = OleUtil::getU1Byte(formatPageBuffer, 0x1ff); //offset with crun (count of 'run of text') for (unsigned int index2 = 0; index2 < crun; ++index2) { unsigned int offset = OleUtil::getU4Bytes(formatPageBuffer, index2 * 4); unsigned int chpxOffset = 2 * OleUtil::getU1Byte(formatPageBuffer, (crun + 1) * 4 + index2); unsigned int len = OleUtil::getU1Byte(formatPageBuffer, chpxOffset); unsigned int charPos = 0; if (!offsetToCharPos(offset, charPos, myPieces)) { continue; } unsigned int styleId = getStyleIdByCharPos(charPos, myStyleInfoList); CharInfo charInfo = getStyleFromStylesheet(styleId, myStyleSheet).CurrentCharInfo; if (chpxOffset != 0) { getCharInfo(chpxOffset, styleId, formatPageBuffer + 1, len - 1, charInfo); } myCharInfoList.push_back(CharPosToCharInfo(charPos, charInfo)); if (chpxOffset != 0) { InlineImageInfo pictureInfo; if (getInlineImageInfo(chpxOffset, formatPageBuffer + 1, len - 1, pictureInfo)) { myInlineImageInfoList.push_back(CharPosToInlineImageInfo(charPos, pictureInfo)); } } } } delete[] formatPageBuffer; return true; } bool OleMainStream::readFloatingImages(const char *headerBuffer, const OleEntry &tableEntry) { //Plcspa structure is a table with information for FSPA (File Shape Address) unsigned int beginPicturesInfo = OleUtil::getU4Bytes(headerBuffer, 0x01DA); // address of Plcspa structure if (beginPicturesInfo == 0) { return true; //there's no office art objects } unsigned int picturesInfoLength = OleUtil::getU4Bytes(headerBuffer, 0x01DE); // length of Plcspa structure if (picturesInfoLength < 4) { return false; } OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string buffer; if (!readToBuffer(buffer, beginPicturesInfo, picturesInfoLength, tableStream)) { return false; } static const unsigned int SPA_SIZE = 26; std::size_t size = calcCountOfPLC(picturesInfoLength, SPA_SIZE); std::vector picturesBlocks; for (std::size_t index = 0, tOffset = 0; index < size; ++index, tOffset += 4) { picturesBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset)); } for (std::size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += SPA_SIZE) { unsigned int spid = OleUtil::getU4Bytes(buffer.c_str(), tOffset); FloatImageInfo info; unsigned int charPos = picturesBlocks.at(index); info.ShapeId = spid; myFloatImageInfoList.push_back(CharPosToFloatImageInfo(charPos, info)); } //DggInfo structure is office art object table data unsigned int beginOfficeArtContent = OleUtil::getU4Bytes(headerBuffer, 0x22A); // address of DggInfo structure if (beginOfficeArtContent == 0) { return true; //there's no office art objects } unsigned int officeArtContentLength = OleUtil::getU4Bytes(headerBuffer, 0x022E); // length of DggInfo structure if (officeArtContentLength < 4) { return false; } shared_ptr newTableStream = new OleStream(myStorage, tableEntry, myBaseStream); shared_ptr newMainStream = new OleStream(myStorage, myOleEntry, myBaseStream); if (newTableStream->open() && newMainStream->open()) { myFLoatImageReader = new DocFloatImageReader(beginOfficeArtContent, officeArtContentLength, newTableStream, newMainStream); myFLoatImageReader->readAll(); } return true; } bool OleMainStream::readParagraphStyleTable(const char *headerBuffer, const OleEntry &tableEntry) { //PlcBtePapx structure is table with formatting for all paragraphs unsigned int beginParagraphInfo = OleUtil::getU4Bytes(headerBuffer, 0x102); // address of PlcBtePapx structure std::size_t paragraphInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x106); // length of PlcBtePapx structure if (paragraphInfoLength < 4) { return false; } OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string buffer; if (!readToBuffer(buffer, beginParagraphInfo, paragraphInfoLength, tableStream)) { return false; } static const unsigned int PAPX_SIZE = 4; std::size_t size = calcCountOfPLC(paragraphInfoLength, PAPX_SIZE); std::vector paragraphBlocks; for (std::size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += PAPX_SIZE) { paragraphBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset)); } char *formatPageBuffer = new char[OleStorage::BBD_BLOCK_SIZE]; for (std::size_t index = 0; index < paragraphBlocks.size(); ++index) { seek(paragraphBlocks.at(index) * OleStorage::BBD_BLOCK_SIZE, true); if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) { return false; } const unsigned int paragraphsCount = OleUtil::getU1Byte(formatPageBuffer, 0x1ff); //offset with 'cpara' value (count of paragraphs) for (unsigned int index2 = 0; index2 < paragraphsCount; ++index2) { const unsigned int offset = OleUtil::getU4Bytes(formatPageBuffer, index2 * 4); unsigned int papxOffset = OleUtil::getU1Byte(formatPageBuffer, (paragraphsCount + 1) * 4 + index2 * 13) * 2; if (papxOffset <= 0) { continue; } unsigned int len = OleUtil::getU1Byte(formatPageBuffer, papxOffset) * 2; if (len == 0) { ++papxOffset; len = OleUtil::getU1Byte(formatPageBuffer, papxOffset) * 2; } const unsigned int styleId = OleUtil::getU2Bytes(formatPageBuffer, papxOffset + 1); Style styleInfo = getStyleFromStylesheet(styleId, myStyleSheet); if (len >= 3) { getStyleInfo(papxOffset, formatPageBuffer + 3, len - 3, styleInfo); } unsigned int charPos = 0; if (!offsetToCharPos(offset, charPos, myPieces)) { continue; } myStyleInfoList.push_back(CharPosToStyle(charPos, styleInfo)); } } delete[] formatPageBuffer; return true; } bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEntry &tableEntry) { //PlcfSed structure is a section table unsigned int beginOfText = OleUtil::getU4Bytes(headerBuffer, 0x18); //address of text's begin in main stream unsigned int beginSectInfo = OleUtil::getU4Bytes(headerBuffer, 0xca); //address if PlcfSed structure std::size_t sectInfoLen = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xce); //length of PlcfSed structure if (sectInfoLen < 4) { return false; } OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string buffer; if (!readToBuffer(buffer, beginSectInfo, sectInfoLen, tableStream)) { return false; } static const unsigned int SED_SIZE = 12; std::size_t decriptorsCount = calcCountOfPLC(sectInfoLen, SED_SIZE); //saving the section offsets (in character positions) std::vector charPos; for (std::size_t index = 0, tOffset = 0; index < decriptorsCount; ++index, tOffset += 4) { unsigned int ulTextOffset = OleUtil::getU4Bytes(buffer.c_str(), tOffset); charPos.push_back(beginOfText + ulTextOffset); } //saving sepx offsets std::vector sectPage; for (std::size_t index = 0, tOffset = (decriptorsCount + 1) * 4; index < decriptorsCount; ++index, tOffset += SED_SIZE) { sectPage.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset + 2)); } //reading the section properties char tmpBuffer[2]; for (std::size_t index = 0; index < sectPage.size(); ++index) { if (sectPage.at(index) == 0xffffffffUL) { //check for invalid record, to make default section info SectionInfo sectionInfo; sectionInfo.CharPosition = charPos.at(index); mySectionInfoList.push_back(sectionInfo); continue; } //getting number of bytes to read if (!seek(sectPage.at(index), true)) { continue; } if (read(tmpBuffer, 2) != 2) { continue; } std::size_t bytes = 2 + (std::size_t)OleUtil::getU2Bytes(tmpBuffer, 0); if (!seek(sectPage.at(index), true)) { continue; } char *formatPageBuffer = new char[bytes]; if (read(formatPageBuffer, bytes) != bytes) { delete[] formatPageBuffer; continue; } SectionInfo sectionInfo; sectionInfo.CharPosition = charPos.at(index); getSectionInfo(formatPageBuffer + 2, bytes - 2, sectionInfo); mySectionInfoList.push_back(sectionInfo); delete[] formatPageBuffer; } return true; } void OleMainStream::getStyleInfo(unsigned int papxOffset, const char *grpprlBuffer, unsigned int bytes, Style &styleInfo) { int tmp, toDelete, toAdd; unsigned int offset = 0; while (bytes >= offset + 2) { unsigned int curPrlLength = 0; switch (OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset)) { case 0x2403: styleInfo.Alignment = (Style::AlignmentType)OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2); break; case 0x4610: styleInfo.LeftIndent += OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); if (styleInfo.LeftIndent < 0) { styleInfo.LeftIndent = 0; } break; case 0xc60d: // ChgTabsPapx case 0xc615: // ChgTabs tmp = OleUtil::get1Byte(grpprlBuffer, papxOffset + offset + 2); if (tmp < 2) { curPrlLength = 1; break; } toDelete = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 3); if (tmp < 2 + 2 * toDelete) { curPrlLength = 1; break; } toAdd = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 4 + 2 * toDelete); if (tmp < 2 + 2 * toDelete + 2 * toAdd) { curPrlLength = 1; break; } break; case 0x840e: styleInfo.RightIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); break; case 0x840f: styleInfo.LeftIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); break; case 0x8411: styleInfo.FirstLineIndent = (int)OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); break; case 0xa413: styleInfo.BeforeParagraphIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); break; case 0xa414: styleInfo.AfterParagraphIndent = OleUtil::getU2Bytes(grpprlBuffer, papxOffset + offset + 2); break; case 0x2407: styleInfo.HasPageBreakBefore = OleUtil::getU1Byte(grpprlBuffer, papxOffset + offset + 2) == 0x01; break; default: break; } if (curPrlLength == 0) { curPrlLength = getPrlLength(grpprlBuffer, papxOffset + offset); } offset += curPrlLength; } } void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId*/, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo) { unsigned int sprm = 0; //single propery modifier unsigned int offset = 0; while (bytes >= offset + 2) { switch (OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset)) { case 0x0835: //bold sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2); switch (sprm) { case UNSET: charInfo.FontStyle &= ~CharInfo::FONT_BOLD; break; case SET: charInfo.FontStyle |= CharInfo::FONT_BOLD; break; case UNCHANGED: break; case NEGATION: charInfo.FontStyle ^= CharInfo::FONT_BOLD; break; default: break; } break; case 0x0836: //italic sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2); switch (sprm) { case UNSET: charInfo.FontStyle &= ~CharInfo::FONT_ITALIC; break; case SET: charInfo.FontStyle |= CharInfo::FONT_ITALIC; break; case UNCHANGED: break; case NEGATION: charInfo.FontStyle ^= CharInfo::FONT_ITALIC; break; default: break; } break; case 0x4a43: //size of font charInfo.FontSize = OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset + 2); break; default: break; } offset += getPrlLength(grpprlBuffer, chpxOffset + offset); } } void OleMainStream::getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo §ionInfo) { unsigned int tmp; std::size_t offset = 0; while (bytes >= offset + 2) { switch (OleUtil::getU2Bytes(grpprlBuffer, offset)) { case 0x3009: //new page tmp = OleUtil::getU1Byte(grpprlBuffer, offset + 2); sectionInfo.IsNewPage = (tmp != 0 && tmp != 1); break; default: break; } offset += getPrlLength(grpprlBuffer, offset); } } bool OleMainStream::getInlineImageInfo(unsigned int chpxOffset, const char *grpprlBuffer, unsigned int bytes, InlineImageInfo &pictureInfo) { //p. 105 of [MS-DOC] documentation unsigned int offset = 0; bool isFound = false; while (bytes >= offset + 2) { switch (OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset)) { case 0x080a: // ole object, p.107 [MS-DOC] if (OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2) == 0x01) { return false; } break; case 0x0806: // is not a picture, but a binary data? (sprmCFData, p.106 [MS-DOC]) if (OleUtil::getU4Bytes(grpprlBuffer, chpxOffset + offset + 2) == 0x01) { return false; } break; // case 0x0855: // sprmCFSpec, p.117 [MS-DOC], MUST BE applied with a value of 1 (see p.105 [MS-DOC]) // if (OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2) != 0x01) { // return false; // } // break; case 0x6a03: // location p.105 [MS-DOC] pictureInfo.DataPosition = OleUtil::getU4Bytes(grpprlBuffer, chpxOffset + offset + 2); isFound = true; break; default: break; } offset += getPrlLength(grpprlBuffer, chpxOffset + offset); } return isFound; } OleMainStream::Style OleMainStream::getStyleFromStylesheet(unsigned int styleId, const StyleSheet &stylesheet) { //TODO optimize it: StyleSheet can be map structure with styleId key Style style; if (styleId != Style::STYLE_INVALID && styleId != Style::STYLE_NIL && styleId != Style::STYLE_USER) { for (std::size_t index = 0; index < stylesheet.size(); ++index) { if (stylesheet.at(index).StyleIdCurrent == styleId) { return stylesheet.at(index); } } } style.StyleIdCurrent = styleId; return style; } int OleMainStream::getStyleIndex(unsigned int styleId, const std::vector &isFilled, const StyleSheet &stylesheet) { //TODO optimize it: StyleSheet can be map structure with styleId key //in that case, this method will be excess if (styleId == Style::STYLE_INVALID) { return -1; } for (int index = 0; index < (int)stylesheet.size(); ++index) { if (isFilled.at(index) && stylesheet.at(index).StyleIdCurrent == styleId) { return index; } } return -1; } unsigned int OleMainStream::getStyleIdByCharPos(unsigned int charPos, const StyleInfoList &styleInfoList) { unsigned int styleId = Style::STYLE_INVALID; for (std::size_t i = 0; i < styleInfoList.size(); ++i) { const Style &info = styleInfoList.at(i).second; if (i == styleInfoList.size() - 1) { //if last styleId = info.StyleIdCurrent; break; } unsigned int curOffset = styleInfoList.at(i).first; unsigned int nextOffset = styleInfoList.at(i + 1).first; if (charPos >= curOffset && charPos < nextOffset) { styleId = info.StyleIdCurrent; break; } } return styleId; } bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces) { if (pieces.empty()) { return false; } if ((unsigned int)pieces.front().Offset > offset) { charPos = 0; return true; } if ((unsigned int)(pieces.back().Offset + pieces.back().Length) <= offset) { return false; } std::size_t pieceNumber = 0; for (std::size_t i = 0; i < pieces.size(); ++i) { if (i == pieces.size() - 1) { //if last pieceNumber = i; break; } unsigned int curOffset = pieces.at(i).Offset; unsigned int nextOffset = pieces.at(i + 1).Offset; if (offset >= curOffset && offset < nextOffset) { pieceNumber = i; break; } } const Piece &piece = pieces.at(pieceNumber); unsigned int diffOffset = offset - piece.Offset; if (!piece.IsANSI) { diffOffset /= 2; } charPos = piece.startCP + diffOffset; return true; } bool OleMainStream::readToBuffer(std::string &result, unsigned int offset, std::size_t length, OleStream &stream) { char *buffer = new char[length]; stream.seek(offset, true); if (stream.read(buffer, length) != length) { return false; } result = std::string(buffer, length); delete[] buffer; return true; } unsigned int OleMainStream::calcCountOfPLC(unsigned int totalSize, unsigned int elementSize) { //calculates count of elements in PLC structure, formula from p.30 [MS-DOC] return (totalSize - 4) / (4 + elementSize); } unsigned int OleMainStream::getPrlLength(const char *grpprlBuffer, unsigned int byteNumber) { unsigned int tmp; unsigned int opCode = OleUtil::getU2Bytes(grpprlBuffer, byteNumber); switch (opCode & 0xe000) { case 0x0000: case 0x2000: return 3; case 0x4000: case 0x8000: case 0xA000: return 4; case 0xE000: return 5; case 0x6000: return 6; case 0xC000: //counting of info length tmp = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 2); if (opCode == 0xc615 && tmp == 255) { unsigned int del = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 3); unsigned int add = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 4 + del * 4); tmp = 2 + del * 4 + add * 3; } return 3 + tmp; default: return 1; } } fbreader-0.99.4.orig/fbreader/src/formats/doc/DocFloatImageReader.cpp0000644000706400070640000002627512056124565024004 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "OleUtil.h" #include "OleStream.h" #include "OleMainStream.h" #include "DocFloatImageReader.h" DocFloatImageReader::DocFloatImageReader(unsigned int off, unsigned int len, shared_ptr tableStream, shared_ptr mainStream) : myTableStream(tableStream), myMainStream(mainStream), myOffset(off), myLength(len) { } void DocFloatImageReader::readAll() { //OfficeArtContent structure is described at p.405-406 [MS-DOC] if (!myTableStream->seek(myOffset, true)) { ZLLogger::Instance().println("DocPlugin", "problems with reading float images"); return; } unsigned int count = 0; RecordHeader header; while (count < myLength) { count += readRecordHeader(header, myTableStream); switch (header.type) { case 0xF000: count += readDggContainer(myItem, header.length, myTableStream, myMainStream); break; case 0xF002: count += readDgContainer(myItem, header.length, myTableStream); break; default: return; break; } } } ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeId(unsigned int shapeId) const { FSPContainer container; bool found = false; for (std::size_t i = 0; !found && i < myItem.FSPs.size(); ++i) { if (myItem.FSPs.at(i).fsp.shapeId == shapeId) { found = true; container = myItem.FSPs.at(i); } } if (!found || container.fopte.empty()) { return ZLFileImage::Blocks(); } for (std::size_t i = 0; i < container.fopte.size(); ++i) { const FOPTE &fopte = container.fopte.at(i); if (fopte.pId == 0x0104 && !fopte.isComplex) { //0x0104 specifies the BLIP, see p.420 [MS-ODRAW] if (fopte.value <= myItem.blips.size() && fopte.value > 0) { Blip blip = myItem.blips.at(fopte.value - 1); return blip.blocks; } } } return ZLFileImage::Blocks(); } unsigned int DocFloatImageReader::readRecordHeader(RecordHeader &header, shared_ptr stream) { //OfficeArtRecordHeader structure is described at p.26 [MS-ODRAW] char buffer[8]; stream->read(buffer, 8); unsigned int temp = OleUtil::getU2Bytes(buffer, 0); header.version = temp & 0x000F; header.instance = temp >> 4; header.type = OleUtil::getU2Bytes(buffer, 2); header.length = OleUtil::getU4Bytes(buffer, 4); return 8; } unsigned int DocFloatImageReader::readDggContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream, shared_ptr mainStream) { //OfficeArtDggContainer structure is described at p.50 [MS-ODRAW] RecordHeader header; unsigned int count = 0; while (count < length) { count += readRecordHeader(header, stream); switch (header.type) { case 0xF001: count += readBStoreContainer(item, header.length, stream, mainStream); break; default: count += skipRecord(header, stream); break; } } stream->seek(1, false); //skipping dgglbl (see p.406 [MS-DOC]) ++count; return count; } unsigned int DocFloatImageReader::readBStoreContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream, shared_ptr mainStream) { //OfficeArtBStoreContainer structure is described at p.58 [MS-ODRAW] RecordHeader header; unsigned int count = 0; while (count < length) { count += readRecordHeader(header, stream); switch (header.type) { case 0xF007: { Blip blip; count += readBStoreContainerFileBlock(blip, stream, mainStream); item.blips.push_back(blip); } break; default: count += skipRecord(header, stream); break; } } return count; } unsigned int DocFloatImageReader::skipRecord(const RecordHeader &header, shared_ptr stream) { stream->seek(header.length, false); return header.length; } unsigned int DocFloatImageReader::readBStoreContainerFileBlock(Blip &blip, shared_ptr stream, shared_ptr mainStream) { //OfficeArtBStoreContainerFileBlock structure is described at p.59 [MS-ODRAW] unsigned int count = readFBSE(blip.storeEntry, stream); if (blip.storeEntry.offsetInDelay != (unsigned int)-1) { if (mainStream->seek(blip.storeEntry.offsetInDelay, true)) { //see p.70 [MS-ODRAW] //TODO maybe we should stop reading float images here ZLLogger::Instance().println("DocPlugin", "DocFloatImageReader: problems with seeking for offset"); return count; } } RecordHeader header; unsigned int count2 = readRecordHeader(header, mainStream); switch (header.type) { case OleMainStream::IMAGE_WMF: case OleMainStream::IMAGE_EMF: case OleMainStream::IMAGE_PICT: count2 += skipRecord(header, mainStream); break; case OleMainStream::IMAGE_JPEG: case OleMainStream::IMAGE_JPEG2: case OleMainStream::IMAGE_PNG: case OleMainStream::IMAGE_DIB: case OleMainStream::IMAGE_TIFF: count2 += readBlip(blip, header, mainStream); break; } blip.type = header.type; return count; } unsigned int DocFloatImageReader::readBlip(Blip &blip, const RecordHeader &header, shared_ptr stream) { //OfficeArtBlip structure is described at p.60-66 [MS-ODRAW] stream->seek(16, false); //skipping rgbUid1 unsigned int count = 16; bool addField = false; switch (header.type) { case OleMainStream::IMAGE_PNG: if (header.instance == 0x6E1) { addField = true; } break; case OleMainStream::IMAGE_JPEG: case OleMainStream::IMAGE_JPEG2: if (header.instance == 0x46B || header.instance == 0x6E3) { addField = true; } break; case OleMainStream::IMAGE_DIB: if (header.instance == 0x7A9) { addField = true; } case OleMainStream::IMAGE_TIFF: if (header.instance == 0x6E5) { addField = true; } break; } if (addField) { stream->seek(16, false); //skipping rgbUid2 count += 16; } stream->seek(1, false); //skipping tag count += 1; blip.blocks = stream->getBlockPieceInfoList(stream->offset(), header.length - count); count += header.length; return count; } unsigned int DocFloatImageReader::readFBSE(BlipStoreEntry &fbse, shared_ptr stream) { //OfficeArtFBSE structure is described at p.68 [MS-ODRAW] stream->seek(2, false); //skipping btWin32 and btMacOS stream->seek(16, false); //skipping rgbUid stream->seek(2, false); //skipping tag fbse.size = read4Bytes(stream); fbse.referenceCount = read4Bytes(stream); fbse.offsetInDelay = read4Bytes(stream); stream->seek(1, false); //skipping unused value unsigned int lengthName = read1Byte(stream); //if it should be multiplied on 2? stream->seek(2, false); // skipping unused values if (lengthName > 0) { stream->seek(lengthName, false); //skipping nameData } return 36 + lengthName; } unsigned int DocFloatImageReader::readDgContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream) { //OfficeArtDgContainer structure is described at p.52 [MS-ODRAW] unsigned int count = 0; RecordHeader header; while (count < length) { count += readRecordHeader(header, stream); switch (header.type) { case 0xF008: //skip OfficeArtFDG record, p. 82 [MS-ODRAW] stream->seek(8, false); count += 8; break; case 0xF003: count += readSpgrContainer(item, header.length, stream); break; case 0xF004: { FSPContainer fspContainer; count += readSpContainter(fspContainer, header.length, stream); item.FSPs.push_back(fspContainer); } break; default: count += skipRecord(header, stream); break; } } return count; } unsigned int DocFloatImageReader::readSpgrContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream) { //OfficeArtSpgrContainer structure is described at p.56 [MS-ODRAW] unsigned count = 0; RecordHeader header; while (count < length) { count += readRecordHeader(header, stream); switch (header.type) { case 0xF003: count += readSpgrContainer(item, header.length, stream); break; case 0xF004: { FSPContainer fspContainer; count += readSpContainter(fspContainer, header.length, stream); item.FSPs.push_back(fspContainer); } break; default: count += skipRecord(header, stream); break; } } return count; } unsigned int DocFloatImageReader::readSpContainter(FSPContainer &item, unsigned int length, shared_ptr stream) { //OfficeArtSpContainter structure is described at p.53-55 [MS-ODRAW] RecordHeader header; unsigned int count = 0; while (count < length) { count += readRecordHeader(header, stream); switch (header.type) { case 0xF009: //skip OfficeArtFSPGR record, p.74 [MS-ODRAW] stream->seek(16, false); count += 16; break; case 0xF00A: count += readFSP(item.fsp, stream); break; case 0xF00B: count += readArrayFOPTE(item.fopte, header.length, stream); break; case 0xF00E: //OfficeArtAnchor case 0xF00F: //OfficeArtChildAnchor, p.75 [MS-ODRAW] case 0xF010: //OfficeArtClientAnchor stream->seek(4, false); count += 4; break; case 0xF00C: case 0xF11F: case 0xF11D: break; default: count += skipRecord(header, stream); break; } } return count; } unsigned int DocFloatImageReader::readFSP(FSP &fsp, shared_ptr stream) { //OfficeArtFSP structure is described at p.76 [MS-ODRAW] fsp.shapeId = read4Bytes(stream); stream->seek(4, false); return 8; } unsigned int DocFloatImageReader::readArrayFOPTE(std::vector &fopteArray,unsigned int length, shared_ptr stream) { //OfficeArtRGFOPTE structure is described at p.98 [MS-ODRAW] unsigned int count = 0; while (count < length) { FOPTE fopte; count += readFOPTE(fopte, stream); fopteArray.push_back(fopte); } for (std::size_t i = 0; i < fopteArray.size(); ++i) { if (fopteArray.at(i).isComplex) { stream->seek(fopteArray.at(i).value, false); count += fopteArray.at(i).value; } } return count; } unsigned int DocFloatImageReader::readFOPTE(FOPTE &fopte, shared_ptr stream) { //OfficeArtFOPTE structure is described at p.32 [MS-ODRAW] unsigned int dtemp; dtemp = read2Bytes(stream); fopte.pId = (dtemp & 0x3fff); fopte.isBlipId = ((dtemp & 0x4000) >> 14) == 0x1; fopte.isComplex = ((dtemp & 0x8000) >> 15) == 0x1; fopte.value = read4Bytes(stream); return 6; } unsigned int DocFloatImageReader::read1Byte(shared_ptr stream) { char b[1]; if (stream->read(b, 1) != 1) { return 0; } return OleUtil::getU1Byte(b, 0); } unsigned int DocFloatImageReader::read2Bytes(shared_ptr stream) { char b[2]; if (stream->read(b, 2) != 2) { return 0; } return OleUtil::getU2Bytes(b, 0); } unsigned int DocFloatImageReader::read4Bytes(shared_ptr stream) { char b[4]; if (stream->read(b, 4) != 4) { return 0; } return OleUtil::getU4Bytes(b, 0); } fbreader-0.99.4.orig/fbreader/src/formats/doc/DocPlugin.cpp0000644000706400070640000000366012056124565022100 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include #include #include "DocPlugin.h" #include "DocMetaInfoReader.h" #include "DocBookReader.h" #include "DocStreams.h" #include "../../bookmodel/BookModel.h" #include "../../library/Book.h" DocPlugin::DocPlugin() { } DocPlugin::~DocPlugin() { } bool DocPlugin::providesMetaInfo() const { return true; } const std::string DocPlugin::supportedFileType() const { return "doc"; } bool DocPlugin::acceptsFile(const ZLFile &file) const { return file.extension() == "doc"; } bool DocPlugin::readMetaInfo(Book &book) const { if (!DocMetaInfoReader(book).readMetaInfo()) { return false; } shared_ptr stream = new DocAnsiStream(book.file(), 50000); if (!detectEncodingAndLanguage(book, *stream)) { stream = new DocUcs2Stream(book.file(), 50000); detectLanguage(book, *stream, ZLEncodingConverter::UTF8, true); } return true; } bool DocPlugin::readLanguageAndEncoding(Book &/*book*/) const { return true; } bool DocPlugin::readModel(BookModel &model) const { return DocBookReader(model, model.book()->encoding()).readBook(); } fbreader-0.99.4.orig/fbreader/src/formats/doc/DocInlineImageReader.h0000644000706400070640000000221212056124565023603 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __DOCINLINEIMAGEREADER_H__ #define __DOCINLINEIMAGEREADER_H__ #include #include "OleStream.h" class DocInlineImageReader { public: DocInlineImageReader(shared_ptr dataStream); ZLFileImage::Blocks getImagePieceInfo(unsigned int dataPos); private: shared_ptr myDataStream; }; #endif /* __DOCINLINEIMAGEREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/doc/OleStreamReader.cpp0000644000706400070640000000523212056124565023227 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "OleMainStream.h" #include "OleUtil.h" #include "OleStreamReader.h" OleStreamReader::OleStreamReader() : myNextPieceNumber(0) { } bool OleStreamReader::readDocument(shared_ptr inputStream, bool doReadFormattingData) { static const std::string WORD_DOCUMENT = "WordDocument"; shared_ptr storage = new OleStorage; if (!storage->init(inputStream, inputStream->sizeOfOpened())) { ZLLogger::Instance().println("DocPlugin", "Broken OLE file"); return false; } OleEntry wordDocumentEntry; if (!storage->getEntryByName(WORD_DOCUMENT, wordDocumentEntry)) { return false; } OleMainStream oleStream(storage, wordDocumentEntry, inputStream); if (!oleStream.open(doReadFormattingData)) { ZLLogger::Instance().println("DocPlugin", "Cannot open OleMainStream"); return false; } return readStream(oleStream); } bool OleStreamReader::readNextPiece(OleMainStream &stream) { const OleMainStream::Pieces &pieces = stream.getPieces(); if (myNextPieceNumber >= pieces.size()) { return false; } const OleMainStream::Piece &piece = pieces.at(myNextPieceNumber); if (piece.Type == OleMainStream::Piece::PIECE_FOOTNOTE) { footnotesStartHandler(); } else if (piece.Type == OleMainStream::Piece::PIECE_OTHER) { return false; } if (!stream.seek(piece.Offset, true)) { //TODO maybe in that case we should take next piece? return false; } char *textBuffer = new char[piece.Length]; std::size_t readBytes = stream.read(textBuffer, piece.Length); if (readBytes != (std::size_t)piece.Length) { ZLLogger::Instance().println("DocPlugin", "not all bytes have been read from piece"); } if (!piece.IsANSI) { for (std::size_t i = 0; i < readBytes; i += 2) { ucs2SymbolHandler(OleUtil::getU2Bytes(textBuffer, i)); } } else { ansiDataHandler(textBuffer, readBytes); } ++myNextPieceNumber; delete[] textBuffer; return true; } fbreader-0.99.4.orig/fbreader/src/formats/doc/OleStreamParser.cpp0000644000706400070640000001605312056124565023264 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ //#include //#include #include #include "OleMainStream.h" #include "OleUtil.h" #include "OleStreamParser.h" //word's control chars: const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_FOOTNOTE_MARK = 0x0002; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_TABLE_SEPARATOR = 0x0007; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_HORIZONTAL_TAB = 0x0009; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_HARD_LINEBREAK = 0x000b; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_PAGE_BREAK = 0x000c; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_END_OF_PARAGRAPH = 0x000d; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_MINUS = 0x001e; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_SOFT_HYPHEN = 0x001f; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_START_FIELD = 0x0013; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_SEPARATOR_FIELD = 0x0014; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_END_FIELD = 0x0015; const ZLUnicodeUtil::Ucs2Char OleStreamParser::WORD_ZERO_WIDTH_UNBREAKABLE_SPACE = 0xfeff; const ZLUnicodeUtil::Ucs2Char OleStreamParser::INLINE_IMAGE = 0x0001; const ZLUnicodeUtil::Ucs2Char OleStreamParser::FLOAT_IMAGE = 0x0008; //unicode values: const ZLUnicodeUtil::Ucs2Char OleStreamParser::NULL_SYMBOL = 0x0; const ZLUnicodeUtil::Ucs2Char OleStreamParser::FILE_SEPARATOR = 0x1c; const ZLUnicodeUtil::Ucs2Char OleStreamParser::LINE_FEED = 0x000a; const ZLUnicodeUtil::Ucs2Char OleStreamParser::SOFT_HYPHEN = 0xad; const ZLUnicodeUtil::Ucs2Char OleStreamParser::SPACE = 0x20; const ZLUnicodeUtil::Ucs2Char OleStreamParser::MINUS = 0x2D; const ZLUnicodeUtil::Ucs2Char OleStreamParser::VERTICAL_LINE = 0x7C; OleStreamParser::OleStreamParser() { myCurBufferPosition = 0; myCurCharPos = 0; myNextStyleInfoIndex = 0; myNextCharInfoIndex = 0; myNextBookmarkIndex = 0; myNextInlineImageInfoIndex = 0; myNextFloatImageInfoIndex = 0; } bool OleStreamParser::readStream(OleMainStream &oleMainStream) { ZLUnicodeUtil::Ucs2Char ucs2char; bool tabMode = false; while (getUcs2Char(oleMainStream, ucs2char)) { if (tabMode) { tabMode = false; if (ucs2char == WORD_TABLE_SEPARATOR) { handleTableEndRow(); continue; } else { handleTableSeparator(); } } if (ucs2char < 32) { switch (ucs2char) { case NULL_SYMBOL: break; case WORD_HARD_LINEBREAK: handleHardLinebreak(); break; case WORD_END_OF_PARAGRAPH: case WORD_PAGE_BREAK: handleParagraphEnd(); break; case WORD_TABLE_SEPARATOR: tabMode = true; break; case WORD_FOOTNOTE_MARK: handleFootNoteMark(); break; case WORD_START_FIELD: handleStartField(); break; case WORD_SEPARATOR_FIELD: handleSeparatorField(); break; case WORD_END_FIELD: handleEndField(); break; case INLINE_IMAGE: case FLOAT_IMAGE: break; default: handleOtherControlChar(ucs2char); break; } } else if (ucs2char == WORD_ZERO_WIDTH_UNBREAKABLE_SPACE) { continue; //skip } else { handleChar(ucs2char); } } return true; } bool OleStreamParser::getUcs2Char(OleMainStream &stream, ZLUnicodeUtil::Ucs2Char &ucs2char) { while (myCurBufferPosition >= myBuffer.size()) { myBuffer.clear(); myCurBufferPosition = 0; if (!readNextPiece(stream)) { return false; } } ucs2char = myBuffer.at(myCurBufferPosition++); processStyles(stream); switch (ucs2char) { case INLINE_IMAGE: processInlineImage(stream); break; case FLOAT_IMAGE: processFloatImage(stream); break; } ++myCurCharPos; return true; } void OleStreamParser::processInlineImage(OleMainStream &stream) { const OleMainStream::InlineImageInfoList &imageInfoList = stream.getInlineImageInfoList(); if (imageInfoList.empty()) { return; } //seek to curCharPos, because not all entries are real pictures while(myNextInlineImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextInlineImageInfoIndex).first < myCurCharPos) { ++myNextInlineImageInfoIndex; } while (myNextInlineImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextInlineImageInfoIndex).first == myCurCharPos) { OleMainStream::InlineImageInfo info = imageInfoList.at(myNextInlineImageInfoIndex).second; ZLFileImage::Blocks list = stream.getInlineImage(info.DataPosition); if (!list.empty()) { handleImage(list); } ++myNextInlineImageInfoIndex; } } void OleStreamParser::processFloatImage(OleMainStream &stream) { const OleMainStream::FloatImageInfoList &imageInfoList = stream.getFloatImageInfoList(); if (imageInfoList.empty()) { return; } //seek to curCharPos, because not all entries are real pictures while(myNextFloatImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextFloatImageInfoIndex).first < myCurCharPos) { ++myNextFloatImageInfoIndex; } while (myNextFloatImageInfoIndex < imageInfoList.size() && imageInfoList.at(myNextFloatImageInfoIndex).first == myCurCharPos) { OleMainStream::FloatImageInfo info = imageInfoList.at(myNextFloatImageInfoIndex).second; ZLFileImage::Blocks list = stream.getFloatImage(info.ShapeId); if (!list.empty()) { handleImage(list); } ++myNextFloatImageInfoIndex; } } void OleStreamParser::processStyles(OleMainStream &stream) { const OleMainStream::StyleInfoList &styleInfoList = stream.getStyleInfoList(); if (!styleInfoList.empty()) { while (myNextStyleInfoIndex < styleInfoList.size() && styleInfoList.at(myNextStyleInfoIndex).first == myCurCharPos) { OleMainStream::Style info = styleInfoList.at(myNextStyleInfoIndex).second; handleParagraphStyle(info); ++myNextStyleInfoIndex; } } const OleMainStream::CharInfoList &charInfoList = stream.getCharInfoList(); if (!charInfoList.empty()) { while (myNextCharInfoIndex < charInfoList.size() && charInfoList.at(myNextCharInfoIndex).first == myCurCharPos) { OleMainStream::CharInfo info = charInfoList.at(myNextCharInfoIndex).second; handleFontStyle(info.FontStyle); ++myNextCharInfoIndex; } } const OleMainStream::BookmarksList &bookmarksList = stream.getBookmarks(); if (!bookmarksList.empty()) { while (myNextBookmarkIndex < bookmarksList.size() && bookmarksList.at(myNextBookmarkIndex).CharPosition == myCurCharPos) { OleMainStream::Bookmark bookmark = bookmarksList.at(myNextBookmarkIndex); handleBookmark(bookmark.Name); ++myNextBookmarkIndex; } } } fbreader-0.99.4.orig/fbreader/src/formats/doc/DocMetaInfoReader.cpp0000644000706400070640000000232612056124565023465 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "../../library/Book.h" #include "DocMetaInfoReader.h" DocMetaInfoReader::DocMetaInfoReader(Book &book) : myBook(book) { myBook.removeAllAuthors(); myBook.setTitle(std::string()); myBook.setLanguage(std::string()); myBook.removeAllTags(); } bool DocMetaInfoReader::readMetaInfo() { myBook.removeAllAuthors(); myBook.setTitle(myBook.file().name(true)); myBook.removeAllTags(); return true; } fbreader-0.99.4.orig/fbreader/src/formats/doc/DocFloatImageReader.h0000644000706400070640000000764212056124565023446 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __DOCFLOATIMAGEREADER_H__ #define __DOCFLOATIMAGEREADER_H__ #include class DocFloatImageReader { public: struct BlipStoreEntry { // see p.68 [MS-ODRAW] unsigned int size; // size of blip in stream unsigned int referenceCount; // (cRef) reference count for the the blip unsigned int offsetInDelay; // foDelay, file offset in the delay stream }; struct Blip { //see p.59, p63-66 [MS-ODRAW] BlipStoreEntry storeEntry; unsigned int type; ZLFileImage::Blocks blocks; }; struct FSP { //see p.76-77 [MS-ODRAW] unsigned int shapeId; //spid }; struct FOPTE { //see p.98 and p.32 [MS-ODRAW] unsigned int pId; //pid bool isBlipId; //fBid bool isComplex; //fComplex unsigned int value; //op }; struct FSPContainer { //see p.53-55 [MS-ODRAW] FSP fsp; std::vector fopte; }; struct OfficeArtContent { //see p.405-406 [MS-DOC] std::vector blips; //retrieved from OfficeArtDggContainer std::vector FSPs; //retrieved from OfficeArtDgContainer }; struct RecordHeader { //see p.26 [MS-ODRAW] unsigned int version; unsigned int instance; unsigned int type; unsigned int length; }; public: DocFloatImageReader(unsigned int off, unsigned int len, shared_ptr tableStream, shared_ptr mainStream); public: void readAll(); ZLFileImage::Blocks getBlocksForShapeId(unsigned int shapeId) const; private: static unsigned int readRecordHeader(RecordHeader &header, shared_ptr stream); static unsigned int readDggContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream, shared_ptr mainStream); static unsigned int readBStoreContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream, shared_ptr mainStream); static unsigned int readBStoreContainerFileBlock(Blip &blip, shared_ptr stream, shared_ptr mainStream); static unsigned int readBlip(Blip &blip, const RecordHeader &header, shared_ptr stream); static unsigned int readFBSE(BlipStoreEntry &fbse, shared_ptr stream); static unsigned int readFOPTE(FOPTE &fopte, shared_ptr stream); static unsigned int readArrayFOPTE(std::vector &fopte, unsigned int length, shared_ptr stream); static unsigned int readFSP(FSP &fsp, shared_ptr stream); static unsigned int readSpContainter(FSPContainer &item, unsigned int length, shared_ptr stream); static unsigned int readSpgrContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream); static unsigned int readDgContainer(OfficeArtContent &item, unsigned int length, shared_ptr stream); static unsigned int skipRecord(const RecordHeader &header, shared_ptr stream); static unsigned int read1Byte(shared_ptr stream); static unsigned int read2Bytes(shared_ptr stream); static unsigned int read4Bytes(shared_ptr stream); private: shared_ptr myTableStream; shared_ptr myMainStream; unsigned int myOffset; unsigned int myLength; OfficeArtContent myItem; }; #endif /* __DOCFLOATIMAGEREADER_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/doc/DocStreams.cpp0000644000706400070640000001234212056124565022255 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include #include #include "DocStreams.h" #include "OleStreamReader.h" class DocReader : public OleStreamReader { public: DocReader(char *buffer, std::size_t maxSize); ~DocReader(); std::size_t readSize() const; private: bool readStream(OleMainStream &stream); void ansiDataHandler(const char *buffer, std::size_t len); void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); void footnotesStartHandler(); protected: char *myBuffer; const std::size_t myMaxSize; std::size_t myActualSize; }; class DocAnsiReader : public DocReader { public: DocAnsiReader(char *buffer, std::size_t maxSize); ~DocAnsiReader(); private: void ansiDataHandler(const char *buffer, std::size_t len); }; class DocUcs2Reader : public DocReader { public: DocUcs2Reader(char *buffer, std::size_t maxSize); ~DocUcs2Reader(); private: void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); }; DocReader::DocReader(char *buffer, std::size_t maxSize) : myBuffer(buffer), myMaxSize(maxSize), myActualSize(0) { } DocReader::~DocReader() { } bool DocReader::readStream(OleMainStream &stream) { // TODO make 2 optmizations: // 1) If another piece is too big, reading of next piece can be stopped if some size parameter will be specified // (it can be transfered as a parameter (with default 0 value, that means no need to use it) to readNextPiece method) // 2) We can specify as a parameter for readNextPiece, what kind of piece should be read next (ANSI or not ANSI). // As type of piece is known already, there's no necessary to read other pieces. while (myActualSize < myMaxSize) { if (!readNextPiece(stream)) { break; } } return true; } void DocReader::ansiDataHandler(const char*, std::size_t) { } void DocReader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char) { } void DocReader::footnotesStartHandler() { } std::size_t DocReader::readSize() const { return myActualSize; } DocAnsiReader::DocAnsiReader(char *buffer, std::size_t maxSize) : DocReader(buffer, maxSize) { } DocAnsiReader::~DocAnsiReader() { } void DocAnsiReader::ansiDataHandler(const char *buffer, std::size_t dataLength) { if (myActualSize < myMaxSize) { const std::size_t len = std::min(dataLength, myMaxSize - myActualSize); std::strncpy(myBuffer + myActualSize, buffer, len); myActualSize += len; } } DocUcs2Reader::DocUcs2Reader(char *buffer, std::size_t maxSize) : DocReader(buffer, maxSize) { } DocUcs2Reader::~DocUcs2Reader() { } void DocUcs2Reader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { if (myActualSize < myMaxSize) { char buffer[4]; const std::size_t dataLength = ZLUnicodeUtil::ucs2ToUtf8(buffer, symbol); const std::size_t len = std::min(dataLength, myMaxSize - myActualSize); std::strncpy(myBuffer + myActualSize, buffer, len); myActualSize += len; } } DocStream::DocStream(const ZLFile& file, std::size_t maxSize) : myFile(file), myBuffer(0), mySize(maxSize) { } DocStream::~DocStream() { close(); } bool DocStream::open() { if (mySize != 0) { myBuffer = new char[mySize]; } shared_ptr reader = createReader(myBuffer, mySize); shared_ptr stream = myFile.inputStream(); if (stream.isNull() || !stream->open()) { return false; } if (!reader->readDocument(stream, false)) { return false; } mySize = reader->readSize(); myOffset = 0; return true; } std::size_t DocStream::read(char *buffer, std::size_t maxSize) { maxSize = std::min(maxSize, mySize - myOffset); if (buffer != 0 && myBuffer != 0) { std::memcpy(buffer, myBuffer + myOffset, maxSize); } myOffset += maxSize; return maxSize; } void DocStream::close() { if (myBuffer != 0) { delete[] myBuffer; myBuffer = 0; } } void DocStream::seek(int offset, bool absoluteOffset) { if (!absoluteOffset) { offset += myOffset; } myOffset = std::min(mySize, (std::size_t)std::max(0, offset)); } std::size_t DocStream::offset() const { return myOffset; } std::size_t DocStream::sizeOfOpened() { return mySize; } DocAnsiStream::DocAnsiStream(const ZLFile& file, std::size_t maxSize) : DocStream(file, maxSize) { } DocAnsiStream::~DocAnsiStream() { } shared_ptr DocAnsiStream::createReader(char *buffer, std::size_t maxSize) { return new DocAnsiReader(buffer, maxSize); } DocUcs2Stream::DocUcs2Stream(const ZLFile& file, std::size_t maxSize) : DocStream(file, maxSize) { } DocUcs2Stream::~DocUcs2Stream() { } shared_ptr DocUcs2Stream::createReader(char *buffer, std::size_t maxSize) { return new DocUcs2Reader(buffer, maxSize); } fbreader-0.99.4.orig/fbreader/src/formats/doc/OleStorage.h0000644000706400070640000000476412056124565021733 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __OLESTORAGE_H__ #define __OLESTORAGE_H__ #include #include #include #include struct OleEntry { enum Type { DIR = 1, STREAM = 2, ROOT_DIR = 5, LOCK_BYTES =3 }; typedef std::vector Blocks; std::string name; unsigned int length; Type type; Blocks blocks; bool isBigBlock; }; class OleStorage { public: static const std::size_t BBD_BLOCK_SIZE; public: OleStorage(); bool init(shared_ptr, std::size_t streamSize); void clear(); const std::vector &getEntries() const; bool getEntryByName(std::string name, OleEntry &entry) const; unsigned int getSectorSize() const; unsigned int getShortSectorSize() const; public: //TODO make private bool countFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber, unsigned int &result) const; private: bool readDIFAT(char *oleBuf); bool readBBD(char *oleBuf); bool readSBD(char *oleBuf); bool readProperties(char *oleBuf); bool readAllEntries(); bool readOleEntry(int propNumber, OleEntry &entry); private: shared_ptr myInputStream; unsigned int mySectorSize, myShortSectorSize; std::size_t myStreamSize; std::vector myDIFAT; //double-indirect file allocation table std::vector myBBD; //Big Block Depot std::vector mySBD; //Small Block Depot std::vector myProperties; std::vector myEntries; int myRootEntryIndex; }; inline const std::vector &OleStorage::getEntries() const { return myEntries; } inline unsigned int OleStorage::getSectorSize() const { return mySectorSize; } inline unsigned int OleStorage::getShortSectorSize() const { return myShortSectorSize; } #endif /* __OLESTORAGE_H__ */ fbreader-0.99.4.orig/fbreader/src/formats/doc/OleStream.cpp0000644000706400070640000001560312056124565022107 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #include #include "OleStream.h" #include "OleUtil.h" OleStream::OleStream(shared_ptr storage, OleEntry oleEntry, shared_ptr stream) : myStorage(storage), myOleEntry(oleEntry), myBaseStream(stream) { myOleOffset = 0; } bool OleStream::open() { if (myOleEntry.type != OleEntry::STREAM) { return false; } return true; } std::size_t OleStream::read(char *buffer, std::size_t maxSize) { std::size_t length = maxSize; std::size_t readedBytes = 0; std::size_t bytesLeftInCurBlock; unsigned int newFileOffset; unsigned int curBlockNumber, modBlock; std::size_t toReadBlocks, toReadBytes; if (myOleOffset + length > myOleEntry.length) { length = myOleEntry.length - myOleOffset; } std::size_t sectorSize = (std::size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); curBlockNumber = myOleOffset / sectorSize; if (curBlockNumber >= myOleEntry.blocks.size()) { return 0; } modBlock = myOleOffset % sectorSize; bytesLeftInCurBlock = sectorSize - modBlock; if (bytesLeftInCurBlock < length) { toReadBlocks = (length - bytesLeftInCurBlock) / sectorSize; toReadBytes = (length - bytesLeftInCurBlock) % sectorSize; } else { toReadBlocks = toReadBytes = 0; } if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { return 0; } newFileOffset += modBlock; myBaseStream->seek(newFileOffset, true); readedBytes = myBaseStream->read(buffer, std::min(length, bytesLeftInCurBlock)); for (std::size_t i = 0; i < toReadBlocks; ++i) { if (++curBlockNumber >= myOleEntry.blocks.size()) { break; } if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { return readedBytes; } myBaseStream->seek(newFileOffset, true); readedBytes += myBaseStream->read(buffer + readedBytes, std::min(length - readedBytes, sectorSize)); } if (toReadBytes > 0 && ++curBlockNumber < myOleEntry.blocks.size()) { if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { return readedBytes; } myBaseStream->seek(newFileOffset, true); readedBytes += myBaseStream->read(buffer + readedBytes, toReadBytes); } myOleOffset += readedBytes; return readedBytes; } bool OleStream::eof() const { return (myOleOffset >= myOleEntry.length); } void OleStream::close() { } bool OleStream::seek(unsigned int offset, bool absoluteOffset) { unsigned int newOleOffset = 0; unsigned int newFileOffset; if (absoluteOffset) { newOleOffset = offset; } else { newOleOffset = myOleOffset + offset; } newOleOffset = std::min(newOleOffset, myOleEntry.length); unsigned int sectorSize = (myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); unsigned int blockNumber = newOleOffset / sectorSize; if (blockNumber >= myOleEntry.blocks.size()) { return false; } unsigned int modBlock = newOleOffset % sectorSize; if (!myStorage->countFileOffsetOfBlock(myOleEntry, blockNumber, newFileOffset)) { return false; } newFileOffset += modBlock; myBaseStream->seek(newFileOffset, true); myOleOffset = newOleOffset; return true; } std::size_t OleStream::offset() { return myOleOffset; } ZLFileImage::Blocks OleStream::getBlockPieceInfoList(unsigned int offset, unsigned int size) const { ZLFileImage::Blocks list; unsigned int sectorSize = (myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); unsigned int curBlockNumber = offset / sectorSize; if (curBlockNumber >= myOleEntry.blocks.size()) { return list; } unsigned int modBlock = offset % sectorSize; unsigned int startFileOffset = 0; if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, startFileOffset)) { return ZLFileImage::Blocks(); } startFileOffset += modBlock; unsigned int bytesLeftInCurBlock = sectorSize - modBlock; unsigned int toReadBlocks = 0, toReadBytes = 0; if (bytesLeftInCurBlock < size) { toReadBlocks = (size - bytesLeftInCurBlock) / sectorSize; toReadBytes = (size - bytesLeftInCurBlock) % sectorSize; } unsigned int readedBytes = std::min(size, bytesLeftInCurBlock); list.push_back(ZLFileImage::Block(startFileOffset, readedBytes)); for (unsigned int i = 0; i < toReadBlocks; ++i) { if (++curBlockNumber >= myOleEntry.blocks.size()) { break; } unsigned int newFileOffset = 0; if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { return ZLFileImage::Blocks(); } unsigned int readbytes = std::min(size - readedBytes, sectorSize); list.push_back(ZLFileImage::Block(newFileOffset, readbytes)); readedBytes += readbytes; } if (toReadBytes > 0 && ++curBlockNumber < myOleEntry.blocks.size()) { unsigned int newFileOffset = 0; if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { return ZLFileImage::Blocks(); } unsigned int readbytes = toReadBytes; list.push_back(ZLFileImage::Block(newFileOffset, readbytes)); readedBytes += readbytes; } return concatBlocks(list); } ZLFileImage::Blocks OleStream::concatBlocks(const ZLFileImage::Blocks &blocks) { if (blocks.size() < 2) { return blocks; } ZLFileImage::Blocks optList; ZLFileImage::Block curBlock = blocks.at(0); unsigned int nextOffset = curBlock.offset + curBlock.size; for (std::size_t i = 1; i < blocks.size(); ++i) { ZLFileImage::Block b = blocks.at(i); if (b.offset == nextOffset) { curBlock.size += b.size; nextOffset += b.size; } else { optList.push_back(curBlock); curBlock = b; nextOffset = curBlock.offset + curBlock.size; } } optList.push_back(curBlock); return optList; } std::size_t OleStream::fileOffset() { //TODO maybe remove this method, it doesn't use at this time std::size_t sectorSize = (std::size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); unsigned int curBlockNumber = myOleOffset / sectorSize; if (curBlockNumber >= myOleEntry.blocks.size()) { return 0; } unsigned int modBlock = myOleOffset % sectorSize; unsigned int curOffset = 0; if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, curOffset)) { return 0; //TODO maybe remove -1? } return curOffset + modBlock; } fbreader-0.99.4.orig/fbreader/src/formats/doc/OleMainStream.h0000644000706400070640000001570312056124565022362 0ustar bagebage/* * Copyright (C) 2004-2012 Geometer Plus * * 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. */ #ifndef __OLEMAINSTREAM_H__ #define __OLEMAINSTREAM_H__ #include #include #include "OleStream.h" #include "DocFloatImageReader.h" class OleMainStream : public OleStream { public: struct Piece { enum PieceType { PIECE_TEXT, PIECE_FOOTNOTE, PIECE_OTHER }; int Offset; // TODO: maybe make it unsigned int int Length; // TODO: maybe make it unsigned int bool IsANSI; PieceType Type; unsigned int startCP; }; typedef std::vector Pieces; struct CharInfo { enum Font { FONT_REGULAR = 0, FONT_BOLD = 1 << 0, FONT_ITALIC = 1 << 1, FONT_UNDERLINE = 1 << 2, FONT_CAPITALS = 1 << 3, FONT_SMALL_CAPS = 1 << 4, FONT_STRIKE = 1 << 5, FONT_HIDDEN = 1 << 6, FONT_MARKDEL = 1 << 7, FONT_SUPERSCRIPT = 1 << 8, FONT_SUBSCRIPT = 1 << 9 }; unsigned int FontStyle; unsigned int FontSize; CharInfo(); }; typedef std::pair CharPosToCharInfo; typedef std::vector CharInfoList; struct Style { enum AlignmentType { ALIGNMENT_LEFT = 0x00, ALIGNMENT_CENTER = 0x01, ALIGNMENT_RIGHT = 0x02, ALIGNMENT_JUSTIFY = 0x03, ALIGNMENT_DEFAULT // for case if alignment is not setted by word }; // style Ids: // (this is not full list of possible style ids, enum is used for using in switch-case) enum StyleID { STYLE_H1 = 0x1, STYLE_H2 = 0x2, STYLE_H3 = 0x3, STYLE_USER = 0xFFE, STYLE_NIL = 0xFFF, STYLE_INVALID = 0xFFFF }; unsigned int StyleIdCurrent; unsigned int StyleIdNext; // Next style unless overruled bool HasPageBreakBefore; unsigned int BeforeParagraphIndent; // Vertical indent before paragraph, pixels unsigned int AfterParagraphIndent; // Vertical indent after paragraph, pixels int LeftIndent; int FirstLineIndent; int RightIndent; AlignmentType Alignment; CharInfo CurrentCharInfo; Style(); }; typedef std::pair CharPosToStyle; typedef std::vector StyleInfoList; typedef std::vector