summaryrefslogtreecommitdiff
path: root/Build/source/texk/dviout-util/dvispc.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dviout-util/dvispc.c')
-rw-r--r--Build/source/texk/dviout-util/dvispc.c76
1 files changed, 49 insertions, 27 deletions
diff --git a/Build/source/texk/dviout-util/dvispc.c b/Build/source/texk/dviout-util/dvispc.c
index 1f4face7df3..eecd552fdb1 100644
--- a/Build/source/texk/dviout-util/dvispc.c
+++ b/Build/source/texk/dviout-util/dvispc.c
@@ -253,12 +253,15 @@ char *out_pages ="T-L";
int total_book_page;
/* non-stack specials */
-int f_background = 0;
char background[MAX_LEN];
-int f_pdf_bgcolor = 0;
+int f_background = 0; /* in each page, 0: not found; 1: found */
char pdf_bgcolor[MAX_LEN];
-int f_pn = 0;
+int f_pdf_bgcolor = 0; /* in each page, 0: not found; 1: found */
char tpic_pn[MAX_LEN];
+char tpic_pn_prev[MAX_LEN];
+int f_pn = 0; /* in each page, 0: not found and not actually used;
+ 1: found before actual use
+ -1: not found before actual use */
/* stack specials */
int color_depth;
@@ -897,7 +900,7 @@ lastpage: if(isdigit(*++out_pages)){
fseek(dvi->file_ptr, 0, SEEK_SET);
for(size = dim->page_index[1]; size > 0; size--)
write_byte(read_byte(dvi->file_ptr), fp); /* Write preamble */
- /* [Process 1] start the first page */
+ /* [Process 1] Start writing the first page. */
current = ftell(fp); /* position of 1-st BOP */
for(size = 41; size > 0; size--) /* Write BOP and c[] */
write_byte(read_byte(dvi->file_ptr), fp);
@@ -906,9 +909,8 @@ lastpage: if(isdigit(*++out_pages)){
for(page = 1; page <= dim->total_page; page++){ /* page loop start */
fseek(dvi->file_ptr, dim->page_index[page], SEEK_SET);
- f_background = 0;
- f_pdf_bgcolor = 0;
- pos = interpret(dvi->file_ptr); /* pos = position of EOP + 1 */
+ pos = interpret(dvi->file_ptr); /* scanned the whole page content; now
+ pos = position of EOP + 1 */
if(f_debug){
fprintf(fp_out, "[%d]", page);
/* if(page <= dim->total_page){ */ /* always true inside loop */
@@ -929,45 +931,63 @@ lastpage: if(isdigit(*++out_pages)){
fprintf(fp_out, "\n%d:%s", count+1, pdf_color_pt[count]);
for(count = 0; count < pdf_annot_depth; count++)
fprintf(fp_out, "\n%d:%s", count+1, pdf_annot_pt[count]);
- if(tpic_pn[0] && f_pn < 0){
- fprintf(fp_out, "\n%s", tpic_pn);
- flag++;
+ if(f_pn < 0){
+ if(!tpic_pn_prev[0])
+ fprintf(stderr, "Cannot find valid tpic pn.\n"
+ "Please check your LaTeX source.\n");
+ else{
+ fprintf(fp_out, "\n%s", tpic_pn_prev);
+ flag++;
+ }
}
if(flag){
- fprintf(fp_out, "\n");
- f_needs_corr++;
+ fprintf(fp_out, "\n"); /* at least one special printed */
+ f_needs_corr += flag;
}
/* } */
+ if(tpic_pn[0]) /* save current status of tpic_pn */
+ strncpy(tpic_pn_prev, tpic_pn, MAX_LEN);
}
if(f_mode == EXE2CHECK)
continue; /* skip loop if (f_mode == EXE2CHECK);
* remainings in this loop are for (f_mode == EXE2MODIFY) */
- /* [Process 2] at the beginning of each page,
- recover from stack underflow, and put non-stack specials if necessary */
- while(color_under > 0){ /* recover underflow of color stack */
+ /* [Process 2] At the beginning of each page,
+ put non-stack specials if necessary.
+ Also, if the page is suffering from stack underflow,
+ open lacking stacks beforehand */
+ while(color_under > 0){ /* recover underflow of color stack */
write_sp(fp, "color push Black");
f_needs_corr++;
color_under--;
}
- while(pdf_color_under > 0){ /* recover underflow of pdf:bcolor ... pdf:ecolor stack */
+ while(pdf_color_under > 0){ /* recover underflow of pdf:bcolor ... pdf:ecolor stack */
write_sp(fp, "pdf:bcolor [0]");
f_needs_corr++;
pdf_color_under--;
}
- if(background[0] && !f_background){ /* no background in this page */
+ if(background[0] && !f_background){ /* background from the former page is effective */
write_sp(fp, background);
f_needs_corr++;
}
- if(pdf_bgcolor[0] && !f_pdf_bgcolor){ /* no pdf:bgcolor in this page */
+ if(pdf_bgcolor[0] && !f_pdf_bgcolor){ /* pdf:bgcolor from the former page is effective */
write_sp(fp, pdf_bgcolor);
f_needs_corr++;
}
-// while(pdf_annot_under > 0){ /* recover underflow of pdf:bann ... pdf:eann stack */
+// while(pdf_annot_under > 0){ /* recover underflow of pdf:bann ... pdf:eann stack */
// /* [TODO] what should we do here? */
// f_needs_corr++;
// pdf_annot_under--;
// }
+ if(f_pn < 0) { /* tpic_pn from the former page is effective */
+ if(!tpic_pn_prev[0])
+ fprintf(stderr, "\nCannot find valid tpic pn."
+ "\nPlease check your LaTeX source.");
+ else{
+ write_sp(fp, tpic_pn_prev);
+ f_needs_corr++;
+ }
+ }
/* [Process 3] write contents of the current page */
fseek(dvi->file_ptr, dim->page_index[page]+45, SEEK_SET);
@@ -1005,15 +1025,15 @@ lastpage: if(isdigit(*++out_pages)){
write_sp(fp, pdf_color_pt[count]);
// for(count = 0; count < pdf_annot_depth; count++)
// write_sp(fp, pdf_annot_pt[count]);
- if(tpic_pn[0]) {
- write_sp(fp, tpic_pn);
- f_needs_corr++;
- }
f_needs_corr += color_depth;
f_needs_corr += pdf_color_depth;
// f_needs_corr += pdf_annot_depth;
- if(tpic_pn[0])
- f_needs_corr++;
+ /* Special case for tpic_pn:
+ save current status of tpic_pn now, before it is (probably)
+ overwritten after scanning the whole next page.
+ Note that pn can have different values in the same page! */
+ if(tpic_pn[0]) /* save current status of tpic_pn */
+ strncpy(tpic_pn_prev, tpic_pn, MAX_LEN);
}
} /* page loop end */
@@ -1270,6 +1290,9 @@ int strsubcmp_n(char *s, char *t)
uint s_work(FILE *dvi)
{
int code, mode, tmp = 0;
+ f_background = 0;
+ f_pdf_bgcolor = 0;
+ f_pn = 0;
while ((code = (uchar)read_byte(dvi)) != EOP){
if(code >= 128){
@@ -1328,8 +1351,7 @@ skip: while (tmp--)
f_pn = 1;
}else if(!f_pn &&
(!strsubcmp(special, "pa") || /* pa: tpic pen at */
- !strsubcmp(special, "ar") || /* ar: draw circle */
- !strsubcmp(special, "ia")) ) /* ia: fill */
+ !strsubcmp(special, "ar")) ) /* ar: draw circle */
f_pn = -1;
else if(!strsubcmp(special, "color")) /* color push/pop */
sp_color(special);