Skip to content

Commit

Permalink
Change logging to logrus
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnsth committed Apr 19, 2020
1 parent 3717928 commit 11c8f66
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 195 deletions.
6 changes: 3 additions & 3 deletions byte_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"fmt"
"io"

"github.com/unidoc/unipdf/v3/common"
"github.com/sirupsen/logrus"
)

// byteWriter encapsulates io.Writer and provides methods to write binary data as fit for truetype fonts.
Expand Down Expand Up @@ -54,9 +54,9 @@ func (w *byteWriter) checksum() uint32 {
data := w.buffer.Bytes()

if len(data) < 60 {
common.Log.Debug("Data: % X", data)
logrus.Debugf("Data: % X", data)
}
common.Log.Debug("Data length: %d", len(data))
logrus.Debugf("Data length: %d", len(data))
sum = 0

for i := 0; i < len(data); i += 4 {
Expand Down
10 changes: 5 additions & 5 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/binary"
"unicode/utf8"

"github.com/unidoc/unipdf/v3/common"
"github.com/sirupsen/logrus"

"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
Expand Down Expand Up @@ -99,7 +99,7 @@ func getCmapEncoding(platformID, encodingID int) cmapEncoding {
return cmapEncodingUCS4
}
}
common.Log.Debug("Unsupported: PlatformID=%d, EncodingID=%d", platformID, encodingID)
logrus.Debugf("Unsupported: PlatformID=%d, EncodingID=%d", platformID, encodingID)

return cmapEncodingUnsupported
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (e cmapEncoding) GetRuneDecoder() runeDecoder {
}

if d == nil {
common.Log.Debug("ERROR: Unsupported encoding (%d) - returning charcodes as runes", e)
logrus.Debugf("ERROR: Unsupported encoding (%d) - returning charcodes as runes", e)
d = unicode.UTF8.NewDecoder()
charcodeBytes = 1
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (d runeDecoder) ToBytes(charcode uint32) []byte {
case 4:
binary.BigEndian.PutUint32(b, charcode)
default:
common.Log.Debug("ERROR: Unsupported number of bytes per charcode: %d", d.charcodeBytes)
logrus.Debugf("ERROR: Unsupported number of bytes per charcode: %d", d.charcodeBytes)
return []byte{0}
}

Expand All @@ -189,7 +189,7 @@ func (d runeDecoder) DecodeRune(b []byte) rune {
// Get decoded bytes (the decoder decodes to UTF8 byte format).
decoded, err := d.Bytes(b)
if err != nil {
common.Log.Debug("Decoding error: %v", err)
logrus.Debugf("Decoding error: %v", err)
}

// TODO(gunnsth): Benchmark utf8.DecodeRune vs string().
Expand Down
8 changes: 4 additions & 4 deletions font.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"fmt"
"io"

"github.com/unidoc/unipdf/v3/common"
"github.com/sirupsen/logrus"
)

// TODO: Export only what unipdf needs:
Expand Down Expand Up @@ -188,7 +188,7 @@ func (f *font) write(w *byteWriter) error {
// Or a combined fixed size buffer with partial file system use.
// Best if such implementation is hidden within a well tested package.

common.Log.Debug("Write 1")
logrus.Debug("Write 1")
numTables := f.numTablesToWrite()
otTable := &offsetTable{
sfntVersion: f.ot.sfntVersion,
Expand All @@ -206,7 +206,7 @@ func (f *font) write(w *byteWriter) error {

fmt.Printf("==== write\nnumTables: %d\nstartOffset: %d\n", numTables, startOffset)

common.Log.Debug("Write 2")
logrus.Debug("Write 2")
// Writing is two phases and is done in a few steps:
// 1. Write the content tables: head, hhea, etc in the expected order and keep track of the length, checksum for each.
// 2. Generate the table records based on the information.
Expand Down Expand Up @@ -358,7 +358,7 @@ func (f *font) write(w *byteWriter) error {
}
}
}
common.Log.Debug("Write 3")
logrus.Debug("Write 3")

// Write the offset and table records to another mock buffer.
var bufh bytes.Buffer
Expand Down
8 changes: 2 additions & 6 deletions font_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package unitype
import (
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"

"github.com/unidoc/unipdf/v3/common"
)

func TestReadWrite(t *testing.T) {
//common.SetLogger(common.NewConsoleLogger(common.LogLevelDebug))

testcases := []struct {
fontPath string
}{
Expand All @@ -32,8 +29,7 @@ func TestReadWrite(t *testing.T) {
fnt, err := ParseFile(tcase.fontPath)
require.NoError(t, err)

common.Log.Debug("Write")

logrus.Debug("Write")
outPath := "/tmp/1.ttf"

t.Logf("WriteFile -> %s", outPath)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/gunnsth/unitype

require (
github.com/davecgh/go-spew v1.1.1
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/sirupsen/logrus v1.5.0
github.com/spf13/cobra v0.0.6
github.com/stretchr/testify v1.4.0
github.com/unidoc/unipdf/v3 v3.4.0
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
golang.org/x/text v0.3.2
)

Expand Down
30 changes: 13 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down Expand Up @@ -40,18 +39,22 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/gunnsth/pkcs7 v0.0.0-20181213175627-3cffc6fbfe83 h1:saj5dTV7eQ1wFg/gVZr1SfbkOmg8CYO9R8frHgQiyR4=
github.com/gunnsth/pkcs7 v0.0.0-20181213175627-3cffc6fbfe83/go.mod h1:xaGEIRenAiJcGgd9p62zbiP4993KaV3PdjczwGnP50I=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand All @@ -75,7 +78,10 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand All @@ -89,13 +95,10 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/unidoc/unipdf/v3 v3.4.0 h1:CO9cb3XV79QyvBTEdrRHbOVjZc6c5xCX/EJP4B109xw=
github.com/unidoc/unipdf/v3 v3.4.0/go.mod h1:deHLROTLv9UDHIcWQFbjcrEZ4aTwyhPXX0fvpyoZyAM=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand All @@ -104,32 +107,25 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190606173856-1492cefac77f/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -138,14 +134,14 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190606174628-0139d5756a7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
Expand Down
8 changes: 4 additions & 4 deletions internal/strutils/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"bytes"
"unicode/utf16"

"github.com/unidoc/unipdf/v3/common"
"github.com/sirupsen/logrus"
)

var pdfdocEncodingRuneMap map[rune]byte
Expand All @@ -29,7 +29,7 @@ func UTF16ToRunes(b []byte) []rune {
}
if len(b)%2 != 0 {
b = append(b, 0)
common.Log.Debug("ERROR: UTF16ToRunes. Padding with zeros.")
logrus.Debug("ERROR: UTF16ToRunes. Padding with zeros.")
}
n := len(b) >> 1
chars := make([]uint16, n)
Expand Down Expand Up @@ -64,7 +64,7 @@ func PDFDocEncodingToRunes(b []byte) []rune {
for _, bval := range b {
rune, has := pdfDocEncoding[bval]
if !has {
common.Log.Debug("Error: PDFDocEncoding input mapping error %d - skipping", bval)
logrus.Debugf("Error: PDFDocEncoding input mapping error %d - skipping", bval)
continue
}

Expand All @@ -85,7 +85,7 @@ func StringToPDFDocEncoding(s string) []byte {
for _, r := range s {
b, has := pdfdocEncodingRuneMap[r]
if !has {
common.Log.Debug("ERROR: PDFDocEncoding rune mapping missing %c/%X - skipping", r, r)
logrus.Debugf("ERROR: PDFDocEncoding rune mapping missing %c/%X - skipping", r, r)
continue
}
buf.WriteByte(b)
Expand Down
20 changes: 10 additions & 10 deletions table_cmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"
"fmt"

"github.com/unidoc/unipdf/v3/common"
"github.com/sirupsen/logrus"
)

// cmapTable represents a Character to Glyph Index Mapping Table (cmap).
Expand All @@ -37,7 +37,7 @@ type encodingRecord struct {

func (f *font) parseCmap(r *byteReader) (*cmapTable, error) {
if f.maxp == nil {
common.Log.Debug("Unable to load cmap: maxp table is nil")
logrus.Debug("Unable to load cmap: maxp table is nil")
return nil, errRequiredField
}

Expand All @@ -46,7 +46,7 @@ func (f *font) parseCmap(r *byteReader) (*cmapTable, error) {
return nil, err
}
if !has {
common.Log.Debug("cmap table absent")
logrus.Debug("cmap table absent")
return nil, nil
}

Expand Down Expand Up @@ -93,11 +93,11 @@ func (f *font) parseCmap(r *byteReader) (*cmapTable, error) {
case 12:
cmap, err = f.parseCmapSubtableFormat12(r, int(enc.platformID), int(enc.encodingID))
default:
common.Log.Debug("Unsupported cmap format %d", format)
logrus.Debugf("Unsupported cmap format %d", format)
continue
}
if err != nil {
common.Log.Debug("Error: %v", err)
logrus.Debugf("Error: %v", err)
return nil, err
}
if cmap != nil {
Expand Down Expand Up @@ -322,7 +322,7 @@ func (f *font) parseCmapSubtableFormat4(r *byteReader, platformID, encodingID in
b := runeDecoder.ToBytes(uint32(c))
r := runeDecoder.DecodeRune(b)
if int(gid) >= int(f.maxp.numGlyphs) {
common.Log.Debug("ERROR: gid > numGlyphs (%d > %d)", gid, f.maxp.numGlyphs)
logrus.Debugf("ERROR: gid > numGlyphs (%d > %d)", gid, f.maxp.numGlyphs)
return nil, errors.New("gid out of range")
}
runes[int(gid)] = r
Expand Down Expand Up @@ -469,15 +469,15 @@ func (f *font) parseCmapSubtableFormat12(r *byteReader, platformID, encodingID i
st := cmapSubtableFormat12{}
err := r.read(&st.reserved, &st.length, &st.language, &st.numGroups)
if err != nil {
common.Log.Debug("Error: %v", err)
logrus.Debugf("Error: %v", err)
return nil, err
}

for i := 0; i < int(st.numGroups); i++ {
var group sequentialMapGroup
err = r.read(&group.startCharCode, &group.endCharCode, &group.startGlyphID)
if err != nil {
common.Log.Debug("Error: %v", err)
logrus.Debugf("Error: %v", err)
return nil, err
}
st.groups = append(st.groups, group)
Expand All @@ -492,8 +492,8 @@ func (f *font) parseCmapSubtableFormat12(r *byteReader, platformID, encodingID i
//fmt.Printf("XXX Parse, startCharcode: %d, endCharCode: %d, startGlyphID: %d\n", group.startCharCode, group.endCharCode, group.startGlyphID)
gid := GlyphIndex(group.startGlyphID)
if int(gid) >= int(f.maxp.numGlyphs) {
common.Log.Debug("gid >= numGlyphs (%d > %d)", gid, f.maxp.numGlyphs)
common.Log.Debug("Error: %v", errRangeCheck)
logrus.Debugf("gid >= numGlyphs (%d > %d)", gid, f.maxp.numGlyphs)
logrus.Debugf("Error: %v", errRangeCheck)
return nil, errRangeCheck
}
for charcode := group.startCharCode; charcode <= group.endCharCode; charcode++ {
Expand Down
Loading

0 comments on commit 11c8f66

Please sign in to comment.