Ai
1 Star 0 Fork 0

coorrer/unipdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
xushuai 提交于 2025-09-23 15:05 +08:00 . init
package cmap
import (
"unicode/utf16"
"gitee.com/coodder/unipdf/common"
)
// hexToCharCode returns the integer that is encoded in `shex` as a big-endian hex value
func hexToCharCode(shex cmapHexString) CharCode {
code := CharCode(0)
for _, v := range shex.b {
code <<= 8
code |= CharCode(v)
}
return code
}
// hexToString decodes the UTF-16BE encoded string `shex` to unicode runes.
// 9.10.3 ToUnicode CMaps (page 293)
// • It shall use the beginbfchar, endbfchar, beginbfrange, and endbfrange operators to define the
// mapping from character codes to Unicode character sequences expressed in UTF-16BE encoding.
func hexToRunes(shex cmapHexString) []rune {
if len(shex.b) == 1 {
return []rune{rune(shex.b[0])}
}
b := shex.b
if len(b)%2 != 0 {
b = append(b, 0)
common.Log.Debug("ERROR: hexToRunes. Padding shex=%#v to %+v", shex, b)
}
n := len(b) >> 1
chars := make([]uint16, n)
for i := 0; i < n; i++ {
chars[i] = uint16(b[i<<1])<<8 + uint16(b[i<<1+1])
}
runes := utf16.Decode(chars)
return runes
}
// hexToRune is the same as hexToRunes but expects only a single rune to be decoded.
func hexToRune(shex cmapHexString) rune {
runes := hexToRunes(shex)
if n := len(runes); n == 0 {
common.Log.Debug("ERROR: hexToRune. Expected at least one rune shex=%#v", shex)
return MissingCodeRune
}
if len(runes) > 1 {
common.Log.Debug("ERROR: hexToRune. Expected exactly one rune shex=%#v -> %#v", shex, runes)
}
return runes[0]
}
func min(i, j int) int {
if i < j {
return i
}
return j
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coorrer/unipdf.git
git@gitee.com:coorrer/unipdf.git
coorrer
unipdf
unipdf
v1.2.0

搜索帮助