Description: Better processing of \pict including addition of EMF type
 Fixes "unrtf 0.21 outputs hex.junk to stdout".
Origin: backport, http://hg.savannah.gnu.org/hgweb/unrtf/raw-rev/ea8512202426,
 http://hg.savannah.gnu.org/hgweb/unrtf/raw-rev/cb5aa73f1c31
Bug-Debian: https://bugs.debian.org/745195
Forwarded: not-needed
Author: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2015-01-26
Applied-Upstream: 0.21.8

--- a/src/convert.c
+++ b/src/convert.c
@@ -163,8 +163,10 @@ enum {
 	PICT_WB,
 	PICT_JPEG,
 	PICT_PNG,
+	PICT_EMF,
 };
 static int within_picture=FALSE;
+static int within_picture_depth;
 static int picture_file_number=1;
 static char picture_path[255];
 static int picture_width;
@@ -2342,12 +2344,30 @@ static int cmd_maybe_ignore (Word *w, in
 		s = word_string(w->next);
 		if(s && strcmp(s, "\\shppict") == 0)
 			return(FALSE);
+		if(s && strcmp(s, "\\blipuid") == 0)
+			return(FALSE);
+		if(s && strcmp(s, "\\picprop") == 0)
+			return(FALSE);
 	}
 	
 	return TRUE;
 }
 
 /*========================================================================
+ * Name:	cmd_blipuid
+ * Purpose:	Dummy function to get rid of uid 
+ * Args:	Word, paragraph align info, and numeric param if any.
+ * Returns:	Flag, true only if rest of Words on line should be ignored.
+ *=======================================================================*/
+
+static int cmd_blipuid (Word *w, int align, char has_param, int param)
+{
+	char *s;
+	CHECK_PARAM_NOT_NULL (w);
+	return TRUE;
+}
+
+/*========================================================================
  * Name:	cmd_info
  * Purpose:	Executes the \info command.
  * Args:	Word, paragraph align info, and numeric param if any.
@@ -2373,6 +2393,18 @@ static int cmd_pict (Word *w, int align,
 	picture_type = PICT_WB;
 	return FALSE;		
 }
+/*========================================================================
+ * Name:	cmd_picprop
+ * Purpose:	Executes the \picprop
+ * Args:	Word, paragraph align info, and numeric param if any.
+ * Returns:	Flag, true only if rest of Words on line should be ignored.
+ *=======================================================================*/
+
+static int cmd_picprop (Word *w, int align, char has_param, int param)
+{
+	return TRUE;		
+}
+
 
 /*========================================================================
  * Name:	cmd_bin
@@ -2423,6 +2455,18 @@ static int cmd_pngblip (Word *w, int ali
 }
 
 /*========================================================================
+ * Name:	cmd_emfblip
+ * Purpose:	Executes the \emfblip command.
+ * Args:	Word, paragraph align info, and numeric param if any.
+ * Returns:	Flag, true only if rest of Words on line should be ignored.
+ *=======================================================================*/
+
+static int cmd_emfblip (Word *w, int align, char has_param, int param) {
+	picture_type = PICT_EMF;
+	return FALSE;		
+}
+
+/*========================================================================
  * Name:	cmd_pnmetafile
  * Purpose:	Executes the \pnmetafile command.
  * Args:	Word, paragraph align info, and numeric param if any.
@@ -2572,6 +2616,7 @@ static HashItem hashArray_b [] = {
 	{ "b", &cmd_b, NULL },
 	{ "bullet", &cmd_bullet, NULL },
 	{ "bin", &cmd_bin, "picture is binary" },
+	{ "blipuid", &cmd_blipuid, NULL },
 #if 0
 	{ "bgbdiag", NULL, NULL },
 	{ "bgcross", NULL, NULL },
@@ -2645,6 +2690,7 @@ static HashItem hashArray_e [] = {
 	{ "embo", &cmd_emboss, NULL },
 	{ "expand", &cmd_expand, NULL },
 	{ "expnd", &cmd_expand, NULL },
+	{ "emfblip", &cmd_emfblip, NULL },
 	{ NULL, NULL, NULL}
 };
 static HashItem hashArray_f [] = {
@@ -2713,10 +2759,12 @@ static HashItem hashArray_p [] = {
 	{ "pca", &cmd_pca , NULL },
 	{ "pich", &cmd_pich, NULL },
 	{ "pict", &cmd_pict, "picture" },
+	{ "picprop", &cmd_picprop, "picture properties" },
 	{ "picw", &cmd_picw, NULL },
 	{ "plain", &cmd_plain, NULL },
 	{ "pngblip", &cmd_pngblip, NULL },
 	{ "pnmetafile", &cmd_pnmetafile, NULL },
+	{ "emfblip", &cmd_emfblip, NULL },
 #if 0
 	{ "piccropb", NULL, NULL },
 	{ "piccropl", NULL, NULL },
@@ -3172,7 +3220,10 @@ word_print_core (Word *w, int groupdepth
 				}
 
 				/*----------------------------------------*/
-				if (within_picture) {
+				if (within_picture)
+				{
+					if (within_picture_depth == 0)
+					    within_picture_depth = groupdepth;
 					starting_body();
 					if (!pictfile && !nopict_mode) {
 						char *ext=NULL;
@@ -3184,6 +3235,7 @@ word_print_core (Word *w, int groupdepth
 						case PICT_PNG: ext="png"; break;
 						case PICT_DI: ext="dib"; break; /* Device independent bitmap=??? */
 						case PICT_PM: ext="pmm"; break; /* OS/2 metafile=??? */
+						case PICT_EMF: ext="emf"; break;  /* Enhanced MetaFile */
 						}
 						sprintf(picture_path, "pict%03d.%s", 
 							picture_file_number++,ext);
@@ -3434,8 +3486,11 @@ word_print_core (Word *w, int groupdepth
 			w = w->next;
 	}
 
-	if (within_picture) {
-		if(pictfile) { 
+	if (within_picture && within_picture_depth == groupdepth)
+	{
+		within_picture_depth = 0;
+		if(pictfile)
+		{ 
 			fclose(pictfile);
 			if (safe_printf(0, op->imagelink_begin)) fprintf(stderr, TOO_MANY_ARGS, "imagelink_begin");
 			printf("%s", picture_path);
@@ -3490,14 +3545,9 @@ word_print (Word *w)
 	CHECK_PARAM_NOT_NULL (w);
 
 	if (!inline_mode) {
-#if 1 /* AK3 - AF */
 		if (safe_printf(0, op->document_begin)) fprintf(stderr, TOO_MANY_ARGS, "document_begin");
 		if (safe_printf(0, op->header_begin)) fprintf(stderr, TOO_MANY_ARGS, "header_begin");
 		if (safe_printf(0, op->utf8_encoding)) fprintf(stderr, TOO_MANY_ARGS, "utf8_encoding");
-#else
-		printf(op->document_begin);
-		printf(op->header_begin);
-#endif
 	}
 
 	print_banner ();
@@ -3510,12 +3560,7 @@ word_print (Word *w)
 	end_table();
 
 	if (!inline_mode) {
-#if 1 /* AK3 - AF */
 		if (safe_printf(0, op->body_end)) fprintf(stderr, TOO_MANY_ARGS, "body_end");
 		if (safe_printf(0, op->document_end)) fprintf(stderr, TOO_MANY_ARGS, "document_end");
-#else
-		printf(op->body_end);
-		printf(op->document_end);
-#endif
 	}
 }
