diff options
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 70 |
1 files changed, 46 insertions, 24 deletions
@@ -59,7 +59,9 @@ func (b *fmtBuffer) printf(fmtStr string, args ...interface{}) { func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) (f *Fpdf) { f = new(Fpdf) if orientationStr == "" { - orientationStr = "P" + orientationStr = "p" + } else { + orientationStr = strings.ToLower(orientationStr) } if unitStr == "" { unitStr = "mm" @@ -132,6 +134,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) f.stdPageSizes["a1"] = SizeType{1683.78, 2383.94} f.stdPageSizes["letter"] = SizeType{612, 792} f.stdPageSizes["legal"] = SizeType{612, 1008} + f.stdPageSizes["tabloid"] = SizeType{792, 1224} if size.Wd > 0 && size.Ht > 0 { f.defPageSize = size } else { @@ -142,7 +145,6 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) } f.curPageSize = f.defPageSize // Page orientation - orientationStr = strings.ToLower(orientationStr) switch orientationStr { case "p", "portrait": f.defOrientation = "P" @@ -179,6 +181,7 @@ func fpdfNew(orientationStr, unitStr, sizeStr, fontDirStr string, size SizeType) } // Enable compression f.SetCompression(!gl.noCompress) + f.spotColorMap = make(map[string]spotColorType) f.blendList = make([]blendModeType, 0, 8) f.blendList = append(f.blendList, blendModeType{}) // blendList[0] is unused (1-based) f.blendMap = make(map[string]int) @@ -215,7 +218,7 @@ func NewCustom(init *InitType) (f *Fpdf) { // string will be replaced with "mm". // // sizeStr specifies the page size. Acceptable values are "A3", "A4", "A5", -// "Letter", or "Legal". An empty string will be replaced with "A4". +// "Letter", "Legal", or "Tabloid". An empty string will be replaced with "A4". // // fontDirStr specifies the file system location in which font resources will // be found. An empty string is replaced with ".". This argument only needs to @@ -510,6 +513,11 @@ func (f *Fpdf) SetCreator(creatorStr string, isUTF8 bool) { f.creator = creatorStr } +// SetXmpMetadata defines XMP metadata that will be embedded with the document. +func (f *Fpdf) SetXmpMetadata(xmpStream []byte) { + f.xmp = xmpStream +} + // AliasNbPages defines an alias for the total number of pages. It will be // substituted as the document is closed. An empty string is replaced with the // string "{nb}". @@ -715,13 +723,6 @@ func (f *Fpdf) PageNo() int { return f.page } -type clrType struct { - r, g, b float64 - ir, ig, ib int - gray bool - str string -} - func colorComp(v int) (int, float64) { if v < 0 { v = 0 @@ -731,10 +732,11 @@ func colorComp(v int) (int, float64) { return v, float64(v) / 255.0 } -func colorValue(r, g, b int, grayStr, fullStr string) (clr clrType) { +func rgbColorValue(r, g, b int, grayStr, fullStr string) (clr colorType) { clr.ir, clr.r = colorComp(r) clr.ig, clr.g = colorComp(g) clr.ib, clr.b = colorComp(b) + clr.mode = colorModeRGB clr.gray = clr.ir == clr.ig && clr.r == clr.b if len(grayStr) > 0 { if clr.gray { @@ -753,13 +755,15 @@ func colorValue(r, g, b int, grayStr, fullStr string) (clr clrType) { // The method can be called before the first page is created. The value is // retained from page to page. func (f *Fpdf) SetDrawColor(r, g, b int) { - f.color.draw = colorValue(r, g, b, "G", "RG") + f.color.draw = rgbColorValue(r, g, b, "G", "RG") if f.page > 0 { f.out(f.color.draw.str) } } -// GetDrawColor returns the current draw color as RGB components (0 - 255). +// GetDrawColor returns the most recently set draw color as RGB components (0 - +// 255). This will not be the current value if a draw color of some other type +// (for example, spot) has been more recently set. func (f *Fpdf) GetDrawColor() (int, int, int) { return f.color.draw.ir, f.color.draw.ig, f.color.draw.ib } @@ -769,14 +773,16 @@ func (f *Fpdf) GetDrawColor() (int, int, int) { // -255). The method can be called before the first page is created and the // value is retained from page to page. func (f *Fpdf) SetFillColor(r, g, b int) { - f.color.fill = colorValue(r, g, b, "g", "rg") + f.color.fill = rgbColorValue(r, g, b, "g", "rg") f.colorFlag = f.color.fill.str != f.color.text.str if f.page > 0 { f.out(f.color.fill.str) } } -// GetFillColor returns the current fill color as RGB components (0 - 255). +// GetFillColor returns the most recently set fill color as RGB components (0 - +// 255). This will not be the current value if a fill color of some other type +// (for example, spot) has been more recently set. func (f *Fpdf) GetFillColor() (int, int, int) { return f.color.fill.ir, f.color.fill.ig, f.color.fill.ib } @@ -785,11 +791,13 @@ func (f *Fpdf) GetFillColor() (int, int, int) { // components (0 - 255). The method can be called before the first page is // created. The value is retained from page to page. func (f *Fpdf) SetTextColor(r, g, b int) { - f.color.text = colorValue(r, g, b, "g", "rg") + f.color.text = rgbColorValue(r, g, b, "g", "rg") f.colorFlag = f.color.fill.str != f.color.text.str } -// GetTextColor returns the current text color as RGB components (0 - 255). +// GetTextColor returns the most recently set text color as RGB components (0 - +// 255). This will not be the current value if a text color of some other type +// (for example, spot) has been more recently set. func (f *Fpdf) GetTextColor() (int, int, int) { return f.color.text.ir, f.color.text.ig, f.color.text.ib } @@ -1177,8 +1185,8 @@ func (f *Fpdf) gradientClipEnd() { func (f *Fpdf) gradient(tp int, r1, g1, b1 int, r2, g2, b2 int, x1, y1 float64, x2, y2 float64, r float64) { pos := len(f.gradientList) - clr1 := colorValue(r1, g1, b1, "", "") - clr2 := colorValue(r2, g2, b2, "", "") + clr1 := rgbColorValue(r1, g1, b1, "", "") + clr2 := rgbColorValue(r2, g2, b2, "", "") f.gradientList = append(f.gradientList, gradientType{tp, clr1.str, clr2.str, x1, y1, x2, y2, r, 0}) f.outf("/Sh%d sh", pos) @@ -1924,19 +1932,19 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, if len(txtStr) > 0 { var dx, dy float64 // Horizontal alignment - if strings.Index(alignStr, "R") != -1 { + if strings.Contains(alignStr, "R") { dx = w - f.cMargin - f.GetStringWidth(txtStr) - } else if strings.Index(alignStr, "C") != -1 { + } else if strings.Contains(alignStr, "C") { dx = (w - f.GetStringWidth(txtStr)) / 2 } else { dx = f.cMargin } // Vertical alignment - if strings.Index(alignStr, "T") != -1 { + if strings.Contains(alignStr, "T") { dy = (f.fontSize - h) / 2.0 - } else if strings.Index(alignStr, "B") != -1 { + } else if strings.Contains(alignStr, "B") { dy = (h - f.fontSize) / 2.0 - } else if strings.Index(alignStr, "A") != -1 { + } else if strings.Contains(alignStr, "A") { var descent float64 d := f.currentFont.Desc if d.Descent == 0 { @@ -3471,6 +3479,7 @@ func (f *Fpdf) putresourcedict() { } // Layers f.layerPutResourceDict() + f.spotColorPutResourceDict() } func (f *Fpdf) putBlendModes() { @@ -3536,6 +3545,7 @@ func (f *Fpdf) putresources() { f.layerPutLayers() f.putBlendModes() f.putGradients() + f.putSpotColors() f.putfonts() if f.err != nil { return @@ -3650,6 +3660,16 @@ func (f *Fpdf) puttrailer() { } } +func (f *Fpdf) putxmp() { + if len(f.xmp) == 0 { + return + } + f.newobj() + f.outf("<< /Type /Metadata /Subtype /XML /Length %d >>", len(f.xmp)) + f.putstream(f.xmp) + f.out("endobj") +} + func (f *Fpdf) putbookmarks() { nb := len(f.outlines) if nb > 0 { @@ -3716,6 +3736,8 @@ func (f *Fpdf) enddoc() { } // Bookmarks f.putbookmarks() + // Metadata + f.putxmp() // Info f.newobj() f.out("<<") |