|
@@ -31,11 +31,7 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
|
|
|
|
private var familyNames = CPDFFont.familyNames
|
|
private var familyNames = CPDFFont.familyNames
|
|
|
|
|
|
- var pdfView: CPDFListView? {
|
|
|
|
- didSet {
|
|
|
|
- reloadData()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ var pdfView: CPDFListView?
|
|
|
|
|
|
var currentArea: CPDFEditTextArea?
|
|
var currentArea: CPDFEditTextArea?
|
|
|
|
|
|
@@ -70,6 +66,7 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
}
|
|
}
|
|
fontTitleSelect.updateMenuItemsArr(menuItemArr)
|
|
fontTitleSelect.updateMenuItemsArr(menuItemArr)
|
|
}
|
|
}
|
|
|
|
+ fontTitleSelect.delegate = self
|
|
|
|
|
|
fontTitleButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, icon: NSImage(named: "toolbar_more"))
|
|
fontTitleButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, icon: NSImage(named: "toolbar_more"))
|
|
fontTitleButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
fontTitleButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
@@ -96,7 +93,8 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
state: .normal,
|
|
state: .normal,
|
|
creatable: true,
|
|
creatable: true,
|
|
text: "12 pt",
|
|
text: "12 pt",
|
|
- regexString: "0123456789 pt")
|
|
|
|
|
|
+ textUnit: " pt",
|
|
|
|
+ regexString: "0123456789")
|
|
if true {
|
|
if true {
|
|
var sizeItemArr: [ComponentMenuitemProperty] = []
|
|
var sizeItemArr: [ComponentMenuitemProperty] = []
|
|
for string in KMHeaderFooterManager.getFontSize() {
|
|
for string in KMHeaderFooterManager.getFontSize() {
|
|
@@ -131,6 +129,7 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
colorGroup.delegate = self
|
|
colorGroup.delegate = self
|
|
|
|
|
|
colorSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
|
|
colorSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
|
|
|
|
+ colorSlider.delegate = self
|
|
|
|
|
|
colorOpacitySelect.properties = ComponentSelectProperties(size: .s,
|
|
colorOpacitySelect.properties = ComponentSelectProperties(size: .s,
|
|
state: .normal,
|
|
state: .normal,
|
|
@@ -160,15 +159,87 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
}
|
|
}
|
|
|
|
|
|
if let area = currentArea {
|
|
if let area = currentArea {
|
|
- let fontName = pdfView?.km_editTextAreasFontNames([area])
|
|
|
|
- let fontStyle = pdfView?.km_editTextAreasFontStyles([area])
|
|
|
|
- let fontSize = pdfView?.km_editTextAreasFontSizes([area])
|
|
|
|
- let bold = pdfView?.km_editTextAreasFontBolds([area])
|
|
|
|
- let itality = pdfView?.km_editTextAreasFontItalics([area])
|
|
|
|
- let alignment = pdfView?.km_editTextAreasTextAlignments([area])
|
|
|
|
- let colors = pdfView?.km_editTextAreasFontColors([area])
|
|
|
|
- let opacity = pdfView?.km_editAreasOpacitys([area])
|
|
|
|
- print("1")
|
|
|
|
|
|
+ if let fontNames = pdfView?.km_editTextAreasFontNames([area]) {
|
|
|
|
+ if let fontName = fontNames.first {
|
|
|
|
+ fontNameSelect.properties.text = fontName
|
|
|
|
+ fontNameSelect.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let fontStyles = pdfView?.km_editTextAreasFontStyles([area]) {
|
|
|
|
+ var styles: [String] = []
|
|
|
|
+ if let fontStyle = fontStyles.first, fontStyle.isEmpty == false {
|
|
|
|
+ styles = fontStyles
|
|
|
|
+
|
|
|
|
+ fontStyleSelect.properties.text = fontStyle
|
|
|
|
+ } else {
|
|
|
|
+ if let name = fontNameSelect.properties.text {
|
|
|
|
+ styles = CPDFFont.fontNames(forFamilyName: name)
|
|
|
|
+ if styles.isEmpty == true {
|
|
|
|
+ styles.append("Regular")
|
|
|
|
+ fontStyleSelect.properties.text = "Regular"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fontStyleSelect.reloadData()
|
|
|
|
+
|
|
|
|
+ var menuItemArr: [ComponentMenuitemProperty] = []
|
|
|
|
+ for string in styles {
|
|
|
|
+ let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: string)
|
|
|
|
+ menuItemArr.append(item)
|
|
|
|
+ }
|
|
|
|
+ fontStyleSelect.updateMenuItemsArr(menuItemArr)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let fontSizes = pdfView?.km_editTextAreasFontSizes([area]) {
|
|
|
|
+ if let fontSize = fontSizes.first {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let bolds = pdfView?.km_editTextAreasFontBolds([area]) {
|
|
|
|
+ if let bold = bolds.first {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let italitys = pdfView?.km_editTextAreasFontItalics([area]) {
|
|
|
|
+ if let itality = italitys.first {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if let alignments = pdfView?.km_editTextAreasTextAlignments([area]) {
|
|
|
|
+ if let alignment = alignments.first {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let colors = pdfView?.km_editTextAreasFontColors([area]) {
|
|
|
|
+ if let color = colors.first {
|
|
|
|
+ colorGroup.currentColor = color
|
|
|
|
+ } else {
|
|
|
|
+ colorGroup.currentColor = NSColor.clear
|
|
|
|
+ }
|
|
|
|
+ colorGroup.refreshUI()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if let opacitys = pdfView?.km_editAreasOpacitys([area]) {
|
|
|
|
+ if var opacity = opacitys.first {
|
|
|
|
+ opacity = min(1, opacity)
|
|
|
|
+ opacity = max(0, opacity)
|
|
|
|
+
|
|
|
|
+ colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
|
|
|
|
+ colorOpacitySelect.reloadData()
|
|
|
|
+
|
|
|
|
+ colorSlider.properties.percent = opacity
|
|
|
|
+ colorSlider.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -182,10 +253,69 @@ class KMEditPDFTextPropertyViewController: NSViewController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+//MARK: - ComponentSelectDelegate
|
|
extension KMEditPDFTextPropertyViewController: ComponentSelectDelegate {
|
|
extension KMEditPDFTextPropertyViewController: ComponentSelectDelegate {
|
|
|
|
+ func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
|
|
|
|
+ if view == fontTitleSelect {
|
|
|
|
+
|
|
|
|
+ } else if view == fontNameSelect {
|
|
|
|
+ if let fontName = menuItemProperty?.text {
|
|
|
|
+ var cFont = CPDFFont.mappingFont(withFontString: fontName)
|
|
|
|
+ var styles = CPDFFont.fontNames(forFamilyName: fontName)
|
|
|
|
+ if styles.isEmpty == false, let style = styles.first {
|
|
|
|
+ cFont = CPDFFont.init(familyName: fontName, fontStyle: style)
|
|
|
|
+ }
|
|
|
|
+ if let cFont = cFont {
|
|
|
|
+ pdfView?.setEditingTextarea_font(font: cFont)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if view == fontStyleSelect {
|
|
|
|
+
|
|
|
|
+ } else if view == fontSizeSelect {
|
|
|
|
+ if let text = menuItemProperty?.text {
|
|
|
|
+ let result = text.stringByDeleteCharString(" pt")
|
|
|
|
+ let fontSize = result.stringToCGFloat()
|
|
|
|
+ pdfView?.setEditingTextarea_FontSize(size: fontSize)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ reloadData()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ func componentSelectTextDidEndEditing(_ view: ComponentSelect) {
|
|
|
|
+ if view == fontSizeSelect {
|
|
|
|
+ if let string = view.properties.text {
|
|
|
|
+ let result = string.stringByDeleteCharString(" pt")
|
|
|
|
+ let size = result.stringToCGFloat()
|
|
|
|
+ let fontSize = max(size, 100)
|
|
|
|
+
|
|
|
|
+ pdfView?.setEditingTextarea_FontSize(size: fontSize)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ reloadData()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//MARK: - ComponentCColorDelegate
|
|
extension KMEditPDFTextPropertyViewController: ComponentCColorDelegate {
|
|
extension KMEditPDFTextPropertyViewController: ComponentCColorDelegate {
|
|
-
|
|
|
|
|
|
+ func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
|
|
|
|
+ if view == colorGroup {
|
|
|
|
+ pdfView?.changeEditingTextarea_Color(color: color)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//MARK: - ComponentSliderDelegate
|
|
|
|
+extension KMEditPDFTextPropertyViewController: ComponentSliderDelegate {
|
|
|
|
+ func componentSliderDidUpdate(_ view: ComponentSlider) {
|
|
|
|
+ let percent = view.properties.percent
|
|
|
|
+
|
|
|
|
+ self.pdfView?.setEditingAreasOpacity(percent)
|
|
|
|
+
|
|
|
|
+ reloadData()
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|