Skip to content

Commit

Permalink
chore: release version 4.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenceLove committed Feb 16, 2024
1 parent 2d47ce1 commit 51c1498
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 78 deletions.
4 changes: 4 additions & 0 deletions Sources/HXPhotoPicker/Core/Extension/Core+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ extension String: HXPickerCompatibleValue {
.shared
}

#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
static var textNotAuthorized: HX.TextManager.Picker.NotAuthorized {
textManager.picker.notAuthorized
}
#endif

#if HXPICKER_ENABLE_PICKER
static var textPhotoList: HX.TextManager.Picker.PhotoList {
textManager.picker.photoList
}

static var textPreview: HX.TextManager.Picker.Preview {
textManager.picker.preview
}
#endif

var lrc: String? {
var lrcString: String?
Expand Down
4 changes: 4 additions & 0 deletions Sources/HXPhotoPicker/Core/Extension/Core+UIFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ extension UIFont: HXPickerCompatibleValue {
HX.TextManager.shared
}

#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
static var textNotAuthorized: HX.TextManager.Picker.NotAuthorized {
textManager.picker.notAuthorized
}
#endif

#if HXPICKER_ENABLE_PICKER
static var textPhotoList: HX.TextManager.Picker.PhotoList {
textManager.picker.photoList
}

static var textPreview: HX.TextManager.Picker.Preview {
textManager.picker.preview
}
#endif

static func regularPingFang(ofSize size: CGFloat) -> UIFont {
if let font = UIFont.init(name: "PingFangSC-Regular", size: size) {
Expand Down
51 changes: 28 additions & 23 deletions Sources/HXPhotoPicker/Core/Extension/Core+UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,51 @@ extension UIImage {
}
return self.scaleToFillSize(size: imageSize)
}

func scaleToFillSize(size: CGSize, mode: HX.ImageTargetMode = .fill, scale: CGFloat = 0) -> UIImage? {
if __CGSizeEqualToSize(self.size, size) {
return self
}
let scale = scale == 0 ? self.scale : scale
let isEqualRatio = size.width / size.height != width / height
let rect: CGRect
if !isEqualRatio && mode == .fill {
let scale = size.width / width
var scaleHeight = scale * height
var scaleWidth = size.width
if scaleHeight < size.height {
scaleWidth = size.height / scaleHeight * size.width
scaleHeight = size.height
let rendererSize: CGSize
if mode == .fill {
let isEqualRatio = size.width / size.height == width / height
if isEqualRatio {
rendererSize = size
rect = CGRect(origin: .zero, size: size)
}else {
let scale = size.width / width
var scaleHeight = scale * height
var scaleWidth = size.width
if scaleHeight < size.height {
scaleWidth = size.height / scaleHeight * size.width
scaleHeight = size.height
}
rendererSize = .init(width: scaleWidth, height: scaleHeight)
rect = .init(origin: .zero, size: rendererSize)
}
rect = CGRect(
x: -(scaleWidth - size.height) * 0.5,
y: -(scaleHeight - size.height) * 0.5,
width: scaleWidth,
height: scaleHeight
)
}else {
rendererSize = size
if mode == .fit {
rect = CGRect(origin: .zero, size: size)
}else {
let scale = size.width / width
let scaleHeight = scale * size.height
let scaleWidth = size.width
var scaleHeight = scale * height
if scaleHeight < size.height {
scaleHeight = size.height
}
rect = CGRect(
x: -(width - scaleWidth) * 0.5,
y: -(height - scaleHeight) * 0.5,
width: width,
height: height
x: 0,
y: -(scaleHeight - size.height) / 2,
width: size.width,
height: scaleHeight
)
}
}
let format = UIGraphicsImageRendererFormat()
format.opaque = false
format.scale = scale
let renderer = UIGraphicsImageRenderer(size: size, format: format)
format.scale = scale == 0 ? self.scale : scale
let renderer = UIGraphicsImageRenderer(size: rendererSize, format: format)
let image = renderer.image { context in
draw(in: rect)
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/HXPhotoPicker/Core/HXPhotoPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public enum HX {
try await Photo.capture(config, type: type, delegate: delegate, fromVC: fromVC)
}
#endif

public enum ImageTargetMode {
/// 与原图宽高比一致,高度会根据`targetSize`计算
case fill
/// 根据`targetSize`拉伸/缩放
case fit
/// 如果`targetSize`的比例与原图不一样则居中显示
case center
}
}

public struct HXPickerWrapper<Base> {
Expand Down
6 changes: 4 additions & 2 deletions Sources/HXPhotoPicker/Core/Util/ImageResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public extension HX {
public var picker: Picker = .init()
#endif

#if HXPICKER_ENABLE_EDITOR
#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_EDITOR_VIEW
/// 编辑器
public var editor: Editor = .init()
#endif
Expand Down Expand Up @@ -138,7 +138,7 @@ public extension HX.ImageResource {
}
#endif

#if HXPICKER_ENABLE_EDITOR
#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_EDITOR_VIEW
struct Editor {
/// 工具栏
public var tools: Tools = .init()
Expand Down Expand Up @@ -231,6 +231,8 @@ public extension HX.ImageResource {
public var back: String = "hx_photo_edit_pull_down"
/// 跳转相册按钮
public var album: String = "hx_editor_tools_chartle_album"
/// 相册为空时的封面图片
public var albumEmptyCover: String = "hx_picker_album_empty"
/// 贴纸删除按钮
public var delete: String = "hx_editor_view_sticker_item_delete"
/// 贴纸旋转按钮
Expand Down
2 changes: 2 additions & 0 deletions Sources/HXPhotoPicker/Core/Util/PhotoTools+Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ extension PhotoTools {
}

/// 显示没有相机权限弹窗
#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
static func showNotCameraAuthorizedAlert(
viewController: UIViewController?,
cancelHandler: (() -> Void)? = nil
Expand All @@ -141,4 +142,5 @@ extension PhotoTools {
openSettingsURL()
}
}
#endif
}
2 changes: 1 addition & 1 deletion Sources/HXPhotoPicker/Core/Util/PhotoTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public struct PhotoTools {
return layer
}

#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_CAMERA
#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_EDITOR_VIEW || HXPICKER_ENABLE_CAMERA
static func getColor(red: Int, green: Int, blue: Int, alpha: Int = 255) -> CIColor {
return CIColor(red: CGFloat(Double(red) / 255.0),
green: CGFloat(Double(green) / 255.0),
Expand Down
22 changes: 8 additions & 14 deletions Sources/HXPhotoPicker/Core/Util/TextManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,17 @@ public extension HX {
class TextManager {
public static let shared = TextManager()

#if HXPICKER_ENABLE_PICKER
#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
/// 选择器
public var picker: Picker = .init()
#endif

#if HXPICKER_ENABLE_EDITOR
/// 编辑器
public var editor: Editor = .init()
#endif

#if HXPICKER_ENABLE_CAMERA
/// 相机
public var camera: Camera = .init()
public var cameraNotAuthorized: CameraNotAuthorized = .init()
#endif

#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
public var cameraNotAuthorized: CameraNotAuthorized = .init()
#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_EDITOR_VIEW
/// 编辑器
public var editor: Editor = .init()
#endif
}
}
Expand All @@ -54,7 +48,7 @@ public extension HX.TextManager {
}
}

#if HXPICKER_ENABLE_PICKER
#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
struct Picker {
/// 相册未授权
public var notAuthorized: NotAuthorized = .init()
Expand Down Expand Up @@ -191,7 +185,7 @@ public extension HX.TextManager {
}
#endif

#if HXPICKER_ENABLE_EDITOR
#if HXPICKER_ENABLE_EDITOR || HXPICKER_ENABLE_EDITOR_VIEW
struct Editor {
public var tools: Tools = .init()
public var brush: Tools = .init()
Expand Down Expand Up @@ -295,7 +289,7 @@ public extension HX.TextManager {
}
#endif

#if HXPICKER_ENABLE_CAMERA
#if HXPICKER_ENABLE_PICKER || HXPICKER_ENABLE_CAMERA
struct Camera {

public var unavailableTitle: TextType = .localized("相机不可用!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ extension EditorAdjusterView {
imageData,
compressionQuality: compressionQuality
) { [weak self] data in
guard let self = self, let data = data else {
guard let self = self,
let data = data,
let image = UIImage(data: data)?.normalizedImage() else {
DispatchQueue.main.async {
completion(.failure(EditorError.error(type: .compressionFailed, message: "图片压缩失败")))
}
Expand All @@ -239,26 +241,24 @@ extension EditorAdjusterView {
}
return
}
self.compressImageData(
data,
compressionQuality: 0.3
) { thumbData in
if let thumbData = thumbData,
let thumbnailImage = UIImage(data: thumbData) {
DispatchQueue.main.async {
completion(
.success(.init(
image: thumbnailImage,
urlConfig: urlConfig,
imageType: .normal,
data: self.getData()
))
)
}
let thumbImage: UIImage?
if image.width * image.height < 40000 {
thumbImage = image
}else {
thumbImage = image.scaleToFillSize(size: .init(width: 200, height: 200))
}
DispatchQueue.main.async {
if let thumbImage {
completion(
.success(.init(
image: thumbImage,
urlConfig: urlConfig,
imageType: .normal,
data: self.getData()
))
)
}else {
DispatchQueue.main.async {
completion(.failure(.error(type: .compressionFailed, message: "封面图片压缩失败")))
}
completion(.failure(.error(type: .compressionFailed, message: "封面图片压缩失败")))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public class EditorChartletViewController: BaseViewController, EditorChartletLis
if let url = title.url {
titleChartlet = EditorChartletTitle(url: url)
}else {
titleChartlet = .init(image: .imageResource.picker.albumList.emptyCover.image)
titleChartlet = .init(image: .imageResource.editor.sticker.albumEmptyCover.image)
}
#else
titleChartlet = .init(image: .imageResource.picker.albumList.emptyCover.image)
titleChartlet = .init(image: .imageResource.editor.sticker.albumEmptyCover.image)
#endif
}
if index == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class EditorFiltersView: UIView {
operation.addExecutionBlock { [unowned operation, weak self] in
guard let self = self else { return }
if operation.isCancelled { return }
self.image = originalImage.scaleToFillSize(size: CGSize(width: 80, height: 80))
self.image = originalImage.scaleToFillSize(size: CGSize(width: 80, height: 80), mode: .center)
if operation.isCancelled { return }
DispatchQueue.main.async {
self.didLoad = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ public struct PhotoListConfiguration {
bottomView.setThemeColor(color)
cell.setThemeColor(color)
assetNumber.setThemeColor(color)
#if HXPICKER_ENABLE_CAMERA && !targetEnvironment(macCatalyst)
if var cameraConfig = cameraType.customConfig {
cameraConfig.tintColor = color
cameraType = .custom(cameraConfig)
}
filterThemeColor = color
#endif
filterThemeColor = color
filterThemeDarkColor = color
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ public struct PickerBottomViewConfiguration {
finishButtonDarkBackgroundColor = color
finishButtonDisableBackgroundColor = color.withAlphaComponent(0.4)
finishButtonDisableDarkBackgroundColor = color.withAlphaComponent(0.4)
#if HXPICKER_ENABLE_EDITOR
editButtonTitleColor = color
#endif
promptIconColor = color
promptIconDarkColor = color
promptTitleColor = color
Expand Down
3 changes: 1 addition & 2 deletions Sources/HXPhotoPicker/Picker/Model/PhotoAsset+Local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ extension PhotoAsset {
size: CGSize(
width: targetWidth,
height: targetWidth
),
mode: .fill
)
)
self.localImageAsset?.thumbnail = thumbnail
DispatchQueue.main.async {
Expand Down
10 changes: 0 additions & 10 deletions Sources/HXPhotoPicker/Picker/Model/PickerTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,4 @@ public enum PhotoPreviewType {
case browser
}

public extension HX {
enum ImageTargetMode {
/// 与原图宽高比一致,高度会根据`targetSize`计算
case fill
/// 根据`targetSize`拉伸/缩放
case fit
/// 如果`targetSize`的比例与原图不一样则居中显示
case center
}
}

Loading

0 comments on commit 51c1498

Please sign in to comment.