summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdf.go13
-rw-r--r--fpdf_test.go28
-rw-r--r--internal/example/example.go1
-rw-r--r--pdf/reference/Fpdf_AddFont.pdfbin27815 -> 27794 bytes
-rw-r--r--pdf/reference/Fpdf_AddLayer.pdfbin1318 -> 1468 bytes
-rw-r--r--pdf/reference/Fpdf_AddPage.pdfbin4690 -> 6423 bytes
-rw-r--r--pdf/reference/Fpdf_Beziergon.pdfbin1272 -> 2017 bytes
-rw-r--r--pdf/reference/Fpdf_Bookmark.pdfbin1992 -> 1979 bytes
-rw-r--r--pdf/reference/Fpdf_CellFormat_align.pdfbin31946 -> 32553 bytes
-rw-r--r--pdf/reference/Fpdf_CellFormat_codepage.pdfbin315684 -> 315955 bytes
-rw-r--r--pdf/reference/Fpdf_CellFormat_codepageescape.pdfbin1461 -> 1770 bytes
-rw-r--r--pdf/reference/Fpdf_CellFormat_tables.pdfbin5863 -> 20549 bytes
-rw-r--r--pdf/reference/Fpdf_Circle_figures.pdfbin2732 -> 6830 bytes
-rw-r--r--pdf/reference/Fpdf_ClipText.pdfbin9018 -> 11018 bytes
-rw-r--r--pdf/reference/Fpdf_DrawPath_fill.pdfbin2150 -> 6088 bytes
-rw-r--r--pdf/reference/Fpdf_EmbeddedFont.pdfbin27818 -> 27799 bytes
-rw-r--r--pdf/reference/Fpdf_HTMLBasicNew.pdfbin5093 -> 5610 bytes
-rw-r--r--pdf/reference/Fpdf_Image.pdfbin23469 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_LinearGradient_gradient.pdfbin2545 -> 2947 bytes
-rw-r--r--pdf/reference/Fpdf_MoveTo_path.pdfbin855 -> 979 bytes
-rw-r--r--pdf/reference/Fpdf_MultiCell.pdfbin11693 -> 22929 bytes
-rw-r--r--pdf/reference/Fpdf_PageSize.pdfbin1520 -> 1464 bytes
-rw-r--r--pdf/reference/Fpdf_Polygon.pdfbin3229 -> 7060 bytes
-rw-r--r--pdf/reference/Fpdf_RegisterImage.pdfbin27788 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_RegisterImageReader_url.pdfbin10998 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_SVGBasicWrite.pdfbin7375 -> 14200 bytes
-rw-r--r--pdf/reference/Fpdf_SetAcceptPageBreakFunc_landscape.pdfbin139383 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_SetAlpha_transparency.pdfbin130413 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_SetFontLoader.pdfbin27815 -> 27794 bytes
-rw-r--r--pdf/reference/Fpdf_SetKeywords.pdfbin44528 -> 0 bytes
-rw-r--r--pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdfbin14966 -> 37191 bytes
-rw-r--r--pdf/reference/Fpdf_SetLineJoinStyle_caps.pdfbin822 -> 1135 bytes
-rw-r--r--pdf/reference/Fpdf_SetProtection.pdfbin1077 -> 1056 bytes
-rw-r--r--pdf/reference/Fpdf_Splitlines.pdfbin1325 -> 1865 bytes
-rw-r--r--pdf/reference/Fpdf_TransformBegin.pdfbin1835 -> 3483 bytes
-rw-r--r--pdf/reference/Fpdf_WriteAligned.pdfbin967 -> 1064 bytes
-rw-r--r--pdf/reference/basic.pdfbin895 -> 876 bytes
-rw-r--r--pdf/reference/contrib_barcode_Register.pdfbin4954 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterCodabar.pdfbin5249 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterCode128.pdfbin5421 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterCode39.pdfbin5252 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterDataMatrix.pdfbin4592 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterEAN.pdfbin4747 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterQR.pdfbin4411 -> 0 bytes
-rw-r--r--pdf/reference/contrib_barcode_RegisterTwoOfFive.pdfbin5599 -> 0 bytes
-rw-r--r--pdf/reference/contrib_httpimg_Register.pdfbin82994 -> 0 bytes
-rw-r--r--png.go212
-rw-r--r--template.go36
-rw-r--r--ttfparser.go50
49 files changed, 281 insertions, 59 deletions
diff --git a/fpdf.go b/fpdf.go
index c5e8e6b..07005df 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -44,6 +44,7 @@ import (
var gl struct {
catalogSort bool
+ noCompress bool // Initial zero value indicates compression
creationDate time.Time
}
@@ -174,7 +175,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType)
return f.autoPageBreak
}
// Enable compression
- f.SetCompression(true)
+ f.SetCompression(!gl.noCompress)
f.blendList = make([]blendModeType, 0, 8)
f.blendList = append(f.blendList, blendModeType{}) // blendList[0] is unused (1-based)
f.blendMap = make(map[string]int)
@@ -431,15 +432,19 @@ func (f *Fpdf) SetDisplayMode(zoomStr, layoutStr string) {
}
}
+// SetDefaultCompression controls the default setting of the internal
+// compression flag. See SetCompression() for more details. Compression is on
+// by default.
+func SetDefaultCompression(compress bool) {
+ gl.noCompress = !compress
+}
+
// SetCompression activates or deactivates page compression with zlib. When
// activated, the internal representation of each page is compressed, which
// leads to a compression ratio of about 2 for the resulting document.
// Compression is on by default.
func (f *Fpdf) SetCompression(compress bool) {
- // if(function_exists('gzcompress'))
f.compress = compress
- // else
- // $this->compress = false;
}
// SetTitle defines the title of the document. isUTF8 indicates if the string
diff --git a/fpdf_test.go b/fpdf_test.go
index 71fe7ad..f7ef961 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -602,22 +602,18 @@ func ExampleFpdf_SetKeywords() {
err = gofpdf.MakeFont(example.FontFile("CalligrapherRegular.pfb"),
example.FontFile("cp1252.map"), example.FontDir(), nil, true)
if err == nil {
- err = gofpdf.MakeFont(example.FontFile("calligra.ttf"),
- example.FontFile("cp1252.map"), example.FontDir(), nil, true)
- if err == nil {
- pdf := gofpdf.New("", "", "", "")
- pdf.SetFontLocation(example.FontDir())
- pdf.SetTitle("世界", true)
- pdf.SetAuthor("世界", true)
- pdf.SetSubject("世界", true)
- pdf.SetCreator("世界", true)
- pdf.SetKeywords("世界", true)
- pdf.AddFont("Calligrapher", "", "CalligrapherRegular.json")
- pdf.AddPage()
- pdf.SetFont("Calligrapher", "", 16)
- pdf.Writef(5, "\x95 %s \x95", pdf)
- err = pdf.OutputFileAndClose(fileStr)
- }
+ pdf := gofpdf.New("", "", "", "")
+ pdf.SetFontLocation(example.FontDir())
+ pdf.SetTitle("世界", true)
+ pdf.SetAuthor("世界", true)
+ pdf.SetSubject("世界", true)
+ pdf.SetCreator("世界", true)
+ pdf.SetKeywords("世界", true)
+ pdf.AddFont("Calligrapher", "", "CalligrapherRegular.json")
+ pdf.AddPage()
+ pdf.SetFont("Calligrapher", "", 16)
+ pdf.Writef(5, "\x95 %s \x95", pdf)
+ err = pdf.OutputFileAndClose(fileStr)
}
example.Summary(err, fileStr)
// Output:
diff --git a/internal/example/example.go b/internal/example/example.go
index 56ffb23..edf2388 100644
--- a/internal/example/example.go
+++ b/internal/example/example.go
@@ -31,6 +31,7 @@ var gofpdfDir string
func init() {
setRoot()
+ gofpdf.SetDefaultCompression(false)
gofpdf.SetDefaultCatalogSort(true)
gofpdf.SetDefaultCreationDate(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
}
diff --git a/pdf/reference/Fpdf_AddFont.pdf b/pdf/reference/Fpdf_AddFont.pdf
index e5c8266..f6a7404 100644
--- a/pdf/reference/Fpdf_AddFont.pdf
+++ b/pdf/reference/Fpdf_AddFont.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_AddLayer.pdf b/pdf/reference/Fpdf_AddLayer.pdf
index 16b4b5b..d0edbe7 100644
--- a/pdf/reference/Fpdf_AddLayer.pdf
+++ b/pdf/reference/Fpdf_AddLayer.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_AddPage.pdf b/pdf/reference/Fpdf_AddPage.pdf
index 72c59eb..cfeafea 100644
--- a/pdf/reference/Fpdf_AddPage.pdf
+++ b/pdf/reference/Fpdf_AddPage.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Beziergon.pdf b/pdf/reference/Fpdf_Beziergon.pdf
index b33e2ee..d0ac598 100644
--- a/pdf/reference/Fpdf_Beziergon.pdf
+++ b/pdf/reference/Fpdf_Beziergon.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Bookmark.pdf b/pdf/reference/Fpdf_Bookmark.pdf
index 463d49e..a7d8c7c 100644
--- a/pdf/reference/Fpdf_Bookmark.pdf
+++ b/pdf/reference/Fpdf_Bookmark.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_CellFormat_align.pdf b/pdf/reference/Fpdf_CellFormat_align.pdf
index 5074357..e197a42 100644
--- a/pdf/reference/Fpdf_CellFormat_align.pdf
+++ b/pdf/reference/Fpdf_CellFormat_align.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_CellFormat_codepage.pdf b/pdf/reference/Fpdf_CellFormat_codepage.pdf
index 4653511..045caf6 100644
--- a/pdf/reference/Fpdf_CellFormat_codepage.pdf
+++ b/pdf/reference/Fpdf_CellFormat_codepage.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_CellFormat_codepageescape.pdf b/pdf/reference/Fpdf_CellFormat_codepageescape.pdf
index 1d31153..a59ed43 100644
--- a/pdf/reference/Fpdf_CellFormat_codepageescape.pdf
+++ b/pdf/reference/Fpdf_CellFormat_codepageescape.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_CellFormat_tables.pdf b/pdf/reference/Fpdf_CellFormat_tables.pdf
index ef0a880..ccb45f4 100644
--- a/pdf/reference/Fpdf_CellFormat_tables.pdf
+++ b/pdf/reference/Fpdf_CellFormat_tables.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Circle_figures.pdf b/pdf/reference/Fpdf_Circle_figures.pdf
index 097d53c..a13ba38 100644
--- a/pdf/reference/Fpdf_Circle_figures.pdf
+++ b/pdf/reference/Fpdf_Circle_figures.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_ClipText.pdf b/pdf/reference/Fpdf_ClipText.pdf
index 258ea1f..2b1ed00 100644
--- a/pdf/reference/Fpdf_ClipText.pdf
+++ b/pdf/reference/Fpdf_ClipText.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_DrawPath_fill.pdf b/pdf/reference/Fpdf_DrawPath_fill.pdf
index fdde12c..488d72d 100644
--- a/pdf/reference/Fpdf_DrawPath_fill.pdf
+++ b/pdf/reference/Fpdf_DrawPath_fill.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_EmbeddedFont.pdf b/pdf/reference/Fpdf_EmbeddedFont.pdf
index 05eb36b..108986a 100644
--- a/pdf/reference/Fpdf_EmbeddedFont.pdf
+++ b/pdf/reference/Fpdf_EmbeddedFont.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_HTMLBasicNew.pdf b/pdf/reference/Fpdf_HTMLBasicNew.pdf
index fb5cbf4..587f2dc 100644
--- a/pdf/reference/Fpdf_HTMLBasicNew.pdf
+++ b/pdf/reference/Fpdf_HTMLBasicNew.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Image.pdf b/pdf/reference/Fpdf_Image.pdf
deleted file mode 100644
index 838dd4b..0000000
--- a/pdf/reference/Fpdf_Image.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_LinearGradient_gradient.pdf b/pdf/reference/Fpdf_LinearGradient_gradient.pdf
index cb1e3bd..67728d7 100644
--- a/pdf/reference/Fpdf_LinearGradient_gradient.pdf
+++ b/pdf/reference/Fpdf_LinearGradient_gradient.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_MoveTo_path.pdf b/pdf/reference/Fpdf_MoveTo_path.pdf
index b5dcca0..b73aee4 100644
--- a/pdf/reference/Fpdf_MoveTo_path.pdf
+++ b/pdf/reference/Fpdf_MoveTo_path.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_MultiCell.pdf b/pdf/reference/Fpdf_MultiCell.pdf
index a073d75..50c82b5 100644
--- a/pdf/reference/Fpdf_MultiCell.pdf
+++ b/pdf/reference/Fpdf_MultiCell.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_PageSize.pdf b/pdf/reference/Fpdf_PageSize.pdf
index f523782..e3e7e56 100644
--- a/pdf/reference/Fpdf_PageSize.pdf
+++ b/pdf/reference/Fpdf_PageSize.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Polygon.pdf b/pdf/reference/Fpdf_Polygon.pdf
index a3c04ed..c16719e 100644
--- a/pdf/reference/Fpdf_Polygon.pdf
+++ b/pdf/reference/Fpdf_Polygon.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_RegisterImage.pdf b/pdf/reference/Fpdf_RegisterImage.pdf
deleted file mode 100644
index 80a14d9..0000000
--- a/pdf/reference/Fpdf_RegisterImage.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_RegisterImageReader_url.pdf b/pdf/reference/Fpdf_RegisterImageReader_url.pdf
deleted file mode 100644
index 171ad32..0000000
--- a/pdf/reference/Fpdf_RegisterImageReader_url.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_SVGBasicWrite.pdf b/pdf/reference/Fpdf_SVGBasicWrite.pdf
index bdefa65..bc05a2b 100644
--- a/pdf/reference/Fpdf_SVGBasicWrite.pdf
+++ b/pdf/reference/Fpdf_SVGBasicWrite.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_SetAcceptPageBreakFunc_landscape.pdf b/pdf/reference/Fpdf_SetAcceptPageBreakFunc_landscape.pdf
deleted file mode 100644
index 7997df9..0000000
--- a/pdf/reference/Fpdf_SetAcceptPageBreakFunc_landscape.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_SetAlpha_transparency.pdf b/pdf/reference/Fpdf_SetAlpha_transparency.pdf
deleted file mode 100644
index 49dde6a..0000000
--- a/pdf/reference/Fpdf_SetAlpha_transparency.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_SetFontLoader.pdf b/pdf/reference/Fpdf_SetFontLoader.pdf
index 1aa2f6f..9af78e2 100644
--- a/pdf/reference/Fpdf_SetFontLoader.pdf
+++ b/pdf/reference/Fpdf_SetFontLoader.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_SetKeywords.pdf b/pdf/reference/Fpdf_SetKeywords.pdf
deleted file mode 100644
index 3d3d3a5..0000000
--- a/pdf/reference/Fpdf_SetKeywords.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdf b/pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdf
index 91b6d59..6ba28c8 100644
--- a/pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdf
+++ b/pdf/reference/Fpdf_SetLeftMargin_multicolumn.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_SetLineJoinStyle_caps.pdf b/pdf/reference/Fpdf_SetLineJoinStyle_caps.pdf
index 9b9badb..94f3a9b 100644
--- a/pdf/reference/Fpdf_SetLineJoinStyle_caps.pdf
+++ b/pdf/reference/Fpdf_SetLineJoinStyle_caps.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_SetProtection.pdf b/pdf/reference/Fpdf_SetProtection.pdf
index 8d007c7..1432cde 100644
--- a/pdf/reference/Fpdf_SetProtection.pdf
+++ b/pdf/reference/Fpdf_SetProtection.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_Splitlines.pdf b/pdf/reference/Fpdf_Splitlines.pdf
index d8064be..e9acfd1 100644
--- a/pdf/reference/Fpdf_Splitlines.pdf
+++ b/pdf/reference/Fpdf_Splitlines.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_TransformBegin.pdf b/pdf/reference/Fpdf_TransformBegin.pdf
index d1ffe34..008d421 100644
--- a/pdf/reference/Fpdf_TransformBegin.pdf
+++ b/pdf/reference/Fpdf_TransformBegin.pdf
Binary files differ
diff --git a/pdf/reference/Fpdf_WriteAligned.pdf b/pdf/reference/Fpdf_WriteAligned.pdf
index c173146..c3b52a0 100644
--- a/pdf/reference/Fpdf_WriteAligned.pdf
+++ b/pdf/reference/Fpdf_WriteAligned.pdf
Binary files differ
diff --git a/pdf/reference/basic.pdf b/pdf/reference/basic.pdf
index 80a7fbf..803212f 100644
--- a/pdf/reference/basic.pdf
+++ b/pdf/reference/basic.pdf
Binary files differ
diff --git a/pdf/reference/contrib_barcode_Register.pdf b/pdf/reference/contrib_barcode_Register.pdf
deleted file mode 100644
index 5ad12e7..0000000
--- a/pdf/reference/contrib_barcode_Register.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterCodabar.pdf b/pdf/reference/contrib_barcode_RegisterCodabar.pdf
deleted file mode 100644
index 4ed247b..0000000
--- a/pdf/reference/contrib_barcode_RegisterCodabar.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterCode128.pdf b/pdf/reference/contrib_barcode_RegisterCode128.pdf
deleted file mode 100644
index f76ae86..0000000
--- a/pdf/reference/contrib_barcode_RegisterCode128.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterCode39.pdf b/pdf/reference/contrib_barcode_RegisterCode39.pdf
deleted file mode 100644
index fee2c99..0000000
--- a/pdf/reference/contrib_barcode_RegisterCode39.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterDataMatrix.pdf b/pdf/reference/contrib_barcode_RegisterDataMatrix.pdf
deleted file mode 100644
index 5ea011d..0000000
--- a/pdf/reference/contrib_barcode_RegisterDataMatrix.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterEAN.pdf b/pdf/reference/contrib_barcode_RegisterEAN.pdf
deleted file mode 100644
index 166090d..0000000
--- a/pdf/reference/contrib_barcode_RegisterEAN.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterQR.pdf b/pdf/reference/contrib_barcode_RegisterQR.pdf
deleted file mode 100644
index 6e989e3..0000000
--- a/pdf/reference/contrib_barcode_RegisterQR.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_barcode_RegisterTwoOfFive.pdf b/pdf/reference/contrib_barcode_RegisterTwoOfFive.pdf
deleted file mode 100644
index 0078dc1..0000000
--- a/pdf/reference/contrib_barcode_RegisterTwoOfFive.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/reference/contrib_httpimg_Register.pdf b/pdf/reference/contrib_httpimg_Register.pdf
deleted file mode 100644
index 212ca93..0000000
--- a/pdf/reference/contrib_httpimg_Register.pdf
+++ /dev/null
Binary files differ
diff --git a/png.go b/png.go
new file mode 100644
index 0000000..854b003
--- /dev/null
+++ b/png.go
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2013-2016 Kurt Jung (Gmail: kurt.w.jung)
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package gofpdf
+
+import (
+ "bytes"
+ "fmt"
+ "strings"
+)
+
+func (f *Fpdf) pngColorSpace(ct byte) (colspace string, colorVal int) {
+ colorVal = 1
+ switch ct {
+ case 0, 4:
+ colspace = "DeviceGray"
+ case 2, 6:
+ colspace = "DeviceRGB"
+ colorVal = 3
+ case 3:
+ colspace = "Indexed"
+ default:
+ f.err = fmt.Errorf("unknown color type in PNG buffer: %d", ct)
+ }
+ return
+}
+
+func (f *Fpdf) parsepngstream(buf *bytes.Buffer, readdpi bool) (info *ImageInfoType) {
+ info = f.newImageInfo()
+ // Check signature
+ if string(buf.Next(8)) != "\x89PNG\x0d\x0a\x1a\x0a" {
+ f.err = fmt.Errorf("not a PNG buffer")
+ return
+ }
+ // Read header chunk
+ _ = buf.Next(4)
+ if string(buf.Next(4)) != "IHDR" {
+ f.err = fmt.Errorf("incorrect PNG buffer")
+ return
+ }
+ w := f.readBeInt32(buf)
+ h := f.readBeInt32(buf)
+ bpc := f.readByte(buf)
+ if bpc > 8 {
+ f.err = fmt.Errorf("16-bit depth not supported in PNG file")
+ }
+ ct := f.readByte(buf)
+ var colspace string
+ var colorVal int
+ colspace, colorVal = f.pngColorSpace(ct)
+ if f.err != nil {
+ return
+ }
+ if f.readByte(buf) != 0 {
+ f.err = fmt.Errorf("'unknown compression method in PNG buffer")
+ return
+ }
+ if f.readByte(buf) != 0 {
+ f.err = fmt.Errorf("'unknown filter method in PNG buffer")
+ return
+ }
+ if f.readByte(buf) != 0 {
+ f.err = fmt.Errorf("interlacing not supported in PNG buffer")
+ return
+ }
+ _ = buf.Next(4)
+ dp := sprintf("/Predictor 15 /Colors %d /BitsPerComponent %d /Columns %d", colorVal, bpc, w)
+ // Scan chunks looking for palette, transparency and image data
+ pal := make([]byte, 0, 32)
+ var trns []int
+ data := make([]byte, 0, 32)
+ loop := true
+ for loop {
+ n := int(f.readBeInt32(buf))
+ // dbg("Loop [%d]", n)
+ switch string(buf.Next(4)) {
+ case "PLTE":
+ // dbg("PLTE")
+ // Read palette
+ pal = buf.Next(n)
+ _ = buf.Next(4)
+ case "tRNS":
+ // dbg("tRNS")
+ // Read transparency info
+ t := buf.Next(n)
+ if ct == 0 {
+ trns = []int{int(t[1])} // ord(substr($t,1,1)));
+ } else if ct == 2 {
+ trns = []int{int(t[1]), int(t[3]), int(t[5])} // array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
+ } else {
+ pos := strings.Index(string(t), "\x00")
+ if pos >= 0 {
+ trns = []int{pos} // array($pos);
+ }
+ }
+ _ = buf.Next(4)
+ case "IDAT":
+ // dbg("IDAT")
+ // Read image data block
+ data = append(data, buf.Next(n)...)
+ _ = buf.Next(4)
+ case "IEND":
+ // dbg("IEND")
+ loop = false
+ case "pHYs":
+ // dbg("pHYs")
+ // png files theoretically support different x/y dpi
+ // but we ignore files like this
+ // but if they're the same then we can stamp our info
+ // object with it
+ x := int(f.readBeInt32(buf))
+ y := int(f.readBeInt32(buf))
+ units := buf.Next(1)[0]
+ // fmt.Printf("got a pHYs block, x=%d, y=%d, u=%d, readdpi=%t\n",
+ // x, y, int(units), readdpi)
+ // only modify the info block if the user wants us to
+ if x == y && readdpi {
+ switch units {
+ // if units is 1 then measurement is px/meter
+ case 1:
+ info.dpi = float64(x) / 39.3701 // inches per meter
+ default:
+ info.dpi = float64(x)
+ }
+ }
+ _ = buf.Next(4)
+ default:
+ // dbg("default")
+ _ = buf.Next(n + 4)
+ }
+ if loop {
+ loop = n > 0
+ }
+ }
+ if colspace == "Indexed" && len(pal) == 0 {
+ f.err = fmt.Errorf("missing palette in PNG buffer")
+ }
+ info.w = float64(w)
+ info.h = float64(h)
+ info.cs = colspace
+ info.bpc = int(bpc)
+ info.f = "FlateDecode"
+ info.dp = dp
+ info.pal = pal
+ info.trns = trns
+ // dbg("ct [%d]", ct)
+ if ct >= 4 {
+ // Separate alpha and color channels
+ var err error
+ data, err = sliceUncompress(data)
+ if err != nil {
+ f.err = err
+ return
+ }
+ var color, alpha bytes.Buffer
+ if ct == 4 {
+ // Gray image
+ width := int(w)
+ height := int(h)
+ length := 2 * width
+ var pos, elPos int
+ for i := 0; i < height; i++ {
+ pos = (1 + length) * i
+ color.WriteByte(data[pos])
+ alpha.WriteByte(data[pos])
+ elPos = pos + 1
+ for k := 0; k < width; k++ {
+ color.WriteByte(data[elPos])
+ alpha.WriteByte(data[elPos+1])
+ elPos += 2
+ }
+ }
+ } else {
+ // RGB image
+ width := int(w)
+ height := int(h)
+ length := 4 * width
+ var pos, elPos int
+ for i := 0; i < height; i++ {
+ pos = (1 + length) * i
+ color.WriteByte(data[pos])
+ alpha.WriteByte(data[pos])
+ elPos = pos + 1
+ for k := 0; k < width; k++ {
+ color.Write(data[elPos : elPos+3])
+ alpha.WriteByte(data[elPos+3])
+ elPos += 4
+ }
+ }
+ }
+ data = sliceCompress(color.Bytes())
+ info.smask = sliceCompress(alpha.Bytes())
+ if f.pdfVersion < "1.4" {
+ f.pdfVersion = "1.4"
+ }
+ }
+ info.data = data
+ return
+}
diff --git a/template.go b/template.go
index 6f29196..1826fd7 100644
--- a/template.go
+++ b/template.go
@@ -109,6 +109,24 @@ type Template interface {
Templates() []Template
}
+func (f *Fpdf) templateFontCatalog() {
+ var keyList []string
+ var font fontDefType
+ var key string
+ f.out("/Font <<")
+ for key = range f.fonts {
+ keyList = append(keyList, key)
+ }
+ if f.catalogSort {
+ sort.Strings(keyList)
+ }
+ for _, key = range keyList {
+ font = f.fonts[key]
+ f.outf("/F%d %d 0 R", font.I, font.N)
+ }
+ f.out(">>")
+}
+
// putTemplates writes the templates to the PDF
func (f *Fpdf) putTemplates() {
filter := ""
@@ -135,23 +153,7 @@ func (f *Fpdf) putTemplates() {
f.out("/Resources ")
f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]")
- f.out("/Font <<")
- {
- var keyList []string
- var font fontDefType
- var key string
- for key = range f.fonts {
- keyList = append(keyList, key)
- }
- if f.catalogSort {
- sort.Strings(keyList)
- }
- for _, key = range keyList {
- font = f.fonts[key]
- f.outf("/F%d %d 0 R", font.I, font.N)
- }
- }
- f.out(">>")
+ f.templateFontCatalog()
tImages := t.Images()
tTemplates := t.Templates()
diff --git a/ttfparser.go b/ttfparser.go
index 3df633c..669ab4d 100644
--- a/ttfparser.go
+++ b/ttfparser.go
@@ -89,28 +89,8 @@ func TtfParse(fileStr string) (TtfRec TtfType, err error) {
t.Skip(4) // length
t.tables[tag] = offset
}
- if err = t.ParseHead(); err != nil {
- return
- }
- if err = t.ParseHhea(); err != nil {
- return
- }
- if err = t.ParseMaxp(); err != nil {
- return
- }
- if err = t.ParseHmtx(); err != nil {
- return
- }
- if err = t.ParseCmap(); err != nil {
- return
- }
- if err = t.ParseName(); err != nil {
- return
- }
- if err = t.ParseOS2(); err != nil {
- return
- }
- if err = t.ParsePost(); err != nil {
+ err = t.ParseComponents()
+ if err != nil {
return
}
t.f.Close()
@@ -118,6 +98,32 @@ func TtfParse(fileStr string) (TtfRec TtfType, err error) {
return
}
+func (t *ttfParser) ParseComponents() (err error) {
+ err = t.ParseHead()
+ if err == nil {
+ err = t.ParseHhea()
+ if err == nil {
+ err = t.ParseMaxp()
+ if err == nil {
+ err = t.ParseHmtx()
+ if err == nil {
+ err = t.ParseCmap()
+ if err == nil {
+ err = t.ParseName()
+ if err == nil {
+ err = t.ParseOS2()
+ if err == nil {
+ err = t.ParsePost()
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return
+}
+
func (t *ttfParser) ParseHead() (err error) {
err = t.Seek("head")
t.Skip(3 * 4) // version, fontRevision, checkSumAdjustment