<commit_before>#include "pdfapp.h"
#include "mupdf.h"
#include "muxps.h"
#include "mucbz.h"

#include <ctype.h> /* for tolower() */

#define ZOOMSTEP 1.142857
#define BEYOND_THRESHHOLD 40

enum panning
{
	DONT_PAN = 0,
	PAN_TO_TOP,
	PAN_TO_BOTTOM
};

static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repaint);

static void pdfapp_warn(pdfapp_t *app, const char *fmt, ...)
{
	char buf[1024];
	va_list ap;
	va_start(ap, fmt);
	vsprintf(buf, fmt, ap);
	va_end(ap);
	winwarn(app, buf);
}

static void pdfapp_error(pdfapp_t *app, char *msg)
{
	winerror(app, msg);
}

char *pdfapp_version(pdfapp_t *app)
{
	return
		"MuPDF 0.9\n"
		"Copyright 2006-2012 Artifex Software, Inc.\n";
}

char *pdfapp_usage(pdfapp_t *app)
{
	return
		"L\t\t-- rotate left\n"
		"R\t\t-- rotate right\n"
		"h\t\t-- scroll left\n"
		"j down\t\t-- scroll down\n"
		"k up\t\t-- scroll up\n"
		"l\t\t-- scroll right\n"
		"+\t\t-- zoom in\n"
		"-\t\t-- zoom out\n"
		"w\t\t-- shrinkwrap\n"
		"r\t\t-- reload file\n"
		". pgdn right space\t-- next page\n"
		", pgup left b\t-- previous page\n"
		">\t\t-- next 10 pages\n"
		"<\t\t-- back 10 pages\n"
		"m\t\t-- mark page for snap back\n"
		"t\t\t-- pop back to latest mark\n"
		"1m\t\t-- mark page in register 1\n"
		"1t\t\t-- go to page in register 1\n"
		"123g\t\t-- go to page 123\n"
		"/\t\t-- search for text\n"
		"n\t\t-- find next search result\n"
		"N\t\t-- find previous search result\n"
		"c\t\t-- toggle between color and grayscale\n"
	;
}

void pdfapp_init(fz_context *ctx, pdfapp_t *app)
{
	memset(app, 0, sizeof(pdfapp_t));
	app->scrw = 640;
	app->scrh = 480;
	app->resolution = 72;
	app->ctx = ctx;
}

void pdfapp_invert(pdfapp_t *app, fz_bbox rect)
{
	fz_invert_pixmap_rect(app->image, rect);
}

void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload)
{
	fz_context *ctx = app->ctx;
	fz_stream *file;
	char *password = "";

	fz_try(ctx)
	{
		file = fz_open_fd(ctx, fd);

		if (strstr(filename, ".xps") || strstr(filename, ".XPS") || strstr(filename, ".rels"))
			app->doc = (fz_document*) xps_open_document_with_stream(file);
		else if (strstr(filename, ".cbz") || strstr(filename, ".CBZ") || strstr(filename, ".zip") || strstr(filename, ".ZIP"))
			app->doc = (fz_document*) cbz_open_document_with_stream(file);
		else
			app->doc = (fz_document*) pdf_open_document_with_stream(file);
<commit_msg>Allow XPS document to be opened from unzipped _rels/.rels in mupdf app again.<commit_after>#include "pdfapp.h"
#include "mupdf.h"
#include "muxps.h"
#include "mucbz.h"

#include <ctype.h> /* for tolower() */

#define ZOOMSTEP 1.142857
#define BEYOND_THRESHHOLD 40

enum panning
{
	DONT_PAN = 0,
	PAN_TO_TOP,
	PAN_TO_BOTTOM
};

static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repaint);

static void pdfapp_warn(pdfapp_t *app, const char *fmt, ...)
{
	char buf[1024];
	va_list ap;
	va_start(ap, fmt);
	vsprintf(buf, fmt, ap);
	va_end(ap);
	winwarn(app, buf);
}

static void pdfapp_error(pdfapp_t *app, char *msg)
{
	winerror(app, msg);
}

char *pdfapp_version(pdfapp_t *app)
{
	return
		"MuPDF 0.9\n"
		"Copyright 2006-2012 Artifex Software, Inc.\n";
}

char *pdfapp_usage(pdfapp_t *app)
{
	return
		"L\t\t-- rotate left\n"
		"R\t\t-- rotate right\n"
		"h\t\t-- scroll left\n"
		"j down\t\t-- scroll down\n"
		"k up\t\t-- scroll up\n"
		"l\t\t-- scroll right\n"
		"+\t\t-- zoom in\n"
		"-\t\t-- zoom out\n"
		"w\t\t-- shrinkwrap\n"
		"r\t\t-- reload file\n"
		". pgdn right space\t-- next page\n"
		", pgup left b\t-- previous page\n"
		">\t\t-- next 10 pages\n"
		"<\t\t-- back 10 pages\n"
		"m\t\t-- mark page for snap back\n"
		"t\t\t-- pop back to latest mark\n"
		"1m\t\t-- mark page in register 1\n"
		"1t\t\t-- go to page in register 1\n"
		"123g\t\t-- go to page 123\n"
		"/\t\t-- search for text\n"
		"n\t\t-- find next search result\n"
		"N\t\t-- find previous search result\n"
		"c\t\t-- toggle between color and grayscale\n"
	;
}

void pdfapp_init(fz_context *ctx, pdfapp_t *app)
{
	memset(app, 0, sizeof(pdfapp_t));
	app->scrw = 640;
	app->scrh = 480;
	app->resolution = 72;
	app->ctx = ctx;
}

void pdfapp_invert(pdfapp_t *app, fz_bbox rect)
{
	fz_invert_pixmap_rect(app->image, rect);
}

void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload)
{
	fz_context *ctx = app->ctx;
	fz_stream *file;
	char *password = "";

	fz_try(ctx)
	{
		file = fz_open_fd(ctx, fd);

		if (strstr(filename, ".rels"))
			app->doc = (fz_document*) xps_open_document(ctx, filename);
		else if (strstr(filename, ".xps") || strstr(filename, ".XPS") || strstr(filename, ".rels"))
			app->doc = (fz_document*) xps_open_document_with_stream(file);
		else if (strstr(filename, ".cbz") || strstr(filename, ".CBZ") || strstr(filename, ".zip") || strstr(filename, ".ZIP"))
			app->doc = (fz_document*) cbz_open_document_with_stream(file);
		else
			app->doc = (fz_document*) pdf_open_document_with_stream(file);

{'fraction_non_alphanumeric': 0.17990606493771696, 'fraction_numerical': 0.01919542577088013, 'mean_word_length': 3.4365942028985508, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, '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': '859612', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2154, 'n_words': 510}