Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 7 additions & 22 deletions Shared/Examples/ExperimentFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,15 @@ class ExperimentFactory: ExampleFactory {
func generateDocument() -> [PDFDocument] {
let document = PDFDocument(format: .a4)

document.add(space: 100)
let table = PDFTable(rows: 50, columns: 4)
table.widths = [0.1, 0.3, 0.3, 0.3]
table.margin = 10
table.padding = 10
table.showHeadersOnEveryPage = false
table.shouldSplitCellsOnPageBreak = false
table.style.columnHeaderCount = 3

for row in 0..<table.size.rows {
table[row, 0].content = "\(row)".asTableContent
for column in 1..<table.size.columns {
table[row, column].content = "\(row),\(column)".asTableContent
}
}

let table = PDFTable(rows: 3, columns: 4)
table.content = [
["0,0", "0,1", "0,2", "0,3"],
["1,0", "1,1", "1,2", "1,3"],
["2,0", "2,1", "2,2", "2,3"],
]
table.rows.allRowsAlignment = [.left, .left, .right, .right]
document.add(table: table)

// let singleCellTable = PDFTable(rows: 1, columns: 1)
// singleCellTable[0,0].content = (0...100).map(String.init)
// .joined(separator: "\n")
// .asTableContent
// document.add(table: singleCellTable)

return [document]
}
}
4 changes: 2 additions & 2 deletions Source/API/Table/Sections/PDFTableRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class PDFTableRow {
}
set {
assert(newValue.count <= cells.count, "Can not access more cells than available")
for (idx, cell) in cells.enumerated() {
for (idx, cell) in cells.enumerated() where idx <= newValue.count - 1 {
cell.style = newValue[idx]
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public class PDFTableRow {
}
set {
assert(newValue.count <= cells.count, "Can not access more cells than available")
for (idx, cell) in cells.enumerated() {
for (idx, cell) in cells.enumerated() where idx <= newValue.count - 1 {
cell.alignment = newValue[idx]
}
}
Expand Down
6 changes: 4 additions & 2 deletions Source/API/Table/Sections/PDFTableRows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ public class PDFTableRows {
fatalError("You cannot read from this object.")
}
set {
assert(newValue.count <= rows.count, "Can not access more rows than available")
rows.forEach { $0.alignment = newValue }
rows.forEach {
assert(newValue.count <= $0.cells.count, "Can not access more columns than available")
$0.alignment = newValue
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions Tests/TPPDFTests/API/Table/Sections/PDFTableRowSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// PDFTableRowSpec.swift
// TPPDF
//
// Created by Philip Niedertscheider on 23.09.20.
//

import Quick
import Nimble
@testable import TPPDF

class PDFTableRowSpec: QuickSpec {

override func spec() {
describe("PDFTableRow") {
describe("alignment") {
it("should set alignment for each row the same") {
let table = PDFTable(rows: 3, columns: 3)
table.rows.allRowsAlignment = [.left, .center, .right]
expect(table.rows.alignment) == [
[.left, .center, .right],
[.left, .center, .right],
[.left, .center, .right]
]
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// PDFTable_RowSubscriptsSpec.swift
// TPPDF
//
// Created by Philip Niedertscheider on 23.09.20.
//

import Quick
import Nimble
@testable import TPPDF

class PDFTable_RowSubscriptsSpec: QuickSpec {

override func spec() {
describe("PDFTable") {
describe("Row Subscripts") {
it("should return row by index") {
let table = PDFTable(rows: 3, columns: 3)
expect(table[row: 1].cells) === table.cells[1]
}
}
}
}
}