InDesign文本修改脚本会跳过内容 [英] InDesign Text Modification Script Skips Content

查看:151
本文介绍了InDesign文本修改脚本会跳过内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此InDesign Javascript遍历textStyleRanges并使用一些特定的AppliedFont转换文本,然后分配新的AppliedFont:-

This InDesign Javascript iterates over textStyleRanges and converts text with a few specific appliedFont's and later assigns a new appliedFont:-

var textStyleRanges = [];
for (var j = app.activeDocument.stories.length-1; j >= 0 ; j--)
  for (var k = app.activeDocument.stories.item(j).textStyleRanges.length-1; k >= 0; k--)
    textStyleRanges.push(app.activeDocument.stories.item(j).textStyleRanges.item(k));

for (var i = textStyleRanges.length-1; i >= 0; i--) {
  var myText = textStyleRanges[i];
  var converted = C2Unic(myText.contents, myText.appliedFont.fontFamily);
  if (myText.contents != converted)
    myText.contents = converted;        

  if (myText.appliedFont.fontFamily == 'Chanakya' 
  || myText.appliedFont.fontFamily ==  'DevLys 010' 
  || myText.appliedFont.fontFamily ==  'Walkman-Chanakya-905') {          
    myText.appliedFont = app.fonts.item("Utsaah");
    myText.composer="Adobe World-Ready Paragraph Composer";
  }
}

但是总有一些范围不发生。我尝试在向前或向后进行迭代,或者在转换之前将元素放入数组中,或者在同一迭代中更新AppliedFont,或者将其更新为另一个。某些范围仍未完全转换。

But there are always some ranges where this doesn't happen. I tried iterating in the forward direction OR in the backward direction OR putting the elements in an array before conversion OR updating the appliedFont in the same iteration OR updating it a different one. Some ranges are still not converted completely.

我这样做是为了将以基于字形的非Unicode编码方式编码的梵文文本转换为Unicode。其中一些涉及重新定位元音符号等,并可能更改代码以使用查找/替换机制,但是需要大量的返工。

I am doing this to convert the Devanagari text encoded in glyph based non-Unicode encoding to Unicode. Some of this involves repositioning vowel signs etc and changing the code to work with find/replace mechanism may be possible but is a lot of rework.

发生了什么?

另请参见: http://cssdk.s3-website -us-east-1.amazonaws.com/sdk/1.0/docs/WebHelp/app_notes/indesign_text_frames.htm#Finding_and_changing_text

此处的示例: https://www.dropbox.com/sh/7y10i6cyx5m5k3c/AAB74PXtavO6_n / a>

Sample here: https://www.dropbox.com/sh/7y10i6cyx5m5k3c/AAB74PXtavO5_0dD4_6sNn8ka?dl=0

推荐答案

这是未经测试的,因为我无法测试获得文档,但尝试使用 getElements()如下:

This is untested since I'm not able to test against your document, but try using getElements() like below:

var doc = app.activeDocument;
var stories = doc.stories;
var textStyleRanges = stories.everyItem().textStyleRanges.everyItem().getElements();

for (var i = textStyleRanges.length-1; i >= 0; i--) {
  var myText = textStyleRanges[i];
  var converted = C2Unic(myText.contents, myText.appliedFont.fontFamily);
  if (myText.contents != converted)
    myText.contents = converted;        

  if (myText.appliedFont.fontFamily == 'Chanakya' 
  || myText.appliedFont.fontFamily ==  'DevLys 010' 
  || myText.appliedFont.fontFamily ==  'Walkman-Chanakya-905') {          
    myText.appliedFont = app.fonts.item("Utsaah");
    myText.composer="Adobe World-Ready Paragraph Composer";
  }
}

这篇关于InDesign文本修改脚本会跳过内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