mupdf
Loading...
Searching...
No Matches
cmap.h
Go to the documentation of this file.
1// Copyright (C) 2004-2025 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 <https://www.gnu.org/licenses/agpl-3.0.en.html>
17//
18// Alternative licensing terms are available from the licensor.
19// For commercial licensing, see <https://www.artifex.com/> or contact
20// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21// CA 94129, USA, for further information.
22
23#ifndef MUPDF_PDF_CMAP_H
24#define MUPDF_PDF_CMAP_H
25
26#include "mupdf/fitz/store.h"
27#include "mupdf/pdf/document.h"
28
29// The maximum 1-to-many mapping length.
30// In the PDF reference, the max is 512 bytes for ToUnicode CMaps.
31// This results in us needing to support up to 256 characters.
32#define PDF_MRANGE_CAP 256
33
34typedef struct
35{
36 unsigned short low, high, out;
37} pdf_range;
38
39typedef struct
40{
41 unsigned int low, high, out;
43
44typedef struct
45{
46 unsigned int low, out;
48
49typedef struct cmap_splay cmap_splay;
50
51typedef struct pdf_cmap
52{
54 char cmap_name[32];
55
56 char usecmap_name[32];
58
59 int wmode;
60
62 struct
63 {
64 int n;
65 unsigned int low;
66 unsigned int high;
67 } codespace[40];
68
69 int rlen, rcap;
71
72 int xlen, xcap;
74
75 int mlen, mcap;
77
78 int dlen, dcap;
79 int *dict;
80
81 int tlen, tcap, ttop;
84
89size_t pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap);
90
94
95/*
96 Add a codespacerange section.
97 These ranges are used by pdf_decode_cmap to decode
98 multi-byte encoded strings.
99*/
100void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, unsigned int low, unsigned int high, size_t n);
101
102/*
103 Add a range of contiguous one-to-one mappings (i.e. 1..5 maps to 21..25)
104*/
105void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, unsigned int srclo, unsigned int srchi, int dstlo);
106
107/*
108 Add a single one-to-many mapping.
109
110 len <= 256.
111*/
112void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, unsigned int one, int *many, size_t len);
114
115/*
116 Lookup the mapping of a codepoint.
117*/
118int pdf_lookup_cmap(pdf_cmap *cmap, unsigned int cpt);
119int pdf_lookup_cmap_full(pdf_cmap *cmap, unsigned int cpt, int *out);
120
121/*
122 Use the codespace ranges to extract a codepoint from a
123 multi-byte encoded string.
124*/
125int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, unsigned char *e, unsigned int *cpt);
126
127/*
128 Create an Identity-* CMap (for both 1 and 2-byte encodings)
129*/
132
133/*
134 Load predefined CMap from system.
135*/
136pdf_cmap *pdf_load_system_cmap(fz_context *ctx, const char *name);
137
138/*
139 Load built-in CMap resource.
140*/
142
143/*
144 Load CMap stream in PDF file
145*/
147
148#endif
void pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap)
pdf_cmap * pdf_new_cmap(fz_context *ctx)
size_t pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap)
void pdf_drop_cmap_imp(fz_context *ctx, fz_storable *cmap)
void pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, unsigned int one, int *many, size_t len)
void pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, unsigned int low, unsigned int high, size_t n)
void pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap)
int pdf_cmap_wmode(fz_context *ctx, pdf_cmap *cmap)
pdf_cmap * pdf_load_cmap(fz_context *ctx, fz_stream *file)
pdf_cmap * pdf_load_embedded_cmap(fz_context *ctx, pdf_document *doc, pdf_obj *ref)
pdf_cmap * pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes)
pdf_cmap * pdf_load_system_cmap(fz_context *ctx, const char *name)
void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap)
pdf_cmap * pdf_load_builtin_cmap(fz_context *ctx, const char *name)
struct cmap_splay cmap_splay
Definition cmap.h:49
pdf_cmap * pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap)
void pdf_set_cmap_wmode(fz_context *ctx, pdf_cmap *cmap, int wmode)
void pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, unsigned int srclo, unsigned int srchi, int dstlo)
int pdf_lookup_cmap_full(pdf_cmap *cmap, unsigned int cpt, int *out)
int pdf_decode_cmap(pdf_cmap *cmap, unsigned char *s, unsigned char *e, unsigned int *cpt)
int pdf_lookup_cmap(pdf_cmap *cmap, unsigned int cpt)
struct pdf_obj pdf_obj
Definition object.h:44
Definition context.h:886
Definition store.h:76
Definition stream.h:320
Definition cmap.h:52
struct pdf_cmap * usecmap
Definition cmap.h:57
pdf_range * ranges
Definition cmap.h:70
unsigned int low
Definition cmap.h:65
fz_storable storable
Definition cmap.h:53
char cmap_name[32]
Definition cmap.h:54
int tcap
Definition cmap.h:81
int tlen
Definition cmap.h:81
int dcap
Definition cmap.h:78
unsigned int high
Definition cmap.h:66
int * dict
Definition cmap.h:79
int wmode
Definition cmap.h:59
int mcap
Definition cmap.h:75
int rlen
Definition cmap.h:69
cmap_splay * tree
Definition cmap.h:82
int xcap
Definition cmap.h:72
struct pdf_cmap::@222214117273136055123337123114344050144201341301 codespace[40]
int rcap
Definition cmap.h:69
int dlen
Definition cmap.h:78
int ttop
Definition cmap.h:81
char usecmap_name[32]
Definition cmap.h:56
pdf_xrange * xranges
Definition cmap.h:73
pdf_mrange * mranges
Definition cmap.h:76
int mlen
Definition cmap.h:75
int n
Definition cmap.h:64
int codespace_len
Definition cmap.h:61
int xlen
Definition cmap.h:72
Definition document.h:463
Definition cmap.h:45
unsigned int low
Definition cmap.h:46
unsigned int out
Definition cmap.h:46
Definition cmap.h:35
unsigned short low
Definition cmap.h:36
unsigned short out
Definition cmap.h:36
unsigned short high
Definition cmap.h:36
Definition cmap.h:40
unsigned int low
Definition cmap.h:41
unsigned int high
Definition cmap.h:41
unsigned int out
Definition cmap.h:41