mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
quietened logging
This commit is contained in:
parent
1e5bc37826
commit
cf88afe2d3
@ -205,6 +205,7 @@ func (this *PdfParser) lookupByNumberWrapper(objNumber int, attemptRepairs bool)
|
|||||||
return obj, inObjStream, nil
|
return obj, inObjStream, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getObjectNumber returns object number, generation number, error for `obj`
|
||||||
func getObjectNumber(obj PdfObject) (int64, int64, error) {
|
func getObjectNumber(obj PdfObject) (int64, int64, error) {
|
||||||
if io, isIndirect := obj.(*PdfIndirectObject); isIndirect {
|
if io, isIndirect := obj.(*PdfIndirectObject); isIndirect {
|
||||||
return io.ObjectNumber, io.GenerationNumber, nil
|
return io.ObjectNumber, io.GenerationNumber, nil
|
||||||
|
@ -233,7 +233,7 @@ func NewPdfPage() *PdfPage {
|
|||||||
func (reader *PdfReader) newPdfPageFromDict(p *PdfObjectDictionary) (*PdfPage, error) {
|
func (reader *PdfReader) newPdfPageFromDict(p *PdfObjectDictionary) (*PdfPage, error) {
|
||||||
page := NewPdfPage()
|
page := NewPdfPage()
|
||||||
|
|
||||||
fmt.Printf("newPdfPageFromDict %+v\n", p)
|
// fmt.Printf("newPdfPageFromDict %+v\n", p)
|
||||||
|
|
||||||
d := *p
|
d := *p
|
||||||
|
|
||||||
@ -614,7 +614,7 @@ func (this *PdfPage) AddWatermarkImage(ximg *XObjectImage, opt WatermarkImageOpt
|
|||||||
pWidth := bbox.Urx - bbox.Llx
|
pWidth := bbox.Urx - bbox.Llx
|
||||||
pHeight := bbox.Ury - bbox.Lly
|
pHeight := bbox.Ury - bbox.Lly
|
||||||
|
|
||||||
fmt.Printf("AddWatermarkImage: bbox=%+v opt=%+v\n", bbox, opt)
|
// fmt.Printf("AddWatermarkImage: bbox=%+v opt=%+v\n", bbox, opt)
|
||||||
var wWidth float64
|
var wWidth float64
|
||||||
var wHeight float64
|
var wHeight float64
|
||||||
var xOffset float64
|
var xOffset float64
|
||||||
@ -661,7 +661,7 @@ func (this *PdfPage) AddWatermarkImage(ximg *XObjectImage, opt WatermarkImageOpt
|
|||||||
"%.0f 0 0 %.0f %.4f %.4f cm\n"+
|
"%.0f 0 0 %.0f %.4f %.4f cm\n"+
|
||||||
"/%s Do\n"+
|
"/%s Do\n"+
|
||||||
"Q", wWidth, wHeight, xOffset, yOffset, imgName)
|
"Q", wWidth, wHeight, xOffset, yOffset, imgName)
|
||||||
fmt.Printf("AddWatermarkImage: contentStr=%q\n", contentStr)
|
// fmt.Printf("AddWatermarkImage: contentStr=%q\n", contentStr)
|
||||||
this.AddContentStreamByString(contentStr)
|
this.AddContentStreamByString(contentStr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -100,11 +100,19 @@ func (this *PdfObjectInteger) DefaultWriteString() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *PdfObjectFloat) String() string {
|
func (this *PdfObjectFloat) String() string {
|
||||||
return fmt.Sprintf("%f", *this)
|
return fmt.Sprintf("%f", pinNumber(*this))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PdfObjectFloat) DefaultWriteString() string {
|
func (this *PdfObjectFloat) DefaultWriteString() string {
|
||||||
return fmt.Sprintf("%f", *this)
|
return fmt.Sprintf("%f", pinNumber(*this))
|
||||||
|
}
|
||||||
|
|
||||||
|
func pinNumber(x float64) float64 {
|
||||||
|
// n := math.Floor(x + 0.5)
|
||||||
|
// if math.Abs(x) > 1.0 && math.Abs(x-n) < 1e-5 {
|
||||||
|
// x = n
|
||||||
|
// }
|
||||||
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PdfObjectString) String() string {
|
func (this *PdfObjectString) String() string {
|
||||||
@ -220,7 +228,7 @@ func (this *PdfObjectArray) DefaultWriteString() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// byName sorts slices of PdfObjectName. It is needed because sort.Strings(keys) gives a typecheck
|
// byName sorts slices of PdfObjectName. It is needed because sort.Strings(keys) gives a typecheck
|
||||||
// error which I find strange because a PdfObjectName is a string.
|
// error, which I find strange because a PdfObjectName is a string.
|
||||||
type byName []PdfObjectName
|
type byName []PdfObjectName
|
||||||
|
|
||||||
func (x byName) Len() int { return len(x) }
|
func (x byName) Len() int { return len(x) }
|
||||||
|
@ -21,16 +21,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Regular Expressions for parsing and identifying object signatures.
|
// Regular Expressions for parsing and identifying object signatures.
|
||||||
var rePdfVersion = regexp.MustCompile(`%PDF-(\d\.\d)`)
|
var (
|
||||||
var reEOF = regexp.MustCompile("%%EOF")
|
rePdfVersion = regexp.MustCompile(`%PDF-(\d\.\d)`)
|
||||||
var reXrefTable = regexp.MustCompile(`\s*xref\s*`)
|
reEOF = regexp.MustCompile("%%EOF")
|
||||||
var reStartXref = regexp.MustCompile(`startx?ref\s*(\d+)`)
|
reXrefTable = regexp.MustCompile(`\s*xref\s*`)
|
||||||
var reNumeric = regexp.MustCompile(`^[\+-.]*([0-9.]+)`)
|
reStartXref = regexp.MustCompile(`startx?ref\s*(\d+)`)
|
||||||
var reExponential = regexp.MustCompile(`^[\+-.]*([0-9.]+)e[\+-.]*([0-9.]+)`)
|
reNumeric = regexp.MustCompile(`^[\+-.]*([0-9.]+)`)
|
||||||
var reReference = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+R`)
|
reExponential = regexp.MustCompile(`^[\+-.]*([0-9.]+)e[\+-.]*([0-9.]+)`)
|
||||||
var reIndirectObject = regexp.MustCompile(`(\d+)\s+(\d+)\s+obj`)
|
reReference = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+R`)
|
||||||
var reXrefSubsection = regexp.MustCompile(`(\d+)\s+(\d+)\s*$`)
|
reIndirectObject = regexp.MustCompile(`(\d+)\s+(\d+)\s+obj`)
|
||||||
var reXrefEntry = regexp.MustCompile(`(\d+)\s+(\d+)\s+([nf])\s*$`)
|
reXrefSubsection = regexp.MustCompile(`(\d+)\s+(\d+)\s*$`)
|
||||||
|
reXrefEntry = regexp.MustCompile(`(\d+)\s+(\d+)\s+([nf])\s*$`)
|
||||||
|
)
|
||||||
|
|
||||||
type PdfParser struct {
|
type PdfParser struct {
|
||||||
rs io.ReadSeeker
|
rs io.ReadSeeker
|
||||||
@ -44,30 +46,18 @@ type PdfParser struct {
|
|||||||
repairsAttempted bool // Avoid multiple attempts for repair.
|
repairsAttempted bool // Avoid multiple attempts for repair.
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWhiteSpace(ch byte) bool {
|
func isWhiteSpace(c byte) bool {
|
||||||
// Table 1 white-space characters (7.2.2 Character Set)
|
// Table 1 white-space characters (7.2.2 Character Set)
|
||||||
// spaceCharacters := string([]byte{0x00, 0x09, 0x0A, 0x0C, 0x0D, 0x20})
|
// spaceCharacters := string([]byte{0x00, 0x09, 0x0A, 0x0C, 0x0D, 0x20})
|
||||||
if (ch == 0x00) || (ch == 0x09) || (ch == 0x0A) || (ch == 0x0C) || (ch == 0x0D) || (ch == 0x20) {
|
return (c == 0x00) || (c == 0x09) || (c == 0x0A) || (c == 0x0C) || (c == 0x0D) || (c == 0x20)
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isDecimalDigit(c byte) bool {
|
func isDecimalDigit(c byte) bool {
|
||||||
if c >= '0' && c <= '9' {
|
return '0' <= c && c <= '9'
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOctalDigit(c byte) bool {
|
func isOctalDigit(c byte) bool {
|
||||||
if c >= '0' && c <= '7' {
|
return '0' <= c && c <= '7'
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip over any spaces.
|
// Skip over any spaces.
|
||||||
@ -836,6 +826,8 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
|
|||||||
common.Log.Debug("ERROR: Unable to decode stream")
|
common.Log.Debug("ERROR: Unable to decode stream")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
fmt.Printf("@@ ds=%d %T %+v\n", len(ds), ds, ds)
|
||||||
|
// panic(fmt.Errorf("WWWWWWWW"))
|
||||||
|
|
||||||
s0 := int(b[0])
|
s0 := int(b[0])
|
||||||
s1 := int(b[0] + b[1])
|
s1 := int(b[0] + b[1])
|
||||||
@ -1040,7 +1032,7 @@ func (this *PdfParser) loadXrefs() (*PdfObjectDictionary, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
common.Log.Debug("fsize: %d", fSize)
|
common.Log.Debug("loadXrefs: fsize: %d", fSize)
|
||||||
if fSize <= offset {
|
if fSize <= offset {
|
||||||
offset = fSize
|
offset = fSize
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user