Skip to main content
Known Participant
June 12, 2012
Question

how to create a text layer with special characters

  • June 12, 2012
  • 1 reply
  • 2371 views

Hi guys,

I'm doing the following things, but now i encountered some problems.

I will get a xml file from remote host, then use this file to create a psd file, but if the file contains some special characters, the psd file  don't render properly. Can anyone help me to solve the problem? The xml file use UTF-8 encoding.

the xml file just like:

<?xml version="1.0" encoding="UTF-8" ?>
<HelloEncodingWorld>Üöäüßßß Test!!!</HelloEncodingWorld>


here is my sample coding.

var script = '';

var assetUrl = ServerURL+xmlFile;

var http = new HttpConnection(assetUrl);  

http.request;

http.method = "GET";

http.response;

http.execute() ;   

var tmpStr = String(http.response);

var xmlString = new XML(tmpStr);

//create psd file script

script += "";

//execute

var bt = new BridgeTalk();

bt.target = "photoshop";

bt.body = script;

bt.send();

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
June 12, 2012

Does this help....

var newText = encodeURI("Üöäüßßß Test!!!");

var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = "var ftn = " + script.toSource() + "; ftn(" + newText.toSource() +");";
bt.send(8);

function script(Content){
var FontName = "Georgia";
var FontSize = 14;
var black = new SolidColor();
black.rgb.hexValue = '000000';
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.documents.add(600,400);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT;
newTextLayer.textItem.color = black;
newTextLayer.textItem.font = FontName;
newTextLayer.textItem.size = FontSize;
newTextLayer.textItem.contents = decodeURI(Content);
newTextLayer.textItem.position = Array(20, 20);
app.preferences.rulerUnits = startRulerUnits;
}

Known Participant
June 13, 2012

thank you for your reply. It works excellently. But that doesn't match my requirement.

Please see my demo code.

                    var assetUrl = 'http://localhost/d.xml';

                    var http = new HttpConnection(assetUrl);  

                    http.request;

                    http.method = "GET";

                    http.response;

                    http.execute() ;   

                    var tmpStr = String(http.response);

                    var xmlString = new XML(tmpStr);

                    var tmp = xmlString.workspace;

                    var templateobj = tmp.template;

                    var text = templateobj[0].txt;          //the text is incorrect, i got the value is ORâS, not OR’S, I think here must to be converted, but i dont't konw how to do it.

                    $.writeln("text.."+ text);

                    var newText = encodeURI(text);

                    var bt = new BridgeTalk();

                    bt.target = "photoshop";

                    bt.body = "var ftn = " + script.toSource() + "; ftn(" + newText.toSource() +");";

                    bt.send(8);

                    function script(Content){

                        var FontName = "Georgia";

                        var FontSize = 14;

                        var black = new SolidColor();

                        black.rgb.hexValue = '000000';

                        var startRulerUnits = app.preferences.rulerUnits;

                        app.preferences.rulerUnits = Units.PIXELS;

                        app.documents.add(600,400);

                        var newTextLayer = activeDocument.artLayers.add();

                        newTextLayer.kind = LayerKind.TEXT;

                        newTextLayer.textItem.kind = TextType.POINTTEXT;

                        newTextLayer.textItem.color = black;

                        newTextLayer.textItem.font = FontName;

                        newTextLayer.textItem.size = FontSize;

                        newTextLayer.textItem.contents = decodeURI(Content);

                        newTextLayer.textItem.position = Array(20, 20);

                        app.preferences.rulerUnits = startRulerUnits;

                    }

the xml file is here:

<?xml version="1.0" encoding="UTF-8"?>

<workspace_set>

  <workspace id="0">

    <template id="0">

        <txt><![CDATA[OR’S]]></txt>

    </template>

  </workspace>

</workspace_set>

Paul Riggott
Inspiring
June 13, 2012

Ah, sorry I thought you were getting the right value but not getting the right result in Photoshop.

I have never used HttpConnection and not sure how to set it up to test.

Maybe the text should be encoded first? I don't know.