mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
model: add a reference to width table format and simplify the code
This commit is contained in:
parent
7e2a987f8a
commit
e07fa3b2c0
@ -439,25 +439,37 @@ func NewCompositePdfFontFromTTFFile(filePath string) (*PdfFont, error) {
|
|||||||
// Construct W array. Stores character code to width mappings.
|
// Construct W array. Stores character code to width mappings.
|
||||||
wArr := &core.PdfObjectArray{}
|
wArr := &core.PdfObjectArray{}
|
||||||
|
|
||||||
for i := uint16(0); int(i) < len(runes); {
|
// 9.7.4.3 Glyph metrics in CIDFonts
|
||||||
|
|
||||||
j := i + 1
|
// In the first format, c shall be an integer specifying a starting CID value; it shall be followed by an array of
|
||||||
for int(j) < len(runes) {
|
// n numbers that shall specify the widths for n consecutive CIDs, starting with c.
|
||||||
if runeToWidthMap[runes[i]] != runeToWidthMap[runes[j]] {
|
// The second format shall define the same width, w, as a number, for all CIDs in the range c_first to c_last.
|
||||||
|
|
||||||
|
// We always use the second format.
|
||||||
|
|
||||||
|
// TODO(dennwc): this can be done on GIDs instead of runes
|
||||||
|
for i := 0; i < len(runes); {
|
||||||
|
w := runeToWidthMap[runes[i]]
|
||||||
|
|
||||||
|
li := i
|
||||||
|
for j := i + 1; j < len(runes); j++ {
|
||||||
|
w2 := runeToWidthMap[runes[j]]
|
||||||
|
if w == w2 {
|
||||||
|
li = j
|
||||||
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
j++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The W maps from CID to width, here CID = GID.
|
// The W maps from CID to width, here CID = GID.
|
||||||
gid1 := ttf.Chars[runes[i]]
|
gid1 := ttf.Chars[runes[i]]
|
||||||
gid2 := ttf.Chars[runes[j-1]]
|
gid2 := ttf.Chars[runes[li]]
|
||||||
|
|
||||||
wArr.Append(core.MakeInteger(int64(gid1)))
|
wArr.Append(core.MakeInteger(int64(gid1)))
|
||||||
wArr.Append(core.MakeInteger(int64(gid2)))
|
wArr.Append(core.MakeInteger(int64(gid2)))
|
||||||
wArr.Append(core.MakeInteger(int64(runeToWidthMap[runes[i]])))
|
wArr.Append(core.MakeInteger(int64(w)))
|
||||||
|
|
||||||
i = j
|
i = li + 1
|
||||||
}
|
}
|
||||||
cidfont.W = core.MakeIndirectObject(wArr)
|
cidfont.W = core.MakeIndirectObject(wArr)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user