├── .dir-locals.el ├── .gitignore ├── COPYING ├── Makefile.am ├── NEWS ├── README.ja.md ├── README.md ├── autogen.sh ├── configure.ac ├── m4 ├── ax_compare_version.m4 ├── ax_cxx_compile_stdcxx.m4 └── ax_cxx_compile_stdcxx_11.m4 ├── man ├── Makefile.am └── extractpdfmark.1 ├── src ├── Makefile.am ├── cmdlineparse.hh ├── encodename.cc ├── iconv_wrapper.hh ├── main.cc ├── output-pdfmark.cc ├── output-pdfmark.hh ├── poppler-core │ ├── Makefile.am │ ├── destname-private.hh │ ├── destname.cc │ ├── pagemode.cc │ ├── poppler-core.cc │ └── poppler-core.hh ├── poppler-cpp │ ├── Makefile.am │ ├── destname-cpp.cc │ ├── pagemode-cpp.cc │ ├── poppler-cpp.cc │ └── poppler-cpp.hh ├── poppler-glib │ ├── Makefile.am │ ├── destname-glib.cc │ ├── pagemode-glib.cc │ ├── poppler-glib.cc │ └── poppler-glib.hh ├── utf16.cc ├── utf16.hh ├── utf8.cc └── utf8.hh └── test ├── Makefile.am ├── addnamedict.ps ├── binary.tex ├── destonly.tex ├── desttype.tex ├── nodest.tex ├── pagemode-fullscreen.tex ├── pagemode-thumbs.tex ├── pagemode-usenone.tex ├── pdfdocencoding.tex ├── special-chars.tex ├── test-expected-pdfmark.sh ├── test-round.sh ├── utf16.tex └── utf8.tex /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ;;; Directory Local Variables 2 | ;;; See Info node `(emacs) Directory Variables' for more information. 3 | 4 | ((c++-mode 5 | (c-file-style . "gnu") 6 | (indent-tabs-mode . nil)) 7 | (autoconf-mode 8 | (indent-tabs-mode . nil)) 9 | (shellscript-mode 10 | (indent-tabs-mode . nil))) 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .\#* 3 | \#* 4 | \#.* 5 | /build/ 6 | /autom4te.cache/ 7 | /aclocal.m4 8 | /compile 9 | /config.h.in 10 | /configure 11 | /depcomp 12 | /install-sh 13 | Makefile.in 14 | /missing 15 | .deps/ 16 | Makefile 17 | config.h 18 | config.log 19 | config.status 20 | stamp-h1 21 | *.o 22 | *.exe 23 | extractpdfmark 24 | /test-driver 25 | config.guess 26 | config.rpath 27 | config.sub 28 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src man test 2 | 3 | dist_doc_DATA = README.md README.ja.md COPYING NEWS 4 | EXTRA_DIST = autogen.sh 5 | 6 | ACLOCAL_AMFLAGS = -I m4 7 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Release 1.1.1 (2022-09-30): 2 | Fix handling a named destination with an empty string name 3 | https://github.com/trueroad/extractpdfmark/issues/3 4 | 5 | Exclude deprecated poppler-core interface for poppler 0.76+ 6 | 7 | Add stable poppler-glib interface for poppler 0.78.0+ 8 | 9 | Release 1.1.0 (2019-02-11): 10 | Add stable poppler-cpp interface for poppler 0.74.0+ 11 | 12 | Release 1.0.3 (2018-12-09): 13 | Support poppler 0.72.0 14 | 15 | Release 1.0.2 (2017-04-17): 16 | Add manpage 17 | Improve README 18 | 19 | Release 1.0.1 (2016-10-23): 20 | Add GCC 4.8.x support 21 | 22 | Release 1.0.0 (2016-10-10): 23 | Initial release 24 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | 2 | # Extract PDFmark 3 | 4 | [ Japanese (日本語) / [English](./README.md) ] 5 | 6 | PDF からページモードやリンクの宛先名を抽出し PDFmark として保存します 7 | 8 | https://github.com/trueroad/extractpdfmark 9 | http://www.ctan.org/pkg/extractpdfmark 10 | 11 | TeX のようなシステムを使って PDF のドキュメントを作る場合、 12 | 図としてたくさんの小さな PDF を用意して、 13 | メインの PDF に貼り付けるようなことが行われます。 14 | このとき、図の PDF では同じフォントを使っていることが多いと思います。 15 | 16 | 図の PDF にフォントのサブセットが埋め込まれていた場合、 17 | TeX システムはそのフォントをそのままメインの PDF に埋め込みます。 18 | 結果として、 19 | メイン PDF には重複した同じフォントの異なるサブセットが埋め込まれます。 20 | サブセットが異なるため重複したフォントを削除することはできません。 21 | よってメイン PDF のファイルサイズは、かなり大きくなってしまいます。 22 | 23 | 一方、図の PDF にフォントをフルセットで埋め込んだ場合、 24 | TeX システムはフルセットのフォントをメインの PDF へ埋め込みます。 25 | メイン PDF にはたくさんの重複したフォントが埋め込まれますが、 26 | すべて同じフルセットのフォントです。 27 | そのため、Ghostscript を使えば重複を削除することができ、 28 | これによってメイン PDF のサイズを低減することができます。 29 | (注意: Ghostscript 9.17 から 9.21 は重複フォント削除のために 30 | `-dPDFDontUseFontObjectNum` コマンドラインオプションが必要です。 31 | Ghostscript 9.22 以降は重複フォント削除ができなくなくなったため、 32 | フルセット埋め込みの方法を採ることができません。 33 | 詳細は https://ghostscript.com/pipermail/gs-devel/2017-September/date.html 34 | や http://lists.gnu.org/archive/html/lilypond-devel/2017-09/index.html 35 | をご覧ください。 36 | この場合は、次に示すフォントを一切埋め込まない方法を採る必要があります。) 37 | 38 | さらに、図の PDF に一切フォントを埋め込まなかった場合、 39 | TeX システムはフォントが欠けたメイン PDF を出力します。 40 | この場合、Ghostscript は必要なフォントを埋め込むことができるので、 41 | 必要なディスク容量を劇的に減らすことができるようになります。 42 | (注意: Ghostscript 9.26 以降で CID フォントを埋め込みたい場合は、 43 | https://bugs.ghostscript.com/show_bug.cgi?id=700367 44 | と https://bugs.ghostscript.com/show_bug.cgi?id=700436 45 | をご覧ください。) 46 | 47 | いずれの方法でも、 48 | Ghostscript へ TeX システムの出力したメイン PDF を入力し、 49 | 最終的な PDF を出力することになります。 50 | しかし、残念ながら、この処理で Ghostscript は PDF のページモードや 51 | リンクの宛先名を残してくれません。 52 | そのため、最終的な PDF は意図したとおりに開かれなかったり、 53 | リモートからのリンクが機能しなくなったりしてしまいます。 54 | 55 | http://bugs.ghostscript.com/show_bug.cgi?id=696943 56 | http://bugs.ghostscript.com/show_bug.cgi?id=695760 57 | 58 | Extract PDFmark は PDF からページモードやリンクの宛先名を抽出し、 59 | PDFmark として保存することができます。 60 | このツールを使うと、ページモードやリンク先名を残したまま、 61 | サイズの小さい PDF を得ることができます。 62 | 63 | ## 使い方 64 | 65 | $ extractpdfmark TeX出力.pdf > 抽出したPDFmark.ps 66 | $ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ 67 | -dPDFDontUseFontObjectNum -dPrinted=false \ 68 | -sOutputFile=最終.pdf TeX出力.pdf 抽出したPDFmark.ps 69 | 70 | (注意: Ghostscript 9.26 以降は `-dPrinted=false` 71 | コマンドラインオプションが必要です。詳細は 72 | https://bugs.ghostscript.com/show_bug.cgi?id=699830 73 | をご覧ください。) 74 | 75 | ## バイナリパッケージからのインストール 76 | 77 | いくつかのディストリビューションには `extractpdfmark` パッケージがあります。 78 | 79 | * Debian 80 | * Ubuntu 81 | * Fedora 82 | * Cygwin 83 | * etc. 84 | 85 | ## [ソース tarball](https://github.com/trueroad/extractpdfmark/releases/download/v1.1.1/extractpdfmark-1.1.1.tar.gz) からのインストール 86 | 87 | ### 必要なもの 88 | 89 | Extract PDFmark は poppler にある 3 種類のインタフェースのうち、 90 | どれかを必要とします。 91 | Extract PDFmark をビルドする際に、どれを使用するか選択してください。 92 | 93 | #### poppler-cpp I/F (推奨) 94 | 95 | [poppler](https://poppler.freedesktop.org/) 0.74.0 以降が必要です。 96 | Extract PDFmark の configure スクリプトは、 97 | pkg-config が poppler-cpp >= 0.74.0 を見つけたら 98 | poppler-cpp I/F を選択します。 99 | 100 | configure スクリプトのオプション `--with-poppler=cpp` によって、 101 | 本 I/F の使用を明示的に指定できます。 102 | 103 | パッケージを使って準備したい場合には、以下が便利でしょう。 104 | 105 | * Debian / Ubuntu 106 | + libpoppler-cpp-dev 107 | * Fedora 108 | + poppler-cpp-devel 109 | * Cygwin 110 | + libpoppler-cpp-devel 111 | 112 | #### poppler-glib I/F 113 | 114 | [poppler](https://poppler.freedesktop.org/) 0.78.0 以降が必要です。 115 | Extract PDFmark の configure スクリプトは、 116 | pkg-config が poppler-cpp >= 0.74.0 を見つけられず、 117 | かつ poppler-glib >= 0.78.0 を見つけたら 118 | poppler-glib I/F を選択します。 119 | 120 | configure スクリプトのオプション `--with-poppler=glib` によって、 121 | 本 I/F の使用を明示的に指定できます。 122 | 123 | #### poppler-core I/F (非推奨) 124 | 125 | [poppler](https://poppler.freedesktop.org/) 0.13.3 から 0.75.0 126 | に以下のオプションをつけてビルドしたものが必要です 127 | (推奨 poppler 0.48.0 から 0.73.0)。 128 | 129 | * --enable-xpdf-headers (poppler 0.59.0 まで) 130 | * -DENABLE_XPDF_HEADERS=ON (poppler 0.60.0 から 0.72.0) 131 | * -DENABLE_UNSTABLE_API_ABI_HEADERS=ON (poppler 0.73.0 から 0.75.0) 132 | 133 | poppler 0.74.0 以降の場合は、この I/F より poppler-cpp I/F の方を推奨します。 134 | poppler 0.76.0 でこの I/F に破壊的変更が入ったため、 135 | poppler 0.76.0 以降ではこの I/F を使ったExtract PDFmarkのビルドが失敗します。 136 | 137 | Extract PDFmark の configure スクリプトは、 138 | pkg-config が poppler-cpp >= 0.74.0 を見つけられず、 139 | poppler-glib >= 0.78.0 を見つけられず、 140 | かつ poppler 0.24.4 - 0.75.0 を見つけたら 141 | poppler-core I/F を選択します。 142 | 本 I/F には private 版と通常版の 2 種類があります。 143 | poppler 0.24.4 から 0.47.0 の場合は private 版が選択されます。 144 | poppler 0.48.0 から 0.75.0 の場合は通常版が選択されます。 145 | 146 | configure スクリプトのオプション `--with-poppler=core-private` によって、 147 | private 版の使用を明示的に指定できます(poppler 0.13.3 から 0.75.0 用)。 148 | configure スクリプトのオプション `--with-poppler=core` によって、 149 | 通常版の使用を明示的に指定できます(poppler 0.48.0 から 0.75.0 用)。 150 | poppler 0.13.3 から 0.24.3 を使うには、 151 | configure スクリプトのオプション `--with-poppler=core-private` を 152 | 明示的に指定する必要があります。 153 | しかし、これらのバージョンでは Extract PDFmark の `make check` 154 | で一部のテストに失敗します。 155 | 156 | パッケージを使って準備したい場合には、以下が便利でしょう。 157 | 158 | * Debian / Ubuntu 159 | + libpoppler-private-dev 160 | + libpoppler-dev 161 | * Fedora 162 | + poppler-devel 163 | * Cygwin 164 | + libpoppler-devel 165 | 166 | ### ビルド・インストール方法 167 | 168 | $ ./configure 169 | $ make 170 | $ make install 171 | 172 | `Ghostscript` 9.14 以降と `diff` 等があれば、 173 | 以下のようにインストール前にテストすることができます。 174 | 175 | $ ./configure 176 | $ make 177 | $ make check 178 | $ make install 179 | 180 | ## [Git リポジトリ](https://github.com/trueroad/extractpdfmark)からのインストール 181 | 182 | ソース tarball のビルド要件と追加の要件が必要です。 183 | 184 | ### 追加で必要なもの 185 | 186 | Autoconf 2.69 以降 187 | Automake 188 | autopoint 0.19.6 以降(gettext 0.19.6 以降) 189 | 190 | ### 追加で推奨するもの 191 | 192 | pdfTeX (テスト PDF の生成用) 193 | Ghostscript 9.14 以降(`make check` 用) 194 | 195 | ### ビルド・インストール方法 196 | 197 | $ git clone https://github.com/trueroad/extractpdfmark.git 198 | $ cd extractpdfmark 199 | $ ./autogen.sh 200 | $ mkdir build 201 | $ cd build 202 | $ ../configure 203 | $ make 204 | $ make check 205 | $ make install 206 | 207 | ## News 208 | 209 | [News](./NEWS) 210 | 211 | ## ライセンス 212 | 213 | Copyright (C) 2016-2022 Masamichi Hosoda 214 | 215 | Extract PDFmark is free software: you can redistribute it and/or modify 216 | it under the terms of the GNU General Public License as published by 217 | the Free Software Foundation, either version 3 of the License, or 218 | (at your option) any later version. 219 | 220 | Extract PDFmark is distributed in the hope that it will be useful, 221 | but WITHOUT ANY WARRANTY; without even the implied warranty of 222 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 223 | GNU General Public License for more details. 224 | 225 | You should have received a copy of the GNU General Public License 226 | along with Extract PDFmark. If not, see . 227 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Extract PDFmark 3 | 4 | [ [Japanese (日本語)](./README.ja.md) / English ] 5 | 6 | Extract page mode and named destinations as PDFmark from PDF 7 | 8 | https://github.com/trueroad/extractpdfmark 9 | http://www.ctan.org/pkg/extractpdfmark 10 | 11 | When you create a PDF document using something like a TeX system 12 | you may include many small PDF files in the main PDF file. 13 | It is common for each of the small PDF files to use the same fonts. 14 | 15 | If the small PDF files contain embedded font subsets, 16 | the TeX system includes them as-is in the main PDF. 17 | As a result, 18 | several subsets of the same font are embedded in the main PDF. 19 | It is not possible to remove the duplicates since they are different subsets. 20 | This vastly increases the size of the main PDF file. 21 | 22 | On the other hand, 23 | if the small PDF files contain embedded full font sets, 24 | the TeX system also includes all of them in the main PDF. 25 | This time, the main PDF contains duplicates of the same full sets of fonts. 26 | Therefore, Ghostscript can remove the duplicates. 27 | This may considerably reduce the main PDF-file's size. 28 | (Note: Ghostscript 9.17 - 9.21 needs `-dPDFDontUseFontObjectNum` 29 | commandline option for removing duplicate fonts. 30 | If you use Ghostscript 9.22+, you cannot use this "full set embedding" method 31 | since it cannot remove duplicate fonts. 32 | See https://ghostscript.com/pipermail/gs-devel/2017-September/date.html 33 | and http://lists.gnu.org/archive/html/lilypond-devel/2017-09/index.html . 34 | In this case, you can use "*not* embedding" method as following.) 35 | 36 | Finally, 37 | if the small PDF files contain some fonts that are *not* embedded, 38 | the TeX system outputs the main PDF file with some fonts missing. 39 | In this case, Ghostscript can embed the necessary fonts. 40 | It can significantly reduce the required disk size. 41 | (Note: If you use Ghostscript 9.26+ and want to embed CID fonts, 42 | see https://bugs.ghostscript.com/show_bug.cgi?id=700367 43 | and https://bugs.ghostscript.com/show_bug.cgi?id=700436 .) 44 | 45 | Either way, 46 | when Ghostscript reads the main PDF produced by the TeX system 47 | and outputs the final PDF 48 | it does not preserve PDF page-mode and named-destinations etc. 49 | As a result, 50 | when you open the final PDF, 51 | it is not displayed correctly. 52 | Also, remote PDF links will not work correctly. 53 | 54 | http://bugs.ghostscript.com/show_bug.cgi?id=696943 55 | http://bugs.ghostscript.com/show_bug.cgi?id=695760 56 | 57 | This program is able to extract page mode and named destinations 58 | as PDFmark from PDF. 59 | By using this you can get the small PDF files 60 | that have preserved them. 61 | 62 | ## Usage 63 | 64 | $ extractpdfmark TeX-System-Outputted.pdf > Extracted-PDFmark.ps 65 | $ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ 66 | -dPDFDontUseFontObjectNum -dPrinted=false \ 67 | -sOutputFile=Final.pdf TeX-System-Outputted.pdf Extracted-PDFmark.ps 68 | 69 | (Note: Ghostscript 9.26+ needs `-dPrinted=false` commandline option. 70 | See https://bugs.ghostscript.com/show_bug.cgi?id=699830 .) 71 | 72 | ## Install from binary package 73 | 74 | Some distributions have `extractpdfmark` package. 75 | 76 | * Debian 77 | * Ubuntu 78 | * Fedora 79 | * Cygwin 80 | * etc. 81 | 82 | ## Install from [source tarball](https://github.com/trueroad/extractpdfmark/releases/download/v1.1.1/extractpdfmark-1.1.1.tar.gz) 83 | 84 | ### Required 85 | 86 | Extract PDFmark requires one of the three interfaces of poppler. 87 | Please choose which to use when building Extrcat PDFmark. 88 | 89 | #### poppler-cpp I/F (recommended) 90 | 91 | [poppler](https://poppler.freedesktop.org/) 0.74.0+ is required. 92 | Extract PDFmark's configure script selects poppler-cpp I/F 93 | if pkg-config finds poppler-cpp >= 0.74.0. 94 | 95 | The configure script's option `--with-poppler=cpp` specifies 96 | explicitly using this interface. 97 | 98 | When you would like to use packages for preparing the required library, 99 | the following might be convenient. 100 | 101 | * Debian / Ubuntu 102 | + libpoppler-cpp-dev 103 | * Fedora 104 | + poppler-cpp-devel 105 | * Cygwin 106 | + libpoppler-cpp-devel 107 | 108 | #### poppler-glib I/F 109 | 110 | [poppler](https://poppler.freedesktop.org/) 0.78.0+ is required. 111 | Extract PDFmark's configure script selects poppler-glib I/F 112 | if pkg-config does not find poppler-cpp >= 0.74.0, 113 | and finds poppler-glib 0.78.0+. 114 | 115 | The configure script's option `--with-poppler=glib` specifies 116 | explicitly using this interface. 117 | 118 | #### poppler-core I/F (deprecated) 119 | 120 | [poppler](https://poppler.freedesktop.org/) 0.13.3 - 0.75.0 121 | built with the following option is required 122 | (recommended poppler 0.48.0 - 0.73.0). 123 | 124 | * --enable-xpdf-headers (poppler 0.59.0 and before) 125 | * -DENABLE_XPDF_HEADERS=ON (poppler 0.60.0 - 0.72.0) 126 | * -DENABLE_UNSTABLE_API_ABI_HEADERS=ON (poppler 0.73.0 - 0.75.0) 127 | 128 | If you have poppler 0.74.0+, poppler-cpp I/F 129 | instead of this I/F is recommended. 130 | Extract PDFmark build with this I/F on poppler-0.76.0+ fails 131 | since poppler-0.76.0 has a disruptive change to the I/F. 132 | 133 | Extract PDFmark's configure script selects poppler-core I/F 134 | if pkg-config does not find poppler-cpp >= 0.74.0, 135 | does not find poppler-glib >= 0.78.0, 136 | and finds poppler 0.24.4 - 0.75.0. 137 | There are two versions of this interface, private and normal. 138 | For popler 0.24.4 - 0.47.0, private version is selected. 139 | For popler 0.48.0 - 0.75.0, normal version is selected. 140 | 141 | The configure script's option `--with-poppler=core-private` specifies 142 | explicitly using private version (for poppler 0.13.3 - 0.75.0). 143 | The configure script's option `--with-poppler=core` specifies 144 | explicitly using normal version (for poppler 0.48.0 - 0.75.0). 145 | If you would like to use poppler 0.13.3 - 0.24.3, 146 | it is necessary to specify explicitly configure script's option 147 | `--with-poppler=core-private`. 148 | However, Extract PDFmark with these versions of popler fails 149 | some tests in `make check`. 150 | 151 | When you would like to use packages for preparing the required library, 152 | the following might be convenient. 153 | 154 | * Debian / Ubuntu 155 | + libpoppler-private-dev 156 | + libpoppler-dev 157 | * Fedora 158 | + poppler-devel 159 | * Cygwin 160 | + libpoppler-devel 161 | 162 | ### Build & install 163 | 164 | $ ./configure 165 | $ make 166 | $ make install 167 | 168 | If you have `Ghostscript` 9.14+ and `diff` etc., 169 | you can run tests before installation as follows. 170 | 171 | $ ./configure 172 | $ make 173 | $ make check 174 | $ make install 175 | 176 | ## Install from [Git repository](https://github.com/trueroad/extractpdfmark) 177 | 178 | Source tarball build requirements and additional requirements are necessary. 179 | 180 | ### Additional required 181 | 182 | Autoconf 2.69+ 183 | Automake 184 | autopoint 0.19.6+ (gettext 0.19.6+) 185 | 186 | ### Additional recommended 187 | 188 | pdfTeX (for generating test PDFs) 189 | Ghostscript 9.14+ (for `make check`) 190 | 191 | ### Build & install 192 | 193 | $ git clone https://github.com/trueroad/extractpdfmark.git 194 | $ cd extractpdfmark 195 | $ ./autogen.sh 196 | $ mkdir build 197 | $ cd build 198 | $ ../configure 199 | $ make 200 | $ make check 201 | $ make install 202 | 203 | ## News 204 | 205 | [News](./NEWS) 206 | 207 | ## Licence 208 | 209 | Copyright (C) 2016-2022 Masamichi Hosoda 210 | 211 | Extract PDFmark is free software: you can redistribute it and/or modify 212 | it under the terms of the GNU General Public License as published by 213 | the Free Software Foundation, either version 3 of the License, or 214 | (at your option) any later version. 215 | 216 | Extract PDFmark is distributed in the hope that it will be useful, 217 | but WITHOUT ANY WARRANTY; without even the implied warranty of 218 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 219 | GNU General Public License for more details. 220 | 221 | You should have received a copy of the GNU General Public License 222 | along with Extract PDFmark. If not, see . 223 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CURRENT_DIR=`pwd` 4 | AUTOPOINT_TMP_DIR=`mktemp -d autopoint.tmp.XXXXXXXXXX` 5 | 6 | echo "*** Entering temporary directory ${AUTOPOINT_TMP_DIR}" 7 | cd ${AUTOPOINT_TMP_DIR} 8 | 9 | echo 10 | echo "*** Creating dummy configure.ac" 11 | { 12 | cat < configure.ac 17 | 18 | echo 19 | echo "*** Invoking autopoint" 20 | 21 | autopoint || 22 | { 23 | echo 24 | echo "WARNING: autopoint failed." 25 | echo "WARNING: It is required for getting \`config.rpath'." 26 | echo "WARNING: Please install autopoint 0.19.6 or newer." 27 | echo "WARNING: Depending on the platform, this is either" 28 | echo "WARNING: a separate package or part of \`gettext-devel'." 29 | } 30 | 31 | echo 32 | echo "*** Leaving temporary directory ${AUTOPOINT_TMP_DIR}" 33 | cd ${CURRENT_DIR} 34 | 35 | echo 36 | echo "*** Copying config.rpath from temporary directory" 37 | cp ${AUTOPOINT_TMP_DIR}/config.rpath . || 38 | { 39 | echo 40 | echo "WARNING: Copy failed." 41 | if [ -e config.rpath ]; then 42 | echo "WARNING: Using existing \`config.rpath'." 43 | else 44 | echo 45 | echo "ERROR: config.rpath does not exist." 46 | echo "ERROR: Please install autopoint 0.19.6 or newer." 47 | echo "ERROR: Depending on the platform, this is either" 48 | echo "ERROR: a separate package or part of \`gettext-devel'." 49 | echo "ERROR: Or, please copy \`config.rpath'." 50 | exit 1 51 | fi 52 | } 53 | 54 | echo 55 | echo "*** Deleting temporary directory" 56 | rm -fr ${AUTOPOINT_TMP_DIR} 57 | 58 | echo 59 | echo "*** Invoking autoreconf" 60 | autoreconf -v -i 61 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([Extract PDFmark], [1.1.1], , [extractpdfmark], 6 | [https://github.com/trueroad/extractpdfmark]) 7 | AM_INIT_AUTOMAKE([foreign]) 8 | AC_CONFIG_SRCDIR([src/main.cc]) 9 | AC_CONFIG_HEADERS([config.h]) 10 | 11 | PACKAGE_COPYRIGHT="Copyright (C) 2016-2022 Masamichi Hosoda" 12 | PACKAGE_LICENSE="License: GPL3+" 13 | 14 | AC_SUBST([PACKAGE_COPYRIGHT]) 15 | AC_SUBST([PACKAGE_LICENSE]) 16 | AC_DEFINE_UNQUOTED([PACKAGE_COPYRIGHT], ["$PACKAGE_COPYRIGHT"], 17 | [Define to the copyright of this package.]) 18 | AC_DEFINE_UNQUOTED([PACKAGE_LICENSE], ["$PACKAGE_LICENSE"], 19 | [Define to the license of this package.]) 20 | 21 | # Checks for programs. 22 | AC_PROG_CXX 23 | AX_CXX_COMPILE_STDCXX_11([noext], [mandatory]) 24 | AC_PROG_RANLIB 25 | AC_PROG_GREP 26 | 27 | AC_PATH_PROG([DIFF], [diff]) 28 | AS_IF([test "x$DIFF" = x], 29 | [AC_MSG_WARN([diff isn't found. `make check' will skip tests.])]) 30 | AC_SUBST([DIFF]) 31 | 32 | AC_PATH_PROG([GHOSTSCRIPT], [gs]) 33 | AS_IF([test ! "x$GHOSTSCRIPT" = x], 34 | [AC_MSG_CHECKING([for gs version ( >= 9.14 )]) 35 | gs_ver=`$GHOSTSCRIPT --version` 36 | AX_COMPARE_VERSION([$gs_ver], [ge], [9.14], 37 | [AC_MSG_RESULT([yes])], 38 | [AC_MSG_RESULT([no]) 39 | GHOSTSCRIPT=])]) 40 | AM_CONDITIONAL([HAVE_GHOSTSCRIPT], [test ! "x$GHOSTSCRIPT" = x]) 41 | AM_COND_IF([HAVE_GHOSTSCRIPT], 42 | , 43 | [AC_MSG_WARN( 44 | [Ghostscript isn't found. `make check' will skip some tests.])]) 45 | AC_SUBST([GHOSTSCRIPT]) 46 | 47 | AC_MSG_CHECKING([for pre-generated test PDFs]) 48 | AS_IF([test ! -e ${srcdir}/test/desttype.pdf], 49 | [AC_MSG_RESULT([no]) 50 | AC_PATH_PROG([PDFTEX], [pdftex]) 51 | AS_IF([test "x$PDFTEX" = x], 52 | [AC_MSG_WARN( 53 | [pdftex isn't found. Test PDFs cannot be generated.]) 54 | AC_MSG_WARN( 55 | [You cannot use `make check'.])], 56 | [AM_COND_IF([HAVE_GHOSTSCRIPT], 57 | [AC_MSG_NOTICE( 58 | [pdftex is found. Test PDFs will be generated.])], 59 | [AC_MSG_WARN( 60 | [pdftex is found but ghostscript isn't found.]) 61 | AC_MSG_WARN( 62 | [You cannot use `make check'.])])])], 63 | [AC_MSG_RESULT([yes])]) 64 | AC_SUBST([PDFTEX]) 65 | 66 | AC_MSG_CHECKING([for pre-generated expected PDFmark files]) 67 | AS_IF([test ! -e ${srcdir}/test/desttype-expected.pdfmark], 68 | [AC_MSG_RESULT([no]) 69 | AC_MSG_WARN( 70 | [PDFmark files will be generated.]) 71 | AC_MSG_WARN( 72 | [`make check' cannot compare with the correct expected results.])], 73 | [AC_MSG_RESULT([yes])]) 74 | 75 | # Checks for libraries. 76 | PKG_PROG_PKG_CONFIG 77 | 78 | AC_ARG_WITH([poppler], 79 | AS_HELP_STRING([--with-poppler=@<:@auto|cpp|glib|core|core-private@:>@], 80 | [Poppler I/F (default: auto)]), 81 | , 82 | [with_poppler=auto]) 83 | AS_CASE(["$with_poppler"], 84 | ["cpp"], 85 | [AC_MSG_NOTICE([--with-poppler=cpp requires poppler >= 0.74.0]) 86 | PKG_CHECK_MODULES([POPPLER_CPP], [poppler-cpp >= 0.74.0])], 87 | ["glib"], 88 | [AC_MSG_NOTICE([--with-poppler=glib requires poppler >= 0.78.0]) 89 | PKG_CHECK_MODULES([POPPLER_GLIB], [poppler-glib >= 0.78.0])], 90 | ["core"], 91 | [AC_MSG_NOTICE( 92 | [--with-poppler=core requires poppler 0.48.0 - 0.75.0]) 93 | PKG_CHECK_MODULES([POPPLER], 94 | [poppler >= 0.48.0 poppler <= 0.75.0])], 95 | ["core-private"], 96 | [AC_MSG_NOTICE( 97 | [--with-poppler=core-private requires poppler 0.13.3 - 0.75.0]) 98 | PKG_CHECK_MODULES([POPPLER], 99 | [poppler >= 0.24.4 poppler <= 0.75.0],, 100 | [PKG_CHECK_MODULES([POPPLER], [poppler >= 0.19.2], 101 | [AC_MSG_WARN([poppler < 0.24.4 is found.]) 102 | AC_MSG_WARN([`make check' will fail some tests.])], 103 | [PKG_CHECK_MODULES([POPPLER], [poppler >= 0.13.3]) 104 | AC_MSG_WARN([poppler < 0.19.2 is found.]) 105 | AC_MSG_WARN([`make check' will fail some tests.]) 106 | AC_DEFINE_UNQUOTED([POPPLER_CORE_IF_VERSION], 107 | ["`$PKG_CONFIG --modversion poppler`"], 108 | [Define poppler version if POPPLER_VERSION cannot be used.])])])], 109 | ["auto"], 110 | [AC_MSG_NOTICE([selecting for --with-poppler=auto]) 111 | AC_MSG_NOTICE([ trying for cpp (poppler-cpp >= 0.74.0)]) 112 | PKG_CHECK_MODULES( 113 | [POPPLER_CPP], [poppler-cpp >= 0.74.0], 114 | [with_poppler="cpp"], 115 | [AC_MSG_NOTICE([ trying for glib (poppler-glib >= 0.78.0)]) 116 | PKG_CHECK_MODULES( 117 | [POPPLER_GLIB], [poppler-glib >= 0.78.0], 118 | [with_poppler="glib"], 119 | [AC_MSG_NOTICE( 120 | [ trying for core (poppler 0.48.0 - 0.75.0)]) 121 | PKG_CHECK_MODULES( 122 | [POPPLER], [poppler >= 0.48.0 poppler <= 0.75.0], 123 | [with_poppler="core"], 124 | [AC_MSG_NOTICE( 125 | [ trying for core-private (poppler >= 0.24.4)]) 126 | PKG_CHECK_MODULES([POPPLER], 127 | [poppler >= 0.24.4 poppler <= 0.75.0], 128 | [with_poppler="core-private"])])])]) 129 | AC_MSG_NOTICE([use --with-poppler=$with_poppler])], 130 | [AC_MSG_ERROR([unrecognized --with-poppler argument: $with_poppler])]) 131 | AS_CASE(["$with_poppler"], 132 | ["cpp"], 133 | [POPPLER_IF="poppler-cpp" 134 | use_library="cpp"], 135 | ["glib"], 136 | [POPPLER_IF="poppler-glib" 137 | use_library="glib"], 138 | ["core"], 139 | [POPPLER_IF="poppler-core" 140 | use_library="core" 141 | AC_DEFINE([HAVE_POPPLER_CORE_IF], [1], 142 | [Define if poppler-core is selected])], 143 | ["core-private"], 144 | [POPPLER_IF="poppler-core private" 145 | use_library="core"], 146 | [AC_MSG_ERROR([programming error])]) 147 | AM_CONDITIONAL([USE_POPPLER_CORE], [test $use_library = core]) 148 | AM_CONDITIONAL([USE_POPPLER_GLIB], [test $use_library = glib]) 149 | AM_CONDITIONAL([USE_POPPLER_CPP], [test $use_library = cpp]) 150 | AC_DEFINE_UNQUOTED([PACKAGE_STRING], ["$PACKAGE_STRING (with $POPPLER_IF)"], 151 | [Define to the full name and version, method of this package.]) 152 | 153 | # Checks for header files. 154 | AM_COND_IF([USE_POPPLER_CORE], 155 | [AC_LANG_PUSH([C++]) 156 | TEMP_CPPFLAGS=$CPPFLAGS 157 | CPPFLAGS="$CPPFLAGS $POPPLER_CFLAGS" 158 | AC_CHECK_HEADERS([Link.h PDFDoc.h PDFDocFactory.h], 159 | , 160 | [AC_MSG_ERROR([poppler xpdf headers are not found.])]) 161 | CPPFLAGS=$TMP_CPPFLAGS 162 | AC_LANG_POP]) 163 | 164 | AC_ARG_ENABLE([codecvt], 165 | [AS_HELP_STRING( 166 | [--enable-codecvt], 167 | [enable codecvt for UTF-8 checking (default is disable)])], 168 | , 169 | [enable_codecvt=no]) 170 | AS_IF([test "x$enable_codecvt" != xno], 171 | [AC_LANG_PUSH([C++]) 172 | AC_CHECK_HEADERS([codecvt]) 173 | AC_LANG_POP]) 174 | AS_IF([test "x$ac_cv_header_codecvt" == xyes], 175 | [AC_DEFINE([USE_CODECVT], [1], [Define if codecvt is enabled.])]) 176 | 177 | AC_ARG_ENABLE([iconv], 178 | [AS_HELP_STRING( 179 | [--disable-iconv], 180 | [disable iconv for UTF-8 checking (default is enable)])], 181 | , 182 | [enable_iconv=yes]) 183 | # AM_ICONV does not seem to be able to put in IF block. 184 | AM_ICONV 185 | AM_CONDITIONAL([USE_ICONV], 186 | [test "x$enable_iconv" = xyes && \ 187 | test "x$am_cv_func_iconv" = xyes && \ 188 | test "x$ac_cv_header_codecvt" != xyes]) 189 | AM_COND_IF([USE_ICONV], 190 | [AC_DEFINE([USE_ICONV], [1], [Define if iconv is enabled.])], 191 | [AS_IF([test "x$ac_cv_header_codecvt" != xyes], 192 | [AC_MSG_WARN( 193 | [Some `make check' will fail since both codecvt and iconv are disabled.])])]) 194 | 195 | # Checks for typedefs, structures, and compiler characteristics. 196 | AM_COND_IF([USE_POPPLER_CORE], 197 | [AC_LANG_PUSH([C++]) 198 | TEMP_CPPFLAGS=$CPPFLAGS 199 | CPPFLAGS="$CPPFLAGS $POPPLER_CFLAGS" 200 | AC_MSG_CHECKING([for poppler's GooString::c_str ()]) 201 | AC_COMPILE_IFELSE( 202 | [AC_LANG_PROGRAM( 203 | [[ #include ]], 204 | [[ GooString goo; const char *dummy = goo.c_str (); ]])], 205 | [AC_MSG_RESULT([yes]) 206 | AC_DEFINE([HAS_GOOSTRING_C_STR], [1], 207 | [Define if poppler's GooString::c_str () exists])], 208 | [AC_MSG_RESULT([no])]) 209 | CPPFLAGS=$TMP_CPPFLAGS 210 | AC_LANG_POP]) 211 | 212 | # Checks for library functions. 213 | 214 | AC_CONFIG_FILES([Makefile 215 | src/Makefile 216 | src/poppler-core/Makefile 217 | src/poppler-glib/Makefile 218 | src/poppler-cpp/Makefile 219 | man/Makefile 220 | test/Makefile]) 221 | AC_OUTPUT 222 | -------------------------------------------------------------------------------- /m4/ax_compare_version.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_compare_version.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # This macro compares two version strings. Due to the various number of 12 | # minor-version numbers that can exist, and the fact that string 13 | # comparisons are not compatible with numeric comparisons, this is not 14 | # necessarily trivial to do in a autoconf script. This macro makes doing 15 | # these comparisons easy. 16 | # 17 | # The six basic comparisons are available, as well as checking equality 18 | # limited to a certain number of minor-version levels. 19 | # 20 | # The operator OP determines what type of comparison to do, and can be one 21 | # of: 22 | # 23 | # eq - equal (test A == B) 24 | # ne - not equal (test A != B) 25 | # le - less than or equal (test A <= B) 26 | # ge - greater than or equal (test A >= B) 27 | # lt - less than (test A < B) 28 | # gt - greater than (test A > B) 29 | # 30 | # Additionally, the eq and ne operator can have a number after it to limit 31 | # the test to that number of minor versions. 32 | # 33 | # eq0 - equal up to the length of the shorter version 34 | # ne0 - not equal up to the length of the shorter version 35 | # eqN - equal up to N sub-version levels 36 | # neN - not equal up to N sub-version levels 37 | # 38 | # When the condition is true, shell commands ACTION-IF-TRUE are run, 39 | # otherwise shell commands ACTION-IF-FALSE are run. The environment 40 | # variable 'ax_compare_version' is always set to either 'true' or 'false' 41 | # as well. 42 | # 43 | # Examples: 44 | # 45 | # AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) 46 | # AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) 47 | # 48 | # would both be true. 49 | # 50 | # AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) 51 | # AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) 52 | # 53 | # would both be false. 54 | # 55 | # AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) 56 | # 57 | # would be true because it is only comparing two minor versions. 58 | # 59 | # AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) 60 | # 61 | # would be true because it is only comparing the lesser number of minor 62 | # versions of the two values. 63 | # 64 | # Note: The characters that separate the version numbers do not matter. An 65 | # empty string is the same as version 0. OP is evaluated by autoconf, not 66 | # configure, so must be a string, not a variable. 67 | # 68 | # The author would like to acknowledge Guido Draheim whose advice about 69 | # the m4_case and m4_ifvaln functions make this macro only include the 70 | # portions necessary to perform the specific comparison specified by the 71 | # OP argument in the final configure script. 72 | # 73 | # LICENSE 74 | # 75 | # Copyright (c) 2008 Tim Toolan 76 | # 77 | # Copying and distribution of this file, with or without modification, are 78 | # permitted in any medium without royalty provided the copyright notice 79 | # and this notice are preserved. This file is offered as-is, without any 80 | # warranty. 81 | 82 | #serial 13 83 | 84 | dnl ######################################################################### 85 | AC_DEFUN([AX_COMPARE_VERSION], [ 86 | AC_REQUIRE([AC_PROG_AWK]) 87 | 88 | # Used to indicate true or false condition 89 | ax_compare_version=false 90 | 91 | # Convert the two version strings to be compared into a format that 92 | # allows a simple string comparison. The end result is that a version 93 | # string of the form 1.12.5-r617 will be converted to the form 94 | # 0001001200050617. In other words, each number is zero padded to four 95 | # digits, and non digits are removed. 96 | AS_VAR_PUSHDEF([A],[ax_compare_version_A]) 97 | A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ 98 | -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ 99 | -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ 100 | -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ 101 | -e 's/[[^0-9]]//g'` 102 | 103 | AS_VAR_PUSHDEF([B],[ax_compare_version_B]) 104 | B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ 105 | -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ 106 | -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ 107 | -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ 108 | -e 's/[[^0-9]]//g'` 109 | 110 | dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary 111 | dnl # then the first line is used to determine if the condition is true. 112 | dnl # The sed right after the echo is to remove any indented white space. 113 | m4_case(m4_tolower($2), 114 | [lt],[ 115 | ax_compare_version=`echo "x$A 116 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` 117 | ], 118 | [gt],[ 119 | ax_compare_version=`echo "x$A 120 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` 121 | ], 122 | [le],[ 123 | ax_compare_version=`echo "x$A 124 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` 125 | ], 126 | [ge],[ 127 | ax_compare_version=`echo "x$A 128 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` 129 | ],[ 130 | dnl Split the operator from the subversion count if present. 131 | m4_bmatch(m4_substr($2,2), 132 | [0],[ 133 | # A count of zero means use the length of the shorter version. 134 | # Determine the number of characters in A and B. 135 | ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` 136 | ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` 137 | 138 | # Set A to no more than B's length and B to no more than A's length. 139 | A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` 140 | B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` 141 | ], 142 | [[0-9]+],[ 143 | # A count greater than zero means use only that many subversions 144 | A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` 145 | B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` 146 | ], 147 | [.+],[ 148 | AC_WARNING( 149 | [invalid OP numeric parameter: $2]) 150 | ],[]) 151 | 152 | # Pad zeros at end of numbers to make same length. 153 | ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" 154 | B="$B`echo $A | sed 's/./0/g'`" 155 | A="$ax_compare_version_tmp_A" 156 | 157 | # Check for equality or inequality as necessary. 158 | m4_case(m4_tolower(m4_substr($2,0,2)), 159 | [eq],[ 160 | test "x$A" = "x$B" && ax_compare_version=true 161 | ], 162 | [ne],[ 163 | test "x$A" != "x$B" && ax_compare_version=true 164 | ],[ 165 | AC_WARNING([invalid OP parameter: $2]) 166 | ]) 167 | ]) 168 | 169 | AS_VAR_POPDEF([A])dnl 170 | AS_VAR_POPDEF([B])dnl 171 | 172 | dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. 173 | if test "$ax_compare_version" = "true" ; then 174 | m4_ifvaln([$4],[$4],[:])dnl 175 | m4_ifvaln([$5],[else $5])dnl 176 | fi 177 | ]) dnl AX_COMPARE_VERSION 178 | -------------------------------------------------------------------------------- /m4/ax_cxx_compile_stdcxx.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the specified 12 | # version of the C++ standard. If necessary, add switches to CXX and 13 | # CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for 14 | # the respective C++ standard version. 15 | # 16 | # The second argument, if specified, indicates whether you insist on an 17 | # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. 18 | # -std=c++11). If neither is specified, you get whatever works, with 19 | # preference for no added switch, and then for an extended mode. 20 | # 21 | # The third argument, if specified 'mandatory' or if left unspecified, 22 | # indicates that baseline support for the specified C++ standard is 23 | # required and that the macro should error out if no mode with that 24 | # support is found. If specified 'optional', then configuration proceeds 25 | # regardless, after defining HAVE_CXX${VERSION} if and only if a 26 | # supporting mode is found. 27 | # 28 | # LICENSE 29 | # 30 | # Copyright (c) 2008 Benjamin Kosnik 31 | # Copyright (c) 2012 Zack Weinberg 32 | # Copyright (c) 2013 Roy Stogner 33 | # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov 34 | # Copyright (c) 2015 Paul Norman 35 | # Copyright (c) 2015 Moritz Klammler 36 | # Copyright (c) 2016, 2018 Krzesimir Nowak 37 | # Copyright (c) 2019 Enji Cooper 38 | # Copyright (c) 2020 Jason Merrill 39 | # Copyright (c) 2021 Jörn Heusipp 40 | # 41 | # Copying and distribution of this file, with or without modification, are 42 | # permitted in any medium without royalty provided the copyright notice 43 | # and this notice are preserved. This file is offered as-is, without any 44 | # warranty. 45 | 46 | #serial 15 47 | 48 | dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro 49 | dnl (serial version number 13). 50 | 51 | AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl 52 | m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"], 53 | [$1], [14], [ax_cxx_compile_alternatives="14 1y"], 54 | [$1], [17], [ax_cxx_compile_alternatives="17 1z"], 55 | [$1], [20], [ax_cxx_compile_alternatives="20"], 56 | [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl 57 | m4_if([$2], [], [], 58 | [$2], [ext], [], 59 | [$2], [noext], [], 60 | [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl 61 | m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], 62 | [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], 63 | [$3], [optional], [ax_cxx_compile_cxx$1_required=false], 64 | [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) 65 | AC_LANG_PUSH([C++])dnl 66 | ac_success=no 67 | 68 | m4_if([$2], [], [dnl 69 | AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, 70 | ax_cv_cxx_compile_cxx$1, 71 | [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 72 | [ax_cv_cxx_compile_cxx$1=yes], 73 | [ax_cv_cxx_compile_cxx$1=no])]) 74 | if test x$ax_cv_cxx_compile_cxx$1 = xyes; then 75 | ac_success=yes 76 | fi]) 77 | 78 | m4_if([$2], [noext], [], [dnl 79 | if test x$ac_success = xno; then 80 | for alternative in ${ax_cxx_compile_alternatives}; do 81 | switch="-std=gnu++${alternative}" 82 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) 83 | AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, 84 | $cachevar, 85 | [ac_save_CXX="$CXX" 86 | CXX="$CXX $switch" 87 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 88 | [eval $cachevar=yes], 89 | [eval $cachevar=no]) 90 | CXX="$ac_save_CXX"]) 91 | if eval test x\$$cachevar = xyes; then 92 | CXX="$CXX $switch" 93 | if test -n "$CXXCPP" ; then 94 | CXXCPP="$CXXCPP $switch" 95 | fi 96 | ac_success=yes 97 | break 98 | fi 99 | done 100 | fi]) 101 | 102 | m4_if([$2], [ext], [], [dnl 103 | if test x$ac_success = xno; then 104 | dnl HP's aCC needs +std=c++11 according to: 105 | dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf 106 | dnl Cray's crayCC needs "-h std=c++11" 107 | for alternative in ${ax_cxx_compile_alternatives}; do 108 | for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do 109 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) 110 | AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, 111 | $cachevar, 112 | [ac_save_CXX="$CXX" 113 | CXX="$CXX $switch" 114 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 115 | [eval $cachevar=yes], 116 | [eval $cachevar=no]) 117 | CXX="$ac_save_CXX"]) 118 | if eval test x\$$cachevar = xyes; then 119 | CXX="$CXX $switch" 120 | if test -n "$CXXCPP" ; then 121 | CXXCPP="$CXXCPP $switch" 122 | fi 123 | ac_success=yes 124 | break 125 | fi 126 | done 127 | if test x$ac_success = xyes; then 128 | break 129 | fi 130 | done 131 | fi]) 132 | AC_LANG_POP([C++]) 133 | if test x$ax_cxx_compile_cxx$1_required = xtrue; then 134 | if test x$ac_success = xno; then 135 | AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) 136 | fi 137 | fi 138 | if test x$ac_success = xno; then 139 | HAVE_CXX$1=0 140 | AC_MSG_NOTICE([No compiler with C++$1 support was found]) 141 | else 142 | HAVE_CXX$1=1 143 | AC_DEFINE(HAVE_CXX$1,1, 144 | [define if the compiler supports basic C++$1 syntax]) 145 | fi 146 | AC_SUBST(HAVE_CXX$1) 147 | ]) 148 | 149 | 150 | dnl Test body for checking C++11 support 151 | 152 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], 153 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 154 | ) 155 | 156 | dnl Test body for checking C++14 support 157 | 158 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], 159 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 160 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 161 | ) 162 | 163 | dnl Test body for checking C++17 support 164 | 165 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], 166 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 167 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 168 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 169 | ) 170 | 171 | dnl Test body for checking C++20 support 172 | 173 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20], 174 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 175 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 176 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 177 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_20 178 | ) 179 | 180 | 181 | dnl Tests for new features in C++11 182 | 183 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ 184 | 185 | // If the compiler admits that it is not ready for C++11, why torture it? 186 | // Hopefully, this will speed up the test. 187 | 188 | #ifndef __cplusplus 189 | 190 | #error "This is not a C++ compiler" 191 | 192 | // MSVC always sets __cplusplus to 199711L in older versions; newer versions 193 | // only set it correctly if /Zc:__cplusplus is specified as well as a 194 | // /std:c++NN switch: 195 | // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ 196 | #elif __cplusplus < 201103L && !defined _MSC_VER 197 | 198 | #error "This is not a C++11 compiler" 199 | 200 | #else 201 | 202 | namespace cxx11 203 | { 204 | 205 | namespace test_static_assert 206 | { 207 | 208 | template 209 | struct check 210 | { 211 | static_assert(sizeof(int) <= sizeof(T), "not big enough"); 212 | }; 213 | 214 | } 215 | 216 | namespace test_final_override 217 | { 218 | 219 | struct Base 220 | { 221 | virtual ~Base() {} 222 | virtual void f() {} 223 | }; 224 | 225 | struct Derived : public Base 226 | { 227 | virtual ~Derived() override {} 228 | virtual void f() override {} 229 | }; 230 | 231 | } 232 | 233 | namespace test_double_right_angle_brackets 234 | { 235 | 236 | template < typename T > 237 | struct check {}; 238 | 239 | typedef check single_type; 240 | typedef check> double_type; 241 | typedef check>> triple_type; 242 | typedef check>>> quadruple_type; 243 | 244 | } 245 | 246 | namespace test_decltype 247 | { 248 | 249 | int 250 | f() 251 | { 252 | int a = 1; 253 | decltype(a) b = 2; 254 | return a + b; 255 | } 256 | 257 | } 258 | 259 | namespace test_type_deduction 260 | { 261 | 262 | template < typename T1, typename T2 > 263 | struct is_same 264 | { 265 | static const bool value = false; 266 | }; 267 | 268 | template < typename T > 269 | struct is_same 270 | { 271 | static const bool value = true; 272 | }; 273 | 274 | template < typename T1, typename T2 > 275 | auto 276 | add(T1 a1, T2 a2) -> decltype(a1 + a2) 277 | { 278 | return a1 + a2; 279 | } 280 | 281 | int 282 | test(const int c, volatile int v) 283 | { 284 | static_assert(is_same::value == true, ""); 285 | static_assert(is_same::value == false, ""); 286 | static_assert(is_same::value == false, ""); 287 | auto ac = c; 288 | auto av = v; 289 | auto sumi = ac + av + 'x'; 290 | auto sumf = ac + av + 1.0; 291 | static_assert(is_same::value == true, ""); 292 | static_assert(is_same::value == true, ""); 293 | static_assert(is_same::value == true, ""); 294 | static_assert(is_same::value == false, ""); 295 | static_assert(is_same::value == true, ""); 296 | return (sumf > 0.0) ? sumi : add(c, v); 297 | } 298 | 299 | } 300 | 301 | namespace test_noexcept 302 | { 303 | 304 | int f() { return 0; } 305 | int g() noexcept { return 0; } 306 | 307 | static_assert(noexcept(f()) == false, ""); 308 | static_assert(noexcept(g()) == true, ""); 309 | 310 | } 311 | 312 | namespace test_constexpr 313 | { 314 | 315 | template < typename CharT > 316 | unsigned long constexpr 317 | strlen_c_r(const CharT *const s, const unsigned long acc) noexcept 318 | { 319 | return *s ? strlen_c_r(s + 1, acc + 1) : acc; 320 | } 321 | 322 | template < typename CharT > 323 | unsigned long constexpr 324 | strlen_c(const CharT *const s) noexcept 325 | { 326 | return strlen_c_r(s, 0UL); 327 | } 328 | 329 | static_assert(strlen_c("") == 0UL, ""); 330 | static_assert(strlen_c("1") == 1UL, ""); 331 | static_assert(strlen_c("example") == 7UL, ""); 332 | static_assert(strlen_c("another\0example") == 7UL, ""); 333 | 334 | } 335 | 336 | namespace test_rvalue_references 337 | { 338 | 339 | template < int N > 340 | struct answer 341 | { 342 | static constexpr int value = N; 343 | }; 344 | 345 | answer<1> f(int&) { return answer<1>(); } 346 | answer<2> f(const int&) { return answer<2>(); } 347 | answer<3> f(int&&) { return answer<3>(); } 348 | 349 | void 350 | test() 351 | { 352 | int i = 0; 353 | const int c = 0; 354 | static_assert(decltype(f(i))::value == 1, ""); 355 | static_assert(decltype(f(c))::value == 2, ""); 356 | static_assert(decltype(f(0))::value == 3, ""); 357 | } 358 | 359 | } 360 | 361 | namespace test_uniform_initialization 362 | { 363 | 364 | struct test 365 | { 366 | static const int zero {}; 367 | static const int one {1}; 368 | }; 369 | 370 | static_assert(test::zero == 0, ""); 371 | static_assert(test::one == 1, ""); 372 | 373 | } 374 | 375 | namespace test_lambdas 376 | { 377 | 378 | void 379 | test1() 380 | { 381 | auto lambda1 = [](){}; 382 | auto lambda2 = lambda1; 383 | lambda1(); 384 | lambda2(); 385 | } 386 | 387 | int 388 | test2() 389 | { 390 | auto a = [](int i, int j){ return i + j; }(1, 2); 391 | auto b = []() -> int { return '0'; }(); 392 | auto c = [=](){ return a + b; }(); 393 | auto d = [&](){ return c; }(); 394 | auto e = [a, &b](int x) mutable { 395 | const auto identity = [](int y){ return y; }; 396 | for (auto i = 0; i < a; ++i) 397 | a += b--; 398 | return x + identity(a + b); 399 | }(0); 400 | return a + b + c + d + e; 401 | } 402 | 403 | int 404 | test3() 405 | { 406 | const auto nullary = [](){ return 0; }; 407 | const auto unary = [](int x){ return x; }; 408 | using nullary_t = decltype(nullary); 409 | using unary_t = decltype(unary); 410 | const auto higher1st = [](nullary_t f){ return f(); }; 411 | const auto higher2nd = [unary](nullary_t f1){ 412 | return [unary, f1](unary_t f2){ return f2(unary(f1())); }; 413 | }; 414 | return higher1st(nullary) + higher2nd(nullary)(unary); 415 | } 416 | 417 | } 418 | 419 | namespace test_variadic_templates 420 | { 421 | 422 | template 423 | struct sum; 424 | 425 | template 426 | struct sum 427 | { 428 | static constexpr auto value = N0 + sum::value; 429 | }; 430 | 431 | template <> 432 | struct sum<> 433 | { 434 | static constexpr auto value = 0; 435 | }; 436 | 437 | static_assert(sum<>::value == 0, ""); 438 | static_assert(sum<1>::value == 1, ""); 439 | static_assert(sum<23>::value == 23, ""); 440 | static_assert(sum<1, 2>::value == 3, ""); 441 | static_assert(sum<5, 5, 11>::value == 21, ""); 442 | static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); 443 | 444 | } 445 | 446 | // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae 447 | // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function 448 | // because of this. 449 | namespace test_template_alias_sfinae 450 | { 451 | 452 | struct foo {}; 453 | 454 | template 455 | using member = typename T::member_type; 456 | 457 | template 458 | void func(...) {} 459 | 460 | template 461 | void func(member*) {} 462 | 463 | void test(); 464 | 465 | void test() { func(0); } 466 | 467 | } 468 | 469 | } // namespace cxx11 470 | 471 | #endif // __cplusplus >= 201103L 472 | 473 | ]]) 474 | 475 | 476 | dnl Tests for new features in C++14 477 | 478 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ 479 | 480 | // If the compiler admits that it is not ready for C++14, why torture it? 481 | // Hopefully, this will speed up the test. 482 | 483 | #ifndef __cplusplus 484 | 485 | #error "This is not a C++ compiler" 486 | 487 | #elif __cplusplus < 201402L && !defined _MSC_VER 488 | 489 | #error "This is not a C++14 compiler" 490 | 491 | #else 492 | 493 | namespace cxx14 494 | { 495 | 496 | namespace test_polymorphic_lambdas 497 | { 498 | 499 | int 500 | test() 501 | { 502 | const auto lambda = [](auto&&... args){ 503 | const auto istiny = [](auto x){ 504 | return (sizeof(x) == 1UL) ? 1 : 0; 505 | }; 506 | const int aretiny[] = { istiny(args)... }; 507 | return aretiny[0]; 508 | }; 509 | return lambda(1, 1L, 1.0f, '1'); 510 | } 511 | 512 | } 513 | 514 | namespace test_binary_literals 515 | { 516 | 517 | constexpr auto ivii = 0b0000000000101010; 518 | static_assert(ivii == 42, "wrong value"); 519 | 520 | } 521 | 522 | namespace test_generalized_constexpr 523 | { 524 | 525 | template < typename CharT > 526 | constexpr unsigned long 527 | strlen_c(const CharT *const s) noexcept 528 | { 529 | auto length = 0UL; 530 | for (auto p = s; *p; ++p) 531 | ++length; 532 | return length; 533 | } 534 | 535 | static_assert(strlen_c("") == 0UL, ""); 536 | static_assert(strlen_c("x") == 1UL, ""); 537 | static_assert(strlen_c("test") == 4UL, ""); 538 | static_assert(strlen_c("another\0test") == 7UL, ""); 539 | 540 | } 541 | 542 | namespace test_lambda_init_capture 543 | { 544 | 545 | int 546 | test() 547 | { 548 | auto x = 0; 549 | const auto lambda1 = [a = x](int b){ return a + b; }; 550 | const auto lambda2 = [a = lambda1(x)](){ return a; }; 551 | return lambda2(); 552 | } 553 | 554 | } 555 | 556 | namespace test_digit_separators 557 | { 558 | 559 | constexpr auto ten_million = 100'000'000; 560 | static_assert(ten_million == 100000000, ""); 561 | 562 | } 563 | 564 | namespace test_return_type_deduction 565 | { 566 | 567 | auto f(int& x) { return x; } 568 | decltype(auto) g(int& x) { return x; } 569 | 570 | template < typename T1, typename T2 > 571 | struct is_same 572 | { 573 | static constexpr auto value = false; 574 | }; 575 | 576 | template < typename T > 577 | struct is_same 578 | { 579 | static constexpr auto value = true; 580 | }; 581 | 582 | int 583 | test() 584 | { 585 | auto x = 0; 586 | static_assert(is_same::value, ""); 587 | static_assert(is_same::value, ""); 588 | return x; 589 | } 590 | 591 | } 592 | 593 | } // namespace cxx14 594 | 595 | #endif // __cplusplus >= 201402L 596 | 597 | ]]) 598 | 599 | 600 | dnl Tests for new features in C++17 601 | 602 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ 603 | 604 | // If the compiler admits that it is not ready for C++17, why torture it? 605 | // Hopefully, this will speed up the test. 606 | 607 | #ifndef __cplusplus 608 | 609 | #error "This is not a C++ compiler" 610 | 611 | #elif __cplusplus < 201703L && !defined _MSC_VER 612 | 613 | #error "This is not a C++17 compiler" 614 | 615 | #else 616 | 617 | #include 618 | #include 619 | #include 620 | 621 | namespace cxx17 622 | { 623 | 624 | namespace test_constexpr_lambdas 625 | { 626 | 627 | constexpr int foo = [](){return 42;}(); 628 | 629 | } 630 | 631 | namespace test::nested_namespace::definitions 632 | { 633 | 634 | } 635 | 636 | namespace test_fold_expression 637 | { 638 | 639 | template 640 | int multiply(Args... args) 641 | { 642 | return (args * ... * 1); 643 | } 644 | 645 | template 646 | bool all(Args... args) 647 | { 648 | return (args && ...); 649 | } 650 | 651 | } 652 | 653 | namespace test_extended_static_assert 654 | { 655 | 656 | static_assert (true); 657 | 658 | } 659 | 660 | namespace test_auto_brace_init_list 661 | { 662 | 663 | auto foo = {5}; 664 | auto bar {5}; 665 | 666 | static_assert(std::is_same, decltype(foo)>::value); 667 | static_assert(std::is_same::value); 668 | } 669 | 670 | namespace test_typename_in_template_template_parameter 671 | { 672 | 673 | template typename X> struct D; 674 | 675 | } 676 | 677 | namespace test_fallthrough_nodiscard_maybe_unused_attributes 678 | { 679 | 680 | int f1() 681 | { 682 | return 42; 683 | } 684 | 685 | [[nodiscard]] int f2() 686 | { 687 | [[maybe_unused]] auto unused = f1(); 688 | 689 | switch (f1()) 690 | { 691 | case 17: 692 | f1(); 693 | [[fallthrough]]; 694 | case 42: 695 | f1(); 696 | } 697 | return f1(); 698 | } 699 | 700 | } 701 | 702 | namespace test_extended_aggregate_initialization 703 | { 704 | 705 | struct base1 706 | { 707 | int b1, b2 = 42; 708 | }; 709 | 710 | struct base2 711 | { 712 | base2() { 713 | b3 = 42; 714 | } 715 | int b3; 716 | }; 717 | 718 | struct derived : base1, base2 719 | { 720 | int d; 721 | }; 722 | 723 | derived d1 {{1, 2}, {}, 4}; // full initialization 724 | derived d2 {{}, {}, 4}; // value-initialized bases 725 | 726 | } 727 | 728 | namespace test_general_range_based_for_loop 729 | { 730 | 731 | struct iter 732 | { 733 | int i; 734 | 735 | int& operator* () 736 | { 737 | return i; 738 | } 739 | 740 | const int& operator* () const 741 | { 742 | return i; 743 | } 744 | 745 | iter& operator++() 746 | { 747 | ++i; 748 | return *this; 749 | } 750 | }; 751 | 752 | struct sentinel 753 | { 754 | int i; 755 | }; 756 | 757 | bool operator== (const iter& i, const sentinel& s) 758 | { 759 | return i.i == s.i; 760 | } 761 | 762 | bool operator!= (const iter& i, const sentinel& s) 763 | { 764 | return !(i == s); 765 | } 766 | 767 | struct range 768 | { 769 | iter begin() const 770 | { 771 | return {0}; 772 | } 773 | 774 | sentinel end() const 775 | { 776 | return {5}; 777 | } 778 | }; 779 | 780 | void f() 781 | { 782 | range r {}; 783 | 784 | for (auto i : r) 785 | { 786 | [[maybe_unused]] auto v = i; 787 | } 788 | } 789 | 790 | } 791 | 792 | namespace test_lambda_capture_asterisk_this_by_value 793 | { 794 | 795 | struct t 796 | { 797 | int i; 798 | int foo() 799 | { 800 | return [*this]() 801 | { 802 | return i; 803 | }(); 804 | } 805 | }; 806 | 807 | } 808 | 809 | namespace test_enum_class_construction 810 | { 811 | 812 | enum class byte : unsigned char 813 | {}; 814 | 815 | byte foo {42}; 816 | 817 | } 818 | 819 | namespace test_constexpr_if 820 | { 821 | 822 | template 823 | int f () 824 | { 825 | if constexpr(cond) 826 | { 827 | return 13; 828 | } 829 | else 830 | { 831 | return 42; 832 | } 833 | } 834 | 835 | } 836 | 837 | namespace test_selection_statement_with_initializer 838 | { 839 | 840 | int f() 841 | { 842 | return 13; 843 | } 844 | 845 | int f2() 846 | { 847 | if (auto i = f(); i > 0) 848 | { 849 | return 3; 850 | } 851 | 852 | switch (auto i = f(); i + 4) 853 | { 854 | case 17: 855 | return 2; 856 | 857 | default: 858 | return 1; 859 | } 860 | } 861 | 862 | } 863 | 864 | namespace test_template_argument_deduction_for_class_templates 865 | { 866 | 867 | template 868 | struct pair 869 | { 870 | pair (T1 p1, T2 p2) 871 | : m1 {p1}, 872 | m2 {p2} 873 | {} 874 | 875 | T1 m1; 876 | T2 m2; 877 | }; 878 | 879 | void f() 880 | { 881 | [[maybe_unused]] auto p = pair{13, 42u}; 882 | } 883 | 884 | } 885 | 886 | namespace test_non_type_auto_template_parameters 887 | { 888 | 889 | template 890 | struct B 891 | {}; 892 | 893 | B<5> b1; 894 | B<'a'> b2; 895 | 896 | } 897 | 898 | namespace test_structured_bindings 899 | { 900 | 901 | int arr[2] = { 1, 2 }; 902 | std::pair pr = { 1, 2 }; 903 | 904 | auto f1() -> int(&)[2] 905 | { 906 | return arr; 907 | } 908 | 909 | auto f2() -> std::pair& 910 | { 911 | return pr; 912 | } 913 | 914 | struct S 915 | { 916 | int x1 : 2; 917 | volatile double y1; 918 | }; 919 | 920 | S f3() 921 | { 922 | return {}; 923 | } 924 | 925 | auto [ x1, y1 ] = f1(); 926 | auto& [ xr1, yr1 ] = f1(); 927 | auto [ x2, y2 ] = f2(); 928 | auto& [ xr2, yr2 ] = f2(); 929 | const auto [ x3, y3 ] = f3(); 930 | 931 | } 932 | 933 | namespace test_exception_spec_type_system 934 | { 935 | 936 | struct Good {}; 937 | struct Bad {}; 938 | 939 | void g1() noexcept; 940 | void g2(); 941 | 942 | template 943 | Bad 944 | f(T*, T*); 945 | 946 | template 947 | Good 948 | f(T1*, T2*); 949 | 950 | static_assert (std::is_same_v); 951 | 952 | } 953 | 954 | namespace test_inline_variables 955 | { 956 | 957 | template void f(T) 958 | {} 959 | 960 | template inline T g(T) 961 | { 962 | return T{}; 963 | } 964 | 965 | template<> inline void f<>(int) 966 | {} 967 | 968 | template<> int g<>(int) 969 | { 970 | return 5; 971 | } 972 | 973 | } 974 | 975 | } // namespace cxx17 976 | 977 | #endif // __cplusplus < 201703L && !defined _MSC_VER 978 | 979 | ]]) 980 | 981 | 982 | dnl Tests for new features in C++20 983 | 984 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[ 985 | 986 | #ifndef __cplusplus 987 | 988 | #error "This is not a C++ compiler" 989 | 990 | #elif __cplusplus < 202002L && !defined _MSC_VER 991 | 992 | #error "This is not a C++20 compiler" 993 | 994 | #else 995 | 996 | #include 997 | 998 | namespace cxx20 999 | { 1000 | 1001 | // As C++20 supports feature test macros in the standard, there is no 1002 | // immediate need to actually test for feature availability on the 1003 | // Autoconf side. 1004 | 1005 | } // namespace cxx20 1006 | 1007 | #endif // __cplusplus < 202002L && !defined _MSC_VER 1008 | 1009 | ]]) 1010 | -------------------------------------------------------------------------------- /m4/ax_cxx_compile_stdcxx_11.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html 3 | # ============================================================================= 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the C++11 12 | # standard; if necessary, add switches to CXX and CXXCPP to enable 13 | # support. 14 | # 15 | # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX 16 | # macro with the version set to C++11. The two optional arguments are 17 | # forwarded literally as the second and third argument respectively. 18 | # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for 19 | # more information. If you want to use this macro, you also need to 20 | # download the ax_cxx_compile_stdcxx.m4 file. 21 | # 22 | # LICENSE 23 | # 24 | # Copyright (c) 2008 Benjamin Kosnik 25 | # Copyright (c) 2012 Zack Weinberg 26 | # Copyright (c) 2013 Roy Stogner 27 | # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov 28 | # Copyright (c) 2015 Paul Norman 29 | # Copyright (c) 2015 Moritz Klammler 30 | # 31 | # Copying and distribution of this file, with or without modification, are 32 | # permitted in any medium without royalty provided the copyright notice 33 | # and this notice are preserved. This file is offered as-is, without any 34 | # warranty. 35 | 36 | #serial 18 37 | 38 | AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) 39 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) 40 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = extractpdfmark.1 2 | EXTRA_DIST = $(man_MANS) 3 | -------------------------------------------------------------------------------- /man/extractpdfmark.1: -------------------------------------------------------------------------------- 1 | .TH EXTRACTPDFMARK 1 "January 26, 2019" 2 | .SH NAME 3 | extractpdfmark \- Extract page mode and named destinations as PDFmark from PDF 4 | .SH SYNOPSIS 5 | .B extractpdfmark 6 | .IR file.pdf " > " file.ps 7 | .SH DESCRIPTION 8 | This manual page documents briefly the 9 | .B extractpdfmark 10 | command. 11 | .PP 12 | When you create a PDF document using a TeX system, you may include 13 | many small PDF files in the main PDF file. 14 | It is common for each of those files to use the same fonts. 15 | .PP 16 | If the small PDF files contain embedded font subsets, the TeX system 17 | includes them as-is in the main PDF. 18 | As a result, several subsets of the same font are embedded in the main PDF. 19 | It is not possible to remove the duplicates since the subsets differ. 20 | This vastly increases the size of the main PDF file. 21 | .PP 22 | On the other hand, if the small PDF files contain embedded full font 23 | sets, the TeX system also includes all of them in the main PDF. 24 | This time, the main PDF contains duplicates of the same full sets of 25 | fonts. 26 | Therefore, Ghostscript can remove the duplicates. 27 | This may considerably reduce the main PDF\-file's size. 28 | (Note: Ghostscript 9.17 - 9.21 needs 29 | .I -dPDFDontUseFontObjectNum 30 | commandline option for removing duplicate fonts. 31 | If you use Ghostscript 9.22+, you cannot use this "full set embedding" method 32 | since it cannot remove duplicate fonts. 33 | In this case, you can use "*not* embedding" method as following.) 34 | .PP 35 | Finally, if the small PDF files contain some fonts that are not 36 | embedded, the TeX system outputs the main PDF file with some fonts 37 | missing. 38 | In this case, Ghostscript can embed the necessary fonts. 39 | It can also significantly reduce the required disk size. 40 | .PP 41 | Either way, when Ghostscript reads the main PDF produced by the 42 | TeX system and outputs the final PDF it does not preserve PDF 43 | page\-mode and named\-destinations, etc. 44 | As a result, when you open the final PDF, it is not displayed correctly. 45 | Also, remote PDF links will not work. 46 | .PP 47 | This program is able to extract the page mode and named destinations 48 | as PDFmark from PDF. 49 | By using this you can get the small PDF files that have preserved them. 50 | .SH EXAMPLE 51 | .EX 52 | $ extractpdfmark TeX-System-Outputted.pdf > Extracted-PDFmark.ps 53 | $ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \e 54 | -dPDFDontUseFontObjectNum -dPrinted=false \e 55 | -sOutputFile=Final.pdf \e 56 | TeX-System-Outputted.pdf Extracted-PDFmark.ps 57 | .EE 58 | .PP 59 | (Note: Ghostscript 9.26+ needs 60 | .I -dPrinted=false 61 | commandline option.) 62 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = 2 | 3 | bin_PROGRAMS = extractpdfmark 4 | extractpdfmark_SOURCES = main.cc cmdlineparse.hh \ 5 | output-pdfmark.cc output-pdfmark.hh \ 6 | encodename.cc \ 7 | utf16.cc utf16.hh \ 8 | utf8.cc utf8.hh 9 | 10 | extractpdfmark_LDADD = 11 | extractpdfmark_LDFLAGS = 12 | extractpdfmark_DEPENDENCIES = 13 | 14 | if USE_POPPLER_CORE 15 | SUBDIRS += poppler-core 16 | extractpdfmark_LDADD += -lextractpdfmark-poppler-core $(POPPLER_LIBS) 17 | extractpdfmark_LDFLAGS += -L./poppler-core 18 | extractpdfmark_DEPENDENCIES += ./poppler-core/libextractpdfmark-poppler-core.a 19 | endif 20 | 21 | if USE_POPPLER_GLIB 22 | SUBDIRS += poppler-glib 23 | extractpdfmark_LDADD += -lextractpdfmark-poppler-glib $(POPPLER_GLIB_LIBS) 24 | extractpdfmark_LDFLAGS += -L./poppler-glib 25 | extractpdfmark_DEPENDENCIES += ./poppler-glib/libextractpdfmark-poppler-glib.a 26 | endif 27 | 28 | if USE_POPPLER_CPP 29 | SUBDIRS += poppler-cpp 30 | extractpdfmark_LDADD += -lextractpdfmark-poppler-cpp $(POPPLER_CPP_LIBS) 31 | extractpdfmark_LDFLAGS += -L./poppler-cpp 32 | extractpdfmark_DEPENDENCIES += ./poppler-cpp/libextractpdfmark-poppler-cpp.a 33 | endif 34 | 35 | if USE_ICONV 36 | extractpdfmark_SOURCES += iconv_wrapper.hh 37 | extractpdfmark_LDADD += $(LIBICONV) 38 | endif 39 | -------------------------------------------------------------------------------- /src/cmdlineparse.hh: -------------------------------------------------------------------------------- 1 | // 2 | // One header file Commandline Parse for C++11 2017-01-29.01 GPL 3 | // https://github.com/trueroad/cmdlineparse/ 4 | // 5 | // Copyright (C) 2016, 2017 Masamichi Hosoda 6 | // 7 | // One header file Commandline Parse for C++11 is free software: 8 | // you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // One header file Commandline Parse for C++11 is distributed 14 | // in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU General Public License 20 | // along with One header file Commandline Parse for C++11. 21 | // If not, see . 22 | // 23 | 24 | #ifndef INCLUDE_GUARD_CMDLINEPARSE_HH 25 | #define INCLUDE_GUARD_CMDLINEPARSE_HH 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // gettext macros 35 | #ifndef _ 36 | 37 | #define _(DUMMY) DUMMY 38 | #define CMDLINEPARSE_HH_DEFINE_DUMMY_GETTEXT 39 | 40 | #endif 41 | 42 | namespace cmdlineparse 43 | { 44 | 45 | enum class arg_mode 46 | { 47 | no_argument = 0, 48 | required_argument = 1, 49 | optional_argument = 2 50 | }; 51 | 52 | enum class abort_reason 53 | { 54 | option_handler = -1, 55 | no_abort = 0, 56 | error_extra_arg, 57 | error_no_arg, 58 | error_ambiguous_option, 59 | error_unknown_option, 60 | error_no_arg_short, 61 | error_unknown_option_short, 62 | }; 63 | 64 | class parser 65 | { 66 | public: 67 | // Add an option handler 68 | bool add_handler (char short_name, const std::string &long_name, 69 | arg_mode has_arg, 70 | std::function option_handler, 71 | const std::string &description = "", 72 | const std::string &typestr = "", 73 | const std::string &header = "", 74 | const std::string &group = ""); 75 | 76 | // Add a flag option 77 | bool add_flag (char short_name, const std::string &long_name, 78 | bool *flag, 79 | const std::string &description = "", 80 | const std::string &group = ""); 81 | 82 | // Add a string option 83 | bool add_string (char short_name, const std::string &long_name, 84 | std::string *var, const std::string &defval, 85 | const std::string &description = "", 86 | const std::string &typestr = "STRING", 87 | const std::string &group = ""); 88 | 89 | // Add help description 90 | void add_description (char short_name, const std::string &long_name, 91 | arg_mode has_arg, 92 | const std::string &description, 93 | const std::string &typestr = "", 94 | const std::string &header = "", 95 | const std::string &group = ""); 96 | 97 | // Add default handler 98 | bool add_default_help (void); 99 | bool add_default_version (void); 100 | bool add_default (void) 101 | { 102 | if (!add_default_help ()) 103 | return false; 104 | return add_default_version (); 105 | } 106 | 107 | // Parse options 108 | bool parse (int argc, char const* const* argv, int optind = 1); 109 | 110 | // Build default strings 111 | std::string build_usage (void) const; 112 | std::string build_help (void) const; 113 | 114 | // Get version_string 115 | const std::string &get_version_string () const noexcept 116 | { 117 | return version_string; 118 | } 119 | 120 | // Set version_string 121 | void set_version_string (const std::string &s) 122 | { 123 | version_string = s; 124 | } 125 | 126 | // Get unamed_args 127 | const std::vector &get_unamed_args () const noexcept 128 | { 129 | return unamed_args; 130 | } 131 | 132 | // Set usage_unamed_opts 133 | void set_usage_unamed_opts (const std::string &s) 134 | { 135 | usage_unamed_opts = s; 136 | } 137 | 138 | // Get abort reason 139 | abort_reason get_abort_reason () const noexcept 140 | { 141 | return abort; 142 | } 143 | 144 | // Get abort option 145 | const std::string &get_abort_option () const noexcept 146 | { 147 | return abort_option; 148 | } 149 | 150 | // Set opterr 151 | void set_opterr (bool flag) noexcept 152 | { 153 | opterr = flag; 154 | } 155 | 156 | // Set long_only 157 | void set_long_only (bool flag) noexcept 158 | { 159 | long_only = flag; 160 | } 161 | 162 | // Set continue_on_error 163 | void set_continue_on_error (bool flag) noexcept 164 | { 165 | continue_on_error = flag; 166 | } 167 | 168 | // Set abbreviated_long_name 169 | void set_abbreviated_long_name (bool flag) noexcept 170 | { 171 | abbreviated_long_name = flag; 172 | } 173 | 174 | // Constructor 175 | parser (); 176 | 177 | // Const 178 | const std::string h_indent {" "}; 179 | const std::string h_space {" "}; 180 | const std::string d_indent {" "}; 181 | 182 | private: 183 | // Internal functions 184 | void add_short (char short_name, arg_mode has_arg, 185 | std::function option_handler); 186 | void add_long (const std::string &long_name, arg_mode has_arg, 187 | std::function option_handler); 188 | bool find_unique_long_name (const std::string &long_name, 189 | std::pair> 191 | *target, 192 | bool *ambiguous); 193 | bool parse_long_name (std::vector::const_iterator *it); 194 | bool parse_short_name (std::vector::const_iterator *it); 195 | 196 | // Error handlers 197 | std::function error_extra_arg 199 | { 200 | [this](const std::string &long_name, const std::string &)->bool 201 | { 202 | if (opterr) 203 | std::cerr << argvs[0] 204 | << _(": option doesn't take an argument -- ") 205 | << long_name << std::endl; 206 | return continue_on_error; 207 | } 208 | }; 209 | std::function error_no_arg 210 | { 211 | [this](const std::string &long_name)->bool 212 | { 213 | if (opterr) 214 | std::cerr << argvs[0] 215 | << _(": option requires an argument -- ") 216 | << long_name << std::endl; 217 | return continue_on_error; 218 | } 219 | }; 220 | std::function error_ambiguous_option 221 | { 222 | [this](const std::string &optchars)->bool 223 | { 224 | if (opterr) 225 | std::cerr << argvs[0] 226 | << _(": ambiguous option -- ") 227 | << optchars << std::endl; 228 | return continue_on_error; 229 | } 230 | }; 231 | std::function error_unknown_option 232 | { 233 | [this](const std::string &optchars)->bool 234 | { 235 | if (opterr) 236 | std::cerr << argvs[0] 237 | << _(": unknown option -- ") 238 | << optchars << std::endl; 239 | return continue_on_error; 240 | } 241 | }; 242 | std::function error_no_arg_short 243 | { 244 | [this](char optchar)->bool 245 | { 246 | if (opterr) 247 | std::cerr << argvs[0] 248 | << _(": option requires an argument -- ") 249 | << optchar << std::endl; 250 | return continue_on_error; 251 | } 252 | }; 253 | std::function error_unknown_option_short 254 | { 255 | [this](char optchar)->bool 256 | { 257 | if (opterr) 258 | std::cerr << argvs[0] 259 | << _(": unknown option -- ") 260 | << optchar << std::endl; 261 | return continue_on_error; 262 | } 263 | }; 264 | 265 | // Help strings 266 | std::string version_string; 267 | std::string usage_unamed_opts; 268 | 269 | // Flags 270 | bool opterr {true}; 271 | bool continue_on_error {false}; 272 | bool long_only {false}; 273 | bool abbreviated_long_name {true}; 274 | 275 | // Abort reason 276 | abort_reason abort {abort_reason::no_abort}; 277 | std::string abort_option; 278 | 279 | // Arguments 280 | std::vector argvs; 281 | std::vector unamed_args; 282 | 283 | // Maps 284 | std::map>> short_map; 287 | std::map>> long_map; 290 | std::map> help_map; 291 | }; 292 | 293 | inline 294 | parser::parser () 295 | { 296 | #ifdef PACKAGE_STRING 297 | // Build version_string 298 | std::stringstream ss; 299 | ss << PACKAGE_STRING << std::endl; 300 | 301 | #ifdef PACKAGE_COPYRIGHT 302 | ss << PACKAGE_COPYRIGHT << std::endl; 303 | #ifdef PACKAGE_LICENSE 304 | ss << PACKAGE_LICENSE << std::endl; 305 | #endif // PACKAGE_LICENSE 306 | #endif // PACKAGE_COPYRIGHT 307 | 308 | #ifdef PACKAGE_URL 309 | ss << std::endl << PACKAGE_URL << std::endl; 310 | #endif // PACKAGE_URL 311 | 312 | version_string = ss.str (); 313 | #endif // PACKAGE_STRING 314 | } 315 | 316 | inline void 317 | parser::add_short (char short_name, arg_mode has_arg, 318 | std::function option_handler) 319 | { 320 | if (short_name) 321 | { 322 | short_map[short_name] = 323 | std::pair> 324 | (has_arg, option_handler); 325 | } 326 | } 327 | 328 | inline void 329 | parser::add_long (const std::string &long_name, arg_mode has_arg, 330 | std::function option_handler) 331 | { 332 | if (!long_name.empty ()) 333 | { 334 | long_map[long_name] = 335 | std::pair> 336 | (has_arg, option_handler); 337 | } 338 | } 339 | 340 | inline void 341 | parser::add_description (char short_name, const std::string &long_name, 342 | arg_mode has_arg, 343 | const std::string &description, 344 | const std::string &typestr, 345 | const std::string &header, 346 | const std::string &group) 347 | { 348 | std::stringstream ss; 349 | 350 | if (short_name || !long_name.empty () || !header.empty ()) 351 | { 352 | ss << h_indent; 353 | if (short_name) 354 | { 355 | ss << "-" << short_name; 356 | if (long_name.empty () && !typestr.empty ()) 357 | ss << typestr; 358 | } 359 | if (!long_name.empty ()) 360 | { 361 | if (short_name) 362 | ss << ", "; 363 | ss << "--" << long_name; 364 | if (!typestr.empty ()) 365 | { 366 | switch (has_arg) 367 | { 368 | case arg_mode::no_argument: 369 | // Nothing to do 370 | break; 371 | case arg_mode::required_argument: 372 | ss << "=" << typestr; 373 | break; 374 | case arg_mode::optional_argument: 375 | ss << "[=" << typestr << "]"; 376 | break; 377 | } 378 | } 379 | } 380 | if (!header.empty ()) 381 | ss << header; 382 | ss << std::endl; 383 | } 384 | 385 | if (!description.empty ()) 386 | ss << description << std::endl; 387 | 388 | help_map[group].push_back (ss.str ()); 389 | } 390 | 391 | inline bool 392 | parser::add_handler (char short_name, const std::string &long_name, 393 | arg_mode has_arg, 394 | std::function option_handler, 395 | const std::string &description, 396 | const std::string &typestr, 397 | const std::string &header, 398 | const std::string &group) 399 | { 400 | if (short_name && short_map.find (short_name) != short_map.end ()) 401 | { 402 | // The short name is already registerd. 403 | return false; 404 | } 405 | if (!long_name.empty() && long_map.find (long_name) != long_map.end ()) 406 | { 407 | // The long name is already registerd. 408 | return false; 409 | } 410 | 411 | add_short (short_name, has_arg, option_handler); 412 | add_long (long_name, has_arg, option_handler); 413 | 414 | if (!description.empty () || !typestr.empty ()) 415 | add_description (short_name, long_name, has_arg, 416 | description, typestr, header, group); 417 | 418 | return true; 419 | } 420 | 421 | inline bool 422 | parser::add_flag (char short_name, const std::string &long_name, 423 | bool *flag, 424 | const std::string &description, 425 | const std::string &group) 426 | { 427 | *flag = false; 428 | return add_handler (short_name, long_name, arg_mode::no_argument, 429 | [flag](const std::string &)->bool 430 | { 431 | *flag = true; 432 | return true; 433 | }, 434 | description, "", "", group); 435 | } 436 | 437 | inline bool 438 | parser::add_string (char short_name, const std::string &long_name, 439 | std::string *var, const std::string &defval, 440 | const std::string &description, 441 | const std::string &typestr, 442 | const std::string &group) 443 | { 444 | *var = defval; 445 | std::string header; 446 | 447 | if(!defval.empty ()) 448 | { 449 | // Three spaces for separator (same as h_space) 450 | header = _(" (default=") + defval + ")"; 451 | } 452 | return add_handler (short_name, long_name, arg_mode::required_argument, 453 | [var](const std::string &optarg)->bool 454 | { 455 | *var = optarg; 456 | return true; 457 | }, 458 | description, typestr, header, group); 459 | } 460 | 461 | inline bool 462 | parser::add_default_help (void) 463 | { 464 | return add_handler ('h', "help", arg_mode::no_argument, 465 | [this](const std::string &)->bool 466 | { 467 | std::cout << build_help (); 468 | return false; 469 | }, 470 | // Four spaces for indent (same as d_indent) 471 | _(" Print help and exit")); 472 | } 473 | 474 | inline bool 475 | parser::add_default_version (void) 476 | { 477 | return add_handler ('V', "version", arg_mode::no_argument, 478 | [this](const std::string &)->bool 479 | { 480 | std::cout << version_string; 481 | return false; 482 | }, 483 | // Four spaces for indent (same as d_indent) 484 | _(" Print version and exit")); 485 | } 486 | 487 | inline bool 488 | parser::find_unique_long_name (const std::string &long_name, 489 | std::pair> 491 | *target, 492 | bool *ambiguous) 493 | { 494 | if (long_map.find (long_name) != long_map.end ()) 495 | { 496 | // Long option name found 497 | *target = long_map[long_name]; 498 | return true; 499 | } 500 | if (abbreviated_long_name) 501 | { 502 | // Search abbreviated long option name 503 | for (decltype (long_map.cbegin()) it = 504 | long_map.upper_bound (long_name); 505 | it != long_map.cend (); 506 | ++it) 507 | { 508 | if (it->first.substr (0, long_name.size ()) == long_name) 509 | { 510 | auto next_it = it; 511 | ++next_it; 512 | if (next_it != long_map.cend () && 513 | next_it->first.substr (0, long_name.size ()) == long_name) 514 | { 515 | // Failed: ambiguous option 516 | *ambiguous = true; 517 | return false; 518 | } 519 | // Unique abbreviated long option name fount 520 | *target = it->second; 521 | return true; 522 | } 523 | } 524 | } 525 | // Failed: unknown long option name 526 | *ambiguous = false; 527 | return false; 528 | } 529 | 530 | inline bool 531 | parser::parse_long_name (std::vector::const_iterator *it) 532 | { 533 | size_t optchars_pos = (*it)->at(1) == '-' ? 534 | 2: // Double hyphen (--long_name) style 535 | 1; // Single hyphen (-long_name) style 536 | auto delimiter_pos = (*it)->find ('='); 537 | std::string long_name = (*it)->substr (optchars_pos, 538 | delimiter_pos - optchars_pos); 539 | std::string optarg; 540 | 541 | if (delimiter_pos != std::string::npos) 542 | { 543 | // Option characters have an option argument 544 | // (something like --long_name=optarg) 545 | optarg = (*it)->substr (delimiter_pos + 1, std::string::npos); 546 | } 547 | 548 | std::pair> target; 549 | bool ambiguous; 550 | if (find_unique_long_name (long_name, &target, &ambiguous)) 551 | { 552 | // Long option name found 553 | switch (target.first) 554 | { 555 | case arg_mode::no_argument: 556 | if (delimiter_pos != std::string::npos) 557 | { 558 | if (!error_extra_arg (long_name, optarg)) 559 | { 560 | abort = abort_reason::error_extra_arg; 561 | abort_option = long_name; 562 | return false; 563 | } 564 | return true; 565 | } 566 | break; 567 | case arg_mode::required_argument: 568 | if (delimiter_pos == std::string::npos) 569 | { 570 | if ((*it + 1) != argvs.cend ()) 571 | { 572 | // Next argv-element is an option argument 573 | // (something like --long_name optarg) 574 | optarg = *(++(*it)); 575 | } 576 | else 577 | { 578 | if (!error_no_arg (long_name)) 579 | { 580 | abort = abort_reason::error_no_arg; 581 | abort_option = long_name; 582 | return false; 583 | } 584 | return true; 585 | } 586 | } 587 | break; 588 | case arg_mode::optional_argument: 589 | // Nothing to do 590 | break; 591 | } 592 | // Call option handler 593 | if (!target.second (optarg)) 594 | { 595 | abort = abort_reason::option_handler; 596 | abort_option = long_name; 597 | return false; 598 | } 599 | return true; 600 | } 601 | 602 | // Long option name did not find 603 | if (optchars_pos == 1) 604 | { 605 | // Fallback to short option name 606 | return parse_short_name (it); 607 | } 608 | if (ambiguous) 609 | { 610 | if (!error_ambiguous_option ((*it)->substr (optchars_pos, 611 | std::string::npos))) 612 | { 613 | abort = abort_reason::error_ambiguous_option; 614 | abort_option = long_name; 615 | return false; 616 | } 617 | return true; 618 | } 619 | if (!error_unknown_option ((*it)->substr (optchars_pos, 620 | std::string::npos))) 621 | { 622 | abort = abort_reason::error_unknown_option; 623 | abort_option = long_name; 624 | return false; 625 | } 626 | return true; 627 | } 628 | 629 | inline bool 630 | parser::parse_short_name (std::vector::const_iterator *it) 631 | { 632 | for (auto name_it = (*it)->cbegin () + 1; 633 | name_it != (*it)->cend (); 634 | ++name_it) 635 | { 636 | if (short_map.find (*name_it) != short_map.end()) 637 | { 638 | // Short option name found 639 | auto target = short_map[*name_it]; 640 | switch (target.first) 641 | { 642 | case arg_mode::no_argument: 643 | // Option characters doesn't have an option argument 644 | // (something like -o) 645 | if (!target.second ("")) // Call option handler 646 | { 647 | abort = abort_reason::option_handler; 648 | abort_option = *name_it; 649 | return false; 650 | } 651 | break; 652 | case arg_mode::required_argument: 653 | if ((name_it + 1) != (*it)->cend ()) 654 | { 655 | // Option characters have an option argument 656 | // (something like -ooptarg) 657 | std::string optarg (name_it + 1, (*it)->cend ()); 658 | if (!target.second (optarg)) // Call option handler 659 | { 660 | abort = abort_reason::option_handler; 661 | abort_option = *name_it; 662 | return false; 663 | } 664 | return true; 665 | } 666 | else if ((*it + 1) != argvs.cend ()) 667 | { 668 | // Next argv-element is an option argument 669 | // (something like -o optarg) 670 | std::string optarg = *(++(*it)); 671 | if (!target.second (optarg)) // Call option handler 672 | { 673 | abort = abort_reason::option_handler; 674 | abort_option = *name_it; 675 | return false; 676 | } 677 | return true; 678 | } 679 | else 680 | { 681 | if (!error_no_arg_short (*name_it)) 682 | { 683 | abort = abort_reason::error_no_arg_short; 684 | abort_option = *name_it; 685 | return false; 686 | } 687 | } 688 | break; 689 | case arg_mode::optional_argument: 690 | if ((name_it + 1) != (*it)->cend ()) 691 | { 692 | // Option characters have an option argument 693 | // (something like -ooptarg) 694 | std::string optarg (name_it + 1, (*it)->cend ()); 695 | if (!target.second (optarg)) // Call option handler 696 | { 697 | abort = abort_reason::option_handler; 698 | abort_option = *name_it; 699 | return false; 700 | } 701 | return true; 702 | } 703 | // Option characters doesn't have an option argument 704 | // (something like -o) 705 | if (!target.second ("")) // Call option handler 706 | { 707 | abort = abort_reason::option_handler; 708 | abort_option = *name_it; 709 | return false; 710 | } 711 | break; 712 | } 713 | } 714 | else 715 | { 716 | if (!error_unknown_option_short (*name_it)) 717 | { 718 | abort = abort_reason::error_unknown_option_short; 719 | abort_option = *name_it; 720 | return false; 721 | } 722 | } 723 | } 724 | return true; 725 | } 726 | 727 | inline bool 728 | parser::parse (int argc, char const* const* argv, int optind) 729 | { 730 | argvs.assign (argv, argv + argc); 731 | 732 | if (version_string.empty ()) 733 | version_string = argvs[0] + "\n"; 734 | 735 | bool all_skip = false; 736 | 737 | for (auto argv_it = argvs.cbegin () + optind; 738 | argv_it != argvs.cend (); 739 | ++argv_it) 740 | { 741 | // Check skip 742 | if (all_skip) 743 | { 744 | unamed_args.push_back (*argv_it); 745 | continue; 746 | } 747 | 748 | // Check "--" and "-" 749 | // They are not option element. 750 | if (*argv_it == "--") 751 | { 752 | all_skip = true; 753 | continue; 754 | } 755 | else if (*argv_it == "-") 756 | { 757 | unamed_args.push_back (*argv_it); 758 | continue; 759 | } 760 | 761 | // Check option element 762 | if (argv_it->substr (0, 2) == "--") 763 | { 764 | // Long option 765 | if (!parse_long_name (&argv_it)) 766 | return false; 767 | } 768 | else if (argv_it->substr (0, 1) == "-") 769 | { 770 | if (long_only) 771 | { 772 | // Long option 773 | if (!parse_long_name (&argv_it)) 774 | return false; 775 | } 776 | else 777 | { 778 | // Short option 779 | if (!parse_short_name (&argv_it)) 780 | return false; 781 | } 782 | } 783 | else 784 | { 785 | // It is not an option element. 786 | unamed_args.push_back (*argv_it); 787 | } 788 | } 789 | return true; 790 | } 791 | 792 | inline std::string 793 | parser::build_usage (void) const 794 | { 795 | std::stringstream ss; 796 | 797 | ss << _("Usage: ") << argvs[0] << _(" [options] "); 798 | if (!usage_unamed_opts.empty ()) 799 | ss << "[" << usage_unamed_opts << "] "; 800 | ss << "..." << std::endl; 801 | 802 | return ss.str (); 803 | } 804 | 805 | inline std::string 806 | parser::build_help (void) const 807 | { 808 | std::stringstream ss; 809 | 810 | ss << version_string << std::endl << build_usage () << std::endl; 811 | 812 | for (const auto &group: help_map) 813 | { 814 | if (!group.first.empty ()) 815 | ss << std::endl << group.first << ":" << std::endl; 816 | for (const auto &description: group.second) 817 | { 818 | ss << description; 819 | } 820 | } 821 | 822 | return ss.str (); 823 | } 824 | 825 | } 826 | 827 | #if defined (_) && defined (CMDLINEPARSE_HH_DEFINE_DUMMY_GETTEXT) 828 | #undef _ 829 | #undef CMDLINEPARSE_HH_DEFINE_DUMMY_GETTEXT 830 | #endif 831 | 832 | #endif 833 | -------------------------------------------------------------------------------- /src/encodename.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "output-pdfmark.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "utf16.hh" 27 | #include "utf8.hh" 28 | 29 | std::string output_pdfmark::encode_literal (const std::string &name) const 30 | { 31 | bool bflag = escape || is_utf16 (name) || !is_utf8 (name); 32 | std::stringstream encoded; 33 | 34 | for (auto c: name) 35 | { 36 | if (bflag || static_cast(c) < 0x20 || 37 | c == '(' || c == ')' || c == '\\' || c == 0x7f) 38 | { 39 | encoded 40 | << '\\' 41 | << std::oct << std::setw (3) << std::setfill ('0') 42 | << static_cast(static_cast(c)); 43 | } 44 | else 45 | { 46 | encoded << c; 47 | } 48 | } 49 | return encoded.str (); 50 | } 51 | 52 | std::string output_pdfmark::encode_hexadecimal (const std::string &name) const 53 | { 54 | std::stringstream encoded; 55 | 56 | encoded << std::hex << std::setw (2) << std::setfill ('0'); 57 | for (auto c: name) 58 | { 59 | encoded << static_cast(static_cast(c)); 60 | } 61 | 62 | return encoded.str (); 63 | } 64 | 65 | std::string output_pdfmark::encode_nameobject (const std::string &name) const 66 | { 67 | std::stringstream encoded; 68 | 69 | for (auto c: name) 70 | { 71 | if (escape || 72 | static_cast(c) < 0x21 || 73 | static_cast(c) > 0x7e || 74 | c == '(' || c == ')' || c == '<' || c == '>' || 75 | c == '[' || c == ']' || c == '{' || c == '}' || 76 | c == '/' || c == '%' || c == '#') 77 | { 78 | encoded 79 | << '#' 80 | << std::hex << std::uppercase 81 | << std::setw (2) << std::setfill ('0') 82 | << static_cast(static_cast(c)); 83 | } 84 | else 85 | { 86 | encoded << c; 87 | } 88 | } 89 | return encoded.str (); 90 | } 91 | 92 | std::string output_pdfmark::encode_name (const std::string &name) const 93 | { 94 | if (hexadecimal) 95 | return "<" + encode_hexadecimal (name) + ">"; 96 | if (nameobject) 97 | return "/" + encode_nameobject (name); 98 | return "(" + encode_literal (name) + ")"; 99 | } 100 | -------------------------------------------------------------------------------- /src/iconv_wrapper.hh: -------------------------------------------------------------------------------- 1 | // 2 | // One header file iconv wrapper for C++11 2022-01-11.12 GPL 3 | // https://github.com/trueroad/iconv_wrapper 4 | // 5 | // Copyright (C) 2016, 2019, 2022, 2023 Masamichi Hosoda. All rights reserved. 6 | // 7 | // One header file iconv wrapper for C++11 is free software: 8 | // you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation, either version 3 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // One header file iconv wrapper for C++11 is distributed 14 | // in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU General Public License 20 | // along with One header file Commandline Parse for C++11. 21 | // If not, see . 22 | // 23 | 24 | #ifndef INCLUDE_GUARD_ICONV_WRAPPER_H 25 | #define INCLUDE_GUARD_ICONV_WRAPPER_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace iconv_wrapper 32 | { 33 | class iconv 34 | { 35 | public: 36 | // Open 37 | void open (const std::string &fromcode, const std::string &tocode); 38 | 39 | // Close 40 | void close () noexcept; 41 | 42 | // Convert 43 | std::string convert (const std::string &in); 44 | 45 | // Convert (with getting the incomplete input / output 46 | // when an exception occurs) 47 | std::string &convert (const std::string &in, 48 | std::string::size_type *pinpos, 49 | std::string *pout); 50 | 51 | // Get initial sequence 52 | std::string get_initial_sequence (void); 53 | 54 | // Get initial sequence 55 | std::string &get_initial_sequence (std::string *pout); 56 | 57 | // Reset conversion state 58 | void reset (void) const noexcept; 59 | 60 | // Constructor / destructor 61 | iconv () = default; 62 | 63 | iconv (const std::string &fromcode, const std::string &tocode) 64 | { 65 | open (fromcode, tocode); 66 | } 67 | 68 | ~iconv () noexcept 69 | { 70 | close (); 71 | } 72 | 73 | // Enable move 74 | iconv (iconv &&) = default; 75 | iconv& operator = (iconv &&) = default; 76 | 77 | private: 78 | // Internal class 79 | // There is two different implements for the second argument of iconv (). 80 | // `const char**' and `char **' 81 | // This class is for automatic type cast switching. 82 | class iconv_const_cast 83 | { 84 | public: 85 | iconv_const_cast (const char **in) noexcept: 86 | t (in) 87 | { 88 | } 89 | operator char** () const noexcept 90 | { 91 | return const_cast(t); 92 | } 93 | operator const char ** () const noexcept 94 | { 95 | return t; 96 | } 97 | private: 98 | const char ** t; 99 | }; 100 | 101 | // Internal function 102 | void do_iconv (std::string *pout, const char *inbuf, size_t *pinleft, 103 | std::string::size_type *pinpos = nullptr); 104 | 105 | // Disable copy 106 | // Since iconv_t cannot duplicate. 107 | iconv (iconv const &) = delete; 108 | iconv& operator = (iconv const &) = delete; 109 | 110 | // Const 111 | // Here is C cast instead of C++ cast. 112 | // C++ reinterpret_cast (pointer) and static_cast (integer) cannot be used. 113 | // Since it depends on the implementation of iconv_t. 114 | const iconv_t invalid_cd = (iconv_t)-1; 115 | 116 | // Conversion descriptor 117 | iconv_t convdesc = invalid_cd; 118 | }; 119 | 120 | inline void iconv::open (const std::string &fromcode, 121 | const std::string &tocode) 122 | { 123 | if (convdesc != invalid_cd) 124 | { 125 | close (); 126 | } 127 | convdesc = iconv_open (tocode.c_str (), fromcode.c_str ()); 128 | if (convdesc == invalid_cd) 129 | { 130 | throw std::system_error (errno, std::system_category ()); 131 | } 132 | } 133 | 134 | inline void iconv::close () noexcept 135 | { 136 | if (convdesc != invalid_cd) 137 | { 138 | iconv_close (convdesc); 139 | convdesc = invalid_cd; 140 | } 141 | } 142 | 143 | inline std::string iconv::convert (const std::string &in) 144 | { 145 | std::string out (in.size (), '\0'); 146 | convert (in, nullptr, &out); 147 | return out; 148 | } 149 | 150 | inline std::string &iconv::convert (const std::string &in, 151 | std::string::size_type *pinpos, 152 | std::string *pout) 153 | { 154 | size_t inleft {in.size ()}; 155 | if (inleft) 156 | do_iconv (pout, &in.at (0), &inleft, pinpos); 157 | else 158 | pout->clear(); 159 | return *pout; 160 | } 161 | 162 | inline std::string iconv::get_initial_sequence (void) 163 | { 164 | std::string out (1, '\0'); 165 | get_initial_sequence (&out); 166 | return out; 167 | } 168 | 169 | inline std::string &iconv::get_initial_sequence (std::string *pout) 170 | { 171 | do_iconv (pout, nullptr, nullptr); 172 | return *pout; 173 | } 174 | 175 | inline void iconv::reset (void) const noexcept 176 | { 177 | ::iconv (convdesc, nullptr, nullptr, nullptr, nullptr); 178 | } 179 | 180 | inline void iconv::do_iconv (std::string *pout, 181 | const char *inbuf, size_t *pinleft, 182 | std::string::size_type *pinpos) 183 | { 184 | if (pout->empty ()) 185 | { 186 | pout->resize (1); 187 | } 188 | const char *inbuf_tmp {inbuf}; 189 | char *outbuf {&pout->at (0)}; 190 | size_t outleft {pout->size ()}; 191 | size_t s; 192 | 193 | while ((s = ::iconv (convdesc, 194 | iconv_const_cast(&inbuf_tmp), pinleft, 195 | &outbuf, &outleft)) == static_cast(-1)) 196 | { 197 | if (errno != E2BIG) 198 | { 199 | if (pinpos && inbuf) 200 | { 201 | *pinpos = (inbuf_tmp - inbuf); 202 | } 203 | pout->resize (outbuf - &pout->at (0)); 204 | throw std::system_error (errno, std::system_category ()); 205 | } 206 | std::string::size_type pos = (outbuf - &pout->at (0)); 207 | pout->resize (pout->size () * 2); 208 | outbuf = &pout->at (pos); 209 | outleft = pout->size () - pos; 210 | } 211 | pout->resize (outbuf - &pout->at (0)); 212 | } 213 | } 214 | 215 | #endif // INCLUDE_GUARD_ICONV_WRAPPER_H 216 | -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "cmdlineparse.hh" 26 | #include "output-pdfmark.hh" 27 | 28 | int main (int argc, char *argv[]) 29 | { 30 | cmdlineparse::parser cmd; 31 | std::unique_ptr opdfmark {create_output_pdfmark ()}; 32 | std::string output_filename; 33 | 34 | cmd.add_default_help (); 35 | cmd.add_handler ('V', "version", 36 | cmdlineparse::arg_mode::no_argument, 37 | [&cmd, &opdfmark](const std::string &)->bool 38 | { 39 | std::cout << cmd.get_version_string () 40 | << std::endl 41 | << opdfmark->version (); 42 | return false; 43 | }, 44 | " Print version and exit"); 45 | cmd.add_string ('o', "output", &output_filename, "", 46 | " Output filename\n" 47 | " (Default: standard output)", 48 | "OUTPUT.ps"); 49 | opdfmark->add_options (&cmd); 50 | 51 | cmd.set_usage_unamed_opts ("INPUT.pdf"); 52 | 53 | if (!cmd.parse (argc, argv)) 54 | return 0; 55 | 56 | if (cmd.get_unamed_args ().empty ()) 57 | { 58 | std::cerr << cmd.get_version_string () << std::endl 59 | << cmd.build_usage () << std::endl; 60 | return 1; 61 | } 62 | 63 | std::ostream *pout; 64 | std::ofstream ofs; 65 | if (output_filename.empty () || output_filename == "-") 66 | { 67 | pout = &std::cout; 68 | } 69 | else 70 | { 71 | ofs.open (output_filename); 72 | pout = &ofs; 73 | } 74 | 75 | *pout << "% " << PACKAGE_STRING << std::endl 76 | << "% " << PACKAGE_URL << std::endl << std::endl; 77 | 78 | if (!opdfmark->open (cmd.get_unamed_args ().at (0))) 79 | return 1; 80 | 81 | opdfmark->parse_options (); 82 | 83 | *pout << opdfmark->pagemode (); 84 | *pout << opdfmark->destname (); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /src/output-pdfmark.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016-2018 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "output-pdfmark.hh" 21 | 22 | #include 23 | #include 24 | 25 | #include "cmdlineparse.hh" 26 | 27 | void output_pdfmark::add_options (cmdlineparse::parser *cmd) 28 | { 29 | cmd->add_string (0, "style", &style, "literal", 30 | " Name style\n" 31 | " literal: literal strings" 32 | #ifdef USE_CODECVT 33 | " (UTF-8 validation by codecvt)\n" 34 | #else 35 | #ifdef USE_ICONV 36 | " (UTF-8 validation by iconv)\n" 37 | #else // USE_ICONV 38 | " (no UTF-8 validation)\n" 39 | #endif // USE_ICONV 40 | #endif // USE_CODECVT 41 | " hex: hexadecimal strings\n" 42 | " name: name object", 43 | "STYLE"); 44 | cmd->add_flag (0, "escape", &escape, 45 | " Escape all characters"); 46 | } 47 | 48 | void output_pdfmark::parse_options (void) 49 | { 50 | if (style == "literal") 51 | { 52 | hexadecimal = false; 53 | nameobject = false; 54 | } 55 | else if (style == "hex") 56 | { 57 | hexadecimal = true; 58 | nameobject = false; 59 | } 60 | else if (style == "name") 61 | { 62 | hexadecimal = false; 63 | nameobject = true; 64 | } 65 | else 66 | std::cerr << "unknown --style argument: " << style << std::endl; 67 | } 68 | -------------------------------------------------------------------------------- /src/output-pdfmark.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_OUTPUT_PDFMARK_HH 19 | #define INCLUDE_GUARD_OUTPUT_PDFMARK_HH 20 | 21 | #include 22 | #include 23 | 24 | namespace cmdlineparse 25 | { 26 | class parser; 27 | } 28 | 29 | class output_pdfmark 30 | { 31 | public: 32 | virtual bool open (const std::string &pdf_filename) = 0; 33 | virtual std::string pagemode (void) = 0; 34 | virtual std::string destname (void) = 0; 35 | virtual std::string version (void) = 0; 36 | 37 | void add_options (cmdlineparse::parser *cmd); 38 | void parse_options (void); 39 | 40 | std::string encode_literal (const std::string &name) const; 41 | std::string encode_hexadecimal (const std::string &name) const; 42 | std::string encode_nameobject (const std::string &name) const; 43 | std::string encode_name (const std::string &name) const; 44 | 45 | output_pdfmark () = default; 46 | virtual ~output_pdfmark () = default; 47 | 48 | private: 49 | output_pdfmark (output_pdfmark const&) = delete; 50 | output_pdfmark (output_pdfmark&&) = delete; 51 | output_pdfmark& operator = (output_pdfmark const&) = delete; 52 | output_pdfmark& operator = (output_pdfmark&&) = delete; 53 | 54 | std::string style; 55 | bool escape = false; 56 | bool hexadecimal = false; 57 | bool nameobject = false; 58 | }; 59 | 60 | std::unique_ptr create_output_pdfmark (void); 61 | 62 | #endif // INCLUDE_GUARD_OUTPUT_PDFMARK_HH 63 | -------------------------------------------------------------------------------- /src/poppler-core/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libextractpdfmark-poppler-core.a 2 | libextractpdfmark_poppler_core_a_SOURCES = poppler-core.cc poppler-core.hh \ 3 | pagemode.cc destname.cc destname-private.hh 4 | libextractpdfmark_poppler_core_a_CPPFLAGS = -I$(srcdir)/.. \ 5 | $(POPPLER_CFLAGS) 6 | -------------------------------------------------------------------------------- /src/poppler-core/destname-private.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_DESTNAME_PRIVATE_HH 19 | #define INCLUDE_GUARD_DESTNAME_PRIVATE_HH 20 | 21 | #include 22 | 23 | // 24 | // *** FIX ME, UGLY *** 25 | // 26 | // poppler does not have destination name enumeration. 27 | // So forced to use a private member function. 28 | // 29 | // http://bloglitb.blogspot.jp/2010/07/access-to-private-members-thats-easy.html 30 | // https://gist.github.com/dabrahams/1528856 31 | // 32 | 33 | template 34 | struct Accessor 35 | { 36 | static typename Tag::type value; 37 | }; 38 | 39 | template 40 | typename Tag::type Accessor::value; 41 | 42 | template 43 | struct Initializer 44 | { 45 | Initializer() 46 | { 47 | Accessor::value = p; 48 | } 49 | static Initializer instance; 50 | }; 51 | 52 | template 53 | Initializer Initializer::instance; 54 | 55 | struct Catalog_getDestNameTree { typedef NameTree* (Catalog::* type)(); }; 56 | 57 | template struct Initializer; 59 | 60 | inline NameTree *get_destnametree (Catalog *catalog) 61 | { 62 | return (catalog->*Accessor::value)(); 63 | } 64 | 65 | // 66 | // *** FIXME, UGLY *** 67 | // 68 | 69 | #endif // INCLUDE_GUARD_DESTNAME_PRIVATE_HH 70 | -------------------------------------------------------------------------------- /src/poppler-core/destname.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2018 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-core.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #ifndef HAVE_POPPLER_CORE_IF 30 | #include "destname-private.hh" 31 | #endif 32 | 33 | inline std::string goo_to_string (GooString *goo) 34 | { 35 | return std::string { 36 | #ifdef HAS_GOOSTRING_C_STR 37 | goo->c_str (), 38 | #else 39 | goo->getCString (), 40 | #endif 41 | static_cast(goo->getLength ())}; 42 | } 43 | 44 | inline void poppler_core::add_destname (GooString *name, 45 | LinkDest *link_dest) 46 | { 47 | std::string str = goo_to_string (name); 48 | add_destname (str, link_dest); 49 | } 50 | 51 | inline void poppler_core::add_destname (GooString *name) 52 | { 53 | std::string str = goo_to_string (name); 54 | std::unique_ptr link_dest {doc->findDest (name)}; 55 | add_destname (str, link_dest.get ()); 56 | } 57 | 58 | inline void poppler_core::add_destname (const char *name) 59 | { 60 | GooString goo {name}; 61 | std::unique_ptr link_dest {doc->findDest (&goo)}; 62 | add_destname (name, link_dest.get ()); 63 | } 64 | 65 | inline void poppler_core::add_destname (const std::string &name, 66 | LinkDest *link_dest) 67 | { 68 | if (link_dest) 69 | { 70 | name_map.insert (std::make_pair (name, *link_dest)); 71 | } 72 | } 73 | 74 | std::string poppler_core::build_destname (const std::string &name, 75 | LinkDest *link_dest) 76 | { 77 | std::stringstream ss; 78 | 79 | if (link_dest) 80 | { 81 | int pagenum; 82 | if (link_dest->isPageRef ()) 83 | { 84 | Ref page_ref = link_dest->getPageRef (); 85 | pagenum = doc->findPage (page_ref.num, page_ref.gen); 86 | } 87 | else 88 | { 89 | pagenum = link_dest->getPageNum (); 90 | } 91 | 92 | switch (link_dest->getKind ()) 93 | { 94 | case destXYZ: 95 | ss 96 | << "[ /Dest " << encode_name (name) 97 | << " /Page " << pagenum 98 | << " /View [/XYZ " << link_dest->getLeft () 99 | << " " << link_dest->getTop () 100 | << " " << link_dest->getZoom () 101 | << "] /DEST pdfmark" << std::endl; 102 | break; 103 | case destFit: 104 | ss 105 | << "[ /Dest " << encode_name (name) 106 | << " /Page " << pagenum 107 | << " /View [/Fit] /DEST pdfmark" << std::endl; 108 | break; 109 | case destFitH: 110 | ss 111 | << "[ /Dest " << encode_name (name) 112 | << " /Page " << pagenum 113 | << " /View [/FitH " << link_dest->getTop () 114 | << "] /DEST pdfmark" << std::endl; 115 | break; 116 | case destFitV: 117 | ss 118 | << "[ /Dest " << encode_name (name) 119 | << " /Page " << pagenum 120 | << " /View [/FitV " << link_dest->getLeft () 121 | << "] /DEST pdfmark" << std::endl; 122 | break; 123 | case destFitR: 124 | ss 125 | << "[ /Dest " << encode_name (name) 126 | << " /Page " << pagenum 127 | << " /View [/FitR " << link_dest->getLeft () 128 | << " " << link_dest->getBottom () 129 | << " " << link_dest->getRight () 130 | << " " << link_dest->getTop () 131 | << "] /DEST pdfmark" << std::endl; 132 | break; 133 | case destFitB: 134 | ss 135 | << "[ /Dest " << encode_name (name) 136 | << " /Page " << pagenum 137 | << " /View [/FitB] /DEST pdfmark" << std::endl; 138 | break; 139 | case destFitBH: 140 | ss 141 | << "[ /Dest " << encode_name (name) 142 | << " /Page " << pagenum 143 | << " /View [/FitBH " << link_dest->getTop () 144 | << "] /DEST pdfmark" << std::endl; 145 | break; 146 | case destFitBV: 147 | ss 148 | << "[ /Dest " << encode_name (name) 149 | << " /Page " << pagenum 150 | << " /View [/FitBV " << link_dest->getLeft () 151 | << "] /DEST pdfmark" << std::endl; 152 | break; 153 | default: 154 | ss << "% link_dest kind is unknown." << std::endl; 155 | break; 156 | } 157 | } 158 | else 159 | { 160 | ss << "% link_dest is null." << std::endl; 161 | } 162 | 163 | return ss.str (); 164 | } 165 | 166 | std::string poppler_core::build_destnames (void) 167 | { 168 | std::string str; 169 | 170 | for (auto &elm: name_map) 171 | { 172 | str += build_destname (elm.first, &elm.second); 173 | } 174 | 175 | return str; 176 | } 177 | 178 | #ifdef HAVE_POPPLER_CORE_IF 179 | 180 | // Use poppler-core interface 181 | std::string poppler_core::destname (void) 182 | { 183 | Catalog *catalog = doc->getCatalog (); 184 | name_map.clear (); 185 | 186 | if (catalog && catalog->isOk ()) 187 | { 188 | int len = catalog->numDestNameTree (); 189 | for (int i=0; igetDestNameTreeName (i), 192 | catalog->getDestNameTreeDest (i)); 193 | } 194 | 195 | len = catalog->numDests (); 196 | for (int i=0; igetDestsName (i), 199 | catalog->getDestsDest (i)); 200 | } 201 | } 202 | else 203 | std::cerr << "Catalog is not OK" << std::endl; 204 | 205 | return build_destnames (); 206 | } 207 | 208 | #else // HAVE_POPPLER_CORE_IF 209 | 210 | // Use poppler-core private access 211 | std::string poppler_core::destname (void) 212 | { 213 | Catalog *catalog = doc->getCatalog (); 214 | name_map.clear (); 215 | 216 | if (catalog && catalog->isOk ()) 217 | { 218 | NameTree *destnametree = get_destnametree (catalog); 219 | if (destnametree) 220 | { 221 | int len = destnametree->numEntries (); 222 | for (int i=0; igetName (i)); 225 | } 226 | } 227 | 228 | Object *obj = catalog->getDests (); 229 | if (obj && obj->isDict ()) 230 | { 231 | int len = obj->dictGetLength (); 232 | for (int i=0; idictGetKey (i)); 235 | } 236 | } 237 | } 238 | else 239 | std::cerr << "Catalog is not OK" << std::endl; 240 | 241 | return build_destnames (); 242 | } 243 | 244 | #endif // HAVE_POPPLER_CORE_IF 245 | -------------------------------------------------------------------------------- /src/poppler-core/pagemode.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-core.hh" 21 | 22 | #include 23 | #include 24 | 25 | std::string poppler_core::pagemode (void) 26 | { 27 | std::stringstream ss; 28 | Catalog *catalog = doc->getCatalog (); 29 | 30 | if (catalog && catalog->isOk ()) 31 | { 32 | switch (catalog->getPageMode ()) 33 | { 34 | case Catalog::pageModeOutlines: 35 | ss << "[ /PageMode /UseOutlines /DOCVIEW pdfmark" << std::endl; 36 | break; 37 | case Catalog::pageModeThumbs: 38 | ss << "[ /PageMode /UseThumbs /DOCVIEW pdfmark" << std::endl; 39 | break; 40 | case Catalog::pageModeFullScreen: 41 | ss << "[ /PageMode /FullScreen /DOCVIEW pdfmark" << std::endl; 42 | break; 43 | case Catalog::pageModeOC: 44 | ss << "% pageModeOC" << std::endl; 45 | break; 46 | case Catalog::pageModeAttach: 47 | ss << "% pageModeAttach" << std::endl; 48 | break; 49 | case Catalog::pageModeNone: 50 | default: 51 | ss << "[ /PageMode /UseNone /DOCVIEW pdfmark" << std::endl; 52 | break; 53 | } 54 | } 55 | else 56 | ss << "% PageMode unset" << std::endl; 57 | 58 | return ss.str (); 59 | } 60 | -------------------------------------------------------------------------------- /src/poppler-core/poppler-core.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-core.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | std::unique_ptr create_output_pdfmark (void) 28 | { 29 | return std::unique_ptr (new poppler_core ()); 30 | } 31 | 32 | bool poppler_core::open (const std::string &pdf_filename) 33 | { 34 | std::unique_ptr fileName 35 | {new GooString {pdf_filename.c_str (), 36 | static_cast (pdf_filename.length ())}}; 37 | doc = std::unique_ptr 38 | {PDFDocFactory ().createPDFDoc (*fileName, NULL, NULL)}; 39 | 40 | if (!doc) 41 | { 42 | std::cerr << "open failed." << std::endl; 43 | return false; 44 | } 45 | if (!doc->isOk ()) 46 | { 47 | std::cerr << "file is not OK." << std::endl; 48 | return false; 49 | } 50 | 51 | return true; 52 | } 53 | 54 | std::string poppler_core::version (void) 55 | { 56 | std::string retval; 57 | 58 | retval = "Compiled with poppler-core"; 59 | #ifndef HAVE_POPPLER_CORE_IF 60 | retval += " private"; 61 | #endif 62 | #ifdef POPPLER_CORE_IF_VERSION 63 | retval += " "; 64 | retval += POPPLER_CORE_IF_VERSION; 65 | #else 66 | #ifdef POPPLER_VERSION 67 | retval += " "; 68 | retval += POPPLER_VERSION; 69 | #endif 70 | #endif 71 | retval += ".\n"; 72 | 73 | return retval; 74 | } 75 | -------------------------------------------------------------------------------- /src/poppler-core/poppler-core.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_POPPLER_CORE_HH 19 | #define INCLUDE_GUARD_POPPLER_CORE_HH 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "output-pdfmark.hh" 27 | 28 | class PDFDoc; 29 | 30 | class poppler_core : public output_pdfmark 31 | { 32 | public: 33 | bool open (const std::string &pdf_filename); 34 | std::string pagemode (void); 35 | std::string destname (void); 36 | std::string version (void); 37 | 38 | private: 39 | std::string build_destname (const std::string &name, LinkDest *link_dest); 40 | std::string build_destnames (void); 41 | void add_destname (const std::string &name, LinkDest *link_dest); 42 | void add_destname (GooString *name, LinkDest *link_dest); 43 | void add_destname (GooString *name); 44 | void add_destname (const char *name); 45 | 46 | std::unique_ptr doc; 47 | std::map name_map; 48 | }; 49 | 50 | #endif // INCLUDE_GUARD_POPPLER_CORE_HH 51 | -------------------------------------------------------------------------------- /src/poppler-cpp/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libextractpdfmark-poppler-cpp.a 2 | libextractpdfmark_poppler_cpp_a_SOURCES = poppler-cpp.cc poppler-cpp.hh \ 3 | pagemode-cpp.cc destname-cpp.cc 4 | libextractpdfmark_poppler_cpp_a_CPPFLAGS = -I$(srcdir)/.. \ 5 | $(POPPLER_CPP_CFLAGS) 6 | -------------------------------------------------------------------------------- /src/poppler-cpp/destname-cpp.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-cpp.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | std::string poppler_cpp::walk (const std::string &name, 27 | const poppler::destination &dest) 28 | { 29 | std::stringstream ss; 30 | 31 | switch (dest.type ()) 32 | { 33 | case poppler::destination::type_enum::xyz: 34 | ss 35 | << "[ /Dest " << encode_name (name) 36 | << " /Page " << dest.page_number () 37 | << " /View [/XYZ " << dest.left () 38 | << " " << dest.top () 39 | << " " << dest.zoom () 40 | << "] /DEST pdfmark" << std::endl; 41 | break; 42 | case poppler::destination::type_enum::fit: 43 | ss 44 | << "[ /Dest " << encode_name (name) 45 | << " /Page " << dest.page_number () 46 | << " /View [/Fit] /DEST pdfmark" << std::endl; 47 | break; 48 | case poppler::destination::type_enum::fit_h: 49 | ss 50 | << "[ /Dest " << encode_name (name) 51 | << " /Page " << dest.page_number () 52 | << " /View [/FitH " << dest.top () 53 | << "] /DEST pdfmark" << std::endl; 54 | break; 55 | case poppler::destination::type_enum::fit_v: 56 | ss 57 | << "[ /Dest " << encode_name (name) 58 | << " /Page " << dest.page_number () 59 | << " /View [/FitV " << dest.left () 60 | << "] /DEST pdfmark" << std::endl; 61 | break; 62 | case poppler::destination::type_enum::fit_r: 63 | ss 64 | << "[ /Dest " << encode_name (name) 65 | << " /Page " << dest.page_number () 66 | << " /View [/FitR " << dest.left () 67 | << " " << dest.bottom () 68 | << " " << dest.right () 69 | << " " << dest.top () 70 | << "] /DEST pdfmark" << std::endl; 71 | break; 72 | case poppler::destination::type_enum::fit_b: 73 | ss 74 | << "[ /Dest " << encode_name (name) 75 | << " /Page " << dest.page_number () 76 | << " /View [/FitB] /DEST pdfmark" << std::endl; 77 | break; 78 | case poppler::destination::type_enum::fit_b_h: 79 | ss 80 | << "[ /Dest " << encode_name (name) 81 | << " /Page " << dest. page_number () 82 | << " /View [/FitBH " << dest.top () 83 | << "] /DEST pdfmark" << std::endl; 84 | break; 85 | case poppler::destination::type_enum::fit_b_v: 86 | ss 87 | << "[ /Dest " << encode_name (name) 88 | << " /Page " << dest.page_number () 89 | << " /View [/FitBV " << dest.left () 90 | << "] /DEST pdfmark" << std::endl; 91 | break; 92 | case poppler::destination::type_enum::unknown: 93 | ss << "% dest type is unknown." << std::endl; 94 | break; 95 | default: 96 | ss << "% dest type error." << std::endl; 97 | break; 98 | } 99 | 100 | return ss.str (); 101 | } 102 | 103 | std::string poppler_cpp::destname (void) 104 | { 105 | auto map {doc->create_destination_map ()}; 106 | std::string retval; 107 | 108 | for (const auto& pair: map) 109 | retval += walk (pair.first, pair.second); 110 | 111 | return retval; 112 | } 113 | -------------------------------------------------------------------------------- /src/poppler-cpp/pagemode-cpp.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-cpp.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | std::string poppler_cpp::pagemode (void) 28 | { 29 | std::stringstream ss; 30 | 31 | if (!doc) 32 | { 33 | std::cerr << "% document is null" << std::endl; 34 | return ""; 35 | } 36 | 37 | switch (doc->page_mode ()) 38 | { 39 | case poppler::document::page_mode_enum::use_none: 40 | ss << "[ /PageMode /UseNone /DOCVIEW pdfmark" << std::endl; 41 | break; 42 | case poppler::document::page_mode_enum::use_outlines: 43 | ss << "[ /PageMode /UseOutlines /DOCVIEW pdfmark" << std::endl; 44 | break; 45 | case poppler::document::page_mode_enum::use_thumbs: 46 | ss << "[ /PageMode /UseThumbs /DOCVIEW pdfmark" << std::endl; 47 | break; 48 | case poppler::document::page_mode_enum::fullscreen: 49 | ss << "[ /PageMode /FullScreen /DOCVIEW pdfmark" << std::endl; 50 | break; 51 | case poppler::document::page_mode_enum::use_oc: 52 | ss << "% PageMode use_oc" << std::endl; 53 | break; 54 | case poppler::document::page_mode_enum::use_attach: 55 | ss << "% PageMode use_attach" << std::endl; 56 | break; 57 | default: 58 | ss << "% PageMode unknown" << std::endl; 59 | break; 60 | } 61 | 62 | return ss.str (); 63 | } 64 | -------------------------------------------------------------------------------- /src/poppler-cpp/poppler-cpp.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-cpp.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::unique_ptr create_output_pdfmark (void) 29 | { 30 | return std::unique_ptr (new poppler_cpp ()); 31 | } 32 | 33 | bool poppler_cpp::open (const std::string &pdf_filename) 34 | { 35 | doc = std::unique_ptr 36 | {poppler::document::load_from_file (pdf_filename)}; 37 | 38 | if (!doc) 39 | { 40 | std::cerr << "poppler::document::load_from_file failed: " 41 | << pdf_filename; 42 | return false; 43 | } 44 | return true; 45 | } 46 | 47 | std::string poppler_cpp::version (void) 48 | { 49 | std::string retval; 50 | 51 | retval = "Compiled with poppler-cpp "; 52 | retval += POPPLER_VERSION; 53 | retval += ".\nRunning with poppler-cpp "; 54 | retval += poppler::version_string (); 55 | retval += ".\n"; 56 | 57 | return retval; 58 | } 59 | -------------------------------------------------------------------------------- /src/poppler-cpp/poppler-cpp.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_POPPLER_CPP_HH 19 | #define INCLUDE_GUARD_POPPLER_CPP_HH 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "output-pdfmark.hh" 27 | 28 | class poppler_cpp : public output_pdfmark 29 | { 30 | public: 31 | bool open (const std::string &pdf_filename); 32 | std::string pagemode (void); 33 | std::string destname (void); 34 | std::string version (void); 35 | 36 | private: 37 | std::string walk (const std::string &name, 38 | const poppler::destination &dest); 39 | 40 | std::unique_ptr doc; 41 | }; 42 | 43 | #endif // INCLUDE_GUARD_POPPLER_CPP_HH 44 | -------------------------------------------------------------------------------- /src/poppler-glib/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libextractpdfmark-poppler-glib.a 2 | libextractpdfmark_poppler_glib_a_SOURCES = poppler-glib.cc poppler-glib.hh \ 3 | pagemode-glib.cc destname-glib.cc 4 | libextractpdfmark_poppler_glib_a_CPPFLAGS = -I$(srcdir)/.. \ 5 | $(POPPLER_GLIB_CFLAGS) 6 | -------------------------------------------------------------------------------- /src/poppler-glib/destname-glib.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-glib.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | gboolean poppler_glib::walk_entry (gpointer key, 28 | gpointer value, 29 | gpointer user_data) 30 | { 31 | gchar *name = static_cast (key); 32 | PopplerDest *dest = static_cast (value); 33 | poppler_glib *pg = static_cast (user_data); 34 | 35 | return pg->walk (name, dest); 36 | } 37 | 38 | bool poppler_glib::walk (gchar *name, PopplerDest *dest) 39 | { 40 | gsize len; 41 | void *data {poppler_named_dest_to_bytestring (name, &len)}; 42 | std::string n {static_cast (data), 43 | static_cast (len)}; 44 | std::stringstream ss; 45 | if (dest) 46 | { 47 | switch (dest->type) 48 | { 49 | case POPPLER_DEST_XYZ: 50 | ss 51 | << "[ /Dest " << encode_name (n) 52 | << " /Page " << dest->page_num 53 | << " /View [/XYZ " << dest->left 54 | << " " << dest->top 55 | << " " << dest->zoom 56 | << "] /DEST pdfmark" << std::endl; 57 | break; 58 | case POPPLER_DEST_FIT: 59 | ss 60 | << "[ /Dest " << encode_name (n) 61 | << " /Page " << dest->page_num 62 | << " /View [/Fit] /DEST pdfmark" << std::endl; 63 | break; 64 | case POPPLER_DEST_FITH: 65 | ss 66 | << "[ /Dest " << encode_name (n) 67 | << " /Page " << dest->page_num 68 | << " /View [/FitH " << dest->top 69 | << "] /DEST pdfmark" << std::endl; 70 | break; 71 | case POPPLER_DEST_FITV: 72 | ss 73 | << "[ /Dest " << encode_name (n) 74 | << " /Page " << dest->page_num 75 | << " /View [/FitV " << dest->left 76 | << "] /DEST pdfmark" << std::endl; 77 | break; 78 | case POPPLER_DEST_FITR: 79 | ss 80 | << "[ /Dest " << encode_name (n) 81 | << " /Page " << dest->page_num 82 | << " /View [/FitR " << dest->left 83 | << " " << dest->bottom 84 | << " " << dest->right 85 | << " " << dest->top 86 | << "] /DEST pdfmark" << std::endl; 87 | break; 88 | case POPPLER_DEST_FITB: 89 | ss 90 | << "[ /Dest " << encode_name (n) 91 | << " /Page " << dest->page_num 92 | << " /View [/FitB] /DEST pdfmark" << std::endl; 93 | break; 94 | case POPPLER_DEST_FITBH: 95 | ss 96 | << "[ /Dest " << encode_name (n) 97 | << " /Page " << dest->page_num 98 | << " /View [/FitBH " << dest->top 99 | << "] /DEST pdfmark" << std::endl; 100 | break; 101 | case POPPLER_DEST_FITBV: 102 | ss 103 | << "[ /Dest " << encode_name (n) 104 | << " /Page " << dest->page_num 105 | << " /View [/FitBV " << dest->left 106 | << "] /DEST pdfmark" << std::endl; 107 | break; 108 | default: 109 | ss << "% dest type is unknown." << std::endl; 110 | break; 111 | } 112 | } 113 | else 114 | { 115 | ss << "% dest is null." << std::endl; 116 | } 117 | 118 | dests += ss.str (); 119 | 120 | // return value is used for GTraverseFunc ()'s return value. 121 | // false means to continue the travarsal (true means to stop) 122 | return false; 123 | } 124 | 125 | std::string poppler_glib::destname (void) 126 | { 127 | std::unique_ptr 128 | tree {poppler_document_create_dests_tree (document), g_tree_destroy}; 129 | dests.clear (); 130 | 131 | g_tree_foreach (tree.get (), walk_entry, this); 132 | 133 | std::string tmp {std::move(dests)}; 134 | dests.clear (); 135 | return tmp; 136 | } 137 | -------------------------------------------------------------------------------- /src/poppler-glib/pagemode-glib.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-glib.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | std::string poppler_glib::pagemode (void) 28 | { 29 | std::stringstream ss; 30 | 31 | if (!document) 32 | { 33 | std::cerr << "% document is null" << std::endl; 34 | return ""; 35 | } 36 | 37 | switch (poppler_document_get_page_mode (document)) 38 | { 39 | case POPPLER_PAGE_MODE_UNSET: 40 | case POPPLER_PAGE_MODE_NONE: 41 | ss << "[ /PageMode /UseNone /DOCVIEW pdfmark" << std::endl; 42 | break; 43 | case POPPLER_PAGE_MODE_USE_OUTLINES: 44 | ss << "[ /PageMode /UseOutlines /DOCVIEW pdfmark" << std::endl; 45 | break; 46 | case POPPLER_PAGE_MODE_USE_THUMBS: 47 | ss << "[ /PageMode /UseThumbs /DOCVIEW pdfmark" << std::endl; 48 | break; 49 | case POPPLER_PAGE_MODE_FULL_SCREEN: 50 | ss << "[ /PageMode /FullScreen /DOCVIEW pdfmark" << std::endl; 51 | break; 52 | case POPPLER_PAGE_MODE_USE_OC: 53 | ss << "% PageMode POPPLER_MODE_USE_OC" << std::endl; 54 | break; 55 | case POPPLER_PAGE_MODE_USE_ATTACHMENTS: 56 | ss << "% PageMode POPPLER_MODE_USE_ATTACHMENTS" << std::endl; 57 | break; 58 | default: 59 | ss << "% PageMode unknown" << std::endl; 60 | break; 61 | } 62 | 63 | return ss.str (); 64 | } 65 | -------------------------------------------------------------------------------- /src/poppler-glib/poppler-glib.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "poppler-glib.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | std::unique_ptr create_output_pdfmark (void) 29 | { 30 | return std::unique_ptr (new poppler_glib ()); 31 | } 32 | 33 | namespace 34 | { 35 | std::string get_uri (const std::string &filename) 36 | { 37 | std::string abs_filename; 38 | 39 | if (g_path_is_absolute (filename.c_str ())) 40 | abs_filename = filename; 41 | else 42 | { 43 | std::unique_ptr dir 44 | {g_get_current_dir (), g_free}; 45 | std::unique_ptr abs 46 | {g_build_filename (dir.get (), filename.c_str (), nullptr), g_free}; 47 | abs_filename = abs.get (); 48 | } 49 | 50 | GError *error {nullptr}; 51 | std::unique_ptr uri 52 | {g_filename_to_uri (abs_filename.c_str (), nullptr, &error), g_free}; 53 | if (!uri) 54 | { 55 | std::cerr << "g_filename_to_uri failed: " << abs_filename; 56 | if (error) 57 | { 58 | std::cerr << ": " << error->message << std::endl; 59 | g_error_free (error); 60 | } 61 | else 62 | { 63 | std::cerr << std::endl; 64 | } 65 | return ""; 66 | } 67 | return uri.get (); 68 | } 69 | } 70 | 71 | bool poppler_glib::open (const std::string &pdf_filename) 72 | { 73 | GError *error {nullptr}; 74 | document = poppler_document_new_from_file (get_uri (pdf_filename).c_str (), 75 | nullptr, &error); 76 | if (!document) 77 | { 78 | std::cerr << "poppler_document_new_from_file failed: " << pdf_filename; 79 | if (error) 80 | { 81 | std::cerr << ": " << error->message << std::endl; 82 | g_error_free (error); 83 | } 84 | else 85 | { 86 | std::cerr << std::endl; 87 | } 88 | return false; 89 | } 90 | return true; 91 | } 92 | 93 | std::string poppler_glib::version (void) 94 | { 95 | std::stringstream ss; 96 | 97 | ss << "Compiled with poppler-glib " 98 | << POPPLER_MAJOR_VERSION << "." 99 | << POPPLER_MINOR_VERSION << "." 100 | << POPPLER_MICRO_VERSION 101 | << ", glib " 102 | << GLIB_MAJOR_VERSION << "." 103 | << GLIB_MINOR_VERSION << "." 104 | << GLIB_MICRO_VERSION 105 | << ".\nRunning with poppler-glib " 106 | << poppler_get_version () 107 | << ", glib " 108 | << glib_major_version << "." 109 | << glib_minor_version << "." 110 | << glib_micro_version 111 | << ".\n"; 112 | 113 | return ss.str (); 114 | } 115 | -------------------------------------------------------------------------------- /src/poppler-glib/poppler-glib.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016, 2019 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_POPPLER_GLIB_HH 19 | #define INCLUDE_GUARD_POPPLER_GLIB_HH 20 | 21 | #include 22 | #include 23 | 24 | #include "output-pdfmark.hh" 25 | 26 | class poppler_glib : public output_pdfmark 27 | { 28 | public: 29 | bool open (const std::string &pdf_filename); 30 | std::string pagemode (void); 31 | std::string destname (void); 32 | std::string version (void); 33 | 34 | ~poppler_glib () 35 | { 36 | g_clear_object (&document); 37 | } 38 | 39 | private: 40 | static gboolean walk_entry (gpointer key, 41 | gpointer value, 42 | gpointer user_data); 43 | bool walk (gchar *name, PopplerDest *dest); 44 | 45 | PopplerDocument *document = nullptr; 46 | std::string dests; 47 | }; 48 | 49 | #endif // INCLUDE_GUARD_POPPLER_GLIB_HH 50 | -------------------------------------------------------------------------------- /src/utf16.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "utf16.hh" 21 | 22 | #include 23 | 24 | bool is_utf16 (const std::string &str) 25 | { 26 | return (str.length () >= 2) && str[0] == '\xfe' && str[1] == '\xff'; 27 | } 28 | -------------------------------------------------------------------------------- /src/utf16.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_UTF16_HH 19 | #define INCLUDE_GUARD_UTF16_HH 20 | 21 | #include 22 | 23 | bool is_utf16 (const std::string &str); 24 | 25 | #endif // INCLUDE_GUARD_UTF16_HH 26 | -------------------------------------------------------------------------------- /src/utf8.cc: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #include "config.h" 19 | 20 | #include "utf8.hh" 21 | 22 | #ifdef USE_CODECVT 23 | #include 24 | #include 25 | #endif 26 | 27 | #include 28 | 29 | #ifdef USE_ICONV 30 | #include "iconv_wrapper.hh" 31 | #endif 32 | 33 | #ifdef USE_CODECVT 34 | 35 | bool is_utf8 (const std::string &str) 36 | { 37 | std::codecvt_utf8 cvt; 38 | auto mb {std::mbstate_t ()}; 39 | return (cvt.length (mb, &str.front (), &str.front () + str.length (), 40 | std::string::npos) 41 | == str.length ()); 42 | } 43 | 44 | #else // USE_CODECVT 45 | 46 | #ifdef USE_ICONV 47 | 48 | bool is_utf8 (const std::string &str) 49 | { 50 | try 51 | { 52 | iconv_wrapper::iconv cvt8to16 {"UTF-8", "UTF-16"}; 53 | std::string utf16 {cvt8to16.convert (str)}; 54 | iconv_wrapper::iconv cvt16to8 {"UTF-16", "UTF-8"}; 55 | std::string utf8 {cvt16to8.convert (utf16)}; 56 | return (str == utf8); 57 | } 58 | catch (std::system_error &error) 59 | { 60 | return false; 61 | } 62 | return false; 63 | } 64 | 65 | #else // USE_ICONV 66 | 67 | bool is_utf8 (const std::string &str) 68 | { 69 | return false; 70 | } 71 | 72 | #endif // USE_ICONV 73 | #endif // USE_CODECVT 74 | -------------------------------------------------------------------------------- /src/utf8.hh: -------------------------------------------------------------------------------- 1 | // This file is part of Extract PDFmark. 2 | // 3 | // Copyright (C) 2016 Masamichi Hosoda 4 | // 5 | // Extract PDFmark is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // Extract PDFmark is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with Extract PDFmark. If not, see . 17 | 18 | #ifndef INCLUDE_GUARD_UTF8_HH 19 | #define INCLUDE_GUARD_UTF8_HH 20 | 21 | #include 22 | 23 | bool is_utf8 (const std::string &str); 24 | 25 | #endif // INCLUDE_GUARD_UTF8_HH 26 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | TESTS = $(TESTMARKS) $(TESTROUNDS) 2 | 3 | TEST_EXTENSIONS = .pdfmark .ps 4 | 5 | PDFMARK_LOG_COMPILER = $(srcdir)/test-expected-pdfmark.sh 6 | PS_LOG_COMPILER = $(srcdir)/test-round.sh 7 | 8 | TESTS_ENVIRONMENT = top_builddir=$(top_builddir) \ 9 | srcdir=$(srcdir) \ 10 | GREP=$(GREP) \ 11 | DIFF=$(DIFF) \ 12 | GHOSTSCRIPT=$(GHOSTSCRIPT) 13 | 14 | # Source files for test PDFs 15 | TESTTEXS = binary.tex destonly.tex desttype.tex nodest.tex \ 16 | pdfdocencoding.tex utf16.tex utf8.tex special-chars.tex \ 17 | pagemode-usenone.tex pagemode-thumbs.tex pagemode-fullscreen.tex 18 | # Test PDFs 19 | TESTPDFS = $(TESTTEXS:.tex=.pdf) namedict.pdf 20 | # Expected PDFmark for expected pdf test 21 | TESTMARKS = $(TESTPDFS:.pdf=-expected.pdfmark) \ 22 | destonly-expected-literal-escape.pdfmark \ 23 | destonly-expected-hex.pdfmark \ 24 | destonly-expected-name.pdfmark \ 25 | destonly-expected-name-escape.pdfmark \ 26 | utf8-expected-literal-escape.pdfmark \ 27 | utf8-expected-hex.pdfmark \ 28 | utf8-expected-name.pdfmark \ 29 | utf8-expected-name-escape.pdfmark \ 30 | special-chars-expected-literal-escape.pdfmark \ 31 | special-chars-expected-hex.pdfmark \ 32 | special-chars-expected-name.pdfmark \ 33 | special-chars-expected-name-escape.pdfmark 34 | # Extracted PDFmark for round test 35 | TESTROUNDS = $(TESTPDFS:.pdf=-round.ps) \ 36 | destonly-round-literal-escape.ps \ 37 | destonly-round-hex.ps \ 38 | destonly-round-name.ps \ 39 | utf8-round-literal-escape.ps \ 40 | utf8-round-hex.ps \ 41 | special-chars-round-literal-escape.ps \ 42 | special-chars-round-hex.ps 43 | 44 | # TESTROUNDS should not be contained. 45 | EXTRA_DIST = test-round.sh test-expected-pdfmark.sh addnamedict.ps \ 46 | $(TESTTEXS) $(TESTPDFS) $(TESTMARKS) 47 | 48 | # For `make clean' 49 | CLEANFILES = $(TESTMARKS:-expected.pdfmark=-expected-test.pdfmark) \ 50 | $(TESTMARKS:-expected-literal-escape.pdfmark=-expected-literal-escape-test.pdfmark) \ 51 | $(TESTMARKS:-expected-hex.pdfmark=-expected-hex-test.pdfmark) \ 52 | $(TESTMARKS:-expected-name.pdfmark=-expected-name-test.pdfmark) \ 53 | $(TESTMARKS:-expected-name-escape.pdfmark=-expected-name-escape-test.pdfmark) \ 54 | $(TESTROUNDS:-round.ps=-round-test.pdf) \ 55 | $(TESTROUNDS:-round.ps=-round-test.ps) \ 56 | $(TESTROUNDS:-round-literal-escape.ps=-round-literal-escape-test.pdf) \ 57 | $(TESTROUNDS:-round-literal-escape.ps=-round-literal-escape-test.ps) \ 58 | $(TESTROUNDS:-round-hex.ps=-round-hex-test.pdf) \ 59 | $(TESTROUNDS:-round-hex.ps=-round-hex-test.ps) \ 60 | $(TESTROUNDS:-round-name.ps=-round-name-test.pdf) \ 61 | $(TESTROUNDS:-round-name.ps=-round-name-test.ps) \ 62 | $(TESTROUNDS:-round-name-escape.ps=-round-name-escape-test.pdf) \ 63 | $(TESTROUNDS:-round-name-escape.ps=-round-name-escape-test.ps) 64 | 65 | if HAVE_GHOSTSCRIPT 66 | # For name object (PDF 1.1) handling test 67 | # PDF 1.2+ uses name tree instead of name object. 68 | # So most PDFs use name tree for named destination. 69 | namedict.pdf: nodest.pdf addnamedict.ps 70 | $(GHOSTSCRIPT) -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$@ \ 71 | -dCompatibilityLevel=1.1 $^ 72 | else 73 | namedict.pdf: 74 | touch $@ 75 | endif 76 | 77 | # Generate test PDFs 78 | # Tarball contains them for convenience. 79 | %.pdf: %.tex 80 | $(PDFTEX) $< 81 | 82 | # Generate expected PDFmark 83 | # Tarball should contain them for checking outputs. 84 | %-expected.pdfmark: %.pdf 85 | $(top_builddir)/src/extractpdfmark $< | \ 86 | $(GREP) -v "^%\|^$$" > $@ 87 | 88 | # Generate expected PDFmark with hexadecimal style 89 | # Tarball should contain them for checking outputs. 90 | %-expected-hex.pdfmark: %.pdf 91 | $(top_builddir)/src/extractpdfmark --style=hex $< | \ 92 | $(GREP) -v "^%\|^$$" > $@ 93 | 94 | # Generate expected PDFmark with literal style full escaped 95 | # Tarball should contain them for checking outputs. 96 | %-expected-literal-escape.pdfmark: %.pdf 97 | $(top_builddir)/src/extractpdfmark --style=literal --escape $< | \ 98 | $(GREP) -v "^%\|^$$" > $@ 99 | 100 | # Generate expected PDFmark with name style 101 | # Tarball should contain them for checking outputs. 102 | %-expected-name.pdfmark: %.pdf 103 | $(top_builddir)/src/extractpdfmark --style=name $< | \ 104 | $(GREP) -v "^%\|^$$" > $@ 105 | 106 | # Generate expected PDFmark with name style full escaped 107 | # Tarball should contain them for checking outputs. 108 | %-expected-name-escape.pdfmark: %.pdf 109 | $(top_builddir)/src/extractpdfmark --style=name --escape $< | \ 110 | $(GREP) -v "^%\|^$$" > $@ 111 | 112 | # Generate extracted PDFmark 113 | # Tarball should not contain them for checking building environment. 114 | %-round.ps: %.pdf 115 | $(top_builddir)/src/extractpdfmark -o $@ $< 116 | 117 | # Generate extracted PDFmark with hexadecimal style 118 | # Tarball should not contain them for checking building environment. 119 | %-round-hex.ps: %.pdf 120 | $(top_builddir)/src/extractpdfmark --style=hex -o $@ $< 121 | 122 | # Generate extracted PDFmark with literal style full escaped 123 | # Tarball should not contain them for checking building environment. 124 | %-round-literal-escape.ps: %.pdf 125 | $(top_builddir)/src/extractpdfmark --style=literal --escape -o $@ $< 126 | 127 | # Generate extracted PDFmark with name style 128 | # Tarball should not contain them for checking building environment. 129 | %-round-name.ps: %.pdf 130 | $(top_builddir)/src/extractpdfmark --style=name -o $@ $< 131 | 132 | # Generate extracted PDFmark with name style full escaped 133 | # Tarball should not contain them for checking building environment. 134 | %-round-name-escape.ps: %.pdf 135 | $(top_builddir)/src/extractpdfmark --style=name --escape -o $@ $< 136 | -------------------------------------------------------------------------------- /test/addnamedict.ps: -------------------------------------------------------------------------------- 1 | [ /Dest /one /Page 1 /View [/XYZ 72 769.89 0] /DEST pdfmark 2 | [ /Dest /two /Page 2 /View [/XYZ 72 769.89 0] /DEST pdfmark 3 | -------------------------------------------------------------------------------- /test/binary.tex: -------------------------------------------------------------------------------- 1 | % Check for binary (broken UTF-16) destination names 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | \catcode0=12 7 | 8 | % US-ASCII for title 9 | \def\furonetitle{fur one} 10 | \def\furtwotitle{fur two} 11 | 12 | % binary (broken UTF-16) for destination name 13 | \def\furonename{^^ff^^fe^^00f^^00^^fc^^00r^^00 ^^00o^^00n^^00e} 14 | \def\furtwoname{^^ff^^fe^^00f^^00^^fc^^00r^^00 ^^00t^^00w^^00o} 15 | 16 | % Destination name could be binary. 17 | % title shuld be PDFDocEncoding (also US-ASCII) or UTF-16. 18 | \pdfoutline goto name{\furonename} {\furonetitle} 19 | \pdfoutline goto name{\furtwoname} {\furtwotitle} 20 | 21 | \pdfdest name{\furonename} xyz 22 | page 1 23 | 24 | \vfill 25 | \eject 26 | 27 | \pdfdest name{\furtwoname} xyz 28 | page 2 29 | 30 | \vfill 31 | \end 32 | -------------------------------------------------------------------------------- /test/destonly.tex: -------------------------------------------------------------------------------- 1 | % Check for no links, destination only PDF 2 | 3 | %\pdfobjcompresslevel=0 4 | 5 | \pdfdest name{one} xyz 6 | page 1 7 | 8 | \vfill 9 | \eject 10 | 11 | \pdfdest name{two} xyz 12 | page 2 13 | 14 | \vfill 15 | \end 16 | -------------------------------------------------------------------------------- /test/desttype.tex: -------------------------------------------------------------------------------- 1 | % Check for some destination types 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | \pdfoutline goto name{fit} {fit} 7 | \pdfoutline goto name{fith} {fith} 8 | \pdfoutline goto name{fitv} {fitv} 9 | \pdfoutline goto name{fitr} {fitr} 10 | \pdfoutline goto name{fitb} {fitb} 11 | \pdfoutline goto name{fitbh} {fitbh} 12 | \pdfoutline goto name{fitbv} {fitbv} 13 | \pdfoutline goto name{xyz} {xyz} 14 | \pdfoutline goto name{xyz zoom 1000} {xyz zoom 1000} 15 | \pdfoutline goto name{xyz zoom 500} {xyz zoom 500} 16 | \pdfoutline goto name{xyz zoom 2000} {xyz zoom 2000} 17 | 18 | \pdfdest name{fit} fit 19 | fit 20 | 21 | \vfill 22 | \eject 23 | 24 | \pdfdest name{fith} fith 25 | fith 26 | 27 | \vfill 28 | \eject 29 | 30 | \pdfdest name{fitv} fitv 31 | fitv 32 | 33 | \vfill 34 | \eject 35 | 36 | \pdfdest name{fitr} fitr 37 | fitr 38 | 39 | \vfill 40 | \eject 41 | 42 | \pdfdest name{fitb} fitb 43 | fitb 44 | 45 | \vfill 46 | \eject 47 | 48 | \pdfdest name{fitbh} fitbh 49 | fitbh 50 | 51 | \vfill 52 | \eject 53 | 54 | \pdfdest name{fitbv} fitbv 55 | fitbv 56 | 57 | \vfill 58 | \eject 59 | 60 | \pdfdest name{xyz} xyz 61 | xyz 62 | 63 | \vfill 64 | \eject 65 | 66 | \pdfdest name{xyz zoom 1000} xyz zoom 1000 67 | xyz zoom 1000 68 | 69 | \vfill 70 | \eject 71 | 72 | \pdfdest name{xyz zoom 500} xyz zoom 500 73 | xyz zoom 500 74 | 75 | \vfill 76 | \eject 77 | 78 | \pdfdest name{xyz zoom 2000} xyz zoom 2000 79 | xyz zoom 2000 80 | 81 | \vfill 82 | \end 83 | -------------------------------------------------------------------------------- /test/nodest.tex: -------------------------------------------------------------------------------- 1 | % Check for no destination 2 | 3 | %\pdfobjcompresslevel=0 4 | 5 | page 1 6 | 7 | \vfill 8 | \eject 9 | 10 | page 2 11 | 12 | \vfill 13 | \end 14 | -------------------------------------------------------------------------------- /test/pagemode-fullscreen.tex: -------------------------------------------------------------------------------- 1 | % Check for pagemode FullScreen 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /FullScreen} 5 | 6 | page 1 7 | 8 | \vfill 9 | \eject 10 | 11 | page 2 12 | 13 | \vfill 14 | \end 15 | -------------------------------------------------------------------------------- /test/pagemode-thumbs.tex: -------------------------------------------------------------------------------- 1 | % Check for pagemode UseThumbs 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseThumbs} 5 | 6 | page 1 7 | 8 | \vfill 9 | \eject 10 | 11 | page 2 12 | 13 | \vfill 14 | \end 15 | -------------------------------------------------------------------------------- /test/pagemode-usenone.tex: -------------------------------------------------------------------------------- 1 | % Check for pagemode UseNone 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseNone} 5 | 6 | page 1 7 | 8 | \vfill 9 | \eject 10 | 11 | page 2 12 | 13 | \vfill 14 | \end 15 | -------------------------------------------------------------------------------- /test/pdfdocencoding.tex: -------------------------------------------------------------------------------- 1 | % Check for PDFDocEncoding destination names 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | % PDFDocEncoding (nearly Latin-1) 7 | \def\furone{f^^fcr one}% f\"ur one 8 | \def\furtwo{f^^fcr two}% f\"ur two 9 | 10 | % PDFDocEncoding can be used for both destination name and title. 11 | \pdfoutline goto name{\furone} {\furone} 12 | \pdfoutline goto name{\furtwo} {\furtwo} 13 | 14 | \pdfdest name{\furone} xyz 15 | page 1 16 | 17 | \vfill 18 | \eject 19 | 20 | \pdfdest name{\furtwo} xyz 21 | page 2 22 | 23 | \vfill 24 | \end 25 | -------------------------------------------------------------------------------- /test/special-chars.tex: -------------------------------------------------------------------------------- 1 | % Check for special character destination names 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | \catcode`\@=0 7 | @catcode`@\=11 8 | @def@bs{\} 9 | @catcode`@\=0 10 | \catcode`@=12 11 | 12 | % Destination name could be binary. 13 | % title shuld be PDFDocEncoding (also US-ASCII) or UTF-16. 14 | \pdfoutline goto name{^^20} {U+0020 SPACE} 15 | \pdfoutline goto name{\bs 050} {U+0028 LEFT PARENTHESIS} 16 | \pdfoutline goto name{\bs 051} {U+0029 RIGHT PARENTHESIS} 17 | \pdfoutline goto name{<} {U+003C LESS-THAN SIGN} 18 | \pdfoutline goto name{>} {U+003E GREATER-THAN SIGN} 19 | \pdfoutline goto name{[} {U+005B LEFT SQUARE BRACKET} 20 | \pdfoutline goto name{]} {U+005D RIGHT SQUARE BRACKET} 21 | \pdfoutline goto name{\bs 173} {U+007B LEFT CURLY BRACKET} 22 | \pdfoutline goto name{\bs 175} {U+007D RIGHT CURLY BRACKET} 23 | \pdfoutline goto name{/} {U+002F SOLIDUS} 24 | \pdfoutline goto name{\bs 134} {U+005C REVERSE SOLIDUS} 25 | \pdfoutline goto name{\bs 045} {U+0025 PERCENT SIGN} 26 | \pdfoutline goto name{\bs 043} {U+0023 NUMBER SIGN} 27 | \pdfoutline goto name{\bs 177} {U+007F DELETE} 28 | 29 | \pdfdest name{^^20} xyz 30 | U+0020 SPACE 31 | 32 | \vfill 33 | \eject 34 | 35 | \pdfdest name{\bs 050} xyz 36 | U+0028 LEFT PARENTHESIS 37 | 38 | \vfill 39 | \eject 40 | 41 | \pdfdest name{\bs 051} xyz 42 | U+0029 RIGHT PARENTHESIS 43 | 44 | \vfill 45 | \eject 46 | 47 | \pdfdest name{<} xyz 48 | U+003C LESS-THAN SIGN 49 | 50 | \vfill 51 | \eject 52 | 53 | \pdfdest name{>} xyz 54 | U+003E GRATER-THAN SIGN 55 | 56 | \vfill 57 | \eject 58 | 59 | \pdfdest name{[} xyz 60 | U+005B LEFT SQUARE BRACKET 61 | 62 | \vfill 63 | \eject 64 | 65 | \pdfdest name{]} xyz 66 | U+005D RIGHT SQUARE BRACKET 67 | 68 | \vfill 69 | \eject 70 | 71 | \pdfdest name{\bs 173} xyz 72 | U+007B LEFT CURLY BRACKET 73 | 74 | \vfill 75 | \eject 76 | 77 | \pdfdest name{\bs 175} xyz 78 | U+007D RIGHT CURLY BRACKET 79 | 80 | \vfill 81 | \eject 82 | 83 | \pdfdest name{/} xyz 84 | U+002F SOLIDUS 85 | 86 | \vfill 87 | \eject 88 | 89 | \pdfdest name{\bs 134} xyz 90 | U+005C REVERSE SOLIDUS 91 | 92 | \vfill 93 | \eject 94 | 95 | \pdfdest name{\bs 045} xyz 96 | U+0025 PERCENT SIGN 97 | 98 | \vfill 99 | \eject 100 | 101 | \pdfdest name{\bs 043} xyz 102 | U+0023 NUMBER SIGN 103 | 104 | \vfill 105 | \eject 106 | 107 | \pdfdest name{\bs 177} xyz 108 | U+007F DELETE 109 | 110 | \vfill 111 | \end 112 | -------------------------------------------------------------------------------- /test/test-expected-pdfmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | EXPECTEDPDFMARK=$1 4 | BASENAME=`basename ${EXPECTEDPDFMARK} | sed -e "s/-expected\(-.\+\)\?\.pdfmark$//"` 5 | OPTSUFFIX=`echo ${EXPECTEDPDFMARK} | sed -e "s/^\(.*-expected\)\(-.\+\)\?\.pdfmark$/\2/"` 6 | DIRNAME=`dirname ${EXPECTEDPDFMARK}` 7 | 8 | PDF="${DIRNAME}/${BASENAME}.pdf" 9 | EXTRACTEDPDFMARK="${BASENAME}-expected${OPTSUFFIX}-test.pdfmark" 10 | 11 | if [ ! -s ${PDF} ]; then 12 | # skip 13 | exit 77 14 | fi 15 | 16 | case "$OPTSUFFIX" in 17 | "-literal" ) 18 | OPTION="--style=literal" 19 | ;; 20 | "-literal-escape" ) 21 | OPTION="--style=literal --escape" 22 | ;; 23 | "-hex" ) 24 | OPTION="--style=hex" 25 | ;; 26 | "-name" ) 27 | OPTION="--style=name" 28 | ;; 29 | "-name-escape" ) 30 | OPTION="--style=name --escape" 31 | ;; 32 | * ) 33 | OPTION="" 34 | ;; 35 | esac 36 | 37 | ${top_builddir}/src/extractpdfmark ${OPTION} ${PDF} | \ 38 | ${GREP} -v "^%\|^$" > ${EXTRACTEDPDFMARK} 39 | 40 | if test x"$DIFF" = x; then 41 | # skip 42 | exit 77 43 | fi 44 | 45 | ${DIFF} -ubwBE ${EXPECTEDPDFMARK} ${EXTRACTEDPDFMARK} 46 | -------------------------------------------------------------------------------- /test/test-round.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | EXTRACTEDPDFMARK=$1 4 | BASENAME=`basename ${EXTRACTEDPDFMARK} | sed -e "s/-round\(-.\+\)\?\.ps$//"` 5 | OPTSUFFIX=`echo ${EXTRACTEDPDFMARK} | sed -e "s/^\(.*-round\)\(-.\+\)\?\.ps$/\2/"` 6 | 7 | PDF="${BASENAME}.pdf" 8 | PDF2="${BASENAME}-round${OPTSUFFIX}-test.pdf" 9 | EXTRACTEDPDFMARK2="${BASENAME}-round${OPTSUFFIX}-test.ps" 10 | 11 | if [ ! -e ${PDF} ]; then 12 | PDF="${srcdir}/${BASENAME}.pdf" 13 | fi 14 | if [ ! -s ${PDF} ]; then 15 | # skip 16 | exit 77 17 | fi 18 | 19 | case "$OPTSUFFIX" in 20 | "-literal" ) 21 | OPTION="--style=literal" 22 | ;; 23 | "-literal-escape" ) 24 | OPTION="--style=literal --escape" 25 | ;; 26 | "-hex" ) 27 | OPTION="--style=hex" 28 | ;; 29 | "-name" ) 30 | OPTION="--style=name" 31 | ;; 32 | "-name-escape" ) 33 | OPTION="--style=name --escape" 34 | ;; 35 | * ) 36 | OPTION="" 37 | ;; 38 | esac 39 | 40 | if test x"$GHOSTSCRIPT" = x; then 41 | # skip 42 | exit 77 43 | fi 44 | 45 | ${GHOSTSCRIPT} -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=${PDF2} \ 46 | ${PDF} ${EXTRACTEDPDFMARK} 47 | ${top_builddir}/src/extractpdfmark ${OPTION} -o ${EXTRACTEDPDFMARK2} ${PDF2} 48 | 49 | if test x"$DIFF" = x; then 50 | # skip 51 | exit 77 52 | fi 53 | 54 | ${DIFF} -u ${EXTRACTEDPDFMARK} ${EXTRACTEDPDFMARK2} 55 | -------------------------------------------------------------------------------- /test/utf16.tex: -------------------------------------------------------------------------------- 1 | % Check for UTF-16 destination names 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | \catcode0=12 7 | 8 | % UTF-16 9 | \def\furone{^^fe^^ff^^00f^^00^^fc^^00r^^00 ^^00o^^00n^^00e}% f\"ur one 10 | \def\furtwo{^^fe^^ff^^00f^^00^^fc^^00r^^00 ^^00t^^00w^^00o}% f\"ur two 11 | 12 | % UTF-16 can be used for both destination name and title. 13 | \pdfoutline goto name{\furone} {\furone} 14 | \pdfoutline goto name{\furtwo} {\furtwo} 15 | 16 | \pdfdest name{\furone} xyz 17 | page 1 18 | 19 | \vfill 20 | \eject 21 | 22 | \pdfdest name{\furtwo} xyz 23 | page 2 24 | 25 | \vfill 26 | \end 27 | -------------------------------------------------------------------------------- /test/utf8.tex: -------------------------------------------------------------------------------- 1 | % Check for UTF-8 destination names 2 | 3 | %\pdfobjcompresslevel=0 4 | \pdfcatalog{/PageMode /UseOutlines} 5 | 6 | \catcode0=12 7 | 8 | % UTF-16 for title 9 | \def\furonetitle{^^fe^^ff^^00f^^00^^fc^^00r^^00 ^^00o^^00n^^00e}% f\"ur one 10 | \def\furtwotitle{^^fe^^ff^^00f^^00^^fc^^00r^^00 ^^00t^^00w^^00o}% f\"ur two 11 | 12 | % UTF-8 for destination name 13 | \def\furonename{f^^c3^^bcr one}% f\"ur one 14 | \def\furtwoname{f^^c3^^bcr two}% f\"ur two 15 | 16 | % Destination name could be binary (also UTF-8). 17 | % title shuld be PDFDocEncoding or UTF-16. 18 | \pdfoutline goto name{\furonename} {\furonetitle} 19 | \pdfoutline goto name{\furtwoname} {\furtwotitle} 20 | 21 | \pdfdest name{\furonename} xyz 22 | page 1 23 | 24 | \vfill 25 | \eject 26 | 27 | \pdfdest name{\furtwoname} xyz 28 | page 2 29 | 30 | \vfill 31 | \end 32 | --------------------------------------------------------------------------------