Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: RevenueMonster/gopdf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.21
Choose a base ref
...
head repository: RevenueMonster/gopdf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Aug 31, 2021

  1. custom mask

    akhll authored and Aleksandr Khylobokyi committed Aug 31, 2021
    Copy the full SHA
    c00daad View commit details
  2. fix go.mod

    Aleksandr Khylobokyi committed Aug 31, 2021
    Copy the full SHA
    bad8dcb View commit details
  3. pass bbox from options

    Aleksandr Khylobokyi committed Aug 31, 2021
    Copy the full SHA
    6bea83c View commit details
  4. rebase fixes

    Aleksandr Khylobokyi committed Aug 31, 2021
    Copy the full SHA
    b00150b View commit details
  5. fix go.mod

    Aleksandr Khylobokyi committed Aug 31, 2021
    Copy the full SHA
    cb1cee9 View commit details

Commits on Sep 1, 2021

  1. increase bbox value

    Aleksandr Khylobokyi committed Sep 1, 2021
    Copy the full SHA
    33bfe65 View commit details

Commits on Sep 2, 2021

  1. ignore ErrGlyphNotFound error

    Aleksandr Khylobokyi committed Sep 2, 2021
    Copy the full SHA
    f52c8a4 View commit details
  2. return modulen name

    Aleksandr Khylobokyi committed Sep 2, 2021
    Copy the full SHA
    c7b95d4 View commit details

Commits on Sep 3, 2021

  1. Copy the full SHA
    eb8e5cc View commit details

Commits on Sep 5, 2021

  1. Copy the full SHA
    aa90769 View commit details

Commits on Sep 6, 2021

  1. Copy the full SHA
    71817cb View commit details

Commits on Sep 8, 2021

  1. Update font size from int to float64

    Christoph Mitterhofer committed Sep 8, 2021
    Copy the full SHA
    2a181ad View commit details
  2. some tests for the new functionality

    Christoph Mitterhofer committed Sep 8, 2021
    Copy the full SHA
    d502cb2 View commit details

Commits on Sep 9, 2021

  1. Fixed RTrim(floatstr, "0.") converts "10.0" to "1"

    Christoph Mitterhofer committed Sep 9, 2021
    Copy the full SHA
    51229b9 View commit details

Commits on Sep 11, 2021

  1. Merge branch 'fontsizefloat64' of https://github.com/mtcxgarble/gopdf

    …into mtcxgarble-fontsizefloat64
    oneplus1000 committed Sep 11, 2021
    Copy the full SHA
    efca6f4 View commit details
  2. add Usage for draw line

    oneplus1000 committed Sep 11, 2021
    Copy the full SHA
    e216800 View commit details
  3. Copy the full SHA
    9ea2b13 View commit details

Commits on Sep 13, 2021

  1. Copy the full SHA
    21cd76f View commit details
  2. Change to draw rectangle directly if radius / radiusPointNumber = 0, …

    …remove fmt.Println and update test case
    fung-leung committed Sep 13, 2021
    Copy the full SHA
    ba0217d View commit details

Commits on Sep 17, 2021

  1. Copy the full SHA
    e4dc835 View commit details

Commits on Sep 23, 2021

  1. replace with some char

    oneplus1000 committed Sep 23, 2021
    Copy the full SHA
    17e8c44 View commit details

Commits on Sep 24, 2021

  1. create new function "OnGlyphNotFoundGetReplace" that Called when a gl…

    …yph cannot be found, we can return a new rune to replace it.
    oneplus1000 committed Sep 24, 2021
    Copy the full SHA
    f0a3396 View commit details

Commits on Sep 25, 2021

  1. remove pdf file

    oneplus1000 committed Sep 25, 2021
    Copy the full SHA
    7788e3c View commit details
  2. Copy the full SHA
    28a5ef8 View commit details
  3. Copy the full SHA
    859dda1 View commit details

Commits on Oct 10, 2021

  1. fix ignored error

    matsuyoshi30 committed Oct 10, 2021
    Copy the full SHA
    a4be0d0 View commit details
  2. try to fix issue 197

    oneplus1000 committed Oct 10, 2021
    Copy the full SHA
    4264ecb View commit details

Commits on Oct 11, 2021

  1. fix test file

    oneplus1000 committed Oct 11, 2021
    Copy the full SHA
    6512b82 View commit details

Commits on Oct 13, 2021

  1. clean code

    oneplus1000 committed Oct 13, 2021
    Copy the full SHA
    3f2853d View commit details

Commits on Oct 16, 2021

  1. Merge branch 'patch-1' of https://github.com/matsuyoshi30/gopdf into …

    …matsuyoshi30-patch-1
    oneplus1000 committed Oct 16, 2021
    Copy the full SHA
    93e7729 View commit details
  2. Copy the full SHA
    afab55f View commit details

