Skip to content
This repository has been archived by the owner. It is now read-only.

font availability test and font fallback? #74

Closed
eroux opened this issue May 14, 2013 · 8 comments
Closed

font availability test and font fallback? #74

eroux opened this issue May 14, 2013 · 8 comments
Assignees

Comments

@eroux
Copy link
Member

@eroux eroux commented May 14, 2013

Building very complex documents (like polyglossia documentation), I realize how useful it would be to be able to test if a font is available or not, this would allow fallbacks for non-available fonts.

Two usecases :

One for polyglossia : we want to write farsi, whatever the font, and not everyone has the same, so we could test a few fonts, and take the first available.

One for unicode-math-example: we build a table with all possible math symbols in all possible math fonts, but it would be useful to check if a math font is available before building its table...

These are very specific, but I'm sure others would come. This would be quite new in the TeX World I guess, but it sounds like an improvement... What do you think?

@phi-gamma
Copy link
Member

@phi-gamma phi-gamma commented May 14, 2013

Sounds useful. But:

  • we have --find=<name> and --list=* in luaotfload-tool that assist in ascertaining whether the system has a font;
  • font name fallbacks seems like a good idea to add another layer of unpredictability (fallbacks) on top of something that is already messy as hell (font names).

Apart from that, what you are pondering is what I’d express as lookup chaining: if the test for a font results in a negative, try the next one in the list of candidates etc. We’d need a special syntax (or csname) for that. It’s not impossible, though the current design doesn’t exactly lend itself for this kind of addition.

Personally I’d rather lobby for Latex to adopt the concept of typescripts :p.

@eroux
Copy link
Member Author

@eroux eroux commented May 14, 2013

Hmmm, I was not thinking about something interfering with the whole lookup thing, but just a small function returning a bool, true if the name or file resolves to something, and false otherwise. With this you could easily do something like

local resolves = luaotfload.aux.resolves
myfarsifont = "Farsi simple bold"
if not resolves(myfarsifont) then
  myfarsifont = "My fallback"
end
tex.sprint(myfarsifont)

it seems simple and clear... for sure, automatization would require something bigger... What do you think?

@phi-gamma
Copy link
Member

@phi-gamma phi-gamma commented May 14, 2013

It depends on what you intend to resolve -- a font name or a filename? For font names you can just do what luaotfload-tool does:

local query = "<font name here>"
local tmpspec = {
    name          = query,
    lookup        = "name",
    specification = "name:" .. query,
    optsize       = 0,
}

local foundname, subfont, success = fonts.names.resolve(nil, nil, tmpspec)

@eroux
Copy link
Member Author

@eroux eroux commented May 14, 2013

hmmm... yes, it sounds good! Though, for a public interface, having two nil arguments for a function is something really strange, what about a

function luaotfload.aux.resolve(s) = fonts.name.resolve(nil, nil, s)

?

@phi-gamma
Copy link
Member

@phi-gamma phi-gamma commented May 14, 2013

Better:

function luaotfload.aux.resolve_name (s) = return fonts.name.resolve(nil, nil, s) end

but still, only for font names.

@ghost ghost assigned phi-gamma May 14, 2013
@phi-gamma
Copy link
Member

@phi-gamma phi-gamma commented May 14, 2013

Just one question: you really only need raw fontnames, not the fancy /b, /i style modifiers?

@phi-gamma
Copy link
Member

@phi-gamma phi-gamma commented May 14, 2013

You now have two functions for that at your disposal: resolve_fontname() which resolves a single name, and resolve_fontlist() which returns the first font found in a list of font names.

\input luaotfload.sty
\directlua{
  print""
  local aux = luaotfload.aux

  %% hit: returns string and int
  local found, sub = aux.resolve_fontname("Iwona Regular")
  print(found, sub)

  %% miss: returns false, false (also triggers db update)
  local found, sub = aux.resolve_fontname("Expensive Adobe Stuff Pro")
  print(found, sub)

  %% or find the first resolvable in list
  local fontlist = {
    "Adobe Comic Sans Pro",
    "Zapf Klingon Bold Italic",
    "LM Roman 12 Regular",
  }
  local foundname, sub = aux.resolve_fontlist(fontlist)
  print(foundname, sub)
  print""
}

\bye

eroux added a commit that referenced this issue May 15, 2013
@eroux
Copy link
Member Author

@eroux eroux commented May 15, 2013

Sorry for the late answer, today is my day off... well, this is just wonderful, actually better than I asked, Thanks!

@eroux eroux closed this May 15, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants