Javascript Photoshop脚本:如何知道溢出的文本部分

Javascript Photoshop脚本:如何知道溢出的文本部分,javascript,text,photoshop-script,Javascript,Text,Photoshop Script,我想在多张幻灯片之间传播一段很长的文字,因为它不能放在一张幻灯片中 我通过手动查看文本在一张幻灯片中停止的位置,然后在下一张幻灯片中从那里继续(直到打印完整个文本) 有没有办法使这个过程自动化?也许是一种检索实际显示文本部分的方法?这可能不是您想要的,但这只是一个开始 它创建一行可以在图像中显示的文本。在我的例子中,我使用了一个640x480@72dpi的新文档 // Switch off any dialog boxes displayDialogs = DialogModes.ERROR;

我想在多张幻灯片之间传播一段很长的文字,因为它不能放在一张幻灯片中

我通过手动查看文本在一张幻灯片中停止的位置,然后在下一张幻灯片中从那里继续(直到打印完整个文本)


有没有办法使这个过程自动化?也许是一种检索实际显示文本部分的方法?

这可能不是您想要的,但这只是一个开始

它创建一行可以在图像中显示的文本。在我的例子中,我使用了一个640x480@72dpi的新文档

// Switch off any dialog boxes
displayDialogs = DialogModes.ERROR; // OFF 

// call the source document
var srcDoc = app.activeDocument;

var myString = "The quick brown fox jumps over the lazy dog";

var w = srcDoc.width.value;
var h = srcDoc.height.value;

var maxWidth = w-20;
var remanderText = "";

for (i = myString.length; i > 0; i--)
{
  var text = myString.slice(0, i);
  create_text("Arial", 36.0, text, 320, 230, "c", maxWidth);

  var sb = get_selection_bounds();

  if (sb[0] < maxWidth)
  {
    //ok
    remanderText = myString.slice(i, myString.length);
    break;
  }
  else
  {
    // delete layer
    srcDoc.activeLayer.remove();
  }
}
alert(remanderText);



// function CREATE TEXT(typeface, size, R, G, B, text content, text X pos, text Y pos)
// --------------------------------------------------------
function create_text(fface, size, content, tX, tY, just, maxw)
{
  var line = content.split("\n");

  // Thanks to visioN for the regex help
  // replaces \n with \r carriage return
  content = content.replace(/\n|<br\s*\/?>/gi, "\r");


// Add a new layer in the new document
  var artLayerRef = app.activeDocument.artLayers.add();

  // Specify that the layer is a text layer
  artLayerRef.kind = LayerKind.TEXT;

  artLayerRef.name = "text";

  //This section defines the color of the hello world text
  textColor = new SolidColor();
  textColor.rgb.red = 0;
  textColor.rgb.green = 0;
  textColor.rgb.blue = 0;

  //Get a reference to the text item so that we can add the text and format it a bit
  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = content;
  textItemRef.color = textColor;
  textItemRef.size = size
  textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top


  if (just == "CENTRE" || just == "CENTER" || just = "C" || just = "c") just = Justification.CENTER
  else if (just == "RIGHT" || just == "right" || just = "R" || just = "r") just = Justification.RIGHT
  else if (just == "LEFT" || just == "left" || just = "L" || just = "l") just = Justification.LEFT
  else (just = Justification.LEFT);

  activeDocument.activeLayer.textItem.justification = just;
}

// function GET SELECTION BOUNDS ()
// ----------------------------------------------------------------
function get_selection_bounds()
{
  select_layer_as_selection();

  var x = parseFloat(app.activeDocument.selection.bounds[0]);
  var y = parseFloat(app.activeDocument.selection.bounds[1]);
  var x1 = parseFloat(app.activeDocument.selection.bounds[2]);
  var y1 = parseFloat(app.activeDocument.selection.bounds[3]);

  var selW = parseFloat(x1-x);
  var selH = parseFloat(y1-y);

  // select nothing; Deselect all
  app.activeDocument.selection.deselect();

  // return the results as an array
  return [(selW), (selW)];
}


// function SELECT LAYER AS SELECTION()
// --------------------------------------------------------
function select_layer_as_selection()
{
    var id1268 = charIDToTypeID( "setd" );
    var desc307 = new ActionDescriptor();
    var id1269 = charIDToTypeID( "null" );
    var ref257 = new ActionReference();
    var id1270 = charIDToTypeID( "Chnl" );
    var id1271 = charIDToTypeID( "fsel" );
    ref257.putProperty( id1270, id1271 );
    desc307.putReference( id1269, ref257 );
    var id1272 = charIDToTypeID( "T   " );
    var ref258 = new ActionReference();
    var id1273 = charIDToTypeID( "Chnl" );
    var id1274 = charIDToTypeID( "Chnl" );
    var id1275 = charIDToTypeID( "Trsp" );
    ref258.putEnumerated( id1273, id1274, id1275 );
    desc307.putReference( id1272, ref258 );
    executeAction( id1268, desc307, DialogModes.NO )
    return;
}
//关闭所有对话框
displayDialogs=DialogModes.ERROR;//关
//调用源文档
var srcDoc=app.activeDocument;
var myString=“敏捷的棕色狐狸跳过懒狗”;
var w=srcDoc.width.value;
var h=srcDoc.height.value;
var maxWidth=w-20;
var remanderText=“”;
对于(i=myString.length;i>0;i--)
{
var text=myString.slice(0,i);
创建_文本(“Arial”,36.0,文本,320230,“c”,最大宽度);
var sb=get_selection_bounds();
if(sb[0]
不确定这是否可以自动化,因为PS不知道什么是“可见”文本。。。(你可能应该使用Indesign,而不是Photoshop)我认为你能做到这一点的唯一方法是一个字符一个字符地循环你的字符串。如果它符合图像的宽度,则转到下一个字符。Photoshop不保存任何字体宽度或间距信息。谢谢,它总比没有好,可能主要考虑的是速度,但当然它必须在每次迭代中创建和渲染一个新的文本层。使用二进制搜索应该会更快!你认为通过查看内存中的进程,我们可以得到有用的东西吗?我快速地看了一下,但是文本总是完整的。(为了记录在案,即使有注释,部分代码也可见)