-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sboh1214/dev
release to master branch 0.1.0
- Loading branch information
Showing
46 changed files
with
660 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- master | ||
|
||
jobs: | ||
test: | ||
coverage: | ||
|
||
runs-on: macos-latest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- master | ||
|
||
jobs: | ||
build: | ||
documentation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
|
||
public enum HwpError: Error { | ||
case invalidFilePath(path: String) | ||
case streamDoesNotExist(name: HwpStreamName) | ||
case streamDecompressFailed(name: HwpStreamName) | ||
case invalidDataForString(data: Data, name: String) | ||
case recordDoesNotExist(tag: UInt32) | ||
case invalidFileHeaderSignature(signature: String) | ||
case unidentifiedTag(tagId: UInt32) | ||
} | ||
|
||
extension HwpError: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case let .invalidFilePath(path): | ||
return "Invalid File Path '\(path)'" | ||
case let .streamDoesNotExist(name): | ||
return "Stream '\(name)' does not exist" | ||
case let .streamDecompressFailed(name): | ||
return "Stream '\(name)' failed to decompress" | ||
case let .invalidDataForString(data, name): | ||
return | ||
""" | ||
Cannot covert data to utf16le string | ||
data: '\(data)' | ||
name: '\(name)' | ||
""" | ||
case let .recordDoesNotExist(tag): | ||
return "Record '\(tag)' does not exist." | ||
case let .invalidFileHeaderSignature(signature): | ||
return "Invalid signature in FileHeader stream : get'\(signature)'" | ||
case let .unidentifiedTag(tagId): | ||
return "Cannot Read HwpRecord Tag : '\(tagId)'" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,71 @@ | ||
import Foundation | ||
import OLEKit | ||
import DataCompression | ||
|
||
public struct HwpFile { | ||
let fileHeader: HwpFileHeader | ||
//let previewText : HKPreviewText | ||
var directories: [DirectoryEntry] = [] | ||
public class HwpFile { | ||
public let fileHeader: HwpFileHeader | ||
public let docInfo: HwpDocInfo | ||
public let previewText: HwpPreviewText | ||
|
||
var warnings: [HwpWarning] = [] | ||
|
||
init(filePath: String) throws { | ||
public init(filePath: String) throws { | ||
let ole: OLEFile | ||
do { | ||
ole = try OLEFile(filePath) | ||
} catch { | ||
throw HwpError.invalidFilePath(path: filePath) | ||
} | ||
let streams = Dictionary(uniqueKeysWithValues: ole.root.children.map { ($0.name, $0 ) }) | ||
let test = Test(ole, streams) | ||
|
||
do { | ||
guard let fileHeaderStream = ole.root.children.first(where: { $0.name == HwpStreamName.fileHeader.rawValue }) else { | ||
throw HwpError.streamDoesNotExist(name: HwpStreamName.fileHeader) | ||
} | ||
fileHeader = HwpFileHeader(dataReader: try ole.stream(fileHeaderStream)) | ||
|
||
} catch { | ||
throw HwpError.invalidFilePath(path: filePath) | ||
} | ||
fileHeader = try HwpFileHeader(test.getDataFromStream(.fileHeader, false)) | ||
|
||
docInfo = try HwpDocInfo(test.getDataFromStream(.docInfo, fileHeader.isCompressed)) | ||
|
||
// do { | ||
// guard let previewTextStream = ole.root.children.first(where: {$0.name == HKStreamName.PreviewText.rawValue}) else { | ||
// throw HKError.StreamDoesNotExist(name: HKStreamName.PreviewText) | ||
// } | ||
// previewText = HKPreviewText(dataReader: try ole.stream(previewTextStream)) | ||
// } | ||
guard let previewTextStream = streams[HwpStreamName.previewText.rawValue] else { | ||
throw HwpError.streamDoesNotExist(name: HwpStreamName.previewText) | ||
} | ||
let previewTextReader = try ole.stream(previewTextStream) | ||
previewText = try HwpPreviewText(previewTextReader.readDataToEnd()) | ||
} | ||
|
||
func report(report: inout HwpReportable) throws -> Void { | ||
|
||
|
||
} | ||
|
||
fileprivate struct Test { | ||
private let ole: OLEFile | ||
private let streams: [String: DirectoryEntry] | ||
|
||
init(_ ole: OLEFile, _ streams: [String: DirectoryEntry]) { | ||
self.ole = ole | ||
self.streams = streams | ||
} | ||
|
||
fileprivate func getDataFromStream(_ streamName: HwpStreamName, _ isCompressed: Bool) throws -> Data { | ||
guard let stream = streams[streamName.rawValue] else { | ||
throw HwpError.streamDoesNotExist(name: streamName) | ||
} | ||
let reader = try ole.stream(stream) | ||
let data = reader.readDataToEnd() | ||
if isCompressed { | ||
if #available(OSX 10.15, *) { | ||
return try (data as NSData).decompressed(using: .zlib) as Data | ||
} else { | ||
guard let decompressedData = data.decompress(withAlgorithm: .zlib) else { | ||
throw HwpError.streamDecompressFailed(name: streamName) | ||
} | ||
return decompressedData | ||
} | ||
|
||
} else { | ||
return data | ||
} | ||
} | ||
} | ||
|
||
public enum HwpStreamName: String { | ||
case fileHeader = "FileHeader" | ||
case docInfo = "DocInfo" | ||
case summary = "\005HwpSummaryInformation" | ||
case previewText = "PrvText" | ||
case previewImage = "PrvImage" | ||
} |
14 changes: 14 additions & 0 deletions
14
Sources/HwpKit/Models/Document Properties/HwpCaratLocation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
public struct HwpCaratLocation: HwpData { | ||
let listId: UInt32 | ||
let paragraphId: UInt32 | ||
let charIndex: UInt32 | ||
|
||
init(_ data: Data) { | ||
var reader = DataReader(data) | ||
listId = reader.readUInt32() | ||
paragraphId = reader.readUInt32() | ||
charIndex = reader.readUInt32() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Sources/HwpKit/Models/Document Properties/HwpDocumentProperties.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
public struct HwpDocumentProperties: HwpData { | ||
public let sectionSize: UInt16 | ||
public let startingIndex: HwpStartingIndex | ||
public let caratLocation: HwpCaratLocation | ||
|
||
init(_ data: Data) { | ||
var reader = DataReader(data) | ||
sectionSize = reader.readUInt16() | ||
startingIndex = HwpStartingIndex(reader.readBytes(12)) | ||
caratLocation = HwpCaratLocation(reader.readBytes(12)) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Sources/HwpKit/Models/Document Properties/HwpStartingIndex.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
public struct HwpStartingIndex: HwpData { | ||
public let page: UInt16 | ||
public let footnote: UInt16 | ||
public let endnote: UInt16 | ||
public let picture: UInt16 | ||
public let table: UInt16 | ||
public let equation: UInt16 | ||
|
||
init(_ data: Data) { | ||
var reader = DataReader(data) | ||
page = reader.readUInt16() | ||
footnote = reader.readUInt16() | ||
endnote = reader.readUInt16() | ||
picture = reader.readUInt16() | ||
table = reader.readUInt16() | ||
equation = reader.readUInt16() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import Foundation | ||
|
||
struct HwpVersion { | ||
let major: UInt8 | ||
let minor: UInt8 | ||
let build: UInt8 | ||
let revision: UInt8 | ||
/** | ||
파일 버전. 0xMMnnPPrr의 형태(예 5.0.3.0) | ||
- MM: 문서 형식의 구조가 완전히 바뀌는 것을 나타냄. 숫 | ||
자가 다르면 구 버전과 호환 불가능. | ||
- nn: 큰 구조는 동일하나, 큰 변화가 있는 것을 나타냄. 숫 | ||
자가 다르면 구 버전과 호환 불가능. | ||
- PP: 구조는 동일, Record가 추가되었거나, 하위 버전에서 | ||
호환되지 않는 정보가 추가된 것을 나타냄. 숫자가 달라도 | ||
구 버전과 호환 가능. | ||
- rr: Record에 정보들이 추가된 것을 나타냄. 숫자가 달라 | ||
도 구 버전과 호환 가능. | ||
*/ | ||
public struct HwpVersion: HwpData { | ||
public let major: UInt8 | ||
public let minor: UInt8 | ||
public let build: UInt8 | ||
public let revision: UInt8 | ||
|
||
init(_ data: Data) { | ||
var reader = DataReader(data) | ||
revision = reader.readUInt8() | ||
build = reader.readUInt8() | ||
minor = reader.readUInt8() | ||
major = reader.readUInt8() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.