创建处理程序以增加字体大小

Creating a handler to increase font size

我正在开发一个文本应用程序,其中包含一个用于增加字段中选定文本的文本大小的按钮。

下面是我正在使用的处理程序,当所有 selectedText 当前大小相同时它工作正常。如果某些文本大小不同,处理程序 returns 会出现此错误:

execution error at line 42 (Operators +: error in left operand), char 68

负责人:

on txtSizeUp
     set the textSize of selectedText to the textSize of selectedText + 2
end txtSizeUp

我需要做什么才能改变大小而不考虑差异?

设置textSize时,LC需要一个chunk表达式,如line 3 of fld 1word 2 to 4 of fld "yourField"

短语 the selectedText 解析为所选内容的实际文本。因此,如果您在一个字段中有 "my dog has fleas",并且选择了 "dog",您的代码要求:

set the textSize of "dog" to someValue

这是不允许的。引擎不知道该怎么做。您需要修改您的脚本和您的方法,以制作块,而不是文本引用。

更改您的处理程序以使用 selectedChunk 而不是 selectedText。

on txtSizeUp
   set the textSize of the selectedChunk to the textSize of the selectedChunk + 1
end txtSizeUp

当然,为了更好的衡量标准:

on txtSizeDown
   set the textSize of the selectedChunk to the textSize of the selectedChunk - 1
end txtSizeDown

编辑:上面的处理程序只有在整个 selectedChunk 的 textSize 相同时才有效。即使选择范围内有不同的大小,您也希望能够增加文本大小。 (我在你原来的问题中错过了那个细节。)

The problem is that the selectedChunk function returns the string "mixed" when there are varying sizes within the selection.这就是你出错的原因; set 语句试图添加 mixed + 1,数据类型不匹配。这是一个应该做你想做的处理程序。

on txtSizeUp
  put the effective textSize of the selectedChunk into tSize
  if tSize is a number then
    set the textSize of the selectedChunk to \
       the effective textSize of the selectedChunk + 1
  else
    lock screen
    put the long name of the selectedField into tFld
    put word 2 of the selectedChunk into tStartChar
    put word 4 of the selectedChunk into tEndChar
    repeat with x = tStartChar to tEndChar
        set the textSize of char x of tFld to \
           the effective textSize of char x of tFld +1
    end repeat
    unlock screen
  end if
end txtSizeUp

还有其他可行的方法,但它们都涉及以某种方式循环选择的文本。