• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Photoshop script to change the font for Superscript(In glyph)

Contributor ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

Hi Everyone,

Could anyone please help to change the font for superscript text(in glyph). For example, I want to change the superscript text  which is in "SF pro display" font and change to "Helvetica Neue". Is it possible with action manager code? Script Listener plugin was not working for photoshop 2021 and above in my mac. So please any action manager code available for this request please share.

 

TOPICS
Actions and scripting

Views

4.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jul 25, 2021 Jul 25, 2021
Your text is strange. There are duplicate ranges in the textStyleRange.
How did you get it, typed it with your hands?
 
Made two corrections in the code.
The first takes into account the presence of duplicate ranges.
The second is the absence of the otbaseline parameter.
 
By the way, it is the presence of otbaseline that makes ordinary number characters look like superscript in the SFProDisplay font. This is not the case in other fonts. I do not know what this parameter is.
 
Checking for
...

Votes

Translate

Translate
Adobe
Contributor ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

Thanks r-bin!

 

I have modified the code as per my requirement and facing some issue is below:

 

var otbaseline = styles[i].getEnumerationValue(stringIDToTypeID("otbaseline"))

If I use the above line in the code for "SF Pro Display" font and got the below error 

 

Screenshot 2021-07-26 at 12.02.57 AM.png

 So I removed the line and change the code, now it change the font to superscript text but it convert the normal number to superscript. see the below modified code.

try { app.activeDocument.suspendHistory("Replace Superscript Font", "replace_superscript_font(activeDocument)"); } catch(e) { alert(e); }

alert("done");
function replace_superscript_font(target)
    {
    try {
        var layers = target.layers;

        for (var i = 0; i < layers.length; i++) 
            {
            if (layers[i].typename == "LayerSet") 
                {
                callee(layers[i]);
                }
            else if (layers[i].kind == LayerKind.TEXT)
                {
                    replace_styles(layers[i].id) 
                }
            }
        }
    catch (e) { throw(e); }        
    }

    


    
    //////////////////////////////////////////////////////
    function replace_styles(id) 
        {
        try {
                var fontPostScriptName = "HelveticaNeue-Bold";

            var dig1_reg = new RegExp("\\d+");
            var dig2_reg = new RegExp("[\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039]");// same unicode values for Superscript and numbers in SF Pro Display Font
            var r = new ActionReference(); 
            r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("textKey"));
            r.putIdentifier(stringIDToTypeID("layer"), id); 
            var textKey = executeActionGet(r).getObjectValue(stringIDToTypeID("textKey"));
    
            var text = textKey.getString(stringIDToTypeID("textKey"));
            var list = textKey.getList(stringIDToTypeID("textStyleRange"));

            var styles = new Array();
            
            for (var i = 0; i < list.count; i++)
                {
                var d = list.getObjectValue(i);

                var from = d.getInteger(stringIDToTypeID("from"));

                var to = d.getInteger(stringIDToTypeID("to"));
            
                var style = d.getObjectValue(stringIDToTypeID("textStyle"));
    
                for (var x = from; x < to; x++) styles.push(style);

                }
    
            var new_text = "";
    
            for (var i = 0; i < text.length; i++)
                {
                var c = text[i];
    
                // change chars with only orig_font_name
                // uncomment if necessary 
                //var font = styles[i].getString(stringIDToTypeID("fontName"));  
                //if (font != orig_font_name) { new_text += c; continue; }
    
                var dig1 = dig1_reg.test(c);
                var dig2 = dig2_reg.test(c);
    
                if (dig1 || dig2)
                    {

                  // var otbaseline = styles[i].getEnumerationValue(stringIDToTypeID("otbaseline")); 
                   if (stringIDToTypeID("superScript")) c = conver_to_superscript(c);
    
                    styles[i].putString(stringIDToTypeID("fontPostScriptName"), fontPostScriptName);
    
                    // uncomment if necessary 
                    //styles[i].putString(stringIDToTypeID("fontName"),           fontName);
                    //styles[i].putString(stringIDToTypeID("fontStyleName"),      fontStyleName);
                    }
    
                new_text += c;
                }
    
            var new_list = new ActionList(); 
    
            styles.push(new ActionDescriptor());
    
            var from = 0;
    
            for (var i = 0; i < styles.length-1; i++)
                {
                if (!styles[i].isEqual(styles[i+1]))
                    {
                    var d = new ActionDescriptor(); 
                    d.putInteger(stringIDToTypeID("from"), from); 
                    d.putInteger(stringIDToTypeID("to"), i+1); 
                    d.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), styles[i]); 
    
                    new_list.putObject(stringIDToTypeID("textStyleRange"), d);
    
                    from = i+1;
                    }
                }
    
            textKey.putString(stringIDToTypeID("textKey"), new_text); 
    
            textKey.putList(stringIDToTypeID("textStyleRange"), new_list); 
    
            var d = new ActionDescriptor(); 
            var r = new ActionReference(); 
            r.putIdentifier(stringIDToTypeID("layer"), id); 
            d.putReference(stringIDToTypeID("null"), r); 
            d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), textKey); 
    
            executeAction(stringIDToTypeID("set"), d, DialogModes.NO); 
            }
        catch(e) { alert(e); }
        }
    
    
    //////////////////////////////////////////////////////
    function conver_to_superscript(c) 
        {
        try {
            switch (c)
                {
                case "1": c = "\u00B9"; break;
                case "2": c = "\u00B2"; break;
                case "3": c = "\u00B3"; break;
                case "0": c = "\u2070"; break;
                case "4": c = "\u2074"; break;
                case "5": c = "\u2075"; break;
                case "6": c = "\u2076"; break;
                case "7": c = "\u2077"; break;
                case "8": c = "\u2078"; break;
                case "9": c = "\u2079"; break;
                }
    
            return c;
            }
        catch(e) { throw(e); }
        }
    
    

 Sample and output file is attached.

 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

LATEST
Your text is strange. There are duplicate ranges in the textStyleRange.
How did you get it, typed it with your hands?
 
Made two corrections in the code.
The first takes into account the presence of duplicate ranges.
The second is the absence of the otbaseline parameter.
 
By the way, it is the presence of otbaseline that makes ordinary number characters look like superscript in the SFProDisplay font. This is not the case in other fonts. I do not know what this parameter is.
 
Checking for the presence of this font was disabled (commented out) in the script. That is, all fonts will be subject to changes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

Hi

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

So if I get this right...

you need to find superscript text in one font, then change it to a different font. Correct?

Because this is REALLY confusing, I'm not even sure wht you want to do.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

Yes from starting itself I have pointed out the same thing. I want to find and change the superscript font(SF Pro Display) to different superscript font(Helvetica Neue). Im using SF pro display font, in the SF pro font numbers, superscript and subscript have same unicode value. For reference see the below thread: photoshop script to differentiate the same unicode characters

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

Before moving to another request isn't an answer given in this thread a correct to mark it so?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

I think people have written enough code for you. It's time you started doing your own work, instead of expecting people to do it for you. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

A message to the helpers in this thread. Sorry the top of my head just came off and steam came out of my ears - from the original poster's appalling (to me) rudeness in starting a new thread without any reference to the huge amount of work already put into this one. I should not and do not seek to suggest anyone stop helping if that's what they want to do.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

You have gotten way off into the weeds. Unicode value is irrelevant here. You are dealing with styling information.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines