- Added : Required modification on border and basic line implementation

- BorderTest
- CellTest
This commit is contained in:
Sakib Sami 2018-08-10 01:40:40 +06:00
parent c024c237d2
commit fd475ad84d
3 changed files with 47 additions and 58 deletions

View File

@ -6,7 +6,6 @@ import (
pdfcontent "github.com/unidoc/unidoc/pdf/contentstream" pdfcontent "github.com/unidoc/unidoc/pdf/contentstream"
pdfcore "github.com/unidoc/unidoc/pdf/core" pdfcore "github.com/unidoc/unidoc/pdf/core"
pdf "github.com/unidoc/unidoc/pdf/model" pdf "github.com/unidoc/unidoc/pdf/model"
"fmt"
) )
type Circle struct { type Circle struct {
@ -382,15 +381,6 @@ type BasicLine struct {
func (line BasicLine) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error) { func (line BasicLine) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error) {
w := line.LineWidth w := line.LineWidth
line.X1 = line.X1 - (line.LineWidth / 2)
line.Y1 = line.Y1 - (line.LineWidth / 2)
fmt.Println("---------------")
fmt.Println("X1 : ", line.X1)
fmt.Println("Y1 : ", line.Y1)
fmt.Println("X2 : ", line.X2)
fmt.Println("Y2 : ", line.Y2)
path := NewPath() path := NewPath()
path = path.AppendPoint(NewPoint(line.X1, line.Y1)) path = path.AppendPoint(NewPoint(line.X1, line.Y1))
path = path.AppendPoint(NewPoint(line.X2, line.Y2)) path = path.AppendPoint(NewPoint(line.X2, line.Y2))

View File

@ -135,14 +135,14 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
if border.borderWidthTop != 0 { if border.borderWidthTop != 0 {
if border.StyleTop == CellBorderStyleDoubleTop { if border.StyleTop == CellBorderStyleDoubleTop {
x := startX x := startX - border.borderWidthTop/2
y := startY y := startY
lineTop := draw.BasicLine{} lineTop := draw.BasicLine{}
lineTop.X1 = x lineTop.X1 = x - (border.borderWidthLeft * 2)
lineTop.Y1 = y lineTop.Y1 = y + (border.borderWidthTop * 2)
lineTop.X2 = x + border.width lineTop.X2 = x + border.width + (border.borderWidthLeft * 2) + border.borderWidthLeft
lineTop.Y2 = y lineTop.Y2 = y + (border.borderWidthTop * 2)
lineTop.LineColor = border.borderColorTop lineTop.LineColor = border.borderColorTop
lineTop.LineWidth = border.borderWidthTop lineTop.LineWidth = border.borderWidthTop
lineTop.LineStyle = border.LineStyle lineTop.LineStyle = border.LineStyle
@ -161,9 +161,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
LineWidth: border.borderWidthTop, LineWidth: border.borderWidthTop,
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorTop, LineColor: border.borderColorTop,
X1: startX, X1: startX - border.borderWidthLeft/2,
Y1: startY, Y1: startY,
X2: startX + border.width, X2: startX + border.width + (border.borderWidthRight / 2),
Y2: startY, Y2: startY,
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
@ -182,17 +182,14 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
y := startY - border.height y := startY - border.height
if border.StyleBottom == CellBorderStyleDoubleBottom { if border.StyleBottom == CellBorderStyleDoubleBottom {
dx := x
dy := y
lineBottom := draw.BasicLine{ lineBottom := draw.BasicLine{
LineWidth: border.borderWidthBottom, LineWidth: border.borderWidthBottom,
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorBottom, LineColor: border.borderColorBottom,
X1: dx, X1: x - (border.borderWidthLeft * 2) - (border.borderWidthLeft / 2),
Y1: dy, Y1: y - (border.borderWidthTop * 2),
X2: dx, X2: x + border.width + (border.borderWidthLeft * 2) + (border.borderWidthLeft / 2),
Y2: dy, Y2: y - (border.borderWidthTop * 2),
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
contentsBottom, _, err := lineBottom.Draw("") contentsBottom, _, err := lineBottom.Draw("")
@ -209,9 +206,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
LineWidth: border.borderWidthBottom, LineWidth: border.borderWidthBottom,
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorBottom, LineColor: border.borderColorBottom,
X1: x, X1: x - border.borderWidthLeft/2,
Y1: y, Y1: y,
X2: x + border.width, X2: x + border.width + (border.borderWidthRight / 2),
Y2: y, Y2: y,
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
@ -235,10 +232,10 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
LineWidth: border.borderWidthLeft, LineWidth: border.borderWidthLeft,
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorLeft, LineColor: border.borderColorLeft,
X1: x, X1: x - (border.borderWidthLeft * 2),
Y1: y, Y1: y + border.borderWidthTop/2 + (border.borderWidthTop * 2),
X2: x, X2: x - (border.borderWidthLeft * 2),
Y2: y - border.height, Y2: y - border.height - (border.borderWidthBottom / 2) - (border.borderWidthBottom * 2),
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
contentsLeft, _, err := lineLeft.Draw("") contentsLeft, _, err := lineLeft.Draw("")
@ -257,9 +254,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorLeft, LineColor: border.borderColorLeft,
X1: x, X1: x,
Y1: y, Y1: y + border.borderWidthTop/2,
X2: x, X2: x,
Y2: y - border.height, Y2: y - border.height - (border.borderWidthBottom / 2),
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
contentsLeft, _, err := lineLeft.Draw("") contentsLeft, _, err := lineLeft.Draw("")
@ -282,10 +279,10 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
LineWidth: border.borderWidthRight, LineWidth: border.borderWidthRight,
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorRight, LineColor: border.borderColorRight,
X1: x, X1: x + (border.borderWidthRight * 2),
Y1: y, Y1: y + border.borderWidthTop/2 + (border.borderWidthTop * 2),
X2: x, X2: x + (border.borderWidthRight * 2),
Y2: y - border.height, Y2: y - border.height - (border.borderWidthBottom / 2) - (border.borderWidthBottom * 2),
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
contentsRight, _, err := lineRight.Draw("") contentsRight, _, err := lineRight.Draw("")
@ -304,9 +301,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
Opacity: 1.0, Opacity: 1.0,
LineColor: border.borderColorRight, LineColor: border.borderColorRight,
X1: x, X1: x,
Y1: y, Y1: y + border.borderWidthTop/2,
X2: x, X2: x,
Y2: y - border.height, Y2: y - border.height - (border.borderWidthBottom / 2),
LineStyle: border.LineStyle, LineStyle: border.LineStyle,
} }
contentsRight, _, err := lineRight.Draw("") contentsRight, _, err := lineRight.Draw("")

View File

@ -1627,8 +1627,7 @@ func TestCreatorTableBorderReq1(t *testing.T) {
c.Draw(table9) c.Draw(table9)
c.Draw(table10) c.Draw(table10)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return
@ -1643,8 +1642,7 @@ func TestBasicLine(t *testing.T) {
c := New() c := New()
c.Draw(line) c.Draw(line)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/basic_line.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return
@ -1660,8 +1658,7 @@ func TestBasicLineWithDash(t *testing.T) {
c := New() c := New()
c.Draw(line) c.Draw(line)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/basic_line_with_dash.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return
@ -1688,8 +1685,7 @@ func TestRectangle(t *testing.T) {
c.Draw(top) c.Draw(top)
c.Draw(right) c.Draw(right)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/rectangle.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return
@ -1700,20 +1696,24 @@ func TestSingleBorder(t *testing.T) {
border := newBorder(100, 100, 100, 100) border := newBorder(100, 100, 100, 100)
//border.SetFillColor(ColorRed) //border.SetFillColor(ColorRed)
border.SetColorBottom(ColorRed) border.SetColorBottom(ColorRed)
border.SetColorTop(ColorRed) border.SetColorTop(ColorGreen)
border.SetColorLeft(ColorRed) border.SetColorLeft(ColorBlack)
border.SetColorRight(ColorRed) border.SetColorRight(ColorBlue)
border.SetWidthBottom(1) border.SetWidthBottom(3)
border.SetWidthTop(1) border.SetWidthTop(3)
border.SetWidthLeft(1) border.SetWidthLeft(3)
border.SetWidthRight(1) border.SetWidthRight(3)
border.StyleTop = CellBorderStyleDoubleTop
border.StyleBottom = CellBorderStyleDoubleBottom
border.StyleLeft = CellBorderStyleDoubleLeft
border.StyleRight = CellBorderStyleDoubleRight
c := New() c := New()
c.Draw(border) c.Draw(border)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/single_border.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return
@ -1726,13 +1726,15 @@ func TestCellBorder(t *testing.T) {
cell1 := table.NewCell() cell1 := table.NewCell()
cell1.SetContent(newContent("Cell 1", TextAlignmentLeft, fonts.NewFontTimesBold(), 8, ColorRed)) cell1.SetContent(newContent("Cell 1", TextAlignmentLeft, fonts.NewFontTimesBold(), 8, ColorRed))
cell1.SetBorder(CellBorderStyleBox, 3) cell1.SetBorder(CellBorderStyleDoubleTop, 1)
cell1.SetBorder(CellBorderStyleDoubleBottom, 1)
cell1.SetBorder(CellBorderStyleDoubleLeft, 1)
cell1.SetBorder(CellBorderStyleDoubleRight, 1)
c := New() c := New()
c.Draw(table) c.Draw(table)
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf") err := c.WriteToFile("/tmp/cell.pdf")
err := c.WriteToFile("../../testfiles/table.pdf")
if err != nil { if err != nil {
t.Errorf("Fail: %v\n", err) t.Errorf("Fail: %v\n", err)
return return