summaryrefslogtreecommitdiff
path: root/devices
diff options
context:
space:
mode:
authorJustin Beaty <foss@beatyconsulting.com>2023-02-13 15:16:37 +0000
committerRobin Watts <Robin.Watts@artifex.com>2023-02-13 16:12:34 +0000
commit9e79b6b270bfbe54a4cfee706fba98f76848a149 (patch)
tree5e2c4b5ea538d98a4bee7da23c33635109d0c690 /devices
parent924b58ac2882ad20e825c77bfc412425c9bcfdb2 (diff)
downloadghostpdl-9e79b6b270bfbe54a4cfee706fba98f76848a149.tar.gz
pdfwrite - permit fonts to be converted to linework based on the name
No bug report for this one, the patch was submitted by Justin after a conversation on Discord (#ghostscript, 11th February 2023). The goal was to extend the 'NoOutputFonts' control, which turns all text in a PDF file into linework, such that the decision could be made based on the font name. The supplied patch does so by adding two new controls, AlwaysOutline and NeverOutline, which can only be set from PostScript (because the font names are in an array). Text using fonts appearing in the AlwaysOutline array will be converted to linework regardless of the setting of NoOutputFonts. If NoOutputFonts is set to true, then text using fonts appearing in the NeverOutline array will still use the font, and will not be converted to linework.
Diffstat (limited to 'devices')
-rw-r--r--devices/vector/gdevpdtb.c4
-rw-r--r--devices/vector/gdevpdtb.h4
-rw-r--r--devices/vector/gdevpdtt.c29
-rw-r--r--devices/vector/gdevpsdf.h11
-rw-r--r--devices/vector/gdevpsdp.c32
5 files changed, 72 insertions, 8 deletions
diff --git a/devices/vector/gdevpdtb.c b/devices/vector/gdevpdtb.c
index 200f6ec3a..bab7995df 100644
--- a/devices/vector/gdevpdtb.c
+++ b/devices/vector/gdevpdtb.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2022 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -47,8 +47,6 @@ private_st_pdf_base_font();
gs_private_st_basic(st_pdf_base_font, pdf_base_font_t, "pdf_base_font_t",\
pdf_base_font_ptrs, pdf_base_font_data);
-#define SUBSET_PREFIX_SIZE 7 /* XXXXXX+ */
-
typedef struct pdf_base14_font_info_s {
const char *urwname;
const char *stdname;
diff --git a/devices/vector/gdevpdtb.h b/devices/vector/gdevpdtb.h
index e8540c289..9ddedf374 100644
--- a/devices/vector/gdevpdtb.h
+++ b/devices/vector/gdevpdtb.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -21,6 +21,8 @@
#include "gdevpdtx.h"
+#define SUBSET_PREFIX_SIZE 7 /* XXXXXX+ */
+
/* ================ Types and structures ================ */
/*
diff --git a/devices/vector/gdevpdtt.c b/devices/vector/gdevpdtt.c
index c3e5574cd..e43dc3819 100644
--- a/devices/vector/gdevpdtt.c
+++ b/devices/vector/gdevpdtt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2022 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -20,6 +20,7 @@
#include <stdlib.h> /* abs() */
#include "gx.h"
#include "gserrors.h"
+#include "gsutil.h" /* for bytes_compare */
#include "gscencs.h"
#include "gscedata.h"
#include "gsmatrix.h"
@@ -543,6 +544,18 @@ pdf_prepare_text_drawing(gx_device_pdf *const pdev, gs_text_enum_t *pte)
return 0;
}
+static bool
+outline_list_includes(const gs_param_string_array *psa, const byte *chars,
+ uint size)
+{
+ uint i;
+
+ for (i = 0; i < psa->size; ++i)
+ if (!bytes_compare(psa->data[i].data, psa->data[i].size, chars, size))
+ return true;
+ return false;
+}
+
int
gdev_pdf_text_begin(gx_device * dev, gs_gstate * pgs,
const gs_text_params_t *text, gs_font * font,
@@ -557,8 +570,20 @@ gdev_pdf_text_begin(gx_device * dev, gs_gstate * pgs,
int code, user_defined = 0;
gs_memory_t * mem = pgs->memory;
+ const gs_font_name *fn = &font->font_name;
+ byte *chars_ptr = fn->chars;
+ uint size = fn->size;
+
+ while (pdf_has_subset_prefix(chars_ptr, size)) {
+ /* Strip off an existing subset prefix. */
+ chars_ptr += SUBSET_PREFIX_SIZE;
+ size -= SUBSET_PREFIX_SIZE;
+ }
+
/* should we "flatten" the font to "normal" marking operations */
- if (pdev->FlattenFonts) {
+ if (outline_list_includes(&pdev->params.AlwaysOutline, (const byte *)chars_ptr, size) ||
+ (pdev->FlattenFonts && !outline_list_includes(&pdev->params.NeverOutline, (const byte *)chars_ptr, size))
+ ) {
font->dir->ccache.upper = 0;
return gx_default_text_begin(dev, pgs, text, font,
pcpath, ppte);
diff --git a/devices/vector/gdevpsdf.h b/devices/vector/gdevpsdf.h
index 8f5d6ad8d..00a7b4ee7 100644
--- a/devices/vector/gdevpsdf.h
+++ b/devices/vector/gdevpsdf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -159,6 +159,11 @@ typedef struct psdf_distiller_params_s {
psdf_image_params MonoImage;
+ /* Font outlining parameters */
+
+ gs_param_string_array AlwaysOutline;
+ gs_param_string_array NeverOutline;
+
/* Font embedding parameters */
gs_param_string_array AlwaysEmbed;
@@ -259,6 +264,8 @@ extern const stream_template s_zlibE_template;
}
#define psdf_font_param_defaults\
+ {0}, /* AlwaysOutline (array of names) */ \
+ {0}, /* NeverOutline (array of names) */ \
{0}, /* AlwaysEmbed (array of names) */ \
{0}, /* NeverEmbed (array of names) */ \
cefp_Warning, /* CannotEmbedFontPolicy */ \
@@ -336,6 +343,8 @@ extern_st(st_device_psdf);
params.GrayImage.Dict),\
GC_OBJ_ELT2(gx_device_psdf, params.MonoImage.ACSDict,\
params.MonoImage.Dict),\
+ GC_OBJ_ELT2(gx_device_psdf, params.AlwaysOutline.data,\
+ params.NeverOutline.data),\
GC_OBJ_ELT2(gx_device_psdf, params.AlwaysEmbed.data,\
params.NeverEmbed.data),\
GC_CONST_STRING_ELT(gx_device_psdf, params.PSDocOptions)\
diff --git a/devices/vector/gdevpsdp.c b/devices/vector/gdevpsdp.c
index cf6933ece..bd0016973 100644
--- a/devices/vector/gdevpsdp.c
+++ b/devices/vector/gdevpsdp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2022 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -499,6 +499,12 @@ gdev_psdf_get_param(gx_device *dev, char *Param, void *list)
return(psdf_write_string_param(plist, "sRGBProfile",
&pdev->params.sRGBProfile));
}
+ if (strcmp(Param, ".AlwaysOutline") == 0) {
+ return(psdf_get_embed_param(plist, ".AlwaysOutline", &pdev->params.AlwaysOutline));
+ }
+ if (strcmp(Param, ".NeverOutline") == 0) {
+ return(psdf_get_embed_param(plist, ".NeverOutline", &pdev->params.NeverOutline));
+ }
if (strcmp(Param, ".AlwaysEmbed") == 0) {
return(psdf_get_embed_param(plist, ".AlwaysEmbed", &pdev->params.AlwaysEmbed));
}
@@ -598,6 +604,16 @@ gdev_psdf_get_params(gx_device * dev, gs_param_list * plist)
if (code < 0)
return code;
+ /* Font outlining parameters */
+
+ code = psdf_get_embed_param(plist, ".AlwaysOutline", &pdev->params.AlwaysOutline);
+ if (code < 0)
+ return code;
+
+ code = psdf_get_embed_param(plist, ".NeverOutline", &pdev->params.NeverOutline);
+ if (code < 0)
+ return code;
+
/* Font embedding parameters */
code = psdf_get_embed_param(plist, ".AlwaysEmbed", &pdev->params.AlwaysEmbed);
@@ -1117,6 +1133,8 @@ gdev_psdf_put_params(gx_device * dev, gs_param_list * plist)
params.ColorImage.ACSDict = params.ColorImage.Dict = 0;
params.GrayImage.ACSDict = params.GrayImage.Dict = 0;
params.MonoImage.ACSDict = params.MonoImage.Dict = 0;
+ params.AlwaysOutline.data = params.NeverOutline.data = NULL;
+ params.AlwaysOutline.size = params.NeverOutline.size = 0;
params.AlwaysEmbed.data = params.NeverEmbed.data = 0;
params.AlwaysEmbed.size = params.AlwaysEmbed.persistent = params.NeverEmbed.size = params.NeverEmbed.persistent = 0;
params.PSPageOptions.data = NULL;
@@ -1223,6 +1241,18 @@ gdev_psdf_put_params(gx_device * dev, gs_param_list * plist)
goto exit;
}
+ /* Font outlining parameters */
+
+ ecode = psdf_put_embed_param(plist, "~AlwaysOutline", ".AlwaysOutline",
+ &params.AlwaysOutline, mem, ecode);
+ ecode = psdf_put_embed_param(plist, "~NeverOutline", ".NeverOutline",
+ &params.NeverOutline, mem, ecode);
+
+ if (ecode < 0) {
+ code = ecode;
+ goto exit;
+ }
+
/* Font embedding parameters */
ecode = psdf_put_embed_param(plist, "~AlwaysEmbed", ".AlwaysEmbed",