Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Test file:
// ====================================
// https://www.dropbox.com/s/dokdemxve0wd6yp/singleline%20or%20multiline%20text%20-%20test.psd?dl=0
// My results:
// ====================================
// (TRUE) 1. Singleline Point text
// (TRUE) 2. Singleline Paragraph text
// (FALSE) 3. Multiline Point text.Forced linebreak
// (FALSE) 4. Multiline Paragraph text. No forced line breaks.
// (FALSE) 5. Multiline Paragraph text. OVERFLOWING TEXT. No forced line breaks.
// (FALSE) 6. Multiline Paragraph text. Forced linebreaks.
// (FALSE) 7. Multiline Paragraph text. Forced linebreaks. OVERFLOWING TEXT.
var doc = app.activeDocument;
var textGroup = doc.layerSets.getByName('Text');
for ( var i=0; i < textGroup.layers.length; i++ ) {
doc.activeLayer = textGroup.layers[i];
$.writeln( '(' + singleLine( doc.activeLayer ) .toString().toUpperCase() + ') ' + doc.activeLayer.textItem.contents.replace(/\r/g,'') + '\n\n' );
}
function singleLine() {
var doc = app.activeDocument;
var layer = doc.activeLayer;
var historyRollback = doc.activeHistoryState;
var rulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
var height1 = size( layer )[1];
layer.textItem.noBreak = true;
layer.textItem.contents = layer.textItem.contents.replace(/\r/g,'');
var height2 = size( layer )[1];
var singleline = height1 > height2 ? false : true;
app.preferences.rulerUnits = rulerUnits;
doc.activeHistoryState = historyRollback;
doc.activeLayer = layer;
return singleline;
function size( layer ) {
var bounds = layer.boundsNoEffects;
var top = bounds[1].value;
var right = bounds[2].value;
var bottom = bounds[3].value;
var left = bounds[0].value;
var width = right - left;
var height = bottom - top;
return [ width, height ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment