├── .gitattributes ├── .github └── workflows │ └── test.yml ├── AUTHORS ├── COPYING ├── README.md ├── example_test.go ├── fitz.go ├── fitz_cgo.go ├── fitz_cgo_cgo.go ├── fitz_cgo_extlib.go ├── fitz_cgo_extlib_pkgconfig.go ├── fitz_content_types.go ├── fitz_content_types_test.go ├── fitz_nocgo.go ├── fitz_test.go ├── fitz_vendor.go ├── go.mod ├── go.sum ├── include ├── mupdf │ ├── fitz.h │ ├── fitz │ │ ├── archive.h │ │ ├── band-writer.h │ │ ├── bidi.h │ │ ├── bitmap.h │ │ ├── buffer.h │ │ ├── color.h │ │ ├── compress.h │ │ ├── compressed-buffer.h │ │ ├── config.h │ │ ├── context.h │ │ ├── crypt.h │ │ ├── device.h │ │ ├── display-list.h │ │ ├── document.h │ │ ├── export.h │ │ ├── filter.h │ │ ├── font.h │ │ ├── geometry.h │ │ ├── getopt.h │ │ ├── glyph-cache.h │ │ ├── glyph.h │ │ ├── hash.h │ │ ├── heap-imp.h │ │ ├── heap.h │ │ ├── image.h │ │ ├── link.h │ │ ├── log.h │ │ ├── outline.h │ │ ├── output-svg.h │ │ ├── output.h │ │ ├── path.h │ │ ├── pixmap.h │ │ ├── pool.h │ │ ├── separation.h │ │ ├── shade.h │ │ ├── store.h │ │ ├── story-writer.h │ │ ├── story.h │ │ ├── stream.h │ │ ├── string-util.h │ │ ├── structured-text.h │ │ ├── system.h │ │ ├── text.h │ │ ├── track-usage.h │ │ ├── transition.h │ │ ├── tree.h │ │ ├── types.h │ │ ├── util.h │ │ ├── vendor.go │ │ ├── version.h │ │ ├── write-pixmap.h │ │ ├── writer.h │ │ └── xml.h │ ├── memento.h │ └── vendor.go └── vendor.go ├── libs ├── libmupdf_android_arm64.a ├── libmupdf_darwin_amd64.a ├── libmupdf_darwin_arm64.a ├── libmupdf_linux_amd64.a ├── libmupdf_linux_amd64_musl.a ├── libmupdf_linux_arm64.a ├── libmupdf_linux_arm64_musl.a ├── libmupdf_windows_amd64.a ├── libmupdf_windows_arm64.a ├── libmupdfthird_android_arm64.a ├── libmupdfthird_darwin_amd64.a ├── libmupdfthird_darwin_arm64.a ├── libmupdfthird_linux_amd64.a ├── libmupdfthird_linux_amd64_musl.a ├── libmupdfthird_linux_arm64.a ├── libmupdfthird_linux_arm64_musl.a ├── libmupdfthird_windows_amd64.a ├── libmupdfthird_windows_arm64.a └── vendor.go ├── purego_darwin.go ├── purego_linux.go ├── purego_windows.go └── testdata ├── test.bmp ├── test.cbz ├── test.docx ├── test.epub ├── test.fb2 ├── test.gif ├── test.jb2 ├── test.jp2 ├── test.jpg ├── test.jxr ├── test.mobi ├── test.pam ├── test.pbm ├── test.pdf ├── test.pfm ├── test.pgm ├── test.png ├── test.ppm ├── test.pptx ├── test.psd ├── test.svg ├── test.tif ├── test.xlsx └── test.xps /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce LF for Netpbm formats on Windows 2 | testdata/test.pam text eol=lf 3 | testdata/test.pbm text eol=lf 4 | testdata/test.pfm text eol=lf 5 | testdata/test.pgm text eol=lf 6 | testdata/test.ppm text eol=lf 7 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | name: Test 3 | jobs: 4 | test: 5 | strategy: 6 | fail-fast: false 7 | matrix: 8 | go-version: [1.22.x] 9 | os: [ubuntu-latest, macos-latest] 10 | runs-on: ${{ matrix.os }} 11 | steps: 12 | - name: Checkout code 13 | uses: actions/checkout@v4 14 | - name: Install Go 15 | uses: actions/setup-go@v5 16 | with: 17 | go-version: ${{ matrix.go-version }} 18 | - name: Test 19 | run: go test 20 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Milan Nikolic 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## go-fitz 2 | [![Build Status](https://github.com/gen2brain/go-fitz/actions/workflows/test.yml/badge.svg)](https://github.com/gen2brain/go-fitz/actions) 3 | [![GoDoc](https://godoc.org/github.com/gen2brain/go-fitz?status.svg)](https://godoc.org/github.com/gen2brain/go-fitz) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/gen2brain/go-fitz?branch=master)](https://goreportcard.com/report/github.com/gen2brain/go-fitz) 5 | 6 | Go wrapper for [MuPDF](http://mupdf.com/) fitz library that can extract pages from PDF, EPUB, MOBI, DOCX, XLSX and PPTX documents as IMG, TXT, HTML or SVG. 7 | 8 | ### Build tags 9 | 10 | * `extlib` - use external MuPDF library 11 | * `static` - build with static external MuPDF library (used with `extlib`) 12 | * `pkgconfig` - enable pkg-config (used with `extlib`) 13 | * `musl` - use musl compiled library 14 | * `nocgo` - experimental [purego](https://github.com/ebitengine/purego) implementation (can also be used with `CGO_ENABLED=0`) 15 | 16 | ### Notes 17 | 18 | The bundled libraries are built without CJK fonts, if you need them you must use the external library. 19 | 20 | Calling e.g. Image() or Text() methods concurrently for the same document is not supported. 21 | 22 | Purego implementation requires `libffi` and `libmupdf` shared libraries on runtime. 23 | You must set `fitz.FzVersion` in your code or set `FZ_VERSION` environment variable to exact version of the shared library. 24 | 25 | ### Example 26 | ```go 27 | package main 28 | 29 | import ( 30 | "fmt" 31 | "image/jpeg" 32 | "os" 33 | "path/filepath" 34 | 35 | "github.com/gen2brain/go-fitz" 36 | ) 37 | 38 | func main() { 39 | doc, err := fitz.New("test.pdf") 40 | if err != nil { 41 | panic(err) 42 | } 43 | 44 | defer doc.Close() 45 | 46 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 47 | if err != nil { 48 | panic(err) 49 | } 50 | 51 | // Extract pages as images 52 | for n := 0; n < doc.NumPage(); n++ { 53 | img, err := doc.Image(n) 54 | if err != nil { 55 | panic(err) 56 | } 57 | 58 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.jpg", n))) 59 | if err != nil { 60 | panic(err) 61 | } 62 | 63 | err = jpeg.Encode(f, img, &jpeg.Options{jpeg.DefaultQuality}) 64 | if err != nil { 65 | panic(err) 66 | } 67 | 68 | f.Close() 69 | } 70 | } 71 | ``` 72 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | package fitz_test 2 | 3 | import ( 4 | "fmt" 5 | "image/jpeg" 6 | "os" 7 | "path/filepath" 8 | 9 | "github.com/gen2brain/go-fitz" 10 | ) 11 | 12 | func ExampleNew() { 13 | doc, err := fitz.New("test.pdf") 14 | if err != nil { 15 | panic(err) 16 | } 17 | 18 | defer doc.Close() 19 | 20 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 21 | if err != nil { 22 | panic(err) 23 | } 24 | 25 | // Extract pages as images 26 | for n := 0; n < doc.NumPage(); n++ { 27 | img, err := doc.Image(n) 28 | if err != nil { 29 | panic(err) 30 | } 31 | 32 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.jpg", n))) 33 | if err != nil { 34 | panic(err) 35 | } 36 | 37 | err = jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}) 38 | if err != nil { 39 | panic(err) 40 | } 41 | 42 | f.Close() 43 | } 44 | 45 | // Extract pages as text 46 | for n := 0; n < doc.NumPage(); n++ { 47 | text, err := doc.Text(n) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.txt", n))) 53 | if err != nil { 54 | panic(err) 55 | } 56 | 57 | _, err = f.WriteString(text) 58 | if err != nil { 59 | panic(err) 60 | } 61 | 62 | f.Close() 63 | } 64 | 65 | // Extract pages as html 66 | for n := 0; n < doc.NumPage(); n++ { 67 | html, err := doc.HTML(n, true) 68 | if err != nil { 69 | panic(err) 70 | } 71 | 72 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.html", n))) 73 | if err != nil { 74 | panic(err) 75 | } 76 | 77 | _, err = f.WriteString(html) 78 | if err != nil { 79 | panic(err) 80 | } 81 | 82 | f.Close() 83 | } 84 | 85 | // Extract pages as svg 86 | for n := 0; n < doc.NumPage(); n++ { 87 | svg, err := doc.SVG(n) 88 | if err != nil { 89 | panic(err) 90 | } 91 | 92 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.svg", n))) 93 | if err != nil { 94 | panic(err) 95 | } 96 | 97 | _, err = f.WriteString(svg) 98 | if err != nil { 99 | panic(err) 100 | } 101 | 102 | f.Close() 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /fitz.go: -------------------------------------------------------------------------------- 1 | // Package fitz provides wrapper for the [MuPDF](http://mupdf.com/) fitz library 2 | // that can extract pages from PDF, EPUB, MOBI, DOCX, XLSX and PPTX documents as IMG, TXT, HTML or SVG. 3 | package fitz 4 | 5 | import ( 6 | "errors" 7 | "unsafe" 8 | ) 9 | 10 | // Errors. 11 | var ( 12 | ErrNoSuchFile = errors.New("fitz: no such file") 13 | ErrCreateContext = errors.New("fitz: cannot create context") 14 | ErrOpenDocument = errors.New("fitz: cannot open document") 15 | ErrEmptyBytes = errors.New("fitz: cannot send empty bytes") 16 | ErrOpenMemory = errors.New("fitz: cannot open memory") 17 | ErrLoadPage = errors.New("fitz: cannot load page") 18 | ErrRunPageContents = errors.New("fitz: cannot run page contents") 19 | ErrPageMissing = errors.New("fitz: page missing") 20 | ErrCreatePixmap = errors.New("fitz: cannot create pixmap") 21 | ErrPixmapSamples = errors.New("fitz: cannot get pixmap samples") 22 | ErrNeedsPassword = errors.New("fitz: document needs password") 23 | ErrLoadOutline = errors.New("fitz: cannot load outline") 24 | ) 25 | 26 | // MaxStore is maximum size in bytes of the resource store, before it will start evicting cached resources such as fonts and images. 27 | var MaxStore = 256 << 20 28 | 29 | // FzVersion is used for experimental purego implementation, it must be exactly the same as libmupdf shared library version. 30 | // It is also possible to set `FZ_VERSION` environment variable. 31 | var FzVersion = "1.24.9" 32 | 33 | // Outline type. 34 | type Outline struct { 35 | // Hierarchy level of the entry (starting from 1). 36 | Level int 37 | // Title of outline item. 38 | Title string 39 | // Destination in the document to be displayed when this outline item is activated. 40 | URI string 41 | // The page number of an internal link. 42 | Page int 43 | // Top. 44 | Top float64 45 | } 46 | 47 | // Link type. 48 | type Link struct { 49 | URI string 50 | } 51 | 52 | func bytePtrToString(p *byte) string { 53 | if p == nil { 54 | return "" 55 | } 56 | if *p == 0 { 57 | return "" 58 | } 59 | 60 | // Find NUL terminator. 61 | n := 0 62 | for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { 63 | ptr = unsafe.Pointer(uintptr(ptr) + 1) 64 | } 65 | 66 | return string(unsafe.Slice(p, n)) 67 | } 68 | -------------------------------------------------------------------------------- /fitz_cgo_cgo.go: -------------------------------------------------------------------------------- 1 | //go:build cgo && !nocgo && !extlib 2 | 3 | package fitz 4 | 5 | /* 6 | #cgo CFLAGS: -Iinclude 7 | 8 | #cgo linux,amd64,!musl LDFLAGS: -L${SRCDIR}/libs -lmupdf_linux_amd64 -lmupdfthird_linux_amd64 -lm 9 | #cgo linux,amd64,musl LDFLAGS: -L${SRCDIR}/libs -lmupdf_linux_amd64_musl -lmupdfthird_linux_amd64_musl -lm 10 | #cgo linux,!android,arm64,!musl LDFLAGS: -L${SRCDIR}/libs -lmupdf_linux_arm64 -lmupdfthird_linux_arm64 -lm 11 | #cgo linux,!android,arm64,musl LDFLAGS: -L${SRCDIR}/libs -lmupdf_linux_arm64_musl -lmupdfthird_linux_arm64_musl -lm 12 | #cgo android,arm64 LDFLAGS: -L${SRCDIR}/libs -lmupdf_android_arm64 -lmupdfthird_android_arm64 -lm -llog 13 | #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/libs -lmupdf_windows_amd64 -lmupdfthird_windows_amd64 -lm -lcomdlg32 -lgdi32 14 | #cgo windows,arm64 LDFLAGS: -L${SRCDIR}/libs -lmupdf_windows_arm64 -lmupdfthird_windows_arm64 -lm -lcomdlg32 -lgdi32 15 | #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/libs -lmupdf_darwin_amd64 -lmupdfthird_darwin_amd64 -lm 16 | #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/libs -lmupdf_darwin_arm64 -lmupdfthird_darwin_arm64 -lm 17 | */ 18 | import "C" 19 | -------------------------------------------------------------------------------- /fitz_cgo_extlib.go: -------------------------------------------------------------------------------- 1 | //go:build cgo && !nocgo && extlib && !pkgconfig 2 | 3 | package fitz 4 | 5 | /* 6 | #cgo !static LDFLAGS: -lmupdf -lm 7 | #cgo static LDFLAGS: -lmupdf -lm -lmupdf-third 8 | #cgo android LDFLAGS: -llog 9 | #cgo windows LDFLAGS: -lcomdlg32 -lgdi32 10 | */ 11 | import "C" 12 | -------------------------------------------------------------------------------- /fitz_cgo_extlib_pkgconfig.go: -------------------------------------------------------------------------------- 1 | //go:build cgo && !nocgo && extlib && pkgconfig 2 | 3 | package fitz 4 | 5 | /* 6 | #cgo !static pkg-config: mupdf 7 | #cgo static pkg-config: --static mupdf 8 | */ 9 | import "C" 10 | -------------------------------------------------------------------------------- /fitz_content_types.go: -------------------------------------------------------------------------------- 1 | package fitz 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | ) 7 | 8 | // contentType returns document MIME type. 9 | func contentType(b []byte) string { 10 | l := len(b) 11 | // for file length shortcuts see https://github.com/mathiasbynens/small 12 | switch { 13 | case l < 8: 14 | return "" 15 | case isPAM(b): 16 | return "image/x-portable-arbitrarymap" 17 | case isPBM(b): 18 | return "image/x-portable-bitmap" 19 | case isPFM(b): 20 | return "image/x-portable-floatmap" 21 | case isPGM(b): 22 | return "image/x-portable-greymap" 23 | case isPPM(b): 24 | return "image/x-portable-pixmap" 25 | case isGIF(b): 26 | return "image/gif" 27 | case l < 16: 28 | return "" 29 | case isBMP(b): 30 | return "image/bmp" 31 | case isJBIG2(b): 32 | // file header + segment header = 24 bytes 33 | return "image/x-jb2" 34 | case l < 32: 35 | return "" 36 | case isTIFF(b): 37 | return "image/tiff" 38 | case isSVG(b): 39 | // min of 41 bytes: 40 | return "image/svg+xml" 41 | case l < 64: 42 | return "" 43 | case isJPEG(b): 44 | return "image/jpeg" 45 | case isPNG(b): 46 | return "image/png" 47 | case isJPEG2000(b): 48 | return "image/jp2" 49 | case isJPEGXR(b): 50 | return "image/vnd.ms-photo" 51 | case isPDF(b): 52 | return "application/pdf" 53 | case isPSD(b): 54 | return "image/vnd.adobe.photoshop" 55 | case isZIP(b): 56 | switch { 57 | case isDOCX(b): 58 | return "application/vnd.openxmlformats-officedocument.wordprocessingml.document" 59 | case isXLSX(b): 60 | return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 61 | case isPPTX(b): 62 | return "application/vnd.openxmlformats-officedocument.presentationml.presentation" 63 | case isEPUB(b): 64 | return "application/epub+zip" 65 | case isXPS(b): 66 | return "application/oxps" 67 | default: 68 | // fitz will consider it a Comic Book Archive 69 | // must contain at least one image, i.e. >64 bytes 70 | return "application/zip" 71 | } 72 | case isXML(b): 73 | // fitz will consider it an FB2 74 | // minimal valid FB2 w/o content is >64 bytes 75 | return "text/xml" 76 | case isMOBI(b): 77 | return "application/x-mobipocket-ebook" 78 | default: 79 | return "" 80 | } 81 | } 82 | 83 | func isBMP(b []byte) bool { 84 | return b[0] == 0x42 && b[1] == 0x4D 85 | } 86 | 87 | func isGIF(b []byte) bool { 88 | return b[0] == 0x47 && b[1] == 0x49 && b[2] == 0x46 && b[3] == 0x38 89 | } 90 | 91 | func isJBIG2(b []byte) bool { 92 | return b[0] == 0x97 && b[1] == 0x4A && b[2] == 0x42 && b[3] == 0x32 && 93 | b[4] == 0x0D && b[5] == 0x0A && b[6] == 0x1A && b[7] == 0x0A 94 | } 95 | 96 | func isJPEG(b []byte) bool { 97 | return b[0] == 0xFF && b[1] == 0xD8 && b[2] == 0xFF 98 | } 99 | 100 | func isJPEG2000(b []byte) bool { 101 | switch { 102 | case b[0] == 0xFF && b[1] == 0x4F && b[2] == 0xFF && b[3] == 0x51: 103 | return true 104 | default: 105 | return b[0] == 0x00 && b[1] == 0x00 && b[2] == 0x00 && b[3] == 0x0C && 106 | b[4] == 0x6A && b[5] == 0x50 && b[6] == 0x20 && b[7] == 0x20 && 107 | b[8] == 0x0D && b[9] == 0x0A && b[10] == 0x87 && b[11] == 0x0A 108 | } 109 | } 110 | 111 | func isJPEGXR(b []byte) bool { 112 | return b[0] == 0x49 && b[1] == 0x49 && b[2] == 0xBC 113 | } 114 | 115 | func isPAM(b []byte) bool { 116 | return b[0] == 0x50 && b[1] == 0x37 && b[2] == 0x0A 117 | } 118 | 119 | func isPBM(b []byte) bool { 120 | return b[0] == 0x50 && (b[1] == 0x31 || b[1] == 0x34) && b[2] == 0x0A 121 | } 122 | 123 | func isPFM(b []byte) bool { 124 | return b[0] == 0x50 && (b[1] == 0x46 || b[1] == 0x66) && b[2] == 0x0A 125 | } 126 | 127 | func isPGM(b []byte) bool { 128 | return b[0] == 0x50 && (b[1] == 0x32 || b[1] == 0x35) && b[2] == 0x0A 129 | } 130 | 131 | func isPPM(b []byte) bool { 132 | return b[0] == 0x50 && (b[1] == 0x33 || b[1] == 0x36) && b[2] == 0x0A 133 | } 134 | 135 | func isPNG(b []byte) bool { 136 | return b[0] == 0x89 && b[1] == 0x50 && b[2] == 0x4E && b[3] == 0x47 && 137 | b[4] == 0x0D && b[5] == 0x0A && b[6] == 0x1A && b[7] == 0x0A 138 | } 139 | 140 | func isTIFF(b []byte) bool { 141 | return b[0] == 0x49 && b[1] == 0x49 && b[2] == 0x2A && b[3] == 0x00 || 142 | b[0] == 0x4D && b[1] == 0x4D && b[2] == 0x00 && b[3] == 0x2A 143 | } 144 | 145 | // PDF magic number 25 50 44 46 = "%PDF". 146 | func isPDF(b []byte) bool { 147 | return b[0] == 0x25 && b[1] == 0x50 && b[2] == 0x44 && b[3] == 0x46 148 | } 149 | 150 | // PSD magic number 38 42 50 53 = "8BPS" 151 | func isPSD(b []byte) bool { 152 | return b[0] == 0x38 && b[1] == 0x42 && b[2] == 0x50 && b[3] == 0x53 153 | } 154 | 155 | // Non-empty ZIP archive magic number 50 4B 03 04. 156 | func isZIP(b []byte) bool { 157 | return b[0] == 0x50 && b[1] == 0x4B && b[2] == 0x03 && b[3] == 0x04 158 | } 159 | 160 | // Looks for a file named "mimetype" containing the ASCII string "application/epub+zip". 161 | // The file must be uncompressed and be the first file within the archive. 162 | func isEPUB(b []byte) bool { 163 | return b[30] == 0x6D && b[31] == 0x69 && b[32] == 0x6D && b[33] == 0x65 && 164 | b[34] == 0x74 && b[35] == 0x79 && b[36] == 0x70 && b[37] == 0x65 && 165 | b[38] == 0x61 && b[39] == 0x70 && b[40] == 0x70 && b[41] == 0x6C && 166 | b[42] == 0x69 && b[43] == 0x63 && b[44] == 0x61 && b[45] == 0x74 && 167 | b[46] == 0x69 && b[47] == 0x6F && b[48] == 0x6E && b[49] == 0x2F && 168 | b[50] == 0x65 && b[51] == 0x70 && b[52] == 0x75 && b[53] == 0x62 && 169 | b[54] == 0x2B && b[55] == 0x7A && b[56] == 0x69 && b[57] == 0x70 170 | } 171 | 172 | // MOBI contains either BOOKMOBI or TEXtREAd string after a 60 bytes offset. 173 | // The magic string is then followed by at least 10 bytes of information. 174 | func isMOBI(b []byte) bool { 175 | switch { 176 | case len(b) < 78: 177 | return false 178 | case b[60] == 0x42 && b[61] == 0x4F && b[62] == 0x4F && b[63] == 0x4B && 179 | b[64] == 0x4D && b[65] == 0x4F && b[66] == 0x42 && b[67] == 0x49: 180 | return true 181 | case b[60] == 0x54 && b[61] == 0x45 && b[62] == 0x58 && b[63] == 0x74 && 182 | b[64] == 0x52 && b[65] == 0x45 && b[66] == 0x41 && b[67] == 0x64: 183 | return true 184 | default: 185 | return false 186 | } 187 | } 188 | 189 | // Looks for a file named "[Content_Types].xml" at the root of a ZIP archive. 190 | // MS Office apps put this file first within the archive enabling for fast detection. 191 | func isXPS(b []byte) bool { 192 | return b[30] == 0x5B && b[31] == 0x43 && b[32] == 0x6F && b[33] == 0x6E && 193 | b[34] == 0x74 && b[35] == 0x65 && b[36] == 0x6E && b[37] == 0x74 && 194 | b[38] == 0x5F && b[39] == 0x54 && b[40] == 0x79 && b[41] == 0x70 && 195 | b[42] == 0x65 && b[43] == 0x73 && b[44] == 0x5D && b[45] == 0x2E && 196 | b[46] == 0x78 && b[47] == 0x6D && b[48] == 0x6C 197 | } 198 | 199 | // Checks for " 239 | goto ParseSVGText 240 | } 241 | } 242 | } 243 | 244 | // Checks for " len(slice) { 339 | return false 340 | } 341 | 342 | s := slice[startOffset : startOffset+sl] 343 | for i := range s { 344 | if subSlice[i] != s[i] { 345 | return false 346 | } 347 | } 348 | 349 | return true 350 | } 351 | 352 | func checkMSOoml(buf []byte, offset int) (typ docType, ok bool) { 353 | ok = true 354 | 355 | switch { 356 | case compareBytes(buf, []byte("word/"), offset): 357 | typ = typeDocx 358 | case compareBytes(buf, []byte("ppt/"), offset): 359 | typ = typePptx 360 | case compareBytes(buf, []byte("xl/"), offset): 361 | typ = typeXlsx 362 | default: 363 | ok = false 364 | } 365 | 366 | return 367 | } 368 | 369 | func search(buf []byte, start, rangeNum int) int { 370 | length := len(buf) 371 | end := start + rangeNum 372 | signature := []byte{'P', 'K', 0x03, 0x04} 373 | 374 | if end > length { 375 | end = length 376 | } 377 | 378 | if start >= end { 379 | return -1 380 | } 381 | 382 | return bytes.Index(buf[start:end], signature) 383 | } 384 | -------------------------------------------------------------------------------- /fitz_content_types_test.go: -------------------------------------------------------------------------------- 1 | package fitz 2 | 3 | import ( 4 | _ "embed" 5 | "testing" 6 | ) 7 | 8 | func testContentType(want string, b []byte, t *testing.T) { 9 | if got := contentType(b); got != want { 10 | t.Errorf("contentType([]byte) = '%v'; want '%v'", got, want) 11 | } 12 | } 13 | 14 | //go:embed testdata/test.bmp 15 | var bmp []byte 16 | 17 | func TestContentTypeBMP(t *testing.T) { 18 | testContentType("image/bmp", bmp, t) 19 | } 20 | 21 | //go:embed testdata/test.epub 22 | var epub []byte 23 | 24 | func TestContentTypeEPUB(t *testing.T) { 25 | testContentType("application/epub+zip", epub, t) 26 | } 27 | 28 | //go:embed testdata/test.mobi 29 | var mobi []byte 30 | 31 | func TestContentTypeMOBI(t *testing.T) { 32 | testContentType("application/x-mobipocket-ebook", mobi, t) 33 | } 34 | 35 | //go:embed testdata/test.cbz 36 | var cbz []byte 37 | 38 | func TestContentTypeCBZ(t *testing.T) { 39 | testContentType("application/zip", cbz, t) 40 | } 41 | 42 | //go:embed testdata/test.fb2 43 | var fb2 []byte 44 | 45 | func TestContentTypeFB2(t *testing.T) { 46 | testContentType("text/xml", fb2, t) 47 | } 48 | 49 | //go:embed testdata/test.gif 50 | var gif []byte 51 | 52 | func TestContentTypeGIF(t *testing.T) { 53 | testContentType("image/gif", gif, t) 54 | } 55 | 56 | //go:embed testdata/test.jb2 57 | var jb2 []byte 58 | 59 | func TestContentTypeJBIG2(t *testing.T) { 60 | testContentType("image/x-jb2", jb2, t) 61 | } 62 | 63 | //go:embed testdata/test.jpg 64 | var jpg []byte 65 | 66 | func TestContentTypeJPEG(t *testing.T) { 67 | testContentType("image/jpeg", jpg, t) 68 | } 69 | 70 | //go:embed testdata/test.jp2 71 | var jp2 []byte 72 | 73 | func TestContentTypeJPEG2000(t *testing.T) { 74 | testContentType("image/jp2", jp2, t) 75 | } 76 | 77 | //go:embed testdata/test.jxr 78 | var jxr []byte 79 | 80 | func TestContentTypeJPEGXR(t *testing.T) { 81 | testContentType("image/vnd.ms-photo", jxr, t) 82 | } 83 | 84 | //go:embed testdata/test.pam 85 | var pam []byte 86 | 87 | func TestContentTypePAM(t *testing.T) { 88 | testContentType("image/x-portable-arbitrarymap", pam, t) 89 | } 90 | 91 | //go:embed testdata/test.pbm 92 | var pbm []byte 93 | 94 | func TestContentTypePBM(t *testing.T) { 95 | testContentType("image/x-portable-bitmap", pbm, t) 96 | } 97 | 98 | //go:embed testdata/test.pdf 99 | var pdf []byte 100 | 101 | func TestContentTypePDF(t *testing.T) { 102 | testContentType("application/pdf", pdf, t) 103 | } 104 | 105 | //go:embed testdata/test.psd 106 | var psd []byte 107 | 108 | func TestContentTypePSD(t *testing.T) { 109 | testContentType("image/vnd.adobe.photoshop", psd, t) 110 | } 111 | 112 | //go:embed testdata/test.pfm 113 | var pfm []byte 114 | 115 | func TestContentTypePFM(t *testing.T) { 116 | testContentType("image/x-portable-floatmap", pfm, t) 117 | } 118 | 119 | //go:embed testdata/test.pgm 120 | var pgm []byte 121 | 122 | func TestContentTypePGM(t *testing.T) { 123 | testContentType("image/x-portable-greymap", pgm, t) 124 | } 125 | 126 | //go:embed testdata/test.ppm 127 | var ppm []byte 128 | 129 | func TestContentTypePPM(t *testing.T) { 130 | testContentType("image/x-portable-pixmap", ppm, t) 131 | } 132 | 133 | //go:embed testdata/test.svg 134 | var svg []byte 135 | 136 | func TestContentTypeSVG(t *testing.T) { 137 | testContentType("image/svg+xml", svg, t) 138 | } 139 | 140 | //go:embed testdata/test.tif 141 | var tif []byte 142 | 143 | func TestContentTypeTIFF(t *testing.T) { 144 | testContentType("image/tiff", tif, t) 145 | } 146 | 147 | //go:embed testdata/test.xps 148 | var xps []byte 149 | 150 | func TestContentTypeXPS(t *testing.T) { 151 | testContentType("application/oxps", xps, t) 152 | } 153 | 154 | //go:embed testdata/test.docx 155 | var docx []byte 156 | 157 | func TestContentTypeDOCX(t *testing.T) { 158 | testContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document", docx, t) 159 | } 160 | 161 | //go:embed testdata/test.xlsx 162 | var xlsx []byte 163 | 164 | func TestContentTypeXLSX(t *testing.T) { 165 | testContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", xlsx, t) 166 | } 167 | 168 | //go:embed testdata/test.pptx 169 | var pptx []byte 170 | 171 | func TestContentTypePPTX(t *testing.T) { 172 | testContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation", pptx, t) 173 | } 174 | -------------------------------------------------------------------------------- /fitz_test.go: -------------------------------------------------------------------------------- 1 | package fitz_test 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "image" 7 | "image/jpeg" 8 | "io" 9 | "os" 10 | "path/filepath" 11 | "testing" 12 | 13 | "github.com/gen2brain/go-fitz" 14 | ) 15 | 16 | func TestImage(t *testing.T) { 17 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 18 | if err != nil { 19 | t.Error(err) 20 | } 21 | 22 | defer doc.Close() 23 | 24 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 25 | if err != nil { 26 | t.Error(err) 27 | } 28 | 29 | defer os.RemoveAll(tmpDir) 30 | 31 | for n := 0; n < doc.NumPage(); n++ { 32 | img, err := doc.Image(n) 33 | if err != nil { 34 | t.Error(err) 35 | } 36 | 37 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.jpg", n))) 38 | if err != nil { 39 | t.Error(err) 40 | } 41 | 42 | err = jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}) 43 | if err != nil { 44 | t.Error(err) 45 | } 46 | 47 | f.Close() 48 | } 49 | } 50 | 51 | func TestImageFromMemory(t *testing.T) { 52 | b, err := os.ReadFile(filepath.Join("testdata", "test.pdf")) 53 | if err != nil { 54 | t.Error(err) 55 | } 56 | 57 | doc, err := fitz.NewFromMemory(b) 58 | if err != nil { 59 | t.Error(err) 60 | } 61 | 62 | defer doc.Close() 63 | 64 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 65 | if err != nil { 66 | t.Error(err) 67 | } 68 | 69 | defer os.RemoveAll(tmpDir) 70 | 71 | for n := 0; n < doc.NumPage(); n++ { 72 | img, err := doc.Image(n) 73 | if err != nil { 74 | t.Error(err) 75 | } 76 | 77 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.jpg", n))) 78 | if err != nil { 79 | t.Error(err) 80 | } 81 | 82 | err = jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}) 83 | if err != nil { 84 | t.Error(err) 85 | } 86 | 87 | f.Close() 88 | } 89 | } 90 | 91 | func TestLinks(t *testing.T) { 92 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 93 | if err != nil { 94 | t.Error(err) 95 | } 96 | 97 | defer doc.Close() 98 | 99 | links, err := doc.Links(2) 100 | if err != nil { 101 | t.Error(err) 102 | } 103 | 104 | if len(links) != 1 { 105 | t.Error("expected 1 link, got", len(links)) 106 | } 107 | 108 | if links[0].URI != "https://creativecommons.org/licenses/by-nc-sa/4.0/" { 109 | t.Error("expected empty URI, got", links[0].URI) 110 | } 111 | } 112 | 113 | func TestText(t *testing.T) { 114 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 115 | if err != nil { 116 | t.Error(err) 117 | } 118 | 119 | defer doc.Close() 120 | 121 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 122 | if err != nil { 123 | t.Error(err) 124 | } 125 | 126 | defer os.RemoveAll(tmpDir) 127 | 128 | for n := 0; n < doc.NumPage(); n++ { 129 | text, err := doc.Text(n) 130 | if err != nil { 131 | t.Error(err) 132 | } 133 | 134 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.txt", n))) 135 | if err != nil { 136 | t.Error(err) 137 | } 138 | 139 | _, err = f.WriteString(text) 140 | if err != nil { 141 | t.Error(err) 142 | } 143 | 144 | f.Close() 145 | } 146 | } 147 | 148 | func TestHTML(t *testing.T) { 149 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 150 | if err != nil { 151 | t.Error(err) 152 | } 153 | 154 | defer doc.Close() 155 | 156 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 157 | if err != nil { 158 | t.Error(err) 159 | } 160 | 161 | defer os.RemoveAll(tmpDir) 162 | 163 | for n := 0; n < doc.NumPage(); n++ { 164 | html, err := doc.HTML(n, true) 165 | if err != nil { 166 | t.Error(err) 167 | } 168 | 169 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.html", n))) 170 | if err != nil { 171 | t.Error(err) 172 | } 173 | 174 | _, err = f.WriteString(html) 175 | if err != nil { 176 | t.Error(err) 177 | } 178 | 179 | f.Close() 180 | } 181 | } 182 | 183 | func TestPNG(t *testing.T) { 184 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 185 | if err != nil { 186 | t.Error(err) 187 | } 188 | 189 | defer doc.Close() 190 | 191 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 192 | if err != nil { 193 | t.Error(err) 194 | } 195 | 196 | defer os.RemoveAll(tmpDir) 197 | 198 | for n := 0; n < doc.NumPage(); n++ { 199 | png, err := doc.ImagePNG(n, 300.0) 200 | if err != nil { 201 | t.Error(err) 202 | } 203 | 204 | if err = os.WriteFile(filepath.Join(tmpDir, fmt.Sprintf("test%03d.png", n)), png, 0644); err != nil { 205 | t.Error(err) 206 | } 207 | } 208 | } 209 | 210 | func TestSVG(t *testing.T) { 211 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 212 | if err != nil { 213 | t.Error(err) 214 | } 215 | 216 | defer doc.Close() 217 | 218 | tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") 219 | if err != nil { 220 | t.Error(err) 221 | } 222 | 223 | defer os.RemoveAll(tmpDir) 224 | 225 | for n := 0; n < doc.NumPage(); n++ { 226 | svg, err := doc.SVG(n) 227 | if err != nil { 228 | t.Error(err) 229 | } 230 | 231 | f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.svg", n))) 232 | if err != nil { 233 | t.Error(err) 234 | } 235 | 236 | _, err = f.WriteString(svg) 237 | if err != nil { 238 | t.Error(err) 239 | } 240 | 241 | f.Close() 242 | } 243 | } 244 | 245 | func TestToC(t *testing.T) { 246 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 247 | if err != nil { 248 | t.Error(err) 249 | } 250 | 251 | defer doc.Close() 252 | 253 | _, err = doc.ToC() 254 | if err != nil { 255 | t.Error(err) 256 | } 257 | } 258 | 259 | func TestMetadata(t *testing.T) { 260 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 261 | if err != nil { 262 | t.Error(err) 263 | } 264 | 265 | defer doc.Close() 266 | 267 | meta := doc.Metadata() 268 | if len(meta) == 0 { 269 | t.Error(fmt.Errorf("metadata is empty")) 270 | } 271 | } 272 | 273 | func TestBound(t *testing.T) { 274 | doc, err := fitz.New(filepath.Join("testdata", "test.pdf")) 275 | if err != nil { 276 | t.Error(err) 277 | } 278 | 279 | defer doc.Close() 280 | expected := image.Rect(0, 0, 612, 792) 281 | 282 | for i := 0; i < doc.NumPage(); i++ { 283 | bound, err := doc.Bound(i) 284 | if err != nil { 285 | t.Error(err) 286 | } 287 | if bound != expected { 288 | t.Error(fmt.Errorf("bounds didn't match go %v when expedient %v", bound, expected)) 289 | } 290 | } 291 | 292 | _, err = doc.Bound(doc.NumPage()) 293 | if !errors.Is(err, fitz.ErrPageMissing) { 294 | t.Error(fmt.Errorf("ErrPageMissing not returned got %v", err)) 295 | } 296 | } 297 | 298 | func TestEmptyBytes(t *testing.T) { 299 | var err error 300 | // empty reader 301 | _, err = fitz.NewFromReader(emptyReader{}) 302 | if !errors.Is(err, fitz.ErrEmptyBytes) { 303 | t.Errorf("Expected ErrEmptyBytes, got %v", err) 304 | } 305 | // nil slice 306 | _, err = fitz.NewFromMemory(nil) 307 | if !errors.Is(err, fitz.ErrEmptyBytes) { 308 | t.Errorf("Expected ErrEmptyBytes, got %v", err) 309 | } 310 | // empty slice 311 | _, err = fitz.NewFromMemory(make([]byte, 0)) 312 | if !errors.Is(err, fitz.ErrEmptyBytes) { 313 | t.Errorf("Expected ErrEmptyBytes, got %v", err) 314 | } 315 | } 316 | 317 | type emptyReader struct{} 318 | 319 | func (emptyReader) Read([]byte) (int, error) { return 0, io.EOF } 320 | -------------------------------------------------------------------------------- /fitz_vendor.go: -------------------------------------------------------------------------------- 1 | //go:build required 2 | 3 | package fitz 4 | 5 | import ( 6 | _ "github.com/gen2brain/go-fitz/include/mupdf" 7 | _ "github.com/gen2brain/go-fitz/include/mupdf/fitz" 8 | _ "github.com/gen2brain/go-fitz/libs" 9 | ) 10 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gen2brain/go-fitz 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/ebitengine/purego v0.8.0 7 | github.com/jupiterrider/ffi v0.2.0 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/ebitengine/purego v0.8.0 h1:JbqvnEzRvPpxhCJzJJ2y0RbiZ8nyjccVUrSM3q+GvvE= 2 | github.com/ebitengine/purego v0.8.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= 3 | github.com/jupiterrider/ffi v0.2.0 h1:tMM70PexgYNmV+WyaYhJgCvQAvtTCs3wXeILPutihnA= 4 | github.com/jupiterrider/ffi v0.2.0/go.mod h1:yqYqX5DdEccAsHeMn+6owkoI2llBLySVAF8dwCDZPVs= 5 | -------------------------------------------------------------------------------- /include/mupdf/fitz.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUDPF_FITZ_H 24 | #define MUDPF_FITZ_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include "mupdf/fitz/version.h" 31 | #include "mupdf/fitz/config.h" 32 | #include "mupdf/fitz/system.h" 33 | #include "mupdf/fitz/context.h" 34 | #include "mupdf/fitz/output.h" 35 | #include "mupdf/fitz/log.h" 36 | 37 | #include "mupdf/fitz/crypt.h" 38 | #include "mupdf/fitz/getopt.h" 39 | #include "mupdf/fitz/geometry.h" 40 | #include "mupdf/fitz/hash.h" 41 | #include "mupdf/fitz/pool.h" 42 | #include "mupdf/fitz/string-util.h" 43 | #include "mupdf/fitz/tree.h" 44 | #include "mupdf/fitz/bidi.h" 45 | #include "mupdf/fitz/xml.h" 46 | 47 | /* I/O */ 48 | #include "mupdf/fitz/buffer.h" 49 | #include "mupdf/fitz/stream.h" 50 | #include "mupdf/fitz/compress.h" 51 | #include "mupdf/fitz/compressed-buffer.h" 52 | #include "mupdf/fitz/filter.h" 53 | #include "mupdf/fitz/archive.h" 54 | #include "mupdf/fitz/heap.h" 55 | 56 | 57 | /* Resources */ 58 | #include "mupdf/fitz/store.h" 59 | #include "mupdf/fitz/color.h" 60 | #include "mupdf/fitz/pixmap.h" 61 | #include "mupdf/fitz/bitmap.h" 62 | #include "mupdf/fitz/image.h" 63 | #include "mupdf/fitz/shade.h" 64 | #include "mupdf/fitz/font.h" 65 | #include "mupdf/fitz/path.h" 66 | #include "mupdf/fitz/text.h" 67 | #include "mupdf/fitz/separation.h" 68 | #include "mupdf/fitz/glyph.h" 69 | 70 | #include "mupdf/fitz/device.h" 71 | #include "mupdf/fitz/display-list.h" 72 | #include "mupdf/fitz/structured-text.h" 73 | 74 | #include "mupdf/fitz/transition.h" 75 | #include "mupdf/fitz/glyph-cache.h" 76 | 77 | /* Document */ 78 | #include "mupdf/fitz/link.h" 79 | #include "mupdf/fitz/outline.h" 80 | #include "mupdf/fitz/document.h" 81 | 82 | #include "mupdf/fitz/util.h" 83 | 84 | /* Output formats */ 85 | #include "mupdf/fitz/writer.h" 86 | #include "mupdf/fitz/band-writer.h" 87 | #include "mupdf/fitz/write-pixmap.h" 88 | #include "mupdf/fitz/output-svg.h" 89 | 90 | #include "mupdf/fitz/story.h" 91 | #include "mupdf/fitz/story-writer.h" 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/mupdf/fitz/band-writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_BAND_WRITER_H 24 | #define MUPDF_FITZ_BAND_WRITER_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/output.h" 29 | #include "mupdf/fitz/color.h" 30 | #include "mupdf/fitz/separation.h" 31 | 32 | /** 33 | fz_band_writer 34 | */ 35 | typedef struct fz_band_writer fz_band_writer; 36 | 37 | /** 38 | Cause a band writer to write the header for 39 | a banded image with the given properties/dimensions etc. This 40 | also configures the bandwriter for the format of the data to be 41 | passed in future calls. 42 | 43 | w, h: Width and Height of the entire page. 44 | 45 | n: Number of components (including spots and alphas). 46 | 47 | alpha: Number of alpha components. 48 | 49 | xres, yres: X and Y resolutions in dpi. 50 | 51 | cs: Colorspace (NULL for bitmaps) 52 | 53 | seps: Separation details (or NULL). 54 | */ 55 | void fz_write_header(fz_context *ctx, fz_band_writer *writer, int w, int h, int n, int alpha, int xres, int yres, int pagenum, fz_colorspace *cs, fz_separations *seps); 56 | 57 | /** 58 | Cause a band writer to write the next band 59 | of data for an image. 60 | 61 | stride: The byte offset from the first byte of the data 62 | for a pixel to the first byte of the data for the same pixel 63 | on the row below. 64 | 65 | band_height: The number of lines in this band. 66 | 67 | samples: Pointer to first byte of the data. 68 | */ 69 | void fz_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_height, const unsigned char *samples); 70 | 71 | /** 72 | Finishes up the output and closes the band writer. After this 73 | call no more headers or bands may be written. 74 | */ 75 | void fz_close_band_writer(fz_context *ctx, fz_band_writer *writer); 76 | 77 | /** 78 | Drop the reference to the band writer, causing it to be 79 | destroyed. 80 | 81 | Never throws an exception. 82 | */ 83 | void fz_drop_band_writer(fz_context *ctx, fz_band_writer *writer); 84 | 85 | /* Implementation details: subject to change. */ 86 | 87 | typedef void (fz_write_header_fn)(fz_context *ctx, fz_band_writer *writer, fz_colorspace *cs); 88 | typedef void (fz_write_band_fn)(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *samples); 89 | typedef void (fz_write_trailer_fn)(fz_context *ctx, fz_band_writer *writer); 90 | typedef void (fz_close_band_writer_fn)(fz_context *ctx, fz_band_writer *writer); 91 | typedef void (fz_drop_band_writer_fn)(fz_context *ctx, fz_band_writer *writer); 92 | 93 | struct fz_band_writer 94 | { 95 | fz_drop_band_writer_fn *drop; 96 | fz_close_band_writer_fn *close; 97 | fz_write_header_fn *header; 98 | fz_write_band_fn *band; 99 | fz_write_trailer_fn *trailer; 100 | fz_output *out; 101 | int w; 102 | int h; 103 | int n; 104 | int s; 105 | int alpha; 106 | int xres; 107 | int yres; 108 | int pagenum; 109 | int line; 110 | fz_separations *seps; 111 | }; 112 | 113 | fz_band_writer *fz_new_band_writer_of_size(fz_context *ctx, size_t size, fz_output *out); 114 | #define fz_new_band_writer(C,M,O) ((M *)Memento_label(fz_new_band_writer_of_size(ctx, sizeof(M), O), #M)) 115 | 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /include/mupdf/fitz/bidi.h: -------------------------------------------------------------------------------- 1 | /** 2 | Bidirectional text processing. 3 | 4 | Derived from the SmartOffice code, which is itself derived 5 | from the example unicode standard code. Original copyright 6 | messages follow: 7 | 8 | Copyright (C) Picsel, 2004-2008. All Rights Reserved. 9 | 10 | Processes Unicode text by arranging the characters into an order 11 | suitable for display. E.g. Hebrew text will be arranged from 12 | right-to-left and any English within the text will remain in the 13 | left-to-right order. 14 | 15 | This is an implementation of the Unicode Bidirectional Algorithm 16 | which can be found here: http://www.unicode.org/reports/tr9/ and 17 | is based on the reference implementation found on Unicode.org. 18 | */ 19 | 20 | #ifndef FITZ_BIDI_H 21 | #define FITZ_BIDI_H 22 | 23 | #include "mupdf/fitz/system.h" 24 | #include "mupdf/fitz/context.h" 25 | 26 | /* Implementation details: subject to change. */ 27 | 28 | typedef enum 29 | { 30 | FZ_BIDI_LTR = 0, 31 | FZ_BIDI_RTL = 1, 32 | FZ_BIDI_NEUTRAL = 2 33 | } 34 | fz_bidi_direction; 35 | 36 | typedef enum 37 | { 38 | FZ_BIDI_CLASSIFY_WHITE_SPACE = 1, 39 | FZ_BIDI_REPLACE_TAB = 2 40 | } 41 | fz_bidi_flags; 42 | 43 | /** 44 | Prototype for callback function supplied to fz_bidi_fragment_text. 45 | 46 | @param fragment first character in fragment 47 | @param fragmentLen number of characters in fragment 48 | @param bidiLevel The bidirectional level for this text. 49 | The bottom bit will be set iff block 50 | should concatenate with other blocks as 51 | right-to-left 52 | @param script the script in use for this fragment (other 53 | than common or inherited) 54 | @param arg data from caller of Bidi_fragmentText 55 | */ 56 | typedef void (fz_bidi_fragment_fn)(const uint32_t *fragment, 57 | size_t fragmentLen, 58 | int bidiLevel, 59 | int script, 60 | void *arg); 61 | 62 | /** 63 | Partitions the given Unicode sequence into one or more 64 | unidirectional fragments and invokes the given callback 65 | function for each fragment. 66 | 67 | For example, if directionality of text is: 68 | 0123456789 69 | rrlllrrrrr, 70 | we'll invoke callback with: 71 | &text[0], length == 2 72 | &text[2], length == 3 73 | &text[5], length == 5 74 | 75 | @param[in] text start of Unicode sequence 76 | @param[in] textlen number of Unicodes to analyse 77 | @param[in] baseDir direction of paragraph (specify FZ_BIDI_NEUTRAL to force auto-detection) 78 | @param[in] callback function to be called for each fragment 79 | @param[in] arg data to be passed to the callback function 80 | @param[in] flags flags to control operation (see fz_bidi_flags above) 81 | */ 82 | void fz_bidi_fragment_text(fz_context *ctx, 83 | const uint32_t *text, 84 | size_t textlen, 85 | fz_bidi_direction *baseDir, 86 | fz_bidi_fragment_fn *callback, 87 | void *arg, 88 | int flags); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/mupdf/fitz/bitmap.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_BITMAP_H 24 | #define MUPDF_FITZ_BITMAP_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/pixmap.h" 29 | 30 | /** 31 | Bitmaps have 1 bit per component. Only used for creating 32 | halftoned versions of contone buffers, and saving out. Samples 33 | are stored msb first, akin to pbms. 34 | 35 | The internals of this struct are considered implementation 36 | details and subject to change. Where possible, accessor 37 | functions should be used in preference. 38 | */ 39 | typedef struct 40 | { 41 | int refs; 42 | int w, h, stride, n; 43 | int xres, yres; 44 | unsigned char *samples; 45 | } fz_bitmap; 46 | 47 | /** 48 | Take an additional reference to the bitmap. The same pointer 49 | is returned. 50 | 51 | Never throws exceptions. 52 | */ 53 | fz_bitmap *fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit); 54 | 55 | /** 56 | Drop a reference to the bitmap. When the reference count reaches 57 | zero, the bitmap will be destroyed. 58 | 59 | Never throws exceptions. 60 | */ 61 | void fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit); 62 | 63 | /** 64 | Invert bitmap. 65 | 66 | Never throws exceptions. 67 | */ 68 | void fz_invert_bitmap(fz_context *ctx, fz_bitmap *bmp); 69 | 70 | /** 71 | A halftone is a set of threshold tiles, one per component. Each 72 | threshold tile is a pixmap, possibly of varying sizes and 73 | phases. Currently, we only provide one 'default' halftone tile 74 | for operating on 1 component plus alpha pixmaps (where the alpha 75 | is ignored). This is signified by a fz_halftone pointer to NULL. 76 | */ 77 | typedef struct fz_halftone fz_halftone; 78 | 79 | /** 80 | Make a bitmap from a pixmap and a halftone. 81 | 82 | pix: The pixmap to generate from. Currently must be a single 83 | color component with no alpha. 84 | 85 | ht: The halftone to use. NULL implies the default halftone. 86 | 87 | Returns the resultant bitmap. Throws exceptions in the case of 88 | failure to allocate. 89 | */ 90 | fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht); 91 | 92 | /** 93 | Make a bitmap from a pixmap and a 94 | halftone, allowing for the position of the pixmap within an 95 | overall banded rendering. 96 | 97 | pix: The pixmap to generate from. Currently must be a single 98 | color component with no alpha. 99 | 100 | ht: The halftone to use. NULL implies the default halftone. 101 | 102 | band_start: Vertical offset within the overall banded rendering 103 | (in pixels) 104 | 105 | Returns the resultant bitmap. Throws exceptions in the case of 106 | failure to allocate. 107 | */ 108 | fz_bitmap *fz_new_bitmap_from_pixmap_band(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht, int band_start); 109 | 110 | /** 111 | Create a new bitmap. 112 | 113 | w, h: Width and Height for the bitmap 114 | 115 | n: Number of color components (assumed to be a divisor of 8) 116 | 117 | xres, yres: X and Y resolutions (in pixels per inch). 118 | 119 | Returns pointer to created bitmap structure. The bitmap 120 | data is uninitialised. 121 | */ 122 | fz_bitmap *fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres); 123 | 124 | /** 125 | Retrieve details of a given bitmap. 126 | 127 | bitmap: The bitmap to query. 128 | 129 | w: Pointer to storage to retrieve width (or NULL). 130 | 131 | h: Pointer to storage to retrieve height (or NULL). 132 | 133 | n: Pointer to storage to retrieve number of color components (or 134 | NULL). 135 | 136 | stride: Pointer to storage to retrieve bitmap stride (or NULL). 137 | */ 138 | void fz_bitmap_details(fz_bitmap *bitmap, int *w, int *h, int *n, int *stride); 139 | 140 | /** 141 | Set the entire bitmap to 0. 142 | 143 | Never throws exceptions. 144 | */ 145 | void fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit); 146 | 147 | /** 148 | Create a 'default' halftone structure 149 | for the given number of components. 150 | 151 | num_comps: The number of components to use. 152 | 153 | Returns a simple default halftone. The default halftone uses 154 | the same halftone tile for each plane, which may not be ideal 155 | for all purposes. 156 | */ 157 | fz_halftone *fz_default_halftone(fz_context *ctx, int num_comps); 158 | 159 | /** 160 | Take an additional reference to the halftone. The same pointer 161 | is returned. 162 | 163 | Never throws exceptions. 164 | */ 165 | fz_halftone *fz_keep_halftone(fz_context *ctx, fz_halftone *half); 166 | 167 | /** 168 | Drop a reference to the halftone. When the reference count 169 | reaches zero, the halftone is destroyed. 170 | 171 | Never throws exceptions. 172 | */ 173 | void fz_drop_halftone(fz_context *ctx, fz_halftone *ht); 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /include/mupdf/fitz/buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2023 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_BUFFER_H 24 | #define MUPDF_FITZ_BUFFER_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | 29 | /** 30 | fz_buffer is a wrapper around a dynamically allocated array of 31 | bytes. 32 | 33 | Buffers have a capacity (the number of bytes storage immediately 34 | available) and a current size. 35 | 36 | The contents of the structure are considered implementation 37 | details and are subject to change. Users should use the accessor 38 | functions in preference. 39 | */ 40 | typedef struct 41 | { 42 | int refs; 43 | unsigned char *data; 44 | size_t cap, len; 45 | int unused_bits; 46 | int shared; 47 | } fz_buffer; 48 | 49 | /** 50 | Take an additional reference to the buffer. The same pointer 51 | is returned. 52 | 53 | Never throws exceptions. 54 | */ 55 | fz_buffer *fz_keep_buffer(fz_context *ctx, fz_buffer *buf); 56 | 57 | /** 58 | Drop a reference to the buffer. When the reference count reaches 59 | zero, the buffer is destroyed. 60 | 61 | Never throws exceptions. 62 | */ 63 | void fz_drop_buffer(fz_context *ctx, fz_buffer *buf); 64 | 65 | /** 66 | Retrieve internal memory of buffer. 67 | 68 | datap: Output parameter that will be pointed to the data. 69 | 70 | Returns the current size of the data in bytes. 71 | */ 72 | size_t fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **datap); 73 | 74 | /** 75 | Ensure that a buffer's data ends in a 76 | 0 byte, and return a pointer to it. 77 | */ 78 | const char *fz_string_from_buffer(fz_context *ctx, fz_buffer *buf); 79 | 80 | fz_buffer *fz_new_buffer(fz_context *ctx, size_t capacity); 81 | 82 | /** 83 | Create a new buffer with existing data. 84 | 85 | data: Pointer to existing data. 86 | size: Size of existing data. 87 | 88 | Takes ownership of data. Does not make a copy. Calls fz_free on 89 | the data when the buffer is deallocated. Do not use 'data' after 90 | passing to this function. 91 | 92 | Returns pointer to new buffer. Throws exception on allocation 93 | failure. 94 | */ 95 | fz_buffer *fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, size_t size); 96 | 97 | /** 98 | Like fz_new_buffer, but does not take ownership. 99 | */ 100 | fz_buffer *fz_new_buffer_from_shared_data(fz_context *ctx, const unsigned char *data, size_t size); 101 | 102 | /** 103 | Create a new buffer containing a copy of the passed data. 104 | */ 105 | fz_buffer *fz_new_buffer_from_copied_data(fz_context *ctx, const unsigned char *data, size_t size); 106 | 107 | /** 108 | Make a new buffer, containing a copy of the data used in 109 | the original. 110 | */ 111 | fz_buffer *fz_clone_buffer(fz_context *ctx, fz_buffer *buf); 112 | 113 | /** 114 | Create a new buffer with data decoded from a base64 input string. 115 | */ 116 | fz_buffer *fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size); 117 | 118 | /** 119 | Ensure that a buffer has a given capacity, 120 | truncating data if required. 121 | 122 | capacity: The desired capacity for the buffer. If the current 123 | size of the buffer contents is smaller than capacity, it is 124 | truncated. 125 | */ 126 | void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, size_t capacity); 127 | 128 | /** 129 | Make some space within a buffer (i.e. ensure that 130 | capacity > size). 131 | */ 132 | void fz_grow_buffer(fz_context *ctx, fz_buffer *buf); 133 | 134 | /** 135 | Trim wasted capacity from a buffer by resizing internal memory. 136 | */ 137 | void fz_trim_buffer(fz_context *ctx, fz_buffer *buf); 138 | 139 | /** 140 | Empties the buffer. Storage is not freed, but is held ready 141 | to be reused as the buffer is refilled. 142 | 143 | Never throws exceptions. 144 | */ 145 | void fz_clear_buffer(fz_context *ctx, fz_buffer *buf); 146 | 147 | /** 148 | Create a new buffer with a (subset of) the data from the buffer. 149 | 150 | start: if >= 0, offset from start of buffer, if < 0 offset from end of buffer. 151 | 152 | end: if >= 0, offset from start of buffer, if < 0 offset from end of buffer. 153 | 154 | */ 155 | fz_buffer *fz_slice_buffer(fz_context *ctx, fz_buffer *buf, int64_t start, int64_t end); 156 | 157 | /** 158 | Append the contents of the source buffer onto the end of the 159 | destination buffer, extending automatically as required. 160 | 161 | Ownership of buffers does not change. 162 | */ 163 | void fz_append_buffer(fz_context *ctx, fz_buffer *destination, fz_buffer *source); 164 | 165 | /** 166 | Write a base64 encoded data block, optionally with periodic newlines. 167 | */ 168 | void fz_append_base64(fz_context *ctx, fz_buffer *out, const unsigned char *data, size_t size, int newline); 169 | 170 | /** 171 | Append a base64 encoded fz_buffer, optionally with periodic newlines. 172 | */ 173 | void fz_append_base64_buffer(fz_context *ctx, fz_buffer *out, fz_buffer *data, int newline); 174 | 175 | /** 176 | fz_append_*: Append data to a buffer. 177 | 178 | The buffer will automatically grow as required. 179 | */ 180 | void fz_append_data(fz_context *ctx, fz_buffer *buf, const void *data, size_t len); 181 | void fz_append_string(fz_context *ctx, fz_buffer *buf, const char *data); 182 | void fz_append_byte(fz_context *ctx, fz_buffer *buf, int c); 183 | void fz_append_rune(fz_context *ctx, fz_buffer *buf, int c); 184 | void fz_append_int32_le(fz_context *ctx, fz_buffer *buf, int x); 185 | void fz_append_int16_le(fz_context *ctx, fz_buffer *buf, int x); 186 | void fz_append_int32_be(fz_context *ctx, fz_buffer *buf, int x); 187 | void fz_append_int16_be(fz_context *ctx, fz_buffer *buf, int x); 188 | void fz_append_bits(fz_context *ctx, fz_buffer *buf, int value, int count); 189 | void fz_append_bits_pad(fz_context *ctx, fz_buffer *buf); 190 | 191 | /** 192 | fz_append_pdf_string: Append a string with PDF syntax quotes and 193 | escapes. 194 | 195 | The buffer will automatically grow as required. 196 | */ 197 | void fz_append_pdf_string(fz_context *ctx, fz_buffer *buffer, const char *text); 198 | 199 | /** 200 | fz_append_printf: Format and append data to buffer using 201 | printf-like formatting (see fz_vsnprintf). 202 | 203 | The buffer will automatically grow as required. 204 | */ 205 | void fz_append_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...); 206 | 207 | /** 208 | fz_append_vprintf: Format and append data to buffer using 209 | printf-like formatting with varargs (see fz_vsnprintf). 210 | */ 211 | void fz_append_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list args); 212 | 213 | /** 214 | Zero-terminate buffer in order to use as a C string. 215 | 216 | This byte is invisible and does not affect the length of the 217 | buffer as returned by fz_buffer_storage. The zero byte is 218 | written *after* the data, and subsequent writes will overwrite 219 | the terminating byte. 220 | 221 | Subsequent changes to the size of the buffer (such as by 222 | fz_buffer_trim, fz_buffer_grow, fz_resize_buffer, etc) may 223 | invalidate this. 224 | */ 225 | void fz_terminate_buffer(fz_context *ctx, fz_buffer *buf); 226 | 227 | /** 228 | Create an MD5 digest from buffer contents. 229 | 230 | Never throws exceptions. 231 | */ 232 | void fz_md5_buffer(fz_context *ctx, fz_buffer *buffer, unsigned char digest[16]); 233 | 234 | /** 235 | Take ownership of buffer contents. 236 | 237 | Performs the same task as fz_buffer_storage, but ownership of 238 | the data buffer returns with this call. The buffer is left 239 | empty. 240 | 241 | Note: Bad things may happen if this is called on a buffer with 242 | multiple references that is being used from multiple threads. 243 | 244 | data: Pointer to place to retrieve data pointer. 245 | 246 | Returns length of stream. 247 | */ 248 | size_t fz_buffer_extract(fz_context *ctx, fz_buffer *buf, unsigned char **data); 249 | 250 | #endif 251 | -------------------------------------------------------------------------------- /include/mupdf/fitz/compress.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_COMPRESS_H 24 | #define MUPDF_FITZ_COMPRESS_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/buffer.h" 28 | #include "mupdf/fitz/pixmap.h" 29 | 30 | typedef enum 31 | { 32 | FZ_DEFLATE_NONE = 0, 33 | FZ_DEFLATE_BEST_SPEED = 1, 34 | FZ_DEFLATE_BEST = 9, 35 | FZ_DEFLATE_DEFAULT = -1 36 | } fz_deflate_level; 37 | 38 | /** 39 | Returns the upper bound on the 40 | size of flated data of length size. 41 | */ 42 | size_t fz_deflate_bound(fz_context *ctx, size_t size); 43 | 44 | /** 45 | Compress source_length bytes of data starting 46 | at source, into a buffer of length *destLen, starting at dest. 47 | *compressed_length will be updated on exit to contain the size 48 | actually used. 49 | */ 50 | void fz_deflate(fz_context *ctx, unsigned char *dest, size_t *compressed_length, const unsigned char *source, size_t source_length, fz_deflate_level level); 51 | 52 | /** 53 | Compress source_length bytes of data starting 54 | at source, into a new memory block malloced for that purpose. 55 | *compressed_length is updated on exit to contain the size used. 56 | Ownership of the block is returned from this function, and the 57 | caller is therefore responsible for freeing it. The block may be 58 | considerably larger than is actually required. The caller is 59 | free to fz_realloc it down if it wants to. 60 | */ 61 | unsigned char *fz_new_deflated_data(fz_context *ctx, size_t *compressed_length, const unsigned char *source, size_t source_length, fz_deflate_level level); 62 | 63 | /** 64 | Compress the contents of a fz_buffer into a 65 | new block malloced for that purpose. *compressed_length is 66 | updated on exit to contain the size used. Ownership of the block 67 | is returned from this function, and the caller is therefore 68 | responsible for freeing it. The block may be considerably larger 69 | than is actually required. The caller is free to fz_realloc it 70 | down if it wants to. 71 | */ 72 | unsigned char *fz_new_deflated_data_from_buffer(fz_context *ctx, size_t *compressed_length, fz_buffer *buffer, fz_deflate_level level); 73 | 74 | /** 75 | Compress bitmap data as CCITT Group 3 1D fax image. 76 | Creates a stream assuming the default PDF parameters, 77 | except the number of columns. 78 | */ 79 | fz_buffer *fz_compress_ccitt_fax_g3(fz_context *ctx, const unsigned char *data, int columns, int rows, ptrdiff_t stride); 80 | 81 | /** 82 | Compress bitmap data as CCITT Group 4 2D fax image. 83 | Creates a stream assuming the default PDF parameters, except 84 | K=-1 and the number of columns. 85 | */ 86 | fz_buffer *fz_compress_ccitt_fax_g4(fz_context *ctx, const unsigned char *data, int columns, int rows, ptrdiff_t stride); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /include/mupdf/fitz/compressed-buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2023 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_COMPRESSED_BUFFER_H 24 | #define MUPDF_FITZ_COMPRESSED_BUFFER_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/buffer.h" 29 | #include "mupdf/fitz/stream.h" 30 | #include "mupdf/fitz/filter.h" 31 | 32 | /** 33 | Compression parameters used for buffers of compressed data; 34 | typically for the source data for images. 35 | */ 36 | typedef struct 37 | { 38 | int type; 39 | union { 40 | struct { 41 | int color_transform; /* Use -1 for unset */ 42 | int invert_cmyk; /* Use 1 for standalone JPEG files */ 43 | } jpeg; 44 | struct { 45 | int smask_in_data; 46 | } jpx; 47 | struct { 48 | fz_jbig2_globals *globals; 49 | int embedded; 50 | } jbig2; 51 | struct { 52 | int columns; 53 | int rows; 54 | int k; 55 | int end_of_line; 56 | int encoded_byte_align; 57 | int end_of_block; 58 | int black_is_1; 59 | int damaged_rows_before_error; 60 | } fax; 61 | struct 62 | { 63 | int columns; 64 | int colors; 65 | int predictor; 66 | int bpc; 67 | } 68 | flate; 69 | struct 70 | { 71 | int columns; 72 | int colors; 73 | int predictor; 74 | int bpc; 75 | int early_change; 76 | } lzw; 77 | } u; 78 | } fz_compression_params; 79 | 80 | /** 81 | Buffers of compressed data; typically for the source data 82 | for images. 83 | */ 84 | typedef struct 85 | { 86 | int refs; 87 | fz_compression_params params; 88 | fz_buffer *buffer; 89 | } fz_compressed_buffer; 90 | 91 | /** 92 | Take a reference to an fz_compressed_buffer. 93 | */ 94 | fz_compressed_buffer *fz_keep_compressed_buffer(fz_context *ctx, fz_compressed_buffer *cbuf); 95 | 96 | /** 97 | Return the storage size used for a buffer and its data. 98 | Used in implementing store handling. 99 | 100 | Never throws exceptions. 101 | */ 102 | size_t fz_compressed_buffer_size(fz_compressed_buffer *buffer); 103 | 104 | /** 105 | Open a stream to read the decompressed version of a buffer. 106 | */ 107 | fz_stream *fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *); 108 | 109 | /** 110 | Open a stream to read the decompressed version of a buffer, 111 | with optional log2 subsampling. 112 | 113 | l2factor = NULL for no subsampling, or a pointer to an integer 114 | containing the maximum log2 subsample factor acceptable (0 = 115 | none, 1 = halve dimensions, 2 = quarter dimensions etc). If 116 | non-NULL, then *l2factor will be updated on exit with the actual 117 | log2 subsample factor achieved. 118 | */ 119 | fz_stream *fz_open_image_decomp_stream_from_buffer(fz_context *ctx, fz_compressed_buffer *, int *l2factor); 120 | 121 | /** 122 | Open a stream to read the decompressed version of another stream 123 | with optional log2 subsampling. 124 | */ 125 | fz_stream *fz_open_image_decomp_stream(fz_context *ctx, fz_stream *, fz_compression_params *, int *l2factor); 126 | 127 | /** 128 | Recognise image format strings in the first 8 bytes from image 129 | data. 130 | */ 131 | int fz_recognize_image_format(fz_context *ctx, unsigned char p[8]); 132 | 133 | /** 134 | Map from FZ_IMAGE_* value to string. 135 | 136 | The returned string is static and therefore must not be freed. 137 | */ 138 | const char *fz_image_type_name(int type); 139 | 140 | /** 141 | Map from (case sensitive) image type string to FZ_IMAGE_* 142 | type value. 143 | */ 144 | int fz_lookup_image_type(const char *type); 145 | 146 | enum 147 | { 148 | FZ_IMAGE_UNKNOWN = 0, 149 | 150 | /* Uncompressed samples */ 151 | FZ_IMAGE_RAW, 152 | 153 | /* Compressed samples */ 154 | FZ_IMAGE_FAX, 155 | FZ_IMAGE_FLATE, 156 | FZ_IMAGE_LZW, 157 | FZ_IMAGE_RLD, 158 | 159 | /* Full image formats */ 160 | FZ_IMAGE_BMP, 161 | FZ_IMAGE_GIF, 162 | FZ_IMAGE_JBIG2, 163 | FZ_IMAGE_JPEG, 164 | FZ_IMAGE_JPX, 165 | FZ_IMAGE_JXR, 166 | FZ_IMAGE_PNG, 167 | FZ_IMAGE_PNM, 168 | FZ_IMAGE_TIFF, 169 | FZ_IMAGE_PSD, 170 | }; 171 | 172 | /** 173 | Drop a reference to a compressed buffer. Destroys the buffer 174 | and frees any storage/other references held by it. 175 | 176 | Never throws exceptions. 177 | */ 178 | void fz_drop_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf); 179 | 180 | /** 181 | Create a new, UNKNOWN format, compressed_buffer. 182 | */ 183 | fz_compressed_buffer *fz_new_compressed_buffer(fz_context *ctx); 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /include/mupdf/fitz/config.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef FZ_CONFIG_H 24 | 25 | #define FZ_CONFIG_H 26 | 27 | /** 28 | Enable the following for spot (and hence overprint/overprint 29 | simulation) capable rendering. This forces FZ_PLOTTERS_N on. 30 | */ 31 | /* #define FZ_ENABLE_SPOT_RENDERING 1 */ 32 | 33 | /** 34 | Choose which plotters we need. 35 | By default we build all the plotters in. To avoid building 36 | plotters in that aren't needed, define the unwanted 37 | FZ_PLOTTERS_... define to 0. 38 | */ 39 | /* #define FZ_PLOTTERS_G 1 */ 40 | /* #define FZ_PLOTTERS_RGB 1 */ 41 | /* #define FZ_PLOTTERS_CMYK 1 */ 42 | /* #define FZ_PLOTTERS_N 1 */ 43 | 44 | /** 45 | Choose which document agents to include. 46 | By default all are enabled. To avoid building unwanted 47 | ones, define FZ_ENABLE_... to 0. 48 | */ 49 | /* #define FZ_ENABLE_PDF 1 */ 50 | /* #define FZ_ENABLE_XPS 1 */ 51 | /* #define FZ_ENABLE_SVG 1 */ 52 | /* #define FZ_ENABLE_CBZ 1 */ 53 | /* #define FZ_ENABLE_IMG 1 */ 54 | /* #define FZ_ENABLE_HTML 1 */ 55 | /* #define FZ_ENABLE_EPUB 1 */ 56 | 57 | /** 58 | Choose which document writers to include. 59 | By default all are enabled. To avoid building unwanted 60 | ones, define FZ_ENABLE_..._OUTPUT to 0. 61 | */ 62 | /* #define FZ_ENABLE_OCR_OUTPUT 1 */ 63 | /* #define FZ_ENABLE_DOCX_OUTPUT 1 */ 64 | /* #define FZ_ENABLE_ODT_OUTPUT 1 */ 65 | 66 | /** 67 | Choose whether to enable ICC color profiles. 68 | */ 69 | /* #define FZ_ENABLE_ICC 1 */ 70 | 71 | /** 72 | Choose whether to enable JPEG2000 decoding. 73 | By default, it is enabled, but due to frequent security 74 | issues with the third party libraries we support disabling 75 | it with this flag. 76 | */ 77 | /* #define FZ_ENABLE_JPX 1 */ 78 | 79 | /** 80 | Choose whether to enable JavaScript. 81 | By default JavaScript is enabled both for mutool and PDF 82 | interactivity. 83 | */ 84 | /* #define FZ_ENABLE_JS 1 */ 85 | 86 | /** 87 | Choose which fonts to include. 88 | By default we include the base 14 PDF fonts, 89 | DroidSansFallback from Android for CJK, and 90 | Charis SIL from SIL for epub/html. 91 | Enable the following defines to AVOID including 92 | unwanted fonts. 93 | */ 94 | /* To avoid all noto fonts except CJK, enable: */ 95 | #define TOFU 96 | 97 | /* To skip the CJK font, enable: (this implicitly enables TOFU_CJK_EXT 98 | * and TOFU_CJK_LANG) */ 99 | #define TOFU_CJK 100 | 101 | /* To skip CJK Extension A, enable: (this implicitly enables 102 | * TOFU_CJK_LANG) */ 103 | /* #define TOFU_CJK_EXT */ 104 | 105 | /* To skip CJK language specific fonts, enable: */ 106 | /* #define TOFU_CJK_LANG */ 107 | 108 | /* To skip the Emoji font, enable: */ 109 | /* #define TOFU_EMOJI */ 110 | 111 | /* To skip the ancient/historic scripts, enable: */ 112 | /* #define TOFU_HISTORIC */ 113 | 114 | /* To skip the symbol font, enable: */ 115 | /* #define TOFU_SYMBOL */ 116 | 117 | /* To skip the SIL fonts, enable: */ 118 | /* #define TOFU_SIL */ 119 | 120 | /* To skip the Base14 fonts, enable: */ 121 | /* #define TOFU_BASE14 */ 122 | /* (You probably really don't want to do that except for measurement 123 | * purposes!) */ 124 | 125 | /* ---------- DO NOT EDIT ANYTHING UNDER THIS LINE ---------- */ 126 | 127 | #ifndef FZ_ENABLE_SPOT_RENDERING 128 | #define FZ_ENABLE_SPOT_RENDERING 1 129 | #endif 130 | 131 | #if FZ_ENABLE_SPOT_RENDERING 132 | #undef FZ_PLOTTERS_N 133 | #define FZ_PLOTTERS_N 1 134 | #endif /* FZ_ENABLE_SPOT_RENDERING */ 135 | 136 | #ifndef FZ_PLOTTERS_G 137 | #define FZ_PLOTTERS_G 1 138 | #endif /* FZ_PLOTTERS_G */ 139 | 140 | #ifndef FZ_PLOTTERS_RGB 141 | #define FZ_PLOTTERS_RGB 1 142 | #endif /* FZ_PLOTTERS_RGB */ 143 | 144 | #ifndef FZ_PLOTTERS_CMYK 145 | #define FZ_PLOTTERS_CMYK 1 146 | #endif /* FZ_PLOTTERS_CMYK */ 147 | 148 | #ifndef FZ_PLOTTERS_N 149 | #define FZ_PLOTTERS_N 1 150 | #endif /* FZ_PLOTTERS_N */ 151 | 152 | /* We need at least 1 plotter defined */ 153 | #if FZ_PLOTTERS_G == 0 && FZ_PLOTTERS_RGB == 0 && FZ_PLOTTERS_CMYK == 0 154 | #undef FZ_PLOTTERS_N 155 | #define FZ_PLOTTERS_N 1 156 | #endif 157 | 158 | #ifndef FZ_ENABLE_PDF 159 | #define FZ_ENABLE_PDF 1 160 | #endif /* FZ_ENABLE_PDF */ 161 | 162 | #ifndef FZ_ENABLE_XPS 163 | #define FZ_ENABLE_XPS 1 164 | #endif /* FZ_ENABLE_XPS */ 165 | 166 | #ifndef FZ_ENABLE_SVG 167 | #define FZ_ENABLE_SVG 1 168 | #endif /* FZ_ENABLE_SVG */ 169 | 170 | #ifndef FZ_ENABLE_CBZ 171 | #define FZ_ENABLE_CBZ 1 172 | #endif /* FZ_ENABLE_CBZ */ 173 | 174 | #ifndef FZ_ENABLE_IMG 175 | #define FZ_ENABLE_IMG 1 176 | #endif /* FZ_ENABLE_IMG */ 177 | 178 | #ifndef FZ_ENABLE_HTML 179 | #define FZ_ENABLE_HTML 1 180 | #endif /* FZ_ENABLE_HTML */ 181 | 182 | #ifndef FZ_ENABLE_EPUB 183 | #define FZ_ENABLE_EPUB 1 184 | #endif /* FZ_ENABLE_EPUB */ 185 | 186 | #ifndef FZ_ENABLE_OCR_OUTPUT 187 | #define FZ_ENABLE_OCR_OUTPUT 1 188 | #endif /* FZ_ENABLE_OCR_OUTPUT */ 189 | 190 | #ifndef FZ_ENABLE_ODT_OUTPUT 191 | #define FZ_ENABLE_ODT_OUTPUT 1 192 | #endif /* FZ_ENABLE_ODT_OUTPUT */ 193 | 194 | #ifndef FZ_ENABLE_DOCX_OUTPUT 195 | #define FZ_ENABLE_DOCX_OUTPUT 1 196 | #endif /* FZ_ENABLE_DOCX_OUTPUT */ 197 | 198 | #ifndef FZ_ENABLE_JPX 199 | #define FZ_ENABLE_JPX 1 200 | #endif /* FZ_ENABLE_JPX */ 201 | 202 | #ifndef FZ_ENABLE_JS 203 | #define FZ_ENABLE_JS 1 204 | #endif /* FZ_ENABLE_JS */ 205 | 206 | #ifndef FZ_ENABLE_ICC 207 | #define FZ_ENABLE_ICC 1 208 | #endif /* FZ_ENABLE_ICC */ 209 | 210 | /* If Epub and HTML are both disabled, disable SIL fonts */ 211 | #if FZ_ENABLE_HTML == 0 && FZ_ENABLE_EPUB == 0 212 | #undef TOFU_SIL 213 | #define TOFU_SIL 214 | #endif 215 | 216 | #if !defined(HAVE_LEPTONICA) || !defined(HAVE_TESSERACT) 217 | #ifndef OCR_DISABLED 218 | #define OCR_DISABLED 219 | #endif 220 | #endif 221 | 222 | #endif /* FZ_CONFIG_H */ 223 | -------------------------------------------------------------------------------- /include/mupdf/fitz/crypt.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_CRYPT_H 24 | #define MUPDF_FITZ_CRYPT_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | 28 | /* md5 digests */ 29 | 30 | /** 31 | Structure definition is public to enable stack 32 | based allocation. Do not access the members directly. 33 | */ 34 | typedef struct 35 | { 36 | uint32_t lo, hi; 37 | uint32_t a, b, c, d; 38 | unsigned char buffer[64]; 39 | } fz_md5; 40 | 41 | /** 42 | MD5 initialization. Begins an MD5 operation, writing a new 43 | context. 44 | 45 | Never throws an exception. 46 | */ 47 | void fz_md5_init(fz_md5 *state); 48 | 49 | /** 50 | MD5 block update operation. Continues an MD5 message-digest 51 | operation, processing another message block, and updating the 52 | context. 53 | 54 | Never throws an exception. 55 | */ 56 | void fz_md5_update(fz_md5 *state, const unsigned char *input, size_t inlen); 57 | 58 | /** 59 | MD5 block update operation. Continues an MD5 message-digest 60 | operation, processing an int64, and updating the context. 61 | 62 | Never throws an exception. 63 | */ 64 | void fz_md5_update_int64(fz_md5 *state, int64_t i); 65 | 66 | /** 67 | MD5 finalization. Ends an MD5 message-digest operation, writing 68 | the message digest and zeroizing the context. 69 | 70 | Never throws an exception. 71 | */ 72 | void fz_md5_final(fz_md5 *state, unsigned char digest[16]); 73 | 74 | /* sha-256 digests */ 75 | 76 | /** 77 | Structure definition is public to enable stack 78 | based allocation. Do not access the members directly. 79 | */ 80 | typedef struct 81 | { 82 | unsigned int state[8]; 83 | unsigned int count[2]; 84 | union { 85 | unsigned char u8[64]; 86 | unsigned int u32[16]; 87 | } buffer; 88 | } fz_sha256; 89 | 90 | /** 91 | SHA256 initialization. Begins an SHA256 operation, initialising 92 | the supplied context. 93 | 94 | Never throws an exception. 95 | */ 96 | void fz_sha256_init(fz_sha256 *state); 97 | 98 | /** 99 | SHA256 block update operation. Continues an SHA256 message- 100 | digest operation, processing another message block, and updating 101 | the context. 102 | 103 | Never throws an exception. 104 | */ 105 | void fz_sha256_update(fz_sha256 *state, const unsigned char *input, size_t inlen); 106 | 107 | /** 108 | MD5 finalization. Ends an MD5 message-digest operation, writing 109 | the message digest and zeroizing the context. 110 | 111 | Never throws an exception. 112 | */ 113 | void fz_sha256_final(fz_sha256 *state, unsigned char digest[32]); 114 | 115 | /* sha-512 digests */ 116 | 117 | /** 118 | Structure definition is public to enable stack 119 | based allocation. Do not access the members directly. 120 | */ 121 | typedef struct 122 | { 123 | uint64_t state[8]; 124 | unsigned int count[2]; 125 | union { 126 | unsigned char u8[128]; 127 | uint64_t u64[16]; 128 | } buffer; 129 | } fz_sha512; 130 | 131 | /** 132 | SHA512 initialization. Begins an SHA512 operation, initialising 133 | the supplied context. 134 | 135 | Never throws an exception. 136 | */ 137 | void fz_sha512_init(fz_sha512 *state); 138 | 139 | /** 140 | SHA512 block update operation. Continues an SHA512 message- 141 | digest operation, processing another message block, and updating 142 | the context. 143 | 144 | Never throws an exception. 145 | */ 146 | void fz_sha512_update(fz_sha512 *state, const unsigned char *input, size_t inlen); 147 | 148 | /** 149 | SHA512 finalization. Ends an SHA512 message-digest operation, 150 | writing the message digest and zeroizing the context. 151 | 152 | Never throws an exception. 153 | */ 154 | void fz_sha512_final(fz_sha512 *state, unsigned char digest[64]); 155 | 156 | /* sha-384 digests */ 157 | 158 | typedef fz_sha512 fz_sha384; 159 | 160 | /** 161 | SHA384 initialization. Begins an SHA384 operation, initialising 162 | the supplied context. 163 | 164 | Never throws an exception. 165 | */ 166 | void fz_sha384_init(fz_sha384 *state); 167 | 168 | /** 169 | SHA384 block update operation. Continues an SHA384 message- 170 | digest operation, processing another message block, and updating 171 | the context. 172 | 173 | Never throws an exception. 174 | */ 175 | void fz_sha384_update(fz_sha384 *state, const unsigned char *input, size_t inlen); 176 | 177 | /** 178 | SHA384 finalization. Ends an SHA384 message-digest operation, 179 | writing the message digest and zeroizing the context. 180 | 181 | Never throws an exception. 182 | */ 183 | void fz_sha384_final(fz_sha384 *state, unsigned char digest[64]); 184 | 185 | /* arc4 crypto */ 186 | 187 | /** 188 | Structure definition is public to enable stack 189 | based allocation. Do not access the members directly. 190 | */ 191 | typedef struct 192 | { 193 | unsigned x; 194 | unsigned y; 195 | unsigned char state[256]; 196 | } fz_arc4; 197 | 198 | /** 199 | RC4 initialization. Begins an RC4 operation, writing a new 200 | context. 201 | 202 | Never throws an exception. 203 | */ 204 | void fz_arc4_init(fz_arc4 *state, const unsigned char *key, size_t len); 205 | 206 | /** 207 | RC4 block encrypt operation; encrypt src into dst (both of 208 | length len) updating the RC4 state as we go. 209 | 210 | Never throws an exception. 211 | */ 212 | void fz_arc4_encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, size_t len); 213 | 214 | /** 215 | RC4 finalization. Zero the context. 216 | 217 | Never throws an exception. 218 | */ 219 | void fz_arc4_final(fz_arc4 *state); 220 | 221 | /* AES block cipher implementation from XYSSL */ 222 | 223 | /** 224 | Structure definitions are public to enable stack 225 | based allocation. Do not access the members directly. 226 | */ 227 | typedef struct 228 | { 229 | int nr; /* number of rounds */ 230 | uint32_t *rk; /* AES round keys */ 231 | uint32_t buf[68]; /* unaligned data */ 232 | } fz_aes; 233 | 234 | #define FZ_AES_DECRYPT 0 235 | #define FZ_AES_ENCRYPT 1 236 | 237 | /** 238 | AES encryption intialisation. Fills in the supplied context 239 | and prepares for encryption using the given key. 240 | 241 | Returns non-zero for error (key size other than 128/192/256). 242 | 243 | Never throws an exception. 244 | */ 245 | int fz_aes_setkey_enc(fz_aes *ctx, const unsigned char *key, int keysize); 246 | 247 | /** 248 | AES decryption intialisation. Fills in the supplied context 249 | and prepares for decryption using the given key. 250 | 251 | Returns non-zero for error (key size other than 128/192/256). 252 | 253 | Never throws an exception. 254 | */ 255 | int fz_aes_setkey_dec(fz_aes *ctx, const unsigned char *key, int keysize); 256 | 257 | /** 258 | AES block processing. Encrypts or Decrypts (according to mode, 259 | which must match what was initially set up) length bytes (which 260 | must be a multiple of 16), using (and modifying) the insertion 261 | vector iv, reading from input, and writing to output. 262 | 263 | Never throws an exception. 264 | */ 265 | void fz_aes_crypt_cbc(fz_aes *ctx, int mode, size_t length, 266 | unsigned char iv[16], 267 | const unsigned char *input, 268 | unsigned char *output ); 269 | 270 | #endif 271 | -------------------------------------------------------------------------------- /include/mupdf/fitz/display-list.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_DISPLAY_LIST_H 24 | #define MUPDF_FITZ_DISPLAY_LIST_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/geometry.h" 29 | #include "mupdf/fitz/device.h" 30 | 31 | /** 32 | Display list device -- record and play back device commands. 33 | */ 34 | 35 | /** 36 | fz_display_list is a list containing drawing commands (text, 37 | images, etc.). The intent is two-fold: as a caching-mechanism 38 | to reduce parsing of a page, and to be used as a data 39 | structure in multi-threading where one thread parses the page 40 | and another renders pages. 41 | 42 | Create a display list with fz_new_display_list, hand it over to 43 | fz_new_list_device to have it populated, and later replay the 44 | list (once or many times) by calling fz_run_display_list. When 45 | the list is no longer needed drop it with fz_drop_display_list. 46 | */ 47 | typedef struct fz_display_list fz_display_list; 48 | 49 | /** 50 | Create an empty display list. 51 | 52 | A display list contains drawing commands (text, images, etc.). 53 | Use fz_new_list_device for populating the list. 54 | 55 | mediabox: Bounds of the page (in points) represented by the 56 | display list. 57 | */ 58 | fz_display_list *fz_new_display_list(fz_context *ctx, fz_rect mediabox); 59 | 60 | /** 61 | Create a rendering device for a display list. 62 | 63 | When the device is rendering a page it will populate the 64 | display list with drawing commands (text, images, etc.). The 65 | display list can later be reused to render a page many times 66 | without having to re-interpret the page from the document file 67 | for each rendering. Once the device is no longer needed, free 68 | it with fz_drop_device. 69 | 70 | list: A display list that the list device takes a reference to. 71 | */ 72 | fz_device *fz_new_list_device(fz_context *ctx, fz_display_list *list); 73 | 74 | /** 75 | (Re)-run a display list through a device. 76 | 77 | list: A display list, created by fz_new_display_list and 78 | populated with objects from a page by running fz_run_page on a 79 | device obtained from fz_new_list_device. 80 | 81 | ctm: Transform to apply to display list contents. May include 82 | for example scaling and rotation, see fz_scale, fz_rotate and 83 | fz_concat. Set to fz_identity if no transformation is desired. 84 | 85 | scissor: Only the part of the contents of the display list 86 | visible within this area will be considered when the list is 87 | run through the device. This does not imply for tile objects 88 | contained in the display list. 89 | 90 | cookie: Communication mechanism between caller and library 91 | running the page. Intended for multi-threaded applications, 92 | while single-threaded applications set cookie to NULL. The 93 | caller may abort an ongoing page run. Cookie also communicates 94 | progress information back to the caller. The fields inside 95 | cookie are continually updated while the page is being run. 96 | */ 97 | void fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, fz_matrix ctm, fz_rect scissor, fz_cookie *cookie); 98 | 99 | /** 100 | Increment the reference count for a display list. Returns the 101 | same pointer. 102 | 103 | Never throws exceptions. 104 | */ 105 | fz_display_list *fz_keep_display_list(fz_context *ctx, fz_display_list *list); 106 | 107 | /** 108 | Decrement the reference count for a display list. When the 109 | reference count reaches zero, all the references in the display 110 | list itself are dropped, and the display list is freed. 111 | 112 | Never throws exceptions. 113 | */ 114 | void fz_drop_display_list(fz_context *ctx, fz_display_list *list); 115 | 116 | /** 117 | Return the bounding box of the page recorded in a display list. 118 | */ 119 | fz_rect fz_bound_display_list(fz_context *ctx, fz_display_list *list); 120 | 121 | /** 122 | Create a new image from a display list. 123 | 124 | w, h: The conceptual width/height of the image. 125 | 126 | transform: The matrix that needs to be applied to the given 127 | list to make it render to the unit square. 128 | 129 | list: The display list. 130 | */ 131 | fz_image *fz_new_image_from_display_list(fz_context *ctx, float w, float h, fz_display_list *list); 132 | 133 | /** 134 | Check for a display list being empty 135 | 136 | list: The list to check. 137 | 138 | Returns true if empty, false otherwise. 139 | */ 140 | int fz_display_list_is_empty(fz_context *ctx, const fz_display_list *list); 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /include/mupdf/fitz/export.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_EXPORT_H 24 | #define MUPDF_FITZ_EXPORT_H 25 | 26 | /* 27 | * Support for building/using MuPDF DLL on Windows. 28 | * 29 | * When compiling code that uses MuPDF DLL, FZ_DLL_CLIENT should be defined. 30 | * 31 | * When compiling MuPDF DLL itself, FZ_DLL should be defined. 32 | */ 33 | 34 | #if defined(_WIN32) || defined(_WIN64) 35 | #if defined(FZ_DLL) 36 | /* Building DLL. */ 37 | #define FZ_FUNCTION __declspec(dllexport) 38 | #define FZ_DATA __declspec(dllexport) 39 | #elif defined(FZ_DLL_CLIENT) 40 | /* Building DLL client code. */ 41 | #define FZ_FUNCTION __declspec(dllexport) 42 | #define FZ_DATA __declspec(dllimport) 43 | #else 44 | #define FZ_FUNCTION 45 | #define FZ_DATA 46 | #endif 47 | #else 48 | #define FZ_FUNCTION 49 | #define FZ_DATA 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/mupdf/fitz/filter.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2023 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_FILTER_H 24 | #define MUPDF_FITZ_FILTER_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/buffer.h" 29 | #include "mupdf/fitz/store.h" 30 | #include "mupdf/fitz/stream.h" 31 | 32 | typedef struct fz_jbig2_globals fz_jbig2_globals; 33 | 34 | typedef struct 35 | { 36 | int64_t offset; 37 | uint64_t length; 38 | } fz_range; 39 | 40 | /** 41 | The null filter reads a specified amount of data from the 42 | substream. 43 | */ 44 | fz_stream *fz_open_null_filter(fz_context *ctx, fz_stream *chain, uint64_t len, int64_t offset); 45 | 46 | /** 47 | The range filter copies data from specified ranges of the 48 | chained stream. 49 | */ 50 | fz_stream *fz_open_range_filter(fz_context *ctx, fz_stream *chain, fz_range *ranges, int nranges); 51 | 52 | /** 53 | The endstream filter reads a PDF substream, and starts to look 54 | for an 'endstream' token after the specified length. 55 | */ 56 | fz_stream *fz_open_endstream_filter(fz_context *ctx, fz_stream *chain, uint64_t len, int64_t offset); 57 | 58 | /** 59 | Concat filter concatenates several streams into one. 60 | */ 61 | fz_stream *fz_open_concat(fz_context *ctx, int max, int pad); 62 | 63 | /** 64 | Add a chained stream to the end of the concatenate filter. 65 | 66 | Ownership of chain is passed in. 67 | */ 68 | void fz_concat_push_drop(fz_context *ctx, fz_stream *concat, fz_stream *chain); 69 | 70 | /** 71 | arc4 filter performs RC4 decoding of data read from the chained 72 | filter using the supplied key. 73 | */ 74 | fz_stream *fz_open_arc4(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen); 75 | 76 | /** 77 | aesd filter performs AES decoding of data read from the chained 78 | filter using the supplied key. 79 | */ 80 | fz_stream *fz_open_aesd(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen); 81 | 82 | /** 83 | a85d filter performs ASCII 85 Decoding of data read 84 | from the chained filter. 85 | */ 86 | fz_stream *fz_open_a85d(fz_context *ctx, fz_stream *chain); 87 | 88 | /** 89 | ahxd filter performs ASCII Hex decoding of data read 90 | from the chained filter. 91 | */ 92 | fz_stream *fz_open_ahxd(fz_context *ctx, fz_stream *chain); 93 | 94 | /** 95 | rld filter performs Run Length Decoding of data read 96 | from the chained filter. 97 | */ 98 | fz_stream *fz_open_rld(fz_context *ctx, fz_stream *chain); 99 | 100 | /** 101 | dctd filter performs DCT (JPEG) decoding of data read 102 | from the chained filter. 103 | 104 | color_transform implements the PDF color_transform option 105 | use -1 for default behavior 106 | use 0 to disable YUV-RGB / YCCK-CMYK transforms 107 | use 1 to enable YUV-RGB / YCCK-CMYK transforms 108 | 109 | invert_cmyk implements the necessary inversion for Photoshop CMYK images 110 | use 0 if embedded in PDF 111 | use 1 if not embedded in PDF 112 | 113 | For subsampling on decode, set l2factor to the log2 of the 114 | reduction required (therefore 0 = full size decode). 115 | 116 | jpegtables is an optional stream from which the JPEG tables 117 | can be read. Use NULL if not required. 118 | */ 119 | fz_stream *fz_open_dctd(fz_context *ctx, fz_stream *chain, int color_transform, int invert_cmyk, int l2factor, fz_stream *jpegtables); 120 | 121 | /** 122 | faxd filter performs FAX decoding of data read from 123 | the chained filter. 124 | 125 | k: see fax specification (fax default is 0). 126 | 127 | end_of_line: whether we expect end of line markers (fax default 128 | is 0). 129 | 130 | encoded_byte_align: whether we align to bytes after each line 131 | (fax default is 0). 132 | 133 | columns: how many columns in the image (fax default is 1728). 134 | 135 | rows: 0 for unspecified or the number of rows of data to expect. 136 | 137 | end_of_block: whether we expect end of block markers (fax 138 | default is 1). 139 | 140 | black_is_1: determines the polarity of the image (fax default is 141 | 0). 142 | */ 143 | fz_stream *fz_open_faxd(fz_context *ctx, fz_stream *chain, 144 | int k, int end_of_line, int encoded_byte_align, 145 | int columns, int rows, int end_of_block, int black_is_1); 146 | 147 | /** 148 | flated filter performs LZ77 decoding (inflating) of data read 149 | from the chained filter. 150 | 151 | window_bits: How large a decompression window to use. Typically 152 | 15. A negative number, -n, means to use n bits, but to expect 153 | raw data with no header. 154 | */ 155 | fz_stream *fz_open_flated(fz_context *ctx, fz_stream *chain, int window_bits); 156 | 157 | /** 158 | libarchived filter performs generic compressed decoding of data 159 | in any format understood by libarchive from the chained filter. 160 | 161 | This will throw an exception if libarchive is not built in, or 162 | if the compression format is not recognised. 163 | */ 164 | fz_stream *fz_open_libarchived(fz_context *ctx, fz_stream *chain); 165 | 166 | /** 167 | lzwd filter performs LZW decoding of data read from the chained 168 | filter. 169 | 170 | early_change: (Default 1) specifies whether to change codes 1 171 | bit early. 172 | 173 | min_bits: (Default 9) specifies the minimum number of bits to 174 | use. 175 | 176 | reverse_bits: (Default 0) allows for compatibility with gif and 177 | old style tiffs (1). 178 | 179 | old_tiff: (Default 0) allows for different handling of the clear 180 | code, as found in old style tiffs. 181 | */ 182 | fz_stream *fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change, int min_bits, int reverse_bits, int old_tiff); 183 | 184 | /** 185 | predict filter performs pixel prediction on data read from 186 | the chained filter. 187 | 188 | predictor: 1 = copy, 2 = tiff, other = inline PNG predictor 189 | 190 | columns: width of image in pixels 191 | 192 | colors: number of components. 193 | 194 | bpc: bits per component (typically 8) 195 | */ 196 | fz_stream *fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, int colors, int bpc); 197 | 198 | /** 199 | Open a filter that performs jbig2 decompression on the chained 200 | stream, using the optional globals record. 201 | */ 202 | fz_stream *fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals, int embedded); 203 | 204 | /** 205 | Create a jbig2 globals record from a buffer. 206 | 207 | Immutable once created. 208 | */ 209 | fz_jbig2_globals *fz_load_jbig2_globals(fz_context *ctx, fz_buffer *buf); 210 | 211 | /** 212 | Increment the reference count for a jbig2 globals record. 213 | 214 | Never throws an exception. 215 | */ 216 | fz_jbig2_globals *fz_keep_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals); 217 | 218 | /** 219 | Decrement the reference count for a jbig2 globals record. 220 | When the reference count hits zero, the record is freed. 221 | 222 | Never throws an exception. 223 | */ 224 | void fz_drop_jbig2_globals(fz_context *ctx, fz_jbig2_globals *globals); 225 | 226 | /** 227 | Special jbig2 globals drop function for use in implementing 228 | store support. 229 | */ 230 | void fz_drop_jbig2_globals_imp(fz_context *ctx, fz_storable *globals); 231 | 232 | /** 233 | Return buffer containing jbig2 globals data stream. 234 | */ 235 | fz_buffer * fz_jbig2_globals_data(fz_context *ctx, fz_jbig2_globals *globals); 236 | 237 | /* Extra filters for tiff */ 238 | 239 | /** 240 | SGI Log 16bit (greyscale) decode from the chained filter. 241 | Decodes lines of w pixels to 8bpp greyscale. 242 | */ 243 | fz_stream *fz_open_sgilog16(fz_context *ctx, fz_stream *chain, int w); 244 | 245 | /** 246 | SGI Log 24bit (LUV) decode from the chained filter. 247 | Decodes lines of w pixels to 8bpc rgb. 248 | */ 249 | fz_stream *fz_open_sgilog24(fz_context *ctx, fz_stream *chain, int w); 250 | 251 | /** 252 | SGI Log 32bit (LUV) decode from the chained filter. 253 | Decodes lines of w pixels to 8bpc rgb. 254 | */ 255 | fz_stream *fz_open_sgilog32(fz_context *ctx, fz_stream *chain, int w); 256 | 257 | /** 258 | 4bit greyscale Thunderscan decoding from the chained filter. 259 | Decodes lines of w pixels to 8bpp greyscale. 260 | */ 261 | fz_stream *fz_open_thunder(fz_context *ctx, fz_stream *chain, int w); 262 | 263 | #endif 264 | -------------------------------------------------------------------------------- /include/mupdf/fitz/getopt.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_GETOPT_H 24 | #define MUPDF_FITZ_GETOPT_H 25 | 26 | #include "export.h" 27 | 28 | typedef struct 29 | { 30 | char *option; 31 | int *flag; 32 | void *opaque; 33 | } fz_getopt_long_options; 34 | 35 | /** 36 | Simple functions/variables for use in tools. 37 | 38 | ostr = option string. Comprises single letter options, followed by : if there 39 | is an argument to the option. 40 | 41 | longopts: NULL (indicating no long options), or a pointer to an array of 42 | longoptions, terminated by an entry with option == NULL. 43 | 44 | In the event of matching a single char option, this function will normally 45 | return the char. The exception to this is when the option requires an 46 | argument and none is supplied; in this case we return ':'. 47 | 48 | In the event of matching a long option, this function returns 0, with fz_optlong 49 | set to point to the matching option. 50 | 51 | A long option entry may be followed with : to indicate there is an argument to the 52 | option. If the need for an argument is specified in this way, and no argument is 53 | given, an error will be displayed and argument processing will stop. If an argument 54 | is given, and the long option record contains a non-null flag pointer, then the code 55 | will decode the argument and fill in that flag pointer. Specifically, 56 | case-insensitive matches to 'yes', 'no', 'true' and 'false' will cause a value of 0 57 | or 1 as appropriate to be written; failing this the arg will be interpreted as a 58 | decimal integer using atoi. 59 | 60 | A long option entry may be followed by an list of options (e.g. myoption=foo|bar|baz) 61 | and the option will be passed to fz_opt_from_list. The return value of that will be 62 | placed in fz_optitem. If the return value of that function is -1, then an error will 63 | be displayed and argument processing will stop. 64 | 65 | In the event of reaching the end of the arg list or '--', this function returns EOF. 66 | 67 | In the event of failing to match anything, an error is printed, and we return '?'. 68 | 69 | If an argument is expected for the option, then fz_optarg will be returned pointing 70 | at the start of the argument. Examples of supported argument formats: '-r500', '-r 500', 71 | '--resolution 500', '--resolution=500'. 72 | */ 73 | extern int fz_getopt_long(int nargc, char * const *nargv, const char *ostr, const fz_getopt_long_options *longopts); 74 | 75 | /** 76 | Identical to fz_getopt_long, but with a NULL longopts field, signifying no long 77 | options. 78 | */ 79 | extern int fz_getopt(int nargc, char * const *nargv, const char *ostr); 80 | 81 | /** 82 | fz_optind is updated to point to the current index being read from the 83 | arguments. 84 | */ 85 | FZ_DATA extern int fz_optind; 86 | 87 | /** 88 | fz_optarg is a pointer to the argument data for the most recently 89 | read option. 90 | */ 91 | FZ_DATA extern char *fz_optarg; 92 | 93 | /** 94 | fz_optlong is a pointer to the record for the most recently 95 | read long option. (i.e. if a long option is detected, this 96 | will be set to point to the record for that option, otherwise 97 | it will be NULL). 98 | */ 99 | FZ_DATA extern const fz_getopt_long_options *fz_optlong; 100 | 101 | /** 102 | The item number for the most recently matched item list. 103 | 104 | First item in the list is numbered 0. No match is -1. 105 | */ 106 | FZ_DATA extern int fz_optitem; 107 | 108 | /** 109 | Return the index of a (case-insensitive) option within an optlist. 110 | 111 | For instance for optlist = "Foo|Bar|Baz", and opt = "bar", 112 | this would return 1. 113 | 114 | If the optlist ends with "|*" then that is a catch all case and 115 | matches all options allowing the caller to process it itself. 116 | fz_optarg will be set to point to the option, and the return 117 | value will be the index of the '*' option within that list. 118 | 119 | If an optlist entry ends with ':' (e.g. "Foo:") then that option 120 | may have suboptions appended to it (for example "JPG:80") and 121 | fz_optarg will be set to point at "80". Otherwise fz_optarg will 122 | be set to NULL. 123 | 124 | In the event of no-match found, prints an error and returns -1. 125 | */ 126 | int fz_opt_from_list(char *opt, const char *optlist); 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/mupdf/fitz/glyph-cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_GLYPH_CACHE_H 24 | #define MUPDF_FITZ_GLYPH_CACHE_H 25 | 26 | #include "mupdf/fitz/context.h" 27 | #include "mupdf/fitz/geometry.h" 28 | #include "mupdf/fitz/font.h" 29 | #include "mupdf/fitz/pixmap.h" 30 | #include "mupdf/fitz/device.h" 31 | 32 | /** 33 | Purge all the glyphs from the cache. 34 | */ 35 | void fz_purge_glyph_cache(fz_context *ctx); 36 | 37 | /** 38 | Create a pixmap containing a rendered glyph. 39 | 40 | Lookup gid from font, clip it with scissor, and rendering it 41 | with aa bits of antialiasing into a new pixmap. 42 | 43 | The caller takes ownership of the pixmap and so must free it. 44 | 45 | Note: This function is no longer used for normal rendering 46 | operations, and is kept around just because we use it in the 47 | app. It should be considered "at risk" of removal from the API. 48 | */ 49 | fz_pixmap *fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, const fz_irect *scissor, int aa); 50 | 51 | /** 52 | Nasty PDF interpreter specific hernia, required to allow the 53 | interpreter to replay glyphs from a type3 font directly into 54 | the target device. 55 | 56 | This is only used in exceptional circumstances (such as type3 57 | glyphs that inherit current graphics state, or nested type3 58 | glyphs). 59 | */ 60 | void fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gid, fz_matrix trm, void *gstate, fz_default_colorspaces *def_cs); 61 | 62 | /** 63 | Force a type3 font to cache the displaylist for a given glyph 64 | id. 65 | 66 | This caching can involve reading the underlying file, so must 67 | happen ahead of time, so we aren't suddenly forced to read the 68 | file while playing a displaylist back. 69 | */ 70 | void fz_prepare_t3_glyph(fz_context *ctx, fz_font *font, int gid); 71 | 72 | /** 73 | Dump debug statistics for the glyph cache. 74 | */ 75 | void fz_dump_glyph_cache_stats(fz_context *ctx, fz_output *out); 76 | 77 | /** 78 | Perform subpixel quantisation and adjustment on a glyph matrix. 79 | 80 | ctm: On entry, the desired 'ideal' transformation for a glyph. 81 | On exit, adjusted to a (very similar) transformation quantised 82 | for subpixel caching. 83 | 84 | subpix_ctm: Initialised by the routine to the transform that 85 | should be used to render the glyph. 86 | 87 | qe, qf: which subpixel position we quantised to. 88 | 89 | Returns: the size of the glyph. 90 | 91 | Note: This is currently only exposed for use in our app. It 92 | should be considered "at risk" of removal from the API. 93 | */ 94 | float fz_subpixel_adjust(fz_context *ctx, fz_matrix *ctm, fz_matrix *subpix_ctm, unsigned char *qe, unsigned char *qf); 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/mupdf/fitz/glyph.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_GLYPH_H 24 | #define MUPDF_FITZ_GLYPH_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/geometry.h" 29 | #include "mupdf/fitz/store.h" 30 | #include "mupdf/fitz/font.h" 31 | #include "mupdf/fitz/path.h" 32 | 33 | /** 34 | Glyphs represent a run length encoded set of pixels for a 2 35 | dimensional region of a plane. 36 | */ 37 | typedef struct fz_glyph fz_glyph; 38 | 39 | /** 40 | Return the bounding box of the glyph in pixels. 41 | */ 42 | fz_irect fz_glyph_bbox(fz_context *ctx, fz_glyph *glyph); 43 | fz_irect fz_glyph_bbox_no_ctx(fz_glyph *src); 44 | 45 | /** 46 | Return the width of the glyph in pixels. 47 | */ 48 | int fz_glyph_width(fz_context *ctx, fz_glyph *glyph); 49 | 50 | /** 51 | Return the height of the glyph in pixels. 52 | */ 53 | int fz_glyph_height(fz_context *ctx, fz_glyph *glyph); 54 | 55 | /** 56 | Take a reference to a glyph. 57 | 58 | pix: The glyph to increment the reference for. 59 | 60 | Returns pix. 61 | */ 62 | fz_glyph *fz_keep_glyph(fz_context *ctx, fz_glyph *pix); 63 | 64 | /** 65 | Drop a reference and free a glyph. 66 | 67 | Decrement the reference count for the glyph. When no 68 | references remain the glyph will be freed. 69 | */ 70 | void fz_drop_glyph(fz_context *ctx, fz_glyph *pix); 71 | 72 | /** 73 | Look a glyph up from a font, and return the outline of the 74 | glyph using the given transform. 75 | 76 | The caller owns the returned path, and so is responsible for 77 | ensuring that it eventually gets dropped. 78 | */ 79 | fz_path *fz_outline_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/mupdf/fitz/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_HASH_H 24 | #define MUPDF_FITZ_HASH_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/output.h" 29 | 30 | #define FZ_HASH_TABLE_KEY_LENGTH 48 31 | 32 | /** 33 | Generic hash-table with fixed-length keys. 34 | 35 | The keys and values are NOT reference counted by the hash table. 36 | Callers are responsible for taking care the reference counts are 37 | correct. Inserting a duplicate entry will NOT overwrite the old 38 | value, and will return the old value. 39 | 40 | The drop_val callback function is only used to release values 41 | when the hash table is destroyed. 42 | */ 43 | 44 | typedef struct fz_hash_table fz_hash_table; 45 | 46 | /** 47 | Function type called when a hash table entry is dropped. 48 | 49 | Only used when the entire hash table is dropped. 50 | */ 51 | typedef void (fz_hash_table_drop_fn)(fz_context *ctx, void *val); 52 | 53 | /** 54 | Create a new hash table. 55 | 56 | initialsize: The initial size of the hashtable. The hashtable 57 | may grow (double in size) if it starts to get crowded (80% 58 | full). 59 | 60 | keylen: byte length for each key. 61 | 62 | lock: -1 for no lock, otherwise the FZ_LOCK to use to protect 63 | this table. 64 | 65 | drop_val: Function to use to destroy values on table drop. 66 | */ 67 | fz_hash_table *fz_new_hash_table(fz_context *ctx, int initialsize, int keylen, int lock, fz_hash_table_drop_fn *drop_val); 68 | 69 | /** 70 | Destroy the hash table. 71 | 72 | Values are dropped using the drop function. 73 | */ 74 | void fz_drop_hash_table(fz_context *ctx, fz_hash_table *table); 75 | 76 | /** 77 | Search for a matching hash within the table, and return the 78 | associated value. 79 | */ 80 | void *fz_hash_find(fz_context *ctx, fz_hash_table *table, const void *key); 81 | 82 | /** 83 | Insert a new key/value pair into the hash table. 84 | 85 | If an existing entry with the same key is found, no change is 86 | made to the hash table, and a pointer to the existing value is 87 | returned. 88 | 89 | If no existing entry with the same key is found, ownership of 90 | val passes in, key is copied, and NULL is returned. 91 | */ 92 | void *fz_hash_insert(fz_context *ctx, fz_hash_table *table, const void *key, void *val); 93 | 94 | /** 95 | Remove the entry for a given key. 96 | 97 | The value is NOT freed, so the caller is expected to take care 98 | of this. 99 | */ 100 | void fz_hash_remove(fz_context *ctx, fz_hash_table *table, const void *key); 101 | 102 | /** 103 | Callback function called on each key/value pair in the hash 104 | table, when fz_hash_for_each is run. 105 | */ 106 | typedef void (fz_hash_table_for_each_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val); 107 | 108 | /** 109 | Iterate over the entries in a hash table. 110 | */ 111 | void fz_hash_for_each(fz_context *ctx, fz_hash_table *table, void *state, fz_hash_table_for_each_fn *callback); 112 | 113 | /** 114 | Callback function called on each key/value pair in the hash 115 | table, when fz_hash_filter is run to remove entries where the 116 | callback returns true. 117 | */ 118 | typedef int (fz_hash_table_filter_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val); 119 | 120 | /** 121 | Iterate over the entries in a hash table, removing all the ones where callback returns true. 122 | Does NOT free the value of the entry, so the caller is expected to take care of this. 123 | */ 124 | void fz_hash_filter(fz_context *ctx, fz_hash_table *table, void *state, fz_hash_table_filter_fn *callback); 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /include/mupdf/fitz/heap-imp.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | /* This file has preprocessor magic in it to instantiate both 24 | * protoypes and implementations for heap sorting structures 25 | * of various different types. Effectively, it's templating for 26 | * C. 27 | * 28 | * If you are including this file directly without intending to 29 | * be instantiating a new set of heap sort functions, you are 30 | * doing the wrong thing. 31 | */ 32 | 33 | #ifndef MUPDF_FITZ_HEAP_I_KNOW_WHAT_IM_DOING 34 | #error Do not include heap-imp.h unless you know what youre doing 35 | #endif 36 | 37 | #define HEAP_XCAT(A,B) A##B 38 | #define HEAP_CAT(A,B) HEAP_XCAT(A,B) 39 | 40 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 41 | typedef struct 42 | { 43 | int max; 44 | int len; 45 | HEAP_CONTAINER_TYPE *heap; 46 | } HEAP_TYPE_NAME; 47 | #endif 48 | 49 | void HEAP_CAT(HEAP_TYPE_NAME,_insert)(fz_context *ctx, HEAP_TYPE_NAME *heap, HEAP_CONTAINER_TYPE v 50 | #ifndef HEAP_CMP 51 | , int (*HEAP_CMP)(HEAP_CONTAINER_TYPE *a, HEAP_CONTAINER_TYPE *b) 52 | #endif 53 | ) 54 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 55 | ; 56 | #else 57 | { 58 | int i; 59 | HEAP_CONTAINER_TYPE *h; 60 | 61 | if (heap->max == heap->len) 62 | { 63 | int m = heap->max * 2; 64 | 65 | if (m == 0) 66 | m = 32; 67 | 68 | heap->heap = (HEAP_CONTAINER_TYPE *)fz_realloc(ctx, heap->heap, sizeof(*heap->heap) * m); 69 | heap->max = m; 70 | } 71 | h = heap->heap; 72 | 73 | /* Insert it into the heap. Consider inserting at position i, and 74 | * then 'heapify' back. We can delay the actual insertion to the 75 | * end of the process. */ 76 | i = heap->len++; 77 | while (i != 0) 78 | { 79 | int parent_idx = (i-1)/2; 80 | HEAP_CONTAINER_TYPE *parent_val = &h[parent_idx]; 81 | if (HEAP_CMP(parent_val, &v) > 0) 82 | break; 83 | h[i] = h[parent_idx]; 84 | i = parent_idx; 85 | } 86 | h[i] = v; 87 | } 88 | #endif 89 | 90 | void HEAP_CAT(HEAP_TYPE_NAME,_sort)(fz_context *ctx, HEAP_TYPE_NAME *heap 91 | #ifndef HEAP_CMP 92 | , int (*HEAP_CMP)(HEAP_CONTAINER_TYPE *a, HEAP_CONTAINER_TYPE *b) 93 | #endif 94 | ) 95 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 96 | ; 97 | #else 98 | { 99 | int j; 100 | HEAP_CONTAINER_TYPE *h = heap->heap; 101 | 102 | /* elements j to len are always sorted. 0 to j are always a valid heap. Gradually move j to 0. */ 103 | for (j = heap->len-1; j > 0; j--) 104 | { 105 | int k; 106 | HEAP_CONTAINER_TYPE val; 107 | 108 | /* Swap max element with j. Invariant valid for next value to j. */ 109 | val = h[j]; 110 | h[j] = h[0]; 111 | /* Now reform the heap. 0 to k is a valid heap. */ 112 | k = 0; 113 | while (1) 114 | { 115 | int kid = k*2+1; 116 | if (kid >= j) 117 | break; 118 | if (kid+1 < j && (HEAP_CMP(&h[kid+1], &h[kid])) > 0) 119 | kid++; 120 | if ((HEAP_CMP(&val, &h[kid])) > 0) 121 | break; 122 | h[k] = h[kid]; 123 | k = kid; 124 | } 125 | h[k] = val; 126 | } 127 | } 128 | #endif 129 | 130 | void HEAP_CAT(HEAP_TYPE_NAME,_uniq)(fz_context *ctx, HEAP_TYPE_NAME *heap 131 | #ifndef HEAP_CMP 132 | , int (*HEAP_CMP)(HEAP_CONTAINER_TYPE *a, HEAP_CONTAINER_TYPE *b) 133 | #endif 134 | ) 135 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 136 | ; 137 | #else 138 | { 139 | int n = heap->len; 140 | int i, j = 0; 141 | HEAP_CONTAINER_TYPE *h = heap->heap; 142 | 143 | if (n == 0) 144 | return; 145 | 146 | j = 0; 147 | for (i = 1; i < n; i++) 148 | { 149 | if (HEAP_CMP(&h[j], &h[i]) == 0) 150 | continue; 151 | j++; 152 | if (i != j) 153 | h[j] = h[i]; 154 | } 155 | heap->len = j+1; 156 | } 157 | #endif 158 | 159 | #undef HEAP_CONTAINER_TYPE 160 | #undef HEAP_TYPE_NAME 161 | #undef HEAP_CMP 162 | #undef HEAP_XCAT 163 | #undef HEAP_CAT 164 | -------------------------------------------------------------------------------- /include/mupdf/fitz/heap.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | /* This file has preprocessor magic in it to instantiate both 24 | * protoypes and implementations for heap sorting structures 25 | * of various different types. Effectively, it's templating for 26 | * C. 27 | * 28 | * If you are including this file directly without intending to 29 | * be instantiating a new set of heap sort functions, you are 30 | * doing the wrong thing. 31 | */ 32 | 33 | /* This header file declares some useful heap functions. (Heap 34 | * as in heap sort, not as in memory heap). It uses some 35 | * clever (read "hacky") multiple inclusion techniques to allow 36 | * us to generate multiple different versions of this code. 37 | * This is kinda like 'templating' in C++, but without language 38 | * support. 39 | */ 40 | 41 | /* For every instance of this code, we end up a heap structure: 42 | * 43 | * typedef struct 44 | * { 45 | * int max; 46 | * int len; 47 | * *heap; 48 | * } fz__heap; 49 | * 50 | * This can be created and initialised on the stack in user code using: 51 | * 52 | * fz__heap heap = { 0 }; 53 | * 54 | * and some functions. 55 | * 56 | * When is a simple int (or float or similar), the ordering required is 57 | * obvious, and so the functions are simple (Form 1): 58 | * 59 | * First some to insert elements into the heap: 60 | * 61 | * void fz__heap_insert(fz_context *ctx, fz__heap *heap, v); 62 | * 63 | * Once all the elements have been inserted, the heap can be sorted: 64 | * 65 | * void fz__heap_sort(fz_context *ctx, fz__heap *heap); 66 | * 67 | * Once sorted, repeated elements can be removed: 68 | * 69 | * void fz__heap_uniq(fz_context *ctx, fz__heap *heap); 70 | * 71 | * 72 | * For more complex TYPEs (such as pointers) the ordering may not be implicit within the , 73 | * but rather depends upon the data found by dereferencing those pointers. For such types, 74 | * the functions are modified with a function, of the form used by qsort etc: 75 | * 76 | * int (x, y) that returns 0 for x == y, +ve for x > y, and -ve for x < y. 77 | * 78 | * The functions are modified thus (Form 2): 79 | * 80 | * void fz__heap_insert(fz_context *ctx, fz__heap *heap, v, t); 81 | * void fz__heap_sort(fz_context *ctx, fz__heap *heap, t); 82 | * void fz__heap_uniq(fz_context *ctx, fz__heap *heap, t); 83 | * 84 | * Currently, we define: 85 | * 86 | * fz_int_heap Operates on 'int' values. Form 1. 87 | * fz_ptr_heap Operates on 'void *' values. Form 2. 88 | * fz_int2_heap Operates on 'typedef struct { int a; int b} fz_int2' values, 89 | * with the sort/uniq being done based on 'a' alone. Form 1. 90 | * fz_intptr_heap Operates on 'typedef struct { int a; void *b} fz_intptr' values, 91 | * with the sort/uniq being done based on 'a' alone. Form 1. 92 | */ 93 | 94 | /* Everything after this point is preprocessor magic. Ignore it, and just read the above 95 | * unless you are wanting to instantiate a new set of functions. */ 96 | 97 | #ifndef MUPDF_FITZ_HEAP_H 98 | 99 | #define MUPDF_FITZ_HEAP_H 100 | 101 | #define MUPDF_FITZ_HEAP_I_KNOW_WHAT_IM_DOING 102 | 103 | /* Instantiate fz_int_heap */ 104 | #define HEAP_TYPE_NAME fz_int_heap 105 | #define HEAP_CONTAINER_TYPE int 106 | #define HEAP_CMP(a,b) ((*a) - (*b)) 107 | #include "mupdf/fitz/heap-imp.h" 108 | 109 | /* Instantiate fz_ptr_heap */ 110 | #define HEAP_TYPE_NAME fz_ptr_heap 111 | #define HEAP_CONTAINER_TYPE void * 112 | #include "mupdf/fitz/heap-imp.h" 113 | 114 | /* Instantiate fz_int2_heap */ 115 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 116 | typedef struct 117 | { 118 | int a; 119 | int b; 120 | } fz_int2; 121 | #endif 122 | #define HEAP_TYPE_NAME fz_int2_heap 123 | #define HEAP_CMP(A,B) (((A)->a) - ((B)->a)) 124 | #define HEAP_CONTAINER_TYPE fz_int2 125 | #include "mupdf/fitz/heap-imp.h" 126 | 127 | /* Instantiate fz_intptr_heap */ 128 | #ifndef MUPDF_FITZ_HEAP_IMPLEMENT 129 | typedef struct 130 | { 131 | int a; 132 | int b; 133 | } fz_intptr; 134 | #endif 135 | #define HEAP_TYPE_NAME fz_intptr_heap 136 | #define HEAP_CONTAINER_TYPE fz_intptr 137 | #define HEAP_CMP(A,B) (((A)->a) - ((B)->a)) 138 | #include "mupdf/fitz/heap-imp.h" 139 | 140 | #endif /* MUPDF_FITZ_HEAP_H */ 141 | -------------------------------------------------------------------------------- /include/mupdf/fitz/link.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_LINK_H 24 | #define MUPDF_FITZ_LINK_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/geometry.h" 29 | #include "mupdf/fitz/types.h" 30 | 31 | typedef struct fz_link fz_link; 32 | typedef void (fz_link_set_rect_fn)(fz_context *ctx, fz_link *link, fz_rect rect); 33 | typedef void (fz_link_set_uri_fn)(fz_context *ctx, fz_link *link, const char *uri); 34 | typedef void (fz_link_drop_link_fn)(fz_context *ctx, fz_link *link); 35 | 36 | /** 37 | fz_link is a list of interactive links on a page. 38 | 39 | There is no relation between the order of the links in the 40 | list and the order they appear on the page. The list of links 41 | for a given page can be obtained from fz_load_links. 42 | 43 | A link is reference counted. Dropping a reference to a link is 44 | done by calling fz_drop_link. 45 | 46 | rect: The hot zone. The area that can be clicked in 47 | untransformed coordinates. 48 | 49 | uri: Link destinations come in two forms: internal and external. 50 | Internal links refer to other pages in the same document. 51 | External links are URLs to other documents. 52 | 53 | next: A pointer to the next link on the same page. 54 | */ 55 | typedef struct fz_link 56 | { 57 | int refs; 58 | struct fz_link *next; 59 | fz_rect rect; 60 | char *uri; 61 | fz_link_set_rect_fn *set_rect_fn; 62 | fz_link_set_uri_fn *set_uri_fn; 63 | fz_link_drop_link_fn *drop; 64 | } fz_link; 65 | 66 | typedef enum 67 | { 68 | FZ_LINK_DEST_FIT, 69 | FZ_LINK_DEST_FIT_B, 70 | FZ_LINK_DEST_FIT_H, 71 | FZ_LINK_DEST_FIT_BH, 72 | FZ_LINK_DEST_FIT_V, 73 | FZ_LINK_DEST_FIT_BV, 74 | FZ_LINK_DEST_FIT_R, 75 | FZ_LINK_DEST_XYZ 76 | } fz_link_dest_type; 77 | 78 | typedef struct 79 | { 80 | fz_location loc; 81 | fz_link_dest_type type; 82 | float x, y, w, h, zoom; 83 | } fz_link_dest; 84 | 85 | fz_link_dest fz_make_link_dest_none(void); 86 | fz_link_dest fz_make_link_dest_xyz(int chapter, int page, float x, float y, float z); 87 | 88 | /** 89 | Create a new link record. 90 | 91 | next is set to NULL with the expectation that the caller will 92 | handle the linked list setup. Internal function. 93 | 94 | Different document types will be implemented by deriving from 95 | fz_link. This macro allocates such derived structures, and 96 | initialises the base sections. 97 | */ 98 | fz_link *fz_new_link_of_size(fz_context *ctx, int size, fz_rect rect, const char *uri); 99 | #define fz_new_derived_link(CTX,TYPE,RECT,URI) \ 100 | ((TYPE *)Memento_label(fz_new_link_of_size(CTX,sizeof(TYPE),RECT,URI),#TYPE)) 101 | 102 | /** 103 | Increment the reference count for a link. The same pointer is 104 | returned. 105 | 106 | Never throws exceptions. 107 | */ 108 | fz_link *fz_keep_link(fz_context *ctx, fz_link *link); 109 | 110 | /** 111 | Decrement the reference count for a link. When the reference 112 | count reaches zero, the link is destroyed. 113 | 114 | When a link is freed, the reference for any linked link (next) 115 | is dropped too, thus an entire linked list of fz_link's can be 116 | freed by just dropping the head. 117 | */ 118 | void fz_drop_link(fz_context *ctx, fz_link *link); 119 | 120 | /** 121 | Query whether a link is external to a document (determined by 122 | uri containing a ':', intended to match with '://' which 123 | separates the scheme from the scheme specific parts in URIs). 124 | */ 125 | int fz_is_external_link(fz_context *ctx, const char *uri); 126 | 127 | void fz_set_link_rect(fz_context *ctx, fz_link *link, fz_rect rect); 128 | void fz_set_link_uri(fz_context *ctx, fz_link *link, const char *uri); 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /include/mupdf/fitz/log.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_LOG_H 24 | #define MUPDF_FITZ_LOG_H 25 | 26 | #include "mupdf/fitz/context.h" 27 | #include "mupdf/fitz/output.h" 28 | 29 | /** 30 | The functions in this file offer simple logging abilities. 31 | 32 | The default logfile is "fitz_log.txt". This can overridden by 33 | defining an environment variable "FZ_LOG_FILE", or module 34 | specific environment variables "FZ_LOG_FILE_" (e.g. 35 | "FZ_LOG_FILE_STORE"). 36 | 37 | Enable the following define(s) to enable built in debug logging 38 | from within the appropriate module(s). 39 | */ 40 | 41 | /* #define ENABLE_STORE_LOGGING */ 42 | 43 | 44 | /** 45 | Output a line to the log. 46 | */ 47 | void fz_log(fz_context *ctx, const char *fmt, ...); 48 | 49 | /** 50 | Output a line to the log for a given module. 51 | */ 52 | void fz_log_module(fz_context *ctx, const char *module, const char *fmt, ...); 53 | 54 | /** 55 | Internal function to actually do the opening of the logfile. 56 | 57 | Caller should close/drop the output when finished with it. 58 | */ 59 | fz_output *fz_new_log_for_module(fz_context *ctx, const char *module); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/mupdf/fitz/outline.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_OUTLINE_H 24 | #define MUPDF_FITZ_OUTLINE_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/types.h" 28 | #include "mupdf/fitz/context.h" 29 | #include "mupdf/fitz/link.h" 30 | #include "mupdf/fitz/output.h" 31 | 32 | /* Outline */ 33 | 34 | typedef struct { 35 | char *title; 36 | char *uri; 37 | int is_open; 38 | } fz_outline_item; 39 | 40 | typedef struct fz_outline_iterator fz_outline_iterator; 41 | 42 | /** 43 | Call to get the current outline item. 44 | 45 | Can return NULL. The item is only valid until the next call. 46 | */ 47 | fz_outline_item *fz_outline_iterator_item(fz_context *ctx, fz_outline_iterator *iter); 48 | 49 | /** 50 | Calls to move the iterator position. 51 | 52 | A negative return value means we could not move as requested. Otherwise: 53 | 0 = the final position has a valid item. 54 | 1 = not a valid item, but we can insert an item here. 55 | */ 56 | int fz_outline_iterator_next(fz_context *ctx, fz_outline_iterator *iter); 57 | int fz_outline_iterator_prev(fz_context *ctx, fz_outline_iterator *iter); 58 | int fz_outline_iterator_up(fz_context *ctx, fz_outline_iterator *iter); 59 | int fz_outline_iterator_down(fz_context *ctx, fz_outline_iterator *iter); 60 | 61 | /** 62 | Call to insert a new item BEFORE the current point. 63 | 64 | Ownership of pointers are retained by the caller. The item data will be copied. 65 | 66 | After an insert, we do not change where we are pointing. 67 | The return code is the same as for next, it indicates the current iterator position. 68 | */ 69 | int fz_outline_iterator_insert(fz_context *ctx, fz_outline_iterator *iter, fz_outline_item *item); 70 | 71 | /** 72 | Delete the current item. 73 | 74 | This implicitly moves us to the 'next' item, and the return code is as for fz_outline_iterator_next. 75 | */ 76 | int fz_outline_iterator_delete(fz_context *ctx, fz_outline_iterator *iter); 77 | 78 | /** 79 | Update the current item properties according to the given item. 80 | */ 81 | void fz_outline_iterator_update(fz_context *ctx, fz_outline_iterator *iter, fz_outline_item *item); 82 | 83 | /** 84 | Drop the current iterator. 85 | */ 86 | void fz_drop_outline_iterator(fz_context *ctx, fz_outline_iterator *iter); 87 | 88 | 89 | /** Structure based API */ 90 | 91 | /** 92 | fz_outline is a tree of the outline of a document (also known 93 | as table of contents). 94 | 95 | title: Title of outline item using UTF-8 encoding. May be NULL 96 | if the outline item has no text string. 97 | 98 | uri: Destination in the document to be displayed when this 99 | outline item is activated. May be an internal or external 100 | link, or NULL if the outline item does not have a destination. 101 | 102 | page: The page number of an internal link, or -1 for external 103 | links or links with no destination. 104 | 105 | next: The next outline item at the same level as this outline 106 | item. May be NULL if no more outline items exist at this level. 107 | 108 | down: The outline items immediate children in the hierarchy. 109 | May be NULL if no children exist. 110 | */ 111 | typedef struct fz_outline 112 | { 113 | int refs; 114 | char *title; 115 | char *uri; 116 | fz_location page; 117 | float x, y; 118 | struct fz_outline *next; 119 | struct fz_outline *down; 120 | int is_open; 121 | } fz_outline; 122 | 123 | /** 124 | Create a new outline entry with zeroed fields for the caller 125 | to fill in. 126 | */ 127 | fz_outline *fz_new_outline(fz_context *ctx); 128 | 129 | /** 130 | Increment the reference count. Returns the same pointer. 131 | 132 | Never throws exceptions. 133 | */ 134 | fz_outline *fz_keep_outline(fz_context *ctx, fz_outline *outline); 135 | 136 | /** 137 | Decrements the reference count. When the reference point 138 | reaches zero, the outline is freed. 139 | 140 | When freed, it will drop linked outline entries (next and down) 141 | too, thus a whole outline structure can be dropped by dropping 142 | the top entry. 143 | 144 | Never throws exceptions. 145 | */ 146 | void fz_drop_outline(fz_context *ctx, fz_outline *outline); 147 | 148 | /** 149 | Routine to implement the old Structure based API from an iterator. 150 | */ 151 | fz_outline * 152 | fz_load_outline_from_iterator(fz_context *ctx, fz_outline_iterator *iter); 153 | 154 | 155 | /** 156 | Implementation details. 157 | Of use to people coding new document handlers. 158 | */ 159 | 160 | /** 161 | Function type for getting the current item. 162 | 163 | Can return NULL. The item is only valid until the next call. 164 | */ 165 | typedef fz_outline_item *(fz_outline_iterator_item_fn)(fz_context *ctx, fz_outline_iterator *iter); 166 | 167 | /** 168 | Function types for moving the iterator position. 169 | 170 | A negative return value means we could not move as requested. Otherwise: 171 | 0 = the final position has a valid item. 172 | 1 = not a valid item, but we can insert an item here. 173 | */ 174 | typedef int (fz_outline_iterator_next_fn)(fz_context *ctx, fz_outline_iterator *iter); 175 | typedef int (fz_outline_iterator_prev_fn)(fz_context *ctx, fz_outline_iterator *iter); 176 | typedef int (fz_outline_iterator_up_fn)(fz_context *ctx, fz_outline_iterator *iter); 177 | typedef int (fz_outline_iterator_down_fn)(fz_context *ctx, fz_outline_iterator *iter); 178 | 179 | /** 180 | Function type for inserting a new item BEFORE the current point. 181 | 182 | Ownership of pointers are retained by the caller. The item data will be copied. 183 | 184 | After an insert, we implicitly do a next, so that a successive insert operation 185 | would insert after the item inserted here. The return code is therefore as for next. 186 | */ 187 | typedef int (fz_outline_iterator_insert_fn)(fz_context *ctx, fz_outline_iterator *iter, fz_outline_item *item); 188 | 189 | /** 190 | Function type for deleting the current item. 191 | 192 | This implicitly moves us to the 'next' item, and the return code is as for fz_outline_iterator_next. 193 | */ 194 | typedef int (fz_outline_iterator_delete_fn)(fz_context *ctx, fz_outline_iterator *iter); 195 | 196 | /** 197 | Function type for updating the current item properties according to the given item. 198 | */ 199 | typedef void (fz_outline_iterator_update_fn)(fz_context *ctx, fz_outline_iterator *iter, fz_outline_item *item); 200 | 201 | /** 202 | Function type for dropping the current iterator. 203 | */ 204 | typedef void (fz_outline_iterator_drop_fn)(fz_context *ctx, fz_outline_iterator *iter); 205 | 206 | #define fz_new_derived_outline_iter(CTX, TYPE, DOC)\ 207 | ((TYPE *)Memento_label(fz_new_outline_iterator_of_size(ctx,sizeof(TYPE),DOC),#TYPE)) 208 | 209 | fz_outline_iterator *fz_new_outline_iterator_of_size(fz_context *ctx, size_t size, fz_document *doc); 210 | 211 | fz_outline_iterator *fz_outline_iterator_from_outline(fz_context *ctx, fz_outline *outline); 212 | 213 | struct fz_outline_iterator { 214 | /* Functions */ 215 | fz_outline_iterator_drop_fn *drop; 216 | fz_outline_iterator_item_fn *item; 217 | fz_outline_iterator_next_fn *next; 218 | fz_outline_iterator_prev_fn *prev; 219 | fz_outline_iterator_up_fn *up; 220 | fz_outline_iterator_down_fn *down; 221 | fz_outline_iterator_insert_fn *insert; 222 | fz_outline_iterator_update_fn *update; 223 | fz_outline_iterator_delete_fn *del; 224 | /* Common state */ 225 | fz_document *doc; 226 | }; 227 | 228 | #endif 229 | -------------------------------------------------------------------------------- /include/mupdf/fitz/output-svg.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_OUTPUT_SVG_H 24 | #define MUPDF_FITZ_OUTPUT_SVG_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/device.h" 29 | #include "mupdf/fitz/output.h" 30 | 31 | enum { 32 | FZ_SVG_TEXT_AS_PATH = 0, 33 | FZ_SVG_TEXT_AS_TEXT = 1, 34 | }; 35 | 36 | /** 37 | Create a device that outputs (single page) SVG files to 38 | the given output stream. 39 | 40 | Equivalent to fz_new_svg_device_with_id passing id = NULL. 41 | */ 42 | fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, float page_height, int text_format, int reuse_images); 43 | 44 | /** 45 | Create a device that outputs (single page) SVG files to 46 | the given output stream. 47 | 48 | output: The output stream to send the constructed SVG page to. 49 | 50 | page_width, page_height: The page dimensions to use (in points). 51 | 52 | text_format: How to emit text. One of the following values: 53 | FZ_SVG_TEXT_AS_TEXT: As elements with possible 54 | layout errors and mismatching fonts. 55 | FZ_SVG_TEXT_AS_PATH: As elements with exact 56 | visual appearance. 57 | 58 | reuse_images: Share image resources using definitions. 59 | 60 | id: ID parameter to keep generated IDs unique across SVG files. 61 | */ 62 | fz_device *fz_new_svg_device_with_id(fz_context *ctx, fz_output *out, float page_width, float page_height, int text_format, int reuse_images, int *id); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/mupdf/fitz/pool.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_POOL_H 24 | #define MUPDF_FITZ_POOL_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | 29 | /** 30 | Simple pool allocators. 31 | 32 | Allocate from the pool, which can then be freed at once. 33 | */ 34 | typedef struct fz_pool fz_pool; 35 | 36 | /** 37 | Create a new pool to allocate from. 38 | */ 39 | fz_pool *fz_new_pool(fz_context *ctx); 40 | 41 | /** 42 | Allocate a block of size bytes from the pool. 43 | */ 44 | void *fz_pool_alloc(fz_context *ctx, fz_pool *pool, size_t size); 45 | 46 | /** 47 | strdup equivalent allocating from the pool. 48 | */ 49 | char *fz_pool_strdup(fz_context *ctx, fz_pool *pool, const char *s); 50 | 51 | /** 52 | The current size of the pool. 53 | 54 | The number of bytes of storage currently allocated to the pool. 55 | This is the total of the storage used for the blocks making 56 | up the pool, rather then total of the allocated blocks so far, 57 | so it will increase in 'lumps'. 58 | from the pool, then the pool size may still be X 59 | */ 60 | size_t fz_pool_size(fz_context *ctx, fz_pool *pool); 61 | 62 | /** 63 | Drop a pool, freeing and invalidating all storage returned from 64 | the pool. 65 | */ 66 | void fz_drop_pool(fz_context *ctx, fz_pool *pool); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/mupdf/fitz/separation.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_SEPARATION_H 24 | #define MUPDF_FITZ_SEPARATION_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/color.h" 29 | 30 | /** 31 | A fz_separation structure holds details of a set of separations 32 | (such as might be used on within a page of the document). 33 | 34 | The app might control the separations by enabling/disabling them, 35 | and subsequent renders would take this into account. 36 | */ 37 | 38 | enum 39 | { 40 | FZ_MAX_SEPARATIONS = 64 41 | }; 42 | 43 | typedef struct fz_separations fz_separations; 44 | 45 | typedef enum 46 | { 47 | /* "Composite" separations are rendered using process 48 | * colors using the equivalent colors */ 49 | FZ_SEPARATION_COMPOSITE = 0, 50 | /* Spot colors are rendered into their own spot plane. */ 51 | FZ_SEPARATION_SPOT = 1, 52 | /* Disabled colors are not rendered at all in the final 53 | * output. */ 54 | FZ_SEPARATION_DISABLED = 2 55 | } fz_separation_behavior; 56 | 57 | /** 58 | Create a new separations structure (initially empty) 59 | */ 60 | fz_separations *fz_new_separations(fz_context *ctx, int controllable); 61 | 62 | /** 63 | Increment the reference count for a separations structure. 64 | Returns the same pointer. 65 | 66 | Never throws exceptions. 67 | */ 68 | fz_separations *fz_keep_separations(fz_context *ctx, fz_separations *sep); 69 | 70 | /** 71 | Decrement the reference count for a separations structure. 72 | When the reference count hits zero, the separations structure 73 | is freed. 74 | 75 | Never throws exceptions. 76 | */ 77 | void fz_drop_separations(fz_context *ctx, fz_separations *sep); 78 | 79 | /** 80 | Add a separation (null terminated name, colorspace) 81 | */ 82 | void fz_add_separation(fz_context *ctx, fz_separations *sep, const char *name, fz_colorspace *cs, int cs_channel); 83 | 84 | /** 85 | Add a separation with equivalents (null terminated name, 86 | colorspace) 87 | 88 | (old, deprecated) 89 | */ 90 | void fz_add_separation_equivalents(fz_context *ctx, fz_separations *sep, uint32_t rgba, uint32_t cmyk, const char *name); 91 | 92 | /** 93 | Control the rendering of a given separation. 94 | */ 95 | void fz_set_separation_behavior(fz_context *ctx, fz_separations *sep, int separation, fz_separation_behavior behavior); 96 | 97 | /** 98 | Test for the current behavior of a separation. 99 | */ 100 | fz_separation_behavior fz_separation_current_behavior(fz_context *ctx, const fz_separations *sep, int separation); 101 | 102 | const char *fz_separation_name(fz_context *ctx, const fz_separations *sep, int separation); 103 | int fz_count_separations(fz_context *ctx, const fz_separations *sep); 104 | 105 | /** 106 | Return the number of active separations. 107 | */ 108 | int fz_count_active_separations(fz_context *ctx, const fz_separations *seps); 109 | 110 | /** 111 | Compare 2 separations structures (or NULLs). 112 | 113 | Return 0 if identical, non-zero if not identical. 114 | */ 115 | int fz_compare_separations(fz_context *ctx, const fz_separations *sep1, const fz_separations *sep2); 116 | 117 | 118 | /** 119 | Return a separations object with all the spots in the input 120 | separations object that are set to composite, reset to be 121 | enabled. If there ARE no spots in the object, this returns 122 | NULL. If the object already has all its spots enabled, then 123 | just returns another handle on the same object. 124 | */ 125 | fz_separations *fz_clone_separations_for_overprint(fz_context *ctx, fz_separations *seps); 126 | 127 | /** 128 | Convert a color given in terms of one colorspace, 129 | to a color in terms of another colorspace/separations. 130 | */ 131 | void fz_convert_separation_colors(fz_context *ctx, fz_colorspace *src_cs, const float *src_color, fz_separations *dst_seps, fz_colorspace *dst_cs, float *dst_color, fz_color_params color_params); 132 | 133 | /** 134 | Get the equivalent separation color in a given colorspace. 135 | */ 136 | void fz_separation_equivalent(fz_context *ctx, const fz_separations *seps, int idx, fz_colorspace *dst_cs, float *dst_color, fz_colorspace *prf, fz_color_params color_params); 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /include/mupdf/fitz/shade.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_SHADE_H 24 | #define MUPDF_FITZ_SHADE_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/geometry.h" 29 | #include "mupdf/fitz/store.h" 30 | #include "mupdf/fitz/pixmap.h" 31 | #include "mupdf/fitz/compressed-buffer.h" 32 | 33 | /** 34 | * The shading code uses gouraud shaded triangle meshes. 35 | */ 36 | 37 | enum 38 | { 39 | FZ_FUNCTION_BASED = 1, 40 | FZ_LINEAR = 2, 41 | FZ_RADIAL = 3, 42 | FZ_MESH_TYPE4 = 4, 43 | FZ_MESH_TYPE5 = 5, 44 | FZ_MESH_TYPE6 = 6, 45 | FZ_MESH_TYPE7 = 7 46 | }; 47 | 48 | /** 49 | Structure is public to allow derived classes. Do not 50 | access the members directly. 51 | */ 52 | typedef struct 53 | { 54 | fz_storable storable; 55 | 56 | fz_rect bbox; /* can be fz_infinite_rect */ 57 | fz_colorspace *colorspace; 58 | 59 | fz_matrix matrix; /* matrix from pattern dict */ 60 | int use_background; /* background color for fills but not 'sh' */ 61 | float background[FZ_MAX_COLORS]; 62 | 63 | /* Just to be confusing, PDF Shadings of Type 1 (Function Based 64 | * Shadings), do NOT use function, but all the others do. This 65 | * is because Type 1 shadings take 2 inputs, whereas all the 66 | * others (when used with a function take 1 input. The type 1 67 | * data is in the 'f' field of the union below. */ 68 | /* If function_stride = 0, then function is not used. Otherwise 69 | * function points to 256*function_stride entries. */ 70 | int function_stride; 71 | float *function; 72 | 73 | int type; /* function, linear, radial, mesh */ 74 | union 75 | { 76 | struct 77 | { 78 | int extend[2]; 79 | float coords[2][3]; /* (x,y,r) twice */ 80 | } l_or_r; 81 | struct 82 | { 83 | int vprow; 84 | int bpflag; 85 | int bpcoord; 86 | int bpcomp; 87 | float x0, x1; 88 | float y0, y1; 89 | float c0[FZ_MAX_COLORS]; 90 | float c1[FZ_MAX_COLORS]; 91 | } m; 92 | struct 93 | { 94 | fz_matrix matrix; 95 | int xdivs; 96 | int ydivs; 97 | float domain[2][2]; 98 | float *fn_vals; 99 | } f; 100 | } u; 101 | 102 | fz_compressed_buffer *buffer; 103 | } fz_shade; 104 | 105 | /** 106 | Increment the reference count for the shade structure. The 107 | same pointer is returned. 108 | 109 | Never throws exceptions. 110 | */ 111 | fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade); 112 | 113 | /** 114 | Decrement the reference count for the shade structure. When 115 | the reference count hits zero, the structure is freed. 116 | 117 | Never throws exceptions. 118 | */ 119 | void fz_drop_shade(fz_context *ctx, fz_shade *shade); 120 | 121 | /** 122 | Bound a given shading. 123 | 124 | shade: The shade to bound. 125 | 126 | ctm: The transform to apply to the shade before bounding. 127 | 128 | r: Pointer to storage to put the bounds in. 129 | 130 | Returns r, updated to contain the bounds for the shading. 131 | */ 132 | fz_rect fz_bound_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm); 133 | 134 | typedef struct fz_shade_color_cache fz_shade_color_cache; 135 | 136 | void fz_drop_shade_color_cache(fz_context *ctx, fz_shade_color_cache *cache); 137 | 138 | /** 139 | Render a shade to a given pixmap. 140 | 141 | shade: The shade to paint. 142 | 143 | override_cs: NULL, or colorspace to override the shades 144 | inbuilt colorspace. 145 | 146 | ctm: The transform to apply. 147 | 148 | dest: The pixmap to render into. 149 | 150 | color_params: The color rendering settings 151 | 152 | bbox: Pointer to a bounding box to limit the rendering 153 | of the shade. 154 | 155 | eop: NULL, or pointer to overprint bitmap. 156 | 157 | cache: *cache is used to cache color information. If *cache is NULL it 158 | is set to point to a new fz_shade_color_cache. If cache is NULL it is 159 | ignored. 160 | */ 161 | void fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *override_cs, fz_matrix ctm, fz_pixmap *dest, fz_color_params color_params, fz_irect bbox, const fz_overprint *eop, fz_shade_color_cache **cache); 162 | 163 | /** 164 | * Handy routine for processing mesh based shades 165 | */ 166 | typedef struct 167 | { 168 | fz_point p; 169 | float c[FZ_MAX_COLORS]; 170 | } fz_vertex; 171 | 172 | /** 173 | Callback function type for use with 174 | fz_process_shade. 175 | 176 | arg: Opaque pointer from fz_process_shade caller. 177 | 178 | v: Pointer to a fz_vertex structure to populate. 179 | 180 | c: Pointer to an array of floats used to populate v. 181 | */ 182 | typedef void (fz_shade_prepare_fn)(fz_context *ctx, void *arg, fz_vertex *v, const float *c); 183 | 184 | /** 185 | Callback function type for use with 186 | fz_process_shade. 187 | 188 | arg: Opaque pointer from fz_process_shade caller. 189 | 190 | av, bv, cv: Pointers to a fz_vertex structure describing 191 | the corner locations and colors of a triangle to be 192 | filled. 193 | */ 194 | typedef void (fz_shade_process_fn)(fz_context *ctx, void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv); 195 | 196 | /** 197 | Process a shade, using supplied callback functions. This 198 | decomposes the shading to a mesh (even ones that are not 199 | natively meshes, such as linear or radial shadings), and 200 | processes triangles from those meshes. 201 | 202 | shade: The shade to process. 203 | 204 | ctm: The transform to use 205 | 206 | prepare: Callback function to 'prepare' each vertex. 207 | This function is passed an array of floats, and populates 208 | a fz_vertex structure. 209 | 210 | process: This function is passed 3 pointers to vertex 211 | structures, and actually performs the processing (typically 212 | filling the area between the vertexes). 213 | 214 | process_arg: An opaque argument passed through from caller 215 | to callback functions. 216 | */ 217 | void fz_process_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_rect scissor, 218 | fz_shade_prepare_fn *prepare, 219 | fz_shade_process_fn *process, 220 | void *process_arg); 221 | 222 | 223 | /* Implementation details: subject to change. */ 224 | 225 | /** 226 | Internal function to destroy a 227 | shade. Only exposed for use with the fz_store. 228 | 229 | shade: The reference to destroy. 230 | */ 231 | void fz_drop_shade_imp(fz_context *ctx, fz_storable *shade); 232 | 233 | #endif 234 | -------------------------------------------------------------------------------- /include/mupdf/fitz/story-writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_STORY_WRITER_H 24 | #define MUPDF_FITZ_STORY_WRITER_H 25 | 26 | #include "mupdf/fitz/story.h" 27 | #include "mupdf/fitz/writer.h" 28 | 29 | /* 30 | * A fz_story_element_position plus page number information; used with 31 | * fz_write_story() and fz_write_stabilized_story(). 32 | */ 33 | typedef struct 34 | { 35 | fz_story_element_position element; 36 | int page_num; 37 | } fz_write_story_position; 38 | 39 | /* 40 | * A set of fz_write_story_position items; used with 41 | * fz_write_stabilized_story(). 42 | */ 43 | typedef struct 44 | { 45 | fz_write_story_position *positions; 46 | int num; 47 | } fz_write_story_positions; 48 | 49 | 50 | /* 51 | * Callback type used by fz_write_story() and fz_write_stabilized_story(). 52 | * 53 | * Should set *rect to rect number . If this is on a new page should also 54 | * set *mediabox and return 1, otherwise return 0. 55 | * 56 | * ref: 57 | * As passed to fz_write_story() or fz_write_stabilized_story(). 58 | * num: 59 | * The rect number. Will typically increment by one each time, being reset 60 | * to zero when fz_write_stabilized_story() starts a new iteration. 61 | * filled: 62 | * From earlier internal call to fz_place_story(). 63 | * rect: 64 | * Out param. 65 | * ctm: 66 | * Out param, defaults to fz_identity. 67 | * mediabox: 68 | * Out param, only used if we return 1. 69 | */ 70 | typedef int (fz_write_story_rectfn)(fz_context *ctx, void *ref, int num, fz_rect filled, fz_rect *rect, fz_matrix *ctm, fz_rect *mediabox); 71 | 72 | /* 73 | * Callback used by fz_write_story() to report information about element 74 | * positions. Slightly different from fz_story_position_callback() because 75 | * also includes the page number. 76 | * 77 | * ref: 78 | * As passed to fz_write_story() or fz_write_stabilized_story(). 79 | * position: 80 | * Called via internal call to fz_story_position_callback(). 81 | */ 82 | typedef void (fz_write_story_positionfn)(fz_context *ctx, void *ref, const fz_write_story_position *position); 83 | 84 | /* 85 | * Callback for fz_write_story(), called twice for each page, before (after=0) 86 | * and after (after=1) the story is written. 87 | * 88 | * ref: 89 | * As passed to fz_write_story() or fz_write_stabilized_story(). 90 | * page_num: 91 | * Page number, starting from 1. 92 | * mediabox: 93 | * As returned from fz_write_story_rectfn(). 94 | * dev: 95 | * Created from the fz_writer passed to fz_write_story() or 96 | * fz_write_stabilized_story(). 97 | * after: 98 | * 0 - before writing the story. 99 | * 1 - after writing the story. 100 | */ 101 | typedef void (fz_write_story_pagefn)(fz_context *ctx, void *ref, int page_num, fz_rect mediabox, fz_device *dev, int after); 102 | 103 | /* 104 | * Callback type for fz_write_stabilized_story(). 105 | * 106 | * Should populate the supplied buffer with html content for use with internal 107 | * calls to fz_new_story(). This may include extra content derived from 108 | * information in , for example a table of contents. 109 | * 110 | * ref: 111 | * As passed to fz_write_stabilized_story(). 112 | * positions: 113 | * Information from previous iteration. 114 | * buffer: 115 | * Where to write the new content. Will be initially empty. 116 | */ 117 | typedef void (fz_write_story_contentfn)(fz_context *ctx, void *ref, const fz_write_story_positions *positions, fz_buffer *buffer); 118 | 119 | 120 | /* 121 | * Places and writes a story to a fz_document_writer. Avoids the need 122 | * for calling code to implement a loop that calls fz_place_story() 123 | * and fz_draw_story() etc, at the expense of having to provide a 124 | * fz_write_story_rectfn() callback. 125 | * 126 | * story: 127 | * The story to place and write. 128 | * writer: 129 | * Where to write the story; can be NULL. 130 | * rectfn: 131 | * Should return information about the rect to be used in the next 132 | * internal call to fz_place_story(). 133 | * rectfn_ref: 134 | * Passed to rectfn(). 135 | * positionfn: 136 | * If not NULL, is called via internal calls to fz_story_positions(). 137 | * positionfn_ref: 138 | * Passed to positionfn(). 139 | * pagefn: 140 | * If not NULL, called at start and end of each page (before and after all 141 | * story content has been written to the device). 142 | * pagefn_ref: 143 | * Passed to pagefn(). 144 | */ 145 | void fz_write_story( 146 | fz_context *ctx, 147 | fz_document_writer *writer, 148 | fz_story *story, 149 | fz_write_story_rectfn rectfn, 150 | void *rectfn_ref, 151 | fz_write_story_positionfn positionfn, 152 | void *positionfn_ref, 153 | fz_write_story_pagefn pagefn, 154 | void *pagefn_ref 155 | ); 156 | 157 | 158 | /* 159 | * Does iterative layout of html content to a fz_document_writer. For example 160 | * this allows one to add a table of contents section while ensuring that page 161 | * numbers are patched up until stable. 162 | * 163 | * Repeatedly creates new story from (contentfn(), contentfn_ref, user_css, em) 164 | * and lays it out with internal call to fz_write_story(); uses a NULL writer 165 | * and populates a fz_write_story_positions which is passed to the next call of 166 | * contentfn(). 167 | * 168 | * When the html from contentfn() becomes unchanged, we do a final iteration 169 | * using . 170 | * 171 | * writer: 172 | * Where to write in the final iteration. 173 | * user_css: 174 | * Used in internal calls to fz_new_story(). 175 | * em: 176 | * Used in internal calls to fz_new_story(). 177 | * contentfn: 178 | * Should return html content for use with fz_new_story(), possibly 179 | * including extra content such as a table-of-contents. 180 | * contentfn_ref: 181 | * Passed to contentfn(). 182 | * rectfn: 183 | * Should return information about the rect to be used in the next 184 | * internal call to fz_place_story(). 185 | * rectfn_ref: 186 | * Passed to rectfn(). 187 | * fz_write_story_pagefn: 188 | * If not NULL, called at start and end of each page (before and after all 189 | * story content has been written to the device). 190 | * pagefn_ref: 191 | * Passed to pagefn(). 192 | * dir: 193 | * NULL, or a directory context to load images etc from. 194 | */ 195 | void fz_write_stabilized_story( 196 | fz_context *ctx, 197 | fz_document_writer *writer, 198 | const char *user_css, 199 | float em, 200 | fz_write_story_contentfn contentfn, 201 | void *contentfn_ref, 202 | fz_write_story_rectfn rectfn, 203 | void *rectfn_ref, 204 | fz_write_story_pagefn pagefn, 205 | void *pagefn_ref, 206 | fz_archive *dir 207 | ); 208 | 209 | #endif 210 | -------------------------------------------------------------------------------- /include/mupdf/fitz/story.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_STORY_H 24 | #define MUPDF_FITZ_STORY_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/buffer.h" 29 | #include "mupdf/fitz/device.h" 30 | #include "mupdf/fitz/xml.h" 31 | #include "mupdf/fitz/archive.h" 32 | 33 | /* 34 | This header file provides an API for laying out and placing styled 35 | text on a page, or pages. 36 | 37 | First a text story is created from some styled HTML. 38 | 39 | Next, this story can be laid out into a given rectangle (possibly 40 | retrying several times with updated rectangles as required). 41 | 42 | Next, the laid out story can be drawn to a given device. 43 | 44 | In the case where the text story cannot be fitted into the given 45 | areas all at once, these two steps can be repeated multiple 46 | times until the text story is completely consumed. 47 | 48 | Finally, the text story can be dropped in the usual fashion. 49 | */ 50 | 51 | 52 | typedef struct fz_story fz_story; 53 | 54 | /* 55 | Create a text story using styled html. 56 | 57 | Passing a NULL buffer will be treated as an empty document. 58 | Passing a NULL user_css will be treated as an empty CSS string. 59 | A non-NULL dir will allow images etc to be loaded. The 60 | story keeps its own reference, so the caller can drop its 61 | reference after this call. 62 | */ 63 | fz_story *fz_new_story(fz_context *ctx, fz_buffer *buf, const char *user_css, float em, fz_archive *dir); 64 | 65 | /* 66 | Retrieve the warnings given from parsing this story. 67 | 68 | If there are warnings, this will be returned as a NULL terminated 69 | C string. If there are no warnings, this will return NULL. 70 | 71 | These warnings will not be complete until AFTER any DOM manipulations 72 | have been completed. 73 | 74 | This function does not need to be called, but once it has been 75 | the DOM is no longer accessible, and any fz_xml pointer 76 | retrieved from fz_story_docment is no longer valid. 77 | */ 78 | const char *fz_story_warnings(fz_context *ctx, fz_story *story); 79 | 80 | /* 81 | Equivalent to fz_place_story_flags with flags being 0. 82 | */ 83 | int fz_place_story(fz_context *ctx, fz_story *story, fz_rect where, fz_rect *filled); 84 | 85 | /* 86 | Place (or continue placing) a story into the supplied rectangle 87 | 'where', updating 'filled' with the actual area that was used. 88 | Returns zero (FZ_PLACE_STORY_RETURN_ALL_FITTED) if all the 89 | content fitted, non-zero if there is more to fit. 90 | 91 | If the FZ_PLACE_STORY_FLAG_NO_OVERFLOW flag is set, then a 92 | return code of FZ_PLACE_STORY_RETURN_OVERFLOW_WIDTH will be 93 | returned when the next item (word) to be placed would not fit 94 | in a rectangle of that given width. 95 | 96 | Note, that filled may not be returned as a strict subset of 97 | where, due to padding/margins at the bottom of pages, and 98 | non-wrapping content extending to the right. 99 | 100 | Subsequent calls will attempt to place the same section of story 101 | again and again, until the placed story is drawn using fz_draw_story, 102 | whereupon subsequent calls to fz_place_story will attempt to place 103 | the unused remainder of the story. 104 | 105 | After this function is called, the DOM is no longer accessible, 106 | and any fz_xml pointer retrieved from fz_story_document is no 107 | longer valid. 108 | 109 | flags: Additional flags controlling layout. Pass 0 if none 110 | required. 111 | */ 112 | int fz_place_story_flags(fz_context *ctx, fz_story *story, fz_rect where, fz_rect *filled, int flags); 113 | 114 | enum 115 | { 116 | /* Avoid the usual HTML behaviour of overflowing the box horizontally 117 | * in some circumstances. We now abort the place in such cases and 118 | * return with */ 119 | FZ_PLACE_STORY_FLAG_NO_OVERFLOW = 1, 120 | 121 | /* Specific return codes from fz_place_story_flags. Also 122 | * "non-zero" for 'more to fit'. */ 123 | FZ_PLACE_STORY_RETURN_ALL_FITTED = 0, 124 | FZ_PLACE_STORY_RETURN_OVERFLOW_WIDTH = 2 125 | }; 126 | 127 | /* 128 | Draw the placed story to the given device. 129 | 130 | This moves the point at which subsequent calls to fz_place_story 131 | will restart placing to the end of what has just been output. 132 | */ 133 | void fz_draw_story(fz_context *ctx, fz_story *story, fz_device *dev, fz_matrix ctm); 134 | 135 | /* 136 | Reset the position within the story at which the next layout call 137 | will continue to the start of the story. 138 | */ 139 | void fz_reset_story(fz_context *ctx, fz_story *story); 140 | 141 | /* 142 | Drop the html story. 143 | */ 144 | void fz_drop_story(fz_context *ctx, fz_story *story); 145 | 146 | /* 147 | Get a borrowed reference to the DOM document pointer for this 148 | story. Do not destroy this reference, it will be destroyed 149 | when the story is laid out. 150 | 151 | This only makes sense before the first placement of the story 152 | or retrieval of the warnings. Once either of those things happen 153 | the DOM representation is destroyed. 154 | */ 155 | fz_xml *fz_story_document(fz_context *ctx, fz_story *story); 156 | 157 | 158 | typedef struct 159 | { 160 | /* The overall depth of this element in the box structure. 161 | * This can be used to compare the relative depths of different 162 | * elements, but shouldn't be relied upon not to change between 163 | * different versions of MuPDF. */ 164 | int depth; 165 | 166 | /* The heading level of this element. 0 if not a header, or 1-6 for h1-h6. */ 167 | int heading; 168 | 169 | /* The id for this element. */ 170 | const char *id; 171 | 172 | /* The href for this element. */ 173 | const char *href; 174 | 175 | /* The rectangle for this element. */ 176 | fz_rect rect; 177 | 178 | /* The immediate text for this element. */ 179 | const char *text; 180 | 181 | /* This indicates whether this opens and/or closes this element. 182 | * 183 | * As we traverse the tree we do a depth first search. In order for 184 | * the caller of fz_story_positions to know whether a given element 185 | * is inside another element, we therefore announce 'start' and 'stop' 186 | * for each element. For instance, with: 187 | * 188 | *
189 | *

