How to Align multiline text?

No noticeable difference - still 5+ seconds to load in the simulator and 10+ seconds on my iPhone.

Nathan.

Wow, ok, that’s strange.

Because after the change I did, I got no loadtime on simulator and around 1 sec on phone.

To explain what happens when you call fontbox.newFontSet:

To position all letters correct I have to get relation between their width and the fontsize. For that I create a textbox and loop through all characters an devide the textbox’s width with the fontsize. The only thing that I could do are funtions that let you save and load fontsets. With that you can save the fontset and load it at the next start.

One questions, did you use fontbox.addSpecialCharacters BEFORE you call fontbox.newFontSet ?

Otherwise I have no idea what could be done against the loading problem, because I couldn’t reproduce it :frowning:

Yes I am calling fontbox.addSpecialCharacters {“ä”, “ö”, “ü”, “Ä”, “Ö”, “Ü”, “ß”} before - as per your sample code - should I call it after?

Note that I also added 0123456789$’ to all_letters.

Thanks,

Nathan.

No that’s fine, you did everything allright.

Below the code what’s happening if you call fontbox.newFontSet. Maybe you can find the mistake.

[LUA]

function fontbox.newFontSet(arg)
    local font_set = {}
    local name = arg.name or “test”
    font_set.font_name = arg.font_name or native.systemFont
    font_set.spacing = arg.spacing or 0.05
    font_set.char_width = arg.char_width or standard_char_width
    font_set.all_letters = arg.all_letters or standard_all_letters
    font_set.underline_size = arg.underline_size or 0.08
    font_set.underline_height = arg.underline_height or 0.5
    font_set.letter_ratios = {}
    font_set.kerning_pairs = arg.kerning_pairs or {}
    
    local all_letters = font_set.all_letters
    
    local font_size = 500
    local letterbox = display.newText("", 0, 0, font_set.font_name, font_size)
    for i=1, slenght( all_letters ) do
        local char = all_letters:sub( i , i )
    
        if char ~= special_chars[“pre”] then
            if special_chars[char] then
                char = special_chars[char]
            end
            
            letterbox.text = char
            local letter_width = letterbox.width
    
            local ratio = letter_width/font_size
            if char == " " then ratio = 0.3 end
            font_set.letter_ratios[char]=ratio
        end
    end
    
    letterbox:removeSelf()
    letterbox=nil
    
    fontbox.fonts[name] = font_set
end

[/LUA]

Newest build (not publ release) ! Cheers to Corona Devteam All works now

Sorry Torbenratzlaff - didn’t get a chance to look at your code in detail. I’m going to cut & run with the built-in alignment.

Nathan.

No problem man,

I had lots of fun writing the module, and now I know very much about string manipulation. :smiley:

So in most cases the built in method is clearly better, due to its way better performance.

torben, your module has other formatting capabilities over and above the center & right justification etc. I am wondering if you would consider updating your module by taking advantage of the new CL SDK features to do the text justification actions while keeping your own formatting pieces. This might be the best of both worlds as it might address the performance issues while keeping the rich formatting abilities in you module. Just an idea. Thanks much for your contribution. 

torben, your module has other formatting capabilities over and above the center & right justification etc. I am wondering if you would consider updating your module by taking advantage of the new CL SDK features to do the text justification actions while keeping your own formatting pieces. This might be the best of both worlds as it might address the performance issues while keeping the rich formatting abilities in you module. Just an idea. Thanks much for your contribution. 

Wouldnt it be ok to read each line of text into a table, give them atributes like CenterReferencePoint, self.width and self.height = prevLine + myTextHeightIncludeSpaceBetweenTextLines. After this is done you set a for loop to spawn each line (the width of the line could be the width of the devices screen devided by the chars width (use monospaced font) now you got the max number of chars to use so when you reach that charCount it makes a new entry to the table of lines and centers it (every line shares the same x cord) Havent tested it, but the problem is to do this with other fonts that uses implicit kerning and tracking tables…I wouldnt even start to try to get this right with, lets say Edwardian, Balentines or fonts like that If I how ever should try, I would make my own tracking tables deviding it into 3 different spaces like thin, medium and thick letters so each letter would be a bearer of this value like: O=thick, I=thin and J=medium. Now each letter entry could check self.trackingSize to nextLetterTrackingSize. Well, this is just what sort of ran out of my head :wink:

Hi Hendrix,

sure you can do something like that, and it would be way simpler, but in both ways. You don’t have adjust so many values by yourself than, but on the other hand you can’t even if you want to. And I as a designer value flexibility in design over th effordence to do so. I mean, with the latest daily build you got text alignment for textboxes. So the only reason (for pro users) to use the module is the higher flexibility when it comes to kerning, lineheight and the use of spans.

I totally agree man

This function should be in the display.newTextField or whatever newText… API as a optional param if you ask me like in native.library but like this:

myText = display.newTextField( textObj, textAlignment, widthOfTextBox, heightOfTextBox, x, y, myFontOrNativeSys… )

or maybe like in the structure of transition.to / from:

myText = display.newTextField( textObj, { allMandatoryOrOptionalParamsGoesHere } )

maybe put in a function for fade inn out too as a param :slight_smile:

Just to let you know that we added text justification to display.newText in Daily Build 1143. It will be available for Starters in the next public release.

Thats really good news for me, Tom! This is something many people has been waiting for

Of course I had to go and test it at once (like a kid on xmas)… cant get it to work with the last daily build: 1150 (2013.6.25)

Hows the new.Text() options look like now, where do I put center, left or right params

Can you give an example?

You can find the documentation and example here: http://docs.coronalabs.com/daily/api/library/display/newText.html

Newest build (not publ release) ! Cheers to Corona Devteam All works now

Sorry Torbenratzlaff - didn’t get a chance to look at your code in detail. I’m going to cut & run with the built-in alignment.

Nathan.

No problem man,

I had lots of fun writing the module, and now I know very much about string manipulation. :smiley:

So in most cases the built in method is clearly better, due to its way better performance.

torben, your module has other formatting capabilities over and above the center & right justification etc. I am wondering if you would consider updating your module by taking advantage of the new CL SDK features to do the text justification actions while keeping your own formatting pieces. This might be the best of both worlds as it might address the performance issues while keeping the rich formatting abilities in you module. Just an idea. Thanks much for your contribution.