From 243be8720a50a04da9d916cc72a1daefa695479b Mon Sep 17 00:00:00 2001 From: Adrian-George Bostan Date: Mon, 24 Sep 2018 20:11:02 +0300 Subject: [PATCH] Change division component test to include styled paragraphs --- pdf/creator/division_test.go | 69 +++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/pdf/creator/division_test.go b/pdf/creator/division_test.go index e372263a..6faf3fbf 100644 --- a/pdf/creator/division_test.go +++ b/pdf/creator/division_test.go @@ -58,6 +58,17 @@ func TestDivVertical(t *testing.T) { p.SetFont(fontBold) div.Add(p) + // Add styled paragraph + style := NewTextStyle() + style.Color = ColorRGBFrom8bit(0, 0, 255) + + s := NewStyledParagraph("Not even with a styled ", style) + + style.Color = ColorRGBFrom8bit(255, 0, 0) + s.Append("paragraph", style) + + div.Add(s) + err = c.Draw(div) if err != nil { t.Fatalf("Error drawing: %v", err) @@ -110,11 +121,26 @@ func TestDivInline(t *testing.T) { p.SetFont(fontRegular) div.Add(p) - p = NewParagraph("This one did not fit in the available line space") + p = NewParagraph("This one did not fit in the available line space. ") p.SetEnableWrap(false) p.SetFont(fontBold) div.Add(p) + // Add styled paragraph + style := NewTextStyle() + style.Color = ColorRGBFrom8bit(0, 0, 255) + + s := NewStyledParagraph("This styled paragraph should ", style) + + style.Color = ColorRGBFrom8bit(255, 0, 0) + s.Append("fit", style) + + style.Color = ColorRGBFrom8bit(0, 255, 0) + style.Font = fontBold + s.Append(" right in.", style) + + div.Add(s) + err = c.Draw(div) if err != nil { t.Fatalf("Error drawing: %v", err) @@ -199,26 +225,43 @@ func TestDivRandomSequences(t *testing.T) { div := NewDivision() div.SetInline(true) - for i := 0; i < 250; i++ { + style := NewTextStyle() + + for i := 0; i < 350; i++ { r := byte(seed.Intn(200)) g := byte(seed.Intn(200)) b := byte(seed.Intn(200)) word := RandString(seed.Intn(10)+5) + " " - fontSize := float64(14 + seed.Intn(3)) - - p := NewParagraph(word) - p.SetEnableWrap(false) - p.SetColor(ColorRGBFrom8bit(r, g, b)) - p.SetFontSize(fontSize) + fontSize := float64(11 + seed.Intn(3)) if seed.Intn(2)%2 == 0 { - p.SetFont(fontBold) - } else { - p.SetFont(fontRegular) - } + p := NewParagraph(word) + p.SetEnableWrap(false) + p.SetColor(ColorRGBFrom8bit(r, g, b)) + p.SetFontSize(fontSize) - div.Add(p) + if seed.Intn(2)%2 == 0 { + p.SetFont(fontBold) + } else { + p.SetFont(fontRegular) + } + + div.Add(p) + } else { + style.Color = ColorRGBFrom8bit(r, g, b) + style.FontSize = fontSize + + if seed.Intn(2)%2 == 0 { + style.Font = fontBold + } else { + style.Font = fontRegular + } + + s := NewStyledParagraph(word, style) + s.SetEnableWrap(false) + div.Add(s) + } } err = c.Draw(div)