Chapter 1

... 190 | *

Chapter 2

... 191 | * ... 192 | *
193 | *
194 | *

Chapter 10

... 195 | *

Chapter 11

... 196 | * ... 197 | *
198 | * 199 | * We would announce: 200 | * + id='part1' (open) 201 | * + header=1 "Chapter 1" (open/close) 202 | * + header=1 "Chapter 2" (open/close) 203 | * ... 204 | * + id='part1' (close) 205 | * + id='part2' (open) 206 | * + header=1 "Chapter 10" (open/close) 207 | * + header=1 "Chapter 11" (open/close) 208 | * ... 209 | * + id='part2' (close) 210 | * 211 | * If bit 0 is set, then this 'opens' the element. 212 | * If bit 1 is set, then this 'closes' the element. 213 | */ 214 | int open_close; 215 | 216 | /* A count of the number of rectangles that the layout code has split the 217 | * story into so far. After the first layout, this will be 1. If a 218 | * layout is repeated, this number is not incremented. */ 219 | int rectangle_num; 220 | } fz_story_element_position; 221 | 222 | typedef void (fz_story_position_callback)(fz_context *ctx, void *arg, const fz_story_element_position *); 223 | 224 | /* 225 | Enumerate the positions for key blocks in the story. 226 | 227 | This will cause the supplied function to be called with details of each 228 | element in the story that is either a header, or has an id. 229 | */ 230 | void fz_story_positions(fz_context *ctx, fz_story *story, fz_story_position_callback *cb, void *arg); 231 | 232 | #endif 233 | -------------------------------------------------------------------------------- /include/mupdf/fitz/string-util.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_STRING_H 24 | #define MUPDF_FITZ_STRING_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | 29 | /* The Unicode character used to incoming character whose value is 30 | * unknown or unrepresentable. */ 31 | #define FZ_REPLACEMENT_CHARACTER 0xFFFD 32 | 33 | /** 34 | Safe string functions 35 | */ 36 | 37 | /** 38 | Return strlen(s), if that is less than maxlen, or maxlen if 39 | there is no null byte ('\0') among the first maxlen bytes. 40 | */ 41 | size_t fz_strnlen(const char *s, size_t maxlen); 42 | 43 | /** 44 | Given a pointer to a C string (or a pointer to NULL) break 45 | it at the first occurrence of a delimiter char (from a given 46 | set). 47 | 48 | stringp: Pointer to a C string pointer (or NULL). Updated on 49 | exit to point to the first char of the string after the 50 | delimiter that was found. The string pointed to by stringp will 51 | be corrupted by this call (as the found delimiter will be 52 | overwritten by 0). 53 | 54 | delim: A C string of acceptable delimiter characters. 55 | 56 | Returns a pointer to a C string containing the chars of stringp 57 | up to the first delimiter char (or the end of the string), or 58 | NULL. 59 | */ 60 | char *fz_strsep(char **stringp, const char *delim); 61 | 62 | /** 63 | Copy at most n-1 chars of a string into a destination 64 | buffer with null termination, returning the real length of the 65 | initial string (excluding terminator). 66 | 67 | dst: Destination buffer, at least n bytes long. 68 | 69 | src: C string (non-NULL). 70 | 71 | n: Size of dst buffer in bytes. 72 | 73 | Returns the length (excluding terminator) of src. 74 | */ 75 | size_t fz_strlcpy(char *dst, const char *src, size_t n); 76 | 77 | /** 78 | Concatenate 2 strings, with a maximum length. 79 | 80 | dst: pointer to first string in a buffer of n bytes. 81 | 82 | src: pointer to string to concatenate. 83 | 84 | n: Size (in bytes) of buffer that dst is in. 85 | 86 | Returns the real length that a concatenated dst + src would have 87 | been (not including terminator). 88 | */ 89 | size_t fz_strlcat(char *dst, const char *src, size_t n); 90 | 91 | /** 92 | Find the start of the first occurrence of the substring needle in haystack. 93 | */ 94 | void *fz_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen); 95 | 96 | /** 97 | extract the directory component from a path. 98 | */ 99 | void fz_dirname(char *dir, const char *path, size_t dirsize); 100 | 101 | /** 102 | Find the filename component in a path. 103 | */ 104 | const char *fz_basename(const char *path); 105 | 106 | /** 107 | Like fz_decode_uri_component but in-place. 108 | */ 109 | char *fz_urldecode(char *url); 110 | 111 | /** 112 | * Return a new string representing the unencoded version of the given URI. 113 | * This decodes all escape sequences except those that would result in a reserved 114 | * character that are part of the URI syntax (; / ? : @ & = + $ , #). 115 | */ 116 | char *fz_decode_uri(fz_context *ctx, const char *s); 117 | 118 | /** 119 | * Return a new string representing the unencoded version of the given URI component. 120 | * This decodes all escape sequences! 121 | */ 122 | char *fz_decode_uri_component(fz_context *ctx, const char *s); 123 | 124 | /** 125 | * Return a new string representing the provided string encoded as a URI. 126 | */ 127 | char *fz_encode_uri(fz_context *ctx, const char *s); 128 | 129 | /** 130 | * Return a new string representing the provided string encoded as an URI component. 131 | * This also encodes the special reserved characters (; / ? : @ & = + $ , #). 132 | */ 133 | char *fz_encode_uri_component(fz_context *ctx, const char *s); 134 | 135 | /** 136 | * Return a new string representing the provided string encoded as an URI path name. 137 | * This also encodes the special reserved characters except /. 138 | */ 139 | char *fz_encode_uri_pathname(fz_context *ctx, const char *s); 140 | 141 | /** 142 | create output file name using a template. 143 | 144 | If the path contains %[0-9]*d, the first such pattern will be 145 | replaced with the page number. If the template does not contain 146 | such a pattern, the page number will be inserted before the 147 | filename extension. If the template does not have a filename 148 | extension, the page number will be added to the end. 149 | */ 150 | void fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page); 151 | 152 | /** 153 | rewrite path to the shortest string that names the same path. 154 | 155 | Eliminates multiple and trailing slashes, interprets "." and 156 | "..". Overwrites the string in place. 157 | */ 158 | char *fz_cleanname(char *name); 159 | 160 | /** 161 | rewrite path to the shortest string that names the same path. 162 | 163 | Eliminates multiple and trailing slashes, interprets "." and 164 | "..". Allocates a new string that the caller must free. 165 | */ 166 | char *fz_cleanname_strdup(fz_context *ctx, const char *name); 167 | 168 | /** 169 | Resolve a path to an absolute file name. 170 | The resolved path buffer must be of at least PATH_MAX size. 171 | */ 172 | char *fz_realpath(const char *path, char *resolved_path); 173 | 174 | /** 175 | Case insensitive (ASCII only) string comparison. 176 | */ 177 | int fz_strcasecmp(const char *a, const char *b); 178 | int fz_strncasecmp(const char *a, const char *b, size_t n); 179 | 180 | /** 181 | FZ_UTFMAX: Maximum number of bytes in a decoded rune (maximum 182 | length returned by fz_chartorune). 183 | */ 184 | enum { FZ_UTFMAX = 4 }; 185 | 186 | /** 187 | UTF8 decode a single rune from a sequence of chars. 188 | 189 | rune: Pointer to an int to assign the decoded 'rune' to. 190 | 191 | str: Pointer to a UTF8 encoded string. 192 | 193 | Returns the number of bytes consumed. 194 | */ 195 | int fz_chartorune(int *rune, const char *str); 196 | 197 | /** 198 | UTF8 encode a rune to a sequence of chars. 199 | 200 | str: Pointer to a place to put the UTF8 encoded character. 201 | 202 | rune: Pointer to a 'rune'. 203 | 204 | Returns the number of bytes the rune took to output. 205 | */ 206 | int fz_runetochar(char *str, int rune); 207 | 208 | /** 209 | Count how many chars are required to represent a rune. 210 | 211 | rune: The rune to encode. 212 | 213 | Returns the number of bytes required to represent this run in 214 | UTF8. 215 | */ 216 | int fz_runelen(int rune); 217 | 218 | /** 219 | Compute the index of a rune in a string. 220 | 221 | str: Pointer to beginning of a string. 222 | 223 | p: Pointer to a char in str. 224 | 225 | Returns the index of the rune pointed to by p in str. 226 | */ 227 | int fz_runeidx(const char *str, const char *p); 228 | 229 | /** 230 | Obtain a pointer to the char representing the rune 231 | at a given index. 232 | 233 | str: Pointer to beginning of a string. 234 | 235 | idx: Index of a rune to return a char pointer to. 236 | 237 | Returns a pointer to the char where the desired rune starts, 238 | or NULL if the string ends before the index is reached. 239 | */ 240 | const char *fz_runeptr(const char *str, int idx); 241 | 242 | /** 243 | Count how many runes the UTF-8 encoded string 244 | consists of. 245 | 246 | s: The UTF-8 encoded, NUL-terminated text string. 247 | 248 | Returns the number of runes in the string. 249 | */ 250 | int fz_utflen(const char *s); 251 | 252 | /* 253 | Convert a wchar string into a new heap allocated utf8 one. 254 | */ 255 | char *fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s); 256 | 257 | /* 258 | Convert a utf8 string into a new heap allocated wchar one. 259 | */ 260 | wchar_t *fz_wchar_from_utf8(fz_context *ctx, const char *path); 261 | 262 | 263 | /** 264 | Locale-independent decimal to binary conversion. On overflow 265 | return (-)INFINITY and set errno to ERANGE. On underflow return 266 | 0 and set errno to ERANGE. Special inputs (case insensitive): 267 | "NAN", "INF" or "INFINITY". 268 | */ 269 | float fz_strtof(const char *s, char **es); 270 | 271 | int fz_grisu(float f, char *s, int *exp); 272 | 273 | /** 274 | Check and parse string into page ranges: 275 | /,?(-?\d+|N)(-(-?\d+|N))?/ 276 | */ 277 | int fz_is_page_range(fz_context *ctx, const char *s); 278 | const char *fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n); 279 | 280 | /** 281 | Unicode aware tolower and toupper functions. 282 | */ 283 | int fz_tolower(int c); 284 | int fz_toupper(int c); 285 | 286 | #endif 287 | -------------------------------------------------------------------------------- /include/mupdf/fitz/text.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_TEXT_H 24 | #define MUPDF_FITZ_TEXT_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/font.h" 29 | #include "mupdf/fitz/path.h" 30 | #include "mupdf/fitz/bidi.h" 31 | 32 | /** 33 | Text buffer. 34 | 35 | The trm field contains the a, b, c and d coefficients. 36 | The e and f coefficients come from the individual elements, 37 | together they form the transform matrix for the glyph. 38 | 39 | Glyphs are referenced by glyph ID. 40 | The Unicode text equivalent is kept in a separate array 41 | with indexes into the glyph array. 42 | */ 43 | 44 | typedef struct 45 | { 46 | float x, y; 47 | int gid; /* -1 for one gid to many ucs mappings */ 48 | int ucs; /* -1 for one ucs to many gid mappings */ 49 | int cid; /* CID for CJK fonts, raw character code for other fonts; or unicode for non-PDF formats. */ 50 | } fz_text_item; 51 | 52 | #define FZ_LANG_TAG2(c1,c2) ((c1-'a'+1) + ((c2-'a'+1)*27)) 53 | #define FZ_LANG_TAG3(c1,c2,c3) ((c1-'a'+1) + ((c2-'a'+1)*27) + ((c3-'a'+1)*27*27)) 54 | 55 | typedef enum 56 | { 57 | FZ_LANG_UNSET = 0, 58 | FZ_LANG_ur = FZ_LANG_TAG2('u','r'), 59 | FZ_LANG_urd = FZ_LANG_TAG3('u','r','d'), 60 | FZ_LANG_ko = FZ_LANG_TAG2('k','o'), 61 | FZ_LANG_ja = FZ_LANG_TAG2('j','a'), 62 | FZ_LANG_zh = FZ_LANG_TAG2('z','h'), 63 | FZ_LANG_zh_Hans = FZ_LANG_TAG3('z','h','s'), 64 | FZ_LANG_zh_Hant = FZ_LANG_TAG3('z','h','t'), 65 | } fz_text_language; 66 | 67 | typedef struct fz_text_span 68 | { 69 | fz_font *font; 70 | fz_matrix trm; 71 | unsigned wmode : 1; /* 0 horizontal, 1 vertical */ 72 | unsigned bidi_level : 7; /* The bidirectional level of text */ 73 | unsigned markup_dir : 2; /* The direction of text as marked in the original document */ 74 | unsigned language : 15; /* The language as marked in the original document */ 75 | int len, cap; 76 | fz_text_item *items; 77 | struct fz_text_span *next; 78 | } fz_text_span; 79 | 80 | typedef struct 81 | { 82 | int refs; 83 | fz_text_span *head, *tail; 84 | } fz_text; 85 | 86 | /** 87 | Create a new empty fz_text object. 88 | 89 | Throws exception on failure to allocate. 90 | */ 91 | fz_text *fz_new_text(fz_context *ctx); 92 | 93 | /** 94 | Increment the reference count for the text object. The same 95 | pointer is returned. 96 | 97 | Never throws exceptions. 98 | */ 99 | fz_text *fz_keep_text(fz_context *ctx, const fz_text *text); 100 | 101 | /** 102 | Decrement the reference count for the text object. When the 103 | reference count hits zero, the text object is freed. 104 | 105 | Never throws exceptions. 106 | */ 107 | void fz_drop_text(fz_context *ctx, const fz_text *text); 108 | 109 | /** 110 | Add a glyph/unicode value to a text object. 111 | 112 | text: Text object to add to. 113 | 114 | font: The font the glyph should be added in. 115 | 116 | trm: The transform to use for the glyph. 117 | 118 | glyph: The glyph id to add. 119 | 120 | unicode: The unicode character for the glyph. 121 | 122 | cid: The CJK CID value or raw character code. 123 | 124 | wmode: 1 for vertical mode, 0 for horizontal. 125 | 126 | bidi_level: The bidirectional level for this glyph. 127 | 128 | markup_dir: The direction of the text as specified in the 129 | markup. 130 | 131 | language: The language in use (if known, 0 otherwise) 132 | (e.g. FZ_LANG_zh_Hans). 133 | 134 | Throws exception on failure to allocate. 135 | */ 136 | void fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, fz_matrix trm, int glyph, int unicode, int wmode, int bidi_level, fz_bidi_direction markup_dir, fz_text_language language); 137 | void fz_show_glyph_aux(fz_context *ctx, fz_text *text, fz_font *font, fz_matrix trm, int glyph, int unicode, int cid, int wmode, int bidi_level, fz_bidi_direction markup_dir, fz_text_language lang); 138 | 139 | /** 140 | Add a UTF8 string to a text object. 141 | 142 | text: Text object to add to. 143 | 144 | font: The font the string should be added in. 145 | 146 | trm: The transform to use. 147 | 148 | s: The utf-8 string to add. 149 | 150 | wmode: 1 for vertical mode, 0 for horizontal. 151 | 152 | bidi_level: The bidirectional level for this glyph. 153 | 154 | markup_dir: The direction of the text as specified in the markup. 155 | 156 | language: The language in use (if known, 0 otherwise) 157 | (e.g. FZ_LANG_zh_Hans). 158 | 159 | Returns the transform updated with the advance width of the 160 | string. 161 | */ 162 | fz_matrix fz_show_string(fz_context *ctx, fz_text *text, fz_font *font, fz_matrix trm, const char *s, int wmode, int bidi_level, fz_bidi_direction markup_dir, fz_text_language language); 163 | 164 | /** 165 | Measure the advance width of a UTF8 string should it be added to a text object. 166 | 167 | This uses the same layout algorithms as fz_show_string, and can be used 168 | to calculate text alignment adjustments. 169 | */ 170 | fz_matrix 171 | fz_measure_string(fz_context *ctx, fz_font *user_font, fz_matrix trm, const char *s, int wmode, int bidi_level, fz_bidi_direction markup_dir, fz_text_language language); 172 | 173 | /** 174 | Find the bounds of a given text object. 175 | 176 | text: The text object to find the bounds of. 177 | 178 | stroke: Pointer to the stroke attributes (for stroked 179 | text), or NULL (for filled text). 180 | 181 | ctm: The matrix in use. 182 | 183 | r: pointer to storage for the bounds. 184 | 185 | Returns a pointer to r, which is updated to contain the 186 | bounding box for the text object. 187 | */ 188 | fz_rect fz_bound_text(fz_context *ctx, const fz_text *text, const fz_stroke_state *stroke, fz_matrix ctm); 189 | 190 | /** 191 | Convert ISO 639 (639-{1,2,3,5}) language specification 192 | strings losslessly to a 15 bit fz_text_language code. 193 | 194 | No validation is carried out. Obviously invalid (out 195 | of spec) codes will be mapped to FZ_LANG_UNSET, but 196 | well-formed (but undefined) codes will be blithely 197 | accepted. 198 | */ 199 | fz_text_language fz_text_language_from_string(const char *str); 200 | 201 | /** 202 | Recover ISO 639 (639-{1,2,3,5}) language specification 203 | strings losslessly from a 15 bit fz_text_language code. 204 | 205 | No validation is carried out. See note above. 206 | */ 207 | char *fz_string_from_text_language(char str[8], fz_text_language lang); 208 | 209 | #endif 210 | -------------------------------------------------------------------------------- /include/mupdf/fitz/track-usage.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef TRACK_USAGE_H 24 | #define TRACK_USAGE_H 25 | 26 | #ifdef TRACK_USAGE 27 | 28 | typedef struct track_usage_data { 29 | int count; 30 | const char *function; 31 | int line; 32 | const char *desc; 33 | struct track_usage_data *next; 34 | } track_usage_data; 35 | 36 | #define TRACK_LABEL(A) \ 37 | do { \ 38 | static track_usage_data USAGE_DATA = { 0 };\ 39 | track_usage(&USAGE_DATA, __FILE__, __LINE__, A);\ 40 | } while (0) 41 | 42 | #define TRACK_FN() \ 43 | do { \ 44 | static track_usage_data USAGE_DATA = { 0 };\ 45 | track_usage(&USAGE_DATA, __FILE__, __LINE__, __FUNCTION__);\ 46 | } while (0) 47 | 48 | void track_usage(track_usage_data *data, const char *function, int line, const char *desc); 49 | 50 | #else 51 | 52 | #define TRACK_LABEL(A) do { } while (0) 53 | #define TRACK_FN() do { } while (0) 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/mupdf/fitz/transition.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_TRANSITION_H 24 | #define MUPDF_FITZ_TRANSITION_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/pixmap.h" 28 | 29 | /* Transition support */ 30 | enum { 31 | FZ_TRANSITION_NONE = 0, /* aka 'R' or 'REPLACE' */ 32 | FZ_TRANSITION_SPLIT, 33 | FZ_TRANSITION_BLINDS, 34 | FZ_TRANSITION_BOX, 35 | FZ_TRANSITION_WIPE, 36 | FZ_TRANSITION_DISSOLVE, 37 | FZ_TRANSITION_GLITTER, 38 | FZ_TRANSITION_FLY, 39 | FZ_TRANSITION_PUSH, 40 | FZ_TRANSITION_COVER, 41 | FZ_TRANSITION_UNCOVER, 42 | FZ_TRANSITION_FADE 43 | }; 44 | 45 | typedef struct 46 | { 47 | int type; 48 | float duration; /* Effect duration (seconds) */ 49 | 50 | /* Parameters controlling the effect */ 51 | int vertical; /* 0 or 1 */ 52 | int outwards; /* 0 or 1 */ 53 | int direction; /* Degrees */ 54 | /* Potentially more to come */ 55 | 56 | /* State variables for use of the transition code */ 57 | int state0; 58 | int state1; 59 | } fz_transition; 60 | 61 | /** 62 | Generate a frame of a transition. 63 | 64 | tpix: Target pixmap 65 | opix: Old pixmap 66 | npix: New pixmap 67 | time: Position within the transition (0 to 256) 68 | trans: Transition details 69 | 70 | Returns 1 if successfully generated a frame. 71 | 72 | Note: Pixmaps must include alpha. 73 | */ 74 | int fz_generate_transition(fz_context *ctx, fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time, fz_transition *trans); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/mupdf/fitz/tree.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_TREE_H 24 | #define MUPDF_FITZ_TREE_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | 29 | /** 30 | AA-tree to look up things by strings. 31 | */ 32 | 33 | typedef struct fz_tree fz_tree; 34 | 35 | /** 36 | Look for the value of a node in the tree with the given key. 37 | 38 | Simple pointer equivalence is used for key. 39 | 40 | Returns NULL for no match. 41 | */ 42 | void *fz_tree_lookup(fz_context *ctx, fz_tree *node, const char *key); 43 | 44 | /** 45 | Insert a new key/value pair and rebalance the tree. 46 | Return the new root of the tree after inserting and rebalancing. 47 | May be called with a NULL root to create a new tree. 48 | 49 | No data is copied into the tree structure; key and value are 50 | merely kept as pointers. 51 | */ 52 | fz_tree *fz_tree_insert(fz_context *ctx, fz_tree *root, const char *key, void *value); 53 | 54 | /** 55 | Drop the tree. 56 | 57 | The storage used by the tree is freed, and each value has 58 | dropfunc called on it. 59 | */ 60 | void fz_drop_tree(fz_context *ctx, fz_tree *node, void (*dropfunc)(fz_context *ctx, void *value)); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /include/mupdf/fitz/types.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_TYPES_H 24 | #define MUPDF_FITZ_TYPES_H 25 | 26 | typedef struct fz_document fz_document; 27 | 28 | /** 29 | Locations within the document are referred to in terms of 30 | chapter and page, rather than just a page number. For some 31 | documents (such as epub documents with large numbers of pages 32 | broken into many chapters) this can make navigation much faster 33 | as only the required chapter needs to be decoded at a time. 34 | */ 35 | typedef struct 36 | { 37 | int chapter; 38 | int page; 39 | } fz_location; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/mupdf/fitz/util.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2022 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_UTIL_H 24 | #define MUPDF_FITZ_UTIL_H 25 | 26 | #include "mupdf/fitz/system.h" 27 | #include "mupdf/fitz/context.h" 28 | #include "mupdf/fitz/geometry.h" 29 | #include "mupdf/fitz/document.h" 30 | #include "mupdf/fitz/pixmap.h" 31 | #include "mupdf/fitz/structured-text.h" 32 | #include "mupdf/fitz/buffer.h" 33 | #include "mupdf/fitz/xml.h" 34 | #include "mupdf/fitz/archive.h" 35 | #include "mupdf/fitz/display-list.h" 36 | 37 | /** 38 | Create a display list. 39 | 40 | Ownership of the display list is returned to the caller. 41 | */ 42 | fz_display_list *fz_new_display_list_from_page(fz_context *ctx, fz_page *page); 43 | fz_display_list *fz_new_display_list_from_page_number(fz_context *ctx, fz_document *doc, int number); 44 | 45 | /** 46 | Create a display list from page contents (no annotations). 47 | 48 | Ownership of the display list is returned to the caller. 49 | */ 50 | fz_display_list *fz_new_display_list_from_page_contents(fz_context *ctx, fz_page *page); 51 | 52 | /** 53 | Render the page to a pixmap using the transform and colorspace. 54 | 55 | Ownership of the pixmap is returned to the caller. 56 | */ 57 | fz_pixmap *fz_new_pixmap_from_display_list(fz_context *ctx, fz_display_list *list, fz_matrix ctm, fz_colorspace *cs, int alpha); 58 | fz_pixmap *fz_new_pixmap_from_page(fz_context *ctx, fz_page *page, fz_matrix ctm, fz_colorspace *cs, int alpha); 59 | fz_pixmap *fz_new_pixmap_from_page_number(fz_context *ctx, fz_document *doc, int number, fz_matrix ctm, fz_colorspace *cs, int alpha); 60 | 61 | /** 62 | Render the page contents without annotations. 63 | 64 | Ownership of the pixmap is returned to the caller. 65 | */ 66 | fz_pixmap *fz_new_pixmap_from_page_contents(fz_context *ctx, fz_page *page, fz_matrix ctm, fz_colorspace *cs, int alpha); 67 | 68 | /** 69 | Render the page contents with control over spot colors. 70 | 71 | Ownership of the pixmap is returned to the caller. 72 | */ 73 | fz_pixmap *fz_new_pixmap_from_display_list_with_separations(fz_context *ctx, fz_display_list *list, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha); 74 | fz_pixmap *fz_new_pixmap_from_page_with_separations(fz_context *ctx, fz_page *page, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha); 75 | fz_pixmap *fz_new_pixmap_from_page_number_with_separations(fz_context *ctx, fz_document *doc, int number, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha); 76 | fz_pixmap *fz_new_pixmap_from_page_contents_with_separations(fz_context *ctx, fz_page *page, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha); 77 | 78 | fz_pixmap *fz_fill_pixmap_from_display_list(fz_context *ctx, fz_display_list *list, fz_matrix ctm, fz_pixmap *pix); 79 | 80 | /** 81 | Extract text from page. 82 | 83 | Ownership of the fz_stext_page is returned to the caller. 84 | */ 85 | fz_stext_page *fz_new_stext_page_from_page(fz_context *ctx, fz_page *page, const fz_stext_options *options); 86 | fz_stext_page *fz_new_stext_page_from_page_number(fz_context *ctx, fz_document *doc, int number, const fz_stext_options *options); 87 | fz_stext_page *fz_new_stext_page_from_chapter_page_number(fz_context *ctx, fz_document *doc, int chapter, int number, const fz_stext_options *options); 88 | fz_stext_page *fz_new_stext_page_from_display_list(fz_context *ctx, fz_display_list *list, const fz_stext_options *options); 89 | 90 | /** 91 | Convert structured text into plain text. 92 | */ 93 | fz_buffer *fz_new_buffer_from_stext_page(fz_context *ctx, fz_stext_page *text); 94 | fz_buffer *fz_new_buffer_from_page(fz_context *ctx, fz_page *page, const fz_stext_options *options); 95 | fz_buffer *fz_new_buffer_from_page_number(fz_context *ctx, fz_document *doc, int number, const fz_stext_options *options); 96 | fz_buffer *fz_new_buffer_from_display_list(fz_context *ctx, fz_display_list *list, const fz_stext_options *options); 97 | 98 | /** 99 | Search for the 'needle' text on the page. 100 | Record the hits in the hit_bbox array and return the number of 101 | hits. Will stop looking once it has filled hit_max rectangles. 102 | */ 103 | int fz_search_page(fz_context *ctx, fz_page *page, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max); 104 | int fz_search_page_number(fz_context *ctx, fz_document *doc, int number, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max); 105 | int fz_search_chapter_page_number(fz_context *ctx, fz_document *doc, int chapter, int page, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max); 106 | int fz_search_display_list(fz_context *ctx, fz_display_list *list, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max); 107 | 108 | /** 109 | Parse an SVG document into a display-list. 110 | */ 111 | fz_display_list *fz_new_display_list_from_svg(fz_context *ctx, fz_buffer *buf, const char *base_uri, fz_archive *dir, float *w, float *h); 112 | 113 | /** 114 | Create a scalable image from an SVG document. 115 | */ 116 | fz_image *fz_new_image_from_svg(fz_context *ctx, fz_buffer *buf, const char *base_uri, fz_archive *dir); 117 | 118 | /** 119 | Parse an SVG document into a display-list. 120 | */ 121 | fz_display_list *fz_new_display_list_from_svg_xml(fz_context *ctx, fz_xml_doc *xmldoc, fz_xml *xml, const char *base_uri, fz_archive *dir, float *w, float *h); 122 | 123 | /** 124 | Create a scalable image from an SVG document. 125 | */ 126 | fz_image *fz_new_image_from_svg_xml(fz_context *ctx, fz_xml_doc *xmldoc, fz_xml *xml, const char *base_uri, fz_archive *dir); 127 | 128 | /** 129 | Write image as a data URI (for HTML and SVG output). 130 | */ 131 | void fz_write_image_as_data_uri(fz_context *ctx, fz_output *out, fz_image *image); 132 | void fz_write_pixmap_as_data_uri(fz_context *ctx, fz_output *out, fz_pixmap *pixmap); 133 | void fz_append_image_as_data_uri(fz_context *ctx, fz_buffer *out, fz_image *image); 134 | void fz_append_pixmap_as_data_uri(fz_context *ctx, fz_buffer *out, fz_pixmap *pixmap); 135 | 136 | /** 137 | Use text extraction to convert the input document into XHTML, 138 | then open the result as a new document that can be reflowed. 139 | */ 140 | fz_document *fz_new_xhtml_document_from_document(fz_context *ctx, fz_document *old_doc, const fz_stext_options *opts); 141 | 142 | /** 143 | Returns an fz_buffer containing a page after conversion to specified format. 144 | 145 | page: The page to convert. 146 | format, options: Passed to fz_new_document_writer_with_output() internally. 147 | transform, cookie: Passed to fz_run_page() internally. 148 | */ 149 | fz_buffer *fz_new_buffer_from_page_with_format(fz_context *ctx, fz_page *page, const char *format, const char *options, fz_matrix transform, fz_cookie *cookie); 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /include/mupdf/fitz/vendor.go: -------------------------------------------------------------------------------- 1 | //go:build required 2 | 3 | package vendor 4 | -------------------------------------------------------------------------------- /include/mupdf/fitz/version.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004-2024 Artifex Software, Inc. 2 | // 3 | // This file is part of MuPDF. 4 | // 5 | // MuPDF is free software: you can redistribute it and/or modify it under the 6 | // terms of the GNU Affero General Public License as published by the Free 7 | // Software Foundation, either version 3 of the License, or (at your option) 8 | // any later version. 9 | // 10 | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY 11 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 13 | // details. 14 | // 15 | // You should have received a copy of the GNU Affero General Public License 16 | // along with MuPDF. If not, see 17 | // 18 | // Alternative licensing terms are available from the licensor. 19 | // For commercial licensing, see or contact 20 | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, 21 | // CA 94129, USA, for further information. 22 | 23 | #ifndef MUPDF_FITZ_VERSION_H 24 | #define MUPDF_FITZ_VERSION_H 25 | #ifndef FZ_VERSION 26 | #define FZ_VERSION "1.24.9" 27 | #define FZ_VERSION_MAJOR 1 28 | #define FZ_VERSION_MINOR 24 29 | #define FZ_VERSION_PATCH 9 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /include/mupdf/vendor.go: -------------------------------------------------------------------------------- 1 | //go:build required 2 | 3 | package vendor 4 | -------------------------------------------------------------------------------- /include/vendor.go: -------------------------------------------------------------------------------- 1 | //go:build required 2 | 3 | package vendor 4 | -------------------------------------------------------------------------------- /libs/libmupdf_android_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_android_arm64.a -------------------------------------------------------------------------------- /libs/libmupdf_darwin_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_darwin_amd64.a -------------------------------------------------------------------------------- /libs/libmupdf_darwin_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_darwin_arm64.a -------------------------------------------------------------------------------- /libs/libmupdf_linux_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_linux_amd64.a -------------------------------------------------------------------------------- /libs/libmupdf_linux_amd64_musl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_linux_amd64_musl.a -------------------------------------------------------------------------------- /libs/libmupdf_linux_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_linux_arm64.a -------------------------------------------------------------------------------- /libs/libmupdf_linux_arm64_musl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_linux_arm64_musl.a -------------------------------------------------------------------------------- /libs/libmupdf_windows_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_windows_amd64.a -------------------------------------------------------------------------------- /libs/libmupdf_windows_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdf_windows_arm64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_android_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_android_arm64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_darwin_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_darwin_amd64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_darwin_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_darwin_arm64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_linux_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_linux_amd64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_linux_amd64_musl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_linux_amd64_musl.a -------------------------------------------------------------------------------- /libs/libmupdfthird_linux_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_linux_arm64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_linux_arm64_musl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_linux_arm64_musl.a -------------------------------------------------------------------------------- /libs/libmupdfthird_windows_amd64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_windows_amd64.a -------------------------------------------------------------------------------- /libs/libmupdfthird_windows_arm64.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/libs/libmupdfthird_windows_arm64.a -------------------------------------------------------------------------------- /libs/vendor.go: -------------------------------------------------------------------------------- 1 | //go:build required 2 | 3 | package vendor 4 | -------------------------------------------------------------------------------- /purego_darwin.go: -------------------------------------------------------------------------------- 1 | //go:build (!cgo || nocgo) && darwin 2 | 3 | package fitz 4 | 5 | import ( 6 | "fmt" 7 | 8 | "github.com/ebitengine/purego" 9 | ) 10 | 11 | const ( 12 | libname = "libmupdf.dylib" 13 | ) 14 | 15 | // loadLibrary loads the so and panics on error. 16 | func loadLibrary() uintptr { 17 | handle, err := purego.Dlopen(libname, purego.RTLD_NOW|purego.RTLD_GLOBAL) 18 | if err != nil { 19 | panic(fmt.Errorf("cannot load library: %w", err)) 20 | } 21 | 22 | return uintptr(handle) 23 | } 24 | -------------------------------------------------------------------------------- /purego_linux.go: -------------------------------------------------------------------------------- 1 | //go:build (!cgo || nocgo) && unix && !darwin 2 | 3 | package fitz 4 | 5 | import ( 6 | "fmt" 7 | "github.com/ebitengine/purego" 8 | ) 9 | 10 | const ( 11 | libname = "libmupdf.so" 12 | ) 13 | 14 | // loadLibrary loads the so and panics on error. 15 | func loadLibrary() uintptr { 16 | handle, err := purego.Dlopen(libname, purego.RTLD_NOW|purego.RTLD_GLOBAL) 17 | if err != nil { 18 | panic(fmt.Errorf("cannot load library: %w", err)) 19 | } 20 | 21 | return handle 22 | } 23 | -------------------------------------------------------------------------------- /purego_windows.go: -------------------------------------------------------------------------------- 1 | //go:build (!cgo || nocgo) && windows 2 | 3 | package fitz 4 | 5 | import ( 6 | "fmt" 7 | "syscall" 8 | ) 9 | 10 | const ( 11 | libname = "libmupdf.dll" 12 | ) 13 | 14 | // loadLibrary loads the dll and panics on error. 15 | func loadLibrary() uintptr { 16 | handle, err := syscall.LoadLibrary(libname) 17 | if err != nil { 18 | panic(fmt.Errorf("cannot load library %s: %w", libname, err)) 19 | } 20 | 21 | return uintptr(handle) 22 | } 23 | -------------------------------------------------------------------------------- /testdata/test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.bmp -------------------------------------------------------------------------------- /testdata/test.cbz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.cbz -------------------------------------------------------------------------------- /testdata/test.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.docx -------------------------------------------------------------------------------- /testdata/test.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.epub -------------------------------------------------------------------------------- /testdata/test.fb2: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello World 6 | 7 | 8 | 9 |
Hello World
10 | 11 |
12 | -------------------------------------------------------------------------------- /testdata/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.gif -------------------------------------------------------------------------------- /testdata/test.jb2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.jb2 -------------------------------------------------------------------------------- /testdata/test.jp2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.jp2 -------------------------------------------------------------------------------- /testdata/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.jpg -------------------------------------------------------------------------------- /testdata/test.jxr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.jxr -------------------------------------------------------------------------------- /testdata/test.mobi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.mobi -------------------------------------------------------------------------------- /testdata/test.pam: -------------------------------------------------------------------------------- 1 | P7 2 | WIDTH 3 3 | HEIGHT 3 4 | DEPTH 1 5 | MAXVAL 1 6 | TUPLETYPE blackandwhite 7 | ENDHDR 8 | 1 0 1 9 | 0 1 0 10 | 1 0 1 -------------------------------------------------------------------------------- /testdata/test.pbm: -------------------------------------------------------------------------------- 1 | P1 2 | 3 3 3 | 1 0 1 4 | 0 1 0 5 | 1 0 1 -------------------------------------------------------------------------------- /testdata/test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.pdf -------------------------------------------------------------------------------- /testdata/test.pfm: -------------------------------------------------------------------------------- 1 | PF 2 | 1 1 3 | -1.0 4 | �? -------------------------------------------------------------------------------- /testdata/test.pgm: -------------------------------------------------------------------------------- 1 | P2 2 | 3 3 3 | 2 4 | 0 1 2 5 | 0 1 2 6 | 0 1 2 -------------------------------------------------------------------------------- /testdata/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.png -------------------------------------------------------------------------------- /testdata/test.ppm: -------------------------------------------------------------------------------- 1 | P3 2 | 3 3 3 | 255 4 | 255 0 0 5 | 0 255 0 6 | 0 0 255 7 | 255 255 0 8 | 0 255 0 9 | 255 0 255 10 | 255 255 255 11 | 0 255 0 12 | 0 255 255 -------------------------------------------------------------------------------- /testdata/test.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.pptx -------------------------------------------------------------------------------- /testdata/test.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.psd -------------------------------------------------------------------------------- /testdata/test.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /testdata/test.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.tif -------------------------------------------------------------------------------- /testdata/test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.xlsx -------------------------------------------------------------------------------- /testdata/test.xps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/go-fitz/f1c7716a999d9e4deb2d470a48eddc36180472f4/testdata/test.xps --------------------------------------------------------------------------------