Browse Source

PDFTools(iOS) - 编辑模块回调、属性处理

chenyu 1 year ago
parent
commit
cc2e8bc573

+ 3 - 0
compdfkit-demo.xcworkspace/contents.xcworkspacedata

@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Workspace
    version = "1.0">
+   <FileRef
+      location = "group:Edit-Ctrl-Demo/Edit-Ctrl-Demo.xcodeproj">
+   </FileRef>
    <FileRef
       location = "group:Annotation-Ctrl-Demo/Annotation-Ctrl-Demo.xcodeproj">
    </FileRef>

+ 8 - 0
compdfkit-tools/compdfkit-tools/Edit/CPDFEditCell/CPDFTextPropertyCell.h

@@ -9,12 +9,20 @@
 
 #import <UIKit/UIKit.h>
 
+
+typedef NS_ENUM(NSUInteger, CPDFTextActionType) {
+    CPDFTextActionColorSelect,
+    CPDFTextActionFontNameSelect
+};
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface CPDFTextPropertyCell : UITableViewCell
 
 +(instancetype)CPDFTextPropertyCell;
 
+@property (nonatomic, strong) void(^actionBlock)(CPDFTextActionType actionType);
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 56 - 0
compdfkit-tools/compdfkit-tools/Edit/CPDFEditCell/CPDFTextPropertyCell.m

@@ -11,12 +11,19 @@
 #import "CPDFTextPropertyCell.h"
 #import "CPDFColorSelectView.h"
 #import "CPDFOpacitySliderView.h"
+#import "CPDFColorPickerView.h"
 
 @interface CPDFTextPropertyCell()<CPDFColorSelectViewDelegate>
 @property (weak, nonatomic) IBOutlet UIView *colorAreaView;
 @property (nonatomic, strong) CPDFColorSelectView * colorView;
 @property (weak, nonatomic) IBOutlet UIView *sliderArea;
 @property (nonatomic, strong) CPDFOpacitySliderView * opacityView;
+@property (nonatomic, strong) CPDFColorPickerView * colorPickerView;
+
+@property (weak, nonatomic) IBOutlet UIButton *leftAlignBtn;
+@property (weak, nonatomic) IBOutlet UIButton *centerAlignBtn;
+@property (weak, nonatomic) IBOutlet UIButton *rightAlignBtn;
+
 
 @end
 
@@ -34,6 +41,7 @@
     if(!self.colorView){
         self.colorView  = [[CPDFColorSelectView alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width-20, 90)];
         self.colorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+        self.colorView.colorLabel.text = NSLocalizedString(@"Font Color:", nil);
         self.colorView.delegate = self;
         [self.colorAreaView addSubview:self.colorView];
     }
@@ -42,8 +50,12 @@
     if(!self.opacityView){
         self.opacityView = [[CPDFOpacitySliderView alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width-20, 90)];
         self.opacityView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+        self.opacityView.titleLabel.text = NSLocalizedString(@"Font Size:", nil);
+        self.opacityView.startLabel.text = @"0";
+        self.opacityView.endLabel.text = @"100";
         [self.sliderArea addSubview:self.opacityView];
     }
+    
 }
 
 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
@@ -53,6 +65,50 @@
 }
 
 #pragma mark - CPDFColorSelectViewDelegate
+- (void)selectColorView:(CPDFColorSelectView *)select {
+    if(self.actionBlock){
+        self.actionBlock(CPDFTextActionColorSelect);
+    }
+}
+
+- (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
+}
+
+#pragma mark - Action
+
+- (IBAction)fontBoldAction:(UIButton *)sender {
+    sender.selected = !sender.selected;
+}
+
+- (IBAction)fontItalicAction:(UIButton *)sender {
+    sender.selected = !sender.selected;
+}
+
+- (IBAction)fontAlignmentAction:(UIButton *)sender {
+    sender.selected = !sender.selected;
+    
+    if(sender == self.leftAlignBtn && sender.isSelected){
+        [self.centerAlignBtn setSelected:NO];
+        [self.rightAlignBtn setSelected:NO];
+    }
+    
+    if(sender == self.centerAlignBtn && sender.isSelected){
+        [self.rightAlignBtn setSelected:NO];
+        [self.leftAlignBtn setSelected:NO];
+    }
+    
+    if(sender == self.rightAlignBtn && sender.isSelected){
+        [self.leftAlignBtn setSelected:NO];
+        [self.centerAlignBtn setSelected:NO];
+    }
+}
+
+- (IBAction)showFontNameAction:(UIButton *)sender {
+    if(self.actionBlock){
+        self.actionBlock(CPDFTextActionFontNameSelect);
+    }
+}
+
 
 
 @end

