Skip to content

Commit

Permalink
Merge pull request #11 from shinjukunian/imageSize
Browse files Browse the repository at this point in the history
image size for nstextattachement
  • Loading branch information
shinjukunian authored Sep 29, 2021
2 parents 6f4e096 + e927eed commit 789a679
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion DocX/NSTextAttachement+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ extension NSTextAttachment{
}

var extentInEMU:Size{
let size=self.dataImageSize
let size:CGSize
if self.bounds != .zero{
size=self.bounds.size
}
else{
size=self.dataImageSize
}

let width=size.width
let height=size.height

Expand Down
22 changes: 22 additions & 0 deletions DocXTests/DocXTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,28 @@ Specifies the border displayed above a set of paragraphs which have the same set



func testLenna_size() throws{
let longString = """
1. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum\r.
"""
let imageURL=URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("lenna.png")
let imageData=try XCTUnwrap(Data(contentsOf: imageURL), "Image not found")
let attachement=NSTextAttachment(data: imageData, ofType: kUTTypePNG as String)
attachement.bounds=CGRect(x: 0, y: 0, width: 128, height: 128)

let attributed=NSMutableAttributedString(string: longString, attributes: [:])
// attributed.addAttributes([.link:URL(string: "http://officeopenxml.com/index.php")!], range: NSRange(location: 2, length: 6))
let imageString=NSAttributedString(attachment: attachement)
let result=NSMutableAttributedString()
result.append(attributed)
result.append(imageString)
result.append(attributed)
// result.append(attributed)
testWriteDocX(attributedString: result, useBuiltin: false)
}



// @available(macOS 12, *)
// func testAttributed(){
// var att=AttributedString("Lorem ipsum dolor sit amet")
Expand Down
Binary file added DocXTests/lenna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let package = Package(
dependencies: ["DocX"],
path: "DocXTests",
exclude: ["Info.plist"],
resources: [.copy("blank.docx"), .copy("Picture1.png")]
resources: [.copy("blank.docx"), .copy("Picture1.png"), .copy("lenna.png")]
),

.testTarget(
Expand Down

0 comments on commit 789a679

Please sign in to comment.