mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
Merge pull request #239 from dennwc/font_minor
Minor fixes to font packages
This commit is contained in:
commit
919b83bbcd
@ -16,6 +16,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
@ -46,6 +47,10 @@ const testWts11TTFFile = "./testdata/wts11.ttf"
|
||||
// This problem did not occur when I replaced FreeSans.ttf with LiberationSans-Regular.ttf
|
||||
const testFreeSansTTFFile = "./testdata/FreeSans.ttf"
|
||||
|
||||
func tempFile(name string) string {
|
||||
return filepath.Join(os.TempDir(), name)
|
||||
}
|
||||
|
||||
func TestTemplate1(t *testing.T) {
|
||||
creator := New()
|
||||
|
||||
@ -77,7 +82,7 @@ func TestTemplate1(t *testing.T) {
|
||||
template.SetPos(100, 200)
|
||||
creator.Draw(template)
|
||||
|
||||
creator.WriteToFile("/tmp/template_1.pdf")
|
||||
creator.WriteToFile(tempFile("template_1.pdf"))
|
||||
|
||||
return
|
||||
}
|
||||
@ -107,7 +112,7 @@ func TestImage1(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/1.pdf")
|
||||
err = creator.WriteToFile(tempFile("1.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -146,7 +151,7 @@ func TestImageWithEncoder(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/1_dct.pdf")
|
||||
err = creator.WriteToFile(tempFile("1_dct.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -232,7 +237,7 @@ func TestShapes1(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/1_shapes.pdf")
|
||||
err = creator.WriteToFile(tempFile("1_shapes.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -281,7 +286,7 @@ func TestShapesOnBlock(t *testing.T) {
|
||||
block.SetAngle(90)
|
||||
creator.Draw(block)
|
||||
|
||||
err = creator.WriteToFile("/tmp/1_shapes_on_block.pdf")
|
||||
err = creator.WriteToFile(tempFile("1_shapes_on_block.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -314,7 +319,7 @@ func TestImageWrapping(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/1_wrap.pdf")
|
||||
err = creator.WriteToFile(tempFile("1_wrap.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -354,7 +359,7 @@ func TestImageRotation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/1_rotate.pdf")
|
||||
err = creator.WriteToFile(tempFile("1_rotate.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -396,7 +401,7 @@ func TestImageRotationAndWrap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/rotate_2.pdf")
|
||||
err = creator.WriteToFile(tempFile("rotate_2.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -419,7 +424,7 @@ func TestParagraph1(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/2_p1.pdf")
|
||||
err = creator.WriteToFile(tempFile("2_p1.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -455,7 +460,7 @@ func TestParagraphWrapping(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err := creator.WriteToFile("/tmp/2_pwrap.pdf")
|
||||
err := creator.WriteToFile(tempFile("2_pwrap.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -485,7 +490,7 @@ func TestParagraphWrapping2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err := creator.WriteToFile("/tmp/2_pwrap2.pdf")
|
||||
err := creator.WriteToFile(tempFile("2_pwrap2.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -531,7 +536,7 @@ func TestParagraphFonts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/2_pArial.pdf")
|
||||
err = creator.WriteToFile(tempFile("2_pArial.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -601,7 +606,7 @@ func TestParagraphStandardFonts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err := creator.WriteToFile("/tmp/2_standard14fonts.pdf")
|
||||
err := creator.WriteToFile(tempFile("2_standard14fonts.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -618,15 +623,15 @@ func TestParagraphChinese(t *testing.T) {
|
||||
"河上白云",
|
||||
}
|
||||
|
||||
font, err := model.NewCompositePdfFontFromTTFFile(testWts11TTFFile)
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, line := range lines {
|
||||
p := creator.NewParagraph(line)
|
||||
|
||||
font, err := model.NewCompositePdfFontFromTTFFile(testWts11TTFFile)
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
p.SetFont(font)
|
||||
|
||||
err = creator.Draw(p)
|
||||
@ -636,11 +641,19 @@ func TestParagraphChinese(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err := creator.WriteToFile("/tmp/2_p_nihao.pdf")
|
||||
fname := tempFile("2_p_nihao.pdf")
|
||||
err = creator.WriteToFile(fname)
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
st, err := os.Stat(fname)
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
t.Logf("output size: %d (%d MB)", st.Size(), st.Size()/1024/1024)
|
||||
}
|
||||
|
||||
// Test paragraph with composite font and various unicode characters.
|
||||
@ -695,7 +708,7 @@ func TestParagraphUnicode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = creator.WriteToFile("/tmp/2_p_multi.pdf")
|
||||
err = creator.WriteToFile(tempFile("2_p_multi.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -721,7 +734,7 @@ func TestChapter(t *testing.T) {
|
||||
|
||||
c.Draw(ch1)
|
||||
|
||||
err := c.WriteToFile("/tmp/3_chapters.pdf")
|
||||
err := c.WriteToFile(tempFile("3_chapters.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -748,7 +761,7 @@ func TestChapterMargins(t *testing.T) {
|
||||
c.Draw(ch)
|
||||
}
|
||||
|
||||
err := c.WriteToFile("/tmp/3_chapters_margins.pdf")
|
||||
err := c.WriteToFile(tempFile("3_chapters_margins.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -857,7 +870,7 @@ func TestSubchaptersSimple(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
err := c.WriteToFile("/tmp/3_subchapters_simple.pdf")
|
||||
err := c.WriteToFile(tempFile("3_subchapters_simple.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -967,7 +980,7 @@ func TestSubchapters(t *testing.T) {
|
||||
|
||||
addHeadersAndFooters(c)
|
||||
|
||||
err := c.WriteToFile("/tmp/3_subchapters.pdf")
|
||||
err := c.WriteToFile(tempFile("3_subchapters.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1027,7 +1040,7 @@ func TestTable(t *testing.T) {
|
||||
|
||||
c.Draw(table)
|
||||
|
||||
err := c.WriteToFile("/tmp/4_table.pdf")
|
||||
err := c.WriteToFile(tempFile("4_table.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1118,7 +1131,7 @@ func TestTableCellWrapping(t *testing.T) {
|
||||
t.Fatalf("Error drawing: %v", err)
|
||||
}
|
||||
|
||||
err = c.WriteToFile("/tmp/tablecell_wrap.pdf")
|
||||
err = c.WriteToFile(tempFile("tablecell_wrap.pdf"))
|
||||
if err != nil {
|
||||
t.Fatalf("Fail: %v\n", err)
|
||||
}
|
||||
@ -1159,7 +1172,7 @@ func TestBorderedTable1(t *testing.T) {
|
||||
|
||||
c.Draw(table)
|
||||
|
||||
err := c.WriteToFile("/tmp/4_table_bordered.pdf")
|
||||
err := c.WriteToFile(tempFile("4_table_bordered.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1220,7 +1233,7 @@ func TestBorderedTable2(t *testing.T) {
|
||||
|
||||
c.Draw(table)
|
||||
|
||||
err := c.WriteToFile("/tmp/4_table_bordered.pdf")
|
||||
err := c.WriteToFile(tempFile("4_table_bordered.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1451,7 +1464,7 @@ func TestCreatorHendricksReq1(t *testing.T) {
|
||||
c.Draw(table2)
|
||||
c.Draw(table3)
|
||||
|
||||
err := c.WriteToFile("/tmp/hendricks.pdf")
|
||||
err := c.WriteToFile(tempFile("hendricks.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1782,7 +1795,7 @@ func TestCreatorTableBorderReq1(t *testing.T) {
|
||||
c.Draw(table9)
|
||||
c.Draw(table10)
|
||||
|
||||
err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile(tempFile("table_border_req1_test.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1803,7 +1816,7 @@ func TestCellBorder(t *testing.T) {
|
||||
|
||||
c.Draw(table)
|
||||
|
||||
err := c.WriteToFile("/tmp/cell.pdf")
|
||||
err := c.WriteToFile(tempFile("cell.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1902,7 +1915,7 @@ func TestTableInSubchapter(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.WriteToFile("/tmp/4_tables_in_subchap.pdf")
|
||||
err = c.WriteToFile(tempFile("4_tables_in_subchap.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1977,7 +1990,7 @@ func TestHeadersAndFooters(t *testing.T) {
|
||||
// Make unidoc headers and footers.
|
||||
addHeadersAndFooters(c)
|
||||
|
||||
err := c.WriteToFile("/tmp/4_headers.pdf")
|
||||
err := c.WriteToFile(tempFile("4_headers.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2022,7 +2035,7 @@ func TestQRCodeOnNewPage(t *testing.T) {
|
||||
creator.Draw(img)
|
||||
}
|
||||
|
||||
creator.WriteToFile("/tmp/3_barcode_qr_newpage.pdf")
|
||||
creator.WriteToFile(tempFile("3_barcode_qr_newpage.pdf"))
|
||||
}
|
||||
|
||||
// Example of using a template Page, generating and applying QR
|
||||
@ -2100,7 +2113,7 @@ func TestQRCodeOnTemplate(t *testing.T) {
|
||||
creator.Draw(loremTpl)
|
||||
|
||||
// Write the example to file.
|
||||
creator.WriteToFile("/tmp/4_barcode_on_tpl.pdf")
|
||||
creator.WriteToFile(tempFile("4_barcode_on_tpl.pdf"))
|
||||
}
|
||||
|
||||
// Test adding encryption to output.
|
||||
@ -2129,7 +2142,7 @@ func TestEncrypting1(t *testing.T) {
|
||||
return err
|
||||
})
|
||||
|
||||
err := c.WriteToFile("/tmp/6_chapters_encrypted_password.pdf")
|
||||
err := c.WriteToFile(tempFile("6_chapters_encrypted_password.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2173,7 +2186,7 @@ func TestEncrypting1(t *testing.T) {
|
||||
func TestOptimizeCombineDuplicateStreams(t *testing.T) {
|
||||
c := createPdf4Optimization(t)
|
||||
|
||||
err := c.WriteToFile("/tmp/7_combine_duplicate_streams_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("7_combine_duplicate_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2183,18 +2196,18 @@ func TestOptimizeCombineDuplicateStreams(t *testing.T) {
|
||||
|
||||
c.SetOptimizer(optimize.New(optimize.Options{CombineDuplicateStreams: true}))
|
||||
|
||||
err = c.WriteToFile("/tmp/7_combine_duplicate_streams_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("7_combine_duplicate_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/7_combine_duplicate_streams_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("7_combine_duplicate_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/7_combine_duplicate_streams_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("7_combine_duplicate_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2236,7 +2249,7 @@ func TestOptimizeImageQuality(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.WriteToFile("/tmp/8_image_quality_not_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("8_image_quality_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2244,18 +2257,18 @@ func TestOptimizeImageQuality(t *testing.T) {
|
||||
|
||||
c.SetOptimizer(optimize.New(optimize.Options{ImageQuality: 20}))
|
||||
|
||||
err = c.WriteToFile("/tmp/8_image_quality_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("8_image_quality_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/8_image_quality_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("8_image_quality_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/8_image_quality_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("8_image_quality_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2365,7 +2378,7 @@ func createPdf4Optimization(t *testing.T) *Creator {
|
||||
func TestOptimizeUseObjectStreams(t *testing.T) {
|
||||
c := createPdf4Optimization(t)
|
||||
|
||||
err := c.WriteToFile("/tmp/9_use_object_streams_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("9_use_object_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2374,18 +2387,18 @@ func TestOptimizeUseObjectStreams(t *testing.T) {
|
||||
c = createPdf4Optimization(t)
|
||||
c.SetOptimizer(optimize.New(optimize.Options{UseObjectStreams: true}))
|
||||
|
||||
err = c.WriteToFile("/tmp/9_use_object_streams_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("9_use_object_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/9_use_object_streams_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("9_use_object_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/9_use_object_streams_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("9_use_object_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2484,7 +2497,7 @@ func TestCombineDuplicateDirectObjects(t *testing.T) {
|
||||
|
||||
c := createDoc()
|
||||
|
||||
err := c.WriteToFile("/tmp/10_combine_duplicate_direct_objects_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("10_combine_duplicate_direct_objects_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2493,18 +2506,18 @@ func TestCombineDuplicateDirectObjects(t *testing.T) {
|
||||
c = createDoc()
|
||||
c.SetOptimizer(optimize.New(optimize.Options{CombineDuplicateDirectObjects: true}))
|
||||
|
||||
err = c.WriteToFile("/tmp/10_combine_duplicate_direct_objects_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("10_combine_duplicate_direct_objects_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/10_combine_duplicate_direct_objects_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("10_combine_duplicate_direct_objects_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/10_combine_duplicate_direct_objects_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("10_combine_duplicate_direct_objects_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2575,7 +2588,7 @@ func TestOptimizeImagePPI(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.WriteToFile("/tmp/11_image_ppi_not_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("11_image_ppi_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2583,18 +2596,18 @@ func TestOptimizeImagePPI(t *testing.T) {
|
||||
|
||||
c.SetOptimizer(optimize.New(optimize.Options{ImageUpperPPI: 144}))
|
||||
|
||||
err = c.WriteToFile("/tmp/11_image_ppi_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("11_image_ppi_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/11_image_ppi_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("11_image_ppi_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/11_image_ppi_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("11_image_ppi_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2684,7 +2697,7 @@ func TestCombineIdenticalIndirectObjects(t *testing.T) {
|
||||
|
||||
addHeadersAndFooters(c)
|
||||
|
||||
err := c.WriteToFile("/tmp/12_identical_indirect_objects_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("12_identical_indirect_objects_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2692,18 +2705,18 @@ func TestCombineIdenticalIndirectObjects(t *testing.T) {
|
||||
|
||||
c.SetOptimizer(optimize.New(optimize.Options{CombineIdenticalIndirectObjects: true}))
|
||||
|
||||
err = c.WriteToFile("/tmp/12_identical_indirect_objects_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("12_identical_indirect_objects_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/12_identical_indirect_objects_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("12_identical_indirect_objects_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/12_identical_indirect_objects_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("12_identical_indirect_objects_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2753,7 +2766,7 @@ ET`)
|
||||
|
||||
c := createDoc()
|
||||
|
||||
err := c.WriteToFile("/tmp/13_compress_streams_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("13_compress_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2762,18 +2775,18 @@ ET`)
|
||||
c = createDoc()
|
||||
c.SetOptimizer(optimize.New(optimize.Options{CompressStreams: true}))
|
||||
|
||||
err = c.WriteToFile("/tmp/13_compress_streams_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("13_compress_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/13_compress_streams_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("13_compress_streams_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/13_compress_streams_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("13_compress_streams_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2870,7 +2883,7 @@ func TestAllOptimizations(t *testing.T) {
|
||||
|
||||
c := createDoc()
|
||||
|
||||
err := c.WriteToFile("/tmp/14_not_optimized.pdf")
|
||||
err := c.WriteToFile(tempFile("14_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -2887,18 +2900,18 @@ func TestAllOptimizations(t *testing.T) {
|
||||
CompressStreams: true,
|
||||
}))
|
||||
|
||||
err = c.WriteToFile("/tmp/14_optimized.pdf")
|
||||
err = c.WriteToFile(tempFile("14_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat("/tmp/14_not_optimized.pdf")
|
||||
fileInfo, err := os.Stat(tempFile("14_not_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
}
|
||||
fileInfoOptimized, err := os.Stat("/tmp/14_optimized.pdf")
|
||||
fileInfoOptimized, err := os.Stat(tempFile("14_optimized.pdf"))
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
|
@ -409,7 +409,7 @@ func NewCompositePdfFontFromTTFFile(filePath string) (*PdfFont, error) {
|
||||
|
||||
// 2-byte character codes ➞ runes
|
||||
runes := make([]uint16, 0, len(ttf.Chars))
|
||||
for _, r := range ttf.Chars {
|
||||
for r := range ttf.Chars {
|
||||
runes = append(runes, r)
|
||||
}
|
||||
|
||||
@ -472,15 +472,20 @@ func NewCompositePdfFontFromTTFFile(filePath string) (*PdfFont, error) {
|
||||
cidfont.CIDSystemInfo = d
|
||||
|
||||
// Make the font descriptor.
|
||||
descriptor := &PdfFontDescriptor{}
|
||||
descriptor.FontName = core.MakeName(ttf.PostScriptName)
|
||||
descriptor.Ascent = core.MakeFloat(k * float64(ttf.TypoAscender))
|
||||
descriptor.Descent = core.MakeFloat(k * float64(ttf.TypoDescender))
|
||||
descriptor.CapHeight = core.MakeFloat(k * float64(ttf.CapHeight))
|
||||
descriptor.FontBBox = core.MakeArrayFromFloats([]float64{k * float64(ttf.Xmin),
|
||||
k * float64(ttf.Ymin), k * float64(ttf.Xmax), k * float64(ttf.Ymax)})
|
||||
descriptor.ItalicAngle = core.MakeFloat(float64(ttf.ItalicAngle))
|
||||
descriptor.MissingWidth = core.MakeFloat(k * float64(ttf.Widths[0]))
|
||||
descriptor := &PdfFontDescriptor{
|
||||
FontName: core.MakeName(ttf.PostScriptName),
|
||||
Ascent: core.MakeFloat(k * float64(ttf.TypoAscender)),
|
||||
Descent: core.MakeFloat(k * float64(ttf.TypoDescender)),
|
||||
CapHeight: core.MakeFloat(k * float64(ttf.CapHeight)),
|
||||
FontBBox: core.MakeArrayFromFloats([]float64{
|
||||
k * float64(ttf.Xmin),
|
||||
k * float64(ttf.Ymin),
|
||||
k * float64(ttf.Xmax),
|
||||
k * float64(ttf.Ymax),
|
||||
}),
|
||||
ItalicAngle: core.MakeFloat(float64(ttf.ItalicAngle)),
|
||||
MissingWidth: core.MakeFloat(k * float64(ttf.Widths[0])),
|
||||
}
|
||||
|
||||
// Embed the TrueType font program.
|
||||
ttfBytes, err := ioutil.ReadFile(filePath)
|
||||
|
@ -262,7 +262,7 @@ func ToFontDifferences(differences map[byte]string) *core.PdfObjectArray {
|
||||
|
||||
// simpleEncodings is a map of the standard 8 bit character encodings.
|
||||
var simpleEncodings = map[string]map[uint16]rune{
|
||||
"MacExpertEncoding": map[uint16]rune{ // 165 entries
|
||||
"MacExpertEncoding": { // 165 entries
|
||||
0x20: 0x0020, // "space"
|
||||
0x21: 0xf721, // "exclamsmall"
|
||||
0x22: 0xf6f8, // "Hungarumlautsmall"
|
||||
@ -429,7 +429,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xfa: 0xf6f7, // "Dotaccentsmall"
|
||||
0xfb: 0xf6fc, // "Ringsmall"
|
||||
},
|
||||
"MacRomanEncoding": map[uint16]rune{ // 255 entries
|
||||
"MacRomanEncoding": { // 255 entries
|
||||
0x01: 0x0001, // "controlSTX"
|
||||
0x02: 0x0002, // "controlSOT"
|
||||
0x03: 0x0003, // "controlETX"
|
||||
@ -686,7 +686,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xfe: 0x02db, // ˛ "ogonek"
|
||||
0xff: 0x02c7, // ˇ "caron"
|
||||
},
|
||||
"PdfDocEncoding": map[uint16]rune{ // 252 entries
|
||||
"PdfDocEncoding": { // 252 entries
|
||||
0x01: 0x0001, // "controlSTX"
|
||||
0x02: 0x0002, // "controlSOT"
|
||||
0x03: 0x0003, // "controlETX"
|
||||
@ -940,7 +940,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xfe: 0x00fe, // þ "thorn"
|
||||
0xff: 0x00ff, // ÿ "ydieresis"
|
||||
},
|
||||
"StandardEncoding": map[uint16]rune{ // 149 entries
|
||||
"StandardEncoding": { // 149 entries
|
||||
0x20: 0x0020, // "space"
|
||||
0x21: 0x0021, // ! "exclam"
|
||||
0x22: 0x0022, // " "quotedbl"
|
||||
@ -1091,7 +1091,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xf9: 0x0153, // œ "oe"
|
||||
0xfa: 0x00df, // ß "germandbls"
|
||||
},
|
||||
"SymbolEncoding": map[uint16]rune{ // 189 entries
|
||||
"SymbolEncoding": { // 189 entries
|
||||
0x20: 0x0020, // "space"
|
||||
0x21: 0x0021, // ! "exclam"
|
||||
0x22: 0x2200, // ∀ "universal"
|
||||
@ -1282,7 +1282,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xfd: 0xf8fd, // "bracerightmid"
|
||||
0xfe: 0xf8fe, // "bracerightbt"
|
||||
},
|
||||
"WinAnsiEncoding": map[uint16]rune{ // 224 entries
|
||||
"WinAnsiEncoding": { // 224 entries
|
||||
0x20: 0x0020, // "space"
|
||||
0x21: 0x0021, // ! "exclam"
|
||||
0x22: 0x0022, // " "quotedbl"
|
||||
@ -1508,7 +1508,7 @@ var simpleEncodings = map[string]map[uint16]rune{
|
||||
0xfe: 0x00fe, // þ "thorn"
|
||||
0xff: 0x00ff, // ÿ "ydieresis"
|
||||
},
|
||||
"ZapfDingbatsEncoding": map[uint16]rune{ // 202 entries
|
||||
"ZapfDingbatsEncoding": { // 202 entries
|
||||
0x20: 0x0020, // "space"
|
||||
0x21: 0x2701, // ✁ "a1"
|
||||
0x22: 0x2702, // ✂ "a2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user