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

Detecting/Correcting text overflow

Explorer ,
Apr 24, 2009 Apr 24, 2009

Hi folks,

Has anyone here ever been able to successfully determine if a TextItem in PS has overflow in it? Basically I am trying to write a script that replaces text in a document. If this in turn causes text overflow I would like the script to reduce the point size. I have done a few exeriments with both point and paragraph text.

There seems to be no obvious methods or properties for determining that overflow occurs. I thought I could cheat and measure the widths and heights of the text items before I replace the text, then check to see if they are different afterwards and if so, reduce the point size.

However in the case of point text it is not possible to determine the text width so I would have to do something like rasterize it then do the measurement. In the case of paragraph text the height and width of the text box do not change if there is overflow.

Does anyone have any better, more efficient ideas?

cheers

Ben

TOPICS
Actions and scripting
1.8K
Translate
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
Adobe
Advisor ,
Apr 24, 2009 Apr 24, 2009
Translate
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
Valorous Hero ,
Apr 24, 2009 Apr 24, 2009

Here is an example..

#target photoshop
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.documents.add(300, 300, 72.0,  "New Canvas", NewDocumentMode.RGB, DocumentFill.WHITE,1.0);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT;
newTextLayer.textItem.position = Array(0, 40);
newTextLayer.textItem.font = "Verdana";
newTextLayer.textItem.size = 14;
newTextLayer.textItem.contents = "The quick brown fox jumps over the lazy dogs back"
var Width = activeDocument.width.value;
var LB=activeDocument.activeLayer.bounds;
var textWidth = LB[2].value - LB[0].value;
if(textWidth > Width) alert("Overflow by " + (textWidth-Width) + " pixels");
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;

Translate
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 ,
Apr 25, 2009 Apr 25, 2009

Many thanks Paul, that method works fine for point text.

As for paragraph text I think I have come up with a solution.

If we convert a paragraph text layer into a point text layer by doing something like:

ArtLayer.textItem.kind = TextType.POINTTEXT;

and overflow has occured, photoshop will clip out the overflowed text.

So after converting the paragraph to point text we need only check that our

text contents matches the text we are trying to replace it with.

These solutions are a both work arounds, it would be nice if there was a proper

method or property to deal with this. Maybe I will make a dear adobe entry.

Translate
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
New Here ,
Mar 02, 2023 Mar 02, 2023
LATEST

Hi Ben,

 

Did you ever find a method for doing this?

 

I'd really like to create a script that detects overflowing text for proofing purposes.

Translate
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