GithubHelp home page GithubHelp logo

Comments (2)

ozitrance avatar ozitrance commented on August 11, 2024 2

@nico75005 It worked perfectly ... 👍 Thank you so much!!!

from simplepdf.

nico75005 avatar nico75005 commented on August 11, 2024 1

It's not used at all. You can replace the content of the method line 302 in SimplePDF.swift

fileprivate func drawTable(rowCount: Int, alignment: ContentAlignment, columnCount: Int, rowHeight: CGFloat, columnWidth: CGFloat?, tableLineWidth: CGFloat, font: UIFont?, tableDefinition:TableDefinition?, dataArray: Array<Array<String>>, currentOffset: CGPoint) -> CGRect

with this:

fileprivate func drawTable(rowCount: Int, alignment: ContentAlignment, columnCount: Int, rowHeight: CGFloat, columnWidth: CGFloat?, tableLineWidth: CGFloat, font: UIFont?, tableDefinition:TableDefinition?, dataArray: Array<Array<String>>, currentOffset: CGPoint) -> CGRect {
        
        let height = (CGFloat(rowCount)*rowHeight)
        
        let drawRect = CGRect(x: currentOffset.x, y: currentOffset.y, width: pageBounds.width - pageMarginLeft - pageMarginRight, height: height)
        
        UIColor.black.setStroke()
        UIColor.black.setFill()
        
        let tableWidth = { () -> CGFloat in
            if let cws = tableDefinition?.columnWidths {
                return cws.reduce(0, { (result, current) -> CGFloat in
                    return result + current
                })
            } else if let cw = columnWidth {
                return CGFloat(columnCount) * cw
            }
            
            return 0 // default which should never be use, because either columnWidth, or columnsWidths is set
        }()
        
        for i in 0...rowCount {
            let newOrigin = drawRect.origin.y + rowHeight*CGFloat(i)
            
            
            
            let from = CGPoint(x: drawRect.origin.x, y: newOrigin)
            let to = CGPoint(x: drawRect.origin.x + tableWidth, y: newOrigin)
            
            drawLineFromPoint(from, to: to, lineWidth: tableLineWidth)
        }
        
        for i in 0...columnCount {
            let currentOffset = { () -> CGFloat in
                if let cws = tableDefinition?.columnWidths {
                    var offset:CGFloat = 0
                    for x in 0..<i {
                        offset += cws[x]
                    }
                    return offset
                } else if let cw = columnWidth {
                    return cw * CGFloat(i)
                }
                
                return 0 // default which should never be use, because either columnWidth, or columnsWidths is set
            }()
            
            let newOrigin = drawRect.origin.x + currentOffset
            
            let from = CGPoint(x: newOrigin, y: drawRect.origin.y)
            let to = CGPoint(x: newOrigin, y: drawRect.origin.y + CGFloat(rowCount)*rowHeight)
            
            drawLineFromPoint(from, to: to, lineWidth: tableLineWidth)
        }
        
        for i in 0..<rowCount {
            for j in 0...columnCount-1 {
                let currentOffset = { () -> CGFloat in
                    if let cws = tableDefinition?.columnWidths {
                        var offset:CGFloat = 0
                        for x in 0..<j {
                            offset += cws[x]
                        }
                        return offset
                    } else if let cw = columnWidth {
                        return cw * CGFloat(j)
                    }
                    
                    return 0 // default which should never be use, because either columnWidth, or columnsWidths is set
                }()
                
                let newOriginX = drawRect.origin.x + currentOffset
                let newOriginY = drawRect.origin.y + ((CGFloat(i)*rowHeight))
                
				let currentAlignment = { () -> ContentAlignment in
					if let a = tableDefinition?.alignments {
						if (a.count > j){
							return a[j]
						}
					} else {
						return alignment
					}

					return .left
				}()

				let currentFont = { () -> UIFont in
                    if let f = tableDefinition?.fonts {
                        if (f.count > j){
                            return f[j]
                        }
                    } else if let f = font {
                        return f
                    }
                    
                    return UIFont.systemFont(ofSize: UIFont.systemFontSize)
                }()
                
                let currentTextColor = { () -> UIColor in
                    if let t = tableDefinition?.textColors {
                        if t.count > j {
                            return t[j]
                        }
                    }
                    
                    return UIColor.black
                }()
                
                let currentColumnWidth = { () -> CGFloat in
                    if let cw = tableDefinition?.columnWidths {
                        if cw.count > j {
                            return cw[j]
                        }
                    } else if let cw = columnWidth {
                        return cw
                    }
                    
                    return 100 // default which should never be use, because either columnWidth, or columnsWidths is set
                }()
                
                let frame = CGRect(x: newOriginX, y: newOriginY, width: currentColumnWidth, height: rowHeight)
                drawTextInCell(frame, text: dataArray[i][j] as NSString, alignment: currentAlignment, font: currentFont, textColor: currentTextColor)
            }
        }
        
        return drawRect
    }

from simplepdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.