| 1 |
/* Copyright (C) 2018-2025 Artifex Software, Inc. |
| 2 |
All Rights Reserved. |
| 3 |
|
| 4 |
This software is provided AS-IS with no warranty, either express or |
| 5 |
implied. |
| 6 |
|
| 7 |
This software is distributed under license and may not be copied, |
| 8 |
modified or distributed except as expressly authorized under the terms |
| 9 |
of the license contained in the file LICENSE in this distribution. |
| 10 |
|
| 11 |
Refer to licensing information at http://www.artifex.com or contact |
| 12 |
Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
| 13 |
CA 94129, USA, for further information. |
| 14 |
*/ |
| 15 |
|
| 16 |
/* Font operations for the PDF interpreter */ |
| 17 |
|
| 18 |
#include "pdf_font_types.h" |
| 19 |
#include "pdf_stack.h" |
| 20 |
|
| 21 |
#ifndef PDF_FONT_OPERATORS |
| 22 |
#define PDF_FONT_OPERATORS |
| 23 |
|
| 24 |
int pdfi_d0(pdf_context *ctx); |
| 25 |
int pdfi_d1(pdf_context *ctx); |
| 26 |
int pdfi_Tf(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict); |
| 27 |
int pdfi_free_font(pdf_obj *font); |
| 28 |
|
| 29 |
static inline void pdfi_countup_current_font(pdf_context *ctx) |
| 30 |
{ |
| 31 |
pdf_font *font; |
| 32 |
|
| 33 |
if (ctx->pgs->font != NULL) { |
| 34 |
font = (pdf_font *)ctx->pgs->font->client_data; |
| 35 |
pdfi_countup(font); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
static inline void pdfi_countdown_current_font(pdf_context *ctx) |
| 40 |
{ |
| 41 |
pdf_font *font; |
| 42 |
|
| 43 |
if (ctx->pgs->font != NULL) { |
| 44 |
font = (pdf_font *)ctx->pgs->font->client_data; |
| 45 |
pdfi_countdown(font); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
static inline pdf_font *pdfi_get_current_pdf_font(pdf_context *ctx) |
| 50 |
{ |
| 51 |
pdf_font *font; |
| 52 |
|
| 53 |
if (ctx->pgs->font != NULL) { |
| 54 |
font = (pdf_font *)ctx->pgs->font->client_data; |
| 55 |
return(font); |
| 56 |
} |
| 57 |
return NULL; |
| 58 |
} |
| 59 |
|
| 60 |
void pdfi_purge_cache_resource_font(pdf_context *ctx); |
| 61 |
|
| 62 |
int pdfi_create_Widths(pdf_context *ctx, pdf_dict *font_dict, pdf_font *pdffont); |
| 63 |
int pdfi_create_Encoding(pdf_context *ctx, pdf_font *ppdffont, pdf_obj *pdf_Encoding, pdf_obj *font_Encoding, pdf_obj **Encoding); |
| 64 |
gs_glyph pdfi_encode_char(gs_font * pfont, gs_char chr, gs_glyph_space_t not_used); |
| 65 |
int pdfi_glyph_index(gs_font *pfont, byte *str, uint size, uint *glyph); |
| 66 |
int pdfi_glyph_name(gs_font * pfont, gs_glyph glyph, gs_const_string * pstr); |
| 67 |
|
| 68 |
void pdfi_cidfont_cid_subst_tables(const char *reg, const int reglen, const char *ord, |
| 69 |
const int ordlen, pdfi_cid_decoding_t **decoding, pdfi_cid_subst_nwp_table_t **substnwp); |
| 70 |
|
| 71 |
int pdfi_cidfont_decode_glyph(gs_font *font, gs_glyph glyph, int ch, ushort *u, unsigned int length); |
| 72 |
|
| 73 |
int pdfi_tounicode_char_to_unicode(pdf_context *ctx, pdf_cmap *tounicode, gs_glyph glyph, int ch, ushort *unicode_return, unsigned int length); |
| 74 |
int pdfi_decode_glyph(gs_font * font, gs_glyph glyph, int ch, ushort *unicode_return, unsigned int length); |
| 75 |
|
| 76 |
/* This is in pdf_fapi.c, but since it is the only exported function |
| 77 |
from that module (so far) it doesn't seem worth a new header |
| 78 |
*/ |
| 79 |
int pdfi_fapi_passfont(pdf_font *font, int subfont, char *fapi_request, |
| 80 |
char *file_name, byte * font_data, int font_data_len); |
| 81 |
|
| 82 |
int pdfi_fapi_check_cmap_for_GID(gs_font *pfont, uint c, uint *g); |
| 83 |
|
| 84 |
#ifdef UFST_BRIDGE |
| 85 |
bool pdfi_fapi_ufst_available(gs_memory_t *mem); |
| 86 |
int pdfi_fapi_get_mtype_font_name(gs_font * pfont, byte * data, int *size); |
| 87 |
int pdfi_fapi_get_mtype_font_number(gs_font * pfont, int *font_number); |
| 88 |
const char *pdfi_fapi_ufst_get_fco_list(gs_memory_t *mem); |
| 89 |
const char *pdfi_fapi_ufst_get_font_dir(gs_memory_t *mem); |
| 90 |
int pdfi_lookup_fco_char_code(const char *decname, int32_t decnamelen, const char *gname, int32_t gnamelen, int64_t *charcode); |
| 91 |
#else /* UFST_BRIDGE */ |
| 92 |
#define pdfi_fapi_get_mtype_font_name(pfont, data, size) gs_error_undefined |
| 93 |
#define pdfi_fapi_get_mtype_font_number(pfont, font_number) gs_error_undefined |
| 94 |
#define pdfi_lookup_fco_char_code(decname, decnamelen, gname, gnamelen, charcode) gs_error_undefined |
| 95 |
#endif /* UFST_BRIDGE */ |
| 96 |
|
| 97 |
|
| 98 |
int pdfi_map_glyph_name_via_agl(pdf_dict *cstrings, pdf_name *gname, pdf_string **cstring); |
| 99 |
|
| 100 |
int pdfi_init_font_directory(pdf_context *ctx); |
| 101 |
|
| 102 |
int pdfi_load_font(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict, pdf_dict *font_dict, gs_font **ppfont, bool cidfont); |
| 103 |
|
| 104 |
int pdfi_load_dict_font(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict, pdf_dict *font_dict, double point_size); |
| 105 |
|
| 106 |
/* Loads a (should be!) non-embedded font by name |
| 107 |
Only currently works for the Type 1 font set from romfs. |
| 108 |
*/ |
| 109 |
int pdfi_load_font_by_name_string(pdf_context *ctx, const byte *fontname, size_t length, pdf_obj **ppdffont); |
| 110 |
|
| 111 |
/* Convenience function for using fonts created by |
| 112 |
pdfi_load_font_by_name_string |
| 113 |
*/ |
| 114 |
int pdfi_set_font_internal(pdf_context *ctx, pdf_obj *fontobj, double point_size); |
| 115 |
|
| 116 |
int pdfi_font_set_internal_string(pdf_context *ctx, const char *fontname, double point_size); |
| 117 |
int pdfi_font_set_internal_name(pdf_context *ctx, pdf_name *fontname, double point_size); |
| 118 |
bool pdfi_font_known_symbolic(pdf_obj *basefont); |
| 119 |
|
| 120 |
|
| 121 |
enum { |
| 122 |
GLYPH_W0_WIDTH_INDEX = 0, |
| 123 |
GLYPH_W0_HEIGHT_INDEX = 1, |
| 124 |
GLYPH_W1_WIDTH_INDEX = 2, |
| 125 |
GLYPH_W1_HEIGHT_INDEX = 3, |
| 126 |
GLYPH_W1_V_X_INDEX = 4, |
| 127 |
GLYPH_W1_V_Y_INDEX = 5 |
| 128 |
}; |
| 129 |
|
| 130 |
int pdfi_get_cidfont_glyph_metrics(gs_font *pfont, gs_glyph cid, double *widths, bool vertical); |
| 131 |
int pdfi_font_create_widths(pdf_context *ctx, pdf_dict *fontdict, pdf_font *font, double wscale); |
| 132 |
void pdfi_font_set_first_last_char(pdf_context *ctx, pdf_dict *fontdict, pdf_font *font); |
| 133 |
int pdfi_font_generate_pseudo_XUID(pdf_context *ctx, pdf_dict *fontdict, gs_font_base *pfont); |
| 134 |
void pdfi_font_set_orig_fonttype(pdf_context *ctx, pdf_font *font); |
| 135 |
|
| 136 |
|
| 137 |
font_proc_font_info(pdfi_default_font_info); |
| 138 |
|
| 139 |
#endif |