+ 36 - 6
compdfkit-tools/compdfkit-tools/Edit/CPDFEditCell/CPDFTextPropertyCell.xib

@@ -34,6 +34,9 @@
                         <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                         <state key="normal" title="Button" image="CPDFEditItalicNormal"/>
                         <state key="selected" image="CPDFEditItalicHighlight"/>
+                        <connections>
+                            <action selector="fontItalicAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="jb1-qR-BcM"/>
+                        </connections>
                     </button>
                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Align Style:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lXb-G8-H3F">
                         <rect key="frame" x="10" y="175" width="85.333333333333329" height="21"/>
@@ -41,7 +44,7 @@
                         <nil key="textColor"/>
                         <nil key="highlightedColor"/>
                     </label>
-                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SQc-1y-yHE">
+                    <button opaque="NO" tag="102" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SQc-1y-yHE">
                         <rect key="frame" x="328" y="175.66666666666666" width="20" height="20"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="20" id="Cvz-Nz-wH1"/>
@@ -50,18 +53,27 @@
                         <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                         <state key="normal" image="CPDFEditAlignmentRight"/>
                         <state key="selected" image="CPDFEditAlignmentRightH"/>
+                        <connections>
+                            <action selector="fontAlignmentAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="V70-hN-tcV"/>
+                        </connections>
                     </button>
-                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VsT-rp-W0E">
+                    <button opaque="NO" tag="101" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VsT-rp-W0E">
                         <rect key="frame" x="279" y="174.66666666666666" width="29" height="22"/>
                         <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                         <state key="normal" title="U" image="CPDFEditAligmentCenter"/>
                         <state key="selected" image="CPDFEditAligmentCenterH"/>
+                        <connections>
+                            <action selector="fontAlignmentAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="fM6-cf-4BE"/>
+                        </connections>
                     </button>
-                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="n1n-vD-767">
+                    <button opaque="NO" tag="100" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="n1n-vD-767">
                         <rect key="frame" x="230" y="174.66666666666666" width="29" height="22"/>
                         <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                         <state key="normal" title="U" image="CPDFEditAlignmentLeft"/>
                         <state key="selected" image="CPDFEditAlignmentLeftHigh"/>
+                        <connections>
+                            <action selector="fontAlignmentAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="MQz-uS-uX9"/>
+                        </connections>
                     </button>
                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ohh-qk-Inu">
                         <rect key="frame" x="0.0" y="215.66666666666663" width="358" height="90"/>
@@ -70,8 +82,8 @@
                             <constraint firstAttribute="height" constant="90" id="dE5-pY-qzE"/>
                         </constraints>
                     </view>
-                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Show Font Name&gt;" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3ni-3O-NWD">
-                        <rect key="frame" x="10" y="130" width="140" height="21"/>
+                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Show Font Name &gt;" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3ni-3O-NWD">
+                        <rect key="frame" x="10" y="130" width="144.33333333333334" height="21"/>
                         <fontDescription key="fontDescription" type="system" pointSize="17"/>
                         <nil key="textColor"/>
                         <nil key="highlightedColor"/>
@@ -81,12 +93,26 @@
                         <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                         <state key="normal" title="Button" image="CPDFEditBoldNormal"/>
                         <state key="selected" image="CPDFEditHiglight"/>
+                        <connections>
+                            <action selector="fontBoldAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="pF5-Zd-wqv"/>
+                        </connections>
+                    </button>
+                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sp9-EM-5gs">
+                        <rect key="frame" x="10" y="123" width="145" height="34"/>
+                        <constraints>
+                            <constraint firstAttribute="width" constant="145" id="NTm-QQ-tAp"/>
+                        </constraints>
+                        <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
+                        <connections>
+                            <action selector="showFontNameAction:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="6kL-hH-nE7"/>
+                        </connections>
                     </button>
                 </subviews>
                 <constraints>
                     <constraint firstItem="tx4-bt-cUh" firstAttribute="leading" secondItem="H2Y-8R-CMe" secondAttribute="trailing" constant="20" id="An4-9q-kCf"/>
                     <constraint firstAttribute="trailing" secondItem="uhx-SF-mln" secondAttribute="trailing" id="CcO-Mn-VMl"/>
                     <constraint firstItem="H2Y-8R-CMe" firstAttribute="height" secondItem="tx4-bt-cUh" secondAttribute="height" multiplier="0.875" id="EOq-0u-oce"/>
+                    <constraint firstItem="sp9-EM-5gs" firstAttribute="top" secondItem="uhx-SF-mln" secondAttribute="bottom" constant="23" id="Gi6-yn-hhK"/>
                     <constraint firstAttribute="trailing" secondItem="ohh-qk-Inu" secondAttribute="trailing" id="Hnl-9t-9H0"/>
                     <constraint firstAttribute="trailing" secondItem="SQc-1y-yHE" secondAttribute="trailing" constant="10" id="J4d-yv-7u0"/>
                     <constraint firstItem="VsT-rp-W0E" firstAttribute="leading" secondItem="n1n-vD-767" secondAttribute="trailing" constant="20" id="KO2-f1-XVf"/>
@@ -103,6 +129,7 @@
                     <constraint firstItem="3ni-3O-NWD" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="e1S-Zj-dYo"/>
                     <constraint firstItem="tx4-bt-cUh" firstAttribute="centerY" secondItem="3ni-3O-NWD" secondAttribute="centerY" id="fFJ-sa-EN4"/>
                     <constraint firstItem="ohh-qk-Inu" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="iKM-NL-byz"/>
+                    <constraint firstItem="sp9-EM-5gs" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="q9p-v7-lEr"/>
                     <constraint firstItem="SQc-1y-yHE" firstAttribute="centerY" secondItem="lXb-G8-H3F" secondAttribute="centerY" id="vPZ-NC-AKb"/>
                     <constraint firstItem="H2Y-8R-CMe" firstAttribute="width" secondItem="tx4-bt-cUh" secondAttribute="width" id="vRw-fM-hZK"/>
                     <constraint firstItem="H2Y-8R-CMe" firstAttribute="centerY" secondItem="tx4-bt-cUh" secondAttribute="centerY" id="wMP-WK-vLX"/>
@@ -110,10 +137,13 @@
             </tableViewCellContentView>
             <viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
             <connections>
+                <outlet property="centerAlignBtn" destination="VsT-rp-W0E" id="zNm-Kr-m3M"/>
                 <outlet property="colorAreaView" destination="uhx-SF-mln" id="8nr-Sz-JCZ"/>
+                <outlet property="leftAlignBtn" destination="n1n-vD-767" id="3YB-B6-02M"/>
+                <outlet property="rightAlignBtn" destination="SQc-1y-yHE" id="RKz-tl-IYE"/>
                 <outlet property="sliderArea" destination="ohh-qk-Inu" id="hfq-6F-dgM"/>
             </connections>
-            <point key="canvasLocation" x="-41.221374045801525" y="85.91549295774648"/>
+            <point key="canvasLocation" x="182" y="85"/>
         </tableViewCell>
     </objects>
     <resources>

+ 20 - 0
compdfkit-tools/compdfkit-tools/Edit/CPDFEditProperty/CPDFTextProperty.h

@@ -10,11 +10,31 @@
 //
 
 #import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+typedef NS_ENUM(NSUInteger, CPDFEditTextAlignment) {
+    CPDFEditTextAlignmentLeft,
+    CPDFEditTextAlignmentCenter,
+    CPDFEditTextAlignmentRighht,
+    CPDFEditTextAlignmentNone
+};
 
 NS_ASSUME_NONNULL_BEGIN
 
 @interface CPDFTextProperty : NSObject
 
+@property (nonatomic, strong) UIColor *fontColor;
+
+@property (nonatomic, strong) NSString *fontName;
+
+@property (nonatomic, assign) BOOL isBold;
+
+@property (nonatomic, assign) BOOL isItalic;
+
+@property (nonatomic, assign) CGFloat fontSize;
+
+@property (nonatomic, assign) CPDFEditTextAlignment textAlignment;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 15 - 1
compdfkit-tools/compdfkit-tools/Edit/CPDFEditViewController.m

@@ -13,6 +13,7 @@
 #import "CPDFEditViewController.h"
 #import "CPDFImagePropertyCell.h"
 #import "CPDFTextPropertyCell.h"
+#import "CPDFColorPickerView.h"
 
 @interface CPDFEditViewController ()<UITableViewDelegate,UITableViewDataSource>
 
@@ -90,7 +91,14 @@
         if (!cell) {
             cell = [CPDFTextPropertyCell CPDFTextPropertyCell];
         }
-        cell.selectionStyle =UITableViewCellSelectionStyleNone;
+        cell.actionBlock = ^(CPDFTextActionType actionType) {
+            if(actionType == CPDFTextActionColorSelect){
+                //Add colorSelectView
+            }else if(actionType == CPDFTextActionFontNameSelect) {
+                //Add actionFontNameSelect
+            }
+        };
+        cell.selectionStyle = UITableViewCellSelectionStyleNone;
         tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
         return cell;
     }else{
@@ -125,4 +133,10 @@
     
     [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
 }
+
+#pragma mark - Accessors
+- (void)addColorSelectView{
+    
+}
+
 @end