mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-07 19:29:16 +08:00
- Added : Required modification on border and basic line implementation
- BorderTest - CellTest
This commit is contained in:
parent
c024c237d2
commit
fd475ad84d
@ -6,7 +6,6 @@ import (
|
||||
pdfcontent "github.com/unidoc/unidoc/pdf/contentstream"
|
||||
pdfcore "github.com/unidoc/unidoc/pdf/core"
|
||||
pdf "github.com/unidoc/unidoc/pdf/model"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Circle struct {
|
||||
@ -382,15 +381,6 @@ type BasicLine struct {
|
||||
func (line BasicLine) Draw(gsName string) ([]byte, *pdf.PdfRectangle, error) {
|
||||
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 = path.AppendPoint(NewPoint(line.X1, line.Y1))
|
||||
path = path.AppendPoint(NewPoint(line.X2, line.Y2))
|
||||
|
@ -135,14 +135,14 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
|
||||
if border.borderWidthTop != 0 {
|
||||
if border.StyleTop == CellBorderStyleDoubleTop {
|
||||
x := startX
|
||||
x := startX - border.borderWidthTop/2
|
||||
y := startY
|
||||
|
||||
lineTop := draw.BasicLine{}
|
||||
lineTop.X1 = x
|
||||
lineTop.Y1 = y
|
||||
lineTop.X2 = x + border.width
|
||||
lineTop.Y2 = y
|
||||
lineTop.X1 = x - (border.borderWidthLeft * 2)
|
||||
lineTop.Y1 = y + (border.borderWidthTop * 2)
|
||||
lineTop.X2 = x + border.width + (border.borderWidthLeft * 2) + border.borderWidthLeft
|
||||
lineTop.Y2 = y + (border.borderWidthTop * 2)
|
||||
lineTop.LineColor = border.borderColorTop
|
||||
lineTop.LineWidth = border.borderWidthTop
|
||||
lineTop.LineStyle = border.LineStyle
|
||||
@ -161,9 +161,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
LineWidth: border.borderWidthTop,
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorTop,
|
||||
X1: startX,
|
||||
X1: startX - border.borderWidthLeft/2,
|
||||
Y1: startY,
|
||||
X2: startX + border.width,
|
||||
X2: startX + border.width + (border.borderWidthRight / 2),
|
||||
Y2: startY,
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
@ -182,17 +182,14 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
y := startY - border.height
|
||||
|
||||
if border.StyleBottom == CellBorderStyleDoubleBottom {
|
||||
dx := x
|
||||
dy := y
|
||||
|
||||
lineBottom := draw.BasicLine{
|
||||
LineWidth: border.borderWidthBottom,
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorBottom,
|
||||
X1: dx,
|
||||
Y1: dy,
|
||||
X2: dx,
|
||||
Y2: dy,
|
||||
X1: x - (border.borderWidthLeft * 2) - (border.borderWidthLeft / 2),
|
||||
Y1: y - (border.borderWidthTop * 2),
|
||||
X2: x + border.width + (border.borderWidthLeft * 2) + (border.borderWidthLeft / 2),
|
||||
Y2: y - (border.borderWidthTop * 2),
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
contentsBottom, _, err := lineBottom.Draw("")
|
||||
@ -209,9 +206,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
LineWidth: border.borderWidthBottom,
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorBottom,
|
||||
X1: x,
|
||||
X1: x - border.borderWidthLeft/2,
|
||||
Y1: y,
|
||||
X2: x + border.width,
|
||||
X2: x + border.width + (border.borderWidthRight / 2),
|
||||
Y2: y,
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
@ -235,10 +232,10 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
LineWidth: border.borderWidthLeft,
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorLeft,
|
||||
X1: x,
|
||||
Y1: y,
|
||||
X2: x,
|
||||
Y2: y - border.height,
|
||||
X1: x - (border.borderWidthLeft * 2),
|
||||
Y1: y + border.borderWidthTop/2 + (border.borderWidthTop * 2),
|
||||
X2: x - (border.borderWidthLeft * 2),
|
||||
Y2: y - border.height - (border.borderWidthBottom / 2) - (border.borderWidthBottom * 2),
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
contentsLeft, _, err := lineLeft.Draw("")
|
||||
@ -257,9 +254,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorLeft,
|
||||
X1: x,
|
||||
Y1: y,
|
||||
Y1: y + border.borderWidthTop/2,
|
||||
X2: x,
|
||||
Y2: y - border.height,
|
||||
Y2: y - border.height - (border.borderWidthBottom / 2),
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
contentsLeft, _, err := lineLeft.Draw("")
|
||||
@ -282,10 +279,10 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
LineWidth: border.borderWidthRight,
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorRight,
|
||||
X1: x,
|
||||
Y1: y,
|
||||
X2: x,
|
||||
Y2: y - border.height,
|
||||
X1: x + (border.borderWidthRight * 2),
|
||||
Y1: y + border.borderWidthTop/2 + (border.borderWidthTop * 2),
|
||||
X2: x + (border.borderWidthRight * 2),
|
||||
Y2: y - border.height - (border.borderWidthBottom / 2) - (border.borderWidthBottom * 2),
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
contentsRight, _, err := lineRight.Draw("")
|
||||
@ -304,9 +301,9 @@ func (border *border) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext
|
||||
Opacity: 1.0,
|
||||
LineColor: border.borderColorRight,
|
||||
X1: x,
|
||||
Y1: y,
|
||||
Y1: y + border.borderWidthTop/2,
|
||||
X2: x,
|
||||
Y2: y - border.height,
|
||||
Y2: y - border.height - (border.borderWidthBottom / 2),
|
||||
LineStyle: border.LineStyle,
|
||||
}
|
||||
contentsRight, _, err := lineRight.Draw("")
|
||||
|
@ -1627,8 +1627,7 @@ func TestCreatorTableBorderReq1(t *testing.T) {
|
||||
c.Draw(table9)
|
||||
c.Draw(table10)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1643,8 +1642,7 @@ func TestBasicLine(t *testing.T) {
|
||||
c := New()
|
||||
c.Draw(line)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/basic_line.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1660,8 +1658,7 @@ func TestBasicLineWithDash(t *testing.T) {
|
||||
c := New()
|
||||
c.Draw(line)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/basic_line_with_dash.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1688,8 +1685,7 @@ func TestRectangle(t *testing.T) {
|
||||
c.Draw(top)
|
||||
c.Draw(right)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/rectangle.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1700,20 +1696,24 @@ func TestSingleBorder(t *testing.T) {
|
||||
border := newBorder(100, 100, 100, 100)
|
||||
//border.SetFillColor(ColorRed)
|
||||
border.SetColorBottom(ColorRed)
|
||||
border.SetColorTop(ColorRed)
|
||||
border.SetColorLeft(ColorRed)
|
||||
border.SetColorRight(ColorRed)
|
||||
border.SetColorTop(ColorGreen)
|
||||
border.SetColorLeft(ColorBlack)
|
||||
border.SetColorRight(ColorBlue)
|
||||
|
||||
border.SetWidthBottom(1)
|
||||
border.SetWidthTop(1)
|
||||
border.SetWidthLeft(1)
|
||||
border.SetWidthRight(1)
|
||||
border.SetWidthBottom(3)
|
||||
border.SetWidthTop(3)
|
||||
border.SetWidthLeft(3)
|
||||
border.SetWidthRight(3)
|
||||
|
||||
border.StyleTop = CellBorderStyleDoubleTop
|
||||
border.StyleBottom = CellBorderStyleDoubleBottom
|
||||
border.StyleLeft = CellBorderStyleDoubleLeft
|
||||
border.StyleRight = CellBorderStyleDoubleRight
|
||||
|
||||
c := New()
|
||||
c.Draw(border)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/single_border.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
@ -1726,13 +1726,15 @@ func TestCellBorder(t *testing.T) {
|
||||
|
||||
cell1 := table.NewCell()
|
||||
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.Draw(table)
|
||||
|
||||
//err := c.WriteToFile("/tmp/table_border_req1_test.pdf")
|
||||
err := c.WriteToFile("../../testfiles/table.pdf")
|
||||
err := c.WriteToFile("/tmp/cell.pdf")
|
||||
if err != nil {
|
||||
t.Errorf("Fail: %v\n", err)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user