Commits on Oct 18, 2021

  1. fix underline

    akhll committed Oct 18, 2021
    Copy the full SHA
    20fbb80 View commit details

Commits on Oct 19, 2021

  1. rename mod

    akhll committed Oct 19, 2021
    Copy the full SHA
    9d1b9a3 View commit details

Commits on Oct 24, 2021

  1. Copy the full SHA
    de10fd6 View commit details

Commits on Nov 11, 2021

  1. Copy the full SHA
    2145c5a View commit details
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -157,6 +157,17 @@ pdf.SetFillColor(0, 255, 0)
pdf.Polygon([]gopdf.Point{{X: 10, Y: 30}, {X: 585, Y: 200}, {X: 585, Y: 250}}, "DF")
```

### Draw rectangle with round corner
```go
pdf.SetStrokeColor(255, 0, 0)
pdf.SetLineWidth(2)
pdf.SetFillColor(0, 255, 0)
err := pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)
if err != nil {
return err
}
```

### Rotation text or image
```go
pdf.SetX(100)
6 changes: 6 additions & 0 deletions cache_content_line.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,15 @@ type cacheContentLine struct {
y1 float64
x2 float64
y2 float64
opts lineOptions
}

func (c *cacheContentLine) write(w io.Writer, protection *PDFProtection) error {
fmt.Fprintf(w, "q\n")
for _, extGStateIndex := range c.opts.extGStateIndexes {
fmt.Fprintf(w, "/GS%d gs\n", extGStateIndex)
}
fmt.Fprintf(w, "%0.2f %0.2f m %0.2f %0.2f l S\n", c.x1, c.pageHeight-c.y1, c.x2, c.pageHeight-c.y2)
fmt.Fprintf(w, "Q\n")
return nil
}
7 changes: 7 additions & 0 deletions cache_content_polygon.go
Original file line number Diff line number Diff line change
@@ -9,10 +9,16 @@ type cacheContentPolygon struct {
pageHeight float64
style string
points []Point
opts polygonOptions
}

