# Information about baseline and descent - Quark specific

Hello,
I’m writing a script to do text box transformation, and whilst I can get the code to work it seems as though the Quark application isn’t supplying the correct information.

I’ll try and explain by way of example. I have a text box that contains seven paragraphs (in its one story). Two of these paragraphs are carriage returns, that is they only contain one character; the other five have a number of characters basically a line or two of text. I’ve written a script which when you select a text box that has multiple paragraphs converts it into multiple text boxes. In effect we simply have one text box with seven paragraphs, and it is converted to seven text boxes.

To determine the height of each new text box I subtract the baseline of the last character in the paragraph, from the previously found baseline. In the case of the first paragraph the previously found baseline is nought.

My understanding of the baseline is this. It is the imaginary line that all the characters sit upon. At school when you prepared a blank piece of paper for writing on you drew faint lines, all characters then sat upon this line. Of course, certain characters have tails, p, q, j to name a few and these hang below the baseline, this value is captured by the descent value. However, in the example I’m working with, the first paragraph is ‘This is some text.’

I realise this isn’t an easy question to answer. I’ve not posted any code because I know the algorithm and the logic isn’t wrong. I’ve looked at all the properties a paragraph holds and the baseline looks to be the best candidate to use, but as I say Quark doesn’t seem to supply the values I’d expect.

Things that might help me are the following: are my assumptions about the baseline correct, and has anyone else tried to do something similar.

Rather than trying to figure out baseline offset, why not use the leading and the number of lines of text to determine the size of the new text box? You can get a count of lines by paragraph like this:

tell paragraph 1
set i to count of lines in it
end tell

Then you can multiply i by the leading and use that number to create the height of each nex text box. You can set this up in a repeat structure so it goes through and does it a paragraph at a time.

Hi thanks for your suggestion, which is a good idea. The problem is that for the example I’m working with the value of the ‘leading’ attribute is 0 :mad: I’ve created a number of test quark files, and as i’ve done nothing more complex than simply drop a few text, and picture, boxes onto a page, I’m assuming that it’s reasonable to expect the ‘leading’ value to be nought in some cases.

I think I’ll go back and review my algorithm for calculating the dimensions of the new text boxes, perhaps it’s simply a case of me adding up incorrectly. Thanks again for replying, it all helps.

northernstar, leading value return of “0” is auto leading. Your point size plus your % increase in quark preferences. 100pt type + say 20% leading. Change leading to 120pt in your doc and no change. So i think you could use an if leading is 0 then calculate leading else use leading value.

Can’t you simply use the property height?:

``````set theHeight to ((height of paragraph n) as point units as real)
``````

seems to give reasonable values

If not - here is an older script I remembered to have seen at lists.apple.com:
it uses baseline and descent to adjust the height of a text box - maybe this example helps?

http://lists.apple.com/archives/Applescript-users/2001/Oct/msg01177.html

Hello,
Just a quick reply to all who have posted.
Thanks very much, it’s much appreciated.

Dan.

I’m not sure what Dominick’s going for. I don’t there’s a height property for paragraph objects. At least I can’t find it in the dictionary or make the syntax work.

Another workaround you could consider norhernstar is to first set the leading for all your text to a fixed leading, say 15 pt, and then use that number for your calculations. That might be easier then calculating the leading based on the autoleading settings. If you want to keep autoleading on, you can first set the leading for all your text to 15 pt and then back to autoleading at the end. This can also be done by creating and referencing some paragraph style sheets. Thay way you can tweak the leading or other paragraph specs and not have to change the script. Good luck.

you can find the ‘height’ property here:

text properties‚n [inh. character properties] : A list of common properties and elements inherited by all text objects
elements
contains characters, lines, paragraphs, stories, texts, text style ranges, words.
properties
ascent (font units, r/o) : the maximum ascent of any character in this text
baseline (vertical measurement, r/o) : vertical offset from the top of the box to the text
character style (character spec) : the character spec applied to this text
contents (string) : contents of this text
descent (font units, r/o) : the maximum descent of any character in this text
→ height (font units, r/o) : height of this text
horizontal offset (horizontal measurement, r/o) : offset from the left side of the box to the text
kern (fixed) : kerning of the first character of this text
length (integer, r/o) : number of characters in this text object
offset (integer, r/o) : index of the first character of this text within the story
trap text (default/overprint/knockout/spread auto amount/choke auto amount) : for the first character of this text
trap text (fixed) : trapping specification for the first character of this text
uniform styles (text style info, r/o) : text styles that are uniformly applied to this text
width (horizontal measurement, r/o) : width of the first character of this text

