[JW Lua] FCString:CreateEnigmaStrings doesn't work on long unicode strings, but on short ones

Jan Angermüller jan at angermueller.com
Wed Jul 8 21:23:30 CEST 2015


Jari,

 >Do you get empty string lengths where i.LuaString seems to result in 
empty strings?
No, the string.len() and i:GetLength() results were indeed never wrong, 
it's only the i.LuaString that troubles me.

The i.LuaString is definitely empty when adding 3 or 4 unicode letters, 
although - weird surprise - i:GetLength() returns the correct unicode 
length. If you look at the console output at the very bottom of the 
mail, you see the weird result: Length>2, but no string output, although 
the output is fine with 1 and 2 letters of the same code.

I attached a modified script where I write the LuaString into a new 
FCTextExpressionDef to show that the empty console output is correct and 
not an "invisible" string coding.
When you open the text expression dialog, the third and fourth 
expression are completely empty - just like the printed result from the 
console. I also attached a screenshot of the created text expression 
definitions: instead of 3 or 4 violin clefs in Bravura, the text area is 
empty.

It took me quite some time to track down this pretty weird behaviour, 
when it first came up two months ago. I did a lot of testing and 
combinations of different characters, and I am pretty sure that it is a 
LuaString problem created through CreateEnigmaStrings.
As a workaround I wrote my own CreateEnigmaStrings routine which solved 
the problem, but probably is much slower than your C++ routine and 
definitely not so well tested.

Best regards,
Jan

function CreateNewTextExpression(textvalue)
     local catdef = finale.FCCategoryDef()
     catdef:Load(1)
     local exprdef = finale.FCTextExpressionDef()
     exprdef:SaveNewTextBlock(textvalue)
     textvalue:TrimEnigmaTags()
     exprdef:SetDescription(textvalue)
     exprdef:AssignToCategory(catdef)
     exprdef:SetUseCategoryPos(false)
     exprdef:SetUseCategoryFont(false)
exprdef:SetVerticalAlignmentPoint(finale.ALIGNVERT_ABOVE_STAFF_BASELINE)
     exprdef:SetVerticalBaselineOffset(0)
     exprdef:SetVerticalEntryOffset(0)
exprdef:SetHorizontalAlignmentPoint(finale.ALIGNHORIZ_LEFTOFALLNOTEHEAD)
     exprdef:SetHorizontalJustification(finale.EXPRJUSTIFY_LEFT)
     exprdef:SetHorizontalOffset(0)
     exprdef:SetBreakMMRest(false)
     exprdef:SaveNew()
end

function SplitEnigma(text)
       --Create enigma strings and print all non-enigma commands 
(i.e.all texts)
       print("String to split:",text.LuaString)
       local splittext=text:CreateEnigmaStrings(true)
       for i in each(splittext) do
           if not i:IsEnigmaCommand() then
              print("String:",i.LuaString,i:GetLength())
i.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"..i.LuaString
              CreateNewTextExpression(i)
           end
       end
end

local text=finale.FCString()
text.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"
text:AppendCharacter(0xe050)
SplitEnigma(text)

text.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)
SplitEnigma(text)

text.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)
SplitEnigma(text)

text.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)
text:AppendCharacter(0xe050)

SplitEnigma(text)
text.LuaString="^fontMus(Bravura,8192)^size(24)^nfx(0)"
text:AppendCharacter(123)
text:AppendCharacter(123)
text:AppendCharacter(123)
text:AppendCharacter(123)
SplitEnigma(text)

Running [Unnamed Script] ======>
String to split: ^fontMus(Bravura,8192)^size(24)^nfx(0)
String:  1
String to split: ^fontMus(Bravura,8192)^size(24)^nfx(0)
String:  2
String to split: ^fontMus(Bravura,8192)^size(24)^nfx(0)
String:  3 ---!! empty string output, but length returns 3 !!
String to split: ^fontMus(Bravura,8192)^size(24)^nfx(0)
String:  4 ---!! empty string output, but length returns 4 !!
String to split: ^fontMus(Bravura,8192)^size(24)^nfx(0){{{{
String: {{{{ 4
<======= [Unnamed Script] succeeded (Processing time: 0.010 s).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20150708/2c6705fc/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: textexpressiondefs created from output.jpg
Type: image/jpeg
Size: 25345 bytes
Desc: not available
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20150708/2c6705fc/attachment.jpg>


More information about the JWLua mailing list