MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tp_compressed

Function tp_compressed

tests/test_doc_links_pdf.c:385–454  ·  view source on GitHub ↗

A PDF whose page and font live in a Flate object stream, indexed by a * PNG-predicted xref stream, with no classic table at all. */

Source from the content-addressed store, hash-verified

383/* A PDF whose page and font live in a Flate object stream, indexed by a
384 * PNG-predicted xref stream, with no classic table at all. */
385static unsigned char *tp_compressed(size_t *out_len) {
386 const char *content = "BT /F1 12 Tf 72 700 Td (from an object stream) Tj ET";
387 size_t clen;
388 unsigned char *cz = tp_flate(content, strlen(content), &clen);
389 /* object stream: objects 3 (page) and 4 (font) */
390 const char *o3 = "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << "
391 "/F1 4 0 R >> >> /Contents 5 0 R >>";
392 const char *o4 = TP_HELV;
393 char hdr[64];
394 snprintf(hdr, sizeof(hdr), "3 0 4 %zu ", strlen(o3) + 1);
395 tp_buf_t stm = {0};
396 tp_puts(&stm, hdr);
397 size_t first = stm.n;
398 tp_puts(&stm, o3);
399 tp_puts(&stm, " ");
400 tp_puts(&stm, o4);
401 size_t sz;
402 unsigned char *stmz = tp_flate(stm.p, stm.n, &sz);
403 tp_buf_t b = {0};
404 tp_puts(&b, "%PDF-1.7\n");
405 size_t off[8] = {0};
406 char line[256];
407 off[1] = b.n;
408 tp_puts(&b, "1 0 obj\n" TP_CATALOG "\nendobj\n");
409 off[2] = b.n;
410 tp_puts(&b, "2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n");
411 off[5] = b.n;
412 snprintf(line, sizeof(line), "5 0 obj\n<< /Length %zu /Filter /FlateDecode >>\nstream\n", clen);
413 tp_puts(&b, line);
414 tp_put(&b, cz, clen);
415 tp_puts(&b, "\nendstream\nendobj\n");
416 off[6] = b.n;
417 snprintf(line, sizeof(line),
418 "6 0 obj\n<< /Type /ObjStm /N 2 /First %zu /Length %zu /Filter /FlateDecode "
419 ">>\nstream\n",
420 first, sz);
421 tp_puts(&b, line);
422 tp_put(&b, stmz, sz);
423 tp_puts(&b, "\nendstream\nendobj\n");
424 off[7] = b.n;
425 /* xref stream rows: W [1 2 1], PNG Up/None rows of 4 bytes + filter byte */
426 unsigned char rows[8][5];
427 for (int i = 0; i < 8; i++) {
428 unsigned type = (i == 0) ? 0 : (i == 3 || i == 4) ? 2 : 1;
429 unsigned f2 = (type == 1) ? (unsigned)off[i] : (type == 2) ? 6U : 0U;
430 unsigned f3 = (i == 4) ? 1U : 0U;
431 rows[i][0] = 0; /* PNG filter: None */
432 rows[i][1] = (unsigned char)type;
433 rows[i][2] = (unsigned char)(f2 >> 8);
434 rows[i][3] = (unsigned char)f2;
435 rows[i][4] = (unsigned char)f3;
436 }
437 size_t xz;
438 unsigned char *xrz = tp_flate(rows, sizeof(rows), &xz);
439 snprintf(line, sizeof(line),
440 "7 0 obj\n<< /Type /XRef /Size 8 /W [1 2 1] /Root 1 0 R /Length %zu /Filter "
441 "/FlateDecode /DecodeParms << /Predictor 12 /Columns 4 >> >>\nstream\n",
442 xz);

Callers 1

Calls 3

tp_flateFunction · 0.85
tp_putsFunction · 0.85
tp_putFunction · 0.85

Tested by

no test coverage detected