mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
1 parent
1432562c6f
commit
8f9e194c0c
1 file changed
+13
-19
+13
-19
@@ -826,10 +826,8 @@ func encodeNumberCFF(buf *bytes.Buffer, val float64) {
|
|||||||
// 返回: []byte 编码后的索引数据
|
// 返回: []byte 编码后的索引数据
|
||||||
func encodeCFFIndex(items []([]byte)) []byte {
|
func encodeCFFIndex(items []([]byte)) []byte {
|
||||||
count := len(items)
|
count := len(items)
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
binary.Write(buf, binary.BigEndian, uint16(count))
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
return buf.Bytes()
|
return []byte{0, 0}
|
||||||
}
|
}
|
||||||
totalSize := 0
|
totalSize := 0
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
@@ -845,25 +843,21 @@ func encodeCFFIndex(items []([]byte)) []byte {
|
|||||||
if totalSize+1 > 16777215 {
|
if totalSize+1 > 16777215 {
|
||||||
offSize = 4
|
offSize = 4
|
||||||
}
|
}
|
||||||
buf.WriteByte(byte(offSize))
|
base := 3 + (count+1)*offSize
|
||||||
|
data := make([]byte, base+totalSize)
|
||||||
|
binary.BigEndian.PutUint16(data, uint16(count))
|
||||||
|
data[2] = byte(offSize)
|
||||||
offset := 1
|
offset := 1
|
||||||
putOffset(buf, offset, offSize)
|
for i := 0; i <= count; i++ {
|
||||||
for _, item := range items {
|
for j := 0; j < offSize; j++ {
|
||||||
offset += len(item)
|
data[3+i*offSize+offSize-1-j] = byte(offset >> (8 * j))
|
||||||
putOffset(buf, offset, offSize)
|
|
||||||
}
|
}
|
||||||
for _, item := range items {
|
if i < count {
|
||||||
buf.Write(item)
|
copy(data[base+offset-1:], items[i])
|
||||||
|
offset += len(items[i])
|
||||||
}
|
}
|
||||||
return buf.Bytes()
|
}
|
||||||
}
|
return data
|
||||||
|
|
||||||
// putOffset 写入指定大小的偏移量
|
|
||||||
// 入参: buf 缓冲区, val 偏移值, size 字节大小
|
|
||||||
func putOffset(buf *bytes.Buffer, val int, size int) {
|
|
||||||
tmp := make([]byte, 4)
|
|
||||||
binary.BigEndian.PutUint32(tmp, uint32(val))
|
|
||||||
buf.Write(tmp[4-size:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCFFIndexCount 读取CFF索引的计数和大小
|
// getCFFIndexCount 读取CFF索引的计数和大小
|
||||||
|
|||||||
Reference in new issue
Block a user