Skip to content

add support for typeQDRectangle #2

@ronzo99

Description

@ronzo99

Similar to the proposed solution to issue #1:

public func unpackAsQDRectangle(_ descriptor: Descriptor) throws -> [Int] {
	
	struct QDRectangle { // derived from MacTypes.h
		var top: Int16
		var left: Int16
		var bottom: Int16
		var right: Int16
	}

	guard descriptor.data.count == MemoryLayout<Int16>.size * 4 else { throw AppleEventError.corruptData }

	let theRect: QDRectangle = descriptor.data.withUnsafeBytes { buffer in
		buffer.bindMemory(to: QDRectangle.self)[0]
	}

	let top 		= Int(Int16(bigEndian: theRect.top))
	let left 	= Int(Int16(bigEndian: theRect.left))
	let bottom 	= Int(Int16(bigEndian: theRect.bottom))
	let right 	= Int(Int16(bigEndian: theRect.right))

	// AppleScript returns {left, top, right, bottom}
	return [left, top, right, bottom]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions