summaryrefslogtreecommitdiff
path: root/src/pdf_bridge.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-06 18:11:36 -0300
committerGabriel Schneider <[email protected]>2026-09-07 13:59:12 -0300
commit60367d8fe23f6af98ec28e3cf6c2094dfe332df0 (patch)
tree310fc734173cf771881f4691c71909135fadde97 /src/pdf_bridge.c
parentfa82cac885cb4738fe36d1e49b4749b5a3e31a4a (diff)
downloadpardes-60367d8fe23f6af98ec28e3cf6c2094dfe332df0.tar.gz
pardes-60367d8fe23f6af98ec28e3cf6c2094dfe332df0.zip
Refactor panes and filesystem; replace FUSE with 9P
Consolidate pane, layout, memory and host code. Serve 9P by default over Unix sockets, with runtime mounts and optional TCP/QUIC transports. Remove FUSE and obsolete proof-of-concept examples. Fix highlighting and terminal-history performance, expand differential and stress-test infrastructure, sort navigation results while preserving the next occurrence, add syntax-colored Braille minimaps, remove SPC-k, and document 9P interaction as a repository skill.
Diffstat (limited to 'src/pdf_bridge.c')
-rw-r--r--src/pdf_bridge.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/pdf_bridge.c b/src/pdf_bridge.c
index bd72a54a..8e433fde 100644
--- a/src/pdf_bridge.c
+++ b/src/pdf_bridge.c
@@ -316,15 +316,17 @@ pardes_pdf_grown_capacity(size_t current, size_t needed, size_t maximum)
return capacity;
}
-pardes_pdf_document *
-pardes_pdf_open(const char *path, int *page_count)
+static pardes_pdf_document *
+pardes_pdf_open_source(const char *path, const unsigned char *bytes, size_t length, int *page_count)
{
pardes_pdf_document *state;
fz_context *ctx;
fz_document *doc = NULL;
+ fz_buffer *buffer = NULL;
+ fz_stream *stream = NULL;
int pages = 0;
- if (path == NULL || page_count == NULL)
+ if ((path == NULL && bytes == NULL) || page_count == NULL)
return NULL;
state = pardes_pdf_allocate_document();
@@ -344,14 +346,27 @@ pardes_pdf_open(const char *path, int *page_count)
}
fz_var(doc);
+ fz_var(buffer);
+ fz_var(stream);
fz_try(ctx)
{
fz_register_document_handlers(ctx);
- doc = fz_open_document(ctx, path);
+ if (path != NULL) {
+ doc = fz_open_document(ctx, path);
+ } else {
+ buffer = fz_new_buffer_from_copied_data(ctx, bytes, length);
+ stream = fz_open_buffer(ctx, buffer);
+ doc = fz_open_document_with_stream(ctx, "application/pdf", stream);
+ }
pages = fz_count_pages(ctx, doc);
if (pages < 1)
fz_throw(ctx, FZ_ERROR_FORMAT, "PDF has no pages");
}
+ fz_always(ctx)
+ {
+ fz_drop_stream(ctx, stream);
+ fz_drop_buffer(ctx, buffer);
+ }
fz_catch(ctx)
{
fz_report_error(ctx);
@@ -369,6 +384,18 @@ pardes_pdf_open(const char *path, int *page_count)
return state;
}
+pardes_pdf_document *
+pardes_pdf_open(const char *path, int *page_count)
+{
+ return pardes_pdf_open_source(path, NULL, 0, page_count);
+}
+
+pardes_pdf_document *
+pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_count)
+{
+ return pardes_pdf_open_source(NULL, bytes, length, page_count);
+}
+
void
pardes_pdf_close(pardes_pdf_document *document)
{