Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/reference/c/fitz/context.md @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 # Context | |
| 2 | |
| 3 Almost all functions in the MuPDF library take a `fz_context` structure as | |
| 4 their first argument. The context is used for many things; primarily it holds | |
| 5 the exception stack for our `setjmp` based exception handling. It also holds | |
| 6 various caches and auxiliary contexts for font rendering and color management. | |
| 7 | |
| 8 Here is the code to create a Fitz context. The first two arguments are used if | |
| 9 you need to use a custom memory allocator, and the third argument is a hint to | |
| 10 much memory the various caches should be allowed to grow. The limit is only a | |
| 11 soft limit. We may exceed it, but will start clearing out stale data to try to | |
| 12 stay below the limit when possible. Setting it to a lower value will prevent | |
| 13 the caches from growing out of hand if you are tight on memory. | |
| 14 | |
| 15 #include <mupdf/fitz.h> | |
| 16 | |
| 17 #include <stdio.h> | |
| 18 #include <stdlib.h> | |
| 19 | |
| 20 main() | |
| 21 { | |
| 22 fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); | |
| 23 if (!ctx) { | |
| 24 fprintf(stderr, "Failed to create a new Fitz context!\n"); | |
| 25 return EXIT_FAILURE; | |
| 26 } | |
| 27 | |
| 28 ... do stuff ... | |
| 29 | |
| 30 fz_drop_context(ctx); | |
| 31 return EXIT_SUCCESS; | |
| 32 } |
