From: Ruslan Shevchenko <Ruslan Shevchenko Kiev UA>
To: dia-list gnome org
Subject: problem with pstrick and patch
Date: Fri, 04 Jan 2002 04:54:23 +0200
Good day.
1. Exists one problem with export to pstrick in dia:
when text string in diagram include TeX special symbol
(for example, '#' - mark for protected data in UML Class diagrams)
TeX breaks.
So, here (attached) is the patch against dia-0.88.1
2. I still can't see text entries in resulting TeX file.
Are anybody have working example of UML class diagram,
exported to TeX pstricks ?
--
Ruslan Shevchenko
GradSoft: Chief Software Architect
http://www.gradsoft.com.ua/eng/
diff -udr dia-0.88.1/plug-ins/pstricks/render_pstricks.c dia-0.88.1.patched/plug-ins/pstricks/render_pstricks.c
--- dia-0.88.1/plug-ins/pstricks/render_pstricks.c Mon Mar 26 04:05:23 2001
+++ dia-0.88.1.patched/plug-ins/pstricks/render_pstricks.c Fri Jan 4 04:28:22 2002
@@ -45,6 +45,7 @@
#include <string.h>
#include <time.h>
#include <math.h>
+#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -649,12 +650,89 @@
fprintf(renderer->file, "\\fill[fillstyle=solid,fillcolor=diafillcolor,linecolor=diafillcolor]}\n");
}
+/*
+ * return number of characters, needed to be added to length of resulted TeX
+ * output with char ch.
+ * return 0 means, that we can do not touch ch for TeX,
+ * otherwise we must output prefix (setted in this function) and
+ * if replace is true -> output char ch itself.
+ *
+ * memory: note, that prefix is setted to static string.
+ */
+static int is_tex_escaped_symbol(char ch,
+ char** prefix,
+ int* replace)
+{
+ switch(ch) {
+ case '#':
+ case '$':
+ case '%':
+ case '&':
+ case '~':
+ case '_':
+ case '^':
+ case '\\':
+ case '{':
+ case '}':
+ *prefix="\\";
+ *replace=0;
+ return 1;
+ case '\xBB': /* '<<' -> '{$\langle\!\langle$}' */
+ *prefix="{$\\langle\\!\\langle$}";
+ *replace=1;
+ return strlen(*prefix)-1;
+ case '\xAB': /* '>>' -> '{$\rangle\!\rangle$}' */
+ *prefix="{$\\rangle\\!\\rangle$}";
+ *replace=1;
+ return strlen(*prefix)-1;
+ default:
+ return 0;
+ }
+}
+
+/**
+ * create string, in which TeX symbols are escaped by '\' symbol
+ * or substituted by tex control sequences.
+ * (example: #xxx -> \#xxx
+ * memory is allocated inside function, so client must free received pointer
+ **/
+static char* create_tex_escaped_string(const char* in_text)
+{
+ /* count number of symbols to escaped */
+ int extra_count = 0;
+ const char* in_cursor;
+ char* out_cursor;
+ char* out_text;
+ char* prefix;
+ int replace=0;
+ for(in_cursor=in_text;*in_cursor; ++in_cursor) {
+ extra_count+=is_tex_escaped_symbol(*in_cursor,&prefix,&replace);
+ }
+ /* now alloc memory and print prefixed escaped string */
+ out_text = malloc(strlen(in_text)+extra_count+1);
+ out_cursor=out_text;
+ for(in_cursor=in_text;*in_cursor;) {
+ if (is_tex_escaped_symbol(*in_cursor,&prefix,&replace)) {
+ while(*prefix) *out_cursor++ = *prefix++;
+ }
+ if (!replace) {
+ *out_cursor++=*in_cursor++;
+ }else{
+ in_cursor++;
+ }
+ }
+ *out_cursor++='\0';
+ return out_text;
+}
+
static void
draw_string(RendererPSTRICKS *renderer,
const char *text,
Point *pos, Alignment alignment,
Color *color)
{
+ char* tex_escaped_text;
+
set_line_color(renderer,color);
fprintf(renderer->file,"\\rput");
@@ -668,7 +746,12 @@
fprintf(renderer->file,"[r]");
break;
}
- fprintf(renderer->file,"(%f,%f){\\scalebox{1 -1}{%s}}\n",pos->x, pos->y,text);
+
+ tex_escaped_text=create_tex_escaped_string(text);
+
+ fprintf(renderer->file,"(%f,%f){\\scalebox{1 -1}{%s}}\n",pos->x, pos->y,tex_escaped_text);
+
+ free(tex_escaped_text);
}
static void