Commit Diff


commit - fa8f1e7fdae47c124d217edb3ef5a572fe8bde54
commit + dae44186d68958fc415607eb19d24d7befb178d7
blob - 8c4789e3ee82116b33fb707ce2326d534449ab33
blob + b049715f67ae624bd8c152fcaa2f30b82d0364c1
--- pdf.c
+++ pdf.c
@@ -2183,7 +2183,6 @@ text_extract(struct Env *aux, const char *outfn, const
 {
 	FILE *stream, *stream2;
 	struct textnode *cur;
-	const HParsedToken *tt_text;
 
 	// open the files for writing
 	if (outfn && !(stream = fopen(outfn, "w")))
@@ -2192,26 +2191,31 @@ text_extract(struct Env *aux, const char *outfn, const
 		err(2, "%s", outfn2);
 
 	for (cur = aux->txthead; cur != NULL; cur = cur->next) {
-		tt_text = cur->tstr->tobj;
-		for (int j = 0; j < tt_text->seq->used; j++) {
-			struct textstr *tstr = NULL;
-			TextEntry *txte = H_CAST(TextEntry, tt_text->seq->elements[j]);
+		if (outfn)
+			fwrite(cur->tstr->text, 1, cur->tstr->nchars, stream);
 
-			switch (txte->type) {
-			case TW_Tj:
-			case TW_Tq:
-			case TW_Tqq:
-				tstr = &txte->tstr;
-				break;
-			case TW_TJ:
-				tstr = &txte->tarray.flattened;
-				break;
-			default:
-				continue;
-			}
-			assert(tstr != NULL);
+		if (outfn2) {
+			const HParsedToken *tt_text = cur->tstr->tobj;
+
+			for (int j = 0; j < tt_text->seq->used; j++) {
+				struct textstr *tstr = NULL;
+				TextEntry *txte = H_CAST(TextEntry,
+				    tt_text->seq->elements[j]);
 
-			if (outfn2) {
+				switch (txte->type) {
+				case TW_Tj:
+				case TW_Tq:
+				case TW_Tqq:
+					tstr = &txte->tstr;
+					break;
+				case TW_TJ:
+					tstr = &txte->tarray.flattened;
+					break;
+				default:
+					continue;
+				}
+				assert(tstr != NULL);
+
 				Fontinfo_T *ft = lookup_font(&txte->node->ts, aux);
 				if (ft)
 					pp_fontinfo(stream2, &txte->node->ts, ft);
@@ -2219,8 +2223,6 @@ text_extract(struct Env *aux, const char *outfn, const
 					fputs("\nMissing Font Info!!\n", stream2);
 				fwrite(tstr->text, 1, tstr->nchars, stream2);
 			}
-			if (outfn)
-				fwrite(tstr->text, 1, (size_t)tstr->nchars, stream);
 		}
 	}