Author
Topic: Stack or Double (Read 2257 times)

For this example, We have a document which is formatted with a static number of lines. We will use 10 lines for our example. There can be Company Name, Agent Name, 2 Agent Titles, an Email and a Web Address. In addition, there is a phone block containing up to 10 phones.

The straight forward way to handle this is to use a line counter and subtract avaiable lines as you identify populated fields.

For example, I have:

Company NameAgent NameAgent TitleEmail AddressWeb Address

This leaves me 5 lines to work with and if I happen to have 10 phones, they all double.

Something like that. This is a basic example, but we could be dealing with more elements and more lines and each additional element or line adds to the clutter.

My solution was to build a repeat loop which decides whether to stack or double the phone elements. The example I will show here actually does quite a bit more because the format is more complicated then just stack or double.

The short version looks something like this:

worddelimiters set to "|"itemcount = number of phone itemslinecounter = number of available linespstring = pipedelimited phone variable (phone1|phone2|etc.)

«--«if pstring≠""«put (the number of words in pstring) into itemcount«repeat while pstring≠""«if itemcount > (linecounter*2)«put "ERROR: TOO MUCH INFO<\#13>" into lines«exit repeat«else if itemcount ≤ linecounter«repeat (itemcount)«put lines & word 1 of pstring & "<\#13>" into lines«put linecounter - 1 into linecounter«put word 2 to the number of words in pstring of pstring into pstring«end repeat«exit repeat«else if itemcount > linecounter«put lines & word 1 of pstring & ", " & word 2 of pstring & "<\#13>" into lines«put linecounter - 1 into linecounter«put word 3 to the number of words in pstring of pstring into pstring«put itemcount - 2 into itemcount«else if itemcount = 0«exit repeat«endif«end repeat«endif«--

For the more adventurous souls, I have a real world example.

In this example, we have three text blocks which have to do the following within a static space (say 100 points of vertical space);

Top align

Center between

Bottom align

To add to the complexity, all elements can have custom text properties (font size, leading, font face, etc.). We are not only tracking the number of lines used, but also the ammount of vertical space (in points) so that we might vertically center the name & title and then the ammount of horizontal space used for each line so that we might scale as needed. We flag an error when the space is used up.

So to set the stage, our variable data collected so far would be something like;

Here we actually want to jump out of the text box we are in after our last element. We also want to collect our metric values as we combine phone elements. Lastly, we want to apply the greater of two leading values to our paragraph style so that we don't get ascenders running into descenders.

On output, we have two overlapping text boxes. The top one is top aligned and the bottom one is bottom aligned. We calculate the remaining vertical space and divide it in half to create a false paragraph which should center the middle block when it is applied. It kind of looks like this on output.

Company Name

<fake spacer>

Nametitle<jump to second box>

address blockphone block<jump out of box>

This was obviously fun to troubleshoot and debug while under a deadline.