Copy link to clipboard
Copied
Hi,
I have developed a script that reads a csv file, and does stuff with the data it gets. So far working good. One issue I seem to be having though is trying to translate superscript tags into actual supserscript in photoshop.
Here is what I'm trying to illustrate:
String of text: "$10.00"
I would want the ".00" to be superscript. I don't really see any way to do this by looking at the documentation found here (https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2019.pdf )
Can someone point me in the right direction on how I can achieve this? Here's some sample code that I am using to test:
layer.textItem.contents = "$10<sup>.00</sup>"
Obviously this wont work, but I am obviously trying to superscript the .00, I have dived as deep as I could into each property available on textItem. I would be open to splitting the string off, aplying one content, then applying another content with superscript. Which is what I was planning on doing, but can't quite seem to figure out how to get this style applied programmatically like this.
One thing I did try, is I applied a superscript to the layer's text to begin with, then before I mutate it, I alert(layer.textItem.content) and there's no special tag or anything, really hope there is a way to do this?
SuperMerlin​ was faster
...// original code written by r-bin
// adapted for actuel requirements by pixxxelschubser
// activeLayer in demo example must be textlayer !!
//activeDocument.activeLayer.textItem.contents = "$10.00";
var s = activeDocument.activeLayer.textItem.size;
var c = activeDocument.activeLayer.textItem.color;
var f = activeDocument.activeLayer.textItem.font;
var idx = activeDocument.activeLayer.textItem.contents.indexOf (".");
set_text_style (idx, 3, s, c, f);
function set_text_style(from, l
Copy link to clipboard
Copied
have a look at this thread...
Copy link to clipboard
Copied
SuperMerlin​ was faster
// original code written by r-bin
// adapted for actuel requirements by pixxxelschubser
// activeLayer in demo example must be textlayer !!
//activeDocument.activeLayer.textItem.contents = "$10.00";
var s = activeDocument.activeLayer.textItem.size;
var c = activeDocument.activeLayer.textItem.color;
var f = activeDocument.activeLayer.textItem.font;
var idx = activeDocument.activeLayer.textItem.contents.indexOf (".");
set_text_style (idx, 3, s, c, f);
function set_text_style(from, len, size, color, font)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
var list1 = new ActionList();
var d2 = new ActionDescriptor();
d2.putInteger(stringIDToTypeID("from"), from);
d2.putInteger(stringIDToTypeID("to"), from+len);
var d3 = new ActionDescriptor();
d3.putUnitDouble(stringIDToTypeID("size"), stringIDToTypeID("pointsUnit"), size);
d3.putString(stringIDToTypeID("fontPostScriptName"), font);
d3.putEnumerated(stringIDToTypeID("baseline"), stringIDToTypeID("baseline"), stringIDToTypeID("superScript"));
var d4 = new ActionDescriptor();
d4.putDouble(stringIDToTypeID("red"), color.rgb.red);
d4.putDouble(stringIDToTypeID("green"), color.rgb.green);
d4.putDouble(stringIDToTypeID("blue"), color.rgb.blue);
d3.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d4);
d2.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), d3);
list1.putObject(stringIDToTypeID("textStyleRange"), d2);
d1.putList(stringIDToTypeID("textStyleRange"), list1);
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
If that works for you
have fun
Copy link to clipboard
Copied
Hi @pixxxelschubser Hope you are doing good. The above script is amazing.
I wanted to know if it's possible to make a single word or number into a superscript in a text layer. For Example, if my text layer content is "20% Discount1 on selected items". I want the result to be "20% Discount¹ on selected items". If you notice, the number "1" alone turns into a superscript. Is it possible to achieve using substr() method? If yes, could you please help modify the above script? Looking forward to your response. Thanks in advance.
Copy link to clipboard
Copied
@pixxxelschubser 's script is a good start, but i believe your 1 for a super script may not be in the same position, so we need to combine it with how we are selecting the other phrase to change the color.
Copy link to clipboard
Copied
Hi @Chuck Uebele, Ya that's right. The position of the superscript will definitely vary. So wanted to understand if we can achieve it with substr() method to identify the "number 1" and make it a superscript.
Copy link to clipboard
Copied
Yea, I think we can adapt the script to find the "1".
Copy link to clipboard
Copied
That's great Chuck. If it's not too much to ask, Could you please help me with that??
Copy link to clipboard
Copied
Yea, hopefully later today.