gdtools/0000755000176200001440000000000014202516522011724 5ustar liggesusersgdtools/NAMESPACE0000644000176200001440000000101614175745336013161 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(font_family_exists) export(fontconfig_reinit) export(glyphs_match) export(m_str_extents) export(match_family) export(raster_str) export(raster_view) export(raster_write) export(set_dummy_conf) export(str_extents) export(str_metrics) export(sys_fonts) export(unset_dummy_conf) export(version_cairo) export(version_freetype) importFrom(Rcpp,sourceCpp) importFrom(grDevices,is.raster) importFrom(systemfonts,match_font) importFrom(systemfonts,system_fonts) useDynLib(gdtools) gdtools/LICENSE0000644000176200001440000010451313775341651012752 0ustar liggesusers GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . gdtools/tools/0000755000176200001440000000000013775341651013101 5ustar liggesusersgdtools/tools/winlibs.R0000644000176200001440000000057213775341651014677 0ustar liggesusersVERSION <- commandArgs(TRUE) if(!file.exists(sprintf("../windows/cairo-%s/include/cairo/cairo.h", VERSION))){ if(getRversion() < "3.3.0") setInternet2() download.file(sprintf("https://github.com/rwinlib/cairo/archive/v%s.zip", VERSION), "lib.zip", quiet = TRUE) dir.create("../windows", showWarnings = FALSE) unzip("lib.zip", exdir = "../windows") unlink("lib.zip") } gdtools/README.md0000644000176200001440000000614114030705275013211 0ustar liggesusers # gdtools [![CRAN status](https://www.r-pkg.org/badges/version/gdtools)](https://CRAN.R-project.org/package=gdtools) [![R build status](https://github.com/davidgohel/gdtools/workflows/R-CMD-check/badge.svg)](https://github.com/davidgohel/gdtools/actions) [![Coverage Status](https://img.shields.io/codecov/c/github/davidgohel/gdtools/master.svg)](https://codecov.io/github/davidgohel/gdtools?branch=master) The package `gdtools` provides functionalities to get font metrics and to generate base64 encoded string from raster matrix. It is used by package `ggiraph` and `rvg` to allow font metric calculation but can also be used to compute the exact size a text would have with specific font options (size, bold, italic). ## Installation You can install the released version of gdtools from [CRAN](https://CRAN.R-project.org) with: ``` r install.packages("gdtools") ``` And the development version from [GitHub](https://github.com/davidgohel/gdtools) with: ``` r # install.packages("devtools") devtools::install_github("davidgohel/gdtools") ``` ## Example ``` r library(gdtools) str_extents(c("a string", "a longer string"), fontsize = 24, bold = TRUE, italic = TRUE) #> [,1] [,2] #> [1,] 86.68359 22.60547 #> [2,] 166.68750 22.60547 ``` ## For mac os users This package needs X11 to be available on mac os machines. This will make cairo, font-config and other system dependancies available. This is documented here: [R for Mac OS X](https://cran.r-project.org/bin/macosx/) ; X11 can be downloaded from [XQuartz](https://www.xquartz.org/) website. - `Unable to load shared object` Sometimes, when your OS got updated, some font settings and several other settings can be changed. An error similar to the one below can be read : Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/Library/Frameworks/R.framework/Versions/.../gdtools/libs/gdtools.so': dlopen(/Library/Frameworks/R.framework/Versions/.../gdtools/libs/gdtools.so, 6): Library not loaded: /opt/X11/lib/libcairo.2.dylib Referenced from: /Library/Frameworks/R.framework/Versions/.../gdtools/libs/gdtools.so Reason: image not found Or Error: package or namespace load failed for ‘xxxx’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/.../systemfonts/libs/systemfonts.so': dlopen(/Library/Frameworks/R.framework/Versions/.../systemfonts/libs/systemfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib Referenced from: /Library/Frameworks/R.framework/Versions/.../systemfonts/libs/systemfonts.so Reason: image not found > Solution: 1. Close all R sessions 2. Re-install XQuartz when upgrading your macOS to a new major version. 3. Re-install package gdtools. If you need to build the package from sources, make sure XCode is installed and you have accepted the license agreement. gdtools/man/0000755000176200001440000000000013775341651012514 5ustar liggesusersgdtools/man/str_extents.Rd0000644000176200001440000000131713775341651015367 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cpp-proxies.R \name{str_extents} \alias{str_extents} \title{Compute string extents.} \usage{ str_extents( x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "" ) } \arguments{ \item{x}{Character vector of strings to measure} \item{fontname}{Font name} \item{fontsize}{Font size} \item{bold, italic}{Is text bold/italic?} \item{fontfile}{Font file} } \description{ Determines the width and height of a bounding box that's big enough to (just) enclose the provided text. } \examples{ str_extents(letters) str_extents("Hello World!", bold = TRUE, italic = FALSE, fontname = "sans", fontsize = 12) } gdtools/man/sys_fonts.Rd0000644000176200001440000000050013775341651015025 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fontconfig.R \name{sys_fonts} \alias{sys_fonts} \title{List system fonts.} \usage{ sys_fonts() } \description{ List system fonts details into a data.frame containing columns foundry, family, file, slant and weight. } \examples{ sys_fonts() } gdtools/man/m_str_extents.Rd0000644000176200001440000000217213775341651015703 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/m_str_extents.R \name{m_str_extents} \alias{m_str_extents} \title{Compute string extents for a vector of string.} \usage{ m_str_extents( x, fontname = "sans", fontsize = 10, bold = FALSE, italic = FALSE, fontfile = NULL ) } \arguments{ \item{x}{Character vector of strings to measure} \item{fontname}{Font name. A vector of character to match with x.} \item{fontsize}{Font size. A vector of numeric to match with x.} \item{bold, italic}{Is text bold/italic?. A vector of logical to match with x.} \item{fontfile}{Font file. A vector of character to match with x.} } \description{ For each \code{x} element, determines the width and height of a bounding box that's big enough to (just) enclose the provided text. Unit is pixel. } \examples{ \donttest{ # The first run can be slow when font caches are missing # as font files are then being scanned to build those font caches. m_str_extents(letters, fontsize = 1:26) m_str_extents(letters[1:3], bold = c(TRUE, FALSE, TRUE), italic = c(FALSE, TRUE, TRUE), fontname = c("sans", "sans", "sans") ) } } gdtools/man/fontconfig_reinit.Rd0000644000176200001440000000065413775341651016516 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fontconfig.R \name{fontconfig_reinit} \alias{fontconfig_reinit} \title{reload Fontconfig configuration} \usage{ fontconfig_reinit() } \description{ This function can be used to make fontconfig reload font configuration files. } \note{ Fontconfig is not used anymore and that function will be deprecated in the next release. } \author{ Paul Murrell } gdtools/man/glyphs_match.Rd0000644000176200001440000000126513775341651015471 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cpp-proxies.R \name{glyphs_match} \alias{glyphs_match} \title{Validate glyph entries} \usage{ glyphs_match(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "") } \arguments{ \item{x}{Character vector of strings} \item{fontname}{Font name} \item{bold, italic}{Is text bold/italic?} \item{fontfile}{Font file} } \value{ a logical vector, if a character element is containing at least a glyph that can not be matched in the font table, FALSE is returned. } \description{ Determines if strings contain glyphs not part of a font. } \examples{ glyphs_match(letters) glyphs_match("\u265E", bold = TRUE) } gdtools/man/raster_write.Rd0000644000176200001440000000131013775341651015510 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/raster.R \name{raster_write} \alias{raster_write} \title{Draw/preview a raster to a png file} \usage{ raster_write(x, path, width = 480, height = 480, interpolate = FALSE) } \arguments{ \item{x}{A raster object} \item{path}{name of the file to create} \item{width, height}{Width and height in pixels.} \item{interpolate}{A logical value indicating whether to linearly interpolate the image.} } \description{ Draw/preview a raster to a png file } \examples{ r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5)) filepng <- tempfile(fileext = ".png") raster_write(x = r, path = filepng, width = 50, height = 50) } gdtools/man/match_family.Rd0000644000176200001440000000113713775341651015442 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fontconfig.R \name{match_family} \alias{match_family} \title{Find best family match with systemfonts} \usage{ match_family(font = "sans", bold = TRUE, italic = TRUE, debug = NULL) } \arguments{ \item{font}{family or face to match.} \item{bold}{Wheter to match a font featuring a \code{bold} face.} \item{italic}{Wheter to match a font featuring an \code{italic} face.} \item{debug}{deprecated} } \description{ \code{match_family()} returns the best font family match. } \examples{ match_family("sans") match_family("serif") } gdtools/man/version_cairo.Rd0000644000176200001440000000067213775341651015652 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/RcppExports.R, R/gdtools.R \name{version_freetype} \alias{version_freetype} \alias{version_cairo} \title{Version numbers of C libraries} \usage{ version_freetype() version_cairo() } \description{ \code{version_cairo()} and \code{version_freetype()} return the runtime version. These helpers return version objects as with \code{\link[utils]{packageVersion}()}. } gdtools/man/font_family_exists.Rd0000644000176200001440000000075713775341651016722 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/font_family_exists.R \name{font_family_exists} \alias{font_family_exists} \title{Check if font family exists.} \usage{ font_family_exists(font_family = "sans") } \arguments{ \item{font_family}{font family name (case sensitive)} } \value{ A logical value } \description{ Check if a font family exists in system fonts. } \examples{ font_family_exists("sans") font_family_exists("Arial") font_family_exists("Courier") } gdtools/man/str_metrics.Rd0000644000176200001440000000116413775341651015343 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cpp-proxies.R \name{str_metrics} \alias{str_metrics} \title{Get font metrics for a string.} \usage{ str_metrics( x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "" ) } \arguments{ \item{x}{Character vector of strings to measure} \item{fontname}{Font name} \item{fontsize}{Font size} \item{bold}{Is text bold/italic?} \item{italic}{Is text bold/italic?} \item{fontfile}{Font file} } \value{ A named numeric vector } \description{ Get font metrics for a string. } \examples{ str_metrics("Hello World!") } gdtools/man/raster_str.Rd0000644000176200001440000000153413775341651015176 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/raster.R \name{raster_str} \alias{raster_str} \alias{raster_view} \title{Draw/preview a raster into a string} \usage{ raster_str(x, width = 480, height = 480, interpolate = FALSE) raster_view(code) } \arguments{ \item{x}{A raster object} \item{width, height}{Width and height in pixels.} \item{interpolate}{A logical value indicating whether to linearly interpolate the image.} \item{code}{base64 code of a raster} } \description{ \code{raster_view} is a helper function for testing. It uses \code{htmltools} to render a png as an image with base64 encoded data image. } \examples{ r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5)) code <- raster_str(r, width = 50, height = 50) if (interactive() && require("htmltools")) { raster_view(code = code) } } gdtools/man/set_dummy_conf.Rd0000644000176200001440000000067013775341651016021 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fontconfig.R \name{set_dummy_conf} \alias{set_dummy_conf} \alias{unset_dummy_conf} \title{Set and unset a minimalistic Fontconfig configuration} \usage{ set_dummy_conf() unset_dummy_conf() } \description{ Set and unset a minimalistic Fontconfig configuration } \note{ Fontconfig is not used anymore and these functions will be deprecated in the next release. } gdtools/DESCRIPTION0000644000176200001440000000247214202516522013437 0ustar liggesusersPackage: gdtools Version: 0.2.4 License: GPL-3 | file LICENSE Title: Utilities for Graphical Rendering Description: Useful tools for writing vector graphics devices. Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", c("aut", "cre")), person("Hadley", "Wickham", , "hadley@rstudio.com", "aut"), person("Lionel", "Henry", , "lionel@rstudio.com", "aut"), person("Jeroen", "Ooms", role = "aut", email = "jeroen@berkeley.edu", comment = c(ORCID = "0000-0002-4035-0289")), person("Yixuan", "Qiu", role = "ctb"), person("R Core Team", role = "cph", comment = "Cairo code from X11 device"), person("RStudio", role = "cph") ) Imports: Rcpp (>= 0.12.12), systemfonts (>= 0.1.1) Suggests: htmltools, testthat, fontquiver (>= 0.2.0), curl Encoding: UTF-8 LinkingTo: Rcpp SystemRequirements: cairo, freetype2, fontconfig BugReports: https://github.com/davidgohel/gdtools/issues RoxygenNote: 7.1.2 NeedsCompilation: yes Packaged: 2022-01-31 11:41:21 UTC; davidgohel Author: David Gohel [aut, cre], Hadley Wickham [aut], Lionel Henry [aut], Jeroen Ooms [aut] (), Yixuan Qiu [ctb], R Core Team [cph] (Cairo code from X11 device), RStudio [cph] Maintainer: David Gohel Repository: CRAN Date/Publication: 2022-02-14 18:20:02 UTC gdtools/tests/0000755000176200001440000000000013775341651013103 5ustar liggesusersgdtools/tests/testthat/0000755000176200001440000000000014202516522014726 5ustar liggesusersgdtools/tests/testthat/test-str_metrics.R0000644000176200001440000000056713775341651020411 0ustar liggesuserscontext("font file metric info") test_that("a string has positive dimensions", { skip_if_not_installed("fontquiver") file <- fontquiver::font("Bitstream Vera", "Sans", "Bold")$ttf value <- str_metrics(x = "Hello World", fontsize = 12, fontfile = file ) expect_true( value["width"] > 0) expect_true( value["ascent"] > 0 ) expect_false( value["descent"] < 0 ) }) gdtools/tests/testthat/test-str_extents.R0000755000176200001440000000174513775341651020437 0ustar liggesuserscontext("metric info") test_that("a string has positive dimensions", { value <- str_extents("Hello World!") expect_true(all( value > 0 )) }) extents <- function(font, ...) { extents <- str_extents("foobar", fontfile = font$ttf, ...) as.vector(round(extents, 4)) } test_that("known fonts have correct metrics", { skip_if_not_installed("fontquiver") sans <- fontquiver::font("Liberation", "Sans", "Regular") mono_bi <- fontquiver::font("Bitstream Vera", "Sans Mono", "Bold Oblique") expect_equal(extents(sans), c(34.0254, 8.8281), tolerance = .1) expect_equal(extents(mono_bi), c(43.3477, 9.2969), tolerance = .1) }) test_that("fractional font sizes are correctly measured", { skip_if_not_installed("fontquiver") sans <- fontquiver::font("Liberation", "Sans", "Regular") if (version_freetype() < "2.6.0") { skip("Old FreeType return different extents for fractional sizes") } expect_equal(extents(sans, fontsize = 15.05), c(42.5317, 11.0156), tolerance = .2) }) gdtools/tests/testthat/test-raster.R0000755000176200001440000000070013775341651017343 0ustar liggesuserscontext("raster") test_that("raster_str", { r <- as.raster(matrix(hcl(0, 80, seq(40, 80, 10)), nrow = 5, ncol = 4)) code <- raster_str(r, width = 50, height = 50) expect_gt(nchar(x = code), 50) }) test_that("raster_write", { r <- as.raster(matrix(hcl(0, 80, seq(40, 80, 10)), nrow = 5, ncol = 4)) filename <- tempfile(fileext = ".png") raster_write(r, path = filename, width = 50, height = 50) expect_true(file.exists(filename)) }) gdtools/tests/testthat/helper-fontconfig.R0000644000176200001440000000010613775341651020474 0ustar liggesusers local <- function() { identical(Sys.getenv("NOT_CRAN"), "true") } gdtools/tests/testthat.R0000644000176200001440000000007213775341651015065 0ustar liggesuserslibrary(testthat) library(gdtools) test_check("gdtools") gdtools/src/0000755000176200001440000000000014175745341012527 5ustar liggesusersgdtools/src/CairoContext.cpp0000644000176200001440000001117113775341651015637 0ustar liggesusers#include #include #include #include #include #include #include #include #include FT_FREETYPE_H #include "gdtools_types.h" using namespace Rcpp; struct CairoContext::CairoContext_ { cairo_surface_t* surface; cairo_t* context; FT_Library library; fontCache fonts; }; CairoContext::CairoContext() { cairo_ = new CairoContext_(); cairo_->surface = cairo_pdf_surface_create(NULL, 720, 720); cairo_->context = cairo_create(cairo_->surface); if (FT_Init_FreeType(&(cairo_->library))) Rcpp::stop("FreeType error: unable to initialize FreeType library object"); } CairoContext::~CairoContext() { fontCache::iterator it = cairo_->fonts.begin(); while (it != cairo_->fonts.end()) { cairo_font_face_destroy(it->second); ++it; } cairo_surface_destroy(cairo_->surface); cairo_destroy(cairo_->context); delete cairo_; } void CairoContext::cacheFont(fontCache& cache, std::string& key, std::string fontfile, int fontindex) { FT_Face face; if (0 != FT_New_Face(cairo_->library, fontfile.c_str(), fontindex, &face)) Rcpp::stop("FreeType error: unable to open %s", fontfile.c_str()); cairo_font_face_t* cairo_face = cairo_ft_font_face_create_for_ft_face(face, 0); cairo_user_data_key_t font_key; cairo_status_t status = cairo_font_face_set_user_data( cairo_face, &font_key, face, (cairo_destroy_func_t) FT_Done_Face ); if (status) { cairo_font_face_destroy(cairo_face); FT_Done_Face(face); Rcpp::stop("Cairo error: unable to handle %s", fontfile.c_str()); } cache[key] = cairo_face; } struct font_file_t { std::string file; int index; }; static int locate_font(const char *family, int italic, int bold, char *path, int max_path_length) { static int (*p_locate_font)(const char *family, int italic, int bold, char *path, int max_path_length) = NULL; if (p_locate_font == NULL) { p_locate_font = (int(*)(const char *, int, int, char *, int)) R_GetCCallable("systemfonts", "locate_font"); } return p_locate_font(family, italic, bold, path, max_path_length); } font_file_t findFontFile(const char* fontname, int bold, int italic) { char *path = new char[PATH_MAX+1]; path[PATH_MAX] = '\0'; font_file_t output; output.index = locate_font(fontname, italic, bold, path, PATH_MAX); output.file = path; delete[] path; if (output.file.size()) return output; else Rcpp::stop("error: unable to match font pattern"); } void CairoContext::setFont(std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile) { std::string key; if (fontfile.size()) { // Use file path as key to cached elements key = fontfile; if (cairo_->fonts.find(key) == cairo_->fonts.end()) { cacheFont(cairo_->fonts, key, fontfile, 0); } } else { // Use font name and bold/italic properties as key char props[20]; snprintf(props, sizeof(props), " %d %d", (int) bold, (int) italic); key = fontname + props; if (cairo_->fonts.find(key) == cairo_->fonts.end()) { // Add font to cache font_file_t fontfile = findFontFile(fontname.c_str(), bold, italic); cacheFont(cairo_->fonts, key, fontfile.file, fontfile.index); } } cairo_set_font_size(cairo_->context, fontsize); cairo_set_font_face(cairo_->context, cairo_->fonts[key]); } FontMetric CairoContext::getExtents(std::string x) { cairo_text_extents_t te; cairo_text_extents(cairo_->context, x.c_str(), &te); FontMetric fm; fm.height = te.height; fm.width = te.x_advance; fm.ascent = -te.y_bearing; fm.descent = te.height + te.y_bearing; return fm; } bool CairoContext::validateGlyphs(std::string x) { cairo_glyph_t* glyphs = NULL; int glyph_count; cairo_text_cluster_t* clusters = NULL; int cluster_count; cairo_text_cluster_flags_t clusterflags; bool out = true; cairo_status_t status = cairo_scaled_font_text_to_glyphs(cairo_get_scaled_font(cairo_->context), 0, 0, x.c_str(), x.size(), &glyphs, &glyph_count, &clusters, &cluster_count, &clusterflags); if (status == CAIRO_STATUS_SUCCESS) { // for each cluster int glyph_index = 0; for (int i = 0; i < cluster_count; i++) { cairo_text_cluster_t* cluster = &clusters[i]; cairo_glyph_t* clusterglyphs = &glyphs[glyph_index]; if( clusterglyphs[0].index < 1 ){ out = false; break; } glyph_index += cluster->num_glyphs; } } else stop("Could not get table of glyphs"); cairo_glyph_free(glyphs); cairo_text_cluster_free(clusters); return out; } gdtools/src/gdtools.cpp0000644000176200001440000000125113775341651014706 0ustar liggesusers#include "gdtools_types.h" #include using namespace Rcpp; // [[Rcpp::interfaces(r, cpp)]] // [[Rcpp::export]] XPtrCairoContext context_create() { return XPtrCairoContext(new CairoContext()); } // [[Rcpp::export]] bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile = "") { cc->setFont(fontname, fontsize, bold, italic, fontfile); // should return void, but doesn't seem to be supported for cpp // interface return true; } // [[Rcpp::export]] FontMetric context_extents(XPtrCairoContext cc, std::string x) { return cc->getExtents(x); } gdtools/src/tests/0000755000176200001440000000000013775341651013672 5ustar liggesusersgdtools/src/tests/sysdeps.c0000644000176200001440000000011013775341651015520 0ustar liggesusers#include #include int main () { return 0; } gdtools/src/font_metrics.cpp0000644000176200001440000000513313775341651015732 0ustar liggesusers#include "gdtools_types.h" #include #include using namespace Rcpp; // [[Rcpp::export]] NumericMatrix str_extents_(CharacterVector x, std::string fontname = "sans", double fontsize = 12, int bold = false, int italic = false, std::string fontfile = "") { int n = x.size(); CairoContext cc; cc.setFont(fontname, fontsize, bold, italic, fontfile); NumericMatrix out(n, 2); for (int i = 0; i < n; ++i) { if (x[i] == NA_STRING) { out(i, 0) = NA_REAL; out(i, 1) = NA_REAL; } else { std::string str(Rf_translateCharUTF8(x[i])); FontMetric fm = cc.getExtents(str); out(i, 0) = fm.width; out(i, 1) = fm.height; } } return out; } // [[Rcpp::export]] NumericVector str_metrics_(CharacterVector x, std::string fontname = "sans", double fontsize = 12, int bold = false, int italic = false, std::string fontfile = "") { CairoContext cc; cc.setFont(fontname, fontsize, bold, italic, fontfile); std::string str(Rf_translateCharUTF8(x[0])); FontMetric fm = cc.getExtents(str); return NumericVector::create( _["width"] = fm.width, _["ascent"] = fm.ascent, _["descent"] = fm.descent ); } // [[Rcpp::export]] NumericMatrix m_str_extents_(CharacterVector x, std::vector fontname, std::vector fontsize, std::vector bold, std::vector italic, std::vector fontfile) { int n = x.size(); CairoContext cc; NumericMatrix out(n, 2); for (int i = 0; i < n; ++i) { cc.setFont(fontname[i], fontsize[i], bold[i], italic[i], fontfile[i]); if (x[i] == NA_STRING) { out(i, 0) = NA_REAL; out(i, 1) = NA_REAL; } else { std::string str(Rf_translateCharUTF8(x[i])); FontMetric fm = cc.getExtents(str); out(i, 0) = fm.width; out(i, 1) = fm.height; } } return out; } // [[Rcpp::export]] LogicalVector glyphs_match_(CharacterVector x, std::string fontname = "sans", int bold = false, int italic = false, std::string fontfile = "") { int n = x.size(); CairoContext cc; cc.setFont(fontname, 10.0, bold, italic, fontfile); LogicalVector out(n); for (int i = 0; i < n; ++i) { if (x[i] == NA_STRING) { out(i) = NA_LOGICAL; } else { std::string str(Rf_translateCharUTF8(x[i])); out(i) = cc.validateGlyphs(str); } } return out; } gdtools/src/Makevars.win0000644000176200001440000000060614065046250015010 0ustar liggesusersVERSION = 1.16.0 RWINLIB = ../windows/cairo-${VERSION} PKG_CPPFLAGS = -I${RWINLIB}/include/cairo -I${RWINLIB}/include \ -I${RWINLIB}/include/freetype2 -I../inst/include PKG_LIBS = -L${RWINLIB}/lib${R_ARCH}${CRT} -lcairo -lfreetype -lpng -lpixman-1 \ -lharfbuzz -lbz2 -lz -liconv -lgdi32 all: winlibs winlibs: "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" ${VERSION} gdtools/src/raster_to_base64.cpp0000644000176200001440000001507613775341651016413 0ustar liggesusers#include #include #include #include #include #include "cairo.h" using namespace Rcpp; using namespace std; // [[Rcpp::interfaces(r, cpp)]] #define R_RED(col) (((col) )&255) #define R_GREEN(col) (((col)>> 8)&255) #define R_BLUE(col) (((col)>>16)&255) #define R_ALPHA(col) (((col)>>24)&255) static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; std::string base64_encode(std::vector data) { unsigned int in_len = data.size(); unsigned char* bytes_to_encode = reinterpret_cast(data.data()); std::string ret; int i = 0; int j = 0; unsigned char char_array_3[3]; unsigned char char_array_4[4]; while (in_len--) { char_array_3[i++] = *(bytes_to_encode++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (i = 0; (i < 4); i++) ret += base64_chars[char_array_4[i]]; i = 0; } } if (i) { for (j = i; j < 3; j++) char_array_3[j] = '\0'; char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (j = 0; (j < i + 1); j++) ret += base64_chars[char_array_4[j]]; while ((i++ < 3)) ret += '='; } return ret; } static cairo_status_t stream_data(void* closure, const unsigned char* data, unsigned int length) { vector* in = reinterpret_cast*>(closure); for (unsigned int i = 0; i < length; ++i) in->push_back(data[i]); return CAIRO_STATUS_SUCCESS; } /* The Cairo raster code is adapted from R's X11 device (c) 2010 R Development Core Team, GPL 2+ */ cairo_surface_t* raster_paint_surface(std::vector& raster, int w, int h, double width, double height, int interpolate) { int img_width = static_cast (std::ceil(width)); int img_height = static_cast (std::ceil(height)); cairo_surface_t* base_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, img_width, img_height ); cairo_t* cc = cairo_create(base_surface); double w_factor = width / w; double h_factor = height / h; if (std::isnan(w_factor)) w_factor = 1; if (std::isnan(h_factor)) h_factor = 1; cairo_scale(cc, w_factor, h_factor); std::vector imageData(4 * w * h); for (int i = 0; i < w * h; i++) { int alpha = R_ALPHA(raster[i]); imageData[i*4 + 3] = alpha; if (alpha < 255) { imageData[i*4 + 2] = R_RED(raster[i]) * alpha / 255; imageData[i*4 + 1] = R_GREEN(raster[i]) * alpha / 255; imageData[i*4 + 0] = R_BLUE(raster[i]) * alpha / 255; } else { imageData[i*4 + 2] = R_RED(raster[i]); imageData[i*4 + 1] = R_GREEN(raster[i]); imageData[i*4 + 0] = R_BLUE(raster[i]); } } int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w); cairo_surface_t* image = cairo_image_surface_create_for_data( &imageData[0], CAIRO_FORMAT_ARGB32, w, h, stride ); cairo_set_source_surface(cc, image, 0, 0); if (interpolate > 0) { cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_BILINEAR); cairo_pattern_set_extend(cairo_get_source(cc), CAIRO_EXTEND_PAD); } else cairo_pattern_set_filter(cairo_get_source(cc), CAIRO_FILTER_NEAREST); cairo_new_path(cc); cairo_rectangle(cc, 0, 0, w, h); cairo_clip(cc); cairo_paint(cc); cairo_destroy(cc); cairo_surface_destroy(image); return base_surface; } // [[Rcpp::export]] std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate) { cairo_surface_t* surface = raster_paint_surface( raster, w, h, width, height, interpolate ); std::vector in; cairo_surface_write_to_png_stream(surface, stream_data, &in); cairo_surface_destroy(surface); return base64_encode(in); } // [[Rcpp::export]] int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename) { cairo_surface_t* surface = raster_paint_surface( raster, w, h, width, height, interpolate ); cairo_surface_write_to_png(surface, filename.c_str()); cairo_surface_destroy(surface); return 1; } vector convert_hex(vector hcode) { vector bit_coded_colors(hcode.size()); for( size_t i = 0 ; i < hcode.size() ; i++ ){ std::stringstream str_abgr; unsigned int bit_coded_color; string in = "0x"; if( hcode[i].size() == 9 ) { in += hcode[i].substr(7, 2 ); } else in += "FF"; in += hcode[i].substr(5, 2 ); in += hcode[i].substr(3, 2 ); in += hcode[i].substr(1, 2 ); str_abgr << std::hex << in; str_abgr >> bit_coded_color; bit_coded_colors[i] = bit_coded_color; } return bit_coded_colors; } // [[Rcpp::export]] bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename) { vector raster = Rcpp::as >(raster_); vector out = convert_hex(raster); raster_to_file(out, w, h, width, height, interpolate, filename); return true; } // [[Rcpp::export]] std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate) { vector raster = Rcpp::as >(raster_); vector out = convert_hex(raster); return raster_to_str(out, w, h, width, height, interpolate); } // Encode a file into base64. // [[Rcpp::export]] std::string base64_file_encode(std::string filename) { ifstream ifs(filename.c_str(), ios::binary | ios::ate); if (!ifs.good()) stop("Failed to open %s", filename); ifstream::pos_type pos = ifs.tellg(); std::vector result(pos); ifs.seekg(0, ios::beg); ifs.read(&result[0], pos); ifs.close(); return base64_encode(result); } // [[Rcpp::export]] std::string base64_string_encode(std::string string) { std::vector chars(string.begin(), string.end()); return base64_encode(chars); } gdtools/src/Makevars.ucrt0000644000176200001440000000003714065046250015166 0ustar liggesusersCRT=-ucrt include Makevars.win gdtools/src/versions.cpp0000644000176200001440000000165313775341651015111 0ustar liggesusers#include #include #include FT_FREETYPE_H #include Rcpp::List version_make(int major, int minor, int patch) { Rcpp::IntegerVector version; Rcpp::CharacterVector s3_class; version = Rcpp::IntegerVector::create(major, minor, patch); s3_class = Rcpp::CharacterVector::create("package_version", "numeric_version"); Rcpp::List output; output = Rcpp::List::create(version); output.attr("class") = s3_class; return output; } //' @rdname version_cairo //' @export // [[Rcpp::export]] Rcpp::List version_freetype() { FT_Library library; if (FT_Init_FreeType(&library)) Rcpp::stop("FreeType error: unable to initialise library"); int major, minor, patch = 0; FT_Library_Version(library, &major, &minor, &patch); FT_Done_FreeType(library); return version_make(major, minor, patch); } // [[Rcpp::export]] Rcpp::CharacterVector version_cairo_() { return cairo_version_string(); } gdtools/src/Makevars.in0000644000176200001440000000020513775341651014626 0ustar liggesusersPKG_CPPFLAGS=@cflags@ -I../inst/include/ PKG_CXXFLAGS=$(C_VISIBILITY) PKG_LIBS=@libs@ all: clean clean: rm -f $(SHLIB) $(OBJECTS) gdtools/src/RcppExports.cpp0000644000176200001440000005467414175740000015527 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include "../inst/include/gdtools.h" #include "../inst/include/gdtools_types.h" #include #include #include using namespace Rcpp; #ifdef RCPP_USE_GLOBAL_ROSTREAM Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // str_extents_ NumericMatrix str_extents_(CharacterVector x, std::string fontname, double fontsize, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_str_extents_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(str_extents_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // str_metrics_ NumericVector str_metrics_(CharacterVector x, std::string fontname, double fontsize, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_str_metrics_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(str_metrics_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // m_str_extents_ NumericMatrix m_str_extents_(CharacterVector x, std::vector fontname, std::vector fontsize, std::vector bold, std::vector italic, std::vector fontfile); RcppExport SEXP _gdtools_m_str_extents_(SEXP xSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::vector >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< std::vector >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< std::vector >::type bold(boldSEXP); Rcpp::traits::input_parameter< std::vector >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::vector >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(m_str_extents_(x, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // glyphs_match_ LogicalVector glyphs_match_(CharacterVector x, std::string fontname, int bold, int italic, std::string fontfile); RcppExport SEXP _gdtools_glyphs_match_(SEXP xSEXP, SEXP fontnameSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< CharacterVector >::type x(xSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< int >::type bold(boldSEXP); Rcpp::traits::input_parameter< int >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(glyphs_match_(x, fontname, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP } // context_create XPtrCairoContext context_create(); static SEXP _gdtools_context_create_try() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; rcpp_result_gen = Rcpp::wrap(context_create()); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_create() { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_create_try()); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // context_set_font bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile); static SEXP _gdtools_context_set_font_try(SEXP ccSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< XPtrCairoContext >::type cc(ccSEXP); Rcpp::traits::input_parameter< std::string >::type fontname(fontnameSEXP); Rcpp::traits::input_parameter< double >::type fontsize(fontsizeSEXP); Rcpp::traits::input_parameter< bool >::type bold(boldSEXP); Rcpp::traits::input_parameter< bool >::type italic(italicSEXP); Rcpp::traits::input_parameter< std::string >::type fontfile(fontfileSEXP); rcpp_result_gen = Rcpp::wrap(context_set_font(cc, fontname, fontsize, bold, italic, fontfile)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_set_font(SEXP ccSEXP, SEXP fontnameSEXP, SEXP fontsizeSEXP, SEXP boldSEXP, SEXP italicSEXP, SEXP fontfileSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_set_font_try(ccSEXP, fontnameSEXP, fontsizeSEXP, boldSEXP, italicSEXP, fontfileSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // context_extents FontMetric context_extents(XPtrCairoContext cc, std::string x); static SEXP _gdtools_context_extents_try(SEXP ccSEXP, SEXP xSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< XPtrCairoContext >::type cc(ccSEXP); Rcpp::traits::input_parameter< std::string >::type x(xSEXP); rcpp_result_gen = Rcpp::wrap(context_extents(cc, x)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_context_extents(SEXP ccSEXP, SEXP xSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_context_extents_try(ccSEXP, xSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_to_str std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate); static SEXP _gdtools_raster_to_str_try(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::vector >::type raster(rasterSEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); rcpp_result_gen = Rcpp::wrap(raster_to_str(raster, w, h, width, height, interpolate)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_to_str(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_to_str_try(rasterSEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_to_file int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename); static SEXP _gdtools_raster_to_file_try(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::vector >::type raster(rasterSEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(raster_to_file(raster, w, h, width, height, interpolate, filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_to_file(SEXP rasterSEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_to_file_try(rasterSEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP, filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // raster_png_ bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename); static SEXP _gdtools_raster_png__try(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type raster_(raster_SEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(raster_png_(raster_, w, h, width, height, interpolate, filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_raster_png_(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP, SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_raster_png__try(raster_SEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP, filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_raster_encode std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate); static SEXP _gdtools_base64_raster_encode_try(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< CharacterVector >::type raster_(raster_SEXP); Rcpp::traits::input_parameter< int >::type w(wSEXP); Rcpp::traits::input_parameter< int >::type h(hSEXP); Rcpp::traits::input_parameter< double >::type width(widthSEXP); Rcpp::traits::input_parameter< double >::type height(heightSEXP); Rcpp::traits::input_parameter< int >::type interpolate(interpolateSEXP); rcpp_result_gen = Rcpp::wrap(base64_raster_encode(raster_, w, h, width, height, interpolate)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_raster_encode(SEXP raster_SEXP, SEXP wSEXP, SEXP hSEXP, SEXP widthSEXP, SEXP heightSEXP, SEXP interpolateSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_raster_encode_try(raster_SEXP, wSEXP, hSEXP, widthSEXP, heightSEXP, interpolateSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_file_encode std::string base64_file_encode(std::string filename); static SEXP _gdtools_base64_file_encode_try(SEXP filenameSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::string >::type filename(filenameSEXP); rcpp_result_gen = Rcpp::wrap(base64_file_encode(filename)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_file_encode(SEXP filenameSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_file_encode_try(filenameSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // base64_string_encode std::string base64_string_encode(std::string string); static SEXP _gdtools_base64_string_encode_try(SEXP stringSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< std::string >::type string(stringSEXP); rcpp_result_gen = Rcpp::wrap(base64_string_encode(string)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } RcppExport SEXP _gdtools_base64_string_encode(SEXP stringSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = PROTECT(_gdtools_base64_string_encode_try(stringSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { UNPROTECT(1); Rf_onintr(); } bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen); if (rcpp_isLongjump_gen) { Rcpp::internal::resumeJump(rcpp_result_gen); } Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error"); if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); Rf_error(CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; } // version_freetype Rcpp::List version_freetype(); RcppExport SEXP _gdtools_version_freetype() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(version_freetype()); return rcpp_result_gen; END_RCPP } // version_cairo_ Rcpp::CharacterVector version_cairo_(); RcppExport SEXP _gdtools_version_cairo_() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; rcpp_result_gen = Rcpp::wrap(version_cairo_()); return rcpp_result_gen; END_RCPP } // validate (ensure exported C++ functions exist before calling them) static int _gdtools_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { signatures.insert("XPtrCairoContext(*context_create)()"); signatures.insert("bool(*context_set_font)(XPtrCairoContext,std::string,double,bool,bool,std::string)"); signatures.insert("FontMetric(*context_extents)(XPtrCairoContext,std::string)"); signatures.insert("std::string(*raster_to_str)(std::vector,int,int,double,double,int)"); signatures.insert("int(*raster_to_file)(std::vector,int,int,double,double,int,std::string)"); signatures.insert("bool(*raster_png_)(CharacterVector,int,int,double,double,int,std::string)"); signatures.insert("std::string(*base64_raster_encode)(CharacterVector,int,int,double,double,int)"); signatures.insert("std::string(*base64_file_encode)(std::string)"); signatures.insert("std::string(*base64_string_encode)(std::string)"); } return signatures.find(sig) != signatures.end(); } // registerCCallable (register entry points for exported C++ functions) RcppExport SEXP _gdtools_RcppExport_registerCCallable() { R_RegisterCCallable("gdtools", "_gdtools_context_create", (DL_FUNC)_gdtools_context_create_try); R_RegisterCCallable("gdtools", "_gdtools_context_set_font", (DL_FUNC)_gdtools_context_set_font_try); R_RegisterCCallable("gdtools", "_gdtools_context_extents", (DL_FUNC)_gdtools_context_extents_try); R_RegisterCCallable("gdtools", "_gdtools_raster_to_str", (DL_FUNC)_gdtools_raster_to_str_try); R_RegisterCCallable("gdtools", "_gdtools_raster_to_file", (DL_FUNC)_gdtools_raster_to_file_try); R_RegisterCCallable("gdtools", "_gdtools_raster_png_", (DL_FUNC)_gdtools_raster_png__try); R_RegisterCCallable("gdtools", "_gdtools_base64_raster_encode", (DL_FUNC)_gdtools_base64_raster_encode_try); R_RegisterCCallable("gdtools", "_gdtools_base64_file_encode", (DL_FUNC)_gdtools_base64_file_encode_try); R_RegisterCCallable("gdtools", "_gdtools_base64_string_encode", (DL_FUNC)_gdtools_base64_string_encode_try); R_RegisterCCallable("gdtools", "_gdtools_RcppExport_validate", (DL_FUNC)_gdtools_RcppExport_validate); return R_NilValue; } static const R_CallMethodDef CallEntries[] = { {"_gdtools_str_extents_", (DL_FUNC) &_gdtools_str_extents_, 6}, {"_gdtools_str_metrics_", (DL_FUNC) &_gdtools_str_metrics_, 6}, {"_gdtools_m_str_extents_", (DL_FUNC) &_gdtools_m_str_extents_, 6}, {"_gdtools_glyphs_match_", (DL_FUNC) &_gdtools_glyphs_match_, 5}, {"_gdtools_context_create", (DL_FUNC) &_gdtools_context_create, 0}, {"_gdtools_context_set_font", (DL_FUNC) &_gdtools_context_set_font, 6}, {"_gdtools_context_extents", (DL_FUNC) &_gdtools_context_extents, 2}, {"_gdtools_raster_to_str", (DL_FUNC) &_gdtools_raster_to_str, 6}, {"_gdtools_raster_to_file", (DL_FUNC) &_gdtools_raster_to_file, 7}, {"_gdtools_raster_png_", (DL_FUNC) &_gdtools_raster_png_, 7}, {"_gdtools_base64_raster_encode", (DL_FUNC) &_gdtools_base64_raster_encode, 6}, {"_gdtools_base64_file_encode", (DL_FUNC) &_gdtools_base64_file_encode, 1}, {"_gdtools_base64_string_encode", (DL_FUNC) &_gdtools_base64_string_encode, 1}, {"_gdtools_version_freetype", (DL_FUNC) &_gdtools_version_freetype, 0}, {"_gdtools_version_cairo_", (DL_FUNC) &_gdtools_version_cairo_, 0}, {"_gdtools_RcppExport_registerCCallable", (DL_FUNC) &_gdtools_RcppExport_registerCCallable, 0}, {NULL, NULL, 0} }; RcppExport void R_init_gdtools(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } gdtools/NEWS0000644000176200001440000000530314065046250012427 0ustar liggesusers# gdtools 0.2.4 * Windows: add support for ucrt toolchains # gdtools 0.2.3 * fixes for configure script for M1 mac and solaris # gdtools 0.2.2 * Small tweaks for configure script # gdtools 0.2.1 ## issues * Change font_family_exists so that it only check a family exists in family column returned by systemfonts::system_fonts() * fix a memory leak # gdtools 0.2.0 * refactor - package is now using package systemfonts instead of using fontconfig to locate fonts file # gdtools 0.1.9 * keep locale intact when using various gdtools functions (fix #51) * Reuse magick FONTCONFIG_PATH if exists # gdtools 0.1.8 * Windows: update cairo stack to rwinlib/cairo v1.15.10 # gdtools 0.1.6 * update with Rcpp 0.12.12 * new function `glyphs_match` to test whether glyphs in strings are all existing in a font table or not. # gdtools 0.1.5 * increase tolerance in font metrics unit-tests as new version of freetype is slightly changing returned extents. # gdtools 0.1.4 * New file src/registerDynamicSymbol.c to correctly register provided routines * a cleanup file to delete src/Makevars when package has been built # gdtools 0.1.3 * Add set_dummy_conf() and unset_dummy_conf() to set a minimalistic Fontconfig configuration. Useful to speed up cache building on Appveyor or CRAN. * skip tests that need fontquiver when not installed. # gdtools 0.1.2 * Fix a crash on some Linux platforms (hadley/svglite#80) # gdtools 0.1.1 ## updates * examples from sys_fonts and match_family are marked as donttest as their first run can be slow if no font caches are existing. # gdtools 0.1.0 ## new functions * sys_fonts: get system fonts details. * font_family_exists: test if a given font family name can be matched exactly * match_family: find best family match for a given Fontconfig pattern * match_font: returns font information for a given Fontconfig pattern * base64_string_export: encode a string in base64 * version_cairo: runtime version of the Cairo library * version_freetype: runtime version of the FreeType library * version_fontconfig: compile-time version of the Fontconfig library ## updates * CONFIGURE file has been updated with Homebrew new repo (Jeroen Ooms) * GPL-3 license file has been added * CairoContext now uses Fontconfig to find system fonts * CairoContext now supports user-defined font files # gdtools 0.0.7 * Fix to let OS X Snow Leopard produce binaries (Jeroen Ooms) # gdtools 0.0.6 * Fix to prevent OSX CRAN builder from linking against old libs in /usr/local/lib (Jeroen Ooms) # gdtools 0.0.5 * new function raster_write to write raster object to a png file * usage of testthat # gdtools 0.0.4 * Fix for Mavericks CRAN builder (Jeroen Ooms) * Fix for solaris CRAN builder (Jeroen Ooms) gdtools/configure.win0000644000176200001440000000000013775341651014427 0ustar liggesusersgdtools/R/0000755000176200001440000000000014175745335012144 5ustar liggesusersgdtools/R/m_str_extents.R0000644000176200001440000000313513775341651015165 0ustar liggesusers#' Compute string extents for a vector of string. #' #' For each \code{x} element, determines the width and height of a bounding box that's big enough #' to (just) enclose the provided text. Unit is pixel. #' @param x Character vector of strings to measure #' @param bold,italic Is text bold/italic?. A vector of logical to match with x. #' @param fontname Font name. A vector of character to match with x. #' @param fontsize Font size. A vector of numeric to match with x. #' @param fontfile Font file. A vector of character to match with x. #' @examples #' \donttest{ #' # The first run can be slow when font caches are missing #' # as font files are then being scanned to build those font caches. #' m_str_extents(letters, fontsize = 1:26) #' m_str_extents(letters[1:3], #' bold = c(TRUE, FALSE, TRUE), #' italic = c(FALSE, TRUE, TRUE), #' fontname = c("sans", "sans", "sans") ) #' } #' @export m_str_extents <- function(x, fontname = "sans", fontsize=10, bold = FALSE, italic = FALSE, fontfile = NULL) { stopifnot(is.character(x), is.character(fontname), is.numeric(fontsize), is.logical(bold), is.logical(italic), is.character(fontfile) || is.null(fontfile)) max_length <- length(x) fontname <- rep(fontname, length.out = max_length) fontsize <- rep(fontsize, length.out = max_length) bold <- rep(bold, length.out = max_length) italic <- rep(italic, length.out = max_length) if( is.null(fontfile) ) fontfile <- rep("", length.out = max_length) else fontfile <- rep(fontfile, length.out = max_length) m_str_extents_(x, fontname, fontsize, bold, italic, fontfile) } gdtools/R/RcppExports.R0000644000176200001440000000520614175745335014563 0ustar liggesusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 str_extents_ <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_str_extents_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } str_metrics_ <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_str_metrics_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } m_str_extents_ <- function(x, fontname, fontsize, bold, italic, fontfile) { .Call('_gdtools_m_str_extents_', PACKAGE = 'gdtools', x, fontname, fontsize, bold, italic, fontfile) } glyphs_match_ <- function(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "") { .Call('_gdtools_glyphs_match_', PACKAGE = 'gdtools', x, fontname, bold, italic, fontfile) } context_create <- function() { .Call('_gdtools_context_create', PACKAGE = 'gdtools') } context_set_font <- function(cc, fontname, fontsize, bold, italic, fontfile = "") { .Call('_gdtools_context_set_font', PACKAGE = 'gdtools', cc, fontname, fontsize, bold, italic, fontfile) } context_extents <- function(cc, x) { .Call('_gdtools_context_extents', PACKAGE = 'gdtools', cc, x) } raster_to_str <- function(raster, w, h, width, height, interpolate) { .Call('_gdtools_raster_to_str', PACKAGE = 'gdtools', raster, w, h, width, height, interpolate) } raster_to_file <- function(raster, w, h, width, height, interpolate, filename) { .Call('_gdtools_raster_to_file', PACKAGE = 'gdtools', raster, w, h, width, height, interpolate, filename) } raster_png_ <- function(raster_, w, h, width, height, interpolate, filename) { .Call('_gdtools_raster_png_', PACKAGE = 'gdtools', raster_, w, h, width, height, interpolate, filename) } base64_raster_encode <- function(raster_, w, h, width, height, interpolate) { .Call('_gdtools_base64_raster_encode', PACKAGE = 'gdtools', raster_, w, h, width, height, interpolate) } base64_file_encode <- function(filename) { .Call('_gdtools_base64_file_encode', PACKAGE = 'gdtools', filename) } base64_string_encode <- function(string) { .Call('_gdtools_base64_string_encode', PACKAGE = 'gdtools', string) } #' @rdname version_cairo #' @export version_freetype <- function() { .Call('_gdtools_version_freetype', PACKAGE = 'gdtools') } version_cairo_ <- function() { .Call('_gdtools_version_cairo_', PACKAGE = 'gdtools') } # Register entry points for exported C++ functions methods::setLoadAction(function(ns) { .Call('_gdtools_RcppExport_registerCCallable', PACKAGE = 'gdtools') }) gdtools/R/font_family_exists.R0000644000176200001440000000076613775341651016204 0ustar liggesusers#' @title Check if font family exists. #' #' @description Check if a font family exists in system fonts. #' #' @return A logical value #' @param font_family font family name (case sensitive) #' @examples #' font_family_exists("sans") #' font_family_exists("Arial") #' font_family_exists("Courier") #' @export #' @importFrom systemfonts match_font system_fonts font_family_exists <- function( font_family = "sans" ){ datafonts <- system_fonts() tolower(font_family) %in% tolower(datafonts$family) } gdtools/R/fontconfig.R0000644000176200001440000000277613775341651014435 0ustar liggesusers#' @title List system fonts. #' #' @description List system fonts details into a data.frame containing columns foundry, family, #' file, slant and weight. #' #' @examples #' sys_fonts() #' @export sys_fonts <- function() { system_fonts() } #' Find best family match with systemfonts #' #' \code{match_family()} returns the best font family match. #' #' @param font family or face to match. #' @param bold Wheter to match a font featuring a \code{bold} face. #' @param italic Wheter to match a font featuring an \code{italic} face. #' @param debug deprecated #' @export #' @examples #' match_family("sans") #' match_family("serif") #' @importFrom systemfonts match_font system_fonts match_family <- function(font = "sans", bold = TRUE, italic = TRUE, debug = NULL) { font <- match_font(font, bold = bold, italic = italic) sysfonts <- system_fonts() match <- which( sysfonts$path %in% font$path ) sysfonts$family[match[1]] } #' Set and unset a minimalistic Fontconfig configuration #' #' @note #' Fontconfig is not used anymore and these functions will be deprecated #' in the next release. #' @export set_dummy_conf <- function() { } #' @rdname set_dummy_conf #' @export unset_dummy_conf <- function() { } #' @export #' @title reload Fontconfig configuration #' @description This function can be used to make fontconfig #' reload font configuration files. #' @note #' Fontconfig is not used anymore and that function will be deprecated #' in the next release. #' @author Paul Murrell fontconfig_reinit <- function() { } gdtools/R/cpp-proxies.R0000644000176200001440000000331713775341651014542 0ustar liggesusers#' Compute string extents. #' #' Determines the width and height of a bounding box that's big enough #' to (just) enclose the provided text. #' #' @param x Character vector of strings to measure #' @param bold,italic Is text bold/italic? #' @param fontname Font name #' @param fontsize Font size #' @param fontfile Font file #' @examples #' str_extents(letters) #' str_extents("Hello World!", bold = TRUE, italic = FALSE, #' fontname = "sans", fontsize = 12) #' @export str_extents <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { str_extents_(x = x, fontname = fontname, fontsize = fontsize, bold = bold, italic = italic, fontfile = fontfile) } #' Get font metrics for a string. #' #' @return A named numeric vector #' @inheritParams str_extents #' @examples #' str_metrics("Hello World!") #' @export str_metrics <- function(x, fontname = "sans", fontsize = 12, bold = FALSE, italic = FALSE, fontfile = "") { str_metrics_(x = x, fontname = fontname, fontsize = fontsize, bold = bold, italic = italic, fontfile = fontfile) } #' Validate glyph entries #' #' Determines if strings contain glyphs not part of a font. #' #' @param x Character vector of strings #' @param bold,italic Is text bold/italic? #' @param fontname Font name #' @param fontfile Font file #' @return a logical vector, if a character element is containing at least #' a glyph that can not be matched in the font table, FALSE is returned. #' #' @examples #' glyphs_match(letters) #' glyphs_match("\u265E", bold = TRUE) #' @export glyphs_match <- function(x, fontname = "sans", bold = FALSE, italic = FALSE, fontfile = "") { glyphs_match_(x = x, fontname = fontname, bold = bold, italic = italic, fontfile = fontfile) } gdtools/R/gdtools.R0000644000176200001440000000104013775341651013733 0ustar liggesusers#' @useDynLib gdtools #' @importFrom Rcpp sourceCpp #' @importFrom grDevices is.raster NULL #' Version numbers of C libraries #' #' \code{version_cairo()} and \code{version_freetype()} return the #' runtime version. These helpers return version objects as with #' \code{\link[utils]{packageVersion}()}. #' @export version_cairo <- function() { ver <- version_cairo_() ver <- strsplit(ver, "\\.")[[1]] ver <- as.integer(ver) structure(list(ver), class = c("package_version", "numeric_version")) } #' @importFrom systemfonts match_font gdtools/R/raster.R0000644000176200001440000000354413775341651013573 0ustar liggesusers#' Draw/preview a raster into a string #' #' \code{raster_view} is a helper function for testing. It uses \code{htmltools} #' to render a png as an image with base64 encoded data image. #' #' @param x A raster object #' @param width,height Width and height in pixels. #' @param interpolate A logical value indicating whether to linearly #' interpolate the image. #' @param code base64 code of a raster #' @export #' @examples #' r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), #' nrow = 4, ncol = 5)) #' code <- raster_str(r, width = 50, height = 50) #' if (interactive() && require("htmltools")) { #' raster_view(code = code) #' } raster_str <- function(x, width = 480, height = 480, interpolate = FALSE) { stopifnot(is.raster(x)) value <- base64_raster_encode(x, w = ncol(x), h = nrow(x), width = width, height = height, interpolate = interpolate) value } #' @export #' @rdname raster_str raster_view <- function(code) { img <- paste0("") htmltools::browsable(htmltools::HTML(img)) } #' Draw/preview a raster to a png file #' #' @param x A raster object #' @param path name of the file to create #' @param width,height Width and height in pixels. #' @param interpolate A logical value indicating whether to linearly #' interpolate the image. #' @export #' @examples #' r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), #' nrow = 4, ncol = 5)) #' filepng <- tempfile(fileext = ".png") #' raster_write(x = r, path = filepng, width = 50, height = 50) raster_write <- function(x, path, width = 480, height = 480, interpolate = FALSE) { stopifnot(is.raster(x)) raster_png_(raster_ = x, w = ncol(x), h = nrow(x), width = as.double(width), height = as.double(height), interpolate = interpolate, filename = path) invisible(path) } gdtools/MD50000644000176200001440000000471414202516522012242 0ustar liggesusersc6dbcb3ec8b60268387fea836f1b0b22 *DESCRIPTION d32239bcb673463ab874e80d47fae504 *LICENSE 17e091526c7c7ee58963c25f0a96d132 *NAMESPACE 5bb5f9c91114da0b8faffd0705983f96 *NEWS f0b63e0e1999064c425ca8e457c0db15 *R/RcppExports.R 0dad7da6bd5af9c60d02ae54d2b8b52c *R/cpp-proxies.R d935e76475f802bdcd4212f86f29ab0c *R/font_family_exists.R 51211b7bfa3b3b670272e74a628f3b8f *R/fontconfig.R 44b848e6ac68b95511b7c6f6821b3680 *R/gdtools.R 7b4828e8bffaa4d4e587f9a3cab7b83a *R/m_str_extents.R 94780024b9e98d4c01a56e06e239f668 *R/raster.R e55eed021ce056376fa2f6a75e4e453d *README.md bc7baead3b6080f04dc81efd2fe1ff39 *cleanup c1f70d35e2a53fd66525c4f6b3cff86c *configure d41d8cd98f00b204e9800998ecf8427e *configure.win 1dd40cfbddcb72173c6d8c2f6b3c8df9 *inst/include/gdtools.h 02ccd021b0ef8f143602d8585ca29ee2 *inst/include/gdtools_RcppExports.h d41d8cd98f00b204e9800998ecf8427e *inst/include/gdtools_types.cpp 2dca6b353cb2cd15593657282218b299 *inst/include/gdtools_types.h 0eb091ca1aaad54395a3bd0201079e36 *man/font_family_exists.Rd 7a1d9ec664e2782a674ab250d3de635f *man/fontconfig_reinit.Rd 4b0ba549d0569f2cc6f8dd0cf3b5c2ab *man/glyphs_match.Rd 47e9db8a68651574e69245ddc44a32b4 *man/m_str_extents.Rd 4dab2884581711ea97cfce4ec03c2716 *man/match_family.Rd 79c3fe71d0572cdddd1f5faf661559e2 *man/raster_str.Rd 9ec0dc2f294656184a81f2dd91529fa8 *man/raster_write.Rd 9bc98cdde728bd01bd614abb107953bb *man/set_dummy_conf.Rd 7105402ca296c58c1bff7ee830b24bc7 *man/str_extents.Rd f9e97eefcc3b288f1d9f0ef5f97f4155 *man/str_metrics.Rd 0dd12297ab29ee5742cb81dfb646a744 *man/sys_fonts.Rd 06afbcca1d0a00c5635944cceb0f3a8e *man/version_cairo.Rd 1406cbb642867f1cec46d30ce148c67d *src/CairoContext.cpp 131e8f2086512f6bd15d7a46fd2998f4 *src/Makevars.in 2cec33791efd347cbcb051402d7cf9c4 *src/Makevars.ucrt 5600c2d7c88bb8a0d6e6aa262ba3a7e1 *src/Makevars.win dd0998651a1a355a6c28f30c51df870f *src/RcppExports.cpp 2053aadb4276b4066e13af220812b9b8 *src/font_metrics.cpp bc6a9479fe9002fc251f3bbca282c303 *src/gdtools.cpp d15f803daf529add0e3c695271bbede3 *src/raster_to_base64.cpp e88be22bd4f02671ef54bf42f42065b8 *src/tests/sysdeps.c 8dabb51a7c1a30785bf722556222a85f *src/versions.cpp d8252437453801ecb341846f83005a7f *tests/testthat.R 3f1839b260441de56baeb401d2b22b7b *tests/testthat/helper-fontconfig.R 2f541f9d74d8ef19bcda19a7ab42729d *tests/testthat/test-raster.R df90cd2644166b7e6efde5b4c377f5fc *tests/testthat/test-str_extents.R 363712ab46912f592279feed64afc32e *tests/testthat/test-str_metrics.R b4e631b807cfc1d857d50f5367200070 *tools/winlibs.R gdtools/inst/0000755000176200001440000000000013775430755012722 5ustar liggesusersgdtools/inst/include/0000755000176200001440000000000013775341651014341 5ustar liggesusersgdtools/inst/include/gdtools_RcppExports.h0000644000176200001440000002707413775341651020550 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_gdtools_RCPPEXPORTS_H_GEN_ #define RCPP_gdtools_RCPPEXPORTS_H_GEN_ #include "gdtools_types.h" #include namespace gdtools { using namespace Rcpp; namespace { void validateSignature(const char* sig) { Rcpp::Function require = Rcpp::Environment::base_env()["require"]; require("gdtools", Rcpp::Named("quietly") = true); typedef int(*Ptr_validate)(const char*); static Ptr_validate p_validate = (Ptr_validate) R_GetCCallable("gdtools", "_gdtools_RcppExport_validate"); if (!p_validate(sig)) { throw Rcpp::function_not_exported( "C++ function with signature '" + std::string(sig) + "' not found in gdtools"); } } } inline XPtrCairoContext context_create() { typedef SEXP(*Ptr_context_create)(); static Ptr_context_create p_context_create = NULL; if (p_context_create == NULL) { validateSignature("XPtrCairoContext(*context_create)()"); p_context_create = (Ptr_context_create)R_GetCCallable("gdtools", "_gdtools_context_create"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_create(); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline bool context_set_font(XPtrCairoContext cc, std::string fontname, double fontsize, bool bold, bool italic, std::string fontfile = "") { typedef SEXP(*Ptr_context_set_font)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_context_set_font p_context_set_font = NULL; if (p_context_set_font == NULL) { validateSignature("bool(*context_set_font)(XPtrCairoContext,std::string,double,bool,bool,std::string)"); p_context_set_font = (Ptr_context_set_font)R_GetCCallable("gdtools", "_gdtools_context_set_font"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_set_font(Shield(Rcpp::wrap(cc)), Shield(Rcpp::wrap(fontname)), Shield(Rcpp::wrap(fontsize)), Shield(Rcpp::wrap(bold)), Shield(Rcpp::wrap(italic)), Shield(Rcpp::wrap(fontfile))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline FontMetric context_extents(XPtrCairoContext cc, std::string x) { typedef SEXP(*Ptr_context_extents)(SEXP,SEXP); static Ptr_context_extents p_context_extents = NULL; if (p_context_extents == NULL) { validateSignature("FontMetric(*context_extents)(XPtrCairoContext,std::string)"); p_context_extents = (Ptr_context_extents)R_GetCCallable("gdtools", "_gdtools_context_extents"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_context_extents(Shield(Rcpp::wrap(cc)), Shield(Rcpp::wrap(x))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string raster_to_str(std::vector raster, int w, int h, double width, double height, int interpolate) { typedef SEXP(*Ptr_raster_to_str)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_to_str p_raster_to_str = NULL; if (p_raster_to_str == NULL) { validateSignature("std::string(*raster_to_str)(std::vector,int,int,double,double,int)"); p_raster_to_str = (Ptr_raster_to_str)R_GetCCallable("gdtools", "_gdtools_raster_to_str"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_to_str(Shield(Rcpp::wrap(raster)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline int raster_to_file(std::vector raster, int w, int h, double width, double height, int interpolate, std::string filename) { typedef SEXP(*Ptr_raster_to_file)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_to_file p_raster_to_file = NULL; if (p_raster_to_file == NULL) { validateSignature("int(*raster_to_file)(std::vector,int,int,double,double,int,std::string)"); p_raster_to_file = (Ptr_raster_to_file)R_GetCCallable("gdtools", "_gdtools_raster_to_file"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_to_file(Shield(Rcpp::wrap(raster)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate)), Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline bool raster_png_(CharacterVector raster_, int w, int h, double width, double height, int interpolate, std::string filename) { typedef SEXP(*Ptr_raster_png_)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_raster_png_ p_raster_png_ = NULL; if (p_raster_png_ == NULL) { validateSignature("bool(*raster_png_)(CharacterVector,int,int,double,double,int,std::string)"); p_raster_png_ = (Ptr_raster_png_)R_GetCCallable("gdtools", "_gdtools_raster_png_"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_raster_png_(Shield(Rcpp::wrap(raster_)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate)), Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_raster_encode(CharacterVector raster_, int w, int h, double width, double height, int interpolate) { typedef SEXP(*Ptr_base64_raster_encode)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_base64_raster_encode p_base64_raster_encode = NULL; if (p_base64_raster_encode == NULL) { validateSignature("std::string(*base64_raster_encode)(CharacterVector,int,int,double,double,int)"); p_base64_raster_encode = (Ptr_base64_raster_encode)R_GetCCallable("gdtools", "_gdtools_base64_raster_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_raster_encode(Shield(Rcpp::wrap(raster_)), Shield(Rcpp::wrap(w)), Shield(Rcpp::wrap(h)), Shield(Rcpp::wrap(width)), Shield(Rcpp::wrap(height)), Shield(Rcpp::wrap(interpolate))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_file_encode(std::string filename) { typedef SEXP(*Ptr_base64_file_encode)(SEXP); static Ptr_base64_file_encode p_base64_file_encode = NULL; if (p_base64_file_encode == NULL) { validateSignature("std::string(*base64_file_encode)(std::string)"); p_base64_file_encode = (Ptr_base64_file_encode)R_GetCCallable("gdtools", "_gdtools_base64_file_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_file_encode(Shield(Rcpp::wrap(filename))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } inline std::string base64_string_encode(std::string string) { typedef SEXP(*Ptr_base64_string_encode)(SEXP); static Ptr_base64_string_encode p_base64_string_encode = NULL; if (p_base64_string_encode == NULL) { validateSignature("std::string(*base64_string_encode)(std::string)"); p_base64_string_encode = (Ptr_base64_string_encode)R_GetCCallable("gdtools", "_gdtools_base64_string_encode"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; rcpp_result_gen = p_base64_string_encode(Shield(Rcpp::wrap(string))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen)) throw Rcpp::LongjumpException(rcpp_result_gen); if (rcpp_result_gen.inherits("try-error")) throw Rcpp::exception(Rcpp::as(rcpp_result_gen).c_str()); return Rcpp::as(rcpp_result_gen); } } #endif // RCPP_gdtools_RCPPEXPORTS_H_GEN_ gdtools/inst/include/gdtools.h0000644000176200001440000000037213775341651016167 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #ifndef RCPP_gdtools_H_GEN_ #define RCPP_gdtools_H_GEN_ #include "gdtools_RcppExports.h" #endif // RCPP_gdtools_H_GEN_ gdtools/inst/include/gdtools_types.cpp0000644000176200001440000000000013775341651017732 0ustar liggesusersgdtools/inst/include/gdtools_types.h0000644000176200001440000000302413775341651017410 0ustar liggesusers#ifndef __GDTOOLS_TYPES__ #define __GDTOOLS_TYPES__ #include class FontMetric { public: double height, width, ascent, descent; FontMetric(); FontMetric(SEXP); operator SEXP() const ; }; #include using namespace Rcpp; inline FontMetric::FontMetric() {} inline FontMetric::FontMetric(SEXP x_) { Rcpp::NumericVector x(x_); if (x.size() != 4) Rcpp::stop("Invalid size"); width = x[0]; height = x[1]; ascent = x[2]; descent = x[3]; } inline FontMetric::operator SEXP() const { return Rcpp::NumericVector::create(width, height, ascent, descent); } typedef struct _cairo_font_face cairo_font_face_t; class CairoContext { struct CairoContext_; CairoContext_* cairo_; typedef std::map fontCache; public: CairoContext(); ~CairoContext(); void cacheFont(fontCache& cache, std::string& key, std::string fontfile, int fontindex); void cacheSystemFont(std::string& key, std::string& fontname, bool bold, bool italic); void setFont(std::string fontname = "sans", double fontsize = 12, bool bold = false, bool italic = false, std::string fontfile = ""); void setUserFont(std::string& fontname, double fontsize, bool bold, bool italic, std::string& fontfile); void setSystemFont(std::string& fontname, double fontsize, bool bold, bool italic); FontMetric getExtents(std::string x); bool validateGlyphs(std::string x); }; typedef Rcpp::XPtr XPtrCairoContext; #endif gdtools/cleanup0000755000176200001440000000005314175745341013313 0ustar liggesusers#!/bin/sh rm -f src/Makevars configure.log gdtools/configure0000755000176200001440000000621514175745341013653 0ustar liggesusers# Anticonf script by Jeroen Ooms (2020) # The script will try 'pkg-config' to find required cflags and ldflags. # Make sure this executable is in PATH when installing the package. # Alternatively, you can set INCLUDE_DIR and LIB_DIR manually: # R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib' # Library settings PKG_CONFIG_NAME="cairo freetype2" PKG_DEB_NAME="libcairo2-dev" PKG_RPM_NAME="cairo-devel" PKG_CSW_NAME="libcairo_dev" PKG_BREW_NAME="cairo" PKG_LIBS="-lcairo -lfreetype" PKG_TEST_FILE="src/tests/sysdeps.c" # Prefer static linking on MacOS if [ `uname` = "Darwin" ]; then PKG_CONFIG_NAME="--static $PKG_CONFIG_NAME" if [ `arch` = "i386" ]; then export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libffi/lib/pkgconfig" fi fi # Use pkg-config if available if [ `command -v pkg-config` ]; then PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}` PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}` fi # On CRAN do not use pkgconfig cairo (which depends on XQuartz) if [ -d "/Builds/CRAN-QA-Simon" ] || [ -d "/Volumes/Builds" ]; then unset PKGCONFIG_CFLAGS unset PKGCONFIG_LIBS fi # Note that cflags may be empty in case of success if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then echo "Found INCLUDE_DIR and/or LIB_DIR!" PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS" PKG_LIBS="-L$LIB_DIR $PKG_LIBS" elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then echo "Found pkg-config cflags and libs!" PKG_CFLAGS=${PKGCONFIG_CFLAGS} PKG_LIBS=${PKGCONFIG_LIBS} elif [ `uname` = "Darwin" ]; then brew --version 2>/dev/null if [ $? -eq 0 ]; then BREWDIR=`brew --prefix` PKG_CFLAGS="-I$BREWDIR/include/cairo -I$BREWDIR/include/fontconfig -I$BREWDIR/include/freetype2" PKG_LIBS="-L$BREWDIR/lib $PKG_LIBS" else curl -sfL "https://autobrew.github.io/scripts/cairo" > autobrew . autobrew fi fi # Find compiler CC=`${R_HOME}/bin/R CMD config CC` CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS` CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS` # For debugging echo "Using PKG_CFLAGS=$PKG_CFLAGS" echo "Using PKG_LIBS=$PKG_LIBS" # Test configuration ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log if [ $? -ne 0 ]; then echo "-----------------------------[ ANTICONF ]-------------------------------" echo "Configuration failed to find libraries. Try installing:" echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu)" echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)" echo " * csw: $PKG_CSW_NAME (Solaris)" echo " * brew: $PKG_BREW_NAME (OSX)" echo "If $PKG_CONFIG_NAME are already installed, check that 'pkg-config' is in your" echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config" echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:" echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" echo "---------------------------[ ERROR MESSAGE ]----------------------------" cat configure.log echo "------------------------------------------------------------------------" exit 1 fi # Write to Makevars sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars # Success exit 0