summaryrefslogtreecommitdiff
path: root/pxl
diff options
context:
space:
mode:
authorHenry Stiles <henry.stiles@artifex.com>2009-08-14 05:27:29 +0000
committerHenry Stiles <henry.stiles@artifex.com>2009-08-14 05:27:29 +0000
commit6087a76325b0959b23ca07486e20cf59d5c24e15 (patch)
tree8eac893ed6c25168afd2a33f3722b24c32538a7b /pxl
parent02e4d163028d453cd37d99f8c9df91b6f6424dd5 (diff)
Fixes part of bug #690704. There was a reference counting problem
with producing the PXL error page. In fact, the problem was part of a deprecated text API, so we moved forward to the later text (gstext.h) API for the error page. Also the commit includes some simplification, the code really did not require allocating all the resource for the error page at the beginning of the job. The added complexity was not worth the benefit in this case. git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@9993 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'pxl')
-rw-r--r--pxl/pxerrors.c142
-rw-r--r--pxl/pxstate.c9
-rw-r--r--pxl/pxstate.h1
-rw-r--r--pxl/pxtop.c2
4 files changed, 67 insertions, 87 deletions
diff --git a/pxl/pxerrors.c b/pxl/pxerrors.c
index 68f4b4d7d..a3e4f598a 100644
--- a/pxl/pxerrors.c
+++ b/pxl/pxerrors.c
@@ -10,18 +10,6 @@
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, (415)492-9861, for further information. */
/*$Id$ */
-/* Portions Copyright (C) 2001 artofcode LLC.
- Portions Copyright (C) 1996, 2001 Artifex Software Inc.
- Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
- This software is based in part on the work of the Independent JPEG Group.
- All Rights Reserved.
-
- This software is distributed under license and may not be copied, modified
- or distributed except as expressly authorized under the terms of that
- license. Refer to licensing information at http://www.artifex.com/ or
- contact Artifex Software, Inc., 101 Lucas Valley Road #110,
- San Rafael, CA 94903, (415)492-9861, for further information. */
-/*$Id$ */
/* pxerrors.c */
/* PCL XL error reporting */
@@ -55,44 +43,40 @@ px_operator_proc(pxSetPageDefaultCTM);
/* ---------------- Initialization ---------------- */
-/* Create the error page font, and preallocate other structures so that */
-/* printing an error message never needs to allocate storage. */
-int
-pxerrors_init(px_state_t *pxs)
-{ px_font_t *pxfont = pl_alloc_font(pxs->memory, "error_page_font");
- gs_show_enum *penum = gs_show_enum_alloc(pxs->memory, pxs->pgs,
- "error_page_show_enum");
- int code;
-
- if ( pxfont == 0 || penum == 0 )
- code = gs_note_error(errorInsufficientMemory);
- else
- { pxfont->storage = pxfsInternal;
- pxfont->font_type = plft_Unicode; /* as good as any */
- pxfont->data_are_permanent = true;
- code =
- px_define_font(pxfont, (byte *)px_bitmap_font_header,
- px_bitmap_font_header_size,
- gs_next_ids(pxs->memory, 1),
- pxs);
- { const byte *cdata = px_bitmap_font_char_data;
- while ( *cdata && code >= 0 )
- { code = pl_font_add_glyph(pxfont, *cdata, cdata + 1);
- ++cdata;
- cdata = cdata + 16 +
- ((uint16at(cdata + 10, true) + 7) >> 3) *
- uint16at(cdata + 12, true);
- }
- }
- }
- if ( code < 0 )
- { gs_free_object(pxs->memory, penum, "pxs->error_page_show_enum");
- gs_free_object(pxs->memory, pxfont, "pxs->error_page_font");
- return code;
- }
- pxs->error_page_font = pxfont;
- pxs->error_page_show_enum = penum;
- return 0;
+/* set the font for the error page */
+static px_font_t *
+px_error_setfont(px_state_t *pxs)
+{
+ int code;
+ px_font_t *pxfont = pl_alloc_font(pxs->memory, "px_error_setfont");
+
+ if (pxfont == 0)
+ return NULL;
+
+ pxfont->storage = pxfsInternal;
+ pxfont->font_type = plft_Unicode; /* as good as any */
+ pxfont->data_are_permanent = true;
+ code = px_define_font(pxfont, (byte *)px_bitmap_font_header,
+ px_bitmap_font_header_size,
+ gs_next_ids(pxs->memory, 1),
+ pxs);
+ {
+ const byte *cdata = px_bitmap_font_char_data;
+ while ( *cdata && code >= 0 ) {
+ code = pl_font_add_glyph(pxfont, *cdata, cdata + 1);
+ ++cdata;
+ cdata = cdata + 16 +
+ ((uint16at(cdata + 10, true) + 7) >> 3) *
+ uint16at(cdata + 12, true);
+ }
+ }
+ if ( code < 0 ) {
+ pl_free_font(pxs->memory, pxfont, "px_error_setfont");
+ return NULL;
+ }
+ gs_setfont(pxs->pgs, pxfont->pfont);
+ pxfont->pfont->FontMatrix = pxfont->pfont->orig_FontMatrix;
+ return pxfont;
}
/* ---------------- Procedures ---------------- */
@@ -249,12 +233,9 @@ px_begin_error_page(px_state_t *pxs)
/*pxSetPageDefaultCTM(NULL, pxs);*/
{
gs_point pt;
- gs_font *pfont = pxs->error_page_font->pfont;
px_get_default_media_size(pxs, &pt);
gs_translate(pgs, 0.0, pt.y);
gs_scale(pgs, 1.0, -1.0);
- gs_setfont(pgs, pfont);
- pfont->FontMatrix = pfont->orig_FontMatrix;
return 90;
}
}
@@ -263,37 +244,46 @@ px_begin_error_page(px_state_t *pxs)
/* Return the updated Y value. */
int
px_error_page_show(const char *message, int ytop, px_state_t *pxs)
-{ gs_state *pgs = pxs->pgs;
- int y = ytop;
- const char *m = message;
- const char *p;
- gs_show_enum *penum = pxs->error_page_show_enum;
- /* Normalize for a 10-point font. */
+{
+ gs_state *pgs = pxs->pgs;
+ int y = ytop;
+ const char *m = message;
+ const char *p;
+ gs_text_enum_t *penum;
+ gs_text_params_t text;
+ int code;
+ /* Normalize for a 10-point font. */
#define point_size 10.0
- double scale = 72.0 / px_bitmap_font_resolution *
- point_size / px_bitmap_font_point_size;
- int code = 0;
+ double scale = 72.0 / px_bitmap_font_resolution *
+ point_size / px_bitmap_font_point_size;
+ px_font_t *pxfont = px_error_setfont(pxs);
+
+ if ( pxfont == NULL )
+ return_error(errorInsufficientMemory);
- /* Peel off the next line and display it. */
- for ( p = m; ; m = ++p )
- { while ( *p != 0 && *p != '\n' )
- ++p;
+ text.operation = TEXT_FROM_STRING | TEXT_DO_DRAW | TEXT_RETURN_WIDTH;
+ /* Peel off the next line and display it. */
+ for ( p = m; ; m = ++p )
+ { while ( *p != 0 && *p != '\n' )
+ ++p;
gs_moveto(pgs, 36.0, y);
gs_scale(pgs, scale, scale);
- code = gs_show_n_init(penum, pgs, m, p - m);
- if ( code >= 0 )
- { code = gs_show_next(penum);
+ text.data.chars = (gs_char *)m;
+ text.size = p - m;
+ code = gs_text_begin(pgs, &text, pxs->memory, &penum);
+ if ( code >= 0 ) {
+ code = gs_text_process(penum);
if ( code > 0 )
- code = gs_note_error(errorBadFontData); /* shouldn't happen! */
- }
- if ( code < 0 )
- gs_show_enum_release(penum, NULL);
+ code = gs_note_error(errorBadFontData); /* shouldn't happen! */
+ gs_text_release(penum, "pxtext");
+ }
gs_scale(pgs, 1 / scale, 1 / scale);
y += point_size * 8 / 5;
if ( !*p || !p[1] )
- break;
- }
- return (code < 0 ? code : y);
+ break;
+ }
+ pl_free_font(pxs->memory, pxfont, "px_error_page_show");
+ return (code < 0 ? code : y);
}
/* Reset the warning table. */
diff --git a/pxl/pxstate.c b/pxl/pxstate.c
index 8d37d9991..858e60f53 100644
--- a/pxl/pxstate.c
+++ b/pxl/pxstate.c
@@ -59,15 +59,8 @@ px_state_alloc(gs_memory_t *memory)
void
px_state_release(px_state_t *pxs)
{
- px_value_t val = {0}; /* arbitrary */
- /* delete the pxl error page and error page enumeration, the
- following deletes the font without having to import the font
- freeing procedure. We add the font to the font dictionary and
- then release all of the fonts */
- px_dict_put(&pxs->font_dict, &val, pxs->error_page_font);
+ /* free the font dictionary */
px_dict_release(&pxs->font_dict);
- gs_free_object(pxs->memory, pxs->error_page_show_enum,
- "px_state_release(pxs->error_page_show_enum)");
/* Don't free pxgs since it'll get freed as pgs' client */
gs_free_object(pxs->memory, pxs, "px_state_release");
}
diff --git a/pxl/pxstate.h b/pxl/pxstate.h
index 14c4ec389..ce79284f9 100644
--- a/pxl/pxstate.h
+++ b/pxl/pxstate.h
@@ -128,7 +128,6 @@ struct px_state_s {
/* Global structures */
gs_font_dir *font_dir;
px_font_t *error_page_font;
- gs_show_enum *error_page_show_enum;
/* Graphics state */
diff --git a/pxl/pxtop.c b/pxl/pxtop.c
index 67a48ae74..a80faa79f 100644
--- a/pxl/pxtop.c
+++ b/pxl/pxtop.c
@@ -44,11 +44,9 @@
typedef int (*px_init_proc) ( px_state_t * );
int pxfont_init(px_state_t *pxs );
-int pxerrors_init(px_state_t *pxs );
const px_init_proc px_init_table[] = {
&pxfont_init,
- &pxerrors_init,
0
};