<commit_before>#include "gl-app.h"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

static int is_draw_mode = 0;
static int new_contents = 0;

static char save_filename[PATH_MAX];
static pdf_write_options save_opts;
static struct input opwinput;
static struct input upwinput;
static int do_high_security;
static int hs_resolution = 200;
static struct input ocr_language_input;
static int ocr_language_input_initialised = 0;
static pdf_document *pdf_has_redactions_doc = NULL;
static int pdf_has_redactions;

static int pdf_filter(const char *fn)
{
	const char *extension = strrchr(fn, '.');
	if (extension && !fz_strcasecmp(extension, ".pdf"))
		return 1;
	return 0;
}

static void init_save_pdf_options(void)
{
	save_opts = pdf_default_write_options;
	if (pdf->redacted)
		save_opts.do_garbage = 1;
	if (pdf_can_be_saved_incrementally(ctx, pdf))
		save_opts.do_incremental = 1;
	save_opts.do_compress = 1;
	save_opts.do_compress_images = 1;
	save_opts.do_compress_fonts = 1;
	do_high_security = 0;
	ui_input_init(&opwinput, "");
	ui_input_init(&upwinput, "");
	if (!ocr_language_input_initialised)
	{
		ui_input_init(&ocr_language_input, "eng");
		ocr_language_input_initialised = 1;
	}
}

static const char *cryptalgo_names[] = {
	"Keep",
	"None",
	"RC4, 40 bit",
	"RC4, 128 bit",
	"AES, 128 bit",
	"AES, 256 bit",
};

static void save_pdf_options(void)
{
	const char *cryptalgo = cryptalgo_names[save_opts.do_encrypt];
	int choice;
	int can_be_incremental;

	ui_layout(T, X, NW, 2, 2);
	ui_label("PDF write options:");
	ui_layout(T, X, NW, 4, 2);

	can_be_incremental = pdf_can_be_saved_incrementally(ctx, pdf);

	ui_checkbox("High Security", &do_high_security);
	if (do_high_security)
	{
		int res200 = (hs_resolution == 200);
		int res300 = (hs_resolution == 300);
		int res600 = (hs_resolution == 600);
		int res1200 = (hs_resolution == 1200);
		ui_label("WARNING: High Security saving is a lossy procedure! Keep your original file safe.");
		ui_label("Resolution:");
		ui_checkbox("200", &res200);
		ui_checkbox("300", &res300);
		ui_checkbox("600", &res600);
		ui_checkbox("1200", &res1200);
		if (res200 && hs_resolution != 200)
			hs_resolution = 200;
		else if (res300 && hs_resolution != 300)
			hs_resolution = 300;
		else if (res600 && hs_resolution != 600)
			hs_resolution = 600;
		else if (res1200 && hs_resolution != 1200)
			hs_resolution = 1200;
		else if (!res200 && !res300 && !res600 && !res1200)
			hs_resolution = 200;
		ui_label("OCR Language:");
		ui_input(&ocr_language_input, 32, 1);

		return; /* ignore normal PDF options */
	}

	if (can_be_incremental)
		ui_checkbox("Incremental", &save_opts.do_incremental);

	fz_try(ctx)
	{
		if (pdf_count_signatures(ctx, pdf))
		{
			if (can_be_incremental)
				ui_label("WARNING: Saving non-incrementally will break existing signatures");
			else
				ui_label("WARNING: Saving will break existing signatures");
		}
	}
	fz_catch(ctx)
	{
		/* Ignore the error. */<commit_msg>gl: Only show WARNING about breaking signatures when we would.<commit_after>#include "gl-app.h"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

static int is_draw_mode = 0;
static int new_contents = 0;

static char save_filename[PATH_MAX];
static pdf_write_options save_opts;
static struct input opwinput;
static struct input upwinput;
static int do_high_security;
static int hs_resolution = 200;
static struct input ocr_language_input;
static int ocr_language_input_initialised = 0;
static pdf_document *pdf_has_redactions_doc = NULL;
static int pdf_has_redactions;

static int pdf_filter(const char *fn)
{
	const char *extension = strrchr(fn, '.');
	if (extension && !fz_strcasecmp(extension, ".pdf"))
		return 1;
	return 0;
}

static void init_save_pdf_options(void)
{
	save_opts = pdf_default_write_options;
	if (pdf->redacted)
		save_opts.do_garbage = 1;
	if (pdf_can_be_saved_incrementally(ctx, pdf))
		save_opts.do_incremental = 1;
	save_opts.do_compress = 1;
	save_opts.do_compress_images = 1;
	save_opts.do_compress_fonts = 1;
	do_high_security = 0;
	ui_input_init(&opwinput, "");
	ui_input_init(&upwinput, "");
	if (!ocr_language_input_initialised)
	{
		ui_input_init(&ocr_language_input, "eng");
		ocr_language_input_initialised = 1;
	}
}

static const char *cryptalgo_names[] = {
	"Keep",
	"None",
	"RC4, 40 bit",
	"RC4, 128 bit",
	"AES, 128 bit",
	"AES, 256 bit",
};

static void save_pdf_options(void)
{
	const char *cryptalgo = cryptalgo_names[save_opts.do_encrypt];
	int choice;
	int can_be_incremental;

	ui_layout(T, X, NW, 2, 2);
	ui_label("PDF write options:");
	ui_layout(T, X, NW, 4, 2);

	can_be_incremental = pdf_can_be_saved_incrementally(ctx, pdf);

	ui_checkbox("High Security", &do_high_security);
	if (do_high_security)
	{
		int res200 = (hs_resolution == 200);
		int res300 = (hs_resolution == 300);
		int res600 = (hs_resolution == 600);
		int res1200 = (hs_resolution == 1200);
		ui_label("WARNING: High Security saving is a lossy procedure! Keep your original file safe.");
		ui_label("Resolution:");
		ui_checkbox("200", &res200);
		ui_checkbox("300", &res300);
		ui_checkbox("600", &res600);
		ui_checkbox("1200", &res1200);
		if (res200 && hs_resolution != 200)
			hs_resolution = 200;
		else if (res300 && hs_resolution != 300)
			hs_resolution = 300;
		else if (res600 && hs_resolution != 600)
			hs_resolution = 600;
		else if (res1200 && hs_resolution != 1200)
			hs_resolution = 1200;
		else if (!res200 && !res300 && !res600 && !res1200)
			hs_resolution = 200;
		ui_label("OCR Language:");
		ui_input(&ocr_language_input, 32, 1);

		return; /* ignore normal PDF options */
	}

	if (can_be_incremental)
		ui_checkbox("Incremental", &save_opts.do_incremental);

	fz_try(ctx)
	{
		if (pdf_count_signatures(ctx, pdf) && !save_opts.do_incremental)
		{
			if (can_be_incremental)
				ui_label("WARNING: Saving non-incrementally will break existing signatures");
			else
				ui_label("WARNING: Saving will break existing signatures");
		}
	}
	fz_catch(ctx)
	{
		/* Ignore the error. */
{'fraction_non_alphanumeric': 0.1266233766233766, 'fraction_numerical': 0.047402597402597405, 'mean_word_length': 5.136454183266932, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2100953', 'n_tokens_mistral': 2687, 'n_tokens_neox': 2256, 'n_words': 550}