\pdfoutput1

\directlua0{\unexpanded{
	function load_otf_font(filename,size)
		local f = { }
		local font = fontforge.open(filename) 
		if font then 
			local otffont = fontforge.to_table(font) 
			f.name = otffont.fontname
			f.fullname = otffont.names[1].names.fullname
			f.parameters = { }
			otffont.design_size = otffont.design_size or 100
			f.designsize = 65536 * otffont.design_size / 10
			if size < 0 then size = f.designsize * (-size / 1000) end
			f.size = size
			f.parameters.slant = 0
			f.parameters.space = size * 0.25
			f.parameters.space_stretch = 0.3 * size
			f.parameters.space_shrink = 0.1 * size
			f.parameters.x_height = 0.4 * size
			f.parameters.quad = 1.0 * size
			f.parameters.extra_space = 0
			f.characters = { }
			local scaling = size / otffont.units_per_em
			local names_of_char = { }
			for char, glyph in pairs(otffont.map.map) do
				names_of_char[otffont.glyphs[glyph].name] =
					otffont.map.backmap[glyph]
			end

% Not used:
%			local names_of_glyph = { }
%			for char, glyph in pairs(otffont.map.map)
%			do
%				names_of_glyph[otffont.glyphs[glyph].name] =
%					glyph
%			end

			for char, glyph in pairs(otffont.map.map) do
				local glyph_table = otffont.glyphs[glyph]

				f.characters[char] = {
					index = glyph,
					width = glyph_table.width * scaling,
					name = glyph_table.name,
				}
				if glyph_table.kerns then
					local kerns = { }
					for _, kern in pairs(glyph_table.kerns) do
						kerns[names_of_char[kern.char]] = kern.off * scaling
					end
					f.characters[char].kerns = kerns
				end
				if glyph_table.ligatures then
					local ligatures = { }
					for _, lig in pairs(glyph_table.ligatures) do
						%texio.write_nl(lig)
						%ligatures[] = {
						%	type = 0,
						%	char = 
						%}
						% TODO:
						%f.characters[char].ligatures = ligatures
					end
				end
			end
			f.filename = filename
			f.type = 'real'
			f.format = 'opentype'
			f.embedding = 'subset'
			f.cidinfo = {
				registry = "Adobe",
				ordering = "Identity",
				supplement = 0,
				version = 1
			}
			
			fontforge.close(font) 
		end
		return f 
	end
	
	function define_font_callback(name,size,id)
		local filename = kpse.find_file(name .. '.otf','opentype fonts')
		texio.write('\nLoading font ' .. filename .. '\n')
		local r = load_otf_font(filename,size)
		texio.write('done\n')
		return r
	end 
	
	callback.register('define_font',define_font_callback)
	
	% And while we're at it: (D)
	texio.write('\n')
	texio.write('012345678901234567890123456789\n')
	texio.write('012345678901234567890123456789\n')
	texio.write('012345678901234567890123456789\n')
	texio.write('012345678901234567890123456789\n')
}}


\font\textfont=lmroman10-regular at 10pt % (A)
% \font\textfont=lmroman10-bold scaled 1000 % (B)
% \font\textfont=lmroman10-bold % (C)

\textfont

Lûátèx sürė ĩs grēăt! fi ffi AV


\bye

A works perfectly. I had an old version of the wiki code at home where
the scaling was incorrect.



B and C produce (C most likely because 'scaled 1000' is the default):

This is LuaTeX, Version snapshot-0.20.0-2007120515 (Web2C 7.5.6)
(OTFTest.texLoading font /usr/local/teTeX/share/texmf.tetex/fonts/opentype/publ
ic/lm/lmroman10-bold.otf [1{/usr/local/teTeX/share/texmf.local/fonts/map/pdftex
/updmap/pdftex.map}
! pdfTeX error (arithmetic): divided by zero.
\plainoutput ...headline \pagebody \makefootline }
                                                  \advancepageno \ifnum \out...
<output> {\plainoutput 
                       }
\supereject ->\par \penalty -\@MM 
                                  
\bye ->\par \vfill \supereject 
                               \end 
l.91 \bye
         
!  ==> Fatal error occurred, no output PDF file produced

Changing the output routine to '\output{}' does not change anything.



D creates some strange output:

 012345678901234567890123456789
 012345678901234567890123456789
 0
12345678901234567890123456789
 012345678901234567890123456789

It seems that texio.write does not reset its internal line length counter
then writing a "\n". Also, there is a leading space for some reason.

BTW: Is it possible to add a function which does not wrap after 80
characters? Or maybe the wrapping is completely obsolete (though I am
not sure about tracing TeX code).


Another weird thing: The Latin Modern font contains ligatures, but they are
not inside a "ligatures" table. Example: "f" (simple output of the fontforge
glyph table using code from the Lua wiki):

[{boundingbox={33,0,357,705},kerns={{char="quotedblright.cm",off=28,lookup="pp_
l_1_s"},{char="quotedblleft.cm",off=28,lookup="pp_l_1_s"},{char="quotedblright"
,off=28,lookup="pp_l_1_s"},{char="quotedblleft",off=28,lookup="pp_l_1_s"},{char
="quoteright",off=28,lookup="pp_l_1_s"},{char="quoteleft",off=28,lookup="pp_l_1
_s"},{char="bracketright",off=28,lookup="pp_l_1_s"},{char="question",off=28,loo
kup="pp_l_1_s"},{char="parenright",off=28,lookup="pp_l_1_s"},{char="exclam",off
=28,lookup="pp_l_1_s"}},name="f",unicodeenc=102,width=306}]

"f" contains a "fi" ligature:

[{lookups={ls_l_10_s={{type="ligature",specification={char="f_i",components="f 
i"}}}},boundingbox={27,0,527,705},name="f_i",unicodeenc=64257,width=556}]

But this ligature is not associated with the "f" letter in any way. Is this a
bug in the font? In LuaTeX? In the manual?

I installed the font in OS X 10.4 and used it in TextEdit (which supports
OpenType ligatures), and fi and other ligatures were inserted correctly.
So I would guess that the font is OK.

The font's version is 1.010.


And finally: "design_size" vs. "designsize" ...

