dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.44k stars 486 forks source link

TextRun fonts do not work in Word Online #2704

Closed dan-cooke closed 1 month ago

dan-cooke commented 3 months ago

Description

When using the TextRun property font to set a font family. The docx just uses the default Aptos font.

Reproduction code

      new TextRun({ text: 'hello world', font: 'Comic Sans MS' })

apologies this is taken from a larger library that I am working on for prosemirror. I can supply a fully working example if required, but its a pretty simple bug to reproduce.

If I generate a docx using this font property.

Edit

anti-the-social commented 3 months ago

That's probably need to be reported to Microsoft, not here. To make license more flexible, you know. I would guess its about licensing of the Comic Sans MS and absence of it in Chrome. If you open it in IE or Edge it might work for you since Microsoft invented that font.

dan-cooke commented 3 months ago

@anti-the-social I don't think thats quite right, correct me if I'm wrong - but if you have Comic Sans MS installed as a System Font on a Windows machine. You own a license to that font.

See Windows 10 font list

The browser should render that font.

If you open it in IE or Edge it might work for you since Microsoft invented that font.

That is not how fonts work on the web, browsers do not ship any fonts, they just use your system fonts. And websites can load additional fonts, the onus of licensing is on the website author. If every visitor to your site had to own a license to view your fonts that would be a pretty poor experience right?

The issue here is not to do with licensing its seemingly a bug in docx, the reason I am so sure about this?

The font property works when used in a Paragraph on Word Online.

There is probably more to this issue however, as I have uncovered some cases where the font property does work on Word Online, I suspect it could be another styling property I am setting that is conflicting with it.

anti-the-social commented 3 months ago

@dan-cooke I tend to disagree here :) Neither my mac nor windows are not having Comic Sans font available in Chrome as a font-family. But my windows machine has Comic Sans at C:/Windows/Fonts In other words, font is not attached to browser Chrome as you said.

And yes, Word document is zip file and it can include custom fonts in it. And probably Word in Web does that - attaches Comic Sans if you chose it for some Paragraph.

anti-the-social commented 3 months ago

BTW, here is an example how to attach custom font to the document https://github.com/dolanmiu/docx/blob/962795743c4f21d84c52e47e4f82dcf4ca536dc3/demo/91-custom-fonts.ts

Highly advice you to read Comic Sans license before attaching and/or using in your commercial or not products.

dan-cooke commented 3 months ago

@anti-the-social I think we are getting our wires crossed here.

I am not distributing the Comic Sans Font. I am simply setting a CSS variable font-family: 'Comic Sans'

But my windows machine has Comic Sans at C:/Windows/Fonts In other words, font is not attached to browser Chrome as you said.

That is not what I said :) ... I said Browsers do not package any fonts, however they are capable of reading your OS System fonts.

I highly advise for you to read up on how fonts work on the web, here is a quick primer on safe web fonts as you can see Comic Sans MS is listed here (because every windows and mac user in the world have this font in their system fonts)

Here is a simple example for you:

  1. Right click some text in this github thread > Inspect
  2. Attach a css property font-family: 'Comic Sans MS'
  3. Boom

image

You see that right? Github did not "distribute" the Comic Sans MS font to you, the browser read it from your system fonts

Anyway. This issue is being derailed - this is not about licensing of Comic Sans. You are talking about a completely unrelated circumstance.

dan-cooke commented 1 month ago

I am closing this as this now seems to be resolved - I actually now suspect this was an issue with Word browser client itself.