Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

find fonts in Windows registry #270

Closed
eroux opened this issue May 23, 2015 · 35 comments
Closed

find fonts in Windows registry #270

eroux opened this issue May 23, 2015 · 35 comments

Comments

@eroux
Copy link
Member

eroux commented May 23, 2015

Apparently, Windows 7 allows shortcuts in C://Windows/Fonts, see this doc. And apparently, luaotfload doesn't recognize them.

@phi-gamma
Copy link
Member

I’m a bit at loss here: What’s a “shortcut” in this context?
A symlink? These should work. Anything else depends
on how one is supposed to handle it.

I don’t currently have a Win VM for testing so I can’t really
experiment with the mechanism described on the linked page.

@eroux
Copy link
Member Author

eroux commented May 26, 2015

In this context, shortcuts are something really Windows-specific, it's a file (with extension .lnk) that contains the path of another file. See msdn. To be honest, I initially thought they were plain text files containing a path, but it seems more complex... The request initially comes from @BGMcoder (through gregorio), maybe he'll be able to help?

@BGMcoder
Copy link

Hi! Thanks for helping out, Elie. Windows shortcuts are like pointers - they are not symlinks. For an example, I can create a shortcut to a folder on my computer's desktop. When I click on the shortcut, Explorer follows the shortcut and opens the folder. The shortcut's file is a *.lnk file (L not i) and if you view it's properties in Windows Explorer you can see that it has a "target file". You can install a font in Windows by creating a shortcut to the font file and placing that shortcut in c:\windows\fonts.
Windows Shortcuts are used EVERYWHERE - all the items in the Windows Start Menu are shortcuts. Most of the icons on the desktop are usually shortcuts. Just right-click on one and look at its properties and you will understand what it is.

@eroux
Copy link
Member Author

eroux commented May 26, 2015

@BGMcoder remember you're talking to people who haven't been using Windows for years...

@eroux
Copy link
Member Author

eroux commented May 26, 2015

Parsing a .lnk file in lua might be a nightmare... Maybe the best would be to propose a patch for LuaTeX adding a lua function calling the relevant Windows system calls? Maybe Hans would be ok to add this, as I guess ConTeXt would need to read lnk in C:\Windows\Fonts too?

@BGMcoder
Copy link

@eroux Well, I've tried to explain it. Windows has used .lnk files for as long as I can remember. Also in Windows, if you right click on or alt+drag any file you can "Create Shortcut".

@BGMcoder
Copy link

In Windows, when you (or your font management application) create a shortcut to a font file and put it in C:\Windows\fonts, Windows treats that font as being "installed" and the font is available to be used now by any application. I suspect that lualatex is not using Windows' own font index, but is reading from the font directory directly.

@eroux
Copy link
Member Author

eroux commented May 26, 2015

pretty much yes... Do you have information about the "Windows' own font index"?

@BGMcoder
Copy link

@eroux Well, okay, Windows stores a list of all the fonts in the registry:
Windows 95
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts]

Windows NT
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
and if the font is installed via shortcut, the real file path is stored there in the registry; if the font file exists in the windows font folder then the path will be excluded.

I just looked at this on my computer and confirm that it is the case.

So, perhaps lualatex would do better to scan that registry key rather than the fonts folder.

Also, here is a thread that explains a bit about the shortcuts: https://thecustomizewindows.com/2011/01/install-fonts-using-shortcut-in-windows-7/
Apparently, there is a setting that allows fonts to be installed that way.

@BGMcoder
Copy link

You can see some screenshots of the registry open to the fonts:
http://www.loseyourmind.com/How-to-export-font-list-from-registry.aspx

Instead of scanning the registry over and over, you could export the key (pretty easy in code!) and then read through the exported text file. But you'd have to refresh it obviously.

@eroux
Copy link
Member Author

eroux commented May 26, 2015

