diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2022-06-07 10:37:01 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2022-07-29 08:18:08 +0100 |
commit | 7409743d98cab135da537bce11103a8416d77f60 (patch) | |
tree | 9ea8b44dda1dac0e04d5a94aec1d46f51454a091 /pdf/pdf_font3.c | |
parent | b0075e3f398cbfe97e70a9ed9c0c6754f2bae738 (diff) | |
download | ghostpdl-7409743d98cab135da537bce11103a8416d77f60.tar.gz |
Copy existing font objects for substitutions
Previously we'd create a new font from the font file for every substitution.
This changes it so we create a "base" font object from the font file, then
substitutes are created by copying that font object.
This also addresses bug 705199
Constitutes the following:
Add a pdf_buffer object
Since the pdf_string/pdf_name rework, we can't use pdf_strings as a convenient
type for abitrary byte arrays which either might be more than 4k (static
analysis tools complain), or where the data buffer already exists, and isn't
being allocated as part of the pdf_string object.
So add a pdf_buffer for such situations. Also includes a function to (re)set the
data pointer and length in a pdf_buffer object. It's important to note that
once referenced by a pdf_buffer object, the data buffer is owned by the
pdf_buffer, and its lifetime is tied to the pdf_buffer object lifetime.
Revise pdf_font_truetype/pdf_cidfont_type2 to use pdf_buffer for their sfnt
data.
Have Type 1 Subr strings stored in a pdf array object
Expunge the old glyph "fake_names"...
...since we now have a "real" name table.
Clean up the CFF pdfi font objects
Move ToUnicode into pdf_font_base...
... rather than pdf_font_common - so it's in both CIDFonts and fonts.
Split out code for First/LastChar, MissingWidth and Widths array
so all font types use common code.
Add font object copying functions
For Type 1, CFF, and TTF fonts (NOT CIDFonts)
Cache substituted fonts
rather recreated on every substitution
Fix font copying to handle object num/generation
Handle multiple levels of lookup in fontmap
Fixes and tweaks in font copying/substituting changes
Don't pass font dict object for substitute font loading
Fix reference counting for file name string in font objects.
A few more font copying tweaks and fixes
Act on stoponerror for broken embedded fonts
Consolidate very similar functions
Diffstat (limited to 'pdf/pdf_font3.c')
-rw-r--r-- | pdf/pdf_font3.c | 63 |
1 files changed, 6 insertions, 57 deletions
diff --git a/pdf/pdf_font3.c b/pdf/pdf_font3.c index 0ca1431c0..708e7658e 100644 --- a/pdf/pdf_font3.c +++ b/pdf/pdf_font3.c @@ -223,6 +223,8 @@ int pdfi_free_font_type3(pdf_obj *font) pdfi_countdown(t3font->CharProcs); pdfi_countdown(t3font->Encoding); pdfi_countdown(t3font->ToUnicode); + pdfi_countdown(t3font->filename); /* Should never exist, but just in case */ + gs_free_object(OBJ_MEMORY(font), font, "Free type 3 font"); return 0; } @@ -230,10 +232,9 @@ int pdfi_free_font_type3(pdf_obj *font) int pdfi_read_type3_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream_dict, pdf_dict *page_dict, pdf_font **ppdffont) { - int code = 0, i, num_chars = 0; + int code = 0; pdf_font_type3 *font = NULL; pdf_obj *obj = NULL; - double f; pdf_obj *tounicode = NULL; *ppdffont = NULL; @@ -271,67 +272,15 @@ int pdfi_read_type3_font(pdf_context *ctx, pdf_dict *font_dict, pdf_dict *stream if (code < 0) goto font3_error; - code = pdfi_dict_get_number(ctx, font_dict, "FirstChar", &f); - if (code < 0) - goto font3_error; - font->FirstChar = (int)f; - code = pdfi_dict_get_number(ctx, font_dict, "LastChar", &f); - if (code < 0) - goto font3_error; - font->LastChar = (int)f; - - num_chars = (font->LastChar - font->FirstChar) + 1; code = pdfi_dict_knownget_type(ctx, font_dict, "FontDescriptor", PDF_DICT, (pdf_obj **)&font->FontDescriptor); if (code < 0) goto font3_error; - if (font->FontDescriptor != NULL) { - code = pdfi_dict_knownget(ctx, font->FontDescriptor, "MissingWidth", &obj); - if (code > 0) { - if (pdfi_type_of(obj) == PDF_INT) { - font->MissingWidth = (double)((pdf_num *) obj)->value.i; - } - else if (pdfi_type_of(obj) == PDF_REAL) { - font->MissingWidth = ((pdf_num *) obj)->value.d; - } - else { - font->MissingWidth = 0; - } - pdfi_countdown(obj); - obj = NULL; - } - else { - font->MissingWidth = 0; - } - } - else { - font->MissingWidth = 1000; - } - - code = pdfi_dict_knownget_type(ctx, font_dict, "Widths", PDF_ARRAY, (pdf_obj **)&obj); - if (code < 0) - goto font3_error; - if (code > 0) { - if (num_chars != pdfi_array_size((pdf_array *)obj)) { - code = gs_note_error(gs_error_rangecheck); - goto font3_error; - } + pdfi_font_set_first_last_char(ctx, font_dict, (pdf_font *)font); + /* ignore errors with widths... for now */ + (void)pdfi_font_create_widths(ctx, font_dict, (pdf_font*)font, 1.0); - font->Widths = (double *)gs_alloc_bytes(ctx->memory, sizeof(double) * num_chars, "type 3 font Widths array"); - if (font->Widths == NULL) { - code = gs_note_error(gs_error_VMerror); - goto font3_error; - } - memset(font->Widths, 0x00, sizeof(double) * num_chars); - for (i = 0; i < num_chars; i++) { - code = pdfi_array_get_number(ctx, (pdf_array *)obj, (uint64_t)i, &font->Widths[i]); - if (code < 0) - goto font3_error; - } - } - pdfi_countdown(obj); - obj = NULL; code = pdfi_dict_get(ctx, font_dict, "Encoding", &obj); if (code < 0) |