TeX output for UML diagrams [path]
- From: Ruslan Shevchenko <ruslan shevchenko kiev ua>
- To: dia-list gnome org, Ruslan Shevchenko <ruslan shevchenko kiev ua>
- Subject: TeX output for UML diagrams [path]
- Date: Sun, 06 Jan 2002 00:34:53 +0200
Diar dia-rs :
0. Thanks for dia ;).
1. Small problem with printing UML diagram in TeX: TeX special symbols
in names (such as #) are not escaped, as result TeX output
are not compiled by TeX.
So, I attach patch against dia-0.88.1
2. Are anybody know: what can cause invisability of some words in TeX
diagrams ?
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]