Skip to content

Commit af1f52b

Browse files
committed
doc: update for missing parts
1 parent 2bde0d4 commit af1f52b

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

Source/Styles/EFQRCodeStyle.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ public class EFStyleParamIcon {
196196
)
197197
}
198198

199+
/**
200+
* Generates SVG elements for rendering the icon in the QR code.
201+
*
202+
* This method creates the necessary SVG markup to display the icon at the center
203+
* of the QR code with proper masking, scaling, and border styling.
204+
*
205+
* - Parameter qrcode: The QR code model containing module structure and dimensions.
206+
* - Returns: An array of SVG strings representing the icon elements.
207+
* - Throws: `EFQRCodeError` if color conversion or image processing fails.
208+
*/
199209
func write(qrcode: QRCode) throws -> [String] {
200210
struct Anchor {
201211
static var uniqueMark: Int = 0
@@ -327,6 +337,15 @@ public class EFStyleParamBackdrop {
327337
self.quietzone = quietzone
328338
}
329339

340+
/**
341+
* Calculates the viewBox dimensions for the QR code with quiet zone considerations.
342+
*
343+
* This method determines the coordinate system and dimensions for the SVG viewBox,
344+
* taking into account any specified quiet zone (border space) around the QR code.
345+
*
346+
* - Parameter moduleCount: The number of modules (squares) along one side of the QR code.
347+
* - Returns: A CGRect defining the viewBox coordinates and dimensions.
348+
*/
330349
func viewBox(moduleCount: Int) -> CGRect {
331350
if let quietzone = quietzone {
332351
return CGRect(
@@ -339,6 +358,19 @@ public class EFStyleParamBackdrop {
339358
return CGRect(x: -1, y: -1, width: moduleCount.cgFloat + 2, height: moduleCount.cgFloat + 2)
340359
}
341360

361+
/**
362+
* Generates the opening and closing SVG markup for the QR code backdrop.
363+
*
364+
* This method creates the SVG container structure with background styling,
365+
* clipping paths, and coordinate transformations. It returns a tuple containing
366+
* the opening SVG elements and the closing elements.
367+
*
368+
* - Parameters:
369+
* - qrcode: The QR code model containing structure information.
370+
* - viewBoxRect: The viewBox rectangle defining the coordinate system.
371+
* - Returns: A tuple containing (opening SVG markup, closing SVG markup).
372+
* - Throws: `EFQRCodeError` if color conversion or image processing fails.
373+
*/
342374
func generateSVG(qrcode: QRCode, viewBoxRect: CGRect) throws -> (String, String) {
343375
let bgColor: String = try color.hexString()
344376
let bgAlpha: CGFloat = max(0, try color.alpha())
@@ -390,6 +422,16 @@ public class EFStyleParamBackdropImage {
390422
self.mode = mode
391423
}
392424

425+
/**
426+
* Generates SVG markup for the backdrop image.
427+
*
428+
* This method processes the backdrop image according to the specified scaling mode
429+
* and generates the corresponding SVG image element with proper sizing and encoding.
430+
*
431+
* - Parameter size: The target size for the backdrop image in the SVG coordinate system.
432+
* - Returns: An SVG image element string with base64-encoded image data.
433+
* - Throws: `EFQRCodeError` if image processing or encoding fails.
434+
*/
393435
func write(size: CGSize) throws -> String {
394436
let imageCliped: CGImage = try self.mode.imageForContent(ofImage: image, inCanvasOfRatio: size)
395437
let pngBase64EncodedString: String = try imageCliped.pngBase64EncodedString()

Source/Styles/EFQRCodeStyleBasic.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,16 @@ public class EFQRCodeStyleBasic: EFQRCodeStyleBase {
295295
/// The parameters for the basic style.
296296
let params: EFStyleBasicParams
297297

298+
/// SVG path data for rounded square shapes used in QR code styling.
299+
/// This path defines a rounded rectangle with corner radius optimized for QR code aesthetics.
298300
static let sq25: String = "M32.048565,-1.29480038e-15 L67.951435,1.29480038e-15 C79.0954192,-7.52316311e-16 83.1364972,1.16032014 87.2105713,3.3391588 C91.2846454,5.51799746 94.4820025,8.71535463 96.6608412,12.7894287 C98.8396799,16.8635028 100,20.9045808 100,32.048565 L100,67.951435 C100,79.0954192 98.8396799,83.1364972 96.6608412,87.2105713 C94.4820025,91.2846454 91.2846454,94.4820025 87.2105713,96.6608412 C83.1364972,98.8396799 79.0954192,100 67.951435,100 L32.048565,100 C20.9045808,100 16.8635028,98.8396799 12.7894287,96.6608412 C8.71535463,94.4820025 5.51799746,91.2846454 3.3391588,87.2105713 C1.16032014,83.1364972 5.01544207e-16,79.0954192 -8.63200256e-16,67.951435 L8.63200256e-16,32.048565 C-5.01544207e-16,20.9045808 1.16032014,16.8635028 3.3391588,12.7894287 C5.51799746,8.71535463 8.71535463,5.51799746 12.7894287,3.3391588 C16.8635028,1.16032014 20.9045808,7.52316311e-16 32.048565,-1.29480038e-15 Z"
301+
302+
/// Horizontal offset values for planet-style position detection patterns.
303+
/// These values define the x-axis positions of satellite elements relative to the center.
299304
static let planetsVw: [CGFloat] = [3, -3]
305+
306+
/// Vertical offset values for planet-style position detection patterns.
307+
/// These values define the y-axis positions of satellite elements relative to the center.
300308
static let planetsVh: [CGFloat] = [3, -3]
301309

302310
/**

Source/Styles/EFQRCodeStyleResampleImage.swift

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,23 @@ public class EFQRCodeStyleResampleImage: EFQRCodeStyleBase {
516516
return pointList
517517
}
518518

519+
/**
520+
* Generates SVG markup for image-resampled QR code modules.
521+
*
522+
* This method creates the resample image effect by sampling colors from the source image
523+
* and applying them to the QR code modules. It processes the image pixels and maps them
524+
* to QR code module positions with proper contrast adjustments.
525+
*
526+
* - Parameters:
527+
* - params: The resample image styling parameters.
528+
* - qrcode: The QR code model containing module structure.
529+
* - image: The image parameters for resampling, or nil if no image is available.
530+
* - newWidth: The target width for the resampled image in pixels.
531+
* - newHeight: The target height for the resampled image in pixels.
532+
* - color: The fallback hex color string for modules when image sampling fails.
533+
* - Returns: An SVG string containing the image-resampled QR code modules.
534+
* - Throws: `EFQRCodeError` if image processing or color conversion fails.
535+
*/
519536
func writeResImage(params: EFStyleResampleImageParams, qrcode: QRCode, image: EFStyleResampleImageParamsImage?, newWidth: Int, newHeight: Int, color: String) throws -> String {
520537
guard let image = image else { return "" }
521538

@@ -578,6 +595,17 @@ public class EFQRCodeStyleResampleImage: EFQRCodeStyleBase {
578595
+ part2
579596
}
580597

598+
/**
599+
* Generates custom SVG markup for non-data modules in the resample image QR code.
600+
*
601+
* This method creates SVG elements for alignment patterns, timing patterns, and
602+
* position detection patterns that are not part of the main data resampling.
603+
* These elements use traditional QR code styling rather than image sampling.
604+
*
605+
* - Parameter qrcode: The QR code model containing module structure and type information.
606+
* - Returns: An SVG string containing the custom-styled QR code control patterns.
607+
* - Throws: `EFQRCodeError` if color conversion fails.
608+
*/
581609
func customSVG(qrcode: QRCode) throws -> String {
582610
let alignType: EFStyleResampleImageParamAlignStyle = params.align.style
583611
let alignColor: String = try params.align.color.hexString()
@@ -663,17 +691,51 @@ public class EFQRCodeStyleResampleImage: EFQRCodeStyleBase {
663691
}
664692
}
665693

694+
/**
695+
* Extensions for CGImage to support resample image QR code generation.
696+
*
697+
* This extension provides utility methods for processing images used in
698+
* resample image QR code styles, including color analysis and pixel sampling.
699+
*/
666700
extension CGImage {
667701

668-
// red, green, blue: [0, 255]
669-
// alpha: [0, 1]
670-
// return: [0, 255]
702+
/**
703+
* Calculates the grayscale value for RGBA color components with gamma correction.
704+
*
705+
* This method converts RGB color values to grayscale using standard luminance
706+
* coefficients and applies alpha blending for proper color representation.
707+
*
708+
* - Parameters:
709+
* - red: The red component value (0-255).
710+
* - green: The green component value (0-255).
711+
* - blue: The blue component value (0-255).
712+
* - alpha: The alpha component value (0-1).
713+
* - Returns: The calculated grayscale value (0-255).
714+
*/
671715
func gamma(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat) -> CGFloat {
672716
let gray: CGFloat = 0.2126 * red + 0.7152 * green + 0.0722 * blue
673717
let weightedGray: CGFloat = gray * alpha + (1 - alpha) * 255.0
674718
return weightedGray
675719
}
676720

721+
/**
722+
* Generates QR code modules by sampling grayscale values from the image.
723+
*
724+
* This method processes the image to create QR code modules based on pixel brightness,
725+
* applying contrast and exposure adjustments. It handles different QR code module types
726+
* (data, alignment, timing) and creates appropriate SVG elements for each.
727+
*
728+
* - Parameters:
729+
* - params: The resample image styling parameters.
730+
* - qrcode: The QR code model containing module structure and type information.
731+
* - newWidth: The target width for image resampling.
732+
* - newHeight: The target height for image resampling.
733+
* - contrast: The contrast adjustment value. Defaults to 0.
734+
* - exposure: The exposure adjustment value. Defaults to 0.
735+
* - color: The fallback color string for modules when image sampling fails.
736+
* - Returns: An array of SVG strings representing the QR code modules.
737+
* - Throws: `EFQRCodeError` if color conversion or image processing fails.
738+
*/
677739
func getGrayPointList(params: EFStyleResampleImageParams, qrcode: QRCode, newWidth: Int, newHeight: Int, contrast: CGFloat = 0, exposure: CGFloat = 0, color: String) throws -> [String] {
678740
// filter trans area
679741
let nCount: Int = qrcode.model.moduleCount

0 commit comments

Comments
 (0)