Skip to content

Commit

Permalink
Added crt styles
Browse files Browse the repository at this point in the history
  • Loading branch information
dagronf committed Jul 22, 2024
1 parent 6aec3d9 commit e3859a9
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 44 deletions.
Binary file added Art/images/data_crt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Art/images/eye_crt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Art/images/pupil_crt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Art/paths.pcvd
Binary file not shown.
2 changes: 1 addition & 1 deletion DSF_QRCode.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'DSF_QRCode'
s.version = '20.1.0'
s.version = '20.2.0'
s.summary = 'A simple drop-in macOS/iOS/tvOS/watchOS QR Code generator view for Swift, Objective-C and SwiftUI.'
s.homepage = 'https://github.com/dagronf/QRCode'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
4 changes: 2 additions & 2 deletions Demo/Cocoapods Test/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- DSF_QRCode (20.0.0):
- DSF_QRCode (20.2.0):
- SwiftImageReadWrite (~> 1.7.2)
- SwiftQRCodeGenerator (~> 2.0.2)
- SwiftImageReadWrite (1.7.2)
Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
DSF_QRCode: 6558f9b71f29ddbedd546e524f6d5e505841c5c6
DSF_QRCode: 694d68eb0572f0a6d16c05ef5ffceae82d1554d5
SwiftImageReadWrite: ef6dfb4a78a0142a62c89cacf549623b26961fd3
SwiftQRCodeGenerator: cc02fed209335064d0b0dd61b2a0874b9bc6bd5a

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ square, circle, rounded rectangle, and more.
|<img src="./Art/images/eye_barsVertical.png" width="60"/> | "barsVertical" |`QRCode.EyeShape.BarsVertical`| Simple rounded rect with three vertical bars as the pupil|
|<img src="./Art/images/eye_circle.png" width="60"/> | "circle" |`QRCode.EyeShape.Circle`|Simple circle|
|<img src="./Art/images/eye_corneredPixels.png" width="60"/> | "corneredPixels" |`QRCode.EyeShape.CorneredPixels`| A simple collection of pixels with configurable corner radius for the entire shape|
|<img src="./Art/images/eye_crt.png" width="60"/> | "crt" |`QRCode.EyeShape.CRT`| A CRT shape |
|<img src="./Art/images/eye_edges.png" width="60"/> | "edges" |`QRCode.EyeShape.Edges`| Simple bordered bars with a configurable corner radius |
|<img src="./Art/images/eye_fireball.png" width="60" /> | "fireball" |`QRCode.EyeShape.Fireball` | A fireball shape |
|<img src="./Art/images/eye_leaf.png" width="60"/> | "leaf" |`QRCode.EyeShape.Leaf`|An eye that look like a leaf|
Expand Down Expand Up @@ -394,6 +395,7 @@ If you don't override the pupil shape, it defaults to the eye shape's pupil shap
|<img src="./Art/images/pupil_corneredPixels.png" width="30"/> |"corneredPixels"|`QRCode.PupilShape.CorneredPixels`| A simple collection of pixels with configurable corner radius for the entire shape |
|<img src="./Art/images/pupil_cross.png" width="30"/> |"cross"|`QRCode.PupilShape.Cross`| A cross |
|<img src="./Art/images/pupil_crossCurved.png" width="30"/> |"crossCurved"|`QRCode.PupilShape.CrossCurved`| A cross with curved insets |
|<img src="./Art/images/pupil_crt.png" width="30"/> | "crt" |`QRCode.PupilShape.CRT`| A CRT shape |
|<img src="./Art/images/pupil_hexagonLeaf.png" width="30" /> |"hexagonLeaf"|`QRCode.PixelShape.HexagonLeaf` | A hexagonal leaf shape |
|<img src="./Art/images/pupil_Leaf.png" width="30"/> |"leaf"|`QRCode.PupilShape.Leaf`|An eye that look like a leaf|
|<img src="./Art/images/pupil_pinch.png" width="30"/> |"pinch"|`QRCode.PupilShape.Pinch`| A square pinched in at the sides |
Expand Down Expand Up @@ -435,6 +437,7 @@ however you can supply a `PixelShape` object to custom-draw the data. There are
| Preview | Name | Class | Description |
|---|---|---|---|
|<img src="./Art/images/data_circle.png" width="60"/> |"circle"|`QRCode.PixelShape.Circle`|A basic circle pixel|
|<img src="./Art/images/data_crt.png" width="60"/> | "crt" |`QRCode.PixelShape.CRT`| A CRT shape |
|<img src="./Art/images/data_curvePixel.png" width="60"/> |"curvePixel"|`QRCode.PixelShape.CurvePixel`|A pixel that curves to follow paths|
|<img src="./Art/images/data_flower.png" width="60"/> |"flower"|`QRCode.PixelShape.Flower`|A 'flower' style|
|<img src="./Art/images/data_horizontal.png" width="60"/> |"horizontal"|`QRCode.PixelShape.Horizontal`|The pixels are horizonally joined to make continuous horizontal bars|
Expand Down Expand Up @@ -1144,7 +1147,7 @@ OPTIONS:
--all-pixel-shapes <all-pixel-shapes>
Print all the available pixel shapes.
-d, --on-pixel-shape <on-pixel-shape>
The onPixels shape to use. Available shapes are circle, curvePixel, flower, horizontal,
The onPixels shape to use. Available shapes are crt, circle, curvePixel, flower, horizontal,
pointy, razor, roundedEndIndent, roundedPath, roundedRect, sharp, shiny, square, squircle,
star, vertical.
-n, --on-pixel-inset-fraction <on-pixel-inset-fraction>
Expand All @@ -1156,7 +1159,7 @@ OPTIONS:
--all-eye-shapes <all-eye-shapes>
Print all the available eye shapes.
-e, --eye-shape <eye-shape>
The eye shape to use. Available shapes are circle, corneredPixels, edges, fireball,
The eye shape to use. Available shapes are crt, circle, corneredPixels, edges, fireball,
barsHorizontal, leaf, peacock, pinch, pixels, roundedOuter, roundedPointingIn,
roundedPointingOut, roundedRect, shield, square, squircle, teardrop, ufo, usePixelShape,
barsVertical.
Expand All @@ -1165,7 +1168,7 @@ OPTIONS:
--all-pupil-shapes <all-pupil-shapes>
Print all the available pupil shapes.
-p, --pupil-shape <pupil-shape>
The pupil shape to use. Available shapes are blobby, circle, corneredPixels, cross,
The pupil shape to use. Available shapes are blobby, crt, circle, corneredPixels, cross,
crossCurved, edges, hexagonLeaf, barsHorizontal, leaf, pinch, pixels, roundedOuter,
roundedPointingIn, roundedPointingOut, roundedRect, seal, shield, square,
barsHorizontalSquare, barsVerticalSquare, squircle, teardrop, ufo, usePixelShape,
Expand Down
74 changes: 37 additions & 37 deletions Sources/QRCode/QRCode+Drawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ public extension QRCode {
) {
// Only works with a 1:1 rect
let sz = min(rect.width, rect.height)

/// The size of each pixel in the output
let additionalQuietSpacePixels = CGFloat(design.additionalQuietZonePixels)
let dm: CGFloat = CGFloat(sz) / (CGFloat(self.cellDimension) + (2.0 * additionalQuietSpacePixels))
let additionalQuietSpace = dm * additionalQuietSpacePixels

// Factor in the additional quiet space in the result
guard (2 * additionalQuietSpace) < sz else {
Swift.print("additionalQuietSpace too large")
return
}

let xoff = additionalQuietSpace + (rect.width - (CGFloat(self.cellDimension) * dm)) / 2.0
let yoff = additionalQuietSpace + (rect.height - (CGFloat(self.cellDimension) * dm)) / 2.0

// This is the final position for the generated qr code, inset within the final image
let finalRect = rect.insetBy(dx: additionalQuietSpace, dy: additionalQuietSpace)

let style = design.style

//
// Special case handling for the 'use pixel shape' eye and pupil types
//
Expand All @@ -63,7 +63,7 @@ public extension QRCode {
if let pupilPixelShape = design.shape.pupil as? QRCode.PupilShape.UsePixelShape {
pupilPixelShape.pixelShape = design.shape.onPixels
}

// Fill the background first
let backgroundStyle = style.background ?? QRCode.FillStyle.clear
ctx.usingGState { context in
Expand All @@ -77,13 +77,13 @@ public extension QRCode {
}
backgroundStyle.fill(ctx: context, rect: rect)
}

if design.shape.negatedOnPixelsOnly {
var negatedMatrix = self.boolMatrix.inverted()
if let logoTemplate = logoTemplate {
negatedMatrix = logoTemplate.applyingMask(matrix: negatedMatrix, dimension: sz)
}

if let c = design.style.onPixelsBackground {
let negatedPath = self.path(
finalRect.size,
Expand All @@ -96,15 +96,15 @@ public extension QRCode {
QRCode.FillStyle.Solid(c).fill(ctx: context, rect: finalRect, path: negatedPath)
}
}

let negatedPath = self.path(
finalRect.size,
components: .negative,
shape: design.shape,
logoTemplate: logoTemplate,
additionalQuietSpace: additionalQuietSpace
)

ctx.usingGState { context in
style.onPixels.fill(ctx: context, rect: finalRect, path: negatedPath)
}
Expand All @@ -125,7 +125,7 @@ public extension QRCode {
ctx.fillPath()
}
}

// Draw the outer eye
let eyeOuterPath = self.path(
finalRect.size,
Expand All @@ -137,7 +137,7 @@ public extension QRCode {
ctx.usingGState { context in
style.actualEyeStyle.fill(ctx: context, rect: finalRect, path: eyeOuterPath)
}

// Draw the eye 'pupil'
let eyePupilPath = self.path(
finalRect.size,
Expand All @@ -149,7 +149,7 @@ public extension QRCode {
ctx.usingGState { context in
style.actualPupilStyle.fill(ctx: context, rect: finalRect, path: eyePupilPath)
}

// Now, the 'on' pixels background
if let c = design.style.onPixelsBackground {
let design: QRCode.Design = {
Expand All @@ -158,7 +158,7 @@ public extension QRCode {
d.style.onPixels = QRCode.FillStyle.Solid(c)
return d
}()

let qrPath2 = self.path(
finalRect.size,
components: .onPixels,
Expand All @@ -170,7 +170,7 @@ public extension QRCode {
design.style.onPixels.fill(ctx: context, rect: finalRect, path: qrPath2)
}
}

// Now, the 'on' pixels
let qrPath = self.path(
finalRect.size,
Expand All @@ -182,7 +182,7 @@ public extension QRCode {
ctx.usingGState { context in
style.onPixels.fill(ctx: context, rect: finalRect, path: qrPath)
}

// The 'off' pixels ONLY IF the user specifies both a offPixels shape AND an offPixels style.
if let s = style.offPixels, let _ = design.shape.offPixels {
// Draw the 'off' pixels background IF the caller has set a color
Expand All @@ -204,7 +204,7 @@ public extension QRCode {
design.style.offPixels?.fill(ctx: context, rect: finalRect, path: qrPath2)
}
}

let qrPath = self.path(
finalRect.size,
components: .offPixels,
Expand All @@ -217,26 +217,26 @@ public extension QRCode {
}
}
}

if let logoTemplate = logoTemplate {
ctx.saveGState()
// Get the absolute rect within the generated image of the mask path
let absMask = logoTemplate.absolutePathForMaskPath(
dimension: min(finalRect.width, finalRect.height),
flipped: true
)

// logo drawing is flipped.
ctx.scaleBy(x: 1, y: -1)
ctx.translateBy(x: xoff - additionalQuietSpace, y: yoff - rect.height - additionalQuietSpace)

// Clip to the mask path.
ctx.addPath(absMask)
ctx.clip()

// Draw the logo image into the mask bounds
ctx.draw(logoTemplate.image, in: absMask.boundingBoxOfPath.insetBy(dx: logoTemplate.inset, dy: logoTemplate.inset))
ctx.restoreGState()
ctx.usingGState { context in
// Get the absolute rect within the generated image of the mask path
let absMask = logoTemplate.absolutePathForMaskPath(
dimension: min(finalRect.width, finalRect.height),
flipped: true
)
// logo drawing is flipped.
context.scaleBy(x: 1, y: -1)
context.translateBy(x: xoff - additionalQuietSpace, y: yoff - rect.height - additionalQuietSpace)
// Clip to the mask path.
context.addPath(absMask)
context.clip()
// Draw the logo image into the mask bounds
context.draw(logoTemplate.image, in: absMask.boundingBoxOfPath.insetBy(dx: logoTemplate.inset, dy: logoTemplate.inset))
}
}
}
}
1 change: 1 addition & 0 deletions Sources/QRCode/styles/data/QRCodePixelShapeFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import Foundation
QRCode.PixelShape.Sharp.self,
QRCode.PixelShape.Star.self,
QRCode.PixelShape.Shiny.self,
QRCode.PixelShape.CRT.self,
].sorted(by: { a, b in a.Title < b.Title })

/// The default matrix to use when generating pixel sample images
Expand Down
Loading

0 comments on commit e3859a9

Please sign in to comment.