summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/patches/pstoedit-3.45asy.patch
blob: da289bba0c0d6f0844e9329272bdef55fa1d2a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
diff -ru pstoedit-3.45/src/cppcomp.h pstoedit-3.45J/src/cppcomp.h
--- pstoedit-3.45/src/cppcomp.h	2007-07-22 05:27:40.000000000 -0600
+++ pstoedit-3.45J/src/cppcomp.h	2009-02-11 23:20:06.000000000 -0700
@@ -22,6 +22,8 @@
 
 */
 
+#include <cstring>
+
 #ifdef _MSC_VER
 # ifndef DLLEXPORT
 # define DLLEXPORT __declspec( dllexport )
@@ -242,7 +244,7 @@
 		*de = 0;
 	} else {
 		cerr << "buffer overflow in strcpy_s. Input string: '" << so << "' count: " << count  << " sourcelen " << sourcelen << " buffersize " << de_size << endl;
-		exit(1);
+		_exit(1);
 	}
 }
 static inline void strcpy_s(char * de, size_t de_size, const char * so) {
diff -ru pstoedit-3.45/src/drvasy.cpp pstoedit-3.45J/src/drvasy.cpp
--- pstoedit-3.45/src/drvasy.cpp	2007-07-22 05:27:30.000000000 -0600
+++ pstoedit-3.45J/src/drvasy.cpp	2007-12-08 16:22:58.000000000 -0700
@@ -58,7 +58,8 @@
   clipmode(false),
   evenoddmode(false),
   firstpage(true),
-  imgcount(0)
+  imgcount(0),
+  level(0)
 {
   // Output copyright information
   outf << "// Converted from PostScript(TM) to Asymptote by pstoedit\n"
@@ -76,6 +77,29 @@
 	options=0;
 }
 
+void drvASY::save()
+{
+  while(gsavestack.size() && gsavestack.front()) {
+    gsavestack.pop_front();
+    outf << "gsave();" << endl;
+    ++level;
+    clipstack.push_back(false);
+  }
+}
+  
+void drvASY::restore() {
+  while(gsavestack.size() && !gsavestack.front()) {
+    gsavestack.pop_front();
+    while(clipstack.size() > 0) {
+      if(clipstack.back())
+	outf << "endclip();" << endl;
+      clipstack.pop_back();
+    }
+    outf << "grestore();" << endl;
+    if(level > 0) --level;
+  }
+}
+
 // Output a path
 void drvASY::print_coords()
 {
@@ -84,11 +108,7 @@
   bool havecycle=false;
   bool firstpoint=false;
 
-  while(gsavestack.size() && gsavestack.front()) {
-    gsavestack.pop_front();
-    outf << "gsave();" << endl;
-    clipstack.push_back(false);
-  }
+  save();
   
   if (fillmode || clipmode) {
     for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
@@ -247,16 +267,7 @@
       outf << ");" << endl;
     }
   }
-  
-  while(gsavestack.size() && !gsavestack.front()) {
-    gsavestack.pop_front();
-    if(clipstack.size() > 0) {
-      if(clipstack.back())
-	outf << "endclip();" << endl;
-      clipstack.pop_back();
-    }
-    outf << "grestore();" << endl;
-  }
+  restore();
 }
 
 // Each page will produce a different figure
@@ -272,6 +283,8 @@
 
 void drvASY::show_image(const PSImage & imageinfo)
 {
+  restore();
+  
   if (outBaseName == "" ) {
     errf << "images cannot be handled via standard output. Use an output file" << endl;
     return;
@@ -285,9 +298,13 @@
   ostringstream buf;
   buf << outBaseName << "." << imgcount << ".eps";
   
-  outf << "label(graphic(\"" << buf.str() << "\"),("
+  outf << "label(graphic(\"" << buf.str() << "\",\"bb="
+       << ll.x_ << " " << ll.y_ << " " << ur.x_ << " " << ur.y_ << "\"),("
        << ll.x_ << "," << ll.y_ << "),align);" << endl;
-  outf << "layer();" << endl;
+  
+  // Try to draw image in a separate layer.
+  if(level == 0) 
+    outf << "layer();" << endl;
   
   ofstream outi(buf.str().c_str());
   if (!outi) {
@@ -304,6 +321,8 @@
 // Output a text string
 void drvASY::show_text(const TextInfo & textinfo)
 {
+  restore();
+  
   // Change fonts
   string thisFontName(textinfo.currentFontName.value());
   string thisFontWeight(textinfo.currentFontWeight.value());
@@ -361,7 +380,8 @@
   if(prevFontAngle != 0.0) outf << "rotate(" << prevFontAngle << ")*(";
   bool texify=false;
   bool quote=false;
-  for (const char *c = textinfo.thetext.value(); *c; c++) {
+  const char *c=textinfo.thetext.value();
+  if(*c) for (; *c; c++) {
     if (*c >= ' ' && *c != '\\' && *c <= '~') {
       if(!texify) {
 	if(quote) outf << "\"+";
@@ -383,7 +403,7 @@
       }
       outf << "\\char" << (int) *c;
     }
-  }
+  } else outf << "\"\"";
   if(quote) outf << "\"";
   if(texify) outf << ")";
   if(prevFontAngle != 0.0) outf << ")";
diff -ru pstoedit-3.45/src/drvasy.h pstoedit-3.45J/src/drvasy.h
--- pstoedit-3.45/src/drvasy.h	2007-07-22 05:27:40.000000000 -0600
+++ pstoedit-3.45J/src/drvasy.h	2007-12-08 16:22:51.000000000 -0700
@@ -58,6 +58,8 @@
 
 private:
   void print_coords();
+  void save();
+  void restore();
   // Previous values of graphics state variables
   string prevFontName;
   string prevFontWeight;
@@ -80,6 +82,9 @@
   
   int imgcount;
   
+  unsigned int level;
+  // gsave nesting level
+  
   std::list<bool> clipstack;
   std::list<bool> gsavestack;
 };
diff -ru pstoedit-3.45/src/dynload.cpp pstoedit-3.45J/src/dynload.cpp
--- pstoedit-3.45/src/dynload.cpp	2007-07-22 05:27:36.000000000 -0600
+++ pstoedit-3.45J/src/dynload.cpp	2009-02-11 15:28:59.000000000 -0700
@@ -93,7 +93,7 @@
 {
 	if (handle) {
 		cerr << "error: DynLoader has already opened a library" << endl;
-		exit(1);
+		_exit(1);
 	}
 	const unsigned int size = strlen(libname_P) + 1; 
 	char *fulllibname = new char[size];