Extending the syntax of the template attribute of the image tag to be able to write special character on images. Below you find the extra documatation for the taglib documentation.
LINKS:
Two patches are attachted to this mail that are needed to make this behaviour work.
START OF CALL: 20040830
END OF CALL: 20040903
[_] +1 (YEA) [_] +0 (ABSTAIN ) [_] -1 (NAY), because : [_] VETO, because:
Please, also indicate if you would like this hack to be added to the 1.7 branch:
[_] +1 (YEA) [_] +0 (ABSTAIN ) [_] -1 (NAY), because : [_] VETO, because:
Jaco
<p>
The text method can have three or four parameters. If three parameters
are supplied, special characters like
the % character are replaced according to the specification of the
ImageMagick documentation. If four parameters are given
to the text attribute and the third parameter begins with the @
character, MMBase will create a temporary file
and write the text of the forth parameter to this file. The temporary
file is given to ImageMagick to read the text from.
This makes it possible to include special characters like the %
character. On a Windows machine you also have to use this method to
write characters outside the ASCII range. All occurrences of single
quotes need to be escaped by two single quotes (sql escaping), this
can be done with
<code><mm:import id="sql_escaped_text" escape="sql">text</mm:import></code>.
Dollar signs should also be escaped if you don't pass the text with
a context parameter.
</p>
<examplevalue>
<value>s(200x200!)+font(mm:fonts/Arial.ttf)+fill(ffffff)+pointsize(20)+gravity(NorthEast)+text(0,20,'MMBase generated image of %w by %h pixels')</value>
</examplevalue>
<examplevalue>
<value>s(200x200!)+font(mm:fonts/Arial.ttf)+fill(ffffff)+pointsize(20)+gravity(NorthEast)+text(0,20,@mmbase,'${sql_escaped_text}')</value>
</examplevalue>
--- ConvertImageMagick.java.orig Mon Aug 30 09:28:21 2004
+++ ConvertImageMagick.java Mon Aug 30 09:45:00 2004
@@ -14,6 +14,7 @@
import org.mmbase.util.externalprocess.CommandLauncher;
import org.mmbase.util.externalprocess.ProcessException;
+import org.mmbase.util.Encode;
import org.mmbase.util.logging.Logging;
import org.mmbase.util.logging.Logger;
@@ -327,8 +328,25 @@
} else if (type.equals("text")) {
int firstcomma = cmd.indexOf(',');
int secondcomma = cmd.indexOf(',', firstcomma + 1);
+ int thirdcomma = cmd.indexOf(',', secondcomma + 1);
type = "draw";
- cmd = "text " + cmd.substring(0, secondcomma) + " " +
cmd.substring(secondcomma + 1);
+ if (thirdcomma == -1) {
+ cmd = "text " + cmd.substring(0, secondcomma) + " " +
cmd.substring(secondcomma + 1);
+ } else if (cmd.charAt(secondcomma + 1) == '@') {
+ String tempFilePrefix = cmd.substring(secondcomma + 2,
thirdcomma);
+ try {
+ File tempFile = File.createTempFile(tempFilePrefix, null);
+ tempFile.deleteOnExit();
+ Encode encoder = new Encode("ESCAPE_SINGLE_QUOTE");
+ String text = cmd.substring(thirdcomma + 1);
+ FileOutputStream tempFileOutputStream = new
FileOutputStream(tempFile);
+
tempFileOutputStream.write(encoder.decode(text.substring(1, text.length() -
1)).getBytes("UTF-8"));
+ tempFileOutputStream.close();
+ cmd = "text " + cmd.substring(0, secondcomma) + " '@" +
tempFile.getPath() + "'";
+ } catch (IOException e) {
+ log.error(e.toString());
+ }
+ }
} else if (type.equals("draw")) {
//try {
//cmd = new String(cmd.getBytes("UTF-8"), "ISO-8859-1");
--- Sql.java.orig Mon Aug 30 09:53:33 2004
+++ Sql.java Mon Aug 16 19:25:28 2004
@@ -20,6 +20,7 @@
* needed in SQL statements.
*
* @author Michiel Meeuwissen
+ * @author Jaco de Groot
*/
public class Sql extends ConfigurableReaderTransformer implements CharTransformer {
@@ -57,6 +58,36 @@
}
/**
+ * Unescapes single quotes in a string.
+ * Unescaping is done by replacing two quotes with one quote.
+ * @param str the string to unescape
+ * @return the unescaped string
+ * @since MMBase-1.8
+ */
+ public static Writer singleQuoteBack(Reader r, Writer w) {
+ try {
+ boolean skipNext = false;
+ while (true) {
+ int c = r.read();
+ if (c == -1) break;
+ if(c == '\'') {
+ if (skipNext) {
+ skipNext = false;
+ } else {
+ w.write(c);
+ skipNext = true;
+ }
+ } else {
+ w.write(c);
+ skipNext = false;
+ }
+ }
+ } catch (java.io.IOException e) {
+ }
+ return w;
+ }
+
+ /**
* Used when registering this class as a possible Transformer
*/
@@ -74,7 +105,7 @@
}
public Writer transformBack(Reader r, Writer w) {
switch(to){
- case ESCAPE_QUOTES: throw new UnsupportedOperationException("Not
needed to revert this at anytime it tinks");
+ case ESCAPE_QUOTES: return singleQuoteBack(r, w);
default: throw new UnsupportedOperationException("Cannot transform");
}
}