Since ‘paragraph’ is a text object you can ask it for it’s heigt. It is working - I have tried it with QuarkXPress Passport 6.5.

D.

Sorry Dominik. I misunderstood. I had no idea that existed. It looks like it gives you the product of the number of lines times the leading. Very handy. Confusing though. I think when I tried it, I may not have been referencing the right text box, which didn’t work, of course. Then when I looked in the dictionary at the paragraph properties, I couldn’t find a height property. Thanks.

Hi,
I’ve been working with the height, and it seems to be doing OK. My basic algorithm was correct, but I am working on doing a few tweaks with regards to rounding errors, and such like. When I’ve got it working in a satisfactory way, I’ll post the script to act as reference.

Dan

Hi folks,
As promised here is the script, or rather the part of the script that deals with calculating the dimensions of my new text boxes.

The problem i was looking at is this. I have a text box with a number of paragraphs. I need to split this text box into separate text boxes for each paragraph.

This script simply finds the selected text box, and sets the initial values.

``````
repeat with tb from 1 to tBoxTotal -- loop through the text boxes on this page
tell text box tb

if (selected is true) then
set selectedTextBox to tb -- this is our selected text box
set selectedPage to pg -- this is the page our selected text box is on.

-- now find these details. We will use them when creating our new boxes
try
copy (top of bounds of it as real) to intY1
on error
set intY1 to 0
end try

try
copy (left of bounds of it as real) to intX1
on error
set intX1 to 0
end try

try
copy (bottom of bounds of it as real) to intY2
on error
set intY2 to 0
end try

try
copy (right of bounds of it as real) to intX2
on error
set intX2 to 0
end try

try
copy (height of bounds of it as real) to intOriginalHeight
on error
set intOriginalHeight to 0
end try

exit repeat -- exit the loop through the text boxes
end if
end tell -- end of working with the text box
end repeat -- end our loop

``````

This script then calculates the new text boxes and writes this information into a list, to put in the textBoxList. Later on I loop through the textBoxList and make the new text boxes.

``````
tell page selectedPage
tell text box selectedTextBox

set strColour to name of color
tell story 1
set intParagraphCount to (paragraph count)

if intParagraphCount is greater than 1 then -- find information to create new text boxes
--Initialise our array/list
repeat intParagraphCount times
set end of textBoxList to ""
end repeat

set intCumulativeHeight to 0 -- initialise this
set intCumulativeYPosition to intY1
set intCumulativeYPosition to my RoundDecimal(intCumulativeYPosition, 3, "to nearest")
set intX1 to my RoundDecimal(intX1, 3, "to nearest")
set intX2 to my RoundDecimal(intX2, 3, "to nearest")

repeat with p from 1 to intParagraphCount
tell paragraph p

set intOffset to offset
set intNumberOfChars to length
set intLastCharacter to (intNumberOfChars + intOffset)

set strText to every text as string
copy (name of color of it as string) to strStoryColour
set strStoryFont to font
set strStorySize to size

set intDescent to (descent as millimeter units)
set intDescent to (intDescent as real)

set intBaseline to (baseline of character intLastCharacter as millimeter units)
set intBaseline to (intBaseline as real)

set intBaseline to (intBaseline + intDescent)
set intBaseline to my RoundDecimal(intBaseline, 3, "to nearest")
set intHeight to ((height) as millimeter units as real)

set intY2Position to (intY1 + intBaseline)
set intY2Position to my RoundDecimal(intY2Position, 3, "to nearest")

set intCumulativeYPosition to (intY2Position - intHeight)
if intNumberOfChars is greater than 1 then
--display dialog ("Make text box '" & intCumulativeYPosition & " : " & intX1 & " : " & intY2Position & " : " & intX2 & "'")
set item p of textBoxList to {intCumulativeYPosition, intX1, intY2Position, intX2, strText, strStoryFont, strStorySize, strStoryColour}
end if

end tell
end repeat
end if -- end of the check on if we have more than one paragraph

end tell -- end of working with the story of the selected text box
end tell -- end of working with the selected text box

``````