summaryrefslogtreecommitdiff
path: root/pdf/ghostpdf.c
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2021-11-04 14:33:01 +0000
committerChris Liddell <chris.liddell@artifex.com>2021-11-09 11:12:04 +0000
commitcb4156b9545f131698026106b289a5253f295e23 (patch)
tree6fdaa396b485780a94097453346e10f16e9d04ab /pdf/ghostpdf.c
parent0a1d08d91a95746f41e8c1d578a4e4af81ee5949 (diff)
downloadghostpdl-cb4156b9545f131698026106b289a5253f295e23.tar.gz
Support user specified Fontmap files in pdfi
Handle -sFONTMAP param in gpdl, and copy the relevant strings from the Postscript world when pdfi is called from Ghostscript. To make things a little simpler, there is also a tweak to the Postscript code, so the FONTMAP parameter gets split into an array of strings during initialisation, rather than at use time, which saves doing that process once for Postscript and once for pdfi.
Diffstat (limited to 'pdf/ghostpdf.c')
-rw-r--r--pdf/ghostpdf.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index e71d39649..0d703d261 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -1363,7 +1363,7 @@ static size_t pdfi_grdir_path_string_match(const byte *str, size_t sl0, byte *pa
int pdfi_add_paths_to_search_paths(pdf_context *ctx, const char *ppath, int l, bool fontpath)
{
- int i, slen, npaths = (l > 0);
+ int i, slen, npaths = (l > 0) ? 1 : 0;
const char *p = ppath;
char *ps;
const char *pe = p + l + 1;
@@ -1503,6 +1503,61 @@ static void pdfi_free_search_paths(pdf_context *ctx)
gs_free_object(ctx->memory, (byte *)ctx->search_paths.font_paths, "array of font paths");
}
+static void pdfi_free_fontmapfiles(pdf_context *ctx)
+{
+ int i;
+ for (i = 0; i < ctx->num_fontmapfiles; i++) {
+ gs_free_object(ctx->memory, ctx->fontmapfiles[i].data, "fontmapfiles string body");
+ }
+ gs_free_object(ctx->memory, ctx->fontmapfiles, "fontmapfiles array");
+}
+
+/* The fontmap file list doesn't extend, later settings in the command line override earlier ones
+ (Unlike the "-I" search paths above).
+ */
+int pdfi_add_fontmapfiles(pdf_context *ctx, const char *ppath, int l)
+{
+ int i, nfilenames = (l > 0) ? 1 : 0;
+ const char *p = ppath;
+ char *ps;
+ const char *pe = p + l + 1;
+ int code = 0;
+
+ pdfi_free_fontmapfiles(ctx);
+
+ for (ps = (char *)p; ps < pe; ps++) {
+ if (*ps == gp_file_name_list_separator)
+ nfilenames++;
+ }
+ if (nfilenames > 0) {
+ ctx->fontmapfiles = (gs_string *)gs_alloc_bytes(ctx->memory, sizeof(gs_string) * nfilenames, "array of fontmap files");
+ if (ctx->fontmapfiles == NULL) {
+ return_error(gs_error_VMerror);
+ }
+ else {
+ memset(ctx->fontmapfiles, 0x00, sizeof(gs_string) * nfilenames);
+ ctx->num_fontmapfiles = nfilenames;
+
+ for (i = 0; i < nfilenames; i++) {
+ for (ps = (char *)p; ps < pe; ps++) {
+ if (*ps == gp_file_name_list_separator)
+ break;
+ }
+ ctx->fontmapfiles[i].data = gs_alloc_bytes(ctx->memory, ps - p, "fontmap file name body");
+ if (ctx->fontmapfiles[i].data == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto done;
+ }
+ memcpy(ctx->fontmapfiles[i].data, p, ps - p);
+ ctx->fontmapfiles[i].size = ps - p;
+ p = ps + 1;
+ }
+ }
+ }
+done:
+ return code;
+}
+
/***********************************************************************************/
/* Highest level functions. The context we create here is returned to the 'PL' */
/* implementation, in future we plan to return it to PostScript by wrapping a */
@@ -1900,6 +1955,7 @@ int pdfi_free_context(pdf_context *ctx)
}
pdfi_free_search_paths(ctx);
+ pdfi_free_fontmapfiles(ctx);
gs_free_object(ctx->memory, ctx, "pdfi_free_context");
#if PDFI_LEAK_CHECK