summaryrefslogtreecommitdiff
path: root/src/fontloader/misc/fontloader-font-otr.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontloader/misc/fontloader-font-otr.lua')
-rw-r--r--src/fontloader/misc/fontloader-font-otr.lua80
1 files changed, 64 insertions, 16 deletions
diff --git a/src/fontloader/misc/fontloader-font-otr.lua b/src/fontloader/misc/fontloader-font-otr.lua
index 3542d18..24f6854 100644
--- a/src/fontloader/misc/fontloader-font-otr.lua
+++ b/src/fontloader/misc/fontloader-font-otr.lua
@@ -60,16 +60,16 @@ if not modules then modules = { } end modules ['font-otr'] = {
-- faster but it might not be the real bottleneck as we still need to juggle data. It
-- is probably more memory efficient as no intermediate strings are involved.
-if not characters then
- require("char-def")
- require("char-ini")
-end
+-- if not characters then
+-- require("char-def")
+-- require("char-ini")
+-- end
local next, type, unpack = next, type, unpack
local byte, lower, char, strip, gsub = string.byte, string.lower, string.char, string.strip, string.gsub
local bittest = bit32.btest
-local concat, remove, unpack = table.concat, table.remov, table.unpack
-local floor, mod, abs, sqrt, round = math.floor, math.mod, math.abs, math.sqrt, math.round
+local concat, remove, unpack, fastcopy = table.concat, table.remov, table.unpack, table.fastcopy
+local floor, abs, sqrt, round = math.floor, math.abs, math.sqrt, math.round
local P, R, S, C, Cs, Cc, Ct, Carg, Cmt = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg.Cc, lpeg.Ct, lpeg.Carg, lpeg.Cmt
local lpegmatch = lpeg.match
@@ -1066,14 +1066,13 @@ readers.hmtx = function(f,fontdata,specification)
local nofmetrics = fontdata.horizontalheader.nofhmetrics
local glyphs = fontdata.glyphs
local nofglyphs = fontdata.nofglyphs
- local nofrepeated = nofglyphs - nofmetrics
local width = 0 -- advance
local leftsidebearing = 0
for i=0,nofmetrics-1 do
local glyph = glyphs[i]
width = readshort(f)
leftsidebearing = readshort(f)
- if advance ~= 0 then
+ if width ~= 0 then
glyph.width = width
end
-- if leftsidebearing ~= 0 then
@@ -1082,8 +1081,8 @@ readers.hmtx = function(f,fontdata,specification)
end
-- The next can happen in for instance a monospace font or in a cjk font
-- with fixed widths.
- for i=nofmetrics,nofrepeated do
- local glyph = glyphs[i]
+ for i=nofmetrics,nofglyphs-1 do
+ local glyph = glyphs[i]
if width ~= 0 then
glyph.width = width
end
@@ -1187,6 +1186,8 @@ local sequence = {
{ 3, 0, 6 },
-- variants
{ 0, 5, 14 },
+ -- last resort ranges
+ { 3, 10, 13 },
}
-- local sequence = {
@@ -1269,10 +1270,10 @@ formatreaders[4] = function(f,fontdata,offset)
-- bad encoding
elseif offset == 0 then
if trace_cmap then
- report("format 4.%i segment %2i from %C upto %C at index %H",1,segment,startchar,endchar,mod(startchar + delta,65536))
+ report("format 4.%i segment %2i from %C upto %C at index %H",1,segment,startchar,endchar,(startchar + delta) % 65536)
end
for unicode=startchar,endchar do
- local index = mod(unicode + delta,65536)
+ local index = (unicode + delta) % 65536
if index and index > 0 then
local glyph = glyphs[index]
if glyph then
@@ -1302,13 +1303,13 @@ formatreaders[4] = function(f,fontdata,offset)
else
local shift = (segment-nofsegments+offset/2) - startchar
if trace_cmap then
- report("format 4.%i segment %2i from %C upto %C at index %H",0,segment,startchar,endchar,mod(startchar + delta,65536))
+ report("format 4.%i segment %2i from %C upto %C at index %H",0,segment,startchar,endchar,(startchar + delta) % 65536)
end
for unicode=startchar,endchar do
local slot = shift + unicode
local index = indices[slot]
if index and index > 0 then
- index = mod(index + delta,65536)
+ index = (index + delta) % 65536
local glyph = glyphs[index]
if glyph then
local gu = glyph.unicode
@@ -1389,7 +1390,7 @@ formatreaders[12] = function(f,fontdata,offset)
local last = readulong(f)
local index = readulong(f)
if trace_cmap then
- report("format 12 from %C to %C",first,last)
+ report("format 12 from %C to %C starts at index %i",first,last,index)
end
for unicode=first,last do
local glyph = glyphs[index]
@@ -1417,6 +1418,53 @@ formatreaders[12] = function(f,fontdata,offset)
return nofdone
end
+formatreaders[13] = function(f,fontdata,offset)
+ --
+ -- this fector is only used for simple fallback fonts
+ --
+ setposition(f,offset+2+2+4+4) -- skip format reserved length language
+ local mapping = fontdata.mapping
+ local glyphs = fontdata.glyphs
+ local duplicates = fontdata.duplicates
+ local nofgroups = readulong(f)
+ local nofdone = 0
+ for i=1,nofgroups do
+ local first = readulong(f)
+ local last = readulong(f)
+ local index = readulong(f)
+ if first < privateoffset then
+ if trace_cmap then
+ report("format 13 from %C to %C get index %i",first,last,index)
+ end
+ local glyph = glyphs[index]
+ local unicode = glyph.unicode
+ if not unicode then
+ unicode = first
+ glyph.unicode = unicode
+ first = first + 1
+ end
+ local list = duplicates[unicode]
+ mapping[index] = unicode
+ if not list then
+ list = { }
+ duplicates[unicode] = list
+ end
+ if last >= privateoffset then
+ local limit = privateoffset - 1
+ report("format 13 from %C to %C pruned to %C",first,last,limit)
+ last = limit
+ end
+ for unicode=first,last do
+ list[unicode] = true
+ end
+ nofdone = nofdone + last - first + 1
+ else
+ report("format 13 from %C to %C ignored",first,last)
+ end
+ end
+ return nofdone
+end
+
formatreaders[14] = function(f,fontdata,offset)
if offset and offset ~= 0 then
setposition(f,offset)
@@ -2226,7 +2274,7 @@ function readers.extend(fontdata)
end
end
---
+-- for now .. this will move to a context specific file
if fonts.hashes then