func (c *cacheContentPolygon) write(w io.Writer, protection *PDFProtection) error {

fmt.Fprintf(w, "q\n")
for _, extGStateIndex := range c.opts.extGStateIndexes {
fmt.Fprintf(w, "/GS%d gs\n", extGStateIndex)
}

for i, point := range c.points {
fmt.Fprintf(w, "%.2f %.2f", point.X, c.pageHeight-point.Y)
if i == 0 {
@@ -31,5 +37,6 @@ func (c *cacheContentPolygon) write(w io.Writer, protection *PDFProtection) erro
fmt.Fprintf(w, " s\n")
}

fmt.Fprintf(w, "Q\n")
return nil
}
78 changes: 59 additions & 19 deletions cache_content_text.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,14 @@ import (
"errors"
"fmt"
"io"
"math"
"strconv"
)

const defaultCoefLineHeight = float64(1)
const defaultCoefUnderlinePosition = float64(1)
const defaultcoefUnderlineThickness = float64(1)

//ContentTypeCell cell
const ContentTypeCell = 0

@@ -19,7 +25,7 @@ type cacheContentText struct {
grayFill float64
txtColorMode string
fontCountIndex int //Curr.FontFontCount+1
fontSize int
fontSize float64
fontStyle int
setXCount int //จำนวนครั้งที่ใช้ setX
x, y float64
@@ -110,6 +116,14 @@ func (c *cacheContentText) calX() (float64, error) {
return 0.0, errors.New("contentType not found")
}

// FormatFloatTrim converts a float64 into a string, like Sprintf("%.3f")
// but with trailing zeroes (and possibly ".") removed
func FormatFloatTrim(floatval float64) (formatted string) {
const precisionFactor = 1000.0
roundedFontSize := math.Round(precisionFactor*floatval) / precisionFactor
return strconv.FormatFloat(roundedFontSize, 'f', -1, 64)
}

func (c *cacheContentText) write(w io.Writer, protection *PDFProtection) error {
r := c.textColor.r
g := c.textColor.g
@@ -135,7 +149,8 @@ func (c *cacheContentText) write(w io.Writer, protection *PDFProtection) error {
}

fmt.Fprintf(w, "%0.2f %0.2f TD\n", x, y)
fmt.Fprintf(w, "/F%d %d Tf\n", c.fontCountIndex, c.fontSize)
fmt.Fprintf(w, "/F%d %s Tf\n", c.fontCountIndex, FormatFloatTrim(c.fontSize))

if c.txtColorMode == "color" {
fmt.Fprintf(w, "%0.3f %0.3f %0.3f rg\n", float64(r)/255, float64(g)/255, float64(b)/255)
}
@@ -147,7 +162,9 @@ func (c *cacheContentText) write(w io.Writer, protection *PDFProtection) error {
for i, r := range c.text {

glyphindex, err := c.fontSubset.CharIndex(r)
if err != nil {
if err == ErrCharNotFound {
continue
} else if err != nil {
return err
}

@@ -169,8 +186,7 @@ func (c *cacheContentText) write(w io.Writer, protection *PDFProtection) error {
io.WriteString(w, "ET\n")

if c.fontStyle&Underline == Underline {
err := c.underline(w, c.x, c.y, c.x+c.cellWidthPdfUnit, c.y)
if err != nil {
if err := c.underline(w); err != nil {
return err
}
}
@@ -233,20 +249,42 @@ func (c *cacheContentText) drawBorder(w io.Writer) error {
return nil
}

func (c *cacheContentText) underline(w io.Writer, startX float64, startY float64, endX float64, endY float64) error {

func (c *cacheContentText) underline(w io.Writer) error {
if c.fontSubset == nil {
return errors.New("error AppendUnderline not found font")
}
unitsPerEm := float64(c.fontSubset.ttfp.UnitsPerEm())
h := c.pageHeight()
ut := float64(c.fontSubset.GetUt())
up := float64(c.fontSubset.GetUp())
textH := ContentObjCalTextHeight(c.fontSize)
arg3 := float64(h) - (float64(startY) - ((up / unitsPerEm) * float64(c.fontSize))) - textH
arg4 := (ut / unitsPerEm) * float64(c.fontSize)
fmt.Fprintf(w, "%0.2f %0.2f %0.2f -%0.2f re f\n", startX, arg3, endX-startX, arg4)
//fmt.Printf("arg3=%f arg4=%f\n", arg3, arg4)

coefLineHeight := defaultCoefLineHeight
if c.cellOpt.CoefLineHeight != 0 {
coefLineHeight = c.cellOpt.CoefLineHeight
}

coefUnderlinePosition := defaultCoefUnderlinePosition
if c.cellOpt.CoefUnderlinePosition != 0 {
coefUnderlinePosition = c.cellOpt.CoefUnderlinePosition
}

coefUnderlineThickness := defaultcoefUnderlineThickness
if c.cellOpt.CoefUnderlineThickness != 0 {
coefUnderlineThickness = c.cellOpt.CoefUnderlineThickness
}

ascenderPx := c.fontSubset.GetAscenderPx(c.fontSize)
descenderPx := -c.fontSubset.GetDescenderPx(c.fontSize)

contentHeight := ascenderPx + descenderPx
virtualHeight := coefLineHeight * float64(c.fontSize)
leading := (contentHeight - virtualHeight) / 2

baseline := ascenderPx + leading

underlinePositionPx := c.fontSubset.GetUnderlinePositionPx(c.fontSize) * coefUnderlinePosition
underlineThicknessPx := c.fontSubset.GetUnderlineThicknessPx(c.fontSize) * coefUnderlineThickness

yUnderlinePosition := c.pageHeight() - c.y + underlinePositionPx - baseline
if _, err := fmt.Fprintf(w, "%0.2f %0.2f %0.2f %0.2f re f\n", c.x, yUnderlinePosition, c.cellWidthPdfUnit, underlineThicknessPx); err != nil {
return err
}

return nil
}
@@ -263,7 +301,7 @@ func (c *cacheContentText) createContent() (float64, float64, error) {
return cellWidthPdfUnit, cellHeightPdfUnit, nil
}

func createContent(f *SubsetFontObj, text string, fontSize int, rectangle *Rect) (float64, float64, float64, error) {
func createContent(f *SubsetFontObj, text string, fontSize float64, rectangle *Rect) (float64, float64, float64, error) {

unitsPerEm := int(f.ttfp.UnitsPerEm())
var leftRune rune
@@ -273,7 +311,9 @@ func createContent(f *SubsetFontObj, text string, fontSize int, rectangle *Rect)
for i, r := range text {

glyphindex, err := f.CharIndex(r)
if err != nil {
if err == ErrCharNotFound {
continue
} else if err != nil {
return 0, 0, 0, err
}

@@ -339,7 +379,7 @@ func (c *CacheContent) Setup(rectangle *Rect,
textColor Rgb,
grayFill float64,
fontCountIndex int, //Curr.FontFontCount+1
fontSize int,
fontSize float64,
fontStyle int,
setXCount int, //จำนวนครั้งที่ใช้ setX
x, y float64,
13 changes: 8 additions & 5 deletions cell_option.go
Original file line number Diff line number Diff line change
@@ -17,10 +17,13 @@ const AllBorders = 15 //001111

//CellOption cell option
type CellOption struct {
Align int //Allows to align the text. Possible values are: Left,Center,Right,Top,Bottom,Middle
Border int //Indicates if borders must be drawn around the cell. Possible values are: Left, Top, Right, Bottom, ALL
Float int //Indicates where the current position should go after the call. Possible values are: Right, Bottom
Transparency *Transparency
Align int //Allows to align the text. Possible values are: Left,Center,Right,Top,Bottom,Middle
Border int //Indicates if borders must be drawn around the cell. Possible values are: Left, Top, Right, Bottom, ALL
Float int //Indicates where the current position should go after the call. Possible values are: Right, Bottom
Transparency *Transparency
CoefUnderlinePosition float64
CoefLineHeight float64
CoefUnderlineThickness float64

extGStateIndexes []int
}
}
14 changes: 11 additions & 3 deletions content_obj.go
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ func (c *ContentObj) AppendStreamSubsetFont(rectangle *Rect, text string, cellOp
}

//AppendStreamLine append line
func (c *ContentObj) AppendStreamLine(x1 float64, y1 float64, x2 float64, y2 float64) {
func (c *ContentObj) AppendStreamLine(x1 float64, y1 float64, x2 float64, y2 float64, lineOpts lineOptions) {
//h := c.getRoot().config.PageSize.H
//c.stream.WriteString(fmt.Sprintf("%0.2f %0.2f m %0.2f %0.2f l s\n", x1, h-y1, x2, h-y2))
var cache cacheContentLine
@@ -189,6 +189,7 @@ func (c *ContentObj) AppendStreamLine(x1 float64, y1 float64, x2 float64, y2 flo
cache.y1 = y1
cache.x2 = x2
cache.y2 = y2
cache.opts = lineOpts
c.listCache.append(&cache)
}

@@ -320,11 +321,12 @@ func (c *ContentObj) AppendStreamImage(index int, opts ImageOptions) {
}

//AppendStreamPolygon append polygon
func (c *ContentObj) AppendStreamPolygon(points []Point, style string) {
func (c *ContentObj) AppendStreamPolygon(points []Point, style string, opts polygonOptions) {
var cache cacheContentPolygon
cache.points = points
cache.style = style
cache.pageHeight = c.getRoot().curr.pageSize.H
cache.opts = opts
c.listCache.append(&cache)
}

@@ -344,8 +346,14 @@ func (c *ContentObj) appendRotateReset() {
c.listCache.append(&cache)
}

//ContentObjCalTextHeight calculates height of text.
//ContentObjCalTextHeight : calculates height of text.
func ContentObjCalTextHeight(fontsize int) float64 {
return ContentObjCalTextHeightPrecise(float64(fontsize))
}

//ContentObjCalTextHeightPrecise : like ContentObjCalTextHeight,
// but fontsize float64
func ContentObjCalTextHeightPrecise(fontsize float64) float64 {
return (float64(fontsize) * 0.7)
}

2 changes: 1 addition & 1 deletion current.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ type Current struct {
CountOfFont int
CountOfL int

FontSize int
FontSize float64
FontStyle int // Regular|Bold|Italic|Underline
FontFontCount int
FontType int // CURRENT_FONT_TYPE_IFONT or CURRENT_FONT_TYPE_SUBSET
10 changes: 6 additions & 4 deletions fontmaker/core/fontmaker.go
Original file line number Diff line number Diff line change
@@ -174,10 +174,10 @@ func (f *FontMaker) MakeDefinitionFile(gofontname string, mappath string, export
str += "func (me * " + gofontname + ")GetDesc() []gopdf.FontDescItem{\n"
str += "\treturn me.desc\n"
str += "}\n"
str += "func (me * " + gofontname + ")GetUp() int{\n"
str += "func (me * " + gofontname + ")GetUnderlinePosition() int{\n"
str += "\treturn me.up\n"
str += "}\n"
str += "func (me * " + gofontname + ")GetUt() int{\n"
str += "func (me * " + gofontname + ")GetUnderlineThickness() int{\n"
str += "\treturn me.ut\n"
str += "}\n"
str += "func (me * " + gofontname + ")GetCw() gopdf.FontCw{\n"
@@ -251,11 +251,14 @@ func (f *FontMaker) MakeFontDescriptor(info TtfInfo) (string, error) {
}
flags += 1 << 5
italicAngle, err := info.GetInt64("ItalicAngle")
if err != nil {
return "", err
}
if italicAngle != 0 {
flags += 1 << 6
}
fd += fmt.Sprintf("\tme.desc[3] = gopdf.FontDescItem{ Key: \"Flags\", Val : \"%d\" }\n", flags)
//fmt.Printf("\n----\n")

// FontBBox
fbb, err := info.GetInt64s("FontBBox")
if err != nil {
@@ -480,7 +483,6 @@ func (f *FontMaker) LoadMap(encodingpath string) ([]FontMap, error) {
return nil, err
}
name := e[2]
//fmt.Println("strC = "+strC+"strUv = "+strUv+" c=%d , uv= %d", c, uv)
fontmaps[c].Name = name
fontmaps[c].Uv = int(uv)
}
Loading