// // CPerimeterMeasureInfoWindowController.swift // Cisdem PDFMaster // // Created by wanjun on 2024/7/16. // import Cocoa protocol CPerimeterMeasureInfoWindowControllerDelegate: AnyObject { func perimeterMeasureInfoWindowControllerSetting(_ perimeterMeasureInfoWindowController: CPerimeterMeasureInfoWindowController) } @objcMembers class CPerimeterMeasureInfoWindowController: NSWindowController { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var scaleTitleLabel: NSTextField! @IBOutlet weak var lengthTitleLabel: NSTextField! @IBOutlet weak var precisionTitleLabel: NSTextField! @IBOutlet weak var angleTitleLabel: NSTextField! @IBOutlet weak var scaleLabel: NSTextField! @IBOutlet weak var lengthLabel: NSTextField! @IBOutlet weak var precisionLabel: NSTextField! @IBOutlet weak var angleLabel: NSTextField! @IBOutlet weak var settingsButton: NSButton! weak var delegate: CPerimeterMeasureInfoWindowControllerDelegate? var measureInfo: CPDFPerimeterMeasureInfo = CPDFPerimeterMeasureInfo() convenience init() { self.init(windowNibName: "CPerimeterMeasureInfoWindowController") } override func windowDidLoad() { super.windowDidLoad() self.window?.level = .floating commonInit() configurationLanguage() } func hideFloatingWindow() { self.window?.orderOut(nil) } private func configurationLanguage() { titleLabel.stringValue = NSLocalizedString("Multilines", comment: "") scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "") lengthTitleLabel.stringValue = NSLocalizedString("Area", comment: "") + ":" precisionTitleLabel.stringValue = NSLocalizedString("Precision", comment: "") + ":" angleTitleLabel.stringValue = NSLocalizedString("Angle", comment: "") + ":" settingsButton.title = NSLocalizedString("Settings", comment: "") } private func commonInit() { scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit) switch measureInfo.precision { case 1: precisionLabel.stringValue = "1" case 10: precisionLabel.stringValue = "0.1" case 100: precisionLabel.stringValue = "0.01" case 1000: precisionLabel.stringValue = "0.001" case 10000: precisionLabel.stringValue = "0.0001" default: break } } func reloadData(with measureInfo: CPDFPerimeterMeasureInfo) { self.measureInfo = measureInfo scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit) let formatValue = measureInfo.formatValue lengthLabel.stringValue = "" if formatValue.count > 4 { let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..