From b79dd6ae4d3baac68fe5832062f6e35a621bc923 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 2 Oct 2018 01:01:17 +0000 Subject: Fixed a bug in MetaPost PostScript handling (S. Hirata) [recommitting 48797 from kakuto] git-svn-id: svn://tug.org/texlive/trunk@48797 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/mpost.c | 70 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'Build/source/texk/dvipdfm-x/mpost.c') diff --git a/Build/source/texk/dvipdfm-x/mpost.c b/Build/source/texk/dvipdfm-x/mpost.c index b38c44b9fcf..f583de88308 100644 --- a/Build/source/texk/dvipdfm-x/mpost.c +++ b/Build/source/texk/dvipdfm-x/mpost.c @@ -95,9 +95,24 @@ static struct mp_font } font_stack[PDF_GSAVE_MAX] = { {NULL, -1, -1, -1, 0} }; -static int currentfont = -1; +static int currentfont = 0; #define CURRENT_FONT() ((currentfont < 0) ? NULL : &font_stack[currentfont]) +#define FONT_DEFINED(f) ((f) && (f)->font_name && ((f)->font_id >= 0)) + +static void +clear_mp_font_struct (struct mp_font *font) +{ + ASSERT(font); + + if (font->font_name) + RELEASE(font->font_name); + font->font_name = NULL; + font->font_id = -1; + font->tfm_id = -1; + font->subfont_id = -1; + font->pt_size = 0.0; +} /* Compatibility */ #define MP_CMODE_MPOST 0 @@ -115,17 +130,6 @@ mp_setfont (const char *font_name, double pt_size) font = CURRENT_FONT(); - if (font) { - if (!strcmp(font->font_name, font_name) && - font->pt_size == pt_size) - return 0; - } else { /* No currentfont */ -/* ***TODO*** Here some problem exists! */ - font = &font_stack[0]; - font->font_name = NULL; - currentfont = 0; - } - mrec = pdf_lookup_fontmap_record(font_name); if (mrec && mrec->charmap.sfd_name && mrec->charmap.subfont_id) { subfont_id = sfd_load_record(mrec->charmap.sfd_name, mrec->charmap.subfont_id); @@ -161,23 +165,22 @@ save_font (void) { struct mp_font *current, *next; - if (currentfont < 0) { - font_stack[0].font_name = NEW(strlen("Courier") + 1, char); - strcpy(font_stack[0].font_name, "Courier"); - font_stack[0].pt_size = 1; - font_stack[0].tfm_id = 0; - font_stack[0].subfont_id = 0; - currentfont = 0; - } - current = &font_stack[currentfont++]; next = &font_stack[currentfont ]; - next->font_name = NEW(strlen(current->font_name)+1, char); - strcpy(next->font_name, current->font_name); - next->pt_size = current->pt_size; - - next->subfont_id = current->subfont_id; - next->tfm_id = current->tfm_id; + if (FONT_DEFINED(current)) { + next->font_name = NEW(strlen(current->font_name)+1, char); + strcpy(next->font_name, current->font_name); + next->font_id = current->font_id; + next->pt_size = current->pt_size; + next->subfont_id = current->subfont_id; + next->tfm_id = current->tfm_id; + } else { + next->font_name = NULL; + next->font_id = -1; + next->pt_size = 0.0; + next->subfont_id = -1; + next->tfm_id = -1; + } } static void @@ -187,11 +190,7 @@ restore_font (void) current = CURRENT_FONT(); if (current) { - if (current->font_name) - RELEASE(current->font_name); - current->font_name = NULL; - } else { - ERROR("No currentfont..."); + clear_mp_font_struct(current); } currentfont--; @@ -201,8 +200,7 @@ static void clear_fonts (void) { while (currentfont >= 0) { - if (font_stack[currentfont].font_name) - RELEASE(font_stack[currentfont].font_name); + clear_mp_font_struct(&font_stack[currentfont]); currentfont--; } } @@ -748,7 +746,7 @@ do_currentfont (void) pdf_obj *font_dict; font = CURRENT_FONT(); - if (!font) { + if (!FONT_DEFINED(font)) { WARN("Currentfont undefined..."); return 1; } else { @@ -785,7 +783,7 @@ do_show (void) double text_width; font = CURRENT_FONT(); - if (!font) { + if (!FONT_DEFINED(font)) { WARN("Currentfont not set."); /* Should not be error... */ return 1; } -- cgit v1.2.3