ref: 8f2d8d661e4230e61e095e336f1b14c739b62ba0
parent: 51ae6b8a96296c1aab50df9d8cee662d09f155bf
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Thu Nov 6 13:08:48 EST 2003
Fix a bug with text region rendering in the Patent.pdf example file from the adobe's encoder. The problem was that we weren't handling the export/import of symbols from dictionaries referred to by the symbol dictionaries referred to by the text region segment. This patch is just a quick fix: we recurse when building the list of referred to symbol dictionaries at text region decode time, which allows us to get at all the symbols. This works because the adobe encoder (at least in this file) always exports all the symbols, imported and encoded, in each dictionary. If it did not, we would have offset errors in the symbol lookup. A proper fix requires decoding the exported symbol flags and building an export version of SBSYMS to store in the segment result that includes the symbols imported from any other dictionaries. All while intelligently sharing the decoded glyph data, of course. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@285 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -289,8 +289,10 @@
for (index = 0; index < segment->referred_to_segment_count; index++) {
rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
- if (rsegment && ((rsegment->flags & 63) == 0))
+ if (rsegment && ((rsegment->flags & 63) == 0)) {
n_dicts++;
+ n_dicts+= count_referred_dicts(ctx, rsegment);
+ }
}
return (n_dicts);
@@ -302,7 +304,7 @@
{
int index;
Jbig2Segment *rsegment;
- Jbig2SymbolDict **dicts;
+ Jbig2SymbolDict **dicts, **rdicts;
int n_dicts = count_referred_dicts(ctx, segment);
int dindex = 0;
@@ -309,8 +311,25 @@
dicts = jbig2_alloc(ctx->allocator, sizeof(Jbig2SymbolDict *) * n_dicts);
for (index = 0; index < segment->referred_to_segment_count; index++) {
rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
- if (rsegment && ((rsegment->flags & 63) == 0))
+ if (rsegment && ((rsegment->flags & 63) == 0)) {
+ /* recurse for imported symbols */
+ int j, n_rdicts = count_referred_dicts(ctx, rsegment);
+ if (n_rdicts > 0) {
+ rdicts = list_referred_dicts(ctx, rsegment);
+ for (j = 0; j < n_rdicts; j++)
+ dicts[dindex++] = rdicts[j];
+ jbig2_free(ctx->allocator, rdicts);
+ }
+ /* add this referred to symbol dictionary */
dicts[dindex++] = (Jbig2SymbolDict *)rsegment->result;
+ }
+ }
+
+ if (dindex != n_dicts) {
+ /* should never happen */
+ jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "counted %d symbol dictionaries but build a list with %d.\n",
+ n_dicts, dindex);
}
return (dicts);