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

Centre text Vertically - Baselineshift???

Explorer ,
Jun 18, 2018 Jun 18, 2018

Copy link to clipboard

Copied

Hi

We have written a script which has a specific text area where text will reside.

var text_width_area = 6142;

The rest of the script is as follows

var fontsize = activeDocument.activeLayer.textItem.size;

var textwidth = Number(activeDocument.activeLayer.bounds[2].value) - Number(activeDocument.activeLayer.bounds[0].value);

var difference = Number(textwidth - text_width_area);

var difference_perc = Number(difference / textwidth * 100);

var text_calc = difference_perc / 100 * fontsize;

var text_calc_final = fontsize - text_calc;

if (Number(textwidth > text_width_area))  {

    activeDocument.activeLayer.textItem.size = text_calc_final;

    activeDocument.activeLayer.textItem.tracking = -50;

    }

So we set the fontsize, text width area, then work out the difference between the two.

Then work out the sum and percentage to reduce text size to so that text fits within the area.

It will only resize if the text goes over the text area

For most of the text changes the new text reduction sits in the middle horizontally, but when a large change is needed, the text sits at the bottom.

The text is not in a bound box as we found it was worse in a bound box.

I know of baselineshift, but i am trying to work out a calculation or something to then get the text in the middle vertically.

The width position is always correct, but i am trying to always centre again the text vertically if it shifts down due to font size change.

Any help is appreciated.

Cheers

TOPICS
Actions and scripting

Views

934

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 , Jun 19, 2018 Jun 19, 2018

// it is assumed that app.preferences.rulerUnits != Units.PERCENT

var text_ver_center = (activeDocument.activeLayer.bounds[1] + activeDocument.activeLayer.bounds[3])/2; 

activeDocument.activeLayer.textItem.size = text_calc_final; 

// your code....

activeDocument.activeLayer.translate(0,  text_ver_center - (activeDocument.activeLayer.bounds[1] + activeDocument.activeLayer.bounds[3])/2);

Votes

Translate

Translate
Adobe
People's Champ ,
Jun 19, 2018 Jun 19, 2018

Copy link to clipboard

Copied

// it is assumed that app.preferences.rulerUnits != Units.PERCENT

var text_ver_center = (activeDocument.activeLayer.bounds[1] + activeDocument.activeLayer.bounds[3])/2; 

activeDocument.activeLayer.textItem.size = text_calc_final; 

// your code....

activeDocument.activeLayer.translate(0,  text_ver_center - (activeDocument.activeLayer.bounds[1] + activeDocument.activeLayer.bounds[3])/2);

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
Explorer ,
Jun 21, 2018 Jun 21, 2018

Copy link to clipboard

Copied

LATEST

Thank you, worked perfect.

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