poppler/CairoFontEngine.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
New commits: commit 773e2d4a42757c440855f6260b9dcf15cf85a74a Author: Oliver Sander <[email protected]> Date: Mon Mar 7 14:29:32 2022 +0100 Let type3_font_info_t have a constructor that takes all information diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc index 2133a77c..1c892165 100644 --- a/poppler/CairoFontEngine.cc +++ b/poppler/CairoFontEngine.cc @@ -550,6 +550,8 @@ static const cairo_user_data_key_t type3_font_key = { 0 }; typedef struct _type3_font_info { + _type3_font_info(GfxFont *fontA, PDFDoc *docA, CairoFontEngine *fontEngineA, bool printingA, XRef *xrefA) : font(fontA), doc(docA), fontEngine(fontEngineA), printing(printingA), xref(xrefA) { } + GfxFont *font; PDFDoc *doc; CairoFontEngine *fontEngine; @@ -667,17 +669,12 @@ CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, PDFDoc *doc, CairoFontE char *name; charProcs = ((Gfx8BitFont *)gfxFont)->getCharProcs(); - type3_font_info_t *info = new type3_font_info_t(); ref = *gfxFont->getID(); font_face = cairo_user_font_face_create(); cairo_user_font_face_set_init_func(font_face, _init_type3_glyph); cairo_user_font_face_set_render_glyph_func(font_face, _render_type3_glyph); gfxFont->incRefCnt(); - info->font = gfxFont; - info->doc = doc; - info->fontEngine = fontEngine; - info->printing = printing; - info->xref = xref; + type3_font_info_t *info = new type3_font_info_t(gfxFont, doc, fontEngine, printing, xref); cairo_font_face_set_user_data(font_face, &type3_font_key, (void *)info, _free_type3_font_info); commit 47ba2b0dfc7a997ba159a39769ff0edf99e08cdc Author: Oliver Sander <[email protected]> Date: Mon Mar 7 14:22:12 2022 +0100 Use new/delete for class type3_font_info_t In a later commit I want to change type3_font_info_t and make it contain types with non-trivial destructors. However, these destructors are only called when the destructor of type3_font_info_t is called. And this only happens if type3_font_info_t is deleted with 'delete', not with 'free'. diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc index 976f6622..2133a77c 100644 --- a/poppler/CairoFontEngine.cc +++ b/poppler/CairoFontEngine.cc @@ -31,7 +31,7 @@ // Copyright (C) 2018 Adam Reichold <[email protected]> // Copyright (C) 2019 Christian Persch <[email protected]> // Copyright (C) 2020 Michal <[email protected]> -// Copyright (C) 2021 Oliver Sander <[email protected]> +// Copyright (C) 2021, 2022 Oliver Sander <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -562,7 +562,7 @@ static void _free_type3_font_info(void *closure) type3_font_info_t *info = (type3_font_info_t *)closure; info->font->decRefCnt(); - free(info); + delete info; } static cairo_status_t _init_type3_glyph(cairo_scaled_font_t *scaled_font, cairo_t *cr, cairo_font_extents_t *extents) @@ -657,7 +657,6 @@ static cairo_status_t _render_type3_glyph(cairo_scaled_font_t *scaled_font, unsi CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, PDFDoc *doc, CairoFontEngine *fontEngine, bool printing, XRef *xref) { - type3_font_info_t *info; cairo_font_face_t *font_face; Ref ref; int *codeToGID; @@ -668,7 +667,7 @@ CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, PDFDoc *doc, CairoFontE char *name; charProcs = ((Gfx8BitFont *)gfxFont)->getCharProcs(); - info = (type3_font_info_t *)malloc(sizeof(*info)); + type3_font_info_t *info = new type3_font_info_t(); ref = *gfxFont->getID(); font_face = cairo_user_font_face_create(); cairo_user_font_face_set_init_func(font_face, _init_type3_glyph);
