Skip to content

Commit

Permalink
Merge pull request eugmes#10 from khaledhosny/reproducible-build
Browse files Browse the repository at this point in the history
Support reproducible builds with PDF output
  • Loading branch information
eugmes authored Dec 26, 2018
2 parents eb3ee08 + 7e10a9c commit f244ad2
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion fntsample.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_SFNT_NAMES_H
Expand Down Expand Up @@ -1034,9 +1035,50 @@ int main(int argc, char **argv)
surface = cairo_ps_surface_create(output_file_name, A4_WIDTH, A4_HEIGHT);
else if (svg_output)
surface = cairo_svg_surface_create(output_file_name, A4_WIDTH, A4_HEIGHT);
else
else {
surface = cairo_pdf_surface_create(output_file_name, A4_WIDTH, A4_HEIGHT); /* A4 paper */

#ifdef CAN_USE_CAIRO_OUTLINES
char buffer[25];
char *endptr;
char *source_date_epoch;
unsigned long long epoch;
time_t now;
struct tm *build_time;
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) || (errno != 0 && epoch == 0)) {
fprintf(stderr, _("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"),
strerror(errno));
exit(1);
}
if (endptr == source_date_epoch) {
fprintf(stderr, _("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"),
endptr);
exit(1);
}
if (*endptr != '\0') {
fprintf(stderr, _("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"),
endptr);
exit(1);
}
if (epoch > ULONG_MAX) {
fprintf(stderr, _("Environment variable $SOURCE_DATE_EPOCH: must be <= %lu but saw: %llu\n"),
ULONG_MAX, epoch);
exit(1);
}
now = (time_t)epoch;
build_time = gmtime(&now);
strftime(buffer, 25, "%Y-%m-%dT%H:%M:%S%z", build_time);
cairo_pdf_surface_set_metadata(surface,
CAIRO_PDF_METADATA_CREATE_DATE,
buffer);
}
#endif
}

cr_status = cairo_surface_status(surface);
if (cr_status != CAIRO_STATUS_SUCCESS) {
/* TRANSLATORS: 'cairo' is a name of a library, and should be left untranslated */
Expand Down

0 comments on commit f244ad2

Please sign in to comment.