Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ func (f Font) getEncoder() TextEncoding {
return &byteEncoder{&macRomanEncoding}
case "Identity-H":
return f.charmapEncoding()
case "UniGB-UCS2-H":
return &ucs2Encoder{}
default:
if DebugOn {
println("unknown encoding", enc.Name())
Expand Down Expand Up @@ -303,6 +305,12 @@ func (e *nopEncoder) Decode(raw string) (text string) {
return raw
}

type ucs2Encoder struct{}

func (e *ucs2Encoder) Decode(raw string) (text string) {
return utf16Decode(raw)
}

type byteEncoder struct {
table *[256]rune
}
Expand Down
30 changes: 30 additions & 0 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ import (
"testing"
)

func TestUcs2Encoder(t *testing.T) {
// raw content in PDF (hexed for pretty)
// 6c5f82cf94f6884c005c284ea4661362636b3e56de5355005c29

// raw bytes in showEncodedText (hexed for pretty)
// 6c5f82cf94f6884c00284ea4661362636b3e56de53550029
data := []byte{
0x6C, 0x5F, // 江
0x82, 0xCF, // 苏
0x94, 0xF6, // 银
0x88, 0x4C, // 行
0x00, 0x28, // (
0x4E, 0xA4, // 交
0x66, 0x13, // 易
0x62, 0x63, // 扣
0x6B, 0x3E, // 款
0x56, 0xDE, // 回
0x53, 0x55, // 单
0x00, 0x29, // )
}

var e ucs2Encoder
text := e.Decode(string(data))

const want = "江苏银行(交易扣款回单)"
if text != want {
t.Errorf("got %q, want %q", text, want)
}
}

func TestNopEncoder(t *testing.T) {
e := &nopEncoder{}
if got := e.Decode("abc"); got != "abc" {
Expand Down
Loading