Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimentally support practical size specification such as A4, B0, introducing PdfSize. #48

Merged
merged 4 commits into from
Dec 3, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
test:
name: "Build Csv2ImgCmd"
runs-on: macos-12
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: maxim-lobanov/setup-xcode@v1
Expand Down
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Csv2ImgCmd.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-n https://raw.githubusercontent.com/fummicc1/csv2img/main/Fixtures/sample_1.csv"
argument = "-n https://raw.githubusercontent.com/fummicc1/csv2img/main/Fixtures/yolov5x6.csv"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
Expand Down
34 changes: 27 additions & 7 deletions Sources/Csv2Img/Csv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@ public actor Csv {
///
/// `separator` is applied to each row and generate items per row.
/// `columns` is array of column whose type is ``Column``.
/// `Row` is array of row whose type is ``Row``
/// `rows` is array of row whose type is ``Row``
/// `exportType` is value of ``ExportType`` with default value `png`.
/// `pdfMetadata` is value of ``PDFMetadata`` with default value `nil`.
public init(
separator: String=",",
rawString: String? = nil,
encoding: String.Encoding = .utf8,
columns: [Csv.Column] = [],
rows: [Csv.Row] = [],
exportType: ExportType = .png
exportType: ExportType = .png,
pdfMetadata: PDFMetadata? = nil
) {
self.imageMarker = ImageMaker(
maximumRowCount: maximumRowCount,
fontSize: 12
)
self.pdfMetadata = pdfMetadata ?? PDFMetadata(
author: "Author",
title: "Title",
size: .a4,
orientation: .portrait
)
self.pdfMarker = PdfMaker(
maximumRowCount: maximumRowCount,
fontSize: 12,
metadata: PDFMetadata(
author: "Author",
title: "Title"
)
metadata: self.pdfMetadata
)
self.encoding = encoding
self.separator = separator
Expand Down Expand Up @@ -130,7 +136,14 @@ public actor Csv {

/// `exportType` determines export type. Please choose ``ExportType.png`` or ``ExportType.pdf``.
public var exportType: ExportType


/// `pdfMetadata` stores pdf metadata which is used when ``Csv2Img.Csv.ExportType`` is `.png`
private var pdfMetadata: PDFMetadata {
didSet {
pdfMarker.set(metadata: pdfMetadata)
}
}

/// ``maximumRowCount`` is the max number of Rows. this is fixed due to performance issue.
private let maximumRowCount: Int? = nil

Expand Down Expand Up @@ -627,4 +640,11 @@ extension Csv {
return nil
}
}

/**
- set ``PdfMetadata``
*/
public func update(pdfMetadata: PDFMetadata) {
self.pdfMetadata = pdfMetadata
}
}
25 changes: 18 additions & 7 deletions Sources/Csv2Img/PDFMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ import Foundation

/// ``PDFMetadata`` is a struct which stores Metadata about output-pdf.
public struct PDFMetadata {

/// `author`. author of document.
public var author: String?
/// `title`. title of document.
public var title: String?

/**
- specify output pdf size with ``PdfSize``.
*/
public var size: PdfSize?
public var orientation: PdfSize.Orientation?

public init(
author: String,
title: String
author: String? = nil,
title: String? = nil,
size: PdfSize? = nil,
orientation: PdfSize.Orientation? = nil
) {
self.author = author
self.title = title
self.size = size
self.orientation = orientation
}

/// `author`. author of document.
public var author: String
/// `title`. title of document.
public var title: String
}
Loading