Skip to main content
November 12, 2011
Question

photoshop text overflow

  • November 12, 2011
  • 1 reply
  • 7076 views

Hello,

Can someon help me with an issue i have. I have a text box in photoshop which i am putting varible data in, I cant stop the ext from overflowing. Can anyone help me with a script that if the text overflows it scales down. either by font or by scaling horizontaly or vertcally.

Thanks

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
November 15, 2011

I’m not optimistic for this task.

After all Photoshop is not really a page layout program and has somewhat limited type-spedific features.

And I could not identify a marker for overflow in the ActionDescriptor-code (though admittedly I only browsed it). 

You might be better off using BridgeTalk to do the typework in Indesign or Illustrator.

Maybe/probably someone else has more insight than me, though; you could also post on http://www.ps-scripts.com/

Inspiring
November 15, 2011

I've solved a related problem in doing contact sheet thumbnail captions. In my case, I know the bounds of the caption and need to fit the name of the image in that bounds. If I can't scale it to fit, I truncate it and append '...' until it fits. The performance is not what I would like, but it's not unreasonable.

ContactSheetII.prototype.insertCaption = function(doc, csOpts, bnds, file,  image) {

  var self = this;

  if (file == undefined) {

    file = File(image.name);

  }

  var caption = decodeURI(file.name);

  if (csOpts.captionFilename) {

    if (csOpts.noExtensions) {

      caption = file.strf("%f");

    }

  } else {

    caption = '';

  }

//   LogFile.write("Inserting caption " + caption + " at " + bnds);

  app.activeDocument = doc;

  var layer = doc.artLayers.add();

  layer.kind = LayerKind.TEXT;

  layer.name = decodeURI(file.name);

  var titem = layer.textItem;

  if (csOpts.autoscaleCaptions) {

    titem.minimumGlyphScaling = 50;

    titem.desiredGlyphScaling = 100;

  }

  titem.contents = caption;

  if (!csOpts._fontColor) {

    csOpts._fontColor = psx.colorFromString(csOpts.fontColor);

  }

  titem.color = csOpts._fontColor;

  titem.size = csOpts.fontSizePX;

  titem.font = csOpts.font;

  titem.kind = TextType.PARAGRAPHTEXT;

  var captionWidth = bnds[2]-bnds[0];

  // Check to see if the caption is too wide

  var twidth = Math.round(titem.width);

  if (csOpts.autoscaleCaptions) {

    // try to scale the glyph width to make it fit

    if (twidth > captionWidth) {

      if ((captionWidth / twidth) > 0.5) {

        titem.desiredGlyphScaling = (100 * captionWidth) / twidth;

      } else {

        titem.desiredGlyphScaling = 50;

      }

    }

    // switching the kind forces PS to recompute the text size

    titem.kind = TextType.POINTTEXT;

    titem.kind = TextType.PARAGRAPHTEXT;

    twidth = Math.round(titem.width);

  }

  if (csOpts.dotTruncate) {

    // truncate the text until it fits

    if (twidth > captionWidth) {

      if (caption.length <= 4) {

        // handle the deviant case here

        titem.contents = caption[0] + '...';

      } else {


        // estimate the string length...

        var len = Math.round((captionWidth/twidth) * caption.length);

        var str = caption.substring(0, len-4) + '...';

        // take off the file extension first

        while (twidth > captionWidth+4) {

          titem.contents = str;

          if (str.length <= 4) {

            break;

          }

          titem.kind = TextType.POINTTEXT;

          titem.kind = TextType.PARAGRAPHTEXT;

          twidth = Math.round(titem.width);

         

          str = str.substring(0, str.length-4) + '...';

        }

      }

    }

  }

  titem.justification = Justification.CENTERJUSTIFIED;

  titem.width = bnds[2]-bnds[0];

  titem.position = [bnds[0], bnds[1]];

  var style = csOpts.captionStyle;

  if (style && style != CSII.NO_CAPTION_STYLE) {

    layer.applyStyle(style);

  }

  return layer;

};

November 17, 2011

thanks xbytor2, will give this a whirl. I dont know how but i did get the horizontalscale to reduce, But since sleping its gone. I cant recall if it was horizontalscale = -1 or horizontalscale.value = etc. but thanks for your input. i hope to return with good news.

Date: Tue, 15 Nov 2011 12:05:41 -0700

From: forums@adobe.com

To: chalkyw42@live.co.uk

Subject: photoshop text overflow

Re: photoshop text overflow

created by xbytor2 in Photoshop Scripting - View the full discussion

I've solved a related problem in doing contact sheet thumbnail captions. In my case, I know the bounds of the caption and need to fit the name of the image in that bounds. If I can't scale it to fit, I truncate it and append '...' until it fits. The performance is not what I would like, but it's not unreasonable. ContactSheetII.prototype.insertCaption = function(doc, csOpts, bnds, file, image) {

var self = this;

if (file == undefined) {

file = File(image.name);

}

var caption = decodeURI(file.name);

if (csOpts.captionFilename) {

if (csOpts.noExtensions) {

caption = file.strf("%f");

}

} else {

caption = '';

}

// LogFile.write("Inserting caption " + caption + " at " + bnds);

app.activeDocument = doc;

var layer = doc.artLayers.add();

layer.kind = LayerKind.TEXT;

layer.name = decodeURI(file.name);

var titem = layer.textItem;

if (csOpts.autoscaleCaptions) {

titem.minimumGlyphScaling = 50;

titem.desiredGlyphScaling = 100;

}

titem.contents = caption;

if (!csOpts._fontColor) {

csOpts._fontColor = psx.colorFromString(csOpts.fontColor);

}

titem.color = csOpts._fontColor;

titem.size = csOpts.fontSizePX;

titem.font = csOpts.font;

titem.kind = TextType.PARAGRAPHTEXT;

var captionWidth = bnds[2]-bnds[0];

// Check to see if the caption is too wide

var twidth = Math.round(titem.width);

if (csOpts.autoscaleCaptions) {

// try to scale the glyph width to make it fit

if (twidth > captionWidth) {

if ((captionWidth / twidth) > 0.5) {

titem.desiredGlyphScaling = (100 * captionWidth) / twidth;

} else {

titem.desiredGlyphScaling = 50;

}

}

// switching the kind forces PS to recompute the text size

titem.kind = TextType.POINTTEXT;

titem.kind = TextType.PARAGRAPHTEXT;

twidth = Math.round(titem.width);

}

if (csOpts.dotTruncate) {

// truncate the text until it fits

if (twidth > captionWidth) {

if (caption.length <= 4) {

// handle the deviant case here

titem.contents = caption[0] + '...';

} else {

// estimate the string length...

var len = Math.round((captionWidth/twidth) * caption.length);

var str = caption.substring(0, len-4) + '...';

// take off the file extension first

while (twidth > captionWidth+4) {

titem.contents = str;

if (str.length <= 4) {

break;

}

titem.kind = TextType.POINTTEXT;

titem.kind = TextType.PARAGRAPHTEXT;

twidth = Math.round(titem.width);

str = str.substring(0, str.length-4) + '...';

}

}

}

}

titem.justification = Justification.CENTERJUSTIFIED;

titem.width = bnds[2]-bnds[0];

titem.position = [bnds[0], bnds[1]];

var style = csOpts.captionStyle;

if (style && style != CSII.NO_CAPTION_STYLE) {

layer.applyStyle(style);

}

return layer;

};

Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:

To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link.

Start a new discussion in Photoshop Scripting by email or at Adobe Forums

For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.