How could these line spacings be being calculated??

Hello! I'm in dire need of help from a font expert, and was curious if someone could help me! 

I don't mean to be off topic, I really think this is font related, its something to do with font files and typography that I am just very confused.

I have some questions on how to calculate the line spacing between lines in a Docx file.

My requirement is to exactly match Wordnot necessarily the OOXML spec, in the spacing between lines in a simple paragraph.

In order to try to do this, I have built a tool to analyze the differences between my layout and Word's layout. To do so it does the following:

  1. First it generates a (or many) docx files.
  2. Next it creates pdfs from the docx files. It uses Word to render the docx to PDF, and my program to render the docx to PDF. "word.pdf", and "me.pdf"
  3. Then it analyzes the resulting PDFs for differences in layout.

So, my tool would say:

  1. create a document "template.docx" with 1000 "a" characters in a single run of text with the same properties.
  2. make a "word.pdf" and "me.pdf" from this docx
  3. calculate info from the pdfs, in particular, calculating the line spacing in terms of the calculated leading between a lines ascent and the previous lines descent (our (Ascent + Descent) are identical-ish, so all that differs is the whitespace between lines)I often think of it as the lines whitespace...

This tool showed me that the leading varies greatly from font to font.

To depict this, I used the tool to make thousands of these comparisons, in particular generating for:

  1. For each font in system
  2. For "a", "y", and a mix of letters and spaces.
  3. For different font sizes.
  4. For different line spacing types (Single, One and a half, and Double)

I was hoping to find groupings, such as "this type of font has 1.3 times my calculation of leading". 

I was able to conclude far less than I had hoped, and was wondering if you could help me further with the issue of calculating line spacing. I'm providing you with a file that is best downloaded and opened in Excel while using the filters in the header row. Note that its not totally complete, there are missing entries, but I doubt they will be a problem for anyone, and I'm going to regenerate it soon but its pretty slow, so I'm finishing up some changes to it first.

Here is a comparison of the layout of our software, vs the layout of Word's for every font installed on my system, etc. 

I'm not positive, but I believe the issue could be one of the following:

  1. Word is using a different process than we are to calculate the "leading" of a font. We don't parse the font files ourselves, instead rely on libraries to get font sizing information, and perhaps in the "world of font files" I am missing something, and word is parsing the fonts directly and differently.
  2. Word has some sort of lookup table that handles groups of fonts, or an algorithm, that scales a fonts leadings up or down based on some criteria I am unaware of.
  3. Word is using an additional criteria besides leading, ascent, and descent, to determine line spacing.

Please feel free to email me at nathanb@windward.net

Thank you so so much!
Nathan Bellowe

Comments

  • AFAIK, Word’s line space is 1.25×(winAscent + winDescent) or 1.25×(typoAscent - typoDescent)
  • Hin-Tak Leung
    Hin-Tak Leung Posts: 361
    edited August 2016
    This seems to be asking the wrong people - you may get a better answer asking say, the libreoffice people or the TeX people. And possibly without asking anybody, just reading libreoffice's source code.

    People who tried to implement the ooxml spec, to match word, probably know the answer. And that would be the libreoffice people.
  • Thanks so much! This is very helpful information from both of you. 

    As well as I can tell, these formulas don't match up nearly as close as they should!! But that does seem like what it should be... (some constant) * (winAscent + winDescent), but it just doesn't seem to work out like that!!!

    For one, they change the line spacing on a line of descenders, e.g. containing a bunch of "a" vs all "y". As typographers, are you surprised by this, or if you could, would you write a piece of software that automatically adjusts for that? 
  • You could try to create a font with very basic vertical metrics: ascender 750, descender -250, line gap 200, and place some rectangles in the font matching ascender and descender values. Then see how this font behaves in Word with different line spacing settings. If font size is 12 and line spacing is set also to exactly 12, descenders and ascenders over multiple lines should be touching. If line spacing is set to single there should be a line gap of 20% of font size between lines.
  • Regarding the aaa vs yyy issue, isn't that what the other reply suggests - the collection of factor * (ascend + decend), for that line?

    Aesthetic - or people's visual preferences - is full of exceptions. The Greek tried golden section (1.618) but then the paper industry settled on 1.414 ; I am sure the microsoft folks have little rules like 'do X most of the time, except when y, do z, unless w is also true, do v instead...' and full of exceptions too.

    It is a well-known fact that you often don't get the same layout after upgrading ms word, though it is getting better. Many pepole writing theses with carefully arranged line/page breaks often moaned about that. For mathematically consistent and reproducible layouts, many turned to TeX instead. A lot of people don't like computer modern roman... But you can typeset something from 30 years ago and get the same layout; try that with word 3 upgrades ago :smile:

    I am not sure what the initial poster is trying to achieve, actually... I think it should be possible to get something 'close enough', though perfect match is unlikely.