diff --git a/README b/README
index 71ea91c..770e669 100644
--- a/README
+++ b/README
@@ -37,12 +37,9 @@ DIRECTORIES
``bin/``
Useful tools based on Origami.
- ``tests/``
+ ``test/``
Test case units.
- ``doc/``
- Automated RubyDoc HTML documentation.
-
HOMEPAGE
http://aslr.fr/pages/Origami
@@ -57,6 +54,10 @@ LICENSE
This software is distributed under the LGPL license.
See the COPYING.LESSER file for more details.
+ Exception is for the PDF Walker graphical interface located in subdirectory
+ bin/gui, which is distributed under the GPL license.
+ See bin/gui/COPYING file for more details.
+
NOTES
It contains many bugs and many incomplete features. If you encounter a
diff --git a/bin/gui/COPYING b/bin/gui/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/bin/gui/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. 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
+them 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 prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. 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.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey 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;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU 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 that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ 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.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+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.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ 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
+state 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 3 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, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program 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, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/bin/gui/about.rb b/bin/gui/about.rb
index 122ed73..259559c 100644
--- a/bin/gui/about.rb
+++ b/bin/gui/about.rb
@@ -4,22 +4,22 @@
about.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
@@ -34,9 +34,9 @@ def about
:name => "PDF Walker",
:program_name => "PDF Walker",
:version => Origami::VERSION,
- :copyright => "Copyright (C) 2010\nGuillaume Delugre, Sogeti-ESEC R&D \nAll right reserved.",
+ :copyright => "Copyright (C) 2010\nGuillaume Delugre \nAll right reserved.",
:comments => "A graphical PDF parser front-end",
- :license => File.read("#{File.dirname(__FILE__)}/../../COPYING.LESSER")
+ :license => File.read("#{File.dirname(__FILE__)}/COPYING")
})
end
diff --git a/bin/gui/config.rb b/bin/gui/config.rb
index 6bdda7a..a1366f8 100644
--- a/bin/gui/config.rb
+++ b/bin/gui/config.rb
@@ -4,22 +4,22 @@
config.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/file.rb b/bin/gui/file.rb
index 0bd0c33..381df81 100644
--- a/bin/gui/file.rb
+++ b/bin/gui/file.rb
@@ -4,22 +4,22 @@
file.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/gtkhex.rb b/bin/gui/gtkhex.rb
new file mode 100644
index 0000000..ad2bb38
--- /dev/null
+++ b/bin/gui/gtkhex.rb
@@ -0,0 +1,1341 @@
+=begin
+
+= File
+ gtkhex.rb
+
+= Info
+ This file is part of PDF Walker, a graphical PDF file browser
+ Copyright (C) 2010 Guillaume Delugré
+ All right reserved.
+
+ PDF Walker 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 3 of the License, or
+ (at your option) any later version.
+
+ PDF Walker 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 PDF Walker. If not, see .
+
+ This work has been derived from the GHex project. Thanks to them.
+ Original implementation: Jaka Mocnik
+=end
+
+require 'gtk2'
+
+module Gtk
+
+ class HexEditor < Fixed
+ module View
+ HEX = 1
+ ASCII = 2
+ end
+
+ module Group
+ BYTE = 1
+ WORD = 2
+ LONG = 4
+ end
+
+ class Highlight
+ attr_accessor :start, :end
+ attr_accessor :start_line, :end_line
+ attr_accessor :style
+ attr_accessor :min_select
+ attr_accessor :valid
+ end
+
+ class AutoHighlight
+ attr_accessor :search_view
+ attr_accessor :search_string
+ attr_accessor :search_len
+
+ attr_accessor :color
+
+ attr_accessor :view_min
+ attr_accessor :view_max
+
+ attr_accessor :highlights
+ end
+
+ DEFAULT_FONT = "Monospace 12"
+ DEFAULT_CPL = 32
+ DEFAULT_LINES = 16
+ DISPLAY_BORDER = 4
+ SCROLL_TIMEOUT = 100
+
+ type_register
+
+ @@primary = Clipboard.get(Gdk::Selection::PRIMARY)
+ @@clipboard = Clipboard.get(Gdk::Selection::CLIPBOARD)
+
+ def initialize(data = '')
+ super()
+
+ @data = data
+ if RUBY_VERSION >= '1.9'
+ @data.force_encoding('binary')
+ end
+
+ @scroll_timeout = -1
+ @disp_buffer = ""
+ @starting_offset = 0
+
+ @xdisp_width = @adisp_width = 200
+ @xdisp_gc = @adisp_gc = nil
+ @active_view = View::HEX
+ @group_type = Group::BYTE
+ @lines = @vis_lines = @top_line = @cpl = 0
+ @cursor_pos = 0
+ @lower_nibble = false
+ @cursor_shown = false
+ @button = 0
+ @insert = false
+ @selecting = false
+
+ @selection = Highlight.new
+ @selection.start = @selection.end = 0
+ @selection.style = nil
+ @selection.min_select = 1
+ @selection.valid = false
+
+ @highlights = [ @selection ]
+
+ @auto_highlight = nil
+
+ @disp_font_metrics = load_font DEFAULT_FONT
+ @font_desc = Pango::FontDescription.new DEFAULT_FONT
+
+ @char_width = get_max_char_width(@disp_font_metrics)
+ @char_height = Pango.pixels(@disp_font_metrics.ascent) + Pango.pixels(@disp_font_metrics.descent) + 2
+
+ self.can_focus = true
+ self.events = Gdk::Event::KEY_PRESS_MASK
+ self.border_width = DISPLAY_BORDER
+
+ mouse_handler = lambda do |widget, event|
+ if event.event_type == Gdk::Event::BUTTON_RELEASE and event.button == 1
+ if @scroll_timeout
+ GLib::Source.remove @scroll_timeout
+ @scroll_timeout = nil
+ @scroll_dir = 0
+ end
+
+ @selecting = false
+ Gtk.grab_remove(widget)
+ @button = 0
+ elsif event.event_type == Gdk::Event::BUTTON_PRESS and event.button == 1
+ self.grab_focus unless self.has_focus?
+
+ Gtk.grab_add(widget)
+ @button = event.button
+
+ focus_view = (widget == @xdisp) ? View::HEX : View::ASCII
+
+ if @active_view == focus_view
+ if @active_view == View::HEX
+ hex_to_pointer(event.x, event.y)
+ else
+ ascii_to_pointer(event.x, event.y)
+ end
+
+ unless @selecting
+ @selecting = true
+ set_selection(@cursor_pos, @cursor_pos)
+ end
+ else
+ hide_cursor
+ @active_view = focus_view
+ show_cursor
+ end
+ elsif event.event_type == Gdk::Event::BUTTON_PRESS and event.button == 2
+ # TODO
+ else
+ @button = 0
+ end
+ end
+
+ @xdisp = DrawingArea.new
+ @xdisp.modify_font @font_desc
+ @xlayout = @xdisp.create_pango_layout('')
+ @xdisp.events =
+ Gdk::Event::EXPOSURE_MASK |
+ Gdk::Event::BUTTON_PRESS_MASK |
+ Gdk::Event::BUTTON_RELEASE_MASK |
+ Gdk::Event::BUTTON_MOTION_MASK |
+ Gdk::Event::SCROLL_MASK
+
+ @xdisp.signal_connect 'realize' do
+ @xdisp_gc = Gdk::GC.new(@xdisp.window)
+ @xdisp_gc.set_exposures(true)
+ end
+
+ @xdisp.signal_connect 'expose_event' do |xdisp, event|
+ imin = (event.area.y / @char_height).to_i
+ imax = ((event.area.y + event.area.height) / @char_height).to_i
+ imax += 1 if (event.area.y + event.area.height).to_i % @char_height != 0
+
+ imax = [ imax, @vis_lines ].min
+
+ render_hex_lines(imin, imax)
+ end
+
+ @xdisp.signal_connect 'scroll_event' do |xdisp, event|
+ @scrollbar.event(event)
+ end
+
+ @xdisp.signal_connect 'button_press_event' do |xdisp, event|
+ mouse_handler[xdisp, event]
+ end
+
+ @xdisp.signal_connect 'button_release_event' do |xdisp, event|
+ mouse_handler[xdisp, event]
+ end
+
+ @xdisp.signal_connect 'motion_notify_event' do |xdisp, event|
+ w, x, y, m = xdisp.window.pointer
+
+ if y < 0
+ @scroll_dir = -1
+ elsif y >= xdisp.allocation.height
+ @scroll_dir = 1
+ else
+ @scroll_dir = 0
+ end
+
+ if @scroll_dir != 0
+ if @scroll_timeout == nil
+ @scroll_timeout = GLib::Timeout.add(SCROLL_TIMEOUT) {
+ if @scroll_dir < 0
+ set_cursor([ 0, @cursor_pos - @cpl ].max)
+ elsif @scroll_dir > 0
+ set_cursor([ @data.size - 1, @cursor_pos + @cpl ].min)
+ end
+
+ true
+ }
+ next
+ end
+ else
+ if @scroll_timeout != nil
+ GLib::Source.remove @scroll_timeout
+ @scroll_timeout = nil
+ end
+ end
+
+ next if event.window != xdisp.window
+
+ hex_to_pointer(x,y) if @active_view == View::HEX and @button == 1
+ end
+
+ put @xdisp, 0, 0
+ @xdisp.show
+
+ @adisp = DrawingArea.new
+ @adisp.modify_font @font_desc
+ @alayout = @adisp.create_pango_layout('')
+ @adisp.events =
+ Gdk::Event::EXPOSURE_MASK |
+ Gdk::Event::BUTTON_PRESS_MASK |
+ Gdk::Event::BUTTON_RELEASE_MASK |
+ Gdk::Event::BUTTON_MOTION_MASK |
+ Gdk::Event::SCROLL_MASK
+
+
+ @adisp.signal_connect 'realize' do
+ @adisp_gc = Gdk::GC.new(@adisp.window)
+ @adisp_gc.set_exposures(true)
+ end
+
+ @adisp.signal_connect 'expose_event' do |adisp, event|
+ imin = (event.area.y / @char_height).to_i
+ imax = ((event.area.y + event.area.height) / @char_height).to_i
+ imax += 1 if (event.area.y + event.area.height).to_i % @char_height != 0
+
+ imax = [ imax, @vis_lines ].min
+ render_ascii_lines(imin, imax)
+ end
+
+ @adisp.signal_connect 'scroll_event' do |adisp, event|
+ @scrollbar.event(event)
+ end
+
+ @adisp.signal_connect 'button_press_event' do |adisp, event|
+ mouse_handler[adisp, event]
+ end
+
+ @adisp.signal_connect 'button_release_event' do |adisp, event|
+ mouse_handler[adisp, event]
+ end
+
+ @adisp.signal_connect 'motion_notify_event' do |adisp, event|
+ w, x, y, m = adisp.window.pointer
+
+ if y < 0
+ @scroll_dir = -1
+ elsif y >= adisp.allocation.height
+ @scroll_dir = 1
+ else
+ @scroll_dir = 0
+ end
+
+ if @scroll_dir != 0
+ if @scroll_timeout == nil
+ @scroll_timeout = GLib::Timeout.add(SCROLL_TIMEOUT) {
+ if @scroll_dir < 0
+ set_cursor([ 0, @cursor_pos - @cpl ].max)
+ elsif @scroll_dir > 0
+ set_cursor([ @data.size - 1, @cursor_pos + @cpl ].min)
+ end
+
+ true
+ }
+ next
+ end
+ else
+ if @scroll_timeout != nil
+ GLib::Source.remove @scroll_timeout
+ @scroll_timeout = nil
+ end
+ end
+
+ next if event.window != adisp.window
+
+ ascii_to_pointer(x,y) if @active_view == View::ASCII and @button == 1
+ end
+
+ put @adisp, 0, 0
+ @adisp.show
+
+ @adj = Gtk::Adjustment.new(0, 0, 0, 0, 0, 0)
+ @scrollbar = VScrollbar.new(@adj)
+ @adj.signal_connect 'value_changed' do |adj|
+ unless @xdisp_gc.nil? or @adisp_gc.nil? or not @xdisp.drawable? or not @adisp.drawable?
+
+ source_min = (adj.value.to_i - @top_line) * @char_height
+ source_max = source_min + @xdisp.allocation.height
+ dest_min = 0
+ dest_max = @xdisp.allocation.height
+
+ rect = Gdk::Rectangle.new(0, 0, 0, 0)
+ @top_line = adj.value.to_i
+ if source_min < 0
+ rect.y = 0
+ rect.height = -source_min
+ rect_height = [ rect.height, @xdisp.allocation.height ].min
+ source_min = 0
+ dest_min = rect.height
+ else
+ rect.y = 2 * @xdisp.allocation.height - source_max
+ rect.y = 0 if rect.y < 0
+ rect.height = @xdisp.allocation.height - rect.y
+ source_max = @xdisp.allocation.height
+ dest_max = rect.y
+ end
+
+ if source_min != source_max
+ @xdisp.window.draw_drawable(
+ @xdisp_gc,
+ @xdisp.window,
+ 0, source_min,
+ 0, dest_min,
+ @xdisp.allocation.width,
+ source_max - source_min
+ )
+ @adisp.window.draw_drawable(
+ @adisp_gc,
+ @adisp.window,
+ 0, source_min,
+ 0, dest_min,
+ @adisp.allocation.width,
+ source_max - source_min
+ )
+
+ if @offsets
+ if @offsets_gc.nil?
+ @offsets_gc = Gdk::GC.new(@offsets.window)
+ @offsets_gc.set_exposures(true)
+ end
+
+ @offsets.window.draw_drawable(
+ @offsets_gc,
+ @offsets.window,
+ 0, source_min,
+ 0, dest_min,
+ @offsets.allocation.width,
+ source_max - source_min
+ )
+ end
+
+ # TODO update_all_auto_highlights(true, true)
+ invalidate_all_highlights
+
+ rect.width = @xdisp.allocation.width
+ @xdisp.window.invalidate(rect, false)
+ rect.width = @adisp.allocation.width
+ @adisp.window.invalidate(rect, false)
+
+ if @offsets
+ rect.width = @offsets.allocation.width
+ @offsets.window.invalidate(rect, false)
+ end
+ end
+ end
+ end
+
+ put @scrollbar, 0, 0
+ @scrollbar.show
+ end
+
+ def set_selection(s, e)
+ e = [ e, @data.size ].min
+
+ @@primary.clear if @selection.start != @selection.end
+
+ os, oe = [ @selection.start, @selection.end ].sort
+
+ @selection.start = [ 0, s ].max
+ @selection.start = [ @selection.start, @data.size ].min
+ @selection.end = [ e, @data.size ].min
+
+ invalidate_highlight(@selection)
+
+ ns, ne = [ @selection.start, @selection.end ].sort
+
+ if ns != os and ne != oe
+ bytes_changed([ns, os].min, [ne, oe].max)
+ elsif ne != oe
+ bytes_changed(*[ne, oe].sort)
+ elsif ns != os
+ bytes_changed(*[ns, os].sort)
+ end
+
+ if @selection.start != @selection.end
+ if @active_view == View::HEX
+ brk_len = 2 * @cpl + @cpl / @group_type
+ format_xblock(s,e)
+ (@disp_buffer.size / brk_len + 1).times do |i| @disp_buffer.insert(i * (brk_len + 1), $/) end
+ else
+ brk_len = @cpl
+ format_ablock(s,e)
+ end
+
+ @@primary.set_text(@disp_buffer)
+ end
+ end
+
+ def get_selection
+ [ @selection.start, @selection.end ].sort
+ end
+
+ def clear_selection
+ set_selection(0, 0)
+ end
+
+ def cursor
+ @cursor_pos
+ end
+
+ def set_cursor(index)
+ return if index < 0 or index > @data.size
+
+ old_pos = @cursor_pos
+ index -= 1 if @insert and index == @data.size
+ index = [ 0, index ].max
+
+ hide_cursor
+
+ @cursor_pos = index
+ return if @cpl == 0
+
+ y = index / @cpl
+ if y >= @top_line + @vis_lines
+ @adj.value = [ y - @vis_lines + 1, @lines - @vis_lines ].min
+ @adj.value = [ 0, @adj.value ].max
+ @adj.signal_emit 'value_changed'
+ elsif y < @top_line
+ @adj.value = y
+ @adj.signal_emit 'value_changed'
+ end
+
+ @lower_nibble = false if index == @data.size
+
+ if @selecting
+ set_selection(@selection.start, @cursor_pos)
+ bytes_changed(*[@cursor_pos, old_pos].sort)
+ else# @selection.start != @selection.end
+ s, e = [@selection.start, @selection.end].sort
+ @selection.end = @selection.start = @cursor_pos
+ bytes_changed(s, e)
+ end
+
+ self.signal_emit 'cursor_moved'
+
+ bytes_changed(old_pos, old_pos)
+ show_cursor
+ end
+
+ def set_cursor_xy(x, y)
+ pos = y.to_i * @cpl + x.to_i
+ return if y < 0 or y >= @lines or x < 0 or x >= @cpl or pos > @data.size
+
+ set_cursor(pos)
+ end
+
+ def set_cursor_on_lower_nibble(bool)
+ if @selecting
+ bytes_changed(@cursor_pos, @cursor_pos)
+ @lower_nibble = bool
+ elsif @selection.start != @selection.end
+ s, e = [ @selection.start, @selection.end ].sort
+
+ @selection.start = @selection.end = 0
+ bytes_changed(s, e)
+ @lower_nibble = bool
+ else
+ hide_cursor
+ @lower_nibble = bool
+ show_cursor
+ end
+ end
+
+ def set_group_type(type)
+ hide_cursor
+ @group_type = type
+ recalc_displays(self.allocation.width, self.allocation.height)
+ self.queue_resize
+ show_cursor
+ end
+
+ def show_offsets(bool)
+ return unless @show_offsets ^ bool
+
+ @show_offsets = bool
+ if bool
+ show_offsets_widget
+ else
+ hide_offsets_widget
+ end
+ end
+
+ def set_font(fontname)
+ @font_desc = Pango::FontDescription.new(fontname)
+ @disp_font_metrics = load_font(fontname)
+
+ @xdisp.modify_font(@font_desc) if @xdisp
+ @adisp.modify_font(@font_desc) if @adisp
+ @offsets.modify_font(@font_desc) if @offsets
+
+ @char_width = get_max_char_width(@disp_font_metrics)
+ @char_height = Pango.pixels(@disp_font_metrics.ascent) + Pango.pixels(@disp_font_metrics.descent) + 2
+ recalc_displays(self.allocation.width, self.allocation.height)
+
+ redraw_widget
+ end
+
+ def set_data(data)
+ prev_data_size = @data.size
+ @data = data.dup
+
+ recalc_displays(self.allocation.width, self.allocation.height)
+
+ set_cursor 0
+ bytes_changed(0, [ prev_data_size, @data.size ].max)
+ redraw_widget
+ end
+
+ def validate_highlight(hl)
+ unless hl.valid
+ hl.start_line = [ hl.start, hl.end ].min / @cpl - @top_line
+ hl.end_line = [ hl.start, hl.end ].max / @cpl - @top_line
+ hl.valid = true
+ end
+ end
+
+ def invalidate_highlight(hl)
+ hl.valid = false
+ end
+
+ def invalidate_all_highlights
+ @highlights.each do |hl| invalidate_highlight(hl) end
+ end
+
+ private
+
+ signal_new(
+ 'data_changed',
+ GLib::Signal::RUN_FIRST,
+ nil,
+ nil,
+ String
+ )
+
+ signal_new(
+ 'cursor_moved',
+ GLib::Signal::RUN_FIRST,
+ nil,
+ nil
+ )
+
+ def signal_do_cursor_moved
+ end
+
+ def signal_do_data_changed(data)
+ # TODO
+ end
+
+ def signal_do_realize
+ super
+
+ self.window.set_back_pixmap(nil, true)
+ end
+
+ def signal_do_size_allocate(alloc)
+ hide_cursor
+
+ recalc_displays(alloc.width, alloc.height)
+
+ self.set_allocation(alloc.x, alloc.y, alloc.width, alloc.height)
+ self.window.move_resize(
+ alloc.x, alloc.y,
+ alloc.width, alloc.height
+ ) if self.realized?
+
+ bw = self.border_width
+ xt = widget_get_xt
+ yt = widget_get_yt
+
+ my_alloc = Gtk::Allocation.new(0, 0, 0, 0)
+ my_alloc.x = bw + xt
+ my_alloc.y = bw + yt
+ my_alloc.height = [ alloc.height - 2*bw - 2*yt, 1 ].max
+ if @show_offsets
+ my_alloc.width = 8 * @char_width
+ @offsets.size_allocate(my_alloc)
+ @offsets.queue_draw
+ my_alloc.x += 2*xt + my_alloc.width
+ end
+
+ my_alloc.width = @xdisp_width
+ @xdisp.size_allocate(my_alloc)
+
+ my_alloc.x = alloc.width - bw - @scrollbar.requisition[0]
+ my_alloc.y = bw
+ my_alloc.width = @scrollbar.requisition[0]
+ my_alloc.height = [ alloc.height - 2*bw, 1 ].max
+ @scrollbar.size_allocate(my_alloc)
+
+ my_alloc.x -= @adisp_width + xt
+ my_alloc.y = bw + yt
+ my_alloc.width = @adisp_width
+ my_alloc.height = [ alloc.height - 2*bw - 2*yt, 1 ].max
+ @adisp.size_allocate(my_alloc)
+
+ show_cursor
+ end
+
+ def signal_do_size_request(req)
+ sb_width, sb_height = @scrollbar.size_request
+ bw = self.border_width
+ xt, yt = widget_get_xt, widget_get_yt
+
+ width = 4*xt + 2*bw + sb_width +
+ @char_width*(DEFAULT_CPL + (DEFAULT_CPL-1)/@group_type)
+
+ width += 2*xt + 8*@char_width if @show_offsets
+
+ height = DEFAULT_LINES * @char_height + 2*yt + 2*bw
+
+ req[0] = width
+ req[1] = height
+ end
+
+ def signal_do_expose_event(event)
+ draw_shadow(event.area)
+ super(event)
+
+ true
+ end
+
+ def signal_do_key_press_event(event)
+ old_cp = @cursor_pos
+
+ hide_cursor
+ @selecting = (event.state & Gdk::Window::SHIFT_MASK) != 0
+ ret = true
+
+ case event.keyval
+ when Gdk::Keyval::GDK_KP_Tab, Gdk::Keyval::GDK_Tab
+ @active_view = (@active_view == View::HEX) ? View::ASCII : View::HEX
+
+ when Gdk::Keyval::GDK_Up
+ set_cursor(@cursor_pos - @cpl)
+
+ when Gdk::Keyval::GDK_Down
+ set_cursor(@cursor_pos + @cpl)
+
+ when Gdk::Keyval::GDK_Page_Up
+ set_cursor([0, @cursor_pos - @vis_lines * @cpl].max)
+
+ when Gdk::Keyval::GDK_Page_Down
+ set_cursor([@cursor_pos + @vis_lines * @cpl, @data.size].min)
+
+ when Gdk::Keyval::GDK_Left
+ if @active_view == View::HEX
+ if @selecting
+ set_cursor(@cursor_pos - 1)
+ else
+ @lower_nibble ^= 1
+ set_cursor(@cursor_pos - 1) if @lower_nibble
+ end
+ else
+ set_cursor(@cursor_pos - 1)
+ end
+
+ when Gdk::Keyval::GDK_Right
+ if @active_view == View::HEX
+ if @selecting
+ set_cursor(@cursor_pos + 1)
+ else
+ @lower_nibble ^= 1
+ set_cursor(@cursor_pos + 1) unless @lower_nibble
+ end
+ else
+ set_cursor(@cursor_pos + 1)
+ end
+
+ when Gdk::Keyval::GDK_c, Gdk::Keyval::GDK_C
+ if event.state & Gdk::Window::CONTROL_MASK != 0
+ s,e = @selection.start, @selection.end + 1
+ if @active_view == View::HEX
+ brk_len = 2 * @cpl + @cpl / @group_type
+ format_xblock(s,e)
+ (@disp_buffer.size / brk_len + 1).times do |i| @disp_buffer.insert(i * (brk_len + 1), $/) end
+ else
+ brk_len = @cpl
+ format_ablock(s,e)
+ end
+
+ @@clipboard.set_text(@disp_buffer)
+ end
+ else
+ ret = false
+ end
+
+ show_cursor
+
+ ret
+ end
+
+ def hex_to_pointer(mx, my)
+ cy = @top_line + my.to_i / @char_height
+
+ cx = x = 0
+ while cx < 2 * @cpl
+ x += @char_width
+
+ if x > mx
+ set_cursor_xy(cx / 2, cy)
+ set_cursor_on_lower_nibble(cx % 2 != 0)
+
+ cx = 2 * @cpl
+ end
+
+ cx += 1
+ x += @char_width if ( cx % (2 * @group_type) == 0 )
+ end
+ end
+
+ def ascii_to_pointer(mx, my)
+ cx = mx / @char_width
+ cy = @top_line + my / @char_height
+
+ set_cursor_xy(cx, cy)
+ end
+
+ def load_font(fontname)
+ desc = Pango::FontDescription.new(fontname)
+ context = Gdk::Pango.context
+ context.set_language(Gtk.default_language)
+
+ font = context.load_font(desc)
+
+ font.metrics(context.language)
+ end
+
+ def draw_shadow(area)
+ bw = self.border_width
+ x = bw
+ xt = widget_get_xt
+
+ if @show_offsets
+ self.style.paint_shadow(
+ self.window,
+ Gtk::STATE_NORMAL, Gtk::SHADOW_IN,
+ nil, self, nil,
+ bw, bw,
+ 8*@char_width + 2*xt, self.allocation.height - 2*bw
+ )
+
+ x += 8*@char_width + 2*xt
+ end
+
+ self.style.paint_shadow(
+ self.window,
+ Gtk::STATE_NORMAL, Gtk::SHADOW_IN,
+ nil, self, nil,
+ x, bw,
+ @xdisp_width + 2*xt, self.allocation.height - 2*bw
+ )
+
+ self.style.paint_shadow(
+ self.window,
+ Gtk::STATE_NORMAL, Gtk::SHADOW_IN,
+ nil, self, nil,
+ self.allocation.width - bw - @adisp_width - @scrollbar.requisition[0] - 2*xt, bw,
+ @adisp_width + 2*xt, self.allocation.height - 2*bw
+ )
+ end
+
+ def redraw_widget
+ return unless self.realized?
+
+ self.window.invalidate(nil, false)
+ end
+
+ def widget_get_xt
+ self.style.xthickness
+ end
+
+ def widget_get_yt
+ self.style.ythickness
+ end
+
+ def recalc_displays(width, height)
+ old_cpl = @cpl
+
+ w, h = @scrollbar.size_request
+ @xdisp_width = 1
+ @adisp_width = 1
+
+ total_width = width - 2 * self.border_width - 4 * widget_get_xt - w
+ total_width -= 2 * widget_get_xt + 8 * @char_width if @show_offsets
+
+ total_cpl = total_width / @char_width
+ if total_cpl == 0 or total_width < 0
+ @cpl = @lines = @vis_lines = 0
+ return
+ end
+
+ @cpl = 0
+ begin
+ break if @cpl % @group_type == 0 and total_cpl < @group_type * 3
+
+ @cpl += 1
+ total_cpl -= 3
+
+ total_cpl -= 1 if @cpl % @group_type == 0
+ end while total_cpl > 0
+
+ return if @cpl == 0
+
+ if @data.empty?
+ @lines = 1
+ else
+ @lines = @data.size / @cpl
+ @lines += 1 if @data.size % @cpl != 0
+ end
+
+ @vis_lines = (height - 2*self.border_width - 2*widget_get_yt).to_i / @char_height.to_i
+ @adisp_width = @cpl * @char_width + 1
+ xcpl = @cpl * 2 + (@cpl - 1) / @group_type
+ @xdisp_width = xcpl * @char_width + 1
+
+ @disp_buffer = ''
+
+ @adj.value = [@top_line * old_cpl / @cpl, @lines - @vis_lines].min
+ @adj.value = [ 0, @adj.value ].max
+ if @cursor_pos / @cpl < @adj.value or @cursor_pos / @cpl > @adj.value + @vis_lines - 1
+ @adj.value = [ @cursor_pos / @cpl, @lines - @vis_lines ].min
+ @adj.value = [ 0, @adj.value ].max
+ end
+
+ @adj.lower = 0
+ @adj.upper = @lines
+ @adj.step_increment = 1
+ @adj.page_increment = @vis_lines - 1
+ @adj.page_size = @vis_lines
+
+ @adj.signal_emit 'changed'
+ @adj.signal_emit 'value_changed'
+ end
+
+ def get_max_char_width(metrics)
+
+ layout = self.create_pango_layout('')
+ layout.set_font_description(@font_desc)
+ char_widths = [ 0 ]
+
+ (1..100).each do |i|
+ logical_rect = Pango::Rectangle.new(0, 0, 0, 0)
+ if is_displayable(i.chr)
+ layout.set_text(i.chr)
+ logical_rect = layout.pixel_extents[1]
+ end
+ char_widths << logical_rect.width
+ end
+
+ char_widths[48..122].max
+ end
+
+ def show_cursor
+ unless @cursor_shown
+ if @xdisp_gc and @adisp_gc and @xdisp.realized? and @adisp.realized?
+ render_xc
+ render_ac
+ end
+
+ @cursor_shown = true
+ end
+ end
+
+ def hide_cursor
+ if @cursor_shown
+ if @xdisp_gc and @adisp_gc and @xdisp.realized? and @adisp.realized?
+ render_byte(@cursor_pos)
+ end
+
+ @cursor_shown = false
+ end
+ end
+
+ def show_offsets_widget
+ @offsets = DrawingArea.new
+ @offsets.modify_font @font_desc
+ @olayout = @offsets.create_pango_layout('')
+
+ @offsets.events = Gdk::Event::EXPOSURE_MASK
+ @offsets.signal_connect 'expose_event' do |offsets, event|
+ imin = (event.area.y / @char_height).to_i
+ imax = ((event.area.y + event.area.height) / @char_height).to_i
+ imax += 1 if (event.area.y + event.area.height).to_i % @char_height != 0
+
+ imax = [ imax, @vis_lines ].min
+
+ render_offsets(imin, imax)
+ end
+
+ put @offsets, 0, 0
+ @offsets.show
+ end
+
+ def hide_offsets_widget
+ if @offsets
+ self.remove(@offsets)
+ @offsets = @offsets_gc = nil
+ end
+ end
+
+ def is_displayable(c)
+ if RUBY_VERSION < '1.9'
+ c = c[0]
+ else
+ c = c.ord
+ end
+
+ c >= 0x20 and c < 0x7f
+ end
+
+ def bytes_changed(s, e)
+ start_line = s / @cpl - @top_line
+ end_line = e / @cpl - @top_line
+
+ return if end_line < 0 or start_line > @vis_lines
+
+ start_line = [ 0, start_line ].max
+
+ render_hex_lines(start_line, end_line)
+ render_ascii_lines(start_line, end_line)
+ render_offsets(start_line, end_line) if @show_offsets
+ end
+
+ def render_hex_highlights(cursor_line)
+ xcpl = @cpl * 2 + @cpl / @group_type
+
+ @highlights.each do |hl|
+ next if (hl.start - hl.end).abs < hl.min_select
+
+ validate_highlight(hl)
+
+ s, e = [ hl.start, hl.end ].sort
+ sl, el = hl.start_line, hl.end_line
+
+ hl.style.attach(@xdisp.window) if hl.style
+ state = (@active_view == View::HEX) ? Gtk::STATE_SELECTED : Gtk::STATE_INSENSITIVE
+
+ if cursor_line == sl
+ cursor_off = 2 * (s % @cpl) + (s % @cpl) / @group_type
+ if cursor_line == el
+ len = 2 * (e % @cpl + 1) + (e % @cpl) / @group_type
+ else
+ len = xcpl
+ end
+
+ len -= cursor_off
+ (hl.style || self.style).paint_flat_box(
+ @xdisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @xdisp, '',
+ cursor_off * @char_width, cursor_line * @char_height,
+ len * @char_width, @char_height
+ ) if len > 0
+
+ elsif cursor_line == el
+ cursor_off = 2 * (e % @cpl + 1) + (e % @cpl) / @group_type
+ (hl.style || self.style).paint_flat_box(
+ @xdisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @xdisp, '',
+ 0, cursor_line * @char_height,
+ cursor_off * @char_width, @char_height
+ ) if cursor_off > 0
+
+ elsif cursor_line > sl and cursor_line < el
+ (hl.style || self.style).paint_flat_box(
+ @xdisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @xdisp, '',
+ 0, cursor_line * @char_height,
+ xcpl * @char_width, @char_height
+ )
+ end
+
+ hl.style.attach(@adisp.window) if hl.style
+ end
+ end
+
+ def render_hex_lines(imin, imax)
+ return unless self.realized? and @cpl != 0
+
+ cursor_line = @cursor_pos / @cpl - @top_line
+
+ @xdisp_gc.set_foreground(self.style.base(Gtk::STATE_NORMAL))
+ @xdisp.window.draw_rectangle(
+ @xdisp_gc,
+ true,
+ 0,
+ imin * @char_height,
+ @xdisp.allocation.width,
+ (imax - imin + 1) * @char_height
+ )
+
+ imax = [ imax, @vis_lines, @lines ].min
+
+ @xdisp_gc.set_foreground(self.style.text(Gtk::STATE_NORMAL))
+
+ frm_len = format_xblock((@top_line+imin) * @cpl, [(@top_line+imax+1) * @cpl, @data.size].min)
+
+ tmp = nil
+ xcpl = @cpl*2 + @cpl/@group_type
+ (imin..imax).each do |i|
+ return unless (tmp = frm_len - ((i - imin) * xcpl)) > 0
+
+ render_hex_highlights(i)
+ text = @disp_buffer[(i-imin) * xcpl, [xcpl, tmp].min]
+ @xlayout.set_text(text)
+ @xdisp.window.draw_layout(@xdisp_gc, 0, i * @char_height, @xlayout)
+ end
+
+ render_xc if cursor_line >= imin and cursor_line <= imax and @cursor_shown
+ end
+
+ def render_ascii_highlights(cursor_line)
+ @highlights.each do |hl|
+ next if (hl.start - hl.end).abs < hl.min_select
+
+ validate_highlight(hl)
+
+ s, e = [ hl.start, hl.end ].sort
+ sl, el = hl.start_line, hl.end_line
+
+ hl.style.attach(@adisp.window) if hl.style
+ state = (@active_view == View::ASCII) ? Gtk::STATE_SELECTED : Gtk::STATE_INSENSITIVE
+
+ if cursor_line == sl
+ cursor_off = s % @cpl
+ len =
+ if cursor_line == el
+ e - s + 1
+ else
+ @cpl - cursor_off
+ end
+
+ (hl.style || self.style).paint_flat_box(
+ @adisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @adisp, '',
+ cursor_off * @char_width, cursor_line * @char_height,
+ len * @char_width, @char_height
+ ) if len > 0
+
+ elsif cursor_line == el
+ cursor_off = e % @cpl + 1
+ (hl.style || self.style).paint_flat_box(
+ @adisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @adisp, '',
+ 0, cursor_line * @char_height,
+ cursor_off * @char_width, @char_height
+ ) if cursor_off > 0
+
+ elsif cursor_line > sl and cursor_line < el
+ (hl.style || self.style).paint_flat_box(
+ @adisp.window,
+ state, Gtk::SHADOW_NONE,
+ nil, @adisp, '',
+ 0, cursor_line * @char_height,
+ @cpl * @char_width, @char_height
+ )
+ end
+
+ hl.style.attach(@adisp.window) if hl.style
+ end
+ end
+
+ def render_ascii_lines(imin, imax)
+ return unless self.realized? and @cpl != 0
+
+ cursor_line = @cursor_pos / @cpl - @top_line
+
+ @adisp_gc.set_foreground(self.style.base(Gtk::STATE_NORMAL))
+ @adisp.window.draw_rectangle(
+ @adisp_gc,
+ true,
+ 0,
+ imin * @char_height,
+ @adisp.allocation.width,
+ (imax - imin + 1) * @char_height
+ )
+
+ imax = [ imax, @vis_lines, @lines ].min
+
+ @adisp_gc.set_foreground(self.style.text(Gtk::STATE_NORMAL))
+
+ frm_len = format_ablock((@top_line+imin) * @cpl, [(@top_line+imax+1) * @cpl, @data.size].min)
+
+ tmp = nil
+ (imin..imax).each do |i|
+ return unless (tmp = frm_len - ((i - imin) * @cpl)) > 0
+
+ render_ascii_highlights(i)
+ text = @disp_buffer[(i-imin) * @cpl, [@cpl, tmp].min]
+ @alayout.set_text(text)
+ @adisp.window.draw_layout(@adisp_gc, 0, i * @char_height, @alayout)
+ end
+
+ render_ac if cursor_line >= imin and cursor_line <= imax and @cursor_shown
+ end
+
+ def render_offsets(imin, imax)
+ return unless self.realized?
+
+ unless @offsets_gc
+ @offsets_gc = Gdk::GC.new(@offsets.window)
+ @offsets_gc.set_exposures(true)
+ end
+
+ @offsets_gc.set_foreground(self.style.base(Gtk::STATE_INSENSITIVE))
+ @offsets.window.draw_rectangle(
+ @offsets_gc,
+ true,
+ 0, imin * @char_height,
+ @offsets.allocation.width, (imax - imin + 1) * @char_height
+ )
+
+ imax = [ imax, @vis_lines, @lines - @top_line - 1 ].min
+ @offsets_gc.set_foreground(self.style.text(Gtk::STATE_NORMAL))
+
+ (imin..imax).each do |i|
+ text = "%08x" % ((@top_line + i) * @cpl + @starting_offset)
+ @olayout.set_text(text)
+ @offsets.window.draw_layout(@offsets_gc, 0, i * @char_height, @olayout)
+ end
+ end
+
+ def render_byte(pos)
+ return unless @xdisp_gc and @adisp_gc and @xdisp.realized? and @adisp.realized?
+
+ return unless (coords = get_xcoords(pos))
+ cx, cy = coords
+ c = format_xbyte(pos)
+
+ @xdisp_gc.set_foreground(self.style.base(Gtk::STATE_NORMAL))
+ @xdisp.window.draw_rectangle(
+ @xdisp_gc,
+ true,
+ cx, cy,
+ 2 * @char_width, @char_height
+ )
+
+ if pos < @data.size
+ @xdisp_gc.set_foreground(self.style.text(Gtk::STATE_NORMAL))
+ @xlayout.set_text(c)
+ @xdisp.window.draw_layout(@xdisp_gc, cx, cy, @xlayout)
+ end
+
+ return unless (coords = get_acoords(pos))
+ cx, cy = coords
+
+ @adisp_gc.set_foreground(self.style.base(Gtk::STATE_NORMAL))
+ @adisp.window.draw_rectangle(
+ @adisp_gc,
+ true,
+ cx, cy,
+ @char_width, @char_height
+ )
+
+ if pos < @data.size
+ @adisp_gc.set_foreground(self.style.text(Gtk::STATE_NORMAL))
+ c = get_byte(pos)
+ c = '.' unless is_displayable(c)
+
+ @alayout.set_text(c)
+ @adisp.window.draw_layout(@adisp_gc, cx, cy, @alayout)
+ end
+ end
+
+ def render_xc
+ return unless @xdisp.realized?
+
+ if coords = get_xcoords(@cursor_pos)
+ cx, cy = coords
+
+ c = format_xbyte(@cursor_pos)
+ if @lower_nibble
+ cx += @char_width
+ c = c[1,1]
+ else
+ c = c[0,1]
+ end
+
+ @xdisp_gc.set_foreground(self.style.base(Gtk::STATE_ACTIVE))
+ @xdisp.window.draw_rectangle(
+ @xdisp_gc,
+ (@active_view == View::HEX),
+ cx, cy,
+ @char_width,
+ @char_height - 1
+ )
+ @xdisp_gc.set_foreground(self.style.text(Gtk::STATE_ACTIVE))
+ @xlayout.set_text(c)
+ @xdisp.window.draw_layout(@xdisp_gc, cx, cy, @xlayout)
+ end
+ end
+
+ def render_ac
+ return unless @adisp.realized?
+
+ if coords = get_acoords(@cursor_pos)
+ cx, cy = coords
+
+ c = get_byte(@cursor_pos)
+ c = '.' unless is_displayable(c)
+
+ @adisp_gc.set_foreground(self.style.base(Gtk::STATE_ACTIVE))
+ @adisp.window.draw_rectangle(
+ @adisp_gc,
+ (@active_view == View::ASCII),
+ cx, cy,
+ @char_width,
+ @char_height - 1
+ )
+ @adisp_gc.set_foreground(self.style.text(Gtk::STATE_ACTIVE))
+ @alayout.set_text(c)
+ @adisp.window.draw_layout(@adisp_gc, cx, cy, @alayout)
+ end
+ end
+
+ def get_xcoords(pos)
+ return nil if @cpl == 0
+
+ cy = pos / @cpl - @top_line
+ return nil if cy < 0
+
+ cx = 2 * (pos % @cpl)
+ spaces = (pos % @cpl) / @group_type
+
+ cx *= @char_width
+ cy *= @char_height
+ spaces *= @char_width
+
+ [cx + spaces, cy]
+ end
+
+ def get_acoords(pos)
+ return nil if @cpl == 0
+
+ cy = pos / @cpl - @top_line
+ return nil if cy < 0
+
+ cy *= @char_height
+ cx = @char_width * (pos % @cpl)
+
+ [cx, cy]
+ end
+
+ def format_xblock(s, e)
+ @disp_buffer = ''
+
+ (s+1..e).each do |i|
+ @disp_buffer << get_byte(i - 1).unpack('H2')[0]
+ @disp_buffer << ' ' if i % @group_type == 0
+ end
+
+ @disp_buffer.size
+ end
+
+ def format_ablock(s, e)
+ @disp_buffer = ''
+
+ (s..e-1).each do |i|
+ c = get_byte(i)
+ c = '.' unless is_displayable(c)
+ @disp_buffer << c
+ end
+
+ @disp_buffer.size
+ end
+
+ def get_byte(offset)
+ if offset >= 0 and offset < @data.size
+ @data[offset, 1]
+ else
+ 0.chr
+ end
+ end
+
+ def format_xbyte(pos)
+ get_byte(pos).unpack('H2')[0]
+ end
+ end
+
+end
+
+__END__
+hexedit = Gtk::HexEditor.new(File.read '/bin/cat')
+hexedit.show_offsets(true)
+hexedit.set_cursor 2
+hexedit.set_cursor_on_lower_nibble true
+hexedit.set_font 'Terminus 12'
+hexedit.set_group_type Gtk::HexEditor::Group::LONG
+
+window = Gtk::Window.new
+window.add(hexedit)
+
+window.show_all
+
+Gtk.main
diff --git a/bin/gui/hexdump.rb b/bin/gui/hexdump.rb
deleted file mode 100644
index d675dcc..0000000
--- a/bin/gui/hexdump.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-=begin
-
-= File
- hexdump.rb
-
-= Info
- This file is part of Origami, PDF manipulation framework for Ruby
- Copyright (C) 2010 Guillaume Delugré
- All right reserved.
-
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Origami 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 Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
-
-=end
-
-class String #:nodoc:
-
- def hexdump(bytesperline = 16, upcase = true, offsets = true)
-
- dump = ""
- counter = 0
-
- while counter < length
-
- offset = sprintf("%010u", counter)
-
- linelen = (counter < length - bytesperline) ? bytesperline : (length - counter)
- bytes = ""
- linelen.times do |i|
-
- byte = self[counter + i].ord.to_s(16)
- if byte.size < 2 then byte.insert(0, "0") end
- bytes << byte
- bytes << " " unless i == bytesperline - 1
-
- end
-
- ascii = self[counter, linelen].ascii_print
-
- if upcase
- offset.upcase!
- bytes.upcase!
- end
-
- dump << "#{offset if offsets} #{bytes.to_s.ljust(bytesperline * 3 - 1)} #{ascii}\n"
-
- counter += bytesperline
-
- end
-
- dump
- end
-
- def ascii_print
-
- printable = ""
- self.each_byte do |c|
- if c >= ' '[0].ord && c <= '~'[0].ord then printable << c else printable << '.' end
- end
-
- printable
- end
-
-end
diff --git a/bin/gui/hexview.rb b/bin/gui/hexview.rb
index 6fcbeb2..eb35f27 100644
--- a/bin/gui/hexview.rb
+++ b/bin/gui/hexview.rb
@@ -4,26 +4,26 @@
hexview.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
-require 'gui/hexdump'
+require 'gui/gtkhex'
module PDFWalker
@@ -44,21 +44,15 @@ def initialize(parent)
set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
@current_obj = nil
- @valuebuffer = TextBuffer.new
- @valueview = TextView.new(@valuebuffer).set_editable(false).set_cursor_visible(false).set_left_margin(5).set_right_margin(5)
+
+ @view = HexEditor.new
+ @view.show_offsets(true)
- @valuebuffer.create_tag( "HexView",
- :weight => Pango::WEIGHT_BOLD,
- #:foreground => "black",
- :family => "Courier",
- :scale => Pango::AttrScale::LARGE
- )
-
- add_with_viewport @valueview
+ add_with_viewport @view
end
def clear
- @valuebuffer.set_text("")
+ @view.set_data ''
end
def load(object)
@@ -69,14 +63,13 @@ def load(object)
case object
when Origami::Stream
- @valuebuffer.set_text(object.data.to_s.hexdump)
+ @view.set_data(object.data)
when Origami::HexaString
- @valuebuffer.set_text(object.value.to_s.hexdump)
+ @view.set_data(object.data.to_s)
when Origami::ByteString
- @valuebuffer.set_text(object.to_utf8)
+ @view.set_data(object.data.to_s)
end
- @valuebuffer.apply_tag("HexView", @valuebuffer.start_iter, @valuebuffer.end_iter)
@current_obj = object
rescue Exception => e
diff --git a/bin/gui/imgview.rb b/bin/gui/imgview.rb
index 63d5b4f..42fdf17 100644
--- a/bin/gui/imgview.rb
+++ b/bin/gui/imgview.rb
@@ -4,22 +4,22 @@
imgview.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/menu.rb b/bin/gui/menu.rb
index ac6b15d..c6aaadc 100644
--- a/bin/gui/menu.rb
+++ b/bin/gui/menu.rb
@@ -4,22 +4,22 @@
menu.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
@@ -266,7 +266,7 @@ def create_menus
AccelMap.add_entry("/File/Open", Gdk::Keyval::GDK_O, Gdk::Window::CONTROL_MASK)
AccelMap.add_entry("/File/Refresh", Gdk::Keyval::GDK_R, Gdk::Window::CONTROL_MASK)
- AccelMap.add_entry("/File/Close", Gdk::Keyval::GDK_X, Gdk::Window::CONTROL_MASK)
+ AccelMap.add_entry("/File/Close", Gdk::Keyval::GDK_W, Gdk::Window::CONTROL_MASK)
AccelMap.add_entry("/File/Save", Gdk::Keyval::GDK_S, Gdk::Window::CONTROL_MASK)
AccelMap.add_entry("/File/Quit", Gdk::Keyval::GDK_Q, Gdk::Window::CONTROL_MASK)
AccelMap.add_entry("/Document/Search", Gdk::Keyval::GDK_F, Gdk::Window::CONTROL_MASK)
diff --git a/bin/gui/properties.rb b/bin/gui/properties.rb
index e4350d0..c44cf17 100644
--- a/bin/gui/properties.rb
+++ b/bin/gui/properties.rb
@@ -4,22 +4,22 @@
properties.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/signing.rb b/bin/gui/signing.rb
index 9a4b9b9..5b96f9b 100644
--- a/bin/gui/signing.rb
+++ b/bin/gui/signing.rb
@@ -4,22 +4,22 @@
signing.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/textview.rb b/bin/gui/textview.rb
index 3288ad1..d49da95 100644
--- a/bin/gui/textview.rb
+++ b/bin/gui/textview.rb
@@ -4,28 +4,25 @@
textview.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
-require 'kconv'
-require 'gui/hexdump'
-
module PDFWalker
class Walker < Window
@@ -56,7 +53,7 @@ def initialize(parent)
@pdfbuffer.create_tag("Object",
:weight => Pango::WEIGHT_BOLD,
- :foreground => "darkblue",
+ #:foreground => "darkblue",
:family => "Courier",
:scale => Pango::AttrScale::LARGE
)
@@ -74,11 +71,11 @@ def load(object)
stm = "#{object.no} #{object.generation} obj\n"
stm << object.dictionary.to_s
- if object.rawdata.is_binary_data?
- stm << "stream\n[Binary data]\nendstream"
- else
- stm << "stream\n#{object.rawdata}endstream"
- end
+ #if object.rawdata.is_binary_data?
+ # stm << "stream\n[Binary data]\nendstream"
+ #else
+ # stm << "stream\n#{object.rawdata}endstream"
+ #end
@pdfbuffer.set_text(stm)
diff --git a/bin/gui/treeview.rb b/bin/gui/treeview.rb
index 4dff2e9..039c263 100644
--- a/bin/gui/treeview.rb
+++ b/bin/gui/treeview.rb
@@ -4,22 +4,22 @@
treeview.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/walker.rb b/bin/gui/walker.rb
index 6c3c04d..c2f1fe0 100644
--- a/bin/gui/walker.rb
+++ b/bin/gui/walker.rb
@@ -6,22 +6,22 @@
walker.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end
diff --git a/bin/gui/xrefs.rb b/bin/gui/xrefs.rb
index de54127..82e26e7 100644
--- a/bin/gui/xrefs.rb
+++ b/bin/gui/xrefs.rb
@@ -4,22 +4,22 @@
xrefs.rb
= Info
- This file is part of Origami, PDF manipulation framework for Ruby
+ This file is part of PDF Walker, a graphical PDF file browser
Copyright (C) 2010 Guillaume Delugré
All right reserved.
- Origami is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
+ PDF Walker 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 3 of the License, or
(at your option) any later version.
- Origami is distributed in the hope that it will be useful,
+ PDF Walker 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 Lesser General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with Origami. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with PDF Walker. If not, see .
=end