Merge branch 'v3' of https://github.com/unidoc/unidoc into text.fixes

This commit is contained in:
Peter Williams 2019-01-03 15:16:38 +11:00
commit a493fce496
5 changed files with 18 additions and 14 deletions

3
Jenkinsfile vendored
View File

@ -38,7 +38,6 @@ node {
sh '(golint ./... >golint.txt 2>&1) || true'
}
stage('Testing') {
// Go test - No tolerance.
sh "rm -f ${env.TMPDIR}/*.pdf"
@ -52,11 +51,11 @@ node {
stage('Test coverage') {
sh 'go test -coverprofile=coverage.out ./...'
sh '/home/jenkins/codecov.sh'
sh 'gocover-cobertura < coverage.out > coverage.xml'
step([$class: 'CoberturaPublisher', coberturaReportFile: 'coverage.xml'])
}
stage('Post') {
// Assemble vet and lint info.
warnings parserConfigurations: [

View File

@ -6,6 +6,7 @@
package model
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
@ -468,7 +469,12 @@ func newPdfCIDFontType2FromPdfObject(d *core.PdfObjectDictionary, base *fontComm
// TODO: May be extended in the future to support a larger variety of CMaps and vertical fonts.
func NewCompositePdfFontFromTTFFile(filePath string) (*PdfFont, error) {
// Load the truetype font data.
ttf, err := fonts.TtfParse(filePath)
ttfBytes, err := ioutil.ReadFile(filePath)
if err != nil {
common.Log.Debug("ERROR: while reading ttf font: %v", err)
return nil, err
}
ttf, err := fonts.TtfParse(bytes.NewReader(ttfBytes))
if err != nil {
common.Log.Debug("ERROR: while loading ttf font: %v", err)
return nil, err
@ -543,12 +549,6 @@ func NewCompositePdfFontFromTTFFile(filePath string) (*PdfFont, error) {
}
// Embed the TrueType font program.
ttfBytes, err := ioutil.ReadFile(filePath)
if err != nil {
common.Log.Debug("ERROR: Unable to read file contents: %v", err)
return nil, err
}
stream, err := core.MakeStream(ttfBytes, core.NewFlateEncoder())
if err != nil {
common.Log.Debug("ERROR: Unable to make stream: %v", err)

View File

@ -395,7 +395,7 @@ func NewPdfFontFromTTFFile(filePath string) (*PdfFont, error) {
const minCode = textencoding.CharCode(32)
const maxCode = textencoding.CharCode(255)
ttf, err := fonts.TtfParse(filePath)
ttf, err := fonts.TtfParseFile(filePath)
if err != nil {
common.Log.Debug("ERROR: loading ttf font: %v", err)
return nil, err

View File

@ -170,15 +170,20 @@ func NewFontFile2FromPdfObject(obj core.PdfObject) (TtfType, error) {
return t.Parse()
}
// TtfParse returns a TtfType describing the TrueType font file in disk file `fileStr`.
func TtfParse(fileStr string) (TtfType, error) {
// TtfParseFile returns a TtfType describing the TrueType font file in disk file `fileStr`.
func TtfParseFile(fileStr string) (TtfType, error) {
f, err := os.Open(fileStr)
if err != nil {
return TtfType{}, err
}
defer f.Close()
t := ttfParser{f: f}
return TtfParse(f)
}
// TtfParse returns a TtfType describing the TrueType font.
func TtfParse(r io.ReadSeeker) (TtfType, error) {
t := &ttfParser{f: r}
return t.Parse()
}

View File

@ -80,7 +80,7 @@ func TestTTFParse(t *testing.T) {
t.Run(c.path, func(t *testing.T) {
path := filepath.Join(fontDir, c.path)
ft, err := TtfParse(path)
ft, err := TtfParseFile(path)
if err != nil {
t.Fatal(err)
}