Docx - Matching Line Spacing of Word

Post general font related questions (e.g. how to install, convert and use fonts) and requests (looking for fonts, designers etc.) here.
Post Reply
nbellowe
Posts: 3
Joined: Wed Aug 24, 2016 10:15 pm

Docx - Matching Line Spacing of Word

Post by nbellowe »

Hello there! I don't know as much about fonts as I could, and I was wondering if some of the brilliant minds here could give me a hand, I'd really appreciate it

Basically, I have some questions on how to calculate the line spacing between lines in a Docx file, and I think my problem may be from parsing fonts. First let me explain the whole dilemma.

My requirement is to exactly match Word, not 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:
  • First it generates a (or many) docx files.
  • 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"
  • 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 line's ascent and the previous line's descent (our "Ascent + Descent" are almost identical, so all that differs is the whitespace between lines). I often think of it as the line's 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:
  • For each font in system
  • For "a", "y", and a mix of letters and spaces.
  • For different font sizes.
  • 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. https://drive.google.com/file/d/0BzQpUd ... sp=sharing

I'm not positive, but I believe the issue could be one of the following:
  • 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.
  • Word has some sort of lookup table that handles groups of fonts, or an algorithm, that scales a font's leading up or down based on some criteria I am unaware of.
  • Word is using an additional criteria besides leading, ascent, and descent, to determine line spacing.
What do you think? Do you think this could be an issue in parsing font files or something related to fonts? Am I missing a key piece of understanding? Thanks so much!

Please feel free to email me: nathanb at windward dot net

Thank you so much for your time!
Bhikkhu Pesala
Top Typographer
Top Typographer
Posts: 9873
Joined: Tue Oct 29, 2002 5:28 am
Location: Seven Kings, London UK
Contact:

Re: Docx - Matching Line Spacing of Word

Post by Bhikkhu Pesala »

See the FAQ thread at the top of the Support forum for some diagrams illustrating the various font metrics and terms.

I design my fonts so that WinAscent - WinDescent + Line Gap = 2458 or 2048 x 1.2

This gives a default line-spacing of 12 points for 10 point text.

Pali Regular:
WinAscent = 1907
WinDescent = -551
Line Gap = 0

Garava
WinAscent = 1991
WinDescent = -467
Line Gap = 0

Sukhumala (Default line-spacing =13 points for 10 point text)
WinAscent = 1991
WinDescent = -670
Line Gap = 1
Sukhumala Font Metrics.png
Sukhumala Font Metrics.png (1.56 KiB) Viewed 12852 times
I don't use Word, so it might calculate leading differently to Serif PagePlus
My FontsReviews: MainTypeFont CreatorHelpFC15 + MT12.0 @ Win 10 64-bit build 19045.2486
Dick Pape
Top Typographer
Top Typographer
Posts: 1360
Joined: Wed Oct 01, 2003 1:19 pm
Location: North Dallas, Texas

Re: Docx - Matching Line Spacing of Word

Post by Dick Pape »

AFAIK, Word’s line space is 1.25×(winAscent + winDescent) or 1.25×(typoAscent - typoDescent)
nbellowe
Posts: 3
Joined: Wed Aug 24, 2016 10:15 pm

Re: Docx - Matching Line Spacing of Word

Post by nbellowe »

Thanks so much!

As far 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), 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?
Bhikkhu Pesala
Top Typographer
Top Typographer
Posts: 9873
Joined: Tue Oct 29, 2002 5:28 am
Location: Seven Kings, London UK
Contact:

Re: Docx - Matching Line Spacing of Word

Post by Bhikkhu Pesala »

nbellowe wrote: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?
That's ridiculous. A superscript for a footnote might change the line-spacing (and does in PagePlus if "Allow for text advances" is enabled), but to change the line-spacing for text without any descenders should never be done. Who on earth would want that to happen?
My FontsReviews: MainTypeFont CreatorHelpFC15 + MT12.0 @ Win 10 64-bit build 19045.2486
nbellowe
Posts: 3
Joined: Wed Aug 24, 2016 10:15 pm

Re: Docx - Matching Line Spacing of Word

Post by nbellowe »

Bhikkhu Pesala wrote:
nbellowe wrote: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?
That's ridiculous. A superscript for a footnote might change the line-spacing (and does in PagePlus if "Allow for text advances" is enabled), but to change the line-spacing for text without any descenders should never be done. Who on earth would want that to happen?
I'm excited to see that passion. I promise, its there! I was surprised as well. Its not huge, but it can be as much as a 30% difference in calculated leading for particular fonts!
Bhikkhu Pesala
Top Typographer
Top Typographer
Posts: 9873
Joined: Tue Oct 29, 2002 5:28 am
Location: Seven Kings, London UK
Contact:

Re: Docx - Matching Line Spacing of Word

Post by Bhikkhu Pesala »

What are the different leading options in Word?

In PagePlus instead of "Single" line-spacing, which calculates the leading from the font metrics, I used Percentage of pointsize (usually I use 120% so that 11 point text is set at 13.2 point line-spacing). It's more flexible than setting an exact line-spacing at 12 points which has to be recalculated and modified if the font size is changed.
Line-spacing.png
Line-spacing.png (9.38 KiB) Viewed 12798 times
Single line-spacing in LibreOffice shows no difference between a paragraph full of "a"s or one full of "y"s.
LibreOffice Line-spacing.png
LibreOffice Line-spacing.png (3.54 KiB) Viewed 12797 times
My FontsReviews: MainTypeFont CreatorHelpFC15 + MT12.0 @ Win 10 64-bit build 19045.2486
Post Reply