<commit_before>#include <stdio.h>
#include <string.h>

#include "pdfgen.h"

int main(int argc, char *argv[])
{
    struct pdf_info info = {
	    .creator = "My software",
	    .producer = "My software",
	    .title = "My document",
	    .author = "<NAME>",
	    .subject = "My subject",
	    .date = "Today"
    };
    struct pdf_doc *pdf = pdf_create(PDF_A4_WIDTH, PDF_A4_HEIGHT, &info);
    int i;
    int height;
    int bm;

    /* Unused */
    (void)argc;
    (void)argv;

    if (pdf_width(pdf) != PDF_A4_WIDTH ||
        pdf_height(pdf) != PDF_A4_HEIGHT) {
        fprintf(stderr, "PDF Size mismatch: %dx%d\n", pdf_width(pdf), pdf_height(pdf));
        return -1;
    }

    i = pdf_get_font_text_width(pdf, "Times-BoldItalic", "foo", 14);
    if (i < 18) {
        fprintf(stderr, "Font width invalid: %d\n", i);
        return -1;
    }

    pdf_set_font(pdf, "Times-BoldItalic");
    pdf_append_page(pdf);

    height = pdf_add_text_wrap(pdf, NULL,
    	"This is a great big long string that I hope will wrap properly "
	"around several lines.\nI've put some embedded line breaks in to "
	"see how it copes with them. Hopefully it all works properly.\n\n\n"
	"We even include multiple breaks\n"
	"thisisanenourmouswordthatwillneverfitandwillhavetobecut",
	16, 60, 600, PDF_RGB(0, 0, 0), 300);
    pdf_add_rectangle(pdf, NULL, 60, 600 + 16, 300, -height, 1, PDF_RGB(0, 0, 0));
    pdf_add_ppm(pdf, NULL, 10, 10, 20, 30, "teapot.ppm");

    pdf_add_jpeg(pdf, NULL, 100, 500, 50, 150, "penguin.jpg");

    pdf_add_barcode(pdf, NULL, PDF_BARCODE_128A, 50, 300, 200, 100, "ABCDEF", PDF_RGB(0, 0, 0));

    pdf_add_text(pdf, NULL, "Page One", 10, 20, 30, PDF_RGB(0xff, 0, 0));
    pdf_add_text(pdf, NULL, "PjGQji", 18, 20, 130, PDF_RGB(0, 0xff, 0xff));
#if 1
    pdf_add_line(pdf, NULL, 10, 24, 100, 24, 4, PDF_RGB(0xff, 0, 0));
    pdf_add_rectangle(pdf, NULL, 150, 150, 100, 100, 4, PDF_RGB(0, 0, 0xff));
    pdf_add_filled_rectangle(pdf, NULL, 150, 450, 100, 100, 4, PDF_RGB(0, 0xff, 0));
    pdf_add_text(pdf, NULL, "", 20, 20, 30, PDF_RGB(0, 0, 0));
    pdf_add_text(pdf, NULL, "Date (YYYY-MM-DD):", 20, 220, 30, PDF_RGB(0, 0, 0));<commit_msg>main: Make sure things fail as we'd expect<commit_after>#include <stdio.h>
#include <string.h>

#include "pdfgen.h"

int main(int argc, char *argv[])
{
    struct pdf_info info = {
	    .creator = "My software",
	    .producer = "My software",
	    .title = "My document",
	    .author = "My name",
	    .subject = "My subject",
	    .date = "Today"
    };
    struct pdf_doc *pdf = pdf_create(PDF_A4_WIDTH, PDF_A4_HEIGHT, &info);
    int i;
    int height;
    int bm;

    /* Unused */
    (void)argc;
    (void)argv;

    if (pdf_width(pdf) != PDF_A4_WIDTH ||
        pdf_height(pdf) != PDF_A4_HEIGHT) {
        fprintf(stderr, "PDF Size mismatch: %dx%d\n", pdf_width(pdf), pdf_height(pdf));
        return -1;
    }

    i = pdf_get_font_text_width(pdf, "Times-BoldItalic", "foo", 14);
    if (i < 18) {
        fprintf(stderr, "Font width invalid: %d\n", i);
        return -1;
    }

    /* These calls should fail, since we haven't added a page yet */
    if (pdf_add_ppm(pdf, NULL, 10, 10, 20, 30, "teapot.ppm") >= 0)
        return -1;

    if (pdf_add_jpeg(pdf, NULL, 100, 500, 50, 150, "penguin.jpg") >= 0)
        return -1;

    if (pdf_add_text(pdf, NULL, "Page One", 10, 20, 30, PDF_RGB(0xff, 0, 0)) >= 0)
        return -1;

    if (pdf_add_bookmark(pdf, NULL, -1, "Another Page") >= 0)
        return -1;

    pdf_clear_err(pdf);
    /* From now on, we shouldn't see any errors */

    pdf_set_font(pdf, "Times-BoldItalic");
    pdf_append_page(pdf);

    height = pdf_add_text_wrap(pdf, NULL,
    	"This is a great big long string that I hope will wrap properly "
	"around several lines.\nI've put some embedded line breaks in to "
	"see how it copes with them. Hopefully it all works properly.\n\n\n"
	"We even include multiple breaks\n"
	"thisisanenourmouswordthatwillneverfitandwillhavetobecut",
	16, 60, 600, PDF_RGB(0, 0, 0), 300);
    pdf_add_rectangle(pdf, NULL, 60, 600 + 16, 300, -height, 1, PDF_RGB(0, 0, 0));
    pdf_add_ppm(pdf, NULL, 10, 10, 20, 30, "teapot.ppm");

    pdf_add_jpeg(pdf, NULL, 100, 500, 50, 150, "penguin.jpg");

    pdf_add_barcode(pdf, NULL, PDF_BARCODE_128A, 50, 300, 200, 100, "ABCDEF", PDF_RGB(0, 0, 0));

    pdf_add_text(pdf, NULL, "Page One", 10, 20, 30, PDF_RGB(0xff, 0, 0));
    pdf_add_text(pdf, NULL, "PjGQji", 18, 20, 130, PDF_RGB(0, 0xff, 0xff));
#if 1
    pdf_add_line(pdf, NULL, 10, 24, 100, 24, 4, PDF_RGB(0xff, 0, 0));
    pdf_add_rectangle(pdf, NULL, 150, 150, 100, 100, 4, PDF_RGB(0, 0, 0xff));
    pdf_add_filled_rectangle(pdf, NULL, 150, 450, 100, 100, 4, PDF_RGB(0, 0xff, 0));
    pdf_add_text(pdf, NULL, "", 20, 20, 30, PDF_RGB(0, 0, 0));
    pdf_add_text(pdf, NULL, "Date (YYYY-MM-DD):", 20, 220, 30, PDF_RGB(0, 0, 0));
{'fraction_non_alphanumeric': 0.1607843137254902, 'fraction_numerical': 0.07244582043343653, 'mean_word_length': 3.2508771929824563, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3640609', 'n_tokens_mistral': 2282, 'n_tokens_neox': 1920, 'n_words': 538}