Skip to main content
Inspiring
March 1, 2024
Answered

Super script with script?

  • March 1, 2024
  • 2 replies
  • 595 views

pun not intended, 

whilst docs do mention

FontOpenTypePositionOption.OPENTYPESUPERSCRIPT,

I could not get it working

This topic has been closed for replies.
Correct answer dolce5EC2

ok, found it by comparing 2 objects.
in case someone's struggling too, it's:
characterAttributes.baselinePosition = FontBaselineOption.SUPERSCRIPT

2 replies

Participant
October 24, 2024

hello, the baselinePosition property seems not working on my character, while using $.writeln() showed the change of it.

textFrame.textRange.characters[Index].characterAttributes.openTypePosition = FontOpenTypePositionOption.OPENTYPESUPERSCRIPT

 

dolce5EC2AuthorCorrect answer
Inspiring
March 1, 2024

ok, found it by comparing 2 objects.
in case someone's struggling too, it's:
characterAttributes.baselinePosition = FontBaselineOption.SUPERSCRIPT

renél80416020
Inspiring
March 1, 2024

Bonjour,

Pour s'amuser un peu...

 

Document ouvert, lancer le script.

// JavaScript document for Illustrator
// Landry René
// elleere Wed, 25 April 2018 17:39:04 GMT
// INIT---------
var c1 = "^";
var c2 = "_";
var text = "2^2.5 + b^2 = 5 C_12^2 sin(20^3)";   // cas 1
//var text = "2^2.5 + b^2 = 5 C^2_12 sin(20^3)"; // cas 2
var corps = 16;
//-------------
var docRef = activeDocument;
var pointText = docRef.textFrames.add();
    pointText.contents = text;
    pointText.position  = [20,-20];
    pointText.textRange.size = corps;
     //expo_indice(pointText,c1,1); // si cas 2
     expo_indice(pointText,c2,0);
     expo_indice(pointText,c1,1); // si cas 1
//--------------
function expo_indice(textRf,rx,drap) {
  var index, pos, i, r, curentChar, suit, baseline;
      baseline = drap ? FontBaselineOption.SUPERSCRIPT : FontBaselineOption.SUBSCRIPT;
      pos = index = textRf.contents.indexOf(rx);
      suit = textRf.contents;
        while (pos != -1) {
          suit = suit.substring(pos+1);
          r = parseFloat(suit)+"";
          //r = drap ? parseFloat(suit)+"" : "1";  // si toujours 1 chiffre
            for (i = 1; i <= r.length; i++) {
              curentChar = textRf.textRanges[index+i];
              curentChar.baselinePosition = baseline;
            }
          textRf.textRanges[index].remove();
          pos = suit.indexOf(rx);
          index += pos;
        }
}
//--------------