Apparently there's a lua module to read the registry... I think if it's added to ctan it could land into TeXLive (as it's Windows-specific, it could be distributed compiled), and it could be used...

@phi-gamma
Copy link
Member

The shortcut's file is a *.lnk file (L not i) and if you view it's properties in Windows Explorer you can see that it has a "target file".

Some basic info: http://en.wikipedia.org/wiki/.lnk

Sounds horrible, especially in the light of all the directory traversal
issues brought up lately. Doesn’t NTFS support proper symlinks nowadays?
Those would offer a more portable, generic solution. In any case it’d seem
more reasonable than attempting to handle a proprietary file format that
duplicates basic file system functionality in some rather quirky fashion.

It gets worse:

Microsoft Windows .lnk files operate as Windows Explorer extensions, rather than file system extensions. As a shell extension, .lnk files cannot be used in place of the file except in Windows Explorer, and have other uses in Windows Explorer in addition to use as a shortcut to a local file (or GUID). These files also begin with "L".

Especially the “cannot be used in place of the file except in Windows Explorer”
part sounds offputting, if you ask me.

Are these things really a common way of handling font files? Even Context
doesn’t appear to deal with this stuff and it’s being developed exclusively
on Windows … I infer even for heavyweight font users the need for .lnk
files rarely arises.

suspect that lualatex is not using Windows' own font index, but is reading from the font directory directly.

Correct, that’s kind of the point. You supply a path ($OSFONTDIR
or whatever) and all the fonts inside are being indexed. Just add the
directory where the font files are to the usual paths and the fonts
should be found.

In any case, before anything can be done we’ll need some official
specification. If someone could volunteer a link (pun intended) it
might help in estimating the feasibility.

@phi-gamma
Copy link
Member

Btw. what does Xetex do if you ask it to read a .lnk file?

@eroux
Copy link
Member Author

eroux commented May 27, 2015

I agree this is really a terrible design answer, certainly initially thought as a dirty replacement for the lack of link functionality in FAT32, and kept ever since, since MS has a policy of keeping the creepy things it invented in the XXth century forever... This kind of reasons made me flee Windows some time ago...

I think this link contains some kind of specifications (if you're not affraid in navigating terrible MS doc).

I thought about a solution not involving luaotfload: do we still use fontconfig? If so, it might help... otherwise, if you're not willing to implement it (which I understand), maybe @BGMcoder could propose a patch, and in the mean time, you could just document that it doesn't work. What do you think?

@BGMcoder
Copy link

@eroux Sure, I am willing to help - I've never made a patch before. What do I do? What do I test?

@eroux
Copy link
Member Author

eroux commented May 27, 2015

First it would help to see if XeTeX recognizes the font, can you please try?

Afterwards you'll have to fork the repository, clone it on your machine, install the version of luaotfload you've just cloned, understand the code that needs fixing (certainly in src/luaotfload-database.lua), find a proper way to read a .lnk file in lua, fix the code, and make a pull request...

@BGMcoder
Copy link

Oh, wow; that sounds rather more involved than I am allowed to commit to... I don't think I can do this.

@eroux
Copy link
Member Author

eroux commented May 27, 2015

Ok, can you at least try with XeTeX please? Take any document (not involving gregorio) using you linked font, to see if XeTeX manages to read the font

@BGMcoder
Copy link

I can do that. I have xetex on the commandline. What kind of document?
I have a simple tex file like this, but xetex doesn't understand \documentclass{article}

\documentclass{article}
\usepackage{fontspec}
\setmainfont{actionis regular}
\begin{document}
test
\end{document}

@eroux
Copy link
Member Author

eroux commented May 27, 2015

You can use xelatex to compile a LaTeX document with XeTeX.

@BGMcoder
Copy link

okay, so I have a font installed via shortcut called "ActionIs Regular".
here is the output once it starts erring:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "actionis regular" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H .
!...............................................

l.3 \setmainfont{actionis regular}

?
kpathsea:make_tex: Invalid fontname actionis regular', contains ' ' kpathsea:make_tex: Invalid fontnameactionis regular', contains ' '

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "actionis regular" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H .
!...............................................

l.3 \setmainfont{actionis regular}

?
kpathsea:make_tex: Invalid fontname actionis regular', contains ' ' kpathsea:make_tex: Invalid fontnameactionis regular/B', contains ' '
kpathsea:make_tex: Invalid fontname actionis regular', contains ' ' kpathsea:make_tex: Invalid fontnameactionis regular/I', contains ' '
kpathsea:make_tex: Invalid fontname actionis regular', contains ' ' kpathsea:make_tex: Invalid fontnameactionis regular/BI', contains ' '
kpathsea:make_tex: Invalid fontname `actionis regular:', contains ' '
! Font EU1/actionisregular(0)/m/n/10="actionis regular:" at 10.0pt not loadable
: Metric (TFM) file or installed font not found.

relax
l.3 \setmainfont{actionis regular}

?

@eroux
Copy link
Member Author

eroux commented May 27, 2015

Thanks! @phi-gamma, if you agree, we can mark it as wontfix (until someone provides a patch) and document it?

@eroux
Copy link
Member Author

eroux commented May 27, 2015

I was about to make a pull request to add the documentation, should I base it on master or is there a more recent branch on your repo?

@BGMcoder
Copy link

@eroux I posted a thread in the High-Logic Font Manager forum, and the windows font guru, Mr. Dennissen is answering my thread.
http://forum.high-logic.com/viewtopic.php?f=12&t=5612&p=25551#p25551

So, it appears I have misled you - Windows Explorer shows those shortcuts, but they are not really there. Apparently, it is a Windows trick to show the shortcut icons. Those files are not located in c:\windows\fonts - AND NEITHER ARE THE *.lnk files. Windows Explorer just shows all the installed fonts there even though there are no files there for those fonts. It's confusing because Explorer is lying to us. When I open c:\windows\fonts in my other file-browser then it shows me the real contents of that directory - AND those fonts are not there, and neither are there any *.lnk files.

@BGMcoder
Copy link

So there are no *.lnk files to read at all. You'll have to read the registry.

@eroux
Copy link
Member Author

eroux commented May 27, 2015

Wow, this design is incredibe... So it seems there are people who sell fonts with an installer that doesn't put the fonts in C:\\Windows\Fonts but only in the registry?

@BGMcoder
Copy link

@eroux
Copy link
Member Author

eroux commented May 27, 2015

There's an entry about reading the register in the Lua FAQ

@BGMcoder
Copy link

@eroux
Copy link
Member Author

eroux commented May 28, 2015

@phi-gamma what do you think about asking Hans about what would be the best solution to that (if any)? There's a ConTeXt user on the thread and this link that might be helpful. Maybe he'd like to have it working in ConTeXt... What do you think? If you agree, tell me if you prefer asking him directly or if you want me to do it.

@eroux eroux changed the title shortcut in C://Windows/Fonts not read find fonts in Windows registry May 30, 2015
@eroux
Copy link
Member Author

eroux commented May 30, 2015

I think the best solution would be Hans' proposal. The main problem is that, as reg is not in the shell_escape_commands, it won't be able to be run in the normal lualatex process, so users would have to run luaotfload-tool by hand, which is not easy under Windows... So it's not perfect, but at least people really interested in this can find a solution. @phi-gamma what do you think?

@phi-gamma
Copy link
Member

@eroux I did a dump of the registry fonts à la Hans on some test
VM at work. That I’ll be able to work with for a start.

@eroux
Copy link
Member Author

eroux commented Jun 10, 2015

Great! Thanks a lot!

@phi-gamma phi-gamma added this to the version 2.7 milestone Nov 21, 2015
@phi-gamma
Copy link
Member

···<date: 2015-05-30, Saturday>···<from: Elie Roux>···

I think the best solution would be Hans' proposal.
The main problem is that, as reg is not in the
shell_escape_commands, it won't be able to be run in the normal
lualatex process, so users would have to run luaotfload-tool
by hand, which is not easy under Windows... So it's not perfect,
but at least people really interested in this can find a
solution. @phi-gamma what do you think?

Here’s a POC parser for reg output:

https://gist.github.com/phi-gamma/404e587650d43af14f2d

There’s a problem though: The fonts listed are all located in the
default directory which is c:/Windows/Fonts on my VM. I. e.
the file names retrieved this way represent relative paths
inside that prefix. The output offers no clue as to how shortcuts
are handled.

Using standard GUI methods (install via context menu) I can’t
make Windows not install the fonts there. The referenced tool
appears to apply some extra magic not accessible to mere mortals.
So in order to proceed at this point we need someone to run

reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"

on a system with shortcut-installed fonts and supply us with the
output. Then we’ll see: If this gets us the resolved paths from
the .lnk file, we’re good. If it yields the location of the
shortcut file itself, we’re back to square one.

@phi-gamma
Copy link
Member

Closing this due to lack of feedback.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants