f
This commit is contained in:
parent
3fa9d34544
commit
d8f6e870a3
1 changed files with 56 additions and 85 deletions
|
@ -349,10 +349,10 @@ type
|
||||||
nominalWidthX: int
|
nominalWidthX: int
|
||||||
ros: array[3, string]
|
ros: array[3, string]
|
||||||
strokeWidth: int
|
strokeWidth: int
|
||||||
uidBase: pointer
|
uidBase: int
|
||||||
underlinePosition: int
|
underlinePosition: int
|
||||||
underlineThickness: int
|
underlineThickness: int
|
||||||
uniqueId: pointer
|
uniqueId: int
|
||||||
version: string
|
version: string
|
||||||
weight: string
|
weight: string
|
||||||
|
|
||||||
|
@ -365,9 +365,6 @@ type
|
||||||
globalSubrIndex: seq[string]
|
globalSubrIndex: seq[string]
|
||||||
topDict: CFFTopDict
|
topDict: CFFTopDict
|
||||||
charIndex: seq[string]
|
charIndex: seq[string]
|
||||||
#charsets*: CFF..
|
|
||||||
#charStringsIndex*: CFF..
|
|
||||||
#privateDict*: CFF..
|
|
||||||
isCID: bool
|
isCID: bool
|
||||||
|
|
||||||
OpenType* = ref object
|
OpenType* = ref object
|
||||||
|
@ -1461,10 +1458,10 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
|
|
||||||
cffTopDict.ros = topDict.getArrStr("ros", ["", "", ""], strings)
|
cffTopDict.ros = topDict.getArrStr("ros", ["", "", ""], strings)
|
||||||
cffTopDict.strokeWidth = topDict.getInt("strokeWidth", 0)
|
cffTopDict.strokeWidth = topDict.getInt("strokeWidth", 0)
|
||||||
# cffTopDict.uidBase: pointer
|
cffTopDict.uidBase = topDict.getInt("uidBase", 0)
|
||||||
cffTopDict.underlinePosition = topDict.getInt("underlinePosition", -100)
|
cffTopDict.underlinePosition = topDict.getInt("underlinePosition", -100)
|
||||||
cffTopDict.underlineThickness = topDict.getInt("underlineThickness", 50)
|
cffTopDict.underlineThickness = topDict.getInt("underlineThickness", 50)
|
||||||
# cffTopDict.uniqueId: pointer
|
cffTopDict.uniqueId = topDict.getInt("uniqueId", 0)
|
||||||
cffTopDict.version = topDict.getStr("version", "")
|
cffTopDict.version = topDict.getStr("version", "")
|
||||||
cffTopDict.weight = topDict.getStr("weight", "")
|
cffTopDict.weight = topDict.getStr("weight", "")
|
||||||
result.add(cffTopDict)
|
result.add(cffTopDict)
|
||||||
|
@ -1477,16 +1474,6 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
failUnsupported("CFF multiple topDict")
|
failUnsupported("CFF multiple topDict")
|
||||||
result.topDict = topDicts[0]
|
result.topDict = topDicts[0]
|
||||||
|
|
||||||
# Subroutines are encoded using the negative half of the number space.
|
|
||||||
# See type 2 chapter 4.7 "Subroutine operators".
|
|
||||||
result.topDict.subrsBias =
|
|
||||||
if result.globalSubrIndex.len < 1240:
|
|
||||||
107
|
|
||||||
elif result.globalSubrIndex.len < 33900:
|
|
||||||
1131
|
|
||||||
else:
|
|
||||||
32768
|
|
||||||
|
|
||||||
if result.topDict.ros[0] != "" and result.topDict.ros[1] != "":
|
if result.topDict.ros[0] != "" and result.topDict.ros[1] != "":
|
||||||
result.isCID = true
|
result.isCID = true
|
||||||
|
|
||||||
|
@ -1504,15 +1491,6 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
var format = buf.readUint8(at)
|
var format = buf.readUint8(at)
|
||||||
inc at
|
inc at
|
||||||
|
|
||||||
# if (format === 0) {
|
|
||||||
# // Simple list of nGlyphs elements
|
|
||||||
# for (var iGid = 0; iGid < nGlyphs; iGid++) {
|
|
||||||
# fdIndex = parser.parseCard8();
|
|
||||||
# if (fdIndex >= fdArrayCount) {
|
|
||||||
# throw new Error('CFF table CID Font FDSelect has bad FD index value ' + fdIndex + ' (FD count ' + fdArrayCount + ')');
|
|
||||||
# }
|
|
||||||
# fdSelect.push(fdIndex);
|
|
||||||
# }
|
|
||||||
if format == 3:
|
if format == 3:
|
||||||
# Ranges
|
# Ranges
|
||||||
var nRanges = buf.readUint16(at).swap().int
|
var nRanges = buf.readUint16(at).swap().int
|
||||||
|
@ -1536,7 +1514,6 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
while first < next:
|
while first < next:
|
||||||
result.add(fdIndex)
|
result.add(fdIndex)
|
||||||
inc first
|
inc first
|
||||||
|
|
||||||
first = next
|
first = next
|
||||||
|
|
||||||
if next != nGlyphs:
|
if next != nGlyphs:
|
||||||
|
@ -1545,7 +1522,8 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
else:
|
else:
|
||||||
failUnsupported("CFF Table CID Font FDSelect format")
|
failUnsupported("CFF Table CID Font FDSelect format")
|
||||||
|
|
||||||
result.topDict.fdSelectSeq = parseCFFFDSelect(buf, fdSelectOffset, maxp.numGlyphs.int, result.topDict.fdArraySeq.len)
|
result.topDict.fdSelectSeq = parseCFFFDSelect(
|
||||||
|
buf, fdSelectOffset, maxp.numGlyphs.int, result.topDict.fdArraySeq.len)
|
||||||
|
|
||||||
if result.topDict.subrs != 0:
|
if result.topDict.subrs != 0:
|
||||||
var subrOffset =
|
var subrOffset =
|
||||||
|
@ -1553,70 +1531,63 @@ proc parseCFFTable(buf: string, offset: int, maxp: MaxpTable): CFFTable =
|
||||||
result.topDict.subrIndex = buf.parseCFFIndex(subrOffset)
|
result.topDict.subrIndex = buf.parseCFFIndex(subrOffset)
|
||||||
result.topDict.subrsBias = calcCFFSubroutineBias(result.topDict.subrIndex)
|
result.topDict.subrsBias = calcCFFSubroutineBias(result.topDict.subrIndex)
|
||||||
|
|
||||||
proc parseCFFIndexLowMemory(buf: string, offset: int): seq[int] =
|
# proc parseCFFIndexLowMemory(buf: string, offset: int): seq[int] =
|
||||||
proc getOffset(dataView: string, offset, offSize: int): int =
|
# proc getOffset(dataView: string, offset, offSize: int): int =
|
||||||
var v = 0
|
# var v = 0
|
||||||
for i in 0 ..< offSize:
|
# for i in 0 ..< offSize:
|
||||||
v = v shl 8
|
# v = v shl 8
|
||||||
v += dataView.readUint8(offset + i).int
|
# v += dataView.readUint8(offset + i).int
|
||||||
return v
|
# return v
|
||||||
let count = buf.readUint16(offset).swap().int
|
# let count = buf.readUint16(offset).swap().int
|
||||||
var objectOffset = 0
|
# var objectOffset = 0
|
||||||
if count != 0:
|
# if count != 0:
|
||||||
var offsetSize = buf.readUint8(offset + 2).int
|
# var offsetSize = buf.readUint8(offset + 2).int
|
||||||
objectOffset = offset + ((count + 1) * offsetSize) + 2
|
# objectOffset = offset + ((count + 1) * offsetSize) + 2
|
||||||
var pos = offset + 3
|
# var pos = offset + 3
|
||||||
for i in 0 .. count:
|
# for i in 0 .. count:
|
||||||
let offsetValue = buf.getOffset(pos, offsetSize)
|
# let offsetValue = buf.getOffset(pos, offsetSize)
|
||||||
result.add offsetValue
|
# result.add offsetValue
|
||||||
pos += offsetSize
|
# pos += offsetSize
|
||||||
|
|
||||||
let charStringsIndex = parseCFFIndexLowMemory(
|
# let charStringsIndex = parseCFFIndexLowMemory(
|
||||||
buf, offset + result.topDict.charStrings)
|
# buf, offset + result.topDict.charStrings)
|
||||||
let nGlyphs = charStringsIndex.len
|
# proc parseCFFCharset(
|
||||||
|
# buf: string,
|
||||||
|
# offset: int,
|
||||||
|
# nGlyphs: int,
|
||||||
|
# stringIndex: seq[string]
|
||||||
|
# ): seq[string] =
|
||||||
|
# # The .notdef glyph is implied
|
||||||
|
# var charset = @[".notdef"]
|
||||||
|
# var nGlyphs = nGlyphs - 1
|
||||||
|
# var pos = offset
|
||||||
|
# var format = buf.readUint8(pos)
|
||||||
|
# inc pos
|
||||||
|
# if format == 2:
|
||||||
|
# while charset.len <= nGlyphs:
|
||||||
|
# var
|
||||||
|
# sid = buf.readUint16(pos).swap().int
|
||||||
|
# pos += 2
|
||||||
|
# var
|
||||||
|
# count = buf.readUint16(pos).swap().int
|
||||||
|
# pos += 2
|
||||||
|
# for i in 0 .. count:
|
||||||
|
# charset.add(getCFFString(stringIndex, sid))
|
||||||
|
# if charset.len >= nGlyphs:
|
||||||
|
# break
|
||||||
|
# sid += 1
|
||||||
|
# else:
|
||||||
|
# failUnsupported("CFF charset format: " & $format)
|
||||||
|
|
||||||
proc parseCFFCharset(
|
# # Why do we need this anyways?
|
||||||
buf: string,
|
# # let nGlyphs = charStringsIndex.len
|
||||||
offset: int,
|
# #var charset = parseCFFCharset(
|
||||||
nGlyphs: int,
|
# # buf, offset + result.topDict.charset, nGlyphs, result.stringIndex.objects)
|
||||||
stringIndex: seq[string]
|
|
||||||
): seq[string] =
|
|
||||||
# The .notdef glyph is implied
|
|
||||||
var charset = @[".notdef"]
|
|
||||||
var nGlyphs = nGlyphs - 1
|
|
||||||
var pos = offset
|
|
||||||
var format = buf.readUint8(pos)
|
|
||||||
inc pos
|
|
||||||
if format == 2:
|
|
||||||
while charset.len <= nGlyphs:
|
|
||||||
var
|
|
||||||
sid = buf.readUint16(pos).swap().int
|
|
||||||
pos += 2
|
|
||||||
var
|
|
||||||
count = buf.readUint16(pos).swap().int
|
|
||||||
pos += 2
|
|
||||||
for i in 0 .. count:
|
|
||||||
charset.add(getCFFString(stringIndex, sid))
|
|
||||||
if charset.len >= nGlyphs:
|
|
||||||
break
|
|
||||||
sid += 1
|
|
||||||
else:
|
|
||||||
failUnsupported("CFF charset format: " & $format)
|
|
||||||
|
|
||||||
# Why do we need this anyways?
|
|
||||||
#var charset = parseCFFCharset(
|
|
||||||
# buf, offset + result.topDict.charset, nGlyphs, result.stringIndex.objects)
|
|
||||||
var start = offset + result.topDict.charStrings
|
var start = offset + result.topDict.charStrings
|
||||||
result.charIndex = buf.parseCFFIndex(start)
|
result.charIndex = buf.parseCFFIndex(start)
|
||||||
|
|
||||||
|
|
||||||
# let glyphIndex = 2539
|
|
||||||
# let charstring = charIndex.objects[glyphIndex]
|
|
||||||
# var path = parseCFFCharstring(result, charstring)
|
|
||||||
# for glyphIndex in 0 ..< result.charIndex.objects.len:
|
|
||||||
# let charstring = result.charIndex.objects[glyphIndex]
|
|
||||||
# var path = parseCFFCharstring(result, charstring)
|
|
||||||
|
|
||||||
|
|
||||||
# proc parseLangSys(buf: string, offset: int): LangSys =
|
# proc parseLangSys(buf: string, offset: int): LangSys =
|
||||||
# var i = offset
|
# var i = offset
|
||||||
|
|
Loading…
Reference in